org-agenda.el 211 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.10
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl)
  29. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-check-holidays "holidays" (date))
  36. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  37. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  39. (declare-function calendar-french-date-string "cal-french" (&optional date))
  40. (declare-function calendar-goto-date "cal-move" (date))
  41. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  42. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  43. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  44. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  45. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  46. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  47. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (defvar calendar-mode-map)
  50. ;; Defined somewhere in this file, but used before definition.
  51. (defvar org-agenda-buffer-name)
  52. (defvar org-agenda-overriding-header)
  53. (defvar entry)
  54. (defvar date)
  55. (defvar org-agenda-undo-list)
  56. (defvar org-agenda-pending-undo-list)
  57. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  58. (defcustom org-agenda-confirm-kill 1
  59. "When set, remote killing from the agenda buffer needs confirmation.
  60. When t, a confirmation is always needed. When a number N, confirmation is
  61. only needed when the text to be killed contains more than N non-white lines."
  62. :group 'org-agenda
  63. :type '(choice
  64. (const :tag "Never" nil)
  65. (const :tag "Always" t)
  66. (number :tag "When more than N lines")))
  67. (defcustom org-agenda-compact-blocks nil
  68. "Non-nil means, make the block agenda more compact.
  69. This is done by leaving out unnecessary lines."
  70. :group 'org-agenda
  71. :type 'boolean)
  72. (defgroup org-agenda-export nil
  73. "Options concerning exporting agenda views in Org-mode."
  74. :tag "Org Agenda Export"
  75. :group 'org-agenda)
  76. (defcustom org-agenda-with-colors t
  77. "Non-nil means, use colors in agenda views."
  78. :group 'org-agenda-export
  79. :type 'boolean)
  80. (defcustom org-agenda-exporter-settings nil
  81. "Alist of variable/value pairs that should be active during agenda export.
  82. This is a good place to set uptions for ps-print and for htmlize."
  83. :group 'org-agenda-export
  84. :type '(repeat
  85. (list
  86. (variable)
  87. (sexp :tag "Value"))))
  88. (defcustom org-agenda-export-html-style ""
  89. "The style specification for exported HTML Agenda files.
  90. If this variable contains a string, it will replace the default <style>
  91. section as produced by `htmlize'.
  92. Since there are different ways of setting style information, this variable
  93. needs to contain the full HTML structure to provide a style, including the
  94. surrounding HTML tags. The style specifications should include definitions
  95. the fonts used by the agenda, here is an example:
  96. <style type=\"text/css\">
  97. p { font-weight: normal; color: gray; }
  98. .org-agenda-structure {
  99. font-size: 110%;
  100. color: #003399;
  101. font-weight: 600;
  102. }
  103. .org-todo {
  104. color: #cc6666;
  105. font-weight: bold;
  106. }
  107. .org-done {
  108. color: #339933;
  109. }
  110. .title { text-align: center; }
  111. .todo, .deadline { color: red; }
  112. .done { color: green; }
  113. </style>
  114. or, if you want to keep the style in a file,
  115. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  116. As the value of this option simply gets inserted into the HTML <head> header,
  117. you can \"misuse\" it to also add other text to the header. However,
  118. <style>...</style> is required, if not present the variable will be ignored."
  119. :group 'org-agenda-export
  120. :group 'org-export-html
  121. :type 'string)
  122. (defgroup org-agenda-custom-commands nil
  123. "Options concerning agenda views in Org-mode."
  124. :tag "Org Agenda Custom Commands"
  125. :group 'org-agenda)
  126. (defconst org-sorting-choice
  127. '(choice
  128. (const time-up) (const time-down)
  129. (const category-keep) (const category-up) (const category-down)
  130. (const tag-down) (const tag-up)
  131. (const priority-up) (const priority-down)
  132. (const todo-state-up) (const todo-state-down)
  133. (const effort-up) (const effort-down))
  134. "Sorting choices.")
  135. (defconst org-agenda-custom-commands-local-options
  136. `(repeat :tag "Local settings for this command. Remember to quote values"
  137. (choice :tag "Setting"
  138. (list :tag "Any variable"
  139. (variable :tag "Variable")
  140. (sexp :tag "Value"))
  141. (list :tag "Files to be searched"
  142. (const org-agenda-files)
  143. (list
  144. (const :format "" quote)
  145. (repeat
  146. (file))))
  147. (list :tag "Sorting strategy"
  148. (const org-agenda-sorting-strategy)
  149. (list
  150. (const :format "" quote)
  151. (repeat
  152. ,org-sorting-choice)))
  153. (list :tag "Prefix format"
  154. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  155. (string))
  156. (list :tag "Number of days in agenda"
  157. (const org-agenda-ndays)
  158. (integer :value 1))
  159. (list :tag "Fixed starting date"
  160. (const org-agenda-start-day)
  161. (string :value "2007-11-01"))
  162. (list :tag "Start on day of week"
  163. (const org-agenda-start-on-weekday)
  164. (choice :value 1
  165. (const :tag "Today" nil)
  166. (number :tag "Weekday No.")))
  167. (list :tag "Include data from diary"
  168. (const org-agenda-include-diary)
  169. (boolean))
  170. (list :tag "Deadline Warning days"
  171. (const org-deadline-warning-days)
  172. (integer :value 1))
  173. (list :tag "Standard skipping condition"
  174. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  175. (const org-agenda-skip-function)
  176. (list
  177. (const :format "" quote)
  178. (list
  179. (choice
  180. :tag "Skiping range"
  181. (const :tag "Skip entry" org-agenda-skip-entry-if)
  182. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  183. (repeat :inline t :tag "Conditions for skipping"
  184. (choice
  185. :tag "Condition type"
  186. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  187. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  188. (const :tag "scheduled" 'scheduled)
  189. (const :tag "not scheduled" 'notscheduled)
  190. (const :tag "deadline" 'deadline)
  191. (const :tag "no deadline" 'notdeadline))))))
  192. (list :tag "Non-standard skipping condition"
  193. :value (org-agenda-skip-function)
  194. (const org-agenda-skip-function)
  195. (sexp :tag "Function or form (quoted!)"))))
  196. "Selection of examples for agenda command settings.
  197. This will be spliced into the custom type of
  198. `org-agenda-custom-commands'.")
  199. (defcustom org-agenda-custom-commands nil
  200. "Custom commands for the agenda.
  201. These commands will be offered on the splash screen displayed by the
  202. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  203. (key desc type match settings files)
  204. key The key (one or more characters as a string) to be associated
  205. with the command.
  206. desc A description of the command, when omitted or nil, a default
  207. description is built using MATCH.
  208. type The command type, any of the following symbols:
  209. agenda The daily/weekly agenda.
  210. todo Entries with a specific TODO keyword, in all agenda files.
  211. search Entries containing search words entry or headline.
  212. tags Tags/Property/TODO match in all agenda files.
  213. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  214. todo-tree Sparse tree of specific TODO keyword in *current* file.
  215. tags-tree Sparse tree with all tags matches in *current* file.
  216. occur-tree Occur sparse tree for *current* file.
  217. ... A user-defined function.
  218. match What to search for:
  219. - a single keyword for TODO keyword searches
  220. - a tags match expression for tags searches
  221. - a word search expression for text searches.
  222. - a regular expression for occur searches
  223. For all other commands, this should be the empty string.
  224. settings A list of option settings, similar to that in a let form, so like
  225. this: ((opt1 val1) (opt2 val2) ...). The values will be
  226. evaluated at the moment of execution, so quote them when needed.
  227. files A list of files file to write the produced agenda buffer to
  228. with the command `org-store-agenda-views'.
  229. If a file name ends in \".html\", an HTML version of the buffer
  230. is written out. If it ends in \".ps\", a postscript version is
  231. produced. Otherwide, only the plain text is written to the file.
  232. You can also define a set of commands, to create a composite agenda buffer.
  233. In this case, an entry looks like this:
  234. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  235. where
  236. desc A description string to be displayed in the dispatcher menu.
  237. cmd An agenda command, similar to the above. However, tree commands
  238. are no allowed, but instead you can get agenda and global todo list.
  239. So valid commands for a set are:
  240. (agenda \"\" settings)
  241. (alltodo \"\" settings)
  242. (stuck \"\" settings)
  243. (todo \"match\" settings files)
  244. (search \"match\" settings files)
  245. (tags \"match\" settings files)
  246. (tags-todo \"match\" settings files)
  247. Each command can carry a list of options, and another set of options can be
  248. given for the whole set of commands. Individual command options take
  249. precedence over the general options.
  250. When using several characters as key to a command, the first characters
  251. are prefix commands. For the dispatcher to display useful information, you
  252. should provide a description for the prefix, like
  253. (setq org-agenda-custom-commands
  254. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  255. (\"hl\" tags \"+HOME+Lisa\")
  256. (\"hp\" tags \"+HOME+Peter\")
  257. (\"hk\" tags \"+HOME+Kim\")))"
  258. :group 'org-agenda-custom-commands
  259. :type `(repeat
  260. (choice :value ("x" "Describe command here" tags "" nil)
  261. (list :tag "Single command"
  262. (string :tag "Access Key(s) ")
  263. (option (string :tag "Description"))
  264. (choice
  265. (const :tag "Agenda" agenda)
  266. (const :tag "TODO list" alltodo)
  267. (const :tag "Search words" search)
  268. (const :tag "Stuck projects" stuck)
  269. (const :tag "Tags search (all agenda files)" tags)
  270. (const :tag "Tags search of TODO entries (all agenda files)" tags-todo)
  271. (const :tag "TODO keyword search (all agenda files)" todo)
  272. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  273. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  274. (const :tag "Occur tree (current buffer)" occur-tree)
  275. (sexp :tag "Other, user-defined function"))
  276. (string :tag "Match (only for some commands)")
  277. ,org-agenda-custom-commands-local-options
  278. (option (repeat :tag "Export" (file :tag "Export to"))))
  279. (list :tag "Command series, all agenda files"
  280. (string :tag "Access Key(s)")
  281. (string :tag "Description ")
  282. (repeat :tag "Component"
  283. (choice
  284. (list :tag "Agenda"
  285. (const :format "" agenda)
  286. (const :tag "" :format "" "")
  287. ,org-agenda-custom-commands-local-options)
  288. (list :tag "TODO list (all keywords)"
  289. (const :format "" alltodo)
  290. (const :tag "" :format "" "")
  291. ,org-agenda-custom-commands-local-options)
  292. (list :tag "Search words"
  293. (const :format "" search)
  294. (string :tag "Match")
  295. ,org-agenda-custom-commands-local-options)
  296. (list :tag "Stuck projects"
  297. (const :format "" stuck)
  298. (const :tag "" :format "" "")
  299. ,org-agenda-custom-commands-local-options)
  300. (list :tag "Tags search"
  301. (const :format "" tags)
  302. (string :tag "Match")
  303. ,org-agenda-custom-commands-local-options)
  304. (list :tag "Tags search, TODO entries only"
  305. (const :format "" tags-todo)
  306. (string :tag "Match")
  307. ,org-agenda-custom-commands-local-options)
  308. (list :tag "TODO keyword search"
  309. (const :format "" todo)
  310. (string :tag "Match")
  311. ,org-agenda-custom-commands-local-options)
  312. (list :tag "Other, user-defined function"
  313. (symbol :tag "function")
  314. (string :tag "Match")
  315. ,org-agenda-custom-commands-local-options)))
  316. (repeat :tag "Settings for entire command set"
  317. (list (variable :tag "Any variable")
  318. (sexp :tag "Value")))
  319. (option (repeat :tag "Export" (file :tag "Export to"))))
  320. (cons :tag "Prefix key documentation"
  321. (string :tag "Access Key(s)")
  322. (string :tag "Description ")))))
  323. (defcustom org-agenda-query-register ?o
  324. "The register holding the current query string.
  325. The prupose of this is that if you construct a query string interactively,
  326. you can then use it to define a custom command."
  327. :group 'org-agenda-custom-commands
  328. :type 'character)
  329. (defcustom org-stuck-projects
  330. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  331. "How to identify stuck projects.
  332. This is a list of four items:
  333. 1. A tags/todo matcher string that is used to identify a project.
  334. The entire tree below a headline matched by this is considered one project.
  335. 2. A list of TODO keywords identifying non-stuck projects.
  336. If the project subtree contains any headline with one of these todo
  337. keywords, the project is considered to be not stuck. If you specify
  338. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  339. 3. A list of tags identifying non-stuck projects.
  340. If the project subtree contains any headline with one of these tags,
  341. the project is considered to be not stuck. If you specify \"*\" as
  342. a tag, any tag will mark the project unstuck.
  343. 4. An arbitrary regular expression matching non-stuck projects.
  344. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  345. or `C-c a #' to produce the list."
  346. :group 'org-agenda-custom-commands
  347. :type '(list
  348. (string :tag "Tags/TODO match to identify a project")
  349. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  350. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  351. (regexp :tag "Projects are *not* stuck if this regexp matches\ninside the subtree")))
  352. (defcustom org-agenda-filter-effort-default-operator "<"
  353. "The default operator for effort estimate filtering.
  354. If you select an effort estimate limit with first pressing an operator,
  355. this one will be used."
  356. :group 'org-agenda-custom-commands
  357. :type '(choice (const :tag "less or equal" "<")
  358. (const :tag "greater or equal"">")
  359. (const :tag "equal" "=")))
  360. (defgroup org-agenda-skip nil
  361. "Options concerning skipping parts of agenda files."
  362. :tag "Org Agenda Skip"
  363. :group 'org-agenda)
  364. (defvar org-agenda-archives-mode nil
  365. "Non-nil means, the agenda will include archived items.
  366. If this is the symbol `trees', trees in the selected agenda scope
  367. that are marked with the ARCHIVE tag will be included anyway. When this is
  368. t, also all archive files associated with the current selection of agenda
  369. files will be included.")
  370. (defcustom org-agenda-skip-comment-trees t
  371. "Non-nil means, skip trees that start with teh COMMENT keyword.
  372. When nil, these trees are also scand by agenda commands."
  373. :group 'org-agenda-skip
  374. :type 'boolean)
  375. (defcustom org-agenda-todo-list-sublevels t
  376. "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
  377. When nil, the sublevels of a TODO entry are not checked, resulting in
  378. potentially much shorter TODO lists."
  379. :group 'org-agenda-skip
  380. :group 'org-todo
  381. :type 'boolean)
  382. (defcustom org-agenda-todo-ignore-with-date nil
  383. "Non-nil means, don't show entries with a date in the global todo list.
  384. You can use this if you prefer to mark mere appointments with a TODO keyword,
  385. but don't want them to show up in the TODO list.
  386. When this is set, it also covers deadlines and scheduled items, the settings
  387. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  388. will be ignored."
  389. :group 'org-agenda-skip
  390. :group 'org-todo
  391. :type 'boolean)
  392. (defcustom org-agenda-todo-ignore-scheduled nil
  393. "Non-nil means, don't show scheduled entries in the global todo list.
  394. The idea behind this is that by scheduling it, you have already taken care
  395. of this item.
  396. See also `org-agenda-todo-ignore-with-date'."
  397. :group 'org-agenda-skip
  398. :group 'org-todo
  399. :type 'boolean)
  400. (defcustom org-agenda-todo-ignore-deadlines nil
  401. "Non-nil means, don't show near deadline entries in the global todo list.
  402. Near means closer than `org-deadline-warning-days' days.
  403. The idea behind this is that such items will appear in the agenda anyway.
  404. See also `org-agenda-todo-ignore-with-date'."
  405. :group 'org-agenda-skip
  406. :group 'org-todo
  407. :type 'boolean)
  408. (defcustom org-agenda-skip-scheduled-if-done nil
  409. "Non-nil means don't show scheduled items in agenda when they are done.
  410. This is relevant for the daily/weekly agenda, not for the TODO list. And
  411. it applies only to the actual date of the scheduling. Warnings about
  412. an item with a past scheduling dates are always turned off when the item
  413. is DONE."
  414. :group 'org-agenda-skip
  415. :type 'boolean)
  416. (defcustom org-agenda-skip-deadline-if-done nil
  417. "Non-nil means don't show deadines when the corresponding item is done.
  418. When nil, the deadline is still shown and should give you a happy feeling.
  419. This is relevant for the daily/weekly agenda. And it applied only to the
  420. actualy date of the deadline. Warnings about approching and past-due
  421. deadlines are always turned off when the item is DONE."
  422. :group 'org-agenda-skip
  423. :type 'boolean)
  424. (defcustom org-agenda-skip-timestamp-if-done nil
  425. "Non-nil means don't select item by timestamp or -range if it is DONE."
  426. :group 'org-agenda-skip
  427. :type 'boolean)
  428. (defcustom org-timeline-show-empty-dates 3
  429. "Non-nil means, `org-timeline' also shows dates without an entry.
  430. When nil, only the days which actually have entries are shown.
  431. When t, all days between the first and the last date are shown.
  432. When an integer, show also empty dates, but if there is a gap of more than
  433. N days, just insert a special line indicating the size of the gap."
  434. :group 'org-agenda-skip
  435. :type '(choice
  436. (const :tag "None" nil)
  437. (const :tag "All" t)
  438. (number :tag "at most")))
  439. (defgroup org-agenda-startup nil
  440. "Options concerning initial settings in the Agenda in Org Mode."
  441. :tag "Org Agenda Startup"
  442. :group 'org-agenda)
  443. (defcustom org-finalize-agenda-hook nil
  444. "Hook run just before displaying an agenda buffer."
  445. :group 'org-agenda-startup
  446. :type 'hook)
  447. (defcustom org-agenda-mouse-1-follows-link nil
  448. "Non-nil means, mouse-1 on a link will follow the link in the agenda.
  449. A longer mouse click will still set point. Does not work on XEmacs.
  450. Needs to be set before org.el is loaded."
  451. :group 'org-agenda-startup
  452. :type 'boolean)
  453. (defcustom org-agenda-start-with-follow-mode nil
  454. "The initial value of follow-mode in a newly created agenda window."
  455. :group 'org-agenda-startup
  456. :type 'boolean)
  457. (defvar org-agenda-include-inactive-timestamps nil
  458. "Non-nil means, include inactive time stamps in agenda and timeline.")
  459. (defgroup org-agenda-windows nil
  460. "Options concerning the windows used by the Agenda in Org Mode."
  461. :tag "Org Agenda Windows"
  462. :group 'org-agenda)
  463. (defcustom org-agenda-window-setup 'reorganize-frame
  464. "How the agenda buffer should be displayed.
  465. Possible values for this option are:
  466. current-window Show agenda in the current window, keeping all other windows.
  467. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  468. other-window Use `switch-to-buffer-other-window' to display agenda.
  469. reorganize-frame Show only two windows on the current frame, the current
  470. window and the agenda.
  471. See also the variable `org-agenda-restore-windows-after-quit'."
  472. :group 'org-agenda-windows
  473. :type '(choice
  474. (const current-window)
  475. (const other-frame)
  476. (const other-window)
  477. (const reorganize-frame)))
  478. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  479. "The min and max height of the agenda window as a fraction of frame height.
  480. The value of the variable is a cons cell with two numbers between 0 and 1.
  481. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  482. :group 'org-agenda-windows
  483. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  484. (defcustom org-agenda-restore-windows-after-quit nil
  485. "Non-nil means, restore window configuration open exiting agenda.
  486. Before the window configuration is changed for displaying the agenda,
  487. the current status is recorded. When the agenda is exited with
  488. `q' or `x' and this option is set, the old state is restored. If
  489. `org-agenda-window-setup' is `other-frame', the value of this
  490. option will be ignored.."
  491. :group 'org-agenda-windows
  492. :type 'boolean)
  493. (defgroup org-agenda-daily/weekly nil
  494. "Options concerning the daily/weekly agenda."
  495. :tag "Org Agenda Daily/Weekly"
  496. :group 'org-agenda)
  497. (defcustom org-agenda-ndays 7
  498. "Number of days to include in overview display.
  499. Should be 1 or 7."
  500. :group 'org-agenda-daily/weekly
  501. :type 'number)
  502. (defcustom org-agenda-start-on-weekday 1
  503. "Non-nil means, start the overview always on the specified weekday.
  504. 0 denotes Sunday, 1 denotes Monday etc.
  505. When nil, always start on the current day."
  506. :group 'org-agenda-daily/weekly
  507. :type '(choice (const :tag "Today" nil)
  508. (number :tag "Weekday No.")))
  509. (defcustom org-agenda-show-all-dates t
  510. "Non-nil means, `org-agenda' shows every day in the selected range.
  511. When nil, only the days which actually have entries are shown."
  512. :group 'org-agenda-daily/weekly
  513. :type 'boolean)
  514. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  515. "Format string for displaying dates in the agenda.
  516. Used by the daily/weekly agenda and by the timeline. This should be
  517. a format string understood by `format-time-string', or a function returning
  518. the formatted date as a string. The function must take a single argument,
  519. a calendar-style date list like (month day year)."
  520. :group 'org-agenda-daily/weekly
  521. :type '(choice
  522. (string :tag "Format string")
  523. (function :tag "Function")))
  524. (defun org-agenda-format-date-aligned (date)
  525. "Format a date string for display in the daily/weekly agenda, or timeline.
  526. This function makes sure that dates are aligned for easy reading."
  527. (require 'cal-iso)
  528. (let* ((dayname (calendar-day-name date))
  529. (day (cadr date))
  530. (day-of-week (calendar-day-of-week date))
  531. (month (car date))
  532. (monthname (calendar-month-name month))
  533. (year (nth 2 date))
  534. (iso-week (org-days-to-iso-week
  535. (calendar-absolute-from-gregorian date)))
  536. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  537. (1- year))
  538. ((and (= month 12) (<= iso-week 1))
  539. (1+ year))
  540. (t year)))
  541. (weekstring (if (= day-of-week 1)
  542. (format " W%02d" iso-week)
  543. "")))
  544. (format "%-10s %2d %s %4d%s"
  545. dayname day monthname year weekstring)))
  546. (defcustom org-agenda-weekend-days '(6 0)
  547. "Which days are weekend?
  548. These days get the special face `org-agenda-date-weekend' in the agenda
  549. and timeline buffers."
  550. :group 'org-agenda-daily/weekly
  551. :type '(set :greedy t
  552. (const :tag "Monday" 1)
  553. (const :tag "Tuesday" 2)
  554. (const :tag "Wednesday" 3)
  555. (const :tag "Thursday" 4)
  556. (const :tag "Friday" 5)
  557. (const :tag "Saturday" 6)
  558. (const :tag "Sunday" 0)))
  559. (defcustom org-agenda-include-diary nil
  560. "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
  561. :group 'org-agenda-daily/weekly
  562. :type 'boolean)
  563. (defcustom org-agenda-include-all-todo nil
  564. "Set means weekly/daily agenda will always contain all TODO entries.
  565. The TODO entries will be listed at the top of the agenda, before
  566. the entries for specific days."
  567. :group 'org-agenda-daily/weekly
  568. :type 'boolean)
  569. (defcustom org-agenda-repeating-timestamp-show-all t
  570. "Non-nil means, show all occurences of a repeating stamp in the agenda.
  571. When nil, only one occurence is shown, either today or the
  572. nearest into the future."
  573. :group 'org-agenda-daily/weekly
  574. :type 'boolean)
  575. (defcustom org-scheduled-past-days 10000
  576. "No. of days to continue listing scheduled items that are not marked DONE.
  577. When an item is scheduled on a date, it shows up in the agenda on this
  578. day and will be listed until it is marked done for the number of days
  579. given here."
  580. :group 'org-agenda-daily/weekly
  581. :type 'number)
  582. (defcustom org-agenda-start-with-clockreport-mode nil
  583. "The initial value of clockreport-mode in a newly created agenda window."
  584. :group 'org-agenda-startup
  585. :group 'org-agenda-daily/weekly
  586. :type 'boolean)
  587. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  588. "Property list with parameters for the clocktable in clockreport mode.
  589. This is the display mode that shows a clock table in the daily/weekly
  590. agenda, the properties for this dynamic block can be set here.
  591. The usual clocktable parameters are allowed here, but you cannot set
  592. the properties :name, :tstart, :tend, :block, and :scope - these will
  593. be overwritten to make sure the content accurately reflects the
  594. current display in the agenda."
  595. :group 'org-agenda-daily/weekly
  596. :type 'plist)
  597. (defgroup org-agenda-time-grid nil
  598. "Options concerning the time grid in the Org-mode Agenda."
  599. :tag "Org Agenda Time Grid"
  600. :group 'org-agenda)
  601. (defcustom org-agenda-use-time-grid t
  602. "Non-nil means, show a time grid in the agenda schedule.
  603. A time grid is a set of lines for specific times (like every two hours between
  604. 8:00 and 20:00). The items scheduled for a day at specific times are
  605. sorted in between these lines.
  606. For details about when the grid will be shown, and what it will look like, see
  607. the variable `org-agenda-time-grid'."
  608. :group 'org-agenda-time-grid
  609. :type 'boolean)
  610. (defcustom org-agenda-time-grid
  611. '((daily today require-timed)
  612. "----------------"
  613. (800 1000 1200 1400 1600 1800 2000))
  614. "The settings for time grid for agenda display.
  615. This is a list of three items. The first item is again a list. It contains
  616. symbols specifying conditions when the grid should be displayed:
  617. daily if the agenda shows a single day
  618. weekly if the agenda shows an entire week
  619. today show grid on current date, independent of daily/weekly display
  620. require-timed show grid only if at least one item has a time specification
  621. The second item is a string which will be placed behind the grid time.
  622. The third item is a list of integers, indicating the times that should have
  623. a grid line."
  624. :group 'org-agenda-time-grid
  625. :type
  626. '(list
  627. (set :greedy t :tag "Grid Display Options"
  628. (const :tag "Show grid in single day agenda display" daily)
  629. (const :tag "Show grid in weekly agenda display" weekly)
  630. (const :tag "Always show grid for today" today)
  631. (const :tag "Show grid only if any timed entries are present"
  632. require-timed)
  633. (const :tag "Skip grid times already present in an entry"
  634. remove-match))
  635. (string :tag "Grid String")
  636. (repeat :tag "Grid Times" (integer :tag "Time"))))
  637. (defgroup org-agenda-sorting nil
  638. "Options concerning sorting in the Org-mode Agenda."
  639. :tag "Org Agenda Sorting"
  640. :group 'org-agenda)
  641. (defcustom org-agenda-sorting-strategy
  642. '((agenda time-up category-keep priority-down)
  643. (todo category-keep priority-down)
  644. (tags category-keep priority-down)
  645. (search category-keep))
  646. "Sorting structure for the agenda items of a single day.
  647. This is a list of symbols which will be used in sequence to determine
  648. if an entry should be listed before another entry. The following
  649. symbols are recognized:
  650. time-up Put entries with time-of-day indications first, early first
  651. time-down Put entries with time-of-day indications first, late first
  652. category-keep Keep the default order of categories, corresponding to the
  653. sequence in `org-agenda-files'.
  654. category-up Sort alphabetically by category, A-Z.
  655. category-down Sort alphabetically by category, Z-A.
  656. tag-up Sort alphabetically by last tag, A-Z.
  657. tag-down Sort alphabetically by last tag, Z-A.
  658. priority-up Sort numerically by priority, high priority last.
  659. priority-down Sort numerically by priority, high priority first.
  660. todo-state-up Sort by todo state, tasks that are done last.
  661. todo-state-down Sort by todo state, tasks that are done first.
  662. effort-up Sort numerically by estimated effort, high effort last.
  663. effort-down Sort numerically by estimated effort, high effort first.
  664. The different possibilities will be tried in sequence, and testing stops
  665. if one comparison returns a \"not-equal\". For example, the default
  666. '(time-up category-keep priority-down)
  667. means: Pull out all entries having a specified time of day and sort them,
  668. in order to make a time schedule for the current day the first thing in the
  669. agenda listing for the day. Of the entries without a time indication, keep
  670. the grouped in categories, don't sort the categories, but keep them in
  671. the sequence given in `org-agenda-files'. Within each category sort by
  672. priority.
  673. Leaving out `category-keep' would mean that items will be sorted across
  674. categories by priority.
  675. Instead of a single list, this can also be a set of list for specific
  676. contents, with a context symbol in the car of the list, any of
  677. `agenda', `todo', `tags' for the corresponding agenda views."
  678. :group 'org-agenda-sorting
  679. :type `(choice
  680. (repeat :tag "General" ,org-sorting-choice)
  681. (list :tag "Individually"
  682. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  683. (repeat ,org-sorting-choice))
  684. (cons (const :tag "Strategy for TODO lists" todo)
  685. (repeat ,org-sorting-choice))
  686. (cons (const :tag "Strategy for Tags matches" tags)
  687. (repeat ,org-sorting-choice)))))
  688. (defcustom org-sort-agenda-notime-is-late t
  689. "Non-nil means, items without time are considered late.
  690. This is only relevant for sorting. When t, items which have no explicit
  691. time like 15:30 will be considered as 99:01, i.e. later than any items which
  692. do have a time. When nil, the default time is before 0:00. You can use this
  693. option to decide if the schedule for today should come before or after timeless
  694. agenda entries."
  695. :group 'org-agenda-sorting
  696. :type 'boolean)
  697. (defcustom org-sort-agenda-noeffort-is-high t
  698. "Non-nil means, items without effort estimate are sorted as high effort.
  699. When nil, such items are sorted as 0 minutes effort."
  700. :group 'org-agenda-sorting
  701. :type 'boolean)
  702. (defgroup org-agenda-line-format nil
  703. "Options concerning the entry prefix in the Org-mode agenda display."
  704. :tag "Org Agenda Line Format"
  705. :group 'org-agenda)
  706. (defcustom org-agenda-prefix-format
  707. '((agenda . " %-12:c%?-12t% s")
  708. (timeline . " % s")
  709. (todo . " %-12:c")
  710. (tags . " %-12:c")
  711. (search . " %-12:c"))
  712. "Format specifications for the prefix of items in the agenda views.
  713. An alist with four entries, for the different agenda types. The keys to the
  714. sublists are `agenda', `timeline', `todo', and `tags'. The values
  715. are format strings.
  716. This format works similar to a printf format, with the following meaning:
  717. %c the category of the item, \"Diary\" for entries from the diary, or
  718. as given by the CATEGORY keyword or derived from the file name.
  719. %T the *last* tag of the item. Last because inherited tags come
  720. first in the list.
  721. %t the time-of-day specification if one applies to the entry, in the
  722. format HH:MM
  723. %s Scheduling/Deadline information, a short string
  724. All specifiers work basically like the standard `%s' of printf, but may
  725. contain two additional characters: A question mark just after the `%' and
  726. a whitespace/punctuation character just before the final letter.
  727. If the first character after `%' is a question mark, the entire field
  728. will only be included if the corresponding value applies to the
  729. current entry. This is useful for fields which should have fixed
  730. width when present, but zero width when absent. For example,
  731. \"%?-12t\" will result in a 12 character time field if a time of the
  732. day is specified, but will completely disappear in entries which do
  733. not contain a time.
  734. If there is punctuation or whitespace character just before the final
  735. format letter, this character will be appended to the field value if
  736. the value is not empty. For example, the format \"%-12:c\" leads to
  737. \"Diary: \" if the category is \"Diary\". If the category were be
  738. empty, no additional colon would be interted.
  739. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  740. - Indent the line with two space characters
  741. - Give the category in a 12 chars wide field, padded with whitespace on
  742. the right (because of `-'). Append a colon if there is a category
  743. (because of `:').
  744. - If there is a time-of-day, put it into a 12 chars wide field. If no
  745. time, don't put in an empty field, just skip it (because of '?').
  746. - Finally, put the scheduling information and append a whitespace.
  747. As another example, if you don't want the time-of-day of entries in
  748. the prefix, you could use:
  749. (setq org-agenda-prefix-format \" %-11:c% s\")
  750. See also the variables `org-agenda-remove-times-when-in-prefix' and
  751. `org-agenda-remove-tags'."
  752. :type '(choice
  753. (string :tag "General format")
  754. (list :greedy t :tag "View dependent"
  755. (cons (const agenda) (string :tag "Format"))
  756. (cons (const timeline) (string :tag "Format"))
  757. (cons (const todo) (string :tag "Format"))
  758. (cons (const tags) (string :tag "Format"))
  759. (cons (const search) (string :tag "Format"))))
  760. :group 'org-agenda-line-format)
  761. (defvar org-prefix-format-compiled nil
  762. "The compiled version of the most recently used prefix format.
  763. See the variable `org-agenda-prefix-format'.")
  764. (defcustom org-agenda-todo-keyword-format "%-1s"
  765. "Format for the TODO keyword in agenda lines.
  766. Set this to something like \"%-12s\" if you want all TODO keywords
  767. to occupy a fixed space in the agenda display."
  768. :group 'org-agenda-line-format
  769. :type 'string)
  770. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  771. "Text preceeding scheduled items in the agenda view.
  772. This is a list with two strings. The first applies when the item is
  773. scheduled on the current day. The second applies when it has been scheduled
  774. previously, it may contain a %d indicating that this is the nth time that
  775. this item is scheduled, due to automatic rescheduling of unfinished items
  776. for the following day. So this number is one larger than the number of days
  777. that passed since this item was scheduled first."
  778. :group 'org-agenda-line-format
  779. :type '(list
  780. (string :tag "Scheduled today ")
  781. (string :tag "Scheduled previously")))
  782. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  783. "Text preceeding deadline items in the agenda view.
  784. This is a list with two strings. The first applies when the item has its
  785. deadline on the current day. The second applies when it is in the past or
  786. in the future, it may contain %d to capture how many days away the deadline
  787. is (was)."
  788. :group 'org-agenda-line-format
  789. :type '(list
  790. (string :tag "Deadline today ")
  791. (choice :tag "Deadline relative"
  792. (string :tag "Format string")
  793. (function))))
  794. (defcustom org-agenda-remove-times-when-in-prefix t
  795. "Non-nil means, remove duplicate time specifications in agenda items.
  796. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  797. time-of-day specification in a headline or diary entry is extracted and
  798. placed into the prefix. If this option is non-nil, the original specification
  799. \(a timestamp or -range, or just a plain time(range) specification like
  800. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  801. cluttered.
  802. The option can be t or nil. It may also be the symbol `beg', indicating
  803. that the time should only be removed what it is located at the beginning of
  804. the headline/diary entry."
  805. :group 'org-agenda-line-format
  806. :type '(choice
  807. (const :tag "Always" t)
  808. (const :tag "Never" nil)
  809. (const :tag "When at beginning of entry" beg)))
  810. (defcustom org-agenda-default-appointment-duration nil
  811. "Default duration for appointments that only have a starting time.
  812. When nil, no duration is specified in such cases.
  813. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  814. :group 'org-agenda-line-format
  815. :type '(choice
  816. (integer :tag "Minutes")
  817. (const :tag "No default duration")))
  818. (defcustom org-agenda-remove-tags nil
  819. "Non-nil means, remove the tags from the headline copy in the agenda.
  820. When this is the symbol `prefix', only remove tags when
  821. `org-agenda-prefix-format' contains a `%T' specifier."
  822. :group 'org-agenda-line-format
  823. :type '(choice
  824. (const :tag "Always" t)
  825. (const :tag "Never" nil)
  826. (const :tag "When prefix format contains %T" prefix)))
  827. (if (fboundp 'defvaralias)
  828. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  829. 'org-agenda-remove-tags))
  830. (defcustom org-agenda-tags-column -80
  831. "Shift tags in agenda items to this column.
  832. If this number is positive, it specifies the column. If it is negative,
  833. it means that the tags should be flushright to that column. For example,
  834. -80 works well for a normal 80 character screen."
  835. :group 'org-agenda-line-format
  836. :type 'integer)
  837. (if (fboundp 'defvaralias)
  838. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  839. (defcustom org-agenda-fontify-priorities t
  840. "Non-nil means, highlight low and high priorities in agenda.
  841. When t, the highest priority entries are bold, lowest priority italic.
  842. This may also be an association list of priority faces, whose
  843. keys are the character values of `org-highest-priority',
  844. `org-default-priority', and `org-lowest-priority' (the default values
  845. are ?A, ?B, and ?C, respectively). The face may be a names face,
  846. or a list like `(:background \"Red\")'."
  847. :group 'org-agenda-line-format
  848. :type '(choice
  849. (const :tag "Never" nil)
  850. (const :tag "Defaults" t)
  851. (repeat :tag "Specify"
  852. (list (character :tag "Priority" :value ?A)
  853. (sexp :tag "face")))))
  854. (defgroup org-agenda-column-view nil
  855. "Options concerning column view in the agenda."
  856. :tag "Org Agenda Column View"
  857. :group 'org-agenda)
  858. (defcustom org-agenda-columns-show-summaries t
  859. "Non-nil means, show summaries for columns displayed in the agenda view."
  860. :group 'org-agenda-column-view
  861. :type 'boolean)
  862. (defcustom org-agenda-columns-remove-prefix-from-item t
  863. "Non-nil means, remove the prefix from a headline for agenda column view.
  864. The special ITEM field in the columns format contains the current line, with
  865. all information shown in other columns (like the TODO state or a tag).
  866. When this variable is non-nil, also the agenda prefix will be removed from
  867. the content of the ITEM field, to make sure as much as possible of the
  868. headline can be shown in the limited width of the field."
  869. :group 'org-agenda
  870. :type 'boolean)
  871. (defcustom org-agenda-columns-compute-summary-properties t
  872. "Non-nil means, recompute all summary properties before column view.
  873. When column view in the agenda is listing properties that have a summary
  874. operator, it can go to all relevant buffers and recompute the summaries
  875. there. This can mean overhead for the agenda column view, but is necessary
  876. to have thing up to date.
  877. As a special case, a CLOCKSUM property also makes sure that the clock
  878. computations are current."
  879. :group 'org-agenda-column-view
  880. :type 'boolean)
  881. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  882. "Non-nil means, the duration of an appointment will add to day effort.
  883. The property to which appointment durations will be added is the one given
  884. in the option `org-effort-property'. If an appointment does not have
  885. an end time, `org-agenda-default-appointment-duration' will be used. If that
  886. is not set, an appointment without end time will not contribute to the time
  887. estimate."
  888. :group 'org-agenda-column-view
  889. :type 'boolean)
  890. (eval-when-compile
  891. (require 'cl))
  892. (require 'org)
  893. (defun org-add-agenda-custom-command (entry)
  894. "Replace or add a command in `org-agenda-custom-commands'.
  895. This is mostly for hacking and trying a new command - once the command
  896. works you probably want to add it to `org-agenda-custom-commands' for good."
  897. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  898. (if ass
  899. (setcdr ass (cdr entry))
  900. (push entry org-agenda-custom-commands))))
  901. ;;; Define the Org-agenda-mode
  902. (defvar org-agenda-mode-map (make-sparse-keymap)
  903. "Keymap for `org-agenda-mode'.")
  904. (defvar org-agenda-menu) ; defined later in this file.
  905. (defvar org-agenda-follow-mode nil)
  906. (defvar org-agenda-clockreport-mode nil)
  907. (defvar org-agenda-show-log nil)
  908. (defvar org-agenda-redo-command nil)
  909. (defvar org-agenda-query-string nil)
  910. (defvar org-agenda-mode-hook nil)
  911. (defvar org-agenda-type nil)
  912. (defvar org-agenda-force-single-file nil)
  913. (defun org-agenda-mode ()
  914. "Mode for time-sorted view on action items in Org-mode files.
  915. The following commands are available:
  916. \\{org-agenda-mode-map}"
  917. (interactive)
  918. (kill-all-local-variables)
  919. (setq org-agenda-undo-list nil
  920. org-agenda-pending-undo-list nil)
  921. (setq major-mode 'org-agenda-mode)
  922. ;; Keep global-font-lock-mode from turning on font-lock-mode
  923. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  924. (setq mode-name "Org-Agenda")
  925. (use-local-map org-agenda-mode-map)
  926. (easy-menu-add org-agenda-menu)
  927. (if org-startup-truncated (setq truncate-lines t))
  928. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  929. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  930. ;; Make sure properties are removed when copying text
  931. (when (boundp 'buffer-substring-filters)
  932. (org-set-local 'buffer-substring-filters
  933. (cons (lambda (x)
  934. (set-text-properties 0 (length x) nil x) x)
  935. buffer-substring-filters)))
  936. (unless org-agenda-keep-modes
  937. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  938. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  939. org-agenda-show-log nil))
  940. (easy-menu-change
  941. '("Agenda") "Agenda Files"
  942. (append
  943. (list
  944. (vector
  945. (if (get 'org-agenda-files 'org-restrict)
  946. "Restricted to single file"
  947. "Edit File List")
  948. '(org-edit-agenda-file-list)
  949. (not (get 'org-agenda-files 'org-restrict)))
  950. "--")
  951. (mapcar 'org-file-menu-entry (org-agenda-files))))
  952. (org-agenda-set-mode-name)
  953. (apply
  954. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  955. (list 'org-agenda-mode-hook)))
  956. (substitute-key-definition 'undo 'org-agenda-undo
  957. org-agenda-mode-map global-map)
  958. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  959. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  960. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  961. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  962. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  963. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  964. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  965. (org-defkey org-agenda-mode-map "A" 'org-agenda-archive-to-archive-sibling)
  966. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  967. (org-defkey org-agenda-mode-map " " 'org-agenda-show)
  968. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  969. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  970. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  971. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  972. (org-defkey org-agenda-mode-map "b" 'org-agenda-tree-to-indirect-buffer)
  973. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  974. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  975. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  976. (org-defkey org-agenda-mode-map "a" 'org-agenda-toggle-archive-tag)
  977. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  978. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  979. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  980. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  981. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  982. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  983. (org-defkey org-agenda-mode-map "m" 'org-agenda-month-view)
  984. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  985. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  986. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  987. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  988. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  989. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-date-later)
  990. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-date-earlier)
  991. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-date-later)
  992. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-date-earlier)
  993. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  994. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  995. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  996. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  997. (while l (org-defkey org-agenda-mode-map
  998. (int-to-string (pop l)) 'digit-argument)))
  999. (org-defkey org-agenda-mode-map "f" 'org-agenda-follow-mode)
  1000. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1001. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1002. (org-defkey org-agenda-mode-map "v" 'org-agenda-archives-mode)
  1003. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1004. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1005. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1006. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1007. (org-defkey org-agenda-mode-map "e" 'org-agenda-execute)
  1008. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1009. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1010. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1011. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1012. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1013. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1014. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1015. (org-defkey org-agenda-mode-map "n" 'next-line)
  1016. (org-defkey org-agenda-mode-map "p" 'previous-line)
  1017. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1018. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1019. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1020. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1021. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1022. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1023. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1024. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1025. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1026. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1027. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1028. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1029. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1030. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1031. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1032. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1033. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1034. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1035. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1036. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1037. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1038. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1039. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1040. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1041. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1042. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1043. (org-defkey org-agenda-mode-map [(right)] 'org-agenda-later)
  1044. (org-defkey org-agenda-mode-map [(left)] 'org-agenda-earlier)
  1045. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1046. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1047. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1048. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1049. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1050. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1051. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1052. (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
  1053. "Local keymap for agenda entries from Org-mode.")
  1054. (org-defkey org-agenda-keymap
  1055. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1056. (org-defkey org-agenda-keymap
  1057. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1058. (when org-agenda-mouse-1-follows-link
  1059. (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
  1060. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1061. '("Agenda"
  1062. ("Agenda Files")
  1063. "--"
  1064. ["Show" org-agenda-show t]
  1065. ["Go To (other window)" org-agenda-goto t]
  1066. ["Go To (this window)" org-agenda-switch-to t]
  1067. ["Follow Mode" org-agenda-follow-mode
  1068. :style toggle :selected org-agenda-follow-mode :active t]
  1069. ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1070. "--"
  1071. ["Cycle TODO" org-agenda-todo t]
  1072. ("Archive"
  1073. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1074. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1075. ["Archive subtree" org-agenda-archive t])
  1076. ["Delete subtree" org-agenda-kill t]
  1077. ["Add note" org-agenda-add-note t]
  1078. "--"
  1079. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1080. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1081. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1082. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)]
  1083. "--"
  1084. ("Tags and Properties"
  1085. ["Show all Tags" org-agenda-show-tags t]
  1086. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1087. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1088. "--"
  1089. ["Column View" org-columns t])
  1090. ("Date/Schedule"
  1091. ["Schedule" org-agenda-schedule t]
  1092. ["Set Deadline" org-agenda-deadline t]
  1093. "--"
  1094. ["Mark item" org-agenda-action :active t :keys "k m"]
  1095. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1096. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1097. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1098. "--"
  1099. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1100. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1101. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1102. ("Clock"
  1103. ["Clock in" org-agenda-clock-in t]
  1104. ["Clock out" org-agenda-clock-out t]
  1105. ["Clock cancel" org-agenda-clock-cancel t]
  1106. ["Goto running clock" org-clock-goto t])
  1107. ("Priority"
  1108. ["Set Priority" org-agenda-priority t]
  1109. ["Increase Priority" org-agenda-priority-up t]
  1110. ["Decrease Priority" org-agenda-priority-down t]
  1111. ["Show Priority" org-agenda-show-priority t])
  1112. ("Calendar/Diary"
  1113. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1114. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1115. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1116. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1117. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1118. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1119. "--"
  1120. ["Create iCalendar file" org-export-icalendar-combine-agenda-files t])
  1121. "--"
  1122. ("View"
  1123. ["Day View" org-agenda-day-view :active (org-agenda-check-type nil 'agenda)
  1124. :style radio :selected (equal org-agenda-ndays 1)]
  1125. ["Week View" org-agenda-week-view :active (org-agenda-check-type nil 'agenda)
  1126. :style radio :selected (equal org-agenda-ndays 7)]
  1127. ["Month View" org-agenda-month-view :active (org-agenda-check-type nil 'agenda)
  1128. :style radio :selected (member org-agenda-ndays '(28 29 30 31))]
  1129. ["Year View" org-agenda-year-view :active (org-agenda-check-type nil 'agenda)
  1130. :style radio :selected (member org-agenda-ndays '(365 366))]
  1131. "--"
  1132. ["Include Diary" org-agenda-toggle-diary
  1133. :style toggle :selected org-agenda-include-diary
  1134. :active (org-agenda-check-type nil 'agenda)]
  1135. ["Use Time Grid" org-agenda-toggle-time-grid
  1136. :style toggle :selected org-agenda-use-time-grid
  1137. :active (org-agenda-check-type nil 'agenda)]
  1138. "--"
  1139. ["Show clock report" org-agenda-clockreport-mode
  1140. :style toggle :selected org-agenda-clockreport-mode
  1141. :active (org-agenda-check-type nil 'agenda)]
  1142. "--"
  1143. ["Show Logbook entries" org-agenda-log-mode
  1144. :style toggle :selected org-agenda-show-log
  1145. :active (org-agenda-check-type nil 'agenda 'timeline)]
  1146. ["Include archived trees" org-agenda-archives-mode
  1147. :style toggle :selected org-agenda-archives-mode :active t]
  1148. ["Include archive files" (org-agenda-archives-mode t)
  1149. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1150. :keys "C-u v"])
  1151. ["Write view to file" org-write-agenda t]
  1152. ["Rebuild buffer" org-agenda-redo t]
  1153. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1154. "--"
  1155. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1156. "--"
  1157. ["Quit" org-agenda-quit t]
  1158. ["Exit and Release Buffers" org-agenda-exit t]
  1159. ))
  1160. ;;; Agenda undo
  1161. (defvar org-agenda-allow-remote-undo t
  1162. "Non-nil means, allow remote undo from the agenda buffer.")
  1163. (defvar org-agenda-undo-list nil
  1164. "List of undoable operations in the agenda since last refresh.")
  1165. (defvar org-agenda-undo-has-started-in nil
  1166. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1167. (defvar org-agenda-pending-undo-list nil
  1168. "In a series of undo commands, this is the list of remaning undo items.")
  1169. (defun org-agenda-undo ()
  1170. "Undo a remote editing step in the agenda.
  1171. This undoes changes both in the agenda buffer and in the remote buffer
  1172. that have been changed along."
  1173. (interactive)
  1174. (or org-agenda-allow-remote-undo
  1175. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
  1176. (if (not (eq this-command last-command))
  1177. (setq org-agenda-undo-has-started-in nil
  1178. org-agenda-pending-undo-list org-agenda-undo-list))
  1179. (if (not org-agenda-pending-undo-list)
  1180. (error "No further undo information"))
  1181. (let* ((entry (pop org-agenda-pending-undo-list))
  1182. buf line cmd rembuf)
  1183. (setq cmd (pop entry) line (pop entry))
  1184. (setq rembuf (nth 2 entry))
  1185. (org-with-remote-undo rembuf
  1186. (while (bufferp (setq buf (pop entry)))
  1187. (if (pop entry)
  1188. (with-current-buffer buf
  1189. (let ((last-undo-buffer buf)
  1190. (inhibit-read-only t))
  1191. (unless (memq buf org-agenda-undo-has-started-in)
  1192. (push buf org-agenda-undo-has-started-in)
  1193. (make-local-variable 'pending-undo-list)
  1194. (undo-start))
  1195. (while (and pending-undo-list
  1196. (listp pending-undo-list)
  1197. (not (car pending-undo-list)))
  1198. (pop pending-undo-list))
  1199. (undo-more 1))))))
  1200. (goto-line line)
  1201. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1202. (defun org-verify-change-for-undo (l1 l2)
  1203. "Verify that a real change occurred between the undo lists L1 and L2."
  1204. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1205. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1206. (not (eq l1 l2)))
  1207. ;;; Agenda dispatch
  1208. (defvar org-agenda-restrict nil)
  1209. (defvar org-agenda-restrict-begin (make-marker))
  1210. (defvar org-agenda-restrict-end (make-marker))
  1211. (defvar org-agenda-last-dispatch-buffer nil)
  1212. (defvar org-agenda-overriding-restriction nil)
  1213. ;;;###autoload
  1214. (defun org-agenda (arg &optional keys restriction)
  1215. "Dispatch agenda commands to collect entries to the agenda buffer.
  1216. Prompts for a command to execute. Any prefix arg will be passed
  1217. on to the selected command. The default selections are:
  1218. a Call `org-agenda-list' to display the agenda for current day or week.
  1219. t Call `org-todo-list' to display the global todo list.
  1220. T Call `org-todo-list' to display the global todo list, select only
  1221. entries with a specific TODO keyword (the user gets a prompt).
  1222. m Call `org-tags-view' to display headlines with tags matching
  1223. a condition (the user is prompted for the condition).
  1224. M Like `m', but select only TODO entries, no ordinary headlines.
  1225. L Create a timeline for the current buffer.
  1226. e Export views to associated files.
  1227. More commands can be added by configuring the variable
  1228. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1229. searches can be pre-defined in this way.
  1230. If the current buffer is in Org-mode and visiting a file, you can also
  1231. first press `<' once to indicate that the agenda should be temporarily
  1232. \(until the next use of \\[org-agenda]) restricted to the current file.
  1233. Pressing `<' twice means to restrict to the current subtree or region
  1234. \(if active)."
  1235. (interactive "P")
  1236. (catch 'exit
  1237. (let* ((prefix-descriptions nil)
  1238. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1239. (org-agenda-custom-commands
  1240. ;; normalize different versions
  1241. (delq nil
  1242. (mapcar
  1243. (lambda (x)
  1244. (cond ((stringp (cdr x))
  1245. (push x prefix-descriptions)
  1246. nil)
  1247. ((stringp (nth 1 x)) x)
  1248. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1249. (t (cons (car x) (cons "" (cdr x))))))
  1250. org-agenda-custom-commands)))
  1251. (buf (current-buffer))
  1252. (bfn (buffer-file-name (buffer-base-buffer)))
  1253. entry key type match lprops ans)
  1254. ;; Turn off restriction unless there is an overriding one
  1255. (unless org-agenda-overriding-restriction
  1256. (put 'org-agenda-files 'org-restrict nil)
  1257. (setq org-agenda-restrict nil)
  1258. (move-marker org-agenda-restrict-begin nil)
  1259. (move-marker org-agenda-restrict-end nil))
  1260. ;; Delete old local properties
  1261. (put 'org-agenda-redo-command 'org-lprops nil)
  1262. ;; Remember where this call originated
  1263. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1264. (unless keys
  1265. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1266. keys (car ans)
  1267. restriction (cdr ans)))
  1268. ;; Estabish the restriction, if any
  1269. (when (and (not org-agenda-overriding-restriction) restriction)
  1270. (put 'org-agenda-files 'org-restrict (list bfn))
  1271. (cond
  1272. ((eq restriction 'region)
  1273. (setq org-agenda-restrict t)
  1274. (move-marker org-agenda-restrict-begin (region-beginning))
  1275. (move-marker org-agenda-restrict-end (region-end)))
  1276. ((eq restriction 'subtree)
  1277. (save-excursion
  1278. (setq org-agenda-restrict t)
  1279. (org-back-to-heading t)
  1280. (move-marker org-agenda-restrict-begin (point))
  1281. (move-marker org-agenda-restrict-end
  1282. (progn (org-end-of-subtree t)))))))
  1283. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1284. ;; For example the todo list should not need it (but does...)
  1285. (cond
  1286. ((setq entry (assoc keys org-agenda-custom-commands))
  1287. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1288. (progn
  1289. (setq type (nth 2 entry) match (nth 3 entry) lprops (nth 4 entry))
  1290. (put 'org-agenda-redo-command 'org-lprops lprops)
  1291. (cond
  1292. ((eq type 'agenda)
  1293. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1294. ((eq type 'alltodo)
  1295. (org-let lprops '(org-todo-list current-prefix-arg)))
  1296. ((eq type 'search)
  1297. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1298. ((eq type 'stuck)
  1299. (org-let lprops '(org-agenda-list-stuck-projects
  1300. current-prefix-arg)))
  1301. ((eq type 'tags)
  1302. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1303. ((eq type 'tags-todo)
  1304. (org-let lprops '(org-tags-view '(4) match)))
  1305. ((eq type 'todo)
  1306. (org-let lprops '(org-todo-list match)))
  1307. ((eq type 'tags-tree)
  1308. (org-check-for-org-mode)
  1309. (org-let lprops '(org-tags-sparse-tree current-prefix-arg match)))
  1310. ((eq type 'todo-tree)
  1311. (org-check-for-org-mode)
  1312. (org-let lprops
  1313. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1314. (regexp-quote match) "\\>"))))
  1315. ((eq type 'occur-tree)
  1316. (org-check-for-org-mode)
  1317. (org-let lprops '(org-occur match)))
  1318. ((functionp type)
  1319. (org-let lprops '(funcall type match)))
  1320. ((fboundp type)
  1321. (org-let lprops '(funcall type match)))
  1322. (t (error "Invalid custom agenda command type %s" type))))
  1323. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1324. ((equal keys "C")
  1325. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1326. (customize-variable 'org-agenda-custom-commands))
  1327. ((equal keys "a") (call-interactively 'org-agenda-list))
  1328. ((equal keys "s") (call-interactively 'org-search-view))
  1329. ((equal keys "t") (call-interactively 'org-todo-list))
  1330. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1331. ((equal keys "m") (call-interactively 'org-tags-view))
  1332. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1333. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1334. ((equal keys "L")
  1335. (unless (org-mode-p)
  1336. (error "This is not an Org-mode file"))
  1337. (unless restriction
  1338. (put 'org-agenda-files 'org-restrict (list bfn))
  1339. (org-call-with-arg 'org-timeline arg)))
  1340. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1341. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1342. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1343. (t (error "Invalid agenda key"))))))
  1344. (defun org-agenda-normalize-custom-commands (cmds)
  1345. (delq nil
  1346. (mapcar
  1347. (lambda (x)
  1348. (cond ((stringp (cdr x)) nil)
  1349. ((stringp (nth 1 x)) x)
  1350. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1351. (t (cons (car x) (cons "" (cdr x))))))
  1352. cmds)))
  1353. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1354. "The user interface for selecting an agenda command."
  1355. (catch 'exit
  1356. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1357. (restrict-ok (and bfn (org-mode-p)))
  1358. (region-p (org-region-active-p))
  1359. (custom org-agenda-custom-commands)
  1360. (selstring "")
  1361. restriction second-time
  1362. c entry key type match prefixes rmheader header-end custom1 desc)
  1363. (save-window-excursion
  1364. (delete-other-windows)
  1365. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1366. (erase-buffer)
  1367. (insert (eval-when-compile
  1368. (let ((header
  1369. "
  1370. Press key for an agenda command: < Buffer, subtree/region restriction
  1371. -------------------------------- > Remove restriction
  1372. a Agenda for current week or day e Export agenda views
  1373. t List of all TODO entries T Entries with special TODO kwd
  1374. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1375. L Timeline for current buffer # List stuck projects (!=configure)
  1376. s Search for keywords C Configure custom agenda commands
  1377. / Multi-occur
  1378. ")
  1379. (start 0))
  1380. (while (string-match
  1381. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1382. header start)
  1383. (setq start (match-end 0))
  1384. (add-text-properties (match-beginning 2) (match-end 2)
  1385. '(face bold) header))
  1386. header)))
  1387. (setq header-end (move-marker (make-marker) (point)))
  1388. (while t
  1389. (setq custom1 custom)
  1390. (when (eq rmheader t)
  1391. (goto-line 1)
  1392. (re-search-forward ":" nil t)
  1393. (delete-region (match-end 0) (point-at-eol))
  1394. (forward-char 1)
  1395. (looking-at "-+")
  1396. (delete-region (match-end 0) (point-at-eol))
  1397. (move-marker header-end (match-end 0)))
  1398. (goto-char header-end)
  1399. (delete-region (point) (point-max))
  1400. (while (setq entry (pop custom1))
  1401. (setq key (car entry) desc (nth 1 entry)
  1402. type (nth 2 entry) match (nth 3 entry))
  1403. (if (> (length key) 1)
  1404. (add-to-list 'prefixes (string-to-char key))
  1405. (insert
  1406. (format
  1407. "\n%-4s%-14s: %s"
  1408. (org-add-props (copy-sequence key)
  1409. '(face bold))
  1410. (cond
  1411. ((string-match "\\S-" desc) desc)
  1412. ((eq type 'agenda) "Agenda for current week or day")
  1413. ((eq type 'alltodo) "List of all TODO entries")
  1414. ((eq type 'search) "Word search")
  1415. ((eq type 'stuck) "List of stuck projects")
  1416. ((eq type 'todo) "TODO keyword")
  1417. ((eq type 'tags) "Tags query")
  1418. ((eq type 'tags-todo) "Tags (TODO)")
  1419. ((eq type 'tags-tree) "Tags tree")
  1420. ((eq type 'todo-tree) "TODO kwd tree")
  1421. ((eq type 'occur-tree) "Occur tree")
  1422. ((functionp type) (if (symbolp type)
  1423. (symbol-name type)
  1424. "Lambda expression"))
  1425. (t "???"))
  1426. (cond
  1427. ((stringp match)
  1428. (org-add-props match nil 'face 'org-warning))
  1429. (match
  1430. (format "set of %d commands" (length match)))
  1431. (t ""))))))
  1432. (when prefixes
  1433. (mapc (lambda (x)
  1434. (insert
  1435. (format "\n%s %s"
  1436. (org-add-props (char-to-string x)
  1437. nil 'face 'bold)
  1438. (or (cdr (assoc (concat selstring (char-to-string x))
  1439. prefix-descriptions))
  1440. "Prefix key"))))
  1441. prefixes))
  1442. (goto-char (point-min))
  1443. (when (fboundp 'fit-window-to-buffer)
  1444. (if second-time
  1445. (if (not (pos-visible-in-window-p (point-max)))
  1446. (fit-window-to-buffer))
  1447. (setq second-time t)
  1448. (fit-window-to-buffer)))
  1449. (message "Press key for agenda command%s:"
  1450. (if (or restrict-ok org-agenda-overriding-restriction)
  1451. (if org-agenda-overriding-restriction
  1452. " (restriction lock active)"
  1453. (if restriction
  1454. (format " (restricted to %s)" restriction)
  1455. " (unrestricted)"))
  1456. ""))
  1457. (setq c (read-char-exclusive))
  1458. (message "")
  1459. (cond
  1460. ((assoc (char-to-string c) custom)
  1461. (setq selstring (concat selstring (char-to-string c)))
  1462. (throw 'exit (cons selstring restriction)))
  1463. ((memq c prefixes)
  1464. (setq selstring (concat selstring (char-to-string c))
  1465. prefixes nil
  1466. rmheader (or rmheader t)
  1467. custom (delq nil (mapcar
  1468. (lambda (x)
  1469. (if (or (= (length (car x)) 1)
  1470. (/= (string-to-char (car x)) c))
  1471. nil
  1472. (cons (substring (car x) 1) (cdr x))))
  1473. custom))))
  1474. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1475. (message "Restriction is only possible in Org-mode buffers")
  1476. (ding) (sit-for 1))
  1477. ((eq c ?1)
  1478. (org-agenda-remove-restriction-lock 'noupdate)
  1479. (setq restriction 'buffer))
  1480. ((eq c ?0)
  1481. (org-agenda-remove-restriction-lock 'noupdate)
  1482. (setq restriction (if region-p 'region 'subtree)))
  1483. ((eq c ?<)
  1484. (org-agenda-remove-restriction-lock 'noupdate)
  1485. (setq restriction
  1486. (cond
  1487. ((eq restriction 'buffer)
  1488. (if region-p 'region 'subtree))
  1489. ((memq restriction '(subtree region))
  1490. nil)
  1491. (t 'buffer))))
  1492. ((eq c ?>)
  1493. (org-agenda-remove-restriction-lock 'noupdate)
  1494. (setq restriction nil))
  1495. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/)))
  1496. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  1497. ((and (> (length selstring) 0) (eq c ?\d))
  1498. (delete-window)
  1499. (org-agenda-get-restriction-and-command prefix-descriptions))
  1500. ((equal c ?q) (error "Abort"))
  1501. (t (error "Invalid key %c" c))))))))
  1502. (defun org-run-agenda-series (name series)
  1503. (org-prepare-agenda name)
  1504. (let* ((org-agenda-multi t)
  1505. (redo (list 'org-run-agenda-series name (list 'quote series)))
  1506. (cmds (car series))
  1507. (gprops (nth 1 series))
  1508. match ;; The byte compiler incorrectly complains about this. Keep it!
  1509. cmd type lprops)
  1510. (while (setq cmd (pop cmds))
  1511. (setq type (car cmd) match (nth 1 cmd) lprops (nth 2 cmd))
  1512. (cond
  1513. ((eq type 'agenda)
  1514. (org-let2 gprops lprops
  1515. '(call-interactively 'org-agenda-list)))
  1516. ((eq type 'alltodo)
  1517. (org-let2 gprops lprops
  1518. '(call-interactively 'org-todo-list)))
  1519. ((eq type 'search)
  1520. (org-let2 gprops lprops
  1521. '(org-search-view current-prefix-arg match nil)))
  1522. ((eq type 'stuck)
  1523. (org-let2 gprops lprops
  1524. '(call-interactively 'org-agenda-list-stuck-projects)))
  1525. ((eq type 'tags)
  1526. (org-let2 gprops lprops
  1527. '(org-tags-view current-prefix-arg match)))
  1528. ((eq type 'tags-todo)
  1529. (org-let2 gprops lprops
  1530. '(org-tags-view '(4) match)))
  1531. ((eq type 'todo)
  1532. (org-let2 gprops lprops
  1533. '(org-todo-list match)))
  1534. ((fboundp type)
  1535. (org-let2 gprops lprops
  1536. '(funcall type match)))
  1537. (t (error "Invalid type in command series"))))
  1538. (widen)
  1539. (setq org-agenda-redo-command redo)
  1540. (goto-char (point-min)))
  1541. (org-finalize-agenda))
  1542. ;;;###autoload
  1543. (defmacro org-batch-agenda (cmd-key &rest parameters)
  1544. "Run an agenda command in batch mode and send the result to STDOUT.
  1545. If CMD-KEY is a string of length 1, it is used as a key in
  1546. `org-agenda-custom-commands' and triggers this command. If it is a
  1547. longer string it is used as a tags/todo match string.
  1548. Paramters are alternating variable names and values that will be bound
  1549. before running the agenda command."
  1550. (let (pars)
  1551. (while parameters
  1552. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1553. (if (> (length cmd-key) 2)
  1554. (eval (list 'let (nreverse pars)
  1555. (list 'org-tags-view nil cmd-key)))
  1556. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1557. (set-buffer org-agenda-buffer-name)
  1558. (princ (org-encode-for-stdout (buffer-string)))))
  1559. (defun org-encode-for-stdout (string)
  1560. (if (fboundp 'encode-coding-string)
  1561. (encode-coding-string string buffer-file-coding-system)
  1562. string))
  1563. (defvar org-agenda-info nil)
  1564. ;;;###autoload
  1565. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  1566. "Run an agenda command in batch mode and send the result to STDOUT.
  1567. If CMD-KEY is a string of length 1, it is used as a key in
  1568. `org-agenda-custom-commands' and triggers this command. If it is a
  1569. longer string it is used as a tags/todo match string.
  1570. Paramters are alternating variable names and values that will be bound
  1571. before running the agenda command.
  1572. The output gives a line for each selected agenda item. Each
  1573. item is a list of comma-separated values, like this:
  1574. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  1575. category The category of the item
  1576. head The headline, without TODO kwd, TAGS and PRIORITY
  1577. type The type of the agenda entry, can be
  1578. todo selected in TODO match
  1579. tagsmatch selected in tags match
  1580. diary imported from diary
  1581. deadline a deadline on given date
  1582. scheduled scheduled on given date
  1583. timestamp entry has timestamp on given date
  1584. closed entry was closed on given date
  1585. upcoming-deadline warning about deadline
  1586. past-scheduled forwarded scheduled item
  1587. block entry has date block including g. date
  1588. todo The todo keyword, if any
  1589. tags All tags including inherited ones, separated by colons
  1590. date The relevant date, like 2007-2-14
  1591. time The time, like 15:00-16:50
  1592. extra Sting with extra planning info
  1593. priority-l The priority letter if any was given
  1594. priority-n The computed numerical priority
  1595. agenda-day The day in the agenda where this is listed"
  1596. (let (pars)
  1597. (while parameters
  1598. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1599. (push (list 'org-agenda-remove-tags t) pars)
  1600. (if (> (length cmd-key) 2)
  1601. (eval (list 'let (nreverse pars)
  1602. (list 'org-tags-view nil cmd-key)))
  1603. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1604. (set-buffer org-agenda-buffer-name)
  1605. (let* ((lines (org-split-string (buffer-string) "\n"))
  1606. line)
  1607. (while (setq line (pop lines))
  1608. (catch 'next
  1609. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  1610. (setq org-agenda-info
  1611. (org-fix-agenda-info (text-properties-at 0 line)))
  1612. (princ
  1613. (org-encode-for-stdout
  1614. (mapconcat 'org-agenda-export-csv-mapper
  1615. '(org-category txt type todo tags date time-of-day extra
  1616. priority-letter priority agenda-day)
  1617. ",")))
  1618. (princ "\n"))))))
  1619. (defun org-fix-agenda-info (props)
  1620. "Make sure all properties on an agenda item have a canonical form,
  1621. so the export commands can easily use it."
  1622. (let (tmp re)
  1623. (when (setq tmp (plist-get props 'tags))
  1624. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  1625. (when (setq tmp (plist-get props 'date))
  1626. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1627. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1628. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  1629. (setq tmp (calendar-date-string tmp)))
  1630. (setq props (plist-put props 'date tmp)))
  1631. (when (setq tmp (plist-get props 'day))
  1632. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  1633. (let ((calendar-date-display-form '(year "-" month "-" day)))
  1634. (setq tmp (calendar-date-string tmp)))
  1635. (setq props (plist-put props 'day tmp))
  1636. (setq props (plist-put props 'agenda-day tmp)))
  1637. (when (setq tmp (plist-get props 'txt))
  1638. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  1639. (plist-put props 'priority-letter (match-string 1 tmp))
  1640. (setq tmp (replace-match "" t t tmp)))
  1641. (when (and (setq re (plist-get props 'org-todo-regexp))
  1642. (setq re (concat "\\`\\.*" re " ?"))
  1643. (string-match re tmp))
  1644. (plist-put props 'todo (match-string 1 tmp))
  1645. (setq tmp (replace-match "" t t tmp)))
  1646. (plist-put props 'txt tmp)))
  1647. props)
  1648. (defun org-agenda-export-csv-mapper (prop)
  1649. (let ((res (plist-get org-agenda-info prop)))
  1650. (setq res
  1651. (cond
  1652. ((not res) "")
  1653. ((stringp res) res)
  1654. (t (prin1-to-string res))))
  1655. (while (string-match "," res)
  1656. (setq res (replace-match ";" t t res)))
  1657. (org-trim res)))
  1658. ;;;###autoload
  1659. (defun org-store-agenda-views (&rest parameters)
  1660. (interactive)
  1661. (eval (list 'org-batch-store-agenda-views)))
  1662. ;; FIXME, why is this a macro?????
  1663. ;;;###autoload
  1664. (defmacro org-batch-store-agenda-views (&rest parameters)
  1665. "Run all custom agenda commands that have a file argument."
  1666. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  1667. (pop-up-frames nil)
  1668. (dir default-directory)
  1669. pars cmd thiscmdkey files opts cmd-or-set)
  1670. (while parameters
  1671. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1672. (setq pars (reverse pars))
  1673. (save-window-excursion
  1674. (while cmds
  1675. (setq cmd (pop cmds)
  1676. thiscmdkey (car cmd)
  1677. cmd-or-set (nth 2 cmd)
  1678. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  1679. files (nth (if (listp cmd-or-set) 4 5) cmd))
  1680. (if (stringp files) (setq files (list files)))
  1681. (when files
  1682. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  1683. (list 'org-agenda nil thiscmdkey)))
  1684. (set-buffer org-agenda-buffer-name)
  1685. (while files
  1686. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  1687. (list 'org-write-agenda
  1688. (expand-file-name (pop files) dir) t))))
  1689. (and (get-buffer org-agenda-buffer-name)
  1690. (kill-buffer org-agenda-buffer-name)))))))
  1691. (defun org-write-agenda (file &optional nosettings)
  1692. "Write the current buffer (an agenda view) as a file.
  1693. Depending on the extension of the file name, plain text (.txt),
  1694. HTML (.html or .htm) or Postscript (.ps) is produced.
  1695. If the extension is .ics, run icalendar export over all files used
  1696. to construct the agenda and limit the export to entries listed in the
  1697. agenda now.
  1698. If NOSETTINGS is given, do not scope the settings of
  1699. `org-agenda-exporter-settings' into the export commands. This is used when
  1700. the settings have already been scoped and we do not wish to overrule other,
  1701. higher priority settings."
  1702. (interactive "FWrite agenda to file: ")
  1703. (if (not (file-writable-p file))
  1704. (error "Cannot write agenda to file %s" file))
  1705. (cond
  1706. ((string-match "\\.html?\\'" file) (require 'htmlize))
  1707. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  1708. (org-let (if nosettings nil org-agenda-exporter-settings)
  1709. '(save-excursion
  1710. (save-window-excursion
  1711. (cond
  1712. ((string-match "\\.html?\\'" file)
  1713. (set-buffer (htmlize-buffer (current-buffer)))
  1714. (when (and org-agenda-export-html-style
  1715. (string-match "<style>" org-agenda-export-html-style))
  1716. ;; replace <style> section with org-agenda-export-html-style
  1717. (goto-char (point-min))
  1718. (kill-region (- (search-forward "<style") 6)
  1719. (search-forward "</style>"))
  1720. (insert org-agenda-export-html-style))
  1721. (write-file file)
  1722. (kill-buffer (current-buffer))
  1723. (message "HTML written to %s" file))
  1724. ((string-match "\\.ps\\'" file)
  1725. (ps-print-buffer-with-faces file)
  1726. (message "Postscript written to %s" file))
  1727. ((string-match "\\.ics\\'" file)
  1728. (let ((org-agenda-marker-table
  1729. (org-create-marker-find-array
  1730. (org-agenda-collect-markers)))
  1731. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  1732. (org-combined-agenda-icalendar-file file))
  1733. (apply 'org-export-icalendar 'combine
  1734. (org-agenda-files nil 'ifmode))))
  1735. (t
  1736. (let ((bs (buffer-string)))
  1737. (find-file file)
  1738. (erase-buffer)
  1739. (insert bs)
  1740. (save-buffer 0)
  1741. (kill-buffer (current-buffer))
  1742. (message "Plain text written to %s" file))))))
  1743. (set-buffer org-agenda-buffer-name)))
  1744. (defun org-agenda-collect-markers ()
  1745. "Collect the markers pointing to entries in the agenda buffer."
  1746. (let (m markers)
  1747. (save-excursion
  1748. (goto-char (point-min))
  1749. (while (not (eobp))
  1750. (when (setq m (or (get-text-property (point) 'org-hd-marker)
  1751. (get-text-property (point) 'org-marker)))
  1752. (push m markers))
  1753. (beginning-of-line 2)))
  1754. (nreverse markers)))
  1755. (defun org-create-marker-find-array (marker-list)
  1756. "Create a alist of files names with all marker positions in that file."
  1757. (let (f tbl m a p)
  1758. (while (setq m (pop marker-list))
  1759. (setq p (marker-position m)
  1760. f (buffer-file-name (or (buffer-base-buffer
  1761. (marker-buffer m))
  1762. (marker-buffer m))))
  1763. (if (setq a (assoc f tbl))
  1764. (push (marker-position m) (cdr a))
  1765. (push (list f p) tbl)))
  1766. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  1767. tbl)))
  1768. (defvar org-agenda-marker-table nil) ; dyamically scoped parameter
  1769. (defun org-check-agenda-marker-table ()
  1770. "Check of the current entry is on the marker list."
  1771. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  1772. a)
  1773. (and (setq a (assoc file org-agenda-marker-table))
  1774. (save-match-data
  1775. (save-excursion
  1776. (org-back-to-heading t)
  1777. (member (point) (cdr a)))))))
  1778. (defun org-check-for-org-mode ()
  1779. "Make sure current buffer is in org-mode. Error if not."
  1780. (or (org-mode-p)
  1781. (error "Cannot execute org-mode agenda command on buffer in %s."
  1782. major-mode)))
  1783. (defun org-fit-agenda-window ()
  1784. "Fit the window to the buffer size."
  1785. (and (memq org-agenda-window-setup '(reorganize-frame))
  1786. (fboundp 'fit-window-to-buffer)
  1787. (fit-window-to-buffer
  1788. nil
  1789. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  1790. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  1791. ;;; Agenda prepare and finalize
  1792. (defvar org-agenda-multi nil) ; dynammically scoped
  1793. (defvar org-agenda-buffer-name "*Org Agenda*")
  1794. (defvar org-pre-agenda-window-conf nil)
  1795. (defvar org-agenda-columns-active nil)
  1796. (defvar org-agenda-name nil)
  1797. (defvar org-agenda-filter nil)
  1798. (defun org-prepare-agenda (&optional name)
  1799. (setq org-todo-keywords-for-agenda nil)
  1800. (setq org-done-keywords-for-agenda nil)
  1801. (setq org-agenda-filter nil)
  1802. (if org-agenda-multi
  1803. (progn
  1804. (setq buffer-read-only nil)
  1805. (goto-char (point-max))
  1806. (unless (or (bobp) org-agenda-compact-blocks)
  1807. (insert "\n" (make-string (window-width) ?=) "\n"))
  1808. (narrow-to-region (point) (point-max)))
  1809. (org-agenda-reset-markers)
  1810. (setq org-agenda-contributing-files nil)
  1811. (setq org-agenda-columns-active nil)
  1812. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  1813. (setq org-todo-keywords-for-agenda
  1814. (org-uniquify org-todo-keywords-for-agenda))
  1815. (setq org-done-keywords-for-agenda
  1816. (org-uniquify org-done-keywords-for-agenda))
  1817. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  1818. (awin (get-buffer-window abuf)))
  1819. (cond
  1820. ((equal (current-buffer) abuf) nil)
  1821. (awin (select-window awin))
  1822. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  1823. ((equal org-agenda-window-setup 'current-window)
  1824. (switch-to-buffer abuf))
  1825. ((equal org-agenda-window-setup 'other-window)
  1826. (org-switch-to-buffer-other-window abuf))
  1827. ((equal org-agenda-window-setup 'other-frame)
  1828. (switch-to-buffer-other-frame abuf))
  1829. ((equal org-agenda-window-setup 'reorganize-frame)
  1830. (delete-other-windows)
  1831. (org-switch-to-buffer-other-window abuf))))
  1832. (setq buffer-read-only nil)
  1833. (let ((inhibit-read-only t)) (erase-buffer))
  1834. (org-agenda-mode)
  1835. (and name (not org-agenda-name)
  1836. (org-set-local 'org-agenda-name name)))
  1837. (setq buffer-read-only nil))
  1838. (defun org-finalize-agenda ()
  1839. "Finishing touch for the agenda buffer, called just before displaying it."
  1840. (unless org-agenda-multi
  1841. (save-excursion
  1842. (let ((inhibit-read-only t))
  1843. (goto-char (point-min))
  1844. (while (org-activate-bracket-links (point-max))
  1845. (add-text-properties (match-beginning 0) (match-end 0)
  1846. '(face org-link)))
  1847. (org-agenda-align-tags)
  1848. (unless org-agenda-with-colors
  1849. (remove-text-properties (point-min) (point-max) '(face nil))))
  1850. (if (and (boundp 'org-overriding-columns-format)
  1851. org-overriding-columns-format)
  1852. (org-set-local 'org-overriding-columns-format
  1853. org-overriding-columns-format))
  1854. (if (and (boundp 'org-agenda-view-columns-initially)
  1855. org-agenda-view-columns-initially)
  1856. (org-agenda-columns))
  1857. (when org-agenda-fontify-priorities
  1858. (org-fontify-priorities))
  1859. (run-hooks 'org-finalize-agenda-hook)
  1860. (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
  1861. )))
  1862. (defun org-fontify-priorities ()
  1863. "Make highest priority lines bold, and lowest italic."
  1864. (interactive)
  1865. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  1866. (org-delete-overlay o)))
  1867. (org-overlays-in (point-min) (point-max)))
  1868. (save-excursion
  1869. (let ((inhibit-read-only t)
  1870. b e p ov h l)
  1871. (goto-char (point-min))
  1872. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  1873. (setq h (or (get-char-property (point) 'org-highest-priority)
  1874. org-highest-priority)
  1875. l (or (get-char-property (point) 'org-lowest-priority)
  1876. org-lowest-priority)
  1877. p (string-to-char (match-string 1))
  1878. b (match-beginning 0) e (point-at-eol)
  1879. ov (org-make-overlay b e))
  1880. (org-overlay-put
  1881. ov 'face
  1882. (cond ((listp org-agenda-fontify-priorities)
  1883. (cdr (assoc p org-agenda-fontify-priorities)))
  1884. ((equal p l) 'italic)
  1885. ((equal p h) 'bold)))
  1886. (org-overlay-put ov 'org-type 'org-priority)))))
  1887. (defvar org-agenda-skip-function nil
  1888. "Function to be called at each match during agenda construction.
  1889. If this function returns nil, the current match should not be skipped.
  1890. Otherwise, the function must return a position from where the search
  1891. should be continued.
  1892. This may also be a Lisp form, it will be evaluated.
  1893. Never set this variable using `setq' or so, because then it will apply
  1894. to all future agenda commands. Instead, bind it with `let' to scope
  1895. it dynamically into the agenda-constructing command. A good way to set
  1896. it is through options in org-agenda-custom-commands.")
  1897. (defun org-agenda-skip ()
  1898. "Throw to `:skip' in places that should be skipped.
  1899. Also moves point to the end of the skipped region, so that search can
  1900. continue from there."
  1901. (let ((p (point-at-bol)) to fp)
  1902. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  1903. (get-text-property p :org-archived)
  1904. (org-end-of-subtree t)
  1905. (throw :skip t))
  1906. (and org-agenda-skip-comment-trees
  1907. (get-text-property p :org-comment)
  1908. (org-end-of-subtree t)
  1909. (throw :skip t))
  1910. (if (equal (char-after p) ?#) (throw :skip t))
  1911. (when (and (or (setq fp (functionp org-agenda-skip-function))
  1912. (consp org-agenda-skip-function))
  1913. (setq to (save-excursion
  1914. (save-match-data
  1915. (if fp
  1916. (funcall org-agenda-skip-function)
  1917. (eval org-agenda-skip-function))))))
  1918. (goto-char to)
  1919. (throw :skip t))))
  1920. (defvar org-agenda-markers nil
  1921. "List of all currently active markers created by `org-agenda'.")
  1922. (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
  1923. "Creation time of the last agenda marker.")
  1924. (defun org-agenda-new-marker (&optional pos)
  1925. "Return a new agenda marker.
  1926. Org-mode keeps a list of these markers and resets them when they are
  1927. no longer in use."
  1928. (let ((m (copy-marker (or pos (point)))))
  1929. (setq org-agenda-last-marker-time (time-to-seconds (current-time)))
  1930. (push m org-agenda-markers)
  1931. m))
  1932. (defun org-agenda-reset-markers ()
  1933. "Reset markers created by `org-agenda'."
  1934. (while org-agenda-markers
  1935. (move-marker (pop org-agenda-markers) nil)))
  1936. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  1937. "Save relative positions of markers in region."
  1938. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  1939. org-agenda-markers))
  1940. ;;; Agenda timeline
  1941. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  1942. (defun org-timeline (&optional include-all)
  1943. "Show a time-sorted view of the entries in the current org file.
  1944. Only entries with a time stamp of today or later will be listed. With
  1945. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  1946. under the current date.
  1947. If the buffer contains an active region, only check the region for
  1948. dates."
  1949. (interactive "P")
  1950. (require 'calendar)
  1951. (org-compile-prefix-format 'timeline)
  1952. (org-set-sorting-strategy 'timeline)
  1953. (let* ((dopast t)
  1954. (dotodo include-all)
  1955. (doclosed org-agenda-show-log)
  1956. (entry buffer-file-name)
  1957. (date (calendar-current-date))
  1958. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  1959. (end (if (org-region-active-p) (region-end) (point-max)))
  1960. (day-numbers (org-get-all-dates beg end 'no-ranges
  1961. t doclosed ; always include today
  1962. org-timeline-show-empty-dates))
  1963. (org-deadline-warning-days 0)
  1964. (org-agenda-only-exact-dates t)
  1965. (today (time-to-days (current-time)))
  1966. (past t)
  1967. args
  1968. s e rtn d emptyp wd)
  1969. (setq org-agenda-redo-command
  1970. (list 'progn
  1971. (list 'org-switch-to-buffer-other-window (current-buffer))
  1972. (list 'org-timeline (list 'quote include-all))))
  1973. (if (not dopast)
  1974. ;; Remove past dates from the list of dates.
  1975. (setq day-numbers (delq nil (mapcar (lambda(x)
  1976. (if (>= x today) x nil))
  1977. day-numbers))))
  1978. (org-prepare-agenda (concat "Timeline "
  1979. (file-name-nondirectory buffer-file-name)))
  1980. (if doclosed (push :closed args))
  1981. (push :timestamp args)
  1982. (push :deadline args)
  1983. (push :scheduled args)
  1984. (push :sexp args)
  1985. (if dotodo (push :todo args))
  1986. (while (setq d (pop day-numbers))
  1987. (if (and (listp d) (eq (car d) :omitted))
  1988. (progn
  1989. (setq s (point))
  1990. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  1991. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  1992. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  1993. (if (and (>= d today)
  1994. dopast
  1995. past)
  1996. (progn
  1997. (setq past nil)
  1998. (insert (make-string 79 ?-) "\n")))
  1999. (setq date (calendar-gregorian-from-absolute d)
  2000. wd (calendar-day-of-week date))
  2001. (setq s (point))
  2002. (setq rtn (and (not emptyp)
  2003. (apply 'org-agenda-get-day-entries entry
  2004. date args)))
  2005. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2006. (progn
  2007. (insert
  2008. (if (stringp org-agenda-format-date)
  2009. (format-time-string org-agenda-format-date
  2010. (org-time-from-absolute date))
  2011. (funcall org-agenda-format-date date))
  2012. "\n")
  2013. (put-text-property s (1- (point)) 'face
  2014. (if (member wd org-agenda-weekend-days)
  2015. 'org-agenda-date-weekend
  2016. 'org-agenda-date))
  2017. (put-text-property s (1- (point)) 'org-date-line t)
  2018. (if (equal d today)
  2019. (put-text-property s (1- (point)) 'org-today t))
  2020. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2021. (put-text-property s (1- (point)) 'day d)))))
  2022. (goto-char (point-min))
  2023. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2024. (point-min)))
  2025. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2026. (org-finalize-agenda)
  2027. (setq buffer-read-only t)))
  2028. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2029. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2030. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2031. not every single day in the range. If FORCE-TODAY is non-nil, make
  2032. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2033. inactive time stamps (those in square brackets) are included.
  2034. When EMPTY is non-nil, also include days without any entries."
  2035. (let ((re (concat
  2036. (if pre-re pre-re "")
  2037. (if inactive org-ts-regexp-both org-ts-regexp)))
  2038. dates dates1 date day day1 day2 ts1 ts2)
  2039. (if force-today
  2040. (setq dates (list (time-to-days (current-time)))))
  2041. (save-excursion
  2042. (goto-char beg)
  2043. (while (re-search-forward re end t)
  2044. (setq day (time-to-days (org-time-string-to-time
  2045. (substring (match-string 1) 0 10))))
  2046. (or (memq day dates) (push day dates)))
  2047. (unless no-ranges
  2048. (goto-char beg)
  2049. (while (re-search-forward org-tr-regexp end t)
  2050. (setq ts1 (substring (match-string 1) 0 10)
  2051. ts2 (substring (match-string 2) 0 10)
  2052. day1 (time-to-days (org-time-string-to-time ts1))
  2053. day2 (time-to-days (org-time-string-to-time ts2)))
  2054. (while (< (setq day1 (1+ day1)) day2)
  2055. (or (memq day1 dates) (push day1 dates)))))
  2056. (setq dates (sort dates '<))
  2057. (when empty
  2058. (while (setq day (pop dates))
  2059. (setq day2 (car dates))
  2060. (push day dates1)
  2061. (when (and day2 empty)
  2062. (if (or (eq empty t)
  2063. (and (numberp empty) (<= (- day2 day) empty)))
  2064. (while (< (setq day (1+ day)) day2)
  2065. (push (list day) dates1))
  2066. (push (cons :omitted (- day2 day)) dates1))))
  2067. (setq dates (nreverse dates1)))
  2068. dates)))
  2069. ;;; Agenda Daily/Weekly
  2070. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2071. (defvar org-agenda-start-day nil) ; dynamically scoped parameter
  2072. (defvar org-agenda-last-arguments nil
  2073. "The arguments of the previous call to org-agenda")
  2074. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2075. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2076. (defvar org-include-all-loc nil) ; local variable
  2077. (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
  2078. ;;;###autoload
  2079. (defun org-agenda-list (&optional include-all start-day ndays)
  2080. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2081. The view will be for the current day or week, but from the overview buffer
  2082. you will be able to go to other days/weeks.
  2083. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2084. all unfinished TODO items will also be shown, before the agenda.
  2085. This feature is considered obsolete, please use the TODO list or a block
  2086. agenda instead.
  2087. With a numeric prefix argument in an interactive call, the agenda will
  2088. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2089. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2090. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2091. given in `org-agenda-start-on-weekday'."
  2092. (interactive "P")
  2093. (if (and (integerp include-all) (> include-all 0))
  2094. (setq ndays include-all include-all nil))
  2095. (setq ndays (or ndays org-agenda-ndays)
  2096. start-day (or start-day org-agenda-start-day))
  2097. (if org-agenda-overriding-arguments
  2098. (setq include-all (car org-agenda-overriding-arguments)
  2099. start-day (nth 1 org-agenda-overriding-arguments)
  2100. ndays (nth 2 org-agenda-overriding-arguments)))
  2101. (if (stringp start-day)
  2102. ;; Convert to an absolute day number
  2103. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2104. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2105. (org-compile-prefix-format 'agenda)
  2106. (org-set-sorting-strategy 'agenda)
  2107. (require 'calendar)
  2108. (let* ((org-agenda-start-on-weekday
  2109. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2110. org-agenda-start-on-weekday nil))
  2111. (thefiles (org-agenda-files nil 'ifmode))
  2112. (files thefiles)
  2113. (today (time-to-days
  2114. (time-subtract (current-time)
  2115. (list 0 (* 3600 org-extend-today-until) 0))))
  2116. (sd (or start-day today))
  2117. (start (if (or (null org-agenda-start-on-weekday)
  2118. (< org-agenda-ndays 7))
  2119. sd
  2120. (let* ((nt (calendar-day-of-week
  2121. (calendar-gregorian-from-absolute sd)))
  2122. (n1 org-agenda-start-on-weekday)
  2123. (d (- nt n1)))
  2124. (- sd (+ (if (< d 0) 7 0) d)))))
  2125. (day-numbers (list start))
  2126. (day-cnt 0)
  2127. (inhibit-redisplay (not debug-on-error))
  2128. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2129. clocktable-start clocktable-end)
  2130. (setq org-agenda-redo-command
  2131. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2132. ;; Make the list of days
  2133. (setq ndays (or ndays org-agenda-ndays)
  2134. nd ndays)
  2135. (while (> ndays 1)
  2136. (push (1+ (car day-numbers)) day-numbers)
  2137. (setq ndays (1- ndays)))
  2138. (setq day-numbers (nreverse day-numbers))
  2139. (setq clocktable-start (car day-numbers)
  2140. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2141. (org-prepare-agenda "Day/Week")
  2142. (org-set-local 'org-starting-day (car day-numbers))
  2143. (org-set-local 'org-include-all-loc include-all)
  2144. (org-set-local 'org-agenda-span
  2145. (org-agenda-ndays-to-span nd))
  2146. (when (and (or include-all org-agenda-include-all-todo)
  2147. (member today day-numbers))
  2148. (setq files thefiles
  2149. rtnall nil)
  2150. (while (setq file (pop files))
  2151. (catch 'nextfile
  2152. (org-check-agenda-file file)
  2153. (setq date (calendar-gregorian-from-absolute today)
  2154. rtn (org-agenda-get-day-entries
  2155. file date :todo))
  2156. (setq rtnall (append rtnall rtn))))
  2157. (when rtnall
  2158. (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
  2159. (add-text-properties (point-min) (1- (point))
  2160. (list 'face 'org-agenda-structure))
  2161. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2162. (unless org-agenda-compact-blocks
  2163. (let* ((d1 (car day-numbers))
  2164. (d2 (org-last day-numbers))
  2165. (w1 (org-days-to-iso-week d1))
  2166. (w2 (org-days-to-iso-week d2)))
  2167. (setq s (point))
  2168. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2169. "-agenda"
  2170. (if (< (- d2 d1) 350)
  2171. (if (= w1 w2)
  2172. (format " (W%02d)" w1)
  2173. (format " (W%02d-W%02d)" w1 w2))
  2174. "")
  2175. ":\n"))
  2176. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  2177. 'org-date-line t)))
  2178. (while (setq d (pop day-numbers))
  2179. (setq date (calendar-gregorian-from-absolute d)
  2180. wd (calendar-day-of-week date)
  2181. s (point))
  2182. (if (or (setq todayp (= d today))
  2183. (and (not start-pos) (= d sd)))
  2184. (setq start-pos (point))
  2185. (if (and start-pos (not end-pos))
  2186. (setq end-pos (point))))
  2187. (setq files thefiles
  2188. rtnall nil)
  2189. (while (setq file (pop files))
  2190. (catch 'nextfile
  2191. (org-check-agenda-file file)
  2192. (if org-agenda-show-log
  2193. (setq rtn (org-agenda-get-day-entries
  2194. file date
  2195. :deadline :scheduled :timestamp :sexp :closed))
  2196. (setq rtn (org-agenda-get-day-entries
  2197. file date
  2198. :deadline :scheduled :sexp :timestamp)))
  2199. (setq rtnall (append rtnall rtn))))
  2200. (if org-agenda-include-diary
  2201. (progn
  2202. (require 'diary-lib)
  2203. (setq rtn (org-get-entries-from-diary date))
  2204. (setq rtnall (append rtnall rtn))))
  2205. (if (or rtnall org-agenda-show-all-dates)
  2206. (progn
  2207. (setq day-cnt (1+ day-cnt))
  2208. (insert
  2209. (if (stringp org-agenda-format-date)
  2210. (format-time-string org-agenda-format-date
  2211. (org-time-from-absolute date))
  2212. (funcall org-agenda-format-date date))
  2213. "\n")
  2214. (put-text-property s (1- (point)) 'face
  2215. (if (member wd org-agenda-weekend-days)
  2216. 'org-agenda-date-weekend
  2217. 'org-agenda-date))
  2218. (put-text-property s (1- (point)) 'org-date-line t)
  2219. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  2220. (if todayp (put-text-property s (1- (point)) 'org-today t))
  2221. (if rtnall (insert
  2222. (org-finalize-agenda-entries
  2223. (org-agenda-add-time-grid-maybe
  2224. rtnall nd todayp))
  2225. "\n"))
  2226. (put-text-property s (1- (point)) 'day d)
  2227. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  2228. (when (and org-agenda-clockreport-mode clocktable-start)
  2229. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  2230. ;; the above line is to ensure the restricted range!
  2231. (p org-agenda-clockreport-parameter-plist)
  2232. tbl)
  2233. (setq p (org-plist-delete p :block))
  2234. (setq p (plist-put p :tstart clocktable-start))
  2235. (setq p (plist-put p :tend clocktable-end))
  2236. (setq p (plist-put p :scope 'agenda))
  2237. (setq tbl (apply 'org-get-clocktable p))
  2238. (insert tbl)))
  2239. (goto-char (point-min))
  2240. (org-fit-agenda-window)
  2241. (unless (and (pos-visible-in-window-p (point-min))
  2242. (pos-visible-in-window-p (point-max)))
  2243. (goto-char (1- (point-max)))
  2244. (recenter -1)
  2245. (if (not (pos-visible-in-window-p (or start-pos 1)))
  2246. (progn
  2247. (goto-char (or start-pos 1))
  2248. (recenter 1))))
  2249. (goto-char (or start-pos 1))
  2250. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  2251. (org-finalize-agenda)
  2252. (setq buffer-read-only t)
  2253. (message "")))
  2254. (defun org-agenda-ndays-to-span (n)
  2255. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  2256. ;;; Agenda word search
  2257. (defvar org-agenda-search-history nil)
  2258. (defvar org-todo-only nil)
  2259. (defvar org-search-syntax-table nil
  2260. "Special syntax table for org-mode search.
  2261. In this table, we have single quotes not as word constituents, to
  2262. that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
  2263. (defun org-search-syntax-table ()
  2264. (unless org-search-syntax-table
  2265. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  2266. (modify-syntax-entry ?' "." org-search-syntax-table)
  2267. (modify-syntax-entry ?` "." org-search-syntax-table))
  2268. org-search-syntax-table)
  2269. ;;;###autoload
  2270. (defun org-search-view (&optional todo-only string edit-at)
  2271. "Show all entries that contain words or regular expressions.
  2272. If the first character of the search string is an asterisks,
  2273. search only the headlines.
  2274. With optional prefix argument TODO-ONLY, only consider entries that are
  2275. TODO entries. The argument STRING can be used to pass a default search
  2276. string into this function. If EDIT-AT is non-nil, it means that the
  2277. user should get a chance to edit this string, with cursor at position
  2278. EDIT-AT.
  2279. The search string is broken into \"words\" by splitting at whitespace.
  2280. The individual words are then interpreted as a boolean expression with
  2281. logical AND. Words prefixed with a minus must not occur in the entry.
  2282. Words without a prefix or prefixed with a plus must occur in the entry.
  2283. Matching is case-insensitive and the words are enclosed by word delimiters.
  2284. Words enclosed by curly braces are interpreted as regular expressions
  2285. that must or must not match in the entry.
  2286. If the search string starts with an asterisk, search only in headlines.
  2287. If (possibly after the leading star) the search string starts with an
  2288. exclamation mark, this also means to look at TODO entries only, an effect
  2289. that can also be achieved with a prefix argument.
  2290. This command searches the agenda files, and in addition the files listed
  2291. in `org-agenda-text-search-extra-files'."
  2292. (interactive "P")
  2293. (org-compile-prefix-format 'search)
  2294. (org-set-sorting-strategy 'search)
  2295. (org-prepare-agenda "SEARCH")
  2296. (let* ((props (list 'face nil
  2297. 'done-face 'org-done
  2298. 'org-not-done-regexp org-not-done-regexp
  2299. 'org-todo-regexp org-todo-regexp
  2300. 'org-complex-heading-regexp org-complex-heading-regexp
  2301. 'mouse-face 'highlight
  2302. 'keymap org-agenda-keymap
  2303. 'help-echo (format "mouse-2 or RET jump to location")))
  2304. regexp rtn rtnall files file pos
  2305. marker priority category tags c neg re
  2306. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  2307. (unless (and (not edit-at)
  2308. (stringp string)
  2309. (string-match "\\S-" string))
  2310. (setq string (read-string "[+-]Word/{Regexp} ...: "
  2311. (cond
  2312. ((integerp edit-at) (cons string edit-at))
  2313. (edit-at string))
  2314. 'org-agenda-search-history)))
  2315. (org-set-local 'org-todo-only todo-only)
  2316. (setq org-agenda-redo-command
  2317. (list 'org-search-view (if todo-only t nil) string
  2318. '(if current-prefix-arg 1 nil)))
  2319. (setq org-agenda-query-string string)
  2320. (if (equal (string-to-char string) ?*)
  2321. (setq hdl-only t
  2322. words (substring string 1))
  2323. (setq words string))
  2324. (when (equal (string-to-char words) ?!)
  2325. (setq todo-only t
  2326. words (substring words 1)))
  2327. (setq words (org-split-string words))
  2328. (mapc (lambda (w)
  2329. (setq c (string-to-char w))
  2330. (if (equal c ?-)
  2331. (setq neg t w (substring w 1))
  2332. (if (equal c ?+)
  2333. (setq neg nil w (substring w 1))
  2334. (setq neg nil)))
  2335. (if (string-match "\\`{.*}\\'" w)
  2336. (setq re (substring w 1 -1))
  2337. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
  2338. (if neg (push re regexps-) (push re regexps+)))
  2339. words)
  2340. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  2341. (if (not regexps+)
  2342. (setq regexp (concat "^" org-outline-regexp))
  2343. (setq regexp (pop regexps+))
  2344. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  2345. regexp))))
  2346. (setq files (org-agenda-files nil 'ifmode))
  2347. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  2348. (pop org-agenda-text-search-extra-files)
  2349. (setq files (org-add-archive-files files)))
  2350. (setq files (append files org-agenda-text-search-extra-files)
  2351. rtnall nil)
  2352. (while (setq file (pop files))
  2353. (setq ee nil)
  2354. (catch 'nextfile
  2355. (org-check-agenda-file file)
  2356. (setq buffer (if (file-exists-p file)
  2357. (org-get-agenda-file-buffer file)
  2358. (error "No such file %s" file)))
  2359. (if (not buffer)
  2360. ;; If file does not exist, make sure an error message is sent
  2361. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  2362. file))))
  2363. (with-current-buffer buffer
  2364. (with-syntax-table (org-search-syntax-table)
  2365. (unless (org-mode-p)
  2366. (error "Agenda file %s is not in `org-mode'" file))
  2367. (let ((case-fold-search t))
  2368. (save-excursion
  2369. (save-restriction
  2370. (if org-agenda-restrict
  2371. (narrow-to-region org-agenda-restrict-begin
  2372. org-agenda-restrict-end)
  2373. (widen))
  2374. (goto-char (point-min))
  2375. (unless (or (org-on-heading-p)
  2376. (outline-next-heading))
  2377. (throw 'nextfile t))
  2378. (goto-char (max (point-min) (1- (point))))
  2379. (while (re-search-forward regexp nil t)
  2380. (org-back-to-heading t)
  2381. (skip-chars-forward "* ")
  2382. (setq beg (point-at-bol)
  2383. beg1 (point)
  2384. end (progn (outline-next-heading) (point)))
  2385. (catch :skip
  2386. (goto-char beg)
  2387. (org-agenda-skip)
  2388. (setq str (buffer-substring-no-properties
  2389. (point-at-bol)
  2390. (if hdl-only (point-at-eol) end)))
  2391. (mapc (lambda (wr) (when (string-match wr str)
  2392. (goto-char (1- end))
  2393. (throw :skip t)))
  2394. regexps-)
  2395. (mapc (lambda (wr) (unless (string-match wr str)
  2396. (goto-char (1- end))
  2397. (throw :skip t)))
  2398. (if todo-only
  2399. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  2400. regexps+)
  2401. regexps+))
  2402. (goto-char beg)
  2403. (setq marker (org-agenda-new-marker (point))
  2404. category (org-get-category)
  2405. tags (org-get-tags-at (point))
  2406. txt (org-format-agenda-item
  2407. ""
  2408. (buffer-substring-no-properties
  2409. beg1 (point-at-eol))
  2410. category tags))
  2411. (org-add-props txt props
  2412. 'org-marker marker 'org-hd-marker marker
  2413. 'org-todo-regexp org-todo-regexp
  2414. 'org-complex-heading-regexp org-complex-heading-regexp
  2415. 'priority 1000 'org-category category
  2416. 'type "search")
  2417. (push txt ee)
  2418. (goto-char (1- end))))))))))
  2419. (setq rtn (nreverse ee))
  2420. (setq rtnall (append rtnall rtn)))
  2421. (if org-agenda-overriding-header
  2422. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2423. nil 'face 'org-agenda-structure) "\n")
  2424. (insert "Search words: ")
  2425. (add-text-properties (point-min) (1- (point))
  2426. (list 'face 'org-agenda-structure))
  2427. (setq pos (point))
  2428. (insert string "\n")
  2429. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2430. (setq pos (point))
  2431. (unless org-agenda-multi
  2432. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  2433. (add-text-properties pos (1- (point))
  2434. (list 'face 'org-agenda-structure))))
  2435. (when rtnall
  2436. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2437. (goto-char (point-min))
  2438. (org-fit-agenda-window)
  2439. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  2440. (org-finalize-agenda)
  2441. (setq buffer-read-only t)))
  2442. ;;; Agenda TODO list
  2443. (defvar org-select-this-todo-keyword nil)
  2444. (defvar org-last-arg nil)
  2445. ;;;###autoload
  2446. (defun org-todo-list (arg)
  2447. "Show all TODO entries from all agenda file in a single list.
  2448. The prefix arg can be used to select a specific TODO keyword and limit
  2449. the list to these. When using \\[universal-argument], you will be prompted
  2450. for a keyword. A numeric prefix directly selects the Nth keyword in
  2451. `org-todo-keywords-1'."
  2452. (interactive "P")
  2453. (require 'calendar)
  2454. (org-compile-prefix-format 'todo)
  2455. (org-set-sorting-strategy 'todo)
  2456. (org-prepare-agenda "TODO")
  2457. (let* ((today (time-to-days (current-time)))
  2458. (date (calendar-gregorian-from-absolute today))
  2459. (kwds org-todo-keywords-for-agenda)
  2460. (completion-ignore-case t)
  2461. (org-select-this-todo-keyword
  2462. (if (stringp arg) arg
  2463. (and arg (integerp arg) (> arg 0)
  2464. (nth (1- arg) kwds))))
  2465. rtn rtnall files file pos)
  2466. (when (equal arg '(4))
  2467. (setq org-select-this-todo-keyword
  2468. (completing-read "Keyword (or KWD1|K2D2|...): "
  2469. (mapcar 'list kwds) nil nil)))
  2470. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  2471. (org-set-local 'org-last-arg arg)
  2472. (setq org-agenda-redo-command
  2473. '(org-todo-list (or current-prefix-arg org-last-arg)))
  2474. (setq files (org-agenda-files nil 'ifmode)
  2475. rtnall nil)
  2476. (while (setq file (pop files))
  2477. (catch 'nextfile
  2478. (org-check-agenda-file file)
  2479. (setq rtn (org-agenda-get-day-entries file date :todo))
  2480. (setq rtnall (append rtnall rtn))))
  2481. (if org-agenda-overriding-header
  2482. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2483. nil 'face 'org-agenda-structure) "\n")
  2484. (insert "Global list of TODO items of type: ")
  2485. (add-text-properties (point-min) (1- (point))
  2486. (list 'face 'org-agenda-structure))
  2487. (setq pos (point))
  2488. (insert (or org-select-this-todo-keyword "ALL") "\n")
  2489. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2490. (setq pos (point))
  2491. (unless org-agenda-multi
  2492. (insert "Available with `N r': (0)ALL")
  2493. (let ((n 0) s)
  2494. (mapc (lambda (x)
  2495. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  2496. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  2497. (insert "\n "))
  2498. (insert " " s))
  2499. kwds))
  2500. (insert "\n"))
  2501. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  2502. (when rtnall
  2503. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2504. (goto-char (point-min))
  2505. (org-fit-agenda-window)
  2506. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  2507. (org-finalize-agenda)
  2508. (setq buffer-read-only t)))
  2509. ;;; Agenda tags match
  2510. ;;;###autoload
  2511. (defun org-tags-view (&optional todo-only match)
  2512. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  2513. The prefix arg TODO-ONLY limits the search to TODO entries."
  2514. (interactive "P")
  2515. (org-compile-prefix-format 'tags)
  2516. (org-set-sorting-strategy 'tags)
  2517. (let* ((org-tags-match-list-sublevels
  2518. (if todo-only t org-tags-match-list-sublevels))
  2519. (completion-ignore-case t)
  2520. rtn rtnall files file pos matcher
  2521. buffer)
  2522. (setq matcher (org-make-tags-matcher match)
  2523. match (car matcher) matcher (cdr matcher))
  2524. (org-prepare-agenda (concat "TAGS " match))
  2525. (setq org-agenda-query-string match)
  2526. (setq org-agenda-redo-command
  2527. (list 'org-tags-view (list 'quote todo-only)
  2528. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  2529. (setq files (org-agenda-files nil 'ifmode)
  2530. rtnall nil)
  2531. (while (setq file (pop files))
  2532. (catch 'nextfile
  2533. (org-check-agenda-file file)
  2534. (setq buffer (if (file-exists-p file)
  2535. (org-get-agenda-file-buffer file)
  2536. (error "No such file %s" file)))
  2537. (if (not buffer)
  2538. ;; If file does not exist, merror message to agenda
  2539. (setq rtn (list
  2540. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  2541. rtnall (append rtnall rtn))
  2542. (with-current-buffer buffer
  2543. (unless (org-mode-p)
  2544. (error "Agenda file %s is not in `org-mode'" file))
  2545. (save-excursion
  2546. (save-restriction
  2547. (if org-agenda-restrict
  2548. (narrow-to-region org-agenda-restrict-begin
  2549. org-agenda-restrict-end)
  2550. (widen))
  2551. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  2552. (setq rtnall (append rtnall rtn))))))))
  2553. (if org-agenda-overriding-header
  2554. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2555. nil 'face 'org-agenda-structure) "\n")
  2556. (insert "Headlines with TAGS match: ")
  2557. (add-text-properties (point-min) (1- (point))
  2558. (list 'face 'org-agenda-structure))
  2559. (setq pos (point))
  2560. (insert match "\n")
  2561. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  2562. (setq pos (point))
  2563. (unless org-agenda-multi
  2564. (insert "Press `C-u r' to search again with new search string\n"))
  2565. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  2566. (when rtnall
  2567. (insert (org-finalize-agenda-entries rtnall) "\n"))
  2568. (goto-char (point-min))
  2569. (org-fit-agenda-window)
  2570. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  2571. (org-finalize-agenda)
  2572. (setq buffer-read-only t)))
  2573. ;;; Agenda Finding stuck projects
  2574. (defvar org-agenda-skip-regexp nil
  2575. "Regular expression used in skipping subtrees for the agenda.
  2576. This is basically a temporary global variable that can be set and then
  2577. used by user-defined selections using `org-agenda-skip-function'.")
  2578. (defvar org-agenda-overriding-header nil
  2579. "When this is set during todo and tags searches, will replace header.")
  2580. (defun org-agenda-skip-subtree-when-regexp-matches ()
  2581. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  2582. If yes, it returns the end position of this tree, causing agenda commands
  2583. to skip this subtree. This is a function that can be put into
  2584. `org-agenda-skip-function' for the duration of a command."
  2585. (let ((end (save-excursion (org-end-of-subtree t)))
  2586. skip)
  2587. (save-excursion
  2588. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  2589. (and skip end)))
  2590. (defun org-agenda-skip-entry-if (&rest conditions)
  2591. "Skip entry if any of CONDITIONS is true.
  2592. See `org-agenda-skip-if' for details."
  2593. (org-agenda-skip-if nil conditions))
  2594. (defun org-agenda-skip-subtree-if (&rest conditions)
  2595. "Skip entry if any of CONDITIONS is true.
  2596. See `org-agenda-skip-if' for details."
  2597. (org-agenda-skip-if t conditions))
  2598. (defun org-agenda-skip-if (subtree conditions)
  2599. "Checks current entity for CONDITIONS.
  2600. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  2601. the entry, i.e. the text before the next heading is checked.
  2602. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  2603. from different tests. Valid conditions are:
  2604. scheduled Check if there is a scheduled cookie
  2605. notscheduled Check if there is no scheduled cookie
  2606. deadline Check if there is a deadline
  2607. notdeadline Check if there is no deadline
  2608. regexp Check if regexp matches
  2609. notregexp Check if regexp does not match.
  2610. The regexp is taken from the conditions list, it must come right after
  2611. the `regexp' or `notregexp' element.
  2612. If any of these conditions is met, this function returns the end point of
  2613. the entity, causing the search to continue from there. This is a function
  2614. that can be put into `org-agenda-skip-function' for the duration of a command."
  2615. (let (beg end m)
  2616. (org-back-to-heading t)
  2617. (setq beg (point)
  2618. end (if subtree
  2619. (progn (org-end-of-subtree t) (point))
  2620. (progn (outline-next-heading) (1- (point)))))
  2621. (goto-char beg)
  2622. (and
  2623. (or
  2624. (and (memq 'scheduled conditions)
  2625. (re-search-forward org-scheduled-time-regexp end t))
  2626. (and (memq 'notscheduled conditions)
  2627. (not (re-search-forward org-scheduled-time-regexp end t)))
  2628. (and (memq 'deadline conditions)
  2629. (re-search-forward org-deadline-time-regexp end t))
  2630. (and (memq 'notdeadline conditions)
  2631. (not (re-search-forward org-deadline-time-regexp end t)))
  2632. (and (setq m (memq 'regexp conditions))
  2633. (stringp (nth 1 m))
  2634. (re-search-forward (nth 1 m) end t))
  2635. (and (setq m (memq 'notregexp conditions))
  2636. (stringp (nth 1 m))
  2637. (not (re-search-forward (nth 1 m) end t))))
  2638. end)))
  2639. ;;;###autoload
  2640. (defun org-agenda-list-stuck-projects (&rest ignore)
  2641. "Create agenda view for projects that are stuck.
  2642. Stuck projects are project that have no next actions. For the definitions
  2643. of what a project is and how to check if it stuck, customize the variable
  2644. `org-stuck-projects'.
  2645. MATCH is being ignored."
  2646. (interactive)
  2647. (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches)
  2648. ;; We could have used org-agenda-skip-if here.
  2649. (org-agenda-overriding-header "List of stuck projects: ")
  2650. (matcher (nth 0 org-stuck-projects))
  2651. (todo (nth 1 org-stuck-projects))
  2652. (todo-wds (if (member "*" todo)
  2653. (progn
  2654. (org-prepare-agenda-buffers (org-agenda-files
  2655. nil 'ifmode))
  2656. (org-delete-all
  2657. org-done-keywords-for-agenda
  2658. (copy-sequence org-todo-keywords-for-agenda)))
  2659. todo))
  2660. (todo-re (concat "^\\*+[ \t]+\\("
  2661. (mapconcat 'identity todo-wds "\\|")
  2662. "\\)\\>"))
  2663. (tags (nth 2 org-stuck-projects))
  2664. (tags-re (if (member "*" tags)
  2665. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  2666. (concat "^\\*+ .*:\\("
  2667. (mapconcat 'identity tags "\\|")
  2668. (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
  2669. (gen-re (nth 3 org-stuck-projects))
  2670. (re-list
  2671. (delq nil
  2672. (list
  2673. (if todo todo-re)
  2674. (if tags tags-re)
  2675. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  2676. gen-re)))))
  2677. (setq org-agenda-skip-regexp
  2678. (if re-list
  2679. (mapconcat 'identity re-list "\\|")
  2680. (error "No information how to identify unstuck projects")))
  2681. (org-tags-view nil matcher)
  2682. (with-current-buffer org-agenda-buffer-name
  2683. (setq org-agenda-redo-command
  2684. '(org-agenda-list-stuck-projects
  2685. (or current-prefix-arg org-last-arg))))))
  2686. ;;; Diary integration
  2687. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  2688. (defvar list-diary-entries-hook)
  2689. (defun org-get-entries-from-diary (date)
  2690. "Get the (Emacs Calendar) diary entries for DATE."
  2691. (require 'diary-lib)
  2692. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  2693. (fancy-diary-buffer diary-fancy-buffer)
  2694. (diary-display-hook '(fancy-diary-display))
  2695. (diary-display-function 'fancy-diary-display)
  2696. (pop-up-frames nil)
  2697. (list-diary-entries-hook
  2698. (cons 'org-diary-default-entry list-diary-entries-hook))
  2699. (diary-file-name-prefix-function nil) ; turn this feature off
  2700. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  2701. entries
  2702. (org-disable-agenda-to-diary t))
  2703. (save-excursion
  2704. (save-window-excursion
  2705. (funcall (if (fboundp 'diary-list-entries)
  2706. 'diary-list-entries 'list-diary-entries)
  2707. date 1)))
  2708. (if (not (get-buffer diary-fancy-buffer))
  2709. (setq entries nil)
  2710. (with-current-buffer diary-fancy-buffer
  2711. (setq buffer-read-only nil)
  2712. (if (zerop (buffer-size))
  2713. ;; No entries
  2714. (setq entries nil)
  2715. ;; Omit the date and other unnecessary stuff
  2716. (org-agenda-cleanup-fancy-diary)
  2717. ;; Add prefix to each line and extend the text properties
  2718. (if (zerop (buffer-size))
  2719. (setq entries nil)
  2720. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  2721. (set-buffer-modified-p nil)
  2722. (kill-buffer diary-fancy-buffer)))
  2723. (when entries
  2724. (setq entries (org-split-string entries "\n"))
  2725. (setq entries
  2726. (mapcar
  2727. (lambda (x)
  2728. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  2729. ;; Extend the text properties to the beginning of the line
  2730. (org-add-props x (text-properties-at (1- (length x)) x)
  2731. 'type "diary" 'date date))
  2732. entries)))))
  2733. (defun org-agenda-cleanup-fancy-diary ()
  2734. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  2735. This gets rid of the date, the underline under the date, and
  2736. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  2737. date. It also removes lines that contain only whitespace."
  2738. (goto-char (point-min))
  2739. (if (looking-at ".*?:[ \t]*")
  2740. (progn
  2741. (replace-match "")
  2742. (re-search-forward "\n=+$" nil t)
  2743. (replace-match "")
  2744. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  2745. (re-search-forward "\n=+$" nil t)
  2746. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  2747. (goto-char (point-min))
  2748. (while (re-search-forward "^ +\n" nil t)
  2749. (replace-match ""))
  2750. (goto-char (point-min))
  2751. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  2752. (replace-match "")))
  2753. ;; Make sure entries from the diary have the right text properties.
  2754. (eval-after-load "diary-lib"
  2755. '(if (boundp 'diary-modify-entry-list-string-function)
  2756. ;; We can rely on the hook, nothing to do
  2757. nil
  2758. ;; Hook not avaiable, must use advice to make this work
  2759. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  2760. "Make the position visible."
  2761. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  2762. (stringp string)
  2763. buffer-file-name)
  2764. (setq string (org-modify-diary-entry-string string))))))
  2765. (defun org-modify-diary-entry-string (string)
  2766. "Add text properties to string, allowing org-mode to act on it."
  2767. (org-add-props string nil
  2768. 'mouse-face 'highlight
  2769. 'keymap org-agenda-keymap
  2770. 'help-echo (if buffer-file-name
  2771. (format "mouse-2 or RET jump to diary file %s"
  2772. (abbreviate-file-name buffer-file-name))
  2773. "")
  2774. 'org-agenda-diary-link t
  2775. 'org-marker (org-agenda-new-marker (point-at-bol))))
  2776. (defun org-diary-default-entry ()
  2777. "Add a dummy entry to the diary.
  2778. Needed to avoid empty dates which mess up holiday display."
  2779. ;; Catch the error if dealing with the new add-to-diary-alist
  2780. (when org-disable-agenda-to-diary
  2781. (condition-case nil
  2782. (org-add-to-diary-list original-date "Org-mode dummy" "")
  2783. (error
  2784. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  2785. (defun org-add-to-diary-list (&rest args)
  2786. (if (fboundp 'diary-add-to-list)
  2787. (apply 'diary-add-to-list args)
  2788. (apply 'add-to-diary-list args)))
  2789. ;;;###autoload
  2790. (defun org-diary (&rest args)
  2791. "Return diary information from org-files.
  2792. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  2793. It accesses org files and extracts information from those files to be
  2794. listed in the diary. The function accepts arguments specifying what
  2795. items should be listed. The following arguments are allowed:
  2796. :timestamp List the headlines of items containing a date stamp or
  2797. date range matching the selected date. Deadlines will
  2798. also be listed, on the expiration day.
  2799. :sexp List entries resulting from diary-like sexps.
  2800. :deadline List any deadlines past due, or due within
  2801. `org-deadline-warning-days'. The listing occurs only
  2802. in the diary for *today*, not at any other date. If
  2803. an entry is marked DONE, it is no longer listed.
  2804. :scheduled List all items which are scheduled for the given date.
  2805. The diary for *today* also contains items which were
  2806. scheduled earlier and are not yet marked DONE.
  2807. :todo List all TODO items from the org-file. This may be a
  2808. long list - so this is not turned on by default.
  2809. Like deadlines, these entries only show up in the
  2810. diary for *today*, not at any other date.
  2811. The call in the diary file should look like this:
  2812. &%%(org-diary) ~/path/to/some/orgfile.org
  2813. Use a separate line for each org file to check. Or, if you omit the file name,
  2814. all files listed in `org-agenda-files' will be checked automatically:
  2815. &%%(org-diary)
  2816. If you don't give any arguments (as in the example above), the default
  2817. arguments (:deadline :scheduled :timestamp :sexp) are used.
  2818. So the example above may also be written as
  2819. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  2820. The function expects the lisp variables `entry' and `date' to be provided
  2821. by the caller, because this is how the calendar works. Don't use this
  2822. function from a program - use `org-agenda-get-day-entries' instead."
  2823. (when (> (- (time-to-seconds (current-time))
  2824. org-agenda-last-marker-time)
  2825. 5)
  2826. (org-agenda-reset-markers))
  2827. (org-compile-prefix-format 'agenda)
  2828. (org-set-sorting-strategy 'agenda)
  2829. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  2830. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  2831. (list entry)
  2832. (org-agenda-files t)))
  2833. file rtn results)
  2834. (org-prepare-agenda-buffers files)
  2835. ;; If this is called during org-agenda, don't return any entries to
  2836. ;; the calendar. Org Agenda will list these entries itself.
  2837. (if org-disable-agenda-to-diary (setq files nil))
  2838. (while (setq file (pop files))
  2839. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  2840. (setq results (append results rtn)))
  2841. (if results
  2842. (concat (org-finalize-agenda-entries results) "\n"))))
  2843. ;;; Agenda entry finders
  2844. (defun org-agenda-get-day-entries (file date &rest args)
  2845. "Does the work for `org-diary' and `org-agenda'.
  2846. FILE is the path to a file to be checked for entries. DATE is date like
  2847. the one returned by `calendar-current-date'. ARGS are symbols indicating
  2848. which kind of entries should be extracted. For details about these, see
  2849. the documentation of `org-diary'."
  2850. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  2851. (let* ((org-startup-folded nil)
  2852. (org-startup-align-all-tables nil)
  2853. (buffer (if (file-exists-p file)
  2854. (org-get-agenda-file-buffer file)
  2855. (error "No such file %s" file)))
  2856. arg results rtn)
  2857. (if (not buffer)
  2858. ;; If file does not exist, make sure an error message ends up in diary
  2859. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  2860. (with-current-buffer buffer
  2861. (unless (org-mode-p)
  2862. (error "Agenda file %s is not in `org-mode'" file))
  2863. (let ((case-fold-search nil))
  2864. (save-excursion
  2865. (save-restriction
  2866. (if org-agenda-restrict
  2867. (narrow-to-region org-agenda-restrict-begin
  2868. org-agenda-restrict-end)
  2869. (widen))
  2870. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  2871. (while (setq arg (pop args))
  2872. (cond
  2873. ((and (eq arg :todo)
  2874. (equal date (calendar-current-date)))
  2875. (setq rtn (org-agenda-get-todos))
  2876. (setq results (append results rtn)))
  2877. ((eq arg :timestamp)
  2878. (setq rtn (org-agenda-get-blocks))
  2879. (setq results (append results rtn))
  2880. (setq rtn (org-agenda-get-timestamps))
  2881. (setq results (append results rtn)))
  2882. ((eq arg :sexp)
  2883. (setq rtn (org-agenda-get-sexps))
  2884. (setq results (append results rtn)))
  2885. ((eq arg :scheduled)
  2886. (setq rtn (org-agenda-get-scheduled))
  2887. (setq results (append results rtn)))
  2888. ((eq arg :closed)
  2889. (setq rtn (org-agenda-get-closed))
  2890. (setq results (append results rtn)))
  2891. ((eq arg :deadline)
  2892. (setq rtn (org-agenda-get-deadlines))
  2893. (setq results (append results rtn))))))))
  2894. results))))
  2895. (defun org-agenda-get-todos ()
  2896. "Return the TODO information for agenda display."
  2897. (let* ((props (list 'face nil
  2898. 'done-face 'org-done
  2899. 'org-not-done-regexp org-not-done-regexp
  2900. 'org-todo-regexp org-todo-regexp
  2901. 'org-complex-heading-regexp org-complex-heading-regexp
  2902. 'mouse-face 'highlight
  2903. 'keymap org-agenda-keymap
  2904. 'help-echo
  2905. (format "mouse-2 or RET jump to org file %s"
  2906. (abbreviate-file-name buffer-file-name))))
  2907. (regexp (concat "^\\*+[ \t]+\\("
  2908. (if org-select-this-todo-keyword
  2909. (if (equal org-select-this-todo-keyword "*")
  2910. org-todo-regexp
  2911. (concat "\\<\\("
  2912. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  2913. "\\)\\>"))
  2914. org-not-done-regexp)
  2915. "[^\n\r]*\\)"))
  2916. marker priority category tags todo-state
  2917. ee txt beg end)
  2918. (goto-char (point-min))
  2919. (while (re-search-forward regexp nil t)
  2920. (catch :skip
  2921. (save-match-data
  2922. (beginning-of-line)
  2923. (setq beg (point) end (progn (outline-next-heading) (point)))
  2924. (when (or (and org-agenda-todo-ignore-with-date (goto-char beg)
  2925. (re-search-forward org-ts-regexp end t))
  2926. (and org-agenda-todo-ignore-scheduled (goto-char beg)
  2927. (re-search-forward org-scheduled-time-regexp end t))
  2928. (and org-agenda-todo-ignore-deadlines (goto-char beg)
  2929. (re-search-forward org-deadline-time-regexp end t)
  2930. (org-deadline-close (match-string 1))))
  2931. (goto-char (1+ beg))
  2932. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  2933. (throw :skip nil)))
  2934. (goto-char beg)
  2935. (org-agenda-skip)
  2936. (goto-char (match-beginning 1))
  2937. (setq marker (org-agenda-new-marker (match-beginning 0))
  2938. category (org-get-category)
  2939. tags (org-get-tags-at (point))
  2940. txt (org-format-agenda-item "" (match-string 1) category tags)
  2941. priority (1+ (org-get-priority txt))
  2942. todo-state (org-get-todo-state))
  2943. (org-add-props txt props
  2944. 'org-marker marker 'org-hd-marker marker
  2945. 'priority priority 'org-category category
  2946. 'type "todo" 'todo-state todo-state)
  2947. (push txt ee)
  2948. (if org-agenda-todo-list-sublevels
  2949. (goto-char (match-end 1))
  2950. (org-end-of-subtree 'invisible))))
  2951. (nreverse ee)))
  2952. (defconst org-agenda-no-heading-message
  2953. "No heading for this item in buffer or region.")
  2954. (defun org-agenda-get-timestamps ()
  2955. "Return the date stamp information for agenda display."
  2956. (let* ((props (list 'face nil
  2957. 'org-not-done-regexp org-not-done-regexp
  2958. 'org-todo-regexp org-todo-regexp
  2959. 'org-complex-heading-regexp org-complex-heading-regexp
  2960. 'mouse-face 'highlight
  2961. 'keymap org-agenda-keymap
  2962. 'help-echo
  2963. (format "mouse-2 or RET jump to org file %s"
  2964. (abbreviate-file-name buffer-file-name))))
  2965. (d1 (calendar-absolute-from-gregorian date))
  2966. (remove-re
  2967. (concat
  2968. (regexp-quote
  2969. (format-time-string
  2970. "<%Y-%m-%d"
  2971. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  2972. ".*?>"))
  2973. (regexp
  2974. (concat
  2975. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  2976. (regexp-quote
  2977. (substring
  2978. (format-time-string
  2979. (car org-time-stamp-formats)
  2980. (apply 'encode-time ; DATE bound by calendar
  2981. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  2982. 1 11))
  2983. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  2984. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  2985. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  2986. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  2987. todo-state)
  2988. (goto-char (point-min))
  2989. (while (re-search-forward regexp nil t)
  2990. (setq b0 (match-beginning 0)
  2991. b3 (match-beginning 3) e3 (match-end 3))
  2992. (catch :skip
  2993. (and (org-at-date-range-p) (throw :skip nil))
  2994. (org-agenda-skip)
  2995. (if (and (match-end 1)
  2996. (not (= d1 (org-time-string-to-absolute
  2997. (match-string 1) d1 nil
  2998. org-agenda-repeating-timestamp-show-all))))
  2999. (throw :skip nil))
  3000. (if (and e3
  3001. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3002. (throw :skip nil))
  3003. (setq marker (org-agenda-new-marker b0)
  3004. category (org-get-category b0)
  3005. tmp (buffer-substring (max (point-min)
  3006. (- b0 org-ds-keyword-length))
  3007. b0)
  3008. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3009. inactivep (= (char-after b0) ?\[)
  3010. deadlinep (string-match org-deadline-regexp tmp)
  3011. scheduledp (string-match org-scheduled-regexp tmp)
  3012. closedp (and org-agenda-include-inactive-timestamps
  3013. (string-match org-closed-string tmp))
  3014. clockp (and org-agenda-include-inactive-timestamps
  3015. (or (string-match org-clock-string tmp)
  3016. (string-match "]-+\\'" tmp)))
  3017. todo-state (org-get-todo-state)
  3018. donep (member todo-state org-done-keywords))
  3019. (if (or scheduledp deadlinep closedp clockp)
  3020. (throw :skip t))
  3021. (if (string-match ">" timestr)
  3022. ;; substring should only run to end of time stamp
  3023. (setq timestr (substring timestr 0 (match-end 0))))
  3024. (save-excursion
  3025. (if (re-search-backward "^\\*+ " nil t)
  3026. (progn
  3027. (goto-char (match-beginning 0))
  3028. (setq hdmarker (org-agenda-new-marker)
  3029. tags (org-get-tags-at))
  3030. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3031. (setq head (match-string 1))
  3032. (and org-agenda-skip-timestamp-if-done donep (throw :skip t))
  3033. (setq txt (org-format-agenda-item
  3034. (if inactivep "[" nil)
  3035. head category tags timestr nil
  3036. remove-re)))
  3037. (setq txt org-agenda-no-heading-message))
  3038. (setq priority (org-get-priority txt))
  3039. (org-add-props txt props
  3040. 'org-marker marker 'org-hd-marker hdmarker)
  3041. (org-add-props txt nil 'priority priority
  3042. 'org-category category 'date date
  3043. 'todo-state todo-state
  3044. 'type "timestamp")
  3045. (push txt ee))
  3046. (outline-next-heading)))
  3047. (nreverse ee)))
  3048. (defun org-agenda-get-sexps ()
  3049. "Return the sexp information for agenda display."
  3050. (require 'diary-lib)
  3051. (let* ((props (list 'face nil
  3052. 'mouse-face 'highlight
  3053. 'keymap org-agenda-keymap
  3054. 'help-echo
  3055. (format "mouse-2 or RET jump to org file %s"
  3056. (abbreviate-file-name buffer-file-name))))
  3057. (regexp "^&?%%(")
  3058. marker category ee txt tags entry result beg b sexp sexp-entry)
  3059. (goto-char (point-min))
  3060. (while (re-search-forward regexp nil t)
  3061. (catch :skip
  3062. (org-agenda-skip)
  3063. (setq beg (match-beginning 0))
  3064. (goto-char (1- (match-end 0)))
  3065. (setq b (point))
  3066. (forward-sexp 1)
  3067. (setq sexp (buffer-substring b (point)))
  3068. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  3069. (org-trim (match-string 1))
  3070. ""))
  3071. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  3072. (when result
  3073. (setq marker (org-agenda-new-marker beg)
  3074. category (org-get-category beg))
  3075. (if (string-match "\\S-" result)
  3076. (setq txt result)
  3077. (setq txt "SEXP entry returned empty string"))
  3078. (setq txt (org-format-agenda-item
  3079. "" txt category tags 'time))
  3080. (org-add-props txt props 'org-marker marker)
  3081. (org-add-props txt nil
  3082. 'org-category category 'date date
  3083. 'type "sexp")
  3084. (push txt ee))))
  3085. (nreverse ee)))
  3086. (defun org-agenda-get-closed ()
  3087. "Return the logged TODO entries for agenda display."
  3088. (let* ((props (list 'mouse-face 'highlight
  3089. 'org-not-done-regexp org-not-done-regexp
  3090. 'org-todo-regexp org-todo-regexp
  3091. 'org-complex-heading-regexp org-complex-heading-regexp
  3092. 'keymap org-agenda-keymap
  3093. 'help-echo
  3094. (format "mouse-2 or RET jump to org file %s"
  3095. (abbreviate-file-name buffer-file-name))))
  3096. (regexp (concat
  3097. "\\<\\(" org-closed-string "\\|" org-clock-string "\\) *\\["
  3098. (regexp-quote
  3099. (substring
  3100. (format-time-string
  3101. (car org-time-stamp-formats)
  3102. (apply 'encode-time ; DATE bound by calendar
  3103. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3104. 1 11))))
  3105. marker hdmarker priority category tags closedp
  3106. ee txt timestr rest clocked)
  3107. (goto-char (point-min))
  3108. (while (re-search-forward regexp nil t)
  3109. (catch :skip
  3110. (org-agenda-skip)
  3111. (setq marker (org-agenda-new-marker (match-beginning 0))
  3112. closedp (equal (match-string 1) org-closed-string)
  3113. category (org-get-category (match-beginning 0))
  3114. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  3115. ;; donep (org-entry-is-done-p)
  3116. )
  3117. (when (string-match "\\]" timestr)
  3118. ;; substring should only run to end of time stamp
  3119. (setq rest (substring timestr (match-end 0))
  3120. timestr (substring timestr 0 (match-end 0)))
  3121. (if (and (not closedp)
  3122. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  3123. (progn (setq timestr (concat (substring timestr 0 -1)
  3124. "-" (match-string 1 rest) "]"))
  3125. (setq clocked (match-string 2 rest)))
  3126. (setq clocked "-")))
  3127. (save-excursion
  3128. (if (re-search-backward "^\\*+ " nil t)
  3129. (progn
  3130. (goto-char (match-beginning 0))
  3131. (setq hdmarker (org-agenda-new-marker)
  3132. tags (org-get-tags-at))
  3133. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3134. (setq txt (org-format-agenda-item
  3135. (if closedp "Closed: "
  3136. (concat "Clocked: (" clocked ")"))
  3137. (match-string 1) category tags timestr)))
  3138. (setq txt org-agenda-no-heading-message))
  3139. (setq priority 100000)
  3140. (org-add-props txt props
  3141. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-done
  3142. 'priority priority 'org-category category
  3143. 'type "closed" 'date date
  3144. 'undone-face 'org-warning 'done-face 'org-done)
  3145. (push txt ee))
  3146. (goto-char (point-at-eol))))
  3147. (nreverse ee)))
  3148. (defun org-agenda-get-deadlines ()
  3149. "Return the deadline information for agenda display."
  3150. (let* ((props (list 'mouse-face 'highlight
  3151. 'org-not-done-regexp org-not-done-regexp
  3152. 'org-todo-regexp org-todo-regexp
  3153. 'org-complex-heading-regexp org-complex-heading-regexp
  3154. 'keymap org-agenda-keymap
  3155. 'help-echo
  3156. (format "mouse-2 or RET jump to org file %s"
  3157. (abbreviate-file-name buffer-file-name))))
  3158. (regexp org-deadline-time-regexp)
  3159. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3160. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3161. d2 diff dfrac wdays pos pos1 category tags
  3162. ee txt head face s todo-state upcomingp donep timestr)
  3163. (goto-char (point-min))
  3164. (while (re-search-forward regexp nil t)
  3165. (catch :skip
  3166. (org-agenda-skip)
  3167. (setq s (match-string 1)
  3168. pos (1- (match-beginning 1))
  3169. d2 (org-time-string-to-absolute
  3170. (match-string 1) d1 'past
  3171. org-agenda-repeating-timestamp-show-all)
  3172. diff (- d2 d1)
  3173. wdays (org-get-wdays s)
  3174. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  3175. upcomingp (and todayp (> diff 0)))
  3176. ;; When to show a deadline in the calendar:
  3177. ;; If the expiration is within wdays warning time.
  3178. ;; Past-due deadlines are only shown on the current date
  3179. (if (or (and (<= diff wdays)
  3180. (and todayp (not org-agenda-only-exact-dates)))
  3181. (= diff 0))
  3182. (save-excursion
  3183. (setq category (org-get-category))
  3184. (setq todo-state (org-get-todo-state))
  3185. (if (re-search-backward "^\\*+[ \t]+" nil t)
  3186. (progn
  3187. (goto-char (match-end 0))
  3188. (setq pos1 (match-beginning 0))
  3189. (setq tags (org-get-tags-at pos1))
  3190. (setq head (buffer-substring-no-properties
  3191. (point)
  3192. (progn (skip-chars-forward "^\r\n")
  3193. (point))))
  3194. (setq donep (member todo-state org-done-keywords))
  3195. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3196. (setq timestr
  3197. (concat (substring s (match-beginning 1)) " "))
  3198. (setq timestr 'time))
  3199. (if (and donep
  3200. (or org-agenda-skip-deadline-if-done
  3201. (not (= diff 0))))
  3202. (setq txt nil)
  3203. (setq txt (org-format-agenda-item
  3204. (if (= diff 0)
  3205. (car org-agenda-deadline-leaders)
  3206. (if (functionp (nth 1 org-agenda-deadline-leaders))
  3207. (funcall (nth 1 org-agenda-deadline-leaders) diff date)
  3208. (format (nth 1 org-agenda-deadline-leaders)
  3209. diff)))
  3210. head category tags
  3211. (if (not (= diff 0)) nil timestr)))))
  3212. (setq txt org-agenda-no-heading-message))
  3213. (when txt
  3214. (setq face (org-agenda-deadline-face dfrac wdays))
  3215. (org-add-props txt props
  3216. 'org-marker (org-agenda-new-marker pos)
  3217. 'org-hd-marker (org-agenda-new-marker pos1)
  3218. 'priority (+ (- diff)
  3219. (org-get-priority txt))
  3220. 'org-category category
  3221. 'todo-state todo-state
  3222. 'type (if upcomingp "upcoming-deadline" "deadline")
  3223. 'date (if upcomingp date d2)
  3224. 'face (if donep 'org-done face)
  3225. 'undone-face face 'done-face 'org-done)
  3226. (push txt ee))))))
  3227. (nreverse ee)))
  3228. (defun org-agenda-deadline-face (fraction &optional wdays)
  3229. "Return the face to displaying a deadline item.
  3230. FRACTION is what fraction of the head-warning time has passed."
  3231. (if (equal wdays 0) (setq fraction 1.))
  3232. (let ((faces org-agenda-deadline-faces) f)
  3233. (catch 'exit
  3234. (while (setq f (pop faces))
  3235. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  3236. (defun org-agenda-get-scheduled ()
  3237. "Return the scheduled information for agenda display."
  3238. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  3239. 'org-todo-regexp org-todo-regexp
  3240. 'org-complex-heading-regexp org-complex-heading-regexp
  3241. 'done-face 'org-done
  3242. 'mouse-face 'highlight
  3243. 'keymap org-agenda-keymap
  3244. 'help-echo
  3245. (format "mouse-2 or RET jump to org file %s"
  3246. (abbreviate-file-name buffer-file-name))))
  3247. (regexp org-scheduled-time-regexp)
  3248. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3249. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3250. d2 diff pos pos1 category tags donep
  3251. ee txt head pastschedp todo-state face timestr s)
  3252. (goto-char (point-min))
  3253. (while (re-search-forward regexp nil t)
  3254. (catch :skip
  3255. (org-agenda-skip)
  3256. (setq s (match-string 1)
  3257. pos (1- (match-beginning 1))
  3258. d2 (org-time-string-to-absolute
  3259. (match-string 1) d1 'past
  3260. org-agenda-repeating-timestamp-show-all)
  3261. diff (- d2 d1))
  3262. (setq pastschedp (and todayp (< diff 0)))
  3263. ;; When to show a scheduled item in the calendar:
  3264. ;; If it is on or past the date.
  3265. (if (or (and (< diff 0)
  3266. (< (abs diff) org-scheduled-past-days)
  3267. (and todayp (not org-agenda-only-exact-dates)))
  3268. (= diff 0))
  3269. (save-excursion
  3270. (setq category (org-get-category))
  3271. (setq todo-state (org-get-todo-state))
  3272. (if (re-search-backward "^\\*+[ \t]+" nil t)
  3273. (progn
  3274. (goto-char (match-end 0))
  3275. (setq pos1 (match-beginning 0))
  3276. (setq tags (org-get-tags-at))
  3277. (setq head (buffer-substring-no-properties
  3278. (point)
  3279. (progn (skip-chars-forward "^\r\n") (point))))
  3280. (setq donep (member todo-state org-done-keywords))
  3281. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3282. (setq timestr
  3283. (concat (substring s (match-beginning 1)) " "))
  3284. (setq timestr 'time))
  3285. (if (and donep
  3286. (or org-agenda-skip-scheduled-if-done
  3287. (not (= diff 0))))
  3288. (setq txt nil)
  3289. (setq txt (org-format-agenda-item
  3290. (if (= diff 0)
  3291. (car org-agenda-scheduled-leaders)
  3292. (format (nth 1 org-agenda-scheduled-leaders)
  3293. (- 1 diff)))
  3294. head category tags
  3295. (if (not (= diff 0)) nil timestr)))))
  3296. (setq txt org-agenda-no-heading-message))
  3297. (when txt
  3298. (setq face
  3299. (cond
  3300. (pastschedp 'org-scheduled-previously)
  3301. (todayp 'org-scheduled-today)
  3302. (t 'org-scheduled)))
  3303. (org-add-props txt props
  3304. 'undone-face face
  3305. 'face (if donep 'org-done face)
  3306. 'org-marker (org-agenda-new-marker pos)
  3307. 'org-hd-marker (org-agenda-new-marker pos1)
  3308. 'type (if pastschedp "past-scheduled" "scheduled")
  3309. 'date (if pastschedp d2 date)
  3310. 'priority (+ 94 (- 5 diff) (org-get-priority txt))
  3311. 'org-category category
  3312. 'todo-state todo-state)
  3313. (push txt ee))))))
  3314. (nreverse ee)))
  3315. (defun org-agenda-get-blocks ()
  3316. "Return the date-range information for agenda display."
  3317. (let* ((props (list 'face nil
  3318. 'org-not-done-regexp org-not-done-regexp
  3319. 'org-todo-regexp org-todo-regexp
  3320. 'org-complex-heading-regexp org-complex-heading-regexp
  3321. 'mouse-face 'highlight
  3322. 'keymap org-agenda-keymap
  3323. 'help-echo
  3324. (format "mouse-2 or RET jump to org file %s"
  3325. (abbreviate-file-name buffer-file-name))))
  3326. (regexp org-tr-regexp)
  3327. (d0 (calendar-absolute-from-gregorian date))
  3328. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  3329. donep head)
  3330. (goto-char (point-min))
  3331. (while (re-search-forward regexp nil t)
  3332. (catch :skip
  3333. (org-agenda-skip)
  3334. (setq pos (point))
  3335. (setq timestr (match-string 0)
  3336. s1 (match-string 1)
  3337. s2 (match-string 2)
  3338. d1 (time-to-days (org-time-string-to-time s1))
  3339. d2 (time-to-days (org-time-string-to-time s2)))
  3340. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  3341. ;; Only allow days between the limits, because the normal
  3342. ;; date stamps will catch the limits.
  3343. (save-excursion
  3344. (setq marker (org-agenda-new-marker (point)))
  3345. (setq category (org-get-category))
  3346. (setq todo-state (org-get-todo-state))
  3347. (if (re-search-backward "^\\*+ " nil t)
  3348. (progn
  3349. (goto-char (match-beginning 0))
  3350. (setq hdmarker (org-agenda-new-marker (point)))
  3351. (setq tags (org-get-tags-at))
  3352. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3353. (setq head (match-string 1))
  3354. (and org-agenda-skip-timestamp-if-done
  3355. (org-entry-is-done-p)
  3356. (throw :skip t))
  3357. (setq txt (org-format-agenda-item
  3358. (format (if (= d1 d2) "" "(%d/%d): ")
  3359. (1+ (- d0 d1)) (1+ (- d2 d1)))
  3360. head category tags
  3361. (if (= d0 d1) timestr))))
  3362. (setq txt org-agenda-no-heading-message))
  3363. (org-add-props txt props
  3364. 'org-marker marker 'org-hd-marker hdmarker
  3365. 'type "block" 'date date
  3366. 'todo-state todo-state
  3367. 'priority (org-get-priority txt) 'org-category category)
  3368. (push txt ee)))
  3369. (goto-char pos)))
  3370. ;; Sort the entries by expiration date.
  3371. (nreverse ee)))
  3372. ;;; Agenda presentation and sorting
  3373. (defvar org-prefix-has-time nil
  3374. "A flag, set by `org-compile-prefix-format'.
  3375. The flag is set if the currently compiled format contains a `%t'.")
  3376. (defvar org-prefix-has-tag nil
  3377. "A flag, set by `org-compile-prefix-format'.
  3378. The flag is set if the currently compiled format contains a `%T'.")
  3379. (defvar org-prefix-has-effort nil
  3380. "A flag, set by `org-compile-prefix-format'.
  3381. The flag is set if the currently compiled format contains a `%e'.")
  3382. (defun org-format-agenda-item (extra txt &optional category tags dotime
  3383. noprefix remove-re)
  3384. "Format TXT to be inserted into the agenda buffer.
  3385. In particular, it adds the prefix and corresponding text properties. EXTRA
  3386. must be a string and replaces the `%s' specifier in the prefix format.
  3387. CATEGORY (string, symbol or nil) may be used to overrule the default
  3388. category taken from local variable or file name. It will replace the `%c'
  3389. specifier in the format. DOTIME, when non-nil, indicates that a
  3390. time-of-day should be extracted from TXT for sorting of this entry, and for
  3391. the `%t' specifier in the format. When DOTIME is a string, this string is
  3392. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  3393. only the correctly processes TXT should be returned - this is used by
  3394. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  3395. Any match of REMOVE-RE will be removed from TXT."
  3396. (save-match-data
  3397. ;; Diary entries sometimes have extra whitespace at the beginning
  3398. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  3399. (let* ((category (or category
  3400. org-category
  3401. (if buffer-file-name
  3402. (file-name-sans-extension
  3403. (file-name-nondirectory buffer-file-name))
  3404. "")))
  3405. ;; time, tag, effort are needed for the eval of the prefix format
  3406. (tag (if tags (nth (1- (length tags)) tags) ""))
  3407. time effort neffort
  3408. (ts (if dotime (concat (if (stringp dotime) dotime "") txt)))
  3409. (time-of-day (and dotime (org-get-time-of-day ts)))
  3410. stamp plain s0 s1 s2 t1 t2 rtn srp
  3411. duration)
  3412. (and (org-mode-p) buffer-file-name
  3413. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  3414. (when (and dotime time-of-day)
  3415. ;; Extract starting and ending time and move them to prefix
  3416. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  3417. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  3418. (setq s0 (match-string 0 ts)
  3419. srp (and stamp (match-end 3))
  3420. s1 (match-string (if plain 1 2) ts)
  3421. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  3422. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  3423. ;; them, we might want to remove them there to avoid duplication.
  3424. ;; The user can turn this off with a variable.
  3425. (if (and org-prefix-has-time
  3426. org-agenda-remove-times-when-in-prefix (or stamp plain)
  3427. (string-match (concat (regexp-quote s0) " *") txt)
  3428. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  3429. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  3430. (= (match-beginning 0) 0)
  3431. t))
  3432. (setq txt (replace-match "" nil nil txt))))
  3433. ;; Normalize the time(s) to 24 hour
  3434. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  3435. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  3436. ;; Compute the duration
  3437. (when s1
  3438. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  3439. (string-to-number (substring s1 3)))
  3440. t2 (cond
  3441. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  3442. (string-to-number (substring s2 3))))
  3443. (org-agenda-default-appointment-duration
  3444. (+ t1 org-agenda-default-appointment-duration))
  3445. (t nil)))
  3446. (setq duration (if t2 (- t2 t1)))))
  3447. (when (and s1 (not s2) org-agenda-default-appointment-duration
  3448. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  3449. (let ((m (+ (string-to-number (match-string 2 s1))
  3450. (* 60 (string-to-number (match-string 1 s1)))
  3451. org-agenda-default-appointment-duration))
  3452. h)
  3453. (setq h (/ m 60) m (- m (* h 60)))
  3454. (setq s2 (format "%02d:%02d" h m))))
  3455. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  3456. txt)
  3457. ;; Tags are in the string
  3458. (if (or (eq org-agenda-remove-tags t)
  3459. (and org-agenda-remove-tags
  3460. org-prefix-has-tag))
  3461. (setq txt (replace-match "" t t txt))
  3462. (setq txt (replace-match
  3463. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  3464. (match-string 2 txt))
  3465. t t txt))))
  3466. (when (org-mode-p)
  3467. (setq effort
  3468. (condition-case nil
  3469. (org-get-effort
  3470. (or (get-text-property 0 'org-hd-marker txt)
  3471. (get-text-property 0 'org-marker txt)))
  3472. (error nil)))
  3473. (when effort
  3474. (setq neffort (org-hh:mm-string-to-minutes effort)
  3475. effort (setq effort (concat "[" effort"]" )))))
  3476. (when remove-re
  3477. (while (string-match remove-re txt)
  3478. (setq txt (replace-match "" t t txt))))
  3479. ;; Create the final string
  3480. (if noprefix
  3481. (setq rtn txt)
  3482. ;; Prepare the variables needed in the eval of the compiled format
  3483. (setq time (cond (s2 (concat s1 "-" s2))
  3484. (s1 (concat s1 "......"))
  3485. (t ""))
  3486. extra (or extra "")
  3487. category (if (symbolp category) (symbol-name category) category))
  3488. ;; Evaluate the compiled format
  3489. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  3490. ;; And finally add the text properties
  3491. (org-add-props rtn nil
  3492. 'org-category (downcase category) 'tags tags
  3493. 'org-highest-priority org-highest-priority
  3494. 'org-lowest-priority org-lowest-priority
  3495. 'prefix-length (- (length rtn) (length txt))
  3496. 'time-of-day time-of-day
  3497. 'duration duration
  3498. 'effort effort
  3499. 'effort-minutes neffort
  3500. 'txt txt
  3501. 'time time
  3502. 'extra extra
  3503. 'dotime dotime))))
  3504. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  3505. (defvar org-agenda-sorting-strategy-selected nil)
  3506. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  3507. (catch 'exit
  3508. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  3509. ((and todayp (member 'today (car org-agenda-time-grid))))
  3510. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  3511. ((member 'weekly (car org-agenda-time-grid)))
  3512. (t (throw 'exit list)))
  3513. (let* ((have (delq nil (mapcar
  3514. (lambda (x) (get-text-property 1 'time-of-day x))
  3515. list)))
  3516. (string (nth 1 org-agenda-time-grid))
  3517. (gridtimes (nth 2 org-agenda-time-grid))
  3518. (req (car org-agenda-time-grid))
  3519. (remove (member 'remove-match req))
  3520. new time)
  3521. (if (and (member 'require-timed req) (not have))
  3522. ;; don't show empty grid
  3523. (throw 'exit list))
  3524. (while (setq time (pop gridtimes))
  3525. (unless (and remove (member time have))
  3526. (setq time (int-to-string time))
  3527. (push (org-format-agenda-item
  3528. nil string "" nil
  3529. (concat (substring time 0 -2) ":" (substring time -2)))
  3530. new)
  3531. (put-text-property
  3532. 1 (length (car new)) 'face 'org-time-grid (car new))))
  3533. (if (member 'time-up org-agenda-sorting-strategy-selected)
  3534. (append new list)
  3535. (append list new)))))
  3536. (defun org-compile-prefix-format (key)
  3537. "Compile the prefix format into a Lisp form that can be evaluated.
  3538. The resulting form is returned and stored in the variable
  3539. `org-prefix-format-compiled'."
  3540. (setq org-prefix-has-time nil org-prefix-has-tag nil
  3541. org-prefix-has-effort nil)
  3542. (let ((s (cond
  3543. ((stringp org-agenda-prefix-format)
  3544. org-agenda-prefix-format)
  3545. ((assq key org-agenda-prefix-format)
  3546. (cdr (assq key org-agenda-prefix-format)))
  3547. (t " %-12:c%?-12t% s")))
  3548. (start 0)
  3549. varform vars var e c f opt)
  3550. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  3551. s start)
  3552. (setq var (cdr (assoc (match-string 4 s)
  3553. '(("c" . category) ("t" . time) ("s" . extra)
  3554. ("T" . tag) ("e" . effort))))
  3555. c (or (match-string 3 s) "")
  3556. opt (match-beginning 1)
  3557. start (1+ (match-beginning 0)))
  3558. (if (equal var 'time) (setq org-prefix-has-time t))
  3559. (if (equal var 'tag) (setq org-prefix-has-tag t))
  3560. (if (equal var 'effort) (setq org-prefix-has-effort t))
  3561. (setq f (concat "%" (match-string 2 s) "s"))
  3562. (if opt
  3563. (setq varform
  3564. `(if (equal "" ,var)
  3565. ""
  3566. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  3567. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c)))))
  3568. (setq s (replace-match "%s" t nil s))
  3569. (push varform vars))
  3570. (setq vars (nreverse vars))
  3571. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  3572. (defun org-set-sorting-strategy (key)
  3573. (if (symbolp (car org-agenda-sorting-strategy))
  3574. ;; the old format
  3575. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  3576. (setq org-agenda-sorting-strategy-selected
  3577. (or (cdr (assq key org-agenda-sorting-strategy))
  3578. (cdr (assq 'agenda org-agenda-sorting-strategy))
  3579. '(time-up category-keep priority-down)))))
  3580. (defun org-get-time-of-day (s &optional string mod24)
  3581. "Check string S for a time of day.
  3582. If found, return it as a military time number between 0 and 2400.
  3583. If not found, return nil.
  3584. The optional STRING argument forces conversion into a 5 character wide string
  3585. HH:MM."
  3586. (save-match-data
  3587. (when
  3588. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  3589. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  3590. (let* ((h (string-to-number (match-string 1 s)))
  3591. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  3592. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  3593. (am-p (equal ampm "am"))
  3594. (h1 (cond ((not ampm) h)
  3595. ((= h 12) (if am-p 0 12))
  3596. (t (+ h (if am-p 0 12)))))
  3597. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  3598. (mod h1 24) h1))
  3599. (t0 (+ (* 100 h2) m))
  3600. (t1 (concat (if (>= h1 24) "+" " ")
  3601. (if (< t0 100) "0" "")
  3602. (if (< t0 10) "0" "")
  3603. (int-to-string t0))))
  3604. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  3605. (defun org-finalize-agenda-entries (list &optional nosort)
  3606. "Sort and concatenate the agenda items."
  3607. (setq list (mapcar 'org-agenda-highlight-todo list))
  3608. (if nosort
  3609. list
  3610. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  3611. (defun org-agenda-highlight-todo (x)
  3612. (let ((org-done-keywords org-done-keywords-for-agenda)
  3613. re pl)
  3614. (if (eq x 'line)
  3615. (save-excursion
  3616. (beginning-of-line 1)
  3617. (setq re (get-text-property (point) 'org-todo-regexp))
  3618. (goto-char (+ (point) (or (get-text-property (point) 'prefix-length) 0)))
  3619. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  3620. (add-text-properties (match-beginning 0) (match-end 0)
  3621. (list 'face (org-get-todo-face 1)))
  3622. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  3623. (delete-region (match-beginning 1) (1- (match-end 0)))
  3624. (goto-char (match-beginning 1))
  3625. (insert (format org-agenda-todo-keyword-format s)))))
  3626. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  3627. pl (get-text-property 0 'prefix-length x))
  3628. (when (and re
  3629. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  3630. x (or pl 0)) pl))
  3631. (add-text-properties
  3632. (or (match-end 1) (match-end 0)) (match-end 0)
  3633. (list 'face (org-get-todo-face (match-string 2 x)))
  3634. x)
  3635. (setq x (concat (substring x 0 (match-end 1))
  3636. (format org-agenda-todo-keyword-format
  3637. (match-string 2 x))
  3638. " "
  3639. (substring x (match-end 3)))))
  3640. x)))
  3641. (defsubst org-cmp-priority (a b)
  3642. "Compare the priorities of string A and B."
  3643. (let ((pa (or (get-text-property 1 'priority a) 0))
  3644. (pb (or (get-text-property 1 'priority b) 0)))
  3645. (cond ((> pa pb) +1)
  3646. ((< pa pb) -1)
  3647. (t nil))))
  3648. (defsubst org-cmp-effort (a b)
  3649. "Compare the priorities of string A and B."
  3650. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  3651. (ea (or (get-text-property 1 'effort-minutes a) def))
  3652. (eb (or (get-text-property 1 'effort-minutes b) def)))
  3653. (cond ((> ea eb) +1)
  3654. ((< ea eb) -1)
  3655. (t nil))))
  3656. (defsubst org-cmp-category (a b)
  3657. "Compare the string values of categories of strings A and B."
  3658. (let ((ca (or (get-text-property 1 'org-category a) ""))
  3659. (cb (or (get-text-property 1 'org-category b) "")))
  3660. (cond ((string-lessp ca cb) -1)
  3661. ((string-lessp cb ca) +1)
  3662. (t nil))))
  3663. (defsubst org-cmp-todo-state (a b)
  3664. "Compare the todo states of strings A and B."
  3665. (let* ((ta (or (get-text-property 1 'todo-state a) ""))
  3666. (tb (or (get-text-property 1 'todo-state b) ""))
  3667. (la (- (length (member ta org-todo-keywords-for-agenda))))
  3668. (lb (- (length (member tb org-todo-keywords-for-agenda))))
  3669. (donepa (member ta org-done-keywords-for-agenda))
  3670. (donepb (member tb org-done-keywords-for-agenda)))
  3671. (cond ((and donepa (not donepb)) -1)
  3672. ((and (not donepa) donepb) +1)
  3673. ((< la lb) -1)
  3674. ((< lb la) +1)
  3675. (t nil))))
  3676. (defsubst org-cmp-tag (a b)
  3677. "Compare the string values of categories of strings A and B."
  3678. (let ((ta (car (last (get-text-property 1 'tags a))))
  3679. (tb (car (last (get-text-property 1 'tags b)))))
  3680. (cond ((not ta) +1)
  3681. ((not tb) -1)
  3682. ((string-lessp ta tb) -1)
  3683. ((string-lessp tb ta) +1)
  3684. (t nil))))
  3685. (defsubst org-cmp-time (a b)
  3686. "Compare the time-of-day values of strings A and B."
  3687. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  3688. (ta (or (get-text-property 1 'time-of-day a) def))
  3689. (tb (or (get-text-property 1 'time-of-day b) def)))
  3690. (cond ((< ta tb) -1)
  3691. ((< tb ta) +1)
  3692. (t nil))))
  3693. (defun org-entries-lessp (a b)
  3694. "Predicate for sorting agenda entries."
  3695. ;; The following variables will be used when the form is evaluated.
  3696. ;; So even though the compiler complains, keep them.
  3697. (let* ((time-up (org-cmp-time a b))
  3698. (time-down (if time-up (- time-up) nil))
  3699. (priority-up (org-cmp-priority a b))
  3700. (priority-down (if priority-up (- priority-up) nil))
  3701. (effort-up (org-cmp-effort a b))
  3702. (effort-down (if effort-up (- effort-up) nil))
  3703. (category-up (org-cmp-category a b))
  3704. (category-down (if category-up (- category-up) nil))
  3705. (category-keep (if category-up +1 nil))
  3706. (tag-up (org-cmp-tag a b))
  3707. (tag-down (if tag-up (- tag-up) nil))
  3708. (todo-state-up (org-cmp-todo-state a b))
  3709. (todo-state-down (if todo-state-up (- todo-state-up) nil)))
  3710. (cdr (assoc
  3711. (eval (cons 'or org-agenda-sorting-strategy-selected))
  3712. '((-1 . t) (1 . nil) (nil . nil))))))
  3713. ;;; Agenda restriction lock
  3714. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  3715. "Overlay to mark the headline to which arenda commands are restricted.")
  3716. (org-overlay-put org-agenda-restriction-lock-overlay
  3717. 'face 'org-agenda-restriction-lock)
  3718. (org-overlay-put org-agenda-restriction-lock-overlay
  3719. 'help-echo "Agendas are currently limited to this subtree.")
  3720. (org-detach-overlay org-agenda-restriction-lock-overlay)
  3721. (defun org-agenda-set-restriction-lock (&optional type)
  3722. "Set restriction lock for agenda, to current subtree or file.
  3723. Restriction will be the file if TYPE is `file', or if type is the
  3724. universal prefix '(4), or if the cursor is before the first headline
  3725. in the file. Otherwise, restriction will be to the current subtree."
  3726. (interactive "P")
  3727. (and (equal type '(4)) (setq type 'file))
  3728. (setq type (cond
  3729. (type type)
  3730. ((org-at-heading-p) 'subtree)
  3731. ((condition-case nil (org-back-to-heading t) (error nil))
  3732. 'subtree)
  3733. (t 'file)))
  3734. (if (eq type 'subtree)
  3735. (progn
  3736. (setq org-agenda-restrict t)
  3737. (setq org-agenda-overriding-restriction 'subtree)
  3738. (put 'org-agenda-files 'org-restrict
  3739. (list (buffer-file-name (buffer-base-buffer))))
  3740. (org-back-to-heading t)
  3741. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  3742. (move-marker org-agenda-restrict-begin (point))
  3743. (move-marker org-agenda-restrict-end
  3744. (save-excursion (org-end-of-subtree t)))
  3745. (message "Locking agenda restriction to subtree"))
  3746. (put 'org-agenda-files 'org-restrict
  3747. (list (buffer-file-name (buffer-base-buffer))))
  3748. (setq org-agenda-restrict nil)
  3749. (setq org-agenda-overriding-restriction 'file)
  3750. (move-marker org-agenda-restrict-begin nil)
  3751. (move-marker org-agenda-restrict-end nil)
  3752. (message "Locking agenda restriction to file"))
  3753. (setq current-prefix-arg nil)
  3754. (org-agenda-maybe-redo))
  3755. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  3756. "Remove the agenda restriction lock."
  3757. (interactive "P")
  3758. (org-detach-overlay org-agenda-restriction-lock-overlay)
  3759. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  3760. (setq org-agenda-overriding-restriction nil)
  3761. (setq org-agenda-restrict nil)
  3762. (put 'org-agenda-files 'org-restrict nil)
  3763. (move-marker org-agenda-restrict-begin nil)
  3764. (move-marker org-agenda-restrict-end nil)
  3765. (setq current-prefix-arg nil)
  3766. (message "Agenda restriction lock removed")
  3767. (or noupdate (org-agenda-maybe-redo)))
  3768. (defun org-agenda-maybe-redo ()
  3769. "If there is any window showing the agenda view, update it."
  3770. (let ((w (get-buffer-window org-agenda-buffer-name t))
  3771. (w0 (selected-window)))
  3772. (when w
  3773. (select-window w)
  3774. (org-agenda-redo)
  3775. (select-window w0)
  3776. (if org-agenda-overriding-restriction
  3777. (message "Agenda view shifted to new %s restriction"
  3778. org-agenda-overriding-restriction)
  3779. (message "Agenda restriction lock removed")))))
  3780. ;;; Agenda commands
  3781. (defun org-agenda-check-type (error &rest types)
  3782. "Check if agenda buffer is of allowed type.
  3783. If ERROR is non-nil, throw an error, otherwise just return nil."
  3784. (if (memq org-agenda-type types)
  3785. t
  3786. (if error
  3787. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  3788. nil)))
  3789. (defun org-agenda-quit ()
  3790. "Exit agenda by removing the window or the buffer."
  3791. (interactive)
  3792. (if org-agenda-columns-active
  3793. (org-columns-quit)
  3794. (let ((buf (current-buffer)))
  3795. (if (not (one-window-p)) (delete-window))
  3796. (kill-buffer buf)
  3797. (org-agenda-reset-markers)
  3798. (org-columns-remove-overlays)
  3799. (setq org-agenda-archives-mode nil))
  3800. ;; Maybe restore the pre-agenda window configuration.
  3801. (and org-agenda-restore-windows-after-quit
  3802. (not (eq org-agenda-window-setup 'other-frame))
  3803. org-pre-agenda-window-conf
  3804. (set-window-configuration org-pre-agenda-window-conf))))
  3805. (defun org-agenda-exit ()
  3806. "Exit agenda by removing the window or the buffer.
  3807. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  3808. Org-mode buffers visited directly by the user will not be touched."
  3809. (interactive)
  3810. (org-release-buffers org-agenda-new-buffers)
  3811. (setq org-agenda-new-buffers nil)
  3812. (org-agenda-quit))
  3813. (defun org-agenda-execute (arg)
  3814. "Execute another agenda command, keeping same window.\\<global-map>
  3815. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  3816. (interactive "P")
  3817. (let ((org-agenda-window-setup 'current-window))
  3818. (org-agenda arg)))
  3819. (defun org-save-all-org-buffers ()
  3820. "Save all Org-mode buffers without user confirmation."
  3821. (interactive)
  3822. (message "Saving all Org-mode buffers...")
  3823. (save-some-buffers t 'org-mode-p)
  3824. (message "Saving all Org-mode buffers... done"))
  3825. (defun org-agenda-redo ()
  3826. "Rebuild Agenda.
  3827. When this is the global TODO list, a prefix argument will be interpreted."
  3828. (interactive)
  3829. (let* ((org-agenda-keep-modes t)
  3830. (filter org-agenda-filter)
  3831. (cols org-agenda-columns-active)
  3832. (line (org-current-line))
  3833. (window-line (- line (org-current-line (window-start))))
  3834. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  3835. (and cols (org-columns-quit))
  3836. (message "Rebuilding agenda buffer...")
  3837. (org-let lprops '(eval org-agenda-redo-command))
  3838. (setq org-agenda-undo-list nil
  3839. org-agenda-pending-undo-list nil)
  3840. (message "Rebuilding agenda buffer...done")
  3841. (and filter (org-agenda-filter-apply filter))
  3842. (and cols (interactive-p) (org-agenda-columns))
  3843. (goto-line line)
  3844. (recenter window-line)))
  3845. (defvar org-global-tags-completion-table nil)
  3846. (defvar org-agenda-filter-form nil)
  3847. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  3848. "Keep only those lines in the agenda buffer that have a specific tag.
  3849. The tag is selected with its fast selection letter, as configured.
  3850. With prefix argument STRIP, remove all lines that do have the tag.
  3851. A lisp caller can specify CHAR. NARROW means that the new tag should be
  3852. used to narrow the search - the interactive user can also press `-' or `+'
  3853. to switch to narrowing."
  3854. (interactive "P")
  3855. (let* ((alist org-tag-alist-for-agenda)
  3856. (tag-chars (mapconcat
  3857. (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
  3858. alist ""))
  3859. (efforts (org-split-string
  3860. (or (cdr (assoc (concat org-effort-property "_ALL")
  3861. org-global-properties))
  3862. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  3863. (effort-op org-agenda-filter-effort-default-operator)
  3864. (effort-prompt "")
  3865. (inhibit-read-only t)
  3866. (current org-agenda-filter)
  3867. char a n tag tags)
  3868. (unless char
  3869. (message
  3870. "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<]:effort: "
  3871. (if narrow "Narrow" "Filter") tag-chars)
  3872. (setq char (read-char)))
  3873. (when (member char '(?+ ?-))
  3874. ;; Narrowing down
  3875. (cond ((equal char ?-) (setq strip t narrow t))
  3876. ((equal char ?+) (setq strip nil narrow t)))
  3877. (message
  3878. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  3879. (setq char (read-char)))
  3880. (when (member char '(?< ?> ?=))
  3881. ;; An effort operator
  3882. (setq effort-op (char-to-string char))
  3883. (loop for i from 0 to 9 do
  3884. (setq effort-prompt
  3885. (concat
  3886. effort-prompt " ["
  3887. (if (= i 9) "0" (int-to-string (1+ i)))
  3888. "]" (nth i efforts))))
  3889. (setq alist nil) ; to make sure it will be interpreted as effort.
  3890. (message "Effort%s: %s " effort-op effort-prompt)
  3891. (setq char (read-char))
  3892. (when (or (< char ?0) (> char ?9))
  3893. (error "Need 1-9,0 to select effort" )))
  3894. (when (equal char ?\t)
  3895. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  3896. (org-set-local 'org-global-tags-completion-table
  3897. (org-global-tags-completion-table)))
  3898. (let ((completion-ignore-case t))
  3899. (setq tag (completing-read
  3900. "Tag: " org-global-tags-completion-table))))
  3901. (cond
  3902. ((equal char ?/) (org-agenda-filter-by-tag-show-all))
  3903. ((or (equal char ?\ )
  3904. (setq a (rassoc char alist))
  3905. (and (>= char ?0) (<= char ?9)
  3906. (setq n (if (= char ?0) 9 (- char ?0 1))
  3907. tag (concat effort-op (nth n efforts))
  3908. a (cons tag nil)))
  3909. (and tag (setq a (cons tag nil))))
  3910. (org-agenda-filter-by-tag-show-all)
  3911. (setq tag (car a))
  3912. (setq org-agenda-filter
  3913. (cons (concat (if strip "-" "+") tag)
  3914. (if narrow current nil)))
  3915. (org-agenda-filter-apply org-agenda-filter))
  3916. (t (error "Invalid tag selection character %c" char)))))
  3917. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  3918. "Refine the current filter. See `org-agenda-filter-by-tag."
  3919. (interactive "P")
  3920. (org-agenda-filter-by-tag strip char 'refine))
  3921. (defun org-agenda-filter-make-matcher ()
  3922. "Create the form that tests a line for the agenda filter."
  3923. (let (f f1)
  3924. (dolist (x org-agenda-filter)
  3925. (if (member x '("-" "+"))
  3926. (setq f1 '(not tags))
  3927. (if (string-match "[<=>]" x)
  3928. (setq f1 (org-agenda-filter-effort-form x))
  3929. (setq f1 (list 'member (substring x 1) 'tags)))
  3930. (if (equal (string-to-char x) ?-)
  3931. (setq f1 (list 'not f1))))
  3932. (push f1 f))
  3933. (cons 'and (nreverse f))))
  3934. (defun org-agenda-filter-effort-form (e)
  3935. "Return the form to compare the effort of the current line with what E says.
  3936. E looks line \"+<2:25\"."
  3937. (let (op)
  3938. (setq e (substring e 1))
  3939. (setq op (string-to-char e) e (substring e 1))
  3940. (setq op (if (equal op ?<) '<= (if (equal op ?>) '>= '=)))
  3941. (list 'org-agenda-compare-effort (list 'quote op)
  3942. (org-hh:mm-string-to-minutes e))))
  3943. (defun org-agenda-compare-effort (op value)
  3944. "Compare the effort of the current line with VALUE, using OP.
  3945. If the line does not have an effort defined, return nil."
  3946. (let ((eff (get-text-property (point) 'effort-minutes)))
  3947. (if (not eff)
  3948. nil ; we don't have an effort defined
  3949. (funcall op eff value))))
  3950. (defun org-agenda-filter-apply (filter)
  3951. "Set FILTER as the new agenda filter and apply it."
  3952. (let (tags)
  3953. (setq org-agenda-filter filter
  3954. org-agenda-filter-form (org-agenda-filter-make-matcher))
  3955. (org-agenda-set-mode-name)
  3956. (save-excursion
  3957. (goto-char (point-min))
  3958. (while (not (eobp))
  3959. (if (get-text-property (point) 'org-marker)
  3960. (progn
  3961. (setq tags (get-text-property (point) 'tags))
  3962. (if (not (eval org-agenda-filter-form))
  3963. (org-agenda-filter-by-tag-hide-line))
  3964. (beginning-of-line 2))
  3965. (beginning-of-line 2))))))
  3966. (defvar org-agenda-filter-overlays nil)
  3967. (defun org-agenda-filter-by-tag-hide-line ()
  3968. (let (ov)
  3969. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  3970. (point-at-eol)))
  3971. (org-overlay-put ov 'invisible t)
  3972. (org-overlay-put ov 'type 'tags-filter)
  3973. (push ov org-agenda-filter-overlays)))
  3974. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  3975. (setq pos (or pos (point)))
  3976. (save-excursion
  3977. (dolist (ov (org-overlays-at pos))
  3978. (when (and (org-overlay-get ov 'invisible)
  3979. (eq (org-overlay-get ov 'type) 'tags-filter))
  3980. (goto-char pos)
  3981. (if (< (org-overlay-start ov) (point-at-eol))
  3982. (org-move-overlay ov (point-at-eol)
  3983. (org-overlay-end ov)))))))
  3984. (defun org-agenda-filter-by-tag-show-all ()
  3985. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  3986. (setq org-agenda-filter-overlays nil)
  3987. (setq org-agenda-filter nil)
  3988. (setq org-agenda-filter-form nil)
  3989. (org-agenda-set-mode-name))
  3990. (defun org-agenda-manipulate-query-add ()
  3991. "Manipulate the query by adding a search term with positive selection.
  3992. Positive selection means, the term must be matched for selection of an entry."
  3993. (interactive)
  3994. (org-agenda-manipulate-query ?\[))
  3995. (defun org-agenda-manipulate-query-subtract ()
  3996. "Manipulate the query by adding a search term with negative selection.
  3997. Negative selection means, term must not be matched for selection of an entry."
  3998. (interactive)
  3999. (org-agenda-manipulate-query ?\]))
  4000. (defun org-agenda-manipulate-query-add-re ()
  4001. "Manipulate the query by adding a search regexp with positive selection.
  4002. Positive selection means, the regexp must match for selection of an entry."
  4003. (interactive)
  4004. (org-agenda-manipulate-query ?\{))
  4005. (defun org-agenda-manipulate-query-subtract-re ()
  4006. "Manipulate the query by adding a search regexp with negative selection.
  4007. Negative selection means, regexp must not match for selection of an entry."
  4008. (interactive)
  4009. (org-agenda-manipulate-query ?\}))
  4010. (defun org-agenda-manipulate-query (char)
  4011. (cond
  4012. ((memq org-agenda-type '(timeline agenda))
  4013. (if (y-or-n-p "Re-display with inactive time stamps included? ")
  4014. (let ((org-agenda-include-inactive-timestamps t))
  4015. (org-agenda-redo))
  4016. (error "Abort")))
  4017. ((eq org-agenda-type 'search)
  4018. (org-add-to-string
  4019. 'org-agenda-query-string
  4020. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  4021. (?\{ . " +{}") (?\} . " -{}")))))
  4022. (setq org-agenda-redo-command
  4023. (list 'org-search-view
  4024. org-todo-only
  4025. org-agenda-query-string
  4026. (+ (length org-agenda-query-string)
  4027. (if (member char '(?\{ ?\})) 0 1))))
  4028. (set-register org-agenda-query-register org-agenda-query-string)
  4029. (org-agenda-redo))
  4030. (t (error "Cannot manipulate query for %s-type agenda buffers"
  4031. org-agenda-type))))
  4032. (defun org-add-to-string (var string)
  4033. (set var (concat (symbol-value var) string)))
  4034. (defun org-agenda-goto-date (date)
  4035. "Jump to DATE in agenda."
  4036. (interactive (list (org-read-date)))
  4037. (org-agenda-list nil date))
  4038. (defun org-agenda-goto-today ()
  4039. "Go to today."
  4040. (interactive)
  4041. (org-agenda-check-type t 'timeline 'agenda)
  4042. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  4043. (cond
  4044. (tdpos (goto-char tdpos))
  4045. ((eq org-agenda-type 'agenda)
  4046. (let* ((sd (time-to-days
  4047. (time-subtract (current-time)
  4048. (list 0 (* 3600 org-extend-today-until) 0))))
  4049. (comp (org-agenda-compute-time-span sd org-agenda-span))
  4050. (org-agenda-overriding-arguments org-agenda-last-arguments))
  4051. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  4052. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  4053. (org-agenda-redo)
  4054. (org-agenda-find-same-or-today-or-agenda)))
  4055. (t (error "Cannot find today")))))
  4056. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  4057. (goto-char
  4058. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  4059. (text-property-any (point-min) (point-max) 'org-today t)
  4060. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  4061. (point-min))))
  4062. (defun org-agenda-later (arg)
  4063. "Go forward in time by thee current span.
  4064. With prefix ARG, go forward that many times the current span."
  4065. (interactive "p")
  4066. (org-agenda-check-type t 'agenda)
  4067. (let* ((span org-agenda-span)
  4068. (sd org-starting-day)
  4069. (greg (calendar-gregorian-from-absolute sd))
  4070. (cnt (get-text-property (point) 'org-day-cnt))
  4071. greg2 nd)
  4072. (cond
  4073. ((eq span 'day)
  4074. (setq sd (+ arg sd) nd 1))
  4075. ((eq span 'week)
  4076. (setq sd (+ (* 7 arg) sd) nd 7))
  4077. ((eq span 'month)
  4078. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  4079. sd (calendar-absolute-from-gregorian greg2))
  4080. (setcar greg2 (1+ (car greg2)))
  4081. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  4082. ((eq span 'year)
  4083. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  4084. sd (calendar-absolute-from-gregorian greg2))
  4085. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  4086. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  4087. (let ((org-agenda-overriding-arguments
  4088. (list (car org-agenda-last-arguments) sd nd t)))
  4089. (org-agenda-redo)
  4090. (org-agenda-find-same-or-today-or-agenda cnt))))
  4091. (defun org-agenda-earlier (arg)
  4092. "Go backward in time by the current span.
  4093. With prefix ARG, go backward that many times the current span."
  4094. (interactive "p")
  4095. (org-agenda-later (- arg)))
  4096. (defun org-agenda-day-view (&optional day-of-year)
  4097. "Switch to daily view for agenda.
  4098. With argument DAY-OF-YEAR, switch to that day of the year."
  4099. (interactive "P")
  4100. (setq org-agenda-ndays 1)
  4101. (org-agenda-change-time-span 'day day-of-year))
  4102. (defun org-agenda-week-view (&optional iso-week)
  4103. "Switch to daily view for agenda.
  4104. With argument ISO-WEEK, switch to the corresponding ISO week.
  4105. If ISO-WEEK has more then 2 digits, only the last two encode the
  4106. week. Any digits before this encode a year. So 200712 means
  4107. week 12 of year 2007. Years in the range 1938-2037 can also be
  4108. written as 2-digit years."
  4109. (interactive "P")
  4110. (setq org-agenda-ndays 7)
  4111. (org-agenda-change-time-span 'week iso-week))
  4112. (defun org-agenda-month-view (&optional month)
  4113. "Switch to monthly view for agenda.
  4114. With argument MONTH, switch to that month."
  4115. (interactive "P")
  4116. (org-agenda-change-time-span 'month month))
  4117. (defun org-agenda-year-view (&optional year)
  4118. "Switch to yearly view for agenda.
  4119. With argument YEAR, switch to that year.
  4120. If MONTH has more then 2 digits, only the last two encode the
  4121. month. Any digits before this encode a year. So 200712 means
  4122. December year 2007. Years in the range 1938-2037 can also be
  4123. written as 2-digit years."
  4124. (interactive "P")
  4125. (when year
  4126. (setq year (org-small-year-to-year year)))
  4127. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  4128. (org-agenda-change-time-span 'year year)
  4129. (error "Abort")))
  4130. (defun org-agenda-change-time-span (span &optional n)
  4131. "Change the agenda view to SPAN.
  4132. SPAN may be `day', `week', `month', `year'."
  4133. (org-agenda-check-type t 'agenda)
  4134. (if (and (not n) (equal org-agenda-span span))
  4135. (error "Viewing span is already \"%s\"" span))
  4136. (let* ((sd (or (get-text-property (point) 'day)
  4137. org-starting-day))
  4138. (computed (org-agenda-compute-time-span sd span n))
  4139. (org-agenda-overriding-arguments
  4140. (list (car org-agenda-last-arguments)
  4141. (car computed) (cdr computed) t)))
  4142. (org-agenda-redo)
  4143. (org-agenda-find-same-or-today-or-agenda))
  4144. (org-agenda-set-mode-name)
  4145. (message "Switched to %s view" span))
  4146. (defun org-agenda-compute-time-span (sd span &optional n)
  4147. "Compute starting date and number of days for agenda.
  4148. SPAN may be `day', `week', `month', `year'. The return value
  4149. is a cons cell with the starting date and the number of days,
  4150. so that the date SD will be in that range."
  4151. (let* ((greg (calendar-gregorian-from-absolute sd))
  4152. (dg (nth 1 greg))
  4153. (mg (car greg))
  4154. (yg (nth 2 greg))
  4155. nd w1 y1 m1 thisweek)
  4156. (cond
  4157. ((eq span 'day)
  4158. (when n
  4159. (setq sd (+ (calendar-absolute-from-gregorian
  4160. (list mg 1 yg))
  4161. n -1)))
  4162. (setq nd 1))
  4163. ((eq span 'week)
  4164. (let* ((nt (calendar-day-of-week
  4165. (calendar-gregorian-from-absolute sd)))
  4166. (d (if org-agenda-start-on-weekday
  4167. (- nt org-agenda-start-on-weekday)
  4168. 0)))
  4169. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  4170. (when n
  4171. (require 'cal-iso)
  4172. (setq thisweek (car (calendar-iso-from-absolute sd)))
  4173. (when (> n 99)
  4174. (setq y1 (org-small-year-to-year (/ n 100))
  4175. n (mod n 100)))
  4176. (setq sd
  4177. (calendar-absolute-from-iso
  4178. (list n 1
  4179. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  4180. (setq nd 7)))
  4181. ((eq span 'month)
  4182. (when (and n (> n 99))
  4183. (setq y1 (org-small-year-to-year (/ n 100))
  4184. n (mod n 100)))
  4185. (setq sd (calendar-absolute-from-gregorian
  4186. (list (or n mg) 1 (or y1 yg)))
  4187. nd (- (calendar-absolute-from-gregorian
  4188. (list (1+ (or n mg)) 1 (or y1 yg)))
  4189. sd)))
  4190. ((eq span 'year)
  4191. (setq sd (calendar-absolute-from-gregorian
  4192. (list 1 1 (or n yg)))
  4193. nd (- (calendar-absolute-from-gregorian
  4194. (list 1 1 (1+ (or n yg))))
  4195. sd))))
  4196. (cons sd nd)))
  4197. (defun org-agenda-next-date-line (&optional arg)
  4198. "Jump to the next line indicating a date in agenda buffer."
  4199. (interactive "p")
  4200. (org-agenda-check-type t 'agenda 'timeline)
  4201. (beginning-of-line 1)
  4202. ;; This does not work if user makes date format that starts with a blank
  4203. (if (looking-at "^\\S-") (forward-char 1))
  4204. (if (not (re-search-forward "^\\S-" nil t arg))
  4205. (progn
  4206. (backward-char 1)
  4207. (error "No next date after this line in this buffer")))
  4208. (goto-char (match-beginning 0)))
  4209. (defun org-agenda-previous-date-line (&optional arg)
  4210. "Jump to the previous line indicating a date in agenda buffer."
  4211. (interactive "p")
  4212. (org-agenda-check-type t 'agenda 'timeline)
  4213. (beginning-of-line 1)
  4214. (if (not (re-search-backward "^\\S-" nil t arg))
  4215. (error "No previous date before this line in this buffer")))
  4216. ;; Initialize the highlight
  4217. (defvar org-hl (org-make-overlay 1 1))
  4218. (org-overlay-put org-hl 'face 'highlight)
  4219. (defun org-highlight (begin end &optional buffer)
  4220. "Highlight a region with overlay."
  4221. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  4222. org-hl begin end (or buffer (current-buffer))))
  4223. (defun org-unhighlight ()
  4224. "Detach overlay INDEX."
  4225. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  4226. ;; FIXME this is currently not used.
  4227. (defun org-highlight-until-next-command (beg end &optional buffer)
  4228. "Move the highlight overlay to BEG/END, remove it before the next command."
  4229. (org-highlight beg end buffer)
  4230. (add-hook 'pre-command-hook 'org-unhighlight-once))
  4231. (defun org-unhighlight-once ()
  4232. "Remove the highlight from its position, and this function from the hook."
  4233. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  4234. (org-unhighlight))
  4235. (defun org-agenda-follow-mode ()
  4236. "Toggle follow mode in an agenda buffer."
  4237. (interactive)
  4238. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  4239. (org-agenda-set-mode-name)
  4240. (message "Follow mode is %s"
  4241. (if org-agenda-follow-mode "on" "off")))
  4242. (defun org-agenda-clockreport-mode ()
  4243. "Toggle clocktable mode in an agenda buffer."
  4244. (interactive)
  4245. (org-agenda-check-type t 'agenda)
  4246. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  4247. (org-agenda-set-mode-name)
  4248. (org-agenda-redo)
  4249. (message "Clocktable mode is %s"
  4250. (if org-agenda-clockreport-mode "on" "off")))
  4251. (defun org-agenda-log-mode ()
  4252. "Toggle log mode in an agenda buffer."
  4253. (interactive)
  4254. (org-agenda-check-type t 'agenda 'timeline)
  4255. (setq org-agenda-show-log (not org-agenda-show-log))
  4256. (org-agenda-set-mode-name)
  4257. (org-agenda-redo)
  4258. (message "Log mode is %s"
  4259. (if org-agenda-show-log "on" "off")))
  4260. (defun org-agenda-archives-mode (&optional with-files)
  4261. "Toggle log mode in an agenda buffer."
  4262. (interactive "P")
  4263. (setq org-agenda-archives-mode
  4264. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  4265. (org-agenda-set-mode-name)
  4266. (org-agenda-redo)
  4267. (message
  4268. "%s"
  4269. (cond
  4270. ((eq org-agenda-archives-mode nil)
  4271. "No archives are included")
  4272. ((eq org-agenda-archives-mode 'trees)
  4273. (format "Trees with :%s: tag are included" org-archive-tag))
  4274. ((eq org-agenda-archives-mode t)
  4275. (format "Trees with :%s: tag and all active archive files are included"
  4276. org-archive-tag)))))
  4277. (defun org-agenda-toggle-diary ()
  4278. "Toggle diary inclusion in an agenda buffer."
  4279. (interactive)
  4280. (org-agenda-check-type t 'agenda)
  4281. (setq org-agenda-include-diary (not org-agenda-include-diary))
  4282. (org-agenda-redo)
  4283. (org-agenda-set-mode-name)
  4284. (message "Diary inclusion turned %s"
  4285. (if org-agenda-include-diary "on" "off")))
  4286. (defun org-agenda-toggle-time-grid ()
  4287. "Toggle time grid in an agenda buffer."
  4288. (interactive)
  4289. (org-agenda-check-type t 'agenda)
  4290. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  4291. (org-agenda-redo)
  4292. (org-agenda-set-mode-name)
  4293. (message "Time-grid turned %s"
  4294. (if org-agenda-use-time-grid "on" "off")))
  4295. (defun org-agenda-set-mode-name ()
  4296. "Set the mode name to indicate all the small mode settings."
  4297. (setq mode-name
  4298. (concat "Org-Agenda"
  4299. (if (equal org-agenda-ndays 1) " Day" "")
  4300. (if (equal org-agenda-ndays 7) " Week" "")
  4301. (if org-agenda-follow-mode " Follow" "")
  4302. (if org-agenda-include-diary " Diary" "")
  4303. (if org-agenda-use-time-grid " Grid" "")
  4304. (if org-agenda-show-log " Log" "")
  4305. (if org-agenda-filter
  4306. (concat " {" (mapconcat 'identity org-agenda-filter "") "}")
  4307. "")
  4308. (if org-agenda-archives-mode
  4309. (if (eq org-agenda-archives-mode t)
  4310. " Archives"
  4311. (format " :%s:" org-archive-tag))
  4312. "")
  4313. (if org-agenda-clockreport-mode " Clock" "")))
  4314. (force-mode-line-update))
  4315. (defun org-agenda-post-command-hook ()
  4316. (and (eolp) (not (bolp)) (backward-char 1))
  4317. (setq org-agenda-type
  4318. (or (get-text-property (point) 'org-agenda-type)
  4319. (get-text-property (max (point-min) (1- (point)))
  4320. 'org-agenda-type)))
  4321. (if (and org-agenda-follow-mode
  4322. (get-text-property (point) 'org-marker))
  4323. (org-agenda-show)))
  4324. (defun org-agenda-show-priority ()
  4325. "Show the priority of the current item.
  4326. This priority is composed of the main priority given with the [#A] cookies,
  4327. and by additional input from the age of a schedules or deadline entry."
  4328. (interactive)
  4329. (let* ((pri (get-text-property (point-at-bol) 'priority)))
  4330. (message "Priority is %d" (if pri pri -1000))))
  4331. (defun org-agenda-show-tags ()
  4332. "Show the tags applicable to the current item."
  4333. (interactive)
  4334. (let* ((tags (get-text-property (point-at-bol) 'tags)))
  4335. (if tags
  4336. (message "Tags are :%s:"
  4337. (org-no-properties (mapconcat 'identity tags ":")))
  4338. (message "No tags associated with this line"))))
  4339. (defun org-agenda-goto (&optional highlight)
  4340. "Go to the Org-mode file which contains the item at point."
  4341. (interactive)
  4342. (let* ((marker (or (get-text-property (point) 'org-marker)
  4343. (org-agenda-error)))
  4344. (buffer (marker-buffer marker))
  4345. (pos (marker-position marker)))
  4346. (switch-to-buffer-other-window buffer)
  4347. (widen)
  4348. (goto-char pos)
  4349. (when (org-mode-p)
  4350. (org-show-context 'agenda)
  4351. (save-excursion
  4352. (and (outline-next-heading)
  4353. (org-flag-heading nil)))) ; show the next heading
  4354. (recenter (/ (window-height) 2))
  4355. (run-hooks 'org-agenda-after-show-hook)
  4356. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  4357. (defvar org-agenda-after-show-hook nil
  4358. "Normal hook run after an item has been shown from the agenda.
  4359. Point is in the buffer where the item originated.")
  4360. (defun org-agenda-kill ()
  4361. "Kill the entry or subtree belonging to the current agenda entry."
  4362. (interactive)
  4363. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  4364. (let* ((marker (or (get-text-property (point) 'org-marker)
  4365. (org-agenda-error)))
  4366. (buffer (marker-buffer marker))
  4367. (pos (marker-position marker))
  4368. (type (get-text-property (point) 'type))
  4369. dbeg dend (n 0) conf)
  4370. (org-with-remote-undo buffer
  4371. (with-current-buffer buffer
  4372. (save-excursion
  4373. (goto-char pos)
  4374. (if (and (org-mode-p) (not (member type '("sexp"))))
  4375. (setq dbeg (progn (org-back-to-heading t) (point))
  4376. dend (org-end-of-subtree t t))
  4377. (setq dbeg (point-at-bol)
  4378. dend (min (point-max) (1+ (point-at-eol)))))
  4379. (goto-char dbeg)
  4380. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  4381. (setq conf (or (eq t org-agenda-confirm-kill)
  4382. (and (numberp org-agenda-confirm-kill)
  4383. (> n org-agenda-confirm-kill))))
  4384. (and conf
  4385. (not (y-or-n-p
  4386. (format "Delete entry with %d lines in buffer \"%s\"? "
  4387. n (buffer-name buffer))))
  4388. (error "Abort"))
  4389. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  4390. (with-current-buffer buffer (delete-region dbeg dend))
  4391. (message "Agenda item and source killed"))))
  4392. (defun org-agenda-archive ()
  4393. "Archive the entry or subtree belonging to the current agenda entry."
  4394. (interactive)
  4395. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  4396. (let* ((marker (or (get-text-property (point) 'org-marker)
  4397. (org-agenda-error)))
  4398. (buffer (marker-buffer marker))
  4399. (pos (marker-position marker)))
  4400. (org-with-remote-undo buffer
  4401. (with-current-buffer buffer
  4402. (if (org-mode-p)
  4403. (save-excursion
  4404. (goto-char pos)
  4405. (org-remove-subtree-entries-from-agenda)
  4406. (org-back-to-heading t)
  4407. (org-archive-subtree))
  4408. (error "Archiving works only in Org-mode files"))))))
  4409. (defun org-agenda-archive-to-archive-sibling ()
  4410. "Move the entry to the archive sibling."
  4411. (interactive)
  4412. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  4413. (let* ((marker (or (get-text-property (point) 'org-marker)
  4414. (org-agenda-error)))
  4415. (buffer (marker-buffer marker))
  4416. (pos (marker-position marker)))
  4417. (org-with-remote-undo buffer
  4418. (with-current-buffer buffer
  4419. (if (org-mode-p)
  4420. (save-excursion
  4421. (goto-char pos)
  4422. (org-remove-subtree-entries-from-agenda)
  4423. (org-back-to-heading t)
  4424. (org-archive-to-archive-sibling))
  4425. (error "Archiving works only in Org-mode files"))))))
  4426. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  4427. "Remove all lines in the agenda that correspond to a given subtree.
  4428. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  4429. If this information is not given, the function uses the tree at point."
  4430. (let ((buf (or buf (current-buffer))) m p)
  4431. (save-excursion
  4432. (unless (and beg end)
  4433. (org-back-to-heading t)
  4434. (setq beg (point))
  4435. (org-end-of-subtree t)
  4436. (setq end (point)))
  4437. (set-buffer (get-buffer org-agenda-buffer-name))
  4438. (save-excursion
  4439. (goto-char (point-max))
  4440. (beginning-of-line 1)
  4441. (while (not (bobp))
  4442. (when (and (setq m (get-text-property (point) 'org-marker))
  4443. (equal buf (marker-buffer m))
  4444. (setq p (marker-position m))
  4445. (>= p beg)
  4446. (<= p end))
  4447. (let ((inhibit-read-only t))
  4448. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  4449. (beginning-of-line 0))))))
  4450. (defun org-agenda-open-link ()
  4451. "Follow the link in the current line, if any."
  4452. (interactive)
  4453. (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
  4454. (save-excursion
  4455. (save-restriction
  4456. (narrow-to-region (point-at-bol) (point-at-eol))
  4457. (org-open-at-point))))
  4458. (defun org-agenda-copy-local-variable (var)
  4459. "Get a variable from a referenced buffer and install it here."
  4460. (let ((m (get-text-property (point) 'org-marker)))
  4461. (when (and m (buffer-live-p (marker-buffer m)))
  4462. (org-set-local var (with-current-buffer (marker-buffer m)
  4463. (symbol-value var))))))
  4464. (defun org-agenda-switch-to (&optional delete-other-windows)
  4465. "Go to the Org-mode file which contains the item at point."
  4466. (interactive)
  4467. (let* ((marker (or (get-text-property (point) 'org-marker)
  4468. (org-agenda-error)))
  4469. (buffer (marker-buffer marker))
  4470. (pos (marker-position marker)))
  4471. (switch-to-buffer buffer)
  4472. (and delete-other-windows (delete-other-windows))
  4473. (widen)
  4474. (goto-char pos)
  4475. (when (org-mode-p)
  4476. (org-show-context 'agenda)
  4477. (save-excursion
  4478. (and (outline-next-heading)
  4479. (org-flag-heading nil)))))) ; show the next heading
  4480. (defun org-agenda-goto-mouse (ev)
  4481. "Go to the Org-mode file which contains the item at the mouse click."
  4482. (interactive "e")
  4483. (mouse-set-point ev)
  4484. (org-agenda-goto))
  4485. (defun org-agenda-show ()
  4486. "Display the Org-mode file which contains the item at point."
  4487. (interactive)
  4488. (let ((win (selected-window)))
  4489. (org-agenda-goto t)
  4490. (select-window win)))
  4491. (defun org-agenda-recenter (arg)
  4492. "Display the Org-mode file which contains the item at point and recenter."
  4493. (interactive "P")
  4494. (let ((win (selected-window)))
  4495. (org-agenda-goto t)
  4496. (recenter arg)
  4497. (select-window win)))
  4498. (defun org-agenda-show-mouse (ev)
  4499. "Display the Org-mode file which contains the item at the mouse click."
  4500. (interactive "e")
  4501. (mouse-set-point ev)
  4502. (org-agenda-show))
  4503. (defun org-agenda-check-no-diary ()
  4504. "Check if the entry is a diary link and abort if yes."
  4505. (if (get-text-property (point) 'org-agenda-diary-link)
  4506. (org-agenda-error)))
  4507. (defun org-agenda-error ()
  4508. (error "Command not allowed in this line"))
  4509. (defun org-agenda-tree-to-indirect-buffer ()
  4510. "Show the subtree corresponding to the current entry in an indirect buffer.
  4511. This calls the command `org-tree-to-indirect-buffer' from the original
  4512. Org-mode buffer.
  4513. With numerical prefix arg ARG, go up to this level and then take that tree.
  4514. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  4515. dedicated frame)."
  4516. (interactive)
  4517. (org-agenda-check-no-diary)
  4518. (let* ((marker (or (get-text-property (point) 'org-marker)
  4519. (org-agenda-error)))
  4520. (buffer (marker-buffer marker))
  4521. (pos (marker-position marker)))
  4522. (with-current-buffer buffer
  4523. (save-excursion
  4524. (goto-char pos)
  4525. (call-interactively 'org-tree-to-indirect-buffer)))))
  4526. (defvar org-last-heading-marker (make-marker)
  4527. "Marker pointing to the headline that last changed its TODO state
  4528. by a remote command from the agenda.")
  4529. (defun org-agenda-todo-nextset ()
  4530. "Switch TODO entry to next sequence."
  4531. (interactive)
  4532. (org-agenda-todo 'nextset))
  4533. (defun org-agenda-todo-previousset ()
  4534. "Switch TODO entry to previous sequence."
  4535. (interactive)
  4536. (org-agenda-todo 'previousset))
  4537. (defun org-agenda-todo (&optional arg)
  4538. "Cycle TODO state of line at point, also in Org-mode file.
  4539. This changes the line at point, all other lines in the agenda referring to
  4540. the same tree node, and the headline of the tree node in the Org-mode file."
  4541. (interactive "P")
  4542. (org-agenda-check-no-diary)
  4543. (let* ((col (current-column))
  4544. (marker (or (get-text-property (point) 'org-marker)
  4545. (org-agenda-error)))
  4546. (buffer (marker-buffer marker))
  4547. (pos (marker-position marker))
  4548. (hdmarker (get-text-property (point) 'org-hd-marker))
  4549. (inhibit-read-only t)
  4550. newhead)
  4551. (org-with-remote-undo buffer
  4552. (with-current-buffer buffer
  4553. (widen)
  4554. (goto-char pos)
  4555. (org-show-context 'agenda)
  4556. (save-excursion
  4557. (and (outline-next-heading)
  4558. (org-flag-heading nil))) ; show the next heading
  4559. (org-todo arg)
  4560. (and (bolp) (forward-char 1))
  4561. (setq newhead (org-get-heading))
  4562. (save-excursion
  4563. (org-back-to-heading)
  4564. (move-marker org-last-heading-marker (point))))
  4565. (beginning-of-line 1)
  4566. (save-excursion
  4567. (org-agenda-change-all-lines newhead hdmarker 'fixface))
  4568. (org-move-to-column col))))
  4569. (defun org-agenda-add-note (&optional arg)
  4570. "Add a time-stamped note to the entry at point."
  4571. (interactive "P")
  4572. (org-agenda-check-no-diary)
  4573. (let* ((marker (or (get-text-property (point) 'org-marker)
  4574. (org-agenda-error)))
  4575. (buffer (marker-buffer marker))
  4576. (pos (marker-position marker))
  4577. (hdmarker (get-text-property (point) 'org-hd-marker))
  4578. (inhibit-read-only t))
  4579. (with-current-buffer buffer
  4580. (widen)
  4581. (goto-char pos)
  4582. (org-show-context 'agenda)
  4583. (save-excursion
  4584. (and (outline-next-heading)
  4585. (org-flag-heading nil))) ; show the next heading
  4586. (org-add-note))))
  4587. (defun org-agenda-change-all-lines (newhead hdmarker &optional fixface)
  4588. "Change all lines in the agenda buffer which match HDMARKER.
  4589. The new content of the line will be NEWHEAD (as modified by
  4590. `org-format-agenda-item'). HDMARKER is checked with
  4591. `equal' against all `org-hd-marker' text properties in the file.
  4592. If FIXFACE is non-nil, the face of each item is modified acording to
  4593. the new TODO state."
  4594. (let* ((inhibit-read-only t)
  4595. props m pl undone-face done-face finish new dotime cat tags)
  4596. (save-excursion
  4597. (goto-char (point-max))
  4598. (beginning-of-line 1)
  4599. (while (not finish)
  4600. (setq finish (bobp))
  4601. (when (and (setq m (get-text-property (point) 'org-hd-marker))
  4602. (equal m hdmarker))
  4603. (setq props (text-properties-at (point))
  4604. dotime (get-text-property (point) 'dotime)
  4605. cat (get-text-property (point) 'org-category)
  4606. tags (get-text-property (point) 'tags)
  4607. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  4608. pl (get-text-property (point) 'prefix-length)
  4609. undone-face (get-text-property (point) 'undone-face)
  4610. done-face (get-text-property (point) 'done-face))
  4611. (org-move-to-column pl)
  4612. (cond
  4613. ((equal new "")
  4614. (beginning-of-line 1)
  4615. (and (looking-at ".*\n?") (replace-match "")))
  4616. ((looking-at ".*")
  4617. (replace-match new t t)
  4618. (beginning-of-line 1)
  4619. (add-text-properties (point-at-bol) (point-at-eol) props)
  4620. (when fixface
  4621. (add-text-properties
  4622. (point-at-bol) (point-at-eol)
  4623. (list 'face
  4624. (if org-last-todo-state-is-todo
  4625. undone-face done-face))))
  4626. (org-agenda-highlight-todo 'line)
  4627. (beginning-of-line 1))
  4628. (t (error "Line update did not work"))))
  4629. (beginning-of-line 0)))
  4630. (org-finalize-agenda)))
  4631. (defun org-agenda-align-tags (&optional line)
  4632. "Align all tags in agenda items to `org-agenda-tags-column'."
  4633. (let ((inhibit-read-only t) l c)
  4634. (save-excursion
  4635. (goto-char (if line (point-at-bol) (point-min)))
  4636. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4637. (if line (point-at-eol) nil) t)
  4638. (add-text-properties
  4639. (match-beginning 2) (match-end 2)
  4640. (list 'face (delq nil (adjoin 'org-tag
  4641. (let ((prop (get-text-property
  4642. (match-beginning 2) 'face)))
  4643. (if (listp prop)
  4644. prop
  4645. (list prop)))))))
  4646. (setq l (- (match-end 2) (match-beginning 2))
  4647. c (if (< org-agenda-tags-column 0)
  4648. (- (abs org-agenda-tags-column) l)
  4649. org-agenda-tags-column))
  4650. (delete-region (match-beginning 1) (match-end 1))
  4651. (goto-char (match-beginning 1))
  4652. (insert (org-add-props
  4653. (make-string (max 1 (- c (current-column))) ?\ )
  4654. (text-properties-at (point))))))))
  4655. (defun org-agenda-priority-up ()
  4656. "Increase the priority of line at point, also in Org-mode file."
  4657. (interactive)
  4658. (org-agenda-priority 'up))
  4659. (defun org-agenda-priority-down ()
  4660. "Decrease the priority of line at point, also in Org-mode file."
  4661. (interactive)
  4662. (org-agenda-priority 'down))
  4663. (defun org-agenda-priority (&optional force-direction)
  4664. "Set the priority of line at point, also in Org-mode file.
  4665. This changes the line at point, all other lines in the agenda referring to
  4666. the same tree node, and the headline of the tree node in the Org-mode file."
  4667. (interactive)
  4668. (org-agenda-check-no-diary)
  4669. (let* ((marker (or (get-text-property (point) 'org-marker)
  4670. (org-agenda-error)))
  4671. (hdmarker (get-text-property (point) 'org-hd-marker))
  4672. (buffer (marker-buffer hdmarker))
  4673. (pos (marker-position hdmarker))
  4674. (inhibit-read-only t)
  4675. newhead)
  4676. (org-with-remote-undo buffer
  4677. (with-current-buffer buffer
  4678. (widen)
  4679. (goto-char pos)
  4680. (org-show-context 'agenda)
  4681. (save-excursion
  4682. (and (outline-next-heading)
  4683. (org-flag-heading nil))) ; show the next heading
  4684. (funcall 'org-priority force-direction)
  4685. (end-of-line 1)
  4686. (setq newhead (org-get-heading)))
  4687. (org-agenda-change-all-lines newhead hdmarker)
  4688. (beginning-of-line 1))))
  4689. ;; FIXME: should fix the tags property of the agenda line.
  4690. (defun org-agenda-set-tags ()
  4691. "Set tags for the current headline."
  4692. (interactive)
  4693. (org-agenda-check-no-diary)
  4694. (if (and (org-region-active-p) (interactive-p))
  4695. (call-interactively 'org-change-tag-in-region)
  4696. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  4697. (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
  4698. (org-agenda-error)))
  4699. (buffer (marker-buffer hdmarker))
  4700. (pos (marker-position hdmarker))
  4701. (inhibit-read-only t)
  4702. newhead)
  4703. (org-with-remote-undo buffer
  4704. (with-current-buffer buffer
  4705. (widen)
  4706. (goto-char pos)
  4707. (save-excursion
  4708. (org-show-context 'agenda))
  4709. (save-excursion
  4710. (and (outline-next-heading)
  4711. (org-flag-heading nil))) ; show the next heading
  4712. (goto-char pos)
  4713. (call-interactively 'org-set-tags)
  4714. (end-of-line 1)
  4715. (setq newhead (org-get-heading)))
  4716. (org-agenda-change-all-lines newhead hdmarker)
  4717. (beginning-of-line 1)))))
  4718. (defun org-agenda-toggle-archive-tag ()
  4719. "Toggle the archive tag for the current entry."
  4720. (interactive)
  4721. (org-agenda-check-no-diary)
  4722. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  4723. (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
  4724. (org-agenda-error)))
  4725. (buffer (marker-buffer hdmarker))
  4726. (pos (marker-position hdmarker))
  4727. (inhibit-read-only t)
  4728. newhead)
  4729. (org-with-remote-undo buffer
  4730. (with-current-buffer buffer
  4731. (widen)
  4732. (goto-char pos)
  4733. (org-show-context 'agenda)
  4734. (save-excursion
  4735. (and (outline-next-heading)
  4736. (org-flag-heading nil))) ; show the next heading
  4737. (call-interactively 'org-toggle-archive-tag)
  4738. (end-of-line 1)
  4739. (setq newhead (org-get-heading)))
  4740. (org-agenda-change-all-lines newhead hdmarker)
  4741. (beginning-of-line 1))))
  4742. (defun org-agenda-date-later (arg &optional what)
  4743. "Change the date of this item to one day later."
  4744. (interactive "p")
  4745. (org-agenda-check-type t 'agenda 'timeline)
  4746. (org-agenda-check-no-diary)
  4747. (let* ((marker (or (get-text-property (point) 'org-marker)
  4748. (org-agenda-error)))
  4749. (buffer (marker-buffer marker))
  4750. (pos (marker-position marker)))
  4751. (org-with-remote-undo buffer
  4752. (with-current-buffer buffer
  4753. (widen)
  4754. (goto-char pos)
  4755. (if (not (org-at-timestamp-p))
  4756. (error "Cannot find time stamp"))
  4757. (org-timestamp-change arg (or what 'day)))
  4758. (org-agenda-show-new-time marker org-last-changed-timestamp))
  4759. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  4760. (defun org-agenda-date-earlier (arg &optional what)
  4761. "Change the date of this item to one day earlier."
  4762. (interactive "p")
  4763. (org-agenda-date-later (- arg) what))
  4764. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  4765. "Show new date stamp via text properties."
  4766. ;; We use text properties to make this undoable
  4767. (let ((inhibit-read-only t)
  4768. (buffer-invisibility-spec))
  4769. (setq stamp (concat " " prefix " => " stamp))
  4770. (save-excursion
  4771. (goto-char (point-max))
  4772. (while (not (bobp))
  4773. (when (equal marker (get-text-property (point) 'org-marker))
  4774. (org-move-to-column (- (window-width) (length stamp)) t)
  4775. (org-agenda-fix-tags-filter-overlays-at (point))
  4776. (if (featurep 'xemacs)
  4777. ;; Use `duplicable' property to trigger undo recording
  4778. (let ((ex (make-extent nil nil))
  4779. (gl (make-glyph stamp)))
  4780. (set-glyph-face gl 'secondary-selection)
  4781. (set-extent-properties
  4782. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  4783. (insert-extent ex (1- (point)) (point-at-eol)))
  4784. (add-text-properties
  4785. (1- (point)) (point-at-eol)
  4786. (list 'display (org-add-props stamp nil
  4787. 'face 'secondary-selection))))
  4788. (beginning-of-line 1))
  4789. (beginning-of-line 0)))))
  4790. (defun org-agenda-date-prompt (arg)
  4791. "Change the date of this item. Date is prompted for, with default today.
  4792. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  4793. be used to request time specification in the time stamp."
  4794. (interactive "P")
  4795. (org-agenda-check-type t 'agenda 'timeline)
  4796. (org-agenda-check-no-diary)
  4797. (let* ((marker (or (get-text-property (point) 'org-marker)
  4798. (org-agenda-error)))
  4799. (buffer (marker-buffer marker))
  4800. (pos (marker-position marker)))
  4801. (org-with-remote-undo buffer
  4802. (with-current-buffer buffer
  4803. (widen)
  4804. (goto-char pos)
  4805. (if (not (org-at-timestamp-p))
  4806. (error "Cannot find time stamp"))
  4807. (org-time-stamp arg)
  4808. (message "Time stamp changed to %s" org-last-changed-timestamp)))))
  4809. (defun org-agenda-schedule (arg)
  4810. "Schedule the item at point."
  4811. (interactive "P")
  4812. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  4813. (org-agenda-check-no-diary)
  4814. (let* ((marker (or (get-text-property (point) 'org-marker)
  4815. (org-agenda-error)))
  4816. (type (marker-insertion-type marker))
  4817. (buffer (marker-buffer marker))
  4818. (pos (marker-position marker))
  4819. (org-insert-labeled-timestamps-at-point nil)
  4820. ts)
  4821. (when type (message "%s" type) (sit-for 3))
  4822. (set-marker-insertion-type marker t)
  4823. (org-with-remote-undo buffer
  4824. (with-current-buffer buffer
  4825. (widen)
  4826. (goto-char pos)
  4827. (setq ts (org-schedule arg)))
  4828. (org-agenda-show-new-time marker ts "S"))
  4829. (message "Item scheduled for %s" ts)))
  4830. (defun org-agenda-deadline (arg)
  4831. "Schedule the item at point."
  4832. (interactive "P")
  4833. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  4834. (org-agenda-check-no-diary)
  4835. (let* ((marker (or (get-text-property (point) 'org-marker)
  4836. (org-agenda-error)))
  4837. (buffer (marker-buffer marker))
  4838. (pos (marker-position marker))
  4839. (org-insert-labeled-timestamps-at-point nil)
  4840. ts)
  4841. (org-with-remote-undo buffer
  4842. (with-current-buffer buffer
  4843. (widen)
  4844. (goto-char pos)
  4845. (setq ts (org-deadline arg)))
  4846. (org-agenda-show-new-time marker ts "S"))
  4847. (message "Deadline for this item set to %s" ts)))
  4848. (defun org-agenda-action ()
  4849. "Select entry for agenda action, or execute an agenda action.
  4850. This command prompts for another letter. Valid inputs are:
  4851. m Mark the entry at point for an agenda action
  4852. s Schedule the marked entry to the date at the cursor
  4853. d Set the deadline of the marked entry to the date at the cursor
  4854. r Call `org-remember' with cursor date as the default date
  4855. SPC Show marked entry in other window
  4856. TAB Visit marked entry in other window
  4857. The cursor may be at a date in the calendar, or in the Org agenda."
  4858. (interactive)
  4859. (let (pos ans)
  4860. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  4861. (setq ans (read-char-exclusive))
  4862. (cond
  4863. ((equal ans ?m)
  4864. ;; Mark this entry
  4865. (if (eq major-mode 'org-agenda-mode)
  4866. (let ((m (or (get-text-property (point) 'org-hd-marker)
  4867. (get-text-property (point) 'org-marker))))
  4868. (if m
  4869. (progn
  4870. (move-marker org-agenda-action-marker
  4871. (marker-position m) (marker-buffer m))
  4872. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  4873. (error "Don't know which entry to mark")))
  4874. (error "This command works only in the agenda")))
  4875. ((equal ans ?s)
  4876. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  4877. ((equal ans ?d)
  4878. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  4879. ((equal ans ?r)
  4880. (org-agenda-do-action '(org-remember) t))
  4881. ((equal ans ?\ )
  4882. (let ((cw (selected-window)))
  4883. (org-switch-to-buffer-other-window
  4884. (marker-buffer org-agenda-action-marker))
  4885. (goto-char org-agenda-action-marker)
  4886. (org-show-context 'agenda)
  4887. (select-window cw)))
  4888. ((equal ans ?\C-i)
  4889. (org-switch-to-buffer-other-window
  4890. (marker-buffer org-agenda-action-marker))
  4891. (goto-char org-agenda-action-marker)
  4892. (org-show-context 'agenda))
  4893. (t (error "Invalid agenda action %c" ans)))))
  4894. (defun org-agenda-do-action (form &optional current-buffer)
  4895. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  4896. (let ((org-overriding-default-time (org-get-cursor-date)))
  4897. (if current-buffer
  4898. (eval form)
  4899. (if (not (marker-buffer org-agenda-action-marker))
  4900. (error "No entry has bee selected for agenda action")
  4901. (with-current-buffer (marker-buffer org-agenda-action-marker)
  4902. (save-excursion
  4903. (save-restriction
  4904. (widen)
  4905. (goto-char org-agenda-action-marker)
  4906. (eval form))))))))
  4907. (defun org-agenda-clock-in (&optional arg)
  4908. "Start the clock on the currently selected item."
  4909. (interactive "P")
  4910. (org-agenda-check-no-diary)
  4911. (if (equal arg '(4))
  4912. (org-clock-in arg)
  4913. (let* ((marker (or (get-text-property (point) 'org-marker)
  4914. (org-agenda-error)))
  4915. (hdmarker (or (get-text-property (point) 'org-hd-marker)
  4916. marker))
  4917. (pos (marker-position marker))
  4918. newhead)
  4919. (org-with-remote-undo (marker-buffer marker)
  4920. (with-current-buffer (marker-buffer marker)
  4921. (widen)
  4922. (goto-char pos)
  4923. (org-show-context 'agenda)
  4924. (org-show-entry)
  4925. (org-cycle-hide-drawers 'children)
  4926. (org-clock-in arg)
  4927. (setq newhead (org-get-heading)))
  4928. (org-agenda-change-all-lines newhead hdmarker t)))))
  4929. (defun org-agenda-clock-out (&optional arg)
  4930. "Stop the currently running clock."
  4931. (interactive "P")
  4932. (unless (marker-buffer org-clock-marker)
  4933. (error "No running clock"))
  4934. (org-with-remote-undo (marker-buffer org-clock-marker)
  4935. (org-clock-out)))
  4936. (defun org-agenda-clock-cancel (&optional arg)
  4937. "Cancel the currently running clock."
  4938. (interactive "P")
  4939. (unless (marker-buffer org-clock-marker)
  4940. (error "No running clock"))
  4941. (org-with-remote-undo (marker-buffer org-clock-marker)
  4942. (org-clock-cancel)))
  4943. (defun org-agenda-diary-entry ()
  4944. "Make a diary entry, like the `i' command from the calendar.
  4945. All the standard commands work: block, weekly etc."
  4946. (interactive)
  4947. (org-agenda-check-type t 'agenda 'timeline)
  4948. (require 'diary-lib)
  4949. (let* ((char (progn
  4950. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  4951. (read-char-exclusive)))
  4952. (cmd (cdr (assoc char
  4953. '((?d . insert-diary-entry)
  4954. (?w . insert-weekly-diary-entry)
  4955. (?m . insert-monthly-diary-entry)
  4956. (?y . insert-yearly-diary-entry)
  4957. (?a . insert-anniversary-diary-entry)
  4958. (?b . insert-block-diary-entry)
  4959. (?c . insert-cyclic-diary-entry)))))
  4960. (oldf (symbol-function 'calendar-cursor-to-date))
  4961. ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  4962. (point (point))
  4963. (mark (or (mark t) (point))))
  4964. (unless cmd
  4965. (error "No command associated with <%c>" char))
  4966. (unless (and (get-text-property point 'day)
  4967. (or (not (equal ?b char))
  4968. (get-text-property mark 'day)))
  4969. (error "Don't know which date to use for diary entry"))
  4970. ;; We implement this by hacking the `calendar-cursor-to-date' function
  4971. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  4972. (let ((calendar-mark-ring
  4973. (list (calendar-gregorian-from-absolute
  4974. (or (get-text-property mark 'day)
  4975. (get-text-property point 'day))))))
  4976. (unwind-protect
  4977. (progn
  4978. (fset 'calendar-cursor-to-date
  4979. (lambda (&optional error dummy)
  4980. (calendar-gregorian-from-absolute
  4981. (get-text-property point 'day))))
  4982. (call-interactively cmd))
  4983. (fset 'calendar-cursor-to-date oldf)))))
  4984. (defun org-agenda-execute-calendar-command (cmd)
  4985. "Execute a calendar command from the agenda, with the date associated to
  4986. the cursor position."
  4987. (org-agenda-check-type t 'agenda 'timeline)
  4988. (require 'diary-lib)
  4989. (unless (get-text-property (point) 'day)
  4990. (error "Don't know which date to use for calendar command"))
  4991. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  4992. (point (point))
  4993. (date (calendar-gregorian-from-absolute
  4994. (get-text-property point 'day)))
  4995. ;; the following 2 vars are needed in the calendar
  4996. (displayed-month (car date))
  4997. (displayed-year (nth 2 date)))
  4998. (unwind-protect
  4999. (progn
  5000. (fset 'calendar-cursor-to-date
  5001. (lambda (&optional error dummy)
  5002. (calendar-gregorian-from-absolute
  5003. (get-text-property point 'day))))
  5004. (call-interactively cmd))
  5005. (fset 'calendar-cursor-to-date oldf))))
  5006. (defun org-agenda-phases-of-moon ()
  5007. "Display the phases of the moon for the 3 months around the cursor date."
  5008. (interactive)
  5009. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  5010. (defun org-agenda-holidays ()
  5011. "Display the holidays for the 3 months around the cursor date."
  5012. (interactive)
  5013. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  5014. (defvar calendar-longitude)
  5015. (defvar calendar-latitude)
  5016. (defvar calendar-location-name)
  5017. (defun org-agenda-sunrise-sunset (arg)
  5018. "Display sunrise and sunset for the cursor date.
  5019. Latitude and longitude can be specified with the variables
  5020. `calendar-latitude' and `calendar-longitude'. When called with prefix
  5021. argument, latitude and longitude will be prompted for."
  5022. (interactive "P")
  5023. (require 'solar)
  5024. (let ((calendar-longitude (if arg nil calendar-longitude))
  5025. (calendar-latitude (if arg nil calendar-latitude))
  5026. (calendar-location-name
  5027. (if arg "the given coordinates" calendar-location-name)))
  5028. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  5029. (defun org-agenda-goto-calendar ()
  5030. "Open the Emacs calendar with the date at the cursor."
  5031. (interactive)
  5032. (org-agenda-check-type t 'agenda 'timeline)
  5033. (let* ((day (or (get-text-property (point) 'day)
  5034. (error "Don't know which date to open in calendar")))
  5035. (date (calendar-gregorian-from-absolute day))
  5036. (calendar-move-hook nil)
  5037. (calendar-view-holidays-initially-flag nil)
  5038. (calendar-view-diary-initially-flag nil)
  5039. (view-calendar-holidays-initially nil)
  5040. (calendar-view-diary-initially-flag nil)
  5041. (calendar-view-holidays-initially-flag nil)
  5042. (view-diary-entries-initially nil))
  5043. (calendar)
  5044. (calendar-goto-date date)))
  5045. ;;;###autoload
  5046. (defun org-calendar-goto-agenda ()
  5047. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  5048. This is a command that has to be installed in `calendar-mode-map'."
  5049. (interactive)
  5050. (org-agenda-list nil (calendar-absolute-from-gregorian
  5051. (calendar-cursor-to-date))
  5052. nil))
  5053. (defun org-agenda-convert-date ()
  5054. (interactive)
  5055. (org-agenda-check-type t 'agenda 'timeline)
  5056. (let ((day (get-text-property (point) 'day))
  5057. date s)
  5058. (unless day
  5059. (error "Don't know which date to convert"))
  5060. (setq date (calendar-gregorian-from-absolute day))
  5061. (setq s (concat
  5062. "Gregorian: " (calendar-date-string date) "\n"
  5063. "ISO: " (calendar-iso-date-string date) "\n"
  5064. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  5065. "Julian: " (calendar-julian-date-string date) "\n"
  5066. "Astron. JD: " (calendar-astro-date-string date)
  5067. " (Julian date number at noon UTC)\n"
  5068. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  5069. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  5070. "French: " (calendar-french-date-string date) "\n"
  5071. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  5072. "Mayan: " (calendar-mayan-date-string date) "\n"
  5073. "Coptic: " (calendar-coptic-date-string date) "\n"
  5074. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  5075. "Persian: " (calendar-persian-date-string date) "\n"
  5076. "Chinese: " (calendar-chinese-date-string date) "\n"))
  5077. (with-output-to-temp-buffer "*Dates*"
  5078. (princ s))
  5079. (if (fboundp 'fit-window-to-buffer)
  5080. (fit-window-to-buffer (get-buffer-window "*Dates*")))))
  5081. ;;; Appointment reminders
  5082. (defvar appt-time-msg-list)
  5083. ;;;###autoload
  5084. (defun org-agenda-to-appt (&optional refresh filter)
  5085. "Activate appointments found in `org-agenda-files'.
  5086. With a \\[universal-argument] prefix, refresh the list of
  5087. appointements.
  5088. If FILTER is t, interactively prompt the user for a regular
  5089. expression, and filter out entries that don't match it.
  5090. If FILTER is a string, use this string as a regular expression
  5091. for filtering entries out.
  5092. FILTER can also be an alist with the car of each cell being
  5093. either 'headline or 'category. For example:
  5094. '((headline \"IMPORTANT\")
  5095. (category \"Work\"))
  5096. will only add headlines containing IMPORTANT or headlines
  5097. belonging to the \"Work\" category."
  5098. (interactive "P")
  5099. (require 'calendar)
  5100. (if refresh (setq appt-time-msg-list nil))
  5101. (if (eq filter t)
  5102. (setq filter (read-from-minibuffer "Regexp filter: ")))
  5103. (let* ((cnt 0) ; count added events
  5104. (org-agenda-new-buffers nil)
  5105. (org-deadline-warning-days 0)
  5106. (today (org-date-to-gregorian
  5107. (time-to-days (current-time))))
  5108. (files (org-agenda-files 'unrestricted)) entries file)
  5109. ;; Get all entries which may contain an appt
  5110. (while (setq file (pop files))
  5111. (setq entries
  5112. (append entries
  5113. (org-agenda-get-day-entries
  5114. file today :timestamp :scheduled :deadline))))
  5115. (setq entries (delq nil entries))
  5116. ;; Map thru entries and find if we should filter them out
  5117. (mapc
  5118. (lambda(x)
  5119. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  5120. (cat (get-text-property 1 'org-category x))
  5121. (tod (get-text-property 1 'time-of-day x))
  5122. (ok (or (null filter)
  5123. (and (stringp filter) (string-match filter evt))
  5124. (and (listp filter)
  5125. (or (string-match
  5126. (cadr (assoc 'category filter)) cat)
  5127. (string-match
  5128. (cadr (assoc 'headline filter)) evt))))))
  5129. ;; FIXME: Shall we remove text-properties for the appt text?
  5130. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  5131. (when (and ok tod)
  5132. (setq tod (concat "00" (number-to-string tod))
  5133. tod (when (string-match
  5134. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  5135. (concat (match-string 1 tod) ":"
  5136. (match-string 2 tod))))
  5137. (appt-add tod evt)
  5138. (setq cnt (1+ cnt))))) entries)
  5139. (org-release-buffers org-agenda-new-buffers)
  5140. (if (eq cnt 0)
  5141. (message "No event to add")
  5142. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  5143. (defun org-agenda-todayp (date)
  5144. "Does DATE mean today, when considering `org-extend-today-until'?"
  5145. (let (today h)
  5146. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  5147. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  5148. (setq h (nth 2 (decode-time (current-time))))
  5149. (or (and (>= h org-extend-today-until)
  5150. (= date today))
  5151. (and (< h org-extend-today-until)
  5152. (= date (1- today))))))
  5153. (provide 'org-agenda)
  5154. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  5155. ;;; org-agenda.el ends here