org-agenda.el 200 KB

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