org-agenda.el 225 KB

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