org-agenda.el 204 KB

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