org-agenda.el 200 KB

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