org-agenda.el 186 KB

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