org-agenda.el 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  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: 7.5
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (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-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defcustom org-agenda-skip-function-global nil
  472. "Function to be called at each match during agenda construction.
  473. If this function returns nil, the current match should not be skipped.
  474. If the function decided to skip an agenda match, is must return the
  475. buffer position from which the search should be continued.
  476. This may also be a Lisp form, which will be evaluated.
  477. This variable will be applied to every agenda match, including
  478. tags/property searches and TODO lists. So try to make the test function
  479. do its checking as efficiently as possible. To implement a skipping
  480. condition just for specific agenda commands, use the variable
  481. `org-agenda-skip-function' which can be set in the options section
  482. of custom agenda commands."
  483. :group 'org-agenda-skip
  484. :type 'sexp)
  485. (defgroup org-agenda-daily/weekly nil
  486. "Options concerning the daily/weekly agenda."
  487. :tag "Org Agenda Daily/Weekly"
  488. :group 'org-agenda)
  489. (defgroup org-agenda-todo-list nil
  490. "Options concerning the global todo list agenda view."
  491. :tag "Org Agenda Todo List"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-match-view nil
  494. "Options concerning the general tags/property/todo match agenda view."
  495. :tag "Org Agenda Match View"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-search-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defvar org-agenda-archives-mode nil
  502. "Non-nil means the agenda will include archived items.
  503. If this is the symbol `trees', trees in the selected agenda scope
  504. that are marked with the ARCHIVE tag will be included anyway. When this is
  505. t, also all archive files associated with the current selection of agenda
  506. files will be included.")
  507. (defcustom org-agenda-skip-comment-trees t
  508. "Non-nil means skip trees that start with the COMMENT keyword.
  509. When nil, these trees are also scanned by agenda commands."
  510. :group 'org-agenda-skip
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-list-sublevels t
  513. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  514. When nil, the sublevels of a TODO entry are not checked, resulting in
  515. potentially much shorter TODO lists."
  516. :group 'org-agenda-skip
  517. :group 'org-agenda-todo-list
  518. :type 'boolean)
  519. (defcustom org-agenda-todo-ignore-with-date nil
  520. "Non-nil means don't show entries with a date in the global todo list.
  521. You can use this if you prefer to mark mere appointments with a TODO keyword,
  522. but don't want them to show up in the TODO list.
  523. When this is set, it also covers deadlines and scheduled items, the settings
  524. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  525. will be ignored.
  526. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type 'boolean)
  530. (defcustom org-agenda-todo-ignore-timestamp nil
  531. "Non-nil means don't show entries with a timestamp.
  532. This applies when creating the global todo list.
  533. Valid values are:
  534. past Don't show entries for today or in the past.
  535. future Don't show entries with a timestamp in the future.
  536. The idea behind this is that if it has a future
  537. timestamp, you don't want to think about it until the
  538. date.
  539. all Don't show any entries with a timestamp in the global todo list.
  540. The idea behind this is that by setting a timestamp, you
  541. have already \"taken care\" of this item.
  542. This variable can also have an integer as a value. If positive (N),
  543. todos with a timestamp N or more days in the future will be ignored. If
  544. negative (-N), todos with a timestamp N or more days in the past will be
  545. ignored. If 0, todos with a timestamp either today or in the future will
  546. be ignored. For example, a value of -1 will exclude todos with a
  547. timestamp in the past (yesterday or earlier), while a value of 7 will
  548. exclude todos with a timestamp a week or more in the future.
  549. See also `org-agenda-todo-ignore-with-date'.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  551. to make his option also apply to the tags-todo list."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type '(choice
  555. (const :tag "Ignore future timestamp todos" future)
  556. (const :tag "Ignore past or present timestamp todos" past)
  557. (const :tag "Ignore all timestamp todos" all)
  558. (const :tag "Show timestamp todos" nil)
  559. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  560. (defcustom org-agenda-todo-ignore-scheduled nil
  561. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  562. This applies when creating the global todo list.
  563. Valid values are:
  564. past Don't show entries scheduled today or in the past.
  565. future Don't show entries scheduled in the future.
  566. The idea behind this is that by scheduling it, you don't want to
  567. think about it until the scheduled date.
  568. all Don't show any scheduled entries in the global todo list.
  569. The idea behind this is that by scheduling it, you have already
  570. \"taken care\" of this item.
  571. t Same as `all', for backward compatibility.
  572. This variable can also have an integer as a value. See
  573. `org-agenda-todo-ignore-timestamp' for more details.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future-scheduled todos" future)
  581. (const :tag "Ignore past- or present-scheduled todos" past)
  582. (const :tag "Ignore all scheduled todos" all)
  583. (const :tag "Ignore all scheduled todos (compatibility)" t)
  584. (const :tag "Show scheduled todos" nil)
  585. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  586. (defcustom org-agenda-todo-ignore-deadlines nil
  587. "Non-nil means ignore some deadlined TODO items when making TODO list.
  588. There are different motivations for using different values, please think
  589. carefully when configuring this variable.
  590. This applies when creating the global todo list.
  591. Valid values are:
  592. near Don't show near deadline entries. A deadline is near when it is
  593. closer than `org-deadline-warning-days' days. The idea behind this
  594. is that such items will appear in the agenda anyway.
  595. far Don't show TODO entries where a deadline has been defined, but
  596. the deadline is not near. This is useful if you don't want to
  597. use the todo list to figure out what to do now.
  598. past Don't show entries with a deadline timestamp for today or in the past.
  599. future Don't show entries with a deadline timestamp in the future, not even
  600. when they become `near' ones. Use it with caution.
  601. all Ignore all TODO entries that do have a deadline.
  602. t Same as `near', for backward compatibility.
  603. This variable can also have an integer as a value. See
  604. `org-agenda-todo-ignore-timestamp' for more details.
  605. See also `org-agenda-todo-ignore-with-date'.
  606. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  607. to make his option also apply to the tags-todo list."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type '(choice
  611. (const :tag "Ignore near deadlines" near)
  612. (const :tag "Ignore near deadlines (compatibility)" t)
  613. (const :tag "Ignore far deadlines" far)
  614. (const :tag "Ignore all TODOs with a deadlines" all)
  615. (const :tag "Show all TODOs, even if they have a deadline" nil)
  616. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  617. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  618. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  619. The variables
  620. `org-agenda-todo-ignore-with-date',
  621. `org-agenda-todo-ignore-timestamp',
  622. `org-agenda-todo-ignore-scheduled',
  623. `org-agenda-todo-ignore-deadlines'
  624. make the global TODO list skip entries that have time stamps of certain
  625. kinds. If this option is set, the same options will also apply for the
  626. tags-todo search, which is the general tags/property matcher
  627. restricted to unfinished TODO entries only."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :group 'org-agenda-match-view
  631. :type 'boolean)
  632. (defcustom org-agenda-skip-scheduled-if-done nil
  633. "Non-nil means don't show scheduled items in agenda when they are done.
  634. This is relevant for the daily/weekly agenda, not for the TODO list. And
  635. it applies only to the actual date of the scheduling. Warnings about
  636. an item with a past scheduling dates are always turned off when the item
  637. is DONE."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-daily/weekly
  640. :type 'boolean)
  641. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  642. "Non-nil means skip scheduling line if same entry shows because of deadline.
  643. In the agenda of today, an entry can show up multiple times because
  644. it is both scheduled and has a nearby deadline, and maybe a plain time
  645. stamp as well.
  646. When this variable is t, then only the deadline is shown and the fact that
  647. the entry is scheduled today or was scheduled previously is not shown.
  648. When this variable is nil, the entry will be shown several times. When
  649. the variable is the symbol `not-today', then skip scheduled previously,
  650. but not scheduled today."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-daily/weekly
  653. :type '(choice
  654. (const :tag "Never" nil)
  655. (const :tag "Always" t)
  656. (const :tag "Not when scheduled today" not-today)))
  657. (defcustom org-agenda-skip-deadline-if-done nil
  658. "Non-nil means don't show deadlines when the corresponding item is done.
  659. When nil, the deadline is still shown and should give you a happy feeling.
  660. This is relevant for the daily/weekly agenda. And it applied only to the
  661. actually date of the deadline. Warnings about approaching and past-due
  662. deadlines are always turned off when the item is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  667. "Non-nil means skip deadline prewarning when entry is also scheduled.
  668. This will apply on all days where a prewarning for the deadline would
  669. be shown, but not at the day when the entry is actually due. On that day,
  670. the deadline will be shown anyway.
  671. This variable may be set to nil, t, or a number which will then give
  672. the number of days before the actual deadline when the prewarnings
  673. should resume.
  674. This can be used in a workflow where the first showing of the deadline will
  675. trigger you to schedule it, and then you don't want to be reminded of it
  676. because you will take care of it on the day when scheduled."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-daily/weekly
  679. :type '(choice
  680. (const :tag "Alwas show prewarning" nil)
  681. (const :tag "Remove prewarning if entry is scheduled" t)
  682. (integer :tag "Restart prewarning N days before deadline")))
  683. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  684. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  685. When non-nil, after the search for timestamps has matched once in an
  686. entry, the rest of the entry will not be searched."
  687. :group 'org-agenda-skip
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-timestamp-if-done nil
  690. "Non-nil means don't select item by timestamp or -range if it is DONE."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-daily/weekly
  693. :type 'boolean)
  694. (defcustom org-agenda-dim-blocked-tasks t
  695. "Non-nil means dim blocked tasks in the agenda display.
  696. This causes some overhead during agenda construction, but if you
  697. have turned on `org-enforce-todo-dependencies',
  698. `org-enforce-todo-checkbox-dependencies', or any other blocking
  699. mechanism, this will create useful feedback in the agenda.
  700. Instead of t, this variable can also have the value `invisible'.
  701. Then blocked tasks will be invisible and only become visible when
  702. they become unblocked. An exemption to this behavior is when a task is
  703. blocked because of unchecked checkboxes below it. Since checkboxes do
  704. not show up in the agenda views, making this task invisible you remove any
  705. trace from agenda views that there is something to do. Therefore, a task
  706. that is blocked because of checkboxes will never be made invisible, it
  707. will only be dimmed."
  708. :group 'org-agenda-daily/weekly
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Do not dim" nil)
  712. (const :tag "Dim to a grey face" t)
  713. (const :tag "Make invisible" invisible)))
  714. (defcustom org-timeline-show-empty-dates 3
  715. "Non-nil means `org-timeline' also shows dates without an entry.
  716. When nil, only the days which actually have entries are shown.
  717. When t, all days between the first and the last date are shown.
  718. When an integer, show also empty dates, but if there is a gap of more than
  719. N days, just insert a special line indicating the size of the gap."
  720. :group 'org-agenda-skip
  721. :type '(choice
  722. (const :tag "None" nil)
  723. (const :tag "All" t)
  724. (integer :tag "at most")))
  725. (defgroup org-agenda-startup nil
  726. "Options concerning initial settings in the Agenda in Org Mode."
  727. :tag "Org Agenda Startup"
  728. :group 'org-agenda)
  729. (defcustom org-agenda-menu-show-matcher t
  730. "Non-nil means show the match string in the agenda dispatcher menu.
  731. When nil, the matcher string is not shown, but is put into the help-echo
  732. property so than moving the mouse over the command shows it.
  733. Setting it to nil is good if matcher strings are very long and/or if
  734. you want to use two-column display (see `org-agenda-menu-two-column')."
  735. :group 'org-agenda
  736. :type 'boolean)
  737. (defcustom org-agenda-menu-two-column nil
  738. "Non-nil means, use two columns to show custom commands in the dispatcher.
  739. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  740. to nil."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-finalize-agenda-hook nil
  744. "Hook run just before displaying an agenda buffer."
  745. :group 'org-agenda-startup
  746. :type 'hook)
  747. (defcustom org-agenda-mouse-1-follows-link nil
  748. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  749. A longer mouse click will still set point. Does not work on XEmacs.
  750. Needs to be set before org.el is loaded."
  751. :group 'org-agenda-startup
  752. :type 'boolean)
  753. (defcustom org-agenda-start-with-follow-mode nil
  754. "The initial value of follow mode in a newly created agenda window."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-show-outline-path t
  758. "Non-nil means show outline path in echo area after line motion."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-start-with-entry-text-mode nil
  762. "The initial value of entry-text-mode in a newly created agenda window."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-entry-text-maxlines 5
  766. "Number of text lines to be added when `E' is pressed in the agenda.
  767. Note that this variable only used during agenda display. Add add entry text
  768. when exporting the agenda, configure the variable
  769. `org-agenda-add-entry-ext-maxlines'."
  770. :group 'org-agenda
  771. :type 'integer)
  772. (defcustom org-agenda-entry-text-exclude-regexps nil
  773. "List of regular expressions to clean up entry text.
  774. The complete matches of all regular expressions in this list will be
  775. removed from entry text before it is shown in the agenda."
  776. :group 'org-agenda
  777. :type '(repeat (regexp)))
  778. (defvar org-agenda-entry-text-cleanup-hook nil
  779. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  780. This cleanup is done in a temporary buffer, so the function may inspect and
  781. change the entire buffer.
  782. Some default stuff like drawers and scheduling/deadline dates will already
  783. have been removed when this is called, as will any matches for regular
  784. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  785. (defvar org-agenda-include-inactive-timestamps nil
  786. "Non-nil means include inactive time stamps in agenda and timeline.")
  787. (defgroup org-agenda-windows nil
  788. "Options concerning the windows used by the Agenda in Org Mode."
  789. :tag "Org Agenda Windows"
  790. :group 'org-agenda)
  791. (defcustom org-agenda-window-setup 'reorganize-frame
  792. "How the agenda buffer should be displayed.
  793. Possible values for this option are:
  794. current-window Show agenda in the current window, keeping all other windows.
  795. other-window Use `switch-to-buffer-other-window' to display agenda.
  796. reorganize-frame Show only two windows on the current frame, the current
  797. window and the agenda.
  798. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  799. Also, when exiting the agenda, kill that frame.
  800. See also the variable `org-agenda-restore-windows-after-quit'."
  801. :group 'org-agenda-windows
  802. :type '(choice
  803. (const current-window)
  804. (const other-frame)
  805. (const other-window)
  806. (const reorganize-frame)))
  807. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  808. "The min and max height of the agenda window as a fraction of frame height.
  809. The value of the variable is a cons cell with two numbers between 0 and 1.
  810. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  811. :group 'org-agenda-windows
  812. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  813. (defcustom org-agenda-restore-windows-after-quit nil
  814. "Non-nil means restore window configuration upon exiting agenda.
  815. Before the window configuration is changed for displaying the agenda,
  816. the current status is recorded. When the agenda is exited with
  817. `q' or `x' and this option is set, the old state is restored. If
  818. `org-agenda-window-setup' is `other-frame', the value of this
  819. option will be ignored."
  820. :group 'org-agenda-windows
  821. :type 'boolean)
  822. (defcustom org-agenda-ndays nil
  823. "Number of days to include in overview display.
  824. Should be 1 or 7.
  825. Obsolete, see `org-agenda-span'."
  826. :group 'org-agenda-daily/weekly
  827. :type 'integer)
  828. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  829. (defcustom org-agenda-span 'week
  830. "Number of days to include in overview display.
  831. Can be day, week, month, year, or any number of days.
  832. Custom commands can set this variable in the options section."
  833. :group 'org-agenda-daily/weekly
  834. :type '(choice (const :tag "Day" day)
  835. (const :tag "Week" week)
  836. (const :tag "Month" month)
  837. (const :tag "Year" year)
  838. (integer :tag "Custom")))
  839. (defcustom org-agenda-start-on-weekday 1
  840. "Non-nil means start the overview always on the specified weekday.
  841. 0 denotes Sunday, 1 denotes Monday etc.
  842. When nil, always start on the current day.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type '(choice (const :tag "Today" nil)
  846. (integer :tag "Weekday No.")))
  847. (defcustom org-agenda-show-all-dates t
  848. "Non-nil means `org-agenda' shows every day in the selected range.
  849. When nil, only the days which actually have entries are shown."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  853. "Format string for displaying dates in the agenda.
  854. Used by the daily/weekly agenda and by the timeline. This should be
  855. a format string understood by `format-time-string', or a function returning
  856. the formatted date as a string. The function must take a single argument,
  857. a calendar-style date list like (month day year)."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice
  860. (string :tag "Format string")
  861. (function :tag "Function")))
  862. (defun org-agenda-format-date-aligned (date)
  863. "Format a date string for display in the daily/weekly agenda, or timeline.
  864. This function makes sure that dates are aligned for easy reading."
  865. (require 'cal-iso)
  866. (let* ((dayname (calendar-day-name date))
  867. (day (cadr date))
  868. (day-of-week (calendar-day-of-week date))
  869. (month (car date))
  870. (monthname (calendar-month-name month))
  871. (year (nth 2 date))
  872. (iso-week (org-days-to-iso-week
  873. (calendar-absolute-from-gregorian date)))
  874. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  875. (1- year))
  876. ((and (= month 12) (<= iso-week 1))
  877. (1+ year))
  878. (t year)))
  879. (weekstring (if (= day-of-week 1)
  880. (format " W%02d" iso-week)
  881. "")))
  882. (format "%-10s %2d %s %4d%s"
  883. dayname day monthname year weekstring)))
  884. (defcustom org-agenda-time-leading-zero nil
  885. "Non-nil means use leading zero for military times in agenda.
  886. For example, 9:30am would become 09:30 rather than 9:30."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-timegrid-use-ampm nil
  890. "When set, show AM/PM style timestamps on the timegrid."
  891. :group 'org-agenda
  892. :type 'boolean)
  893. (defun org-agenda-time-of-day-to-ampm (time)
  894. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  895. (let* ((hour-number (string-to-number (substring time 0 -3)))
  896. (minute (substring time -2))
  897. (ampm "am"))
  898. (cond
  899. ((equal hour-number 12)
  900. (setq ampm "pm"))
  901. ((> hour-number 12)
  902. (setq ampm "pm")
  903. (setq hour-number (- hour-number 12))))
  904. (concat
  905. (if org-agenda-time-leading-zero
  906. (format "%02d" hour-number)
  907. (format "%02s" (number-to-string hour-number)))
  908. ":" minute ampm)))
  909. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  910. "Conditionally convert TIME to AM/PM format
  911. based on `org-agenda-timegrid-use-ampm'"
  912. (if org-agenda-timegrid-use-ampm
  913. (org-agenda-time-of-day-to-ampm time)
  914. time))
  915. (defcustom org-agenda-weekend-days '(6 0)
  916. "Which days are weekend?
  917. These days get the special face `org-agenda-date-weekend' in the agenda
  918. and timeline buffers."
  919. :group 'org-agenda-daily/weekly
  920. :type '(set :greedy t
  921. (const :tag "Monday" 1)
  922. (const :tag "Tuesday" 2)
  923. (const :tag "Wednesday" 3)
  924. (const :tag "Thursday" 4)
  925. (const :tag "Friday" 5)
  926. (const :tag "Saturday" 6)
  927. (const :tag "Sunday" 0)))
  928. (defcustom org-agenda-include-diary nil
  929. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  930. Custom commands can set this variable in the options section."
  931. :group 'org-agenda-daily/weekly
  932. :type 'boolean)
  933. (defcustom org-agenda-include-deadlines t
  934. "If non-nil, include entries within their deadline warning period.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type 'boolean)
  938. (defcustom org-agenda-include-all-todo nil
  939. "Set means weekly/daily agenda will always contain all TODO entries.
  940. The TODO entries will be listed at the top of the agenda, before
  941. the entries for specific days.
  942. This option is deprecated, it is better to define a block agenda instead."
  943. :group 'org-agenda-daily/weekly
  944. :type 'boolean)
  945. (defcustom org-agenda-repeating-timestamp-show-all t
  946. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  947. When set to a list of strings, only show occurrences of repeating
  948. stamps for these TODO keywords. When nil, only one occurrence is
  949. shown, either today or the nearest into the future."
  950. :group 'org-agenda-daily/weekly
  951. :type '(choice
  952. (const :tag "Show repeating stamps" t)
  953. (repeat :tag "Show repeating stamps for these TODO keywords"
  954. (string :tag "TODO Keyword"))
  955. (const :tag "Don't show repeating stamps" nil)))
  956. (defcustom org-scheduled-past-days 10000
  957. "No. of days to continue listing scheduled items that are not marked DONE.
  958. When an item is scheduled on a date, it shows up in the agenda on this
  959. day and will be listed until it is marked done for the number of days
  960. given here."
  961. :group 'org-agenda-daily/weekly
  962. :type 'integer)
  963. (defcustom org-agenda-log-mode-items '(closed clock)
  964. "List of items that should be shown in agenda log mode.
  965. This list may contain the following symbols:
  966. closed Show entries that have been closed on that day.
  967. clock Show entries that have received clocked time on that day.
  968. state Show all logged state changes.
  969. Note that instead of changing this variable, you can also press `C-u l' in
  970. the agenda to display all available LOG items temporarily."
  971. :group 'org-agenda-daily/weekly
  972. :type '(set :greedy t (const closed) (const clock) (const state)))
  973. (defcustom org-agenda-clock-consistency-checks
  974. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  975. :gap-ok-around ("4:00")
  976. :default-face ((:background "DarkRed") (:foreground "white"))
  977. :overlap-face nil :gap-face nil :no-end-time-face nil
  978. :long-face nil :short-face nil)
  979. "This is a property list, with the following keys:
  980. :max-duration Mark clocking chunks that are longer than this time.
  981. This is a time string like \"HH:MM\", or the number
  982. of minutes as an integer.
  983. :min-duration Mark clocking chunks that are shorter that this.
  984. This is a time string like \"HH:MM\", or the number
  985. of minutes as an integer.
  986. :max-gap Mark gaps between clocking chunks that are longer than
  987. this duration. A number of minutes, or a string
  988. like \"HH:MM\".
  989. :gap-ok-around List of times during the day which are usually not working
  990. times. When a gap is detected, but the gap contains any
  991. of these times, the gap is *not* reported. For example,
  992. if this is (\"4:00\" \"13:00\") then gaps that contain
  993. 4:00 in the morning (i.e. the night) and 13:00
  994. (i.e. a typical lunch time) do not cause a warning.
  995. You should have at least one time during the night in this
  996. list, or otherwise the first task each morning will trigger
  997. a warning because it follows a long gap.
  998. Furthermore, the following properties can be used to define faces for
  999. issue display.
  1000. :default-face the default face, if the specific face is undefined
  1001. :overlap-face face for overlapping clocks
  1002. :gap-face face for gaps between clocks
  1003. :no-end-time-face face for incomplete clocks
  1004. :long-face face for clock intervals that are too long
  1005. :short-face face for clock intervals that are too short"
  1006. :group 'org-agenda-daily/weekly
  1007. :group 'org-clock
  1008. :type 'plist)
  1009. (defcustom org-agenda-log-mode-add-notes t
  1010. "Non-nil means add first line of notes to log entries in agenda views.
  1011. If a log item like a state change or a clock entry is associated with
  1012. notes, the first line of these notes will be added to the entry in the
  1013. agenda display."
  1014. :group 'org-agenda-daily/weekly
  1015. :type 'boolean)
  1016. (defcustom org-agenda-start-with-log-mode nil
  1017. "The initial value of log-mode in a newly created agenda window."
  1018. :group 'org-agenda-startup
  1019. :group 'org-agenda-daily/weekly
  1020. :type 'boolean)
  1021. (defcustom org-agenda-start-with-clockreport-mode nil
  1022. "The initial value of clockreport-mode in a newly created agenda window."
  1023. :group 'org-agenda-startup
  1024. :group 'org-agenda-daily/weekly
  1025. :type 'boolean)
  1026. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1027. "Property list with parameters for the clocktable in clockreport mode.
  1028. This is the display mode that shows a clock table in the daily/weekly
  1029. agenda, the properties for this dynamic block can be set here.
  1030. The usual clocktable parameters are allowed here, but you cannot set
  1031. the properties :name, :tstart, :tend, :block, and :scope - these will
  1032. be overwritten to make sure the content accurately reflects the
  1033. current display in the agenda."
  1034. :group 'org-agenda-daily/weekly
  1035. :type 'plist)
  1036. (defcustom org-agenda-search-view-always-boolean nil
  1037. "Non-nil means the search string is interpreted as individual parts.
  1038. The search string for search view can either be interpreted as a phrase,
  1039. or as a list of snippets that define a boolean search for a number of
  1040. strings.
  1041. When this is non-nil, the string will be split on whitespace, and each
  1042. snippet will be searched individually, and all must match in order to
  1043. select an entry. A snippet is then a single string of non-white
  1044. characters, or a string in double quotes, or a regexp in {} braces.
  1045. If a snippet is preceded by \"-\", the snippet must *not* match.
  1046. \"+\" is syntactic sugar for positive selection. Each snippet may
  1047. be found as a full word or a partial word, but see the variable
  1048. `org-agenda-search-view-force-full-words'.
  1049. When this is nil, search will look for the entire search phrase as one,
  1050. with each space character matching any amount of whitespace, including
  1051. line breaks.
  1052. Even when this is nil, you can still switch to Boolean search dynamically
  1053. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1054. is a regexp marked with braces like \"{abc}\", this will also switch to
  1055. boolean search."
  1056. :group 'org-agenda-search-view
  1057. :type 'boolean)
  1058. (if (fboundp 'defvaralias)
  1059. (defvaralias 'org-agenda-search-view-search-words-only
  1060. 'org-agenda-search-view-always-boolean))
  1061. (defcustom org-agenda-search-view-force-full-words nil
  1062. "Non-nil means, search words must be matches as complete words.
  1063. When nil, they may also match part of a word."
  1064. :group 'org-agenda-search-view
  1065. :type 'boolean)
  1066. (defgroup org-agenda-time-grid nil
  1067. "Options concerning the time grid in the Org-mode Agenda."
  1068. :tag "Org Agenda Time Grid"
  1069. :group 'org-agenda)
  1070. (defcustom org-agenda-search-headline-for-time t
  1071. "Non-nil means search headline for a time-of-day.
  1072. If the headline contains a time-of-day in one format or another, it will
  1073. be used to sort the entry into the time sequence of items for a day.
  1074. Some people have time stamps in the headline that refer to the creation
  1075. time or so, and then this produces an unwanted side effect. If this is
  1076. the case for your, use this variable to turn off searching the headline
  1077. for a time."
  1078. :group 'org-agenda-time-grid
  1079. :type 'boolean)
  1080. (defcustom org-agenda-use-time-grid t
  1081. "Non-nil means show a time grid in the agenda schedule.
  1082. A time grid is a set of lines for specific times (like every two hours between
  1083. 8:00 and 20:00). The items scheduled for a day at specific times are
  1084. sorted in between these lines.
  1085. For details about when the grid will be shown, and what it will look like, see
  1086. the variable `org-agenda-time-grid'."
  1087. :group 'org-agenda-time-grid
  1088. :type 'boolean)
  1089. (defcustom org-agenda-time-grid
  1090. '((daily today require-timed)
  1091. "----------------"
  1092. (800 1000 1200 1400 1600 1800 2000))
  1093. "The settings for time grid for agenda display.
  1094. This is a list of three items. The first item is again a list. It contains
  1095. symbols specifying conditions when the grid should be displayed:
  1096. daily if the agenda shows a single day
  1097. weekly if the agenda shows an entire week
  1098. today show grid on current date, independent of daily/weekly display
  1099. require-timed show grid only if at least one item has a time specification
  1100. The second item is a string which will be placed behind the grid time.
  1101. The third item is a list of integers, indicating the times that should have
  1102. a grid line."
  1103. :group 'org-agenda-time-grid
  1104. :type
  1105. '(list
  1106. (set :greedy t :tag "Grid Display Options"
  1107. (const :tag "Show grid in single day agenda display" daily)
  1108. (const :tag "Show grid in weekly agenda display" weekly)
  1109. (const :tag "Always show grid for today" today)
  1110. (const :tag "Show grid only if any timed entries are present"
  1111. require-timed)
  1112. (const :tag "Skip grid times already present in an entry"
  1113. remove-match))
  1114. (string :tag "Grid String")
  1115. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1116. (defcustom org-agenda-show-current-time-in-grid t
  1117. "Non-nil means show the current time in the time grid."
  1118. :group 'org-agenda-time-grid
  1119. :type 'boolean)
  1120. (defcustom org-agenda-current-time-string
  1121. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1122. "The string for the current time marker in the agenda."
  1123. :group 'org-agenda-time-grid
  1124. :type 'string)
  1125. (defgroup org-agenda-sorting nil
  1126. "Options concerning sorting in the Org-mode Agenda."
  1127. :tag "Org Agenda Sorting"
  1128. :group 'org-agenda)
  1129. (defcustom org-agenda-sorting-strategy
  1130. '((agenda habit-down time-up priority-down category-keep)
  1131. (todo priority-down category-keep)
  1132. (tags priority-down category-keep)
  1133. (search category-keep))
  1134. "Sorting structure for the agenda items of a single day.
  1135. This is a list of symbols which will be used in sequence to determine
  1136. if an entry should be listed before another entry. The following
  1137. symbols are recognized:
  1138. time-up Put entries with time-of-day indications first, early first
  1139. time-down Put entries with time-of-day indications first, late first
  1140. category-keep Keep the default order of categories, corresponding to the
  1141. sequence in `org-agenda-files'.
  1142. category-up Sort alphabetically by category, A-Z.
  1143. category-down Sort alphabetically by category, Z-A.
  1144. tag-up Sort alphabetically by last tag, A-Z.
  1145. tag-down Sort alphabetically by last tag, Z-A.
  1146. priority-up Sort numerically by priority, high priority last.
  1147. priority-down Sort numerically by priority, high priority first.
  1148. todo-state-up Sort by todo state, tasks that are done last.
  1149. todo-state-down Sort by todo state, tasks that are done first.
  1150. effort-up Sort numerically by estimated effort, high effort last.
  1151. effort-down Sort numerically by estimated effort, high effort first.
  1152. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1153. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1154. habit-up Put entries that are habits first
  1155. habit-down Put entries that are habits last
  1156. alpha-up Sort headlines alphabetically
  1157. alpha-down Sort headlines alphabetically, reversed
  1158. The different possibilities will be tried in sequence, and testing stops
  1159. if one comparison returns a \"not-equal\". For example, the default
  1160. '(time-up category-keep priority-down)
  1161. means: Pull out all entries having a specified time of day and sort them,
  1162. in order to make a time schedule for the current day the first thing in the
  1163. agenda listing for the day. Of the entries without a time indication, keep
  1164. the grouped in categories, don't sort the categories, but keep them in
  1165. the sequence given in `org-agenda-files'. Within each category sort by
  1166. priority.
  1167. Leaving out `category-keep' would mean that items will be sorted across
  1168. categories by priority.
  1169. Instead of a single list, this can also be a set of list for specific
  1170. contents, with a context symbol in the car of the list, any of
  1171. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1172. Custom commands can bind this variable in the options section."
  1173. :group 'org-agenda-sorting
  1174. :type `(choice
  1175. (repeat :tag "General" ,org-sorting-choice)
  1176. (list :tag "Individually"
  1177. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1178. (repeat ,org-sorting-choice))
  1179. (cons (const :tag "Strategy for TODO lists" todo)
  1180. (repeat ,org-sorting-choice))
  1181. (cons (const :tag "Strategy for Tags matches" tags)
  1182. (repeat ,org-sorting-choice))
  1183. (cons (const :tag "Strategy for search matches" search)
  1184. (repeat ,org-sorting-choice)))))
  1185. (defcustom org-agenda-cmp-user-defined nil
  1186. "A function to define the comparison `user-defined'.
  1187. This function must receive two arguments, agenda entry a and b.
  1188. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1189. the user comparison, return nil.
  1190. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1191. part of an agenda sorting strategy."
  1192. :group 'org-agenda-sorting
  1193. :type 'symbol)
  1194. (defcustom org-sort-agenda-notime-is-late t
  1195. "Non-nil means items without time are considered late.
  1196. This is only relevant for sorting. When t, items which have no explicit
  1197. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1198. do have a time. When nil, the default time is before 0:00. You can use this
  1199. option to decide if the schedule for today should come before or after timeless
  1200. agenda entries."
  1201. :group 'org-agenda-sorting
  1202. :type 'boolean)
  1203. (defcustom org-sort-agenda-noeffort-is-high t
  1204. "Non-nil means items without effort estimate are sorted as high effort.
  1205. This also applies when filtering an agenda view with respect to the
  1206. < or > effort operator. Then, tasks with no effort defined will be treated
  1207. as tasks with high effort.
  1208. When nil, such items are sorted as 0 minutes effort."
  1209. :group 'org-agenda-sorting
  1210. :type 'boolean)
  1211. (defgroup org-agenda-line-format nil
  1212. "Options concerning the entry prefix in the Org-mode agenda display."
  1213. :tag "Org Agenda Line Format"
  1214. :group 'org-agenda)
  1215. (defcustom org-agenda-prefix-format
  1216. '((agenda . " %i %-12:c%?-12t% s")
  1217. (timeline . " % s")
  1218. (todo . " %i %-12:c")
  1219. (tags . " %i %-12:c")
  1220. (search . " %i %-12:c"))
  1221. "Format specifications for the prefix of items in the agenda views.
  1222. An alist with four entries, for the different agenda types. The keys to the
  1223. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1224. are format strings.
  1225. This format works similar to a printf format, with the following meaning:
  1226. %c the category of the item, \"Diary\" for entries from the diary, or
  1227. as given by the CATEGORY keyword or derived from the file name.
  1228. %i the icon category of the item, as give in
  1229. `org-agenda-category-icon-alist'.
  1230. %T the *last* tag of the item. Last because inherited tags come
  1231. first in the list.
  1232. %t the time-of-day specification if one applies to the entry, in the
  1233. format HH:MM
  1234. %s Scheduling/Deadline information, a short string
  1235. %(expression) Eval EXPRESSION and replace the control string
  1236. by the result
  1237. All specifiers work basically like the standard `%s' of printf, but may
  1238. contain two additional characters: A question mark just after the `%' and
  1239. a whitespace/punctuation character just before the final letter.
  1240. If the first character after `%' is a question mark, the entire field
  1241. will only be included if the corresponding value applies to the
  1242. current entry. This is useful for fields which should have fixed
  1243. width when present, but zero width when absent. For example,
  1244. \"%?-12t\" will result in a 12 character time field if a time of the
  1245. day is specified, but will completely disappear in entries which do
  1246. not contain a time.
  1247. If there is punctuation or whitespace character just before the final
  1248. format letter, this character will be appended to the field value if
  1249. the value is not empty. For example, the format \"%-12:c\" leads to
  1250. \"Diary: \" if the category is \"Diary\". If the category were be
  1251. empty, no additional colon would be inserted.
  1252. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1253. - Indent the line with two space characters
  1254. - Give the category in a 12 chars wide field, padded with whitespace on
  1255. the right (because of `-'). Append a colon if there is a category
  1256. (because of `:').
  1257. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1258. time, don't put in an empty field, just skip it (because of '?').
  1259. - Finally, put the scheduling information and append a whitespace.
  1260. As another example, if you don't want the time-of-day of entries in
  1261. the prefix, you could use:
  1262. (setq org-agenda-prefix-format \" %-11:c% s\")
  1263. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1264. `org-agenda-remove-tags'.
  1265. Custom commands can set this variable in the options section."
  1266. :type '(choice
  1267. (string :tag "General format")
  1268. (list :greedy t :tag "View dependent"
  1269. (cons (const agenda) (string :tag "Format"))
  1270. (cons (const timeline) (string :tag "Format"))
  1271. (cons (const todo) (string :tag "Format"))
  1272. (cons (const tags) (string :tag "Format"))
  1273. (cons (const search) (string :tag "Format"))))
  1274. :group 'org-agenda-line-format)
  1275. (defvar org-prefix-format-compiled nil
  1276. "The compiled version of the most recently used prefix format.
  1277. See the variable `org-agenda-prefix-format'.")
  1278. (defcustom org-agenda-todo-keyword-format "%-1s"
  1279. "Format for the TODO keyword in agenda lines.
  1280. Set this to something like \"%-12s\" if you want all TODO keywords
  1281. to occupy a fixed space in the agenda display."
  1282. :group 'org-agenda-line-format
  1283. :type 'string)
  1284. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1285. "Text preceding timerange entries in the agenda view.
  1286. This is a list with two strings. The first applies when the range
  1287. is entirely on one day. The second applies if the range spans several days.
  1288. The strings may have two \"%d\" format specifiers which will be filled
  1289. with the sequence number of the days, and the total number of days in the
  1290. range, respectively."
  1291. :group 'org-agenda-line-format
  1292. :type '(list
  1293. (string :tag "Deadline today ")
  1294. (choice :tag "Deadline relative"
  1295. (string :tag "Format string")
  1296. (function))))
  1297. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1298. "Text preceding scheduled items in the agenda view.
  1299. This is a list with two strings. The first applies when the item is
  1300. scheduled on the current day. The second applies when it has been scheduled
  1301. previously, it may contain a %d indicating that this is the nth time that
  1302. this item is scheduled, due to automatic rescheduling of unfinished items
  1303. for the following day. So this number is one larger than the number of days
  1304. that passed since this item was scheduled first."
  1305. :group 'org-agenda-line-format
  1306. :type '(list
  1307. (string :tag "Scheduled today ")
  1308. (string :tag "Scheduled previously")))
  1309. (defcustom org-agenda-inactive-leader "["
  1310. "Text preceding item pulled into the agenda by inactive time stamps.
  1311. These entries are added to the agenda when pressing \"[\"."
  1312. :group 'org-agenda-line-format
  1313. :type '(list
  1314. (string :tag "Scheduled today ")
  1315. (string :tag "Scheduled previously")))
  1316. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1317. "Text preceding deadline items in the agenda view.
  1318. This is a list with two strings. The first applies when the item has its
  1319. deadline on the current day. The second applies when it is in the past or
  1320. in the future, it may contain %d to capture how many days away the deadline
  1321. is (was)."
  1322. :group 'org-agenda-line-format
  1323. :type '(list
  1324. (string :tag "Deadline today ")
  1325. (choice :tag "Deadline relative"
  1326. (string :tag "Format string")
  1327. (function))))
  1328. (defcustom org-agenda-remove-times-when-in-prefix t
  1329. "Non-nil means remove duplicate time specifications in agenda items.
  1330. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1331. time-of-day specification in a headline or diary entry is extracted and
  1332. placed into the prefix. If this option is non-nil, the original specification
  1333. \(a timestamp or -range, or just a plain time(range) specification like
  1334. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1335. cluttered.
  1336. The option can be t or nil. It may also be the symbol `beg', indicating
  1337. that the time should only be removed when it is located at the beginning of
  1338. the headline/diary entry."
  1339. :group 'org-agenda-line-format
  1340. :type '(choice
  1341. (const :tag "Always" t)
  1342. (const :tag "Never" nil)
  1343. (const :tag "When at beginning of entry" beg)))
  1344. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1345. "Non-nil means remove time ranges specifications in agenda
  1346. items that span on several days."
  1347. :group 'org-agenda-line-format
  1348. :type 'boolean)
  1349. (defcustom org-agenda-default-appointment-duration nil
  1350. "Default duration for appointments that only have a starting time.
  1351. When nil, no duration is specified in such cases.
  1352. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1353. :group 'org-agenda-line-format
  1354. :type '(choice
  1355. (integer :tag "Minutes")
  1356. (const :tag "No default duration")))
  1357. (defcustom org-agenda-show-inherited-tags t
  1358. "Non-nil means show inherited tags in each agenda line."
  1359. :group 'org-agenda-line-format
  1360. :type 'boolean)
  1361. (defcustom org-agenda-hide-tags-regexp nil
  1362. "Regular expression used to filter away specific tags in agenda views.
  1363. This means that these tags will be present, but not be shown in the agenda
  1364. line. Secondary filtering will still work on the hidden tags.
  1365. Nil means don't hide any tags."
  1366. :group 'org-agenda-line-format
  1367. :type '(choice
  1368. (const :tag "Hide none" nil)
  1369. (string :tag "Regexp ")))
  1370. (defcustom org-agenda-remove-tags nil
  1371. "Non-nil means remove the tags from the headline copy in the agenda.
  1372. When this is the symbol `prefix', only remove tags when
  1373. `org-agenda-prefix-format' contains a `%T' specifier."
  1374. :group 'org-agenda-line-format
  1375. :type '(choice
  1376. (const :tag "Always" t)
  1377. (const :tag "Never" nil)
  1378. (const :tag "When prefix format contains %T" prefix)))
  1379. (if (fboundp 'defvaralias)
  1380. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1381. 'org-agenda-remove-tags))
  1382. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1383. "Shift tags in agenda items to this column.
  1384. If this number is positive, it specifies the column. If it is negative,
  1385. it means that the tags should be flushright to that column. For example,
  1386. -80 works well for a normal 80 character screen."
  1387. :group 'org-agenda-line-format
  1388. :type 'integer)
  1389. (if (fboundp 'defvaralias)
  1390. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1391. (defcustom org-agenda-fontify-priorities 'cookies
  1392. "Non-nil means highlight low and high priorities in agenda.
  1393. When t, the highest priority entries are bold, lowest priority italic.
  1394. However, settings in `org-priority-faces' will overrule these faces.
  1395. When this variable is the symbol `cookies', only fontify the
  1396. cookies, not the entire task.
  1397. This may also be an association list of priority faces, whose
  1398. keys are the character values of `org-highest-priority',
  1399. `org-default-priority', and `org-lowest-priority' (the default values
  1400. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1401. color as a string, or a list like `(:background \"Red\")'.
  1402. If it is a color, the variable `org-faces-easy-properties'
  1403. determines if it is a foreground or a background color."
  1404. :group 'org-agenda-line-format
  1405. :type '(choice
  1406. (const :tag "Never" nil)
  1407. (const :tag "Defaults" t)
  1408. (const :tag "Cookies only" cookies)
  1409. (repeat :tag "Specify"
  1410. (list (character :tag "Priority" :value ?A)
  1411. (choice :tag "Face "
  1412. (string :tag "Color")
  1413. (sexp :tag "Face"))))))
  1414. (defcustom org-agenda-day-face-function nil
  1415. "Function called to determine what face should be used to display a day.
  1416. The only argument passed to that function is the day. It should
  1417. returns a face, or nil if does not want to specify a face and let
  1418. the normal rules apply."
  1419. :group 'org-agenda-line-format
  1420. :type 'function)
  1421. (defcustom org-agenda-category-icon-alist nil
  1422. "Alist of category icon to be displayed in agenda views.
  1423. Each entry should have the following format:
  1424. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1425. Where CATEGORY-REGEXP is a regexp matching the categories where
  1426. the icon should be displayed.
  1427. FILE-OR-DATA either a file path or a string containing image data.
  1428. The other fields can be omited safely if not needed:
  1429. TYPE indicates the image type.
  1430. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1431. image data.
  1432. PROPS are additional image attributes to assign to the image,
  1433. like, e.g. `:ascent center'.
  1434. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1435. If you want to set the display properties yourself, just put a
  1436. list as second element:
  1437. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1438. For example, to display a 16px horizontal space for Emacs
  1439. category, you can use:
  1440. (\"Emacs\" '(space . (:width (16))))"
  1441. :group 'org-agenda-line-format
  1442. :type '(alist :key-type (string :tag "Regexp matching category")
  1443. :value-type (choice (list :tag "Icon"
  1444. (string :tag "File or data")
  1445. (symbol :tag "Type")
  1446. (boolean :tag "Data?")
  1447. (repeat :tag "Extra image properties" :inline t symbol))
  1448. (list :tag "Display properties" sexp))))
  1449. (defgroup org-agenda-column-view nil
  1450. "Options concerning column view in the agenda."
  1451. :tag "Org Agenda Column View"
  1452. :group 'org-agenda)
  1453. (defcustom org-agenda-columns-show-summaries t
  1454. "Non-nil means show summaries for columns displayed in the agenda view."
  1455. :group 'org-agenda-column-view
  1456. :type 'boolean)
  1457. (defcustom org-agenda-columns-compute-summary-properties t
  1458. "Non-nil means recompute all summary properties before column view.
  1459. When column view in the agenda is listing properties that have a summary
  1460. operator, it can go to all relevant buffers and recompute the summaries
  1461. there. This can mean overhead for the agenda column view, but is necessary
  1462. to have thing up to date.
  1463. As a special case, a CLOCKSUM property also makes sure that the clock
  1464. computations are current."
  1465. :group 'org-agenda-column-view
  1466. :type 'boolean)
  1467. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1468. "Non-nil means the duration of an appointment will add to day effort.
  1469. The property to which appointment durations will be added is the one given
  1470. in the option `org-effort-property'. If an appointment does not have
  1471. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1472. is not set, an appointment without end time will not contribute to the time
  1473. estimate."
  1474. :group 'org-agenda-column-view
  1475. :type 'boolean)
  1476. (defcustom org-agenda-auto-exclude-function nil
  1477. "A function called with a tag to decide if it is filtered on '/ RET'.
  1478. The sole argument to the function, which is called once for each
  1479. possible tag, is a string giving the name of the tag. The
  1480. function should return either nil if the tag should be included
  1481. as normal, or \"-<TAG>\" to exclude the tag.
  1482. Note that for the purpose of tag filtering, only the lower-case version of
  1483. all tags will be considered, so that this function will only ever see
  1484. the lower-case version of all tags."
  1485. :group 'org-agenda
  1486. :type 'function)
  1487. (eval-when-compile
  1488. (require 'cl))
  1489. (require 'org)
  1490. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1491. "Execute BODY with point at location given by `org-hd-marker' property.
  1492. If STRING is non-nil, the text property will be fetched from position 0
  1493. in that string. If STRING is nil, it will be fetched from the beginning
  1494. of the current line."
  1495. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1496. 'org-hd-marker string)))
  1497. (with-current-buffer (marker-buffer marker)
  1498. (save-excursion
  1499. (goto-char marker)
  1500. ,@body))))
  1501. (defun org-add-agenda-custom-command (entry)
  1502. "Replace or add a command in `org-agenda-custom-commands'.
  1503. This is mostly for hacking and trying a new command - once the command
  1504. works you probably want to add it to `org-agenda-custom-commands' for good."
  1505. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1506. (if ass
  1507. (setcdr ass (cdr entry))
  1508. (push entry org-agenda-custom-commands))))
  1509. ;;; Define the Org-agenda-mode
  1510. (defvar org-agenda-mode-map (make-sparse-keymap)
  1511. "Keymap for `org-agenda-mode'.")
  1512. (if (fboundp 'defvaralias)
  1513. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1514. (defvar org-agenda-menu) ; defined later in this file.
  1515. (defvar org-agenda-restrict) ; defined later in this file.
  1516. (defvar org-agenda-follow-mode nil)
  1517. (defvar org-agenda-entry-text-mode nil)
  1518. (defvar org-agenda-clockreport-mode nil)
  1519. (defvar org-agenda-show-log nil)
  1520. (defvar org-agenda-redo-command nil)
  1521. (defvar org-agenda-query-string nil)
  1522. (defvar org-agenda-mode-hook nil
  1523. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1524. (defvar org-agenda-type nil)
  1525. (defvar org-agenda-force-single-file nil)
  1526. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1527. (defun org-agenda-mode ()
  1528. "Mode for time-sorted view on action items in Org-mode files.
  1529. The following commands are available:
  1530. \\{org-agenda-mode-map}"
  1531. (interactive)
  1532. (kill-all-local-variables)
  1533. (setq org-agenda-undo-list nil
  1534. org-agenda-pending-undo-list nil
  1535. org-agenda-bulk-marked-entries nil)
  1536. (setq major-mode 'org-agenda-mode)
  1537. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1538. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1539. (setq mode-name "Org-Agenda")
  1540. (use-local-map org-agenda-mode-map)
  1541. (easy-menu-add org-agenda-menu)
  1542. (if org-startup-truncated (setq truncate-lines t))
  1543. (org-set-local 'line-move-visual nil)
  1544. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1545. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1546. ;; Make sure properties are removed when copying text
  1547. (when (boundp 'buffer-substring-filters)
  1548. (org-set-local 'buffer-substring-filters
  1549. (cons (lambda (x)
  1550. (set-text-properties 0 (length x) nil x) x)
  1551. buffer-substring-filters)))
  1552. (unless org-agenda-keep-modes
  1553. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1554. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1555. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1556. org-agenda-show-log org-agenda-start-with-log-mode))
  1557. (easy-menu-change
  1558. '("Agenda") "Agenda Files"
  1559. (append
  1560. (list
  1561. (vector
  1562. (if (get 'org-agenda-files 'org-restrict)
  1563. "Restricted to single file"
  1564. "Edit File List")
  1565. '(org-edit-agenda-file-list)
  1566. (not (get 'org-agenda-files 'org-restrict)))
  1567. "--")
  1568. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1569. (org-agenda-set-mode-name)
  1570. (apply
  1571. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1572. (list 'org-agenda-mode-hook)))
  1573. (substitute-key-definition 'undo 'org-agenda-undo
  1574. org-agenda-mode-map global-map)
  1575. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1576. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1577. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1578. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1579. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1580. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1581. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1582. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1583. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1584. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1585. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1586. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1587. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1588. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1589. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1590. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1591. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1592. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1593. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1594. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1595. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1596. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1597. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1598. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1599. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1600. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1601. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1602. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1603. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1604. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1605. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1606. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1607. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1608. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1609. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1610. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1611. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1612. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1613. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1614. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1615. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1616. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1617. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1618. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1619. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1620. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1621. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1622. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1623. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1624. (while l (org-defkey org-agenda-mode-map
  1625. (int-to-string (pop l)) 'digit-argument)))
  1626. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1627. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1628. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1629. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1630. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1631. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1632. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1633. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1634. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1635. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1636. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1637. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1638. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1639. 'org-clock-modify-effort-estimate)
  1640. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1641. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1642. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1643. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1644. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1645. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1646. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1647. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1648. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1649. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1650. (substitute-key-definition 'next-line 'org-agenda-next-line
  1651. org-agenda-mode-map global-map)
  1652. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1653. org-agenda-mode-map global-map)
  1654. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1656. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1657. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1658. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1659. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1660. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1661. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1662. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1663. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1664. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1665. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1667. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1669. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1670. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1671. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1672. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1673. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1674. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1675. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1676. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1677. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1678. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1679. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1680. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1681. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1683. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1684. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1685. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1686. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1687. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1688. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1689. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1690. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1691. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1692. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1693. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1694. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1695. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1696. (when org-agenda-mouse-1-follows-link
  1697. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1698. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1699. '("Agenda"
  1700. ("Agenda Files")
  1701. "--"
  1702. ("Agenda Dates"
  1703. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1704. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1705. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1706. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1707. "--"
  1708. ("View"
  1709. ["Day View" org-agenda-day-view
  1710. :active (org-agenda-check-type nil 'agenda)
  1711. :style radio :selected (eq org-agenda-current-span 'day)
  1712. :keys "v d (or just d)"]
  1713. ["Week View" org-agenda-week-view
  1714. :active (org-agenda-check-type nil 'agenda)
  1715. :style radio :selected (eq org-agenda-current-span 'week)
  1716. :keys "v w (or just w)"]
  1717. ["Month View" org-agenda-month-view
  1718. :active (org-agenda-check-type nil 'agenda)
  1719. :style radio :selected (eq org-agenda-current-span 'month)
  1720. :keys "v m"]
  1721. ["Year View" org-agenda-year-view
  1722. :active (org-agenda-check-type nil 'agenda)
  1723. :style radio :selected (eq org-agenda-current-span 'year)
  1724. :keys "v y"]
  1725. "--"
  1726. ["Include Diary" org-agenda-toggle-diary
  1727. :style toggle :selected org-agenda-include-diary
  1728. :active (org-agenda-check-type nil 'agenda)]
  1729. ["Include Deadlines" org-agenda-toggle-deadlines
  1730. :style toggle :selected org-agenda-include-deadlines
  1731. :active (org-agenda-check-type nil 'agenda)]
  1732. ["Use Time Grid" org-agenda-toggle-time-grid
  1733. :style toggle :selected org-agenda-use-time-grid
  1734. :active (org-agenda-check-type nil 'agenda)]
  1735. "--"
  1736. ["Show clock report" org-agenda-clockreport-mode
  1737. :style toggle :selected org-agenda-clockreport-mode
  1738. :active (org-agenda-check-type nil 'agenda)]
  1739. ["Show some entry text" org-agenda-entry-text-mode
  1740. :style toggle :selected org-agenda-entry-text-mode
  1741. :active t]
  1742. "--"
  1743. ["Show Logbook entries" org-agenda-log-mode
  1744. :style toggle :selected org-agenda-show-log
  1745. :active (org-agenda-check-type nil 'agenda 'timeline)
  1746. :keys "v l (or just l)"]
  1747. ["Include archived trees" org-agenda-archives-mode
  1748. :style toggle :selected org-agenda-archives-mode :active t
  1749. :keys "v a"]
  1750. ["Include archive files" (org-agenda-archives-mode t)
  1751. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1752. :keys "v A"]
  1753. "--"
  1754. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1755. ["Write view to file" org-write-agenda t]
  1756. ["Rebuild buffer" org-agenda-redo t]
  1757. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1758. "--"
  1759. ["Show original entry" org-agenda-show t]
  1760. ["Go To (other window)" org-agenda-goto t]
  1761. ["Go To (this window)" org-agenda-switch-to t]
  1762. ["Follow Mode" org-agenda-follow-mode
  1763. :style toggle :selected org-agenda-follow-mode :active t]
  1764. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1765. "--"
  1766. ("TODO"
  1767. ["Cycle TODO" org-agenda-todo t]
  1768. ["Next TODO set" org-agenda-todo-nextset t]
  1769. ["Previous TODO set" org-agenda-todo-previousset t]
  1770. ["Add note" org-agenda-add-note t])
  1771. ("Archive/Refile/Delete"
  1772. ["Archive default" org-agenda-archive-default t]
  1773. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1774. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1775. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1776. ["Archive subtree" org-agenda-archive t]
  1777. "--"
  1778. ["Refile" org-agenda-refile t]
  1779. "--"
  1780. ["Delete subtree" org-agenda-kill t])
  1781. ("Bulk action"
  1782. ["Mark entry" org-agenda-bulk-mark t]
  1783. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1784. ["Unmark entry" org-agenda-bulk-unmark t]
  1785. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1786. ["Act on all marked" org-agenda-bulk-action t]
  1787. "--"
  1788. ("Tags and Properties"
  1789. ["Show all Tags" org-agenda-show-tags t]
  1790. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1791. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1792. "--"
  1793. ["Column View" org-columns t])
  1794. ("Deadline/Schedule"
  1795. ["Schedule" org-agenda-schedule t]
  1796. ["Set Deadline" org-agenda-deadline t]
  1797. "--"
  1798. ["Mark item" org-agenda-action :active t :keys "k m"]
  1799. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1800. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1801. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1802. "--"
  1803. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1804. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1805. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1806. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1807. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1808. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1809. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1810. ("Clock and Effort"
  1811. ["Clock in" org-agenda-clock-in t]
  1812. ["Clock out" org-agenda-clock-out t]
  1813. ["Clock cancel" org-agenda-clock-cancel t]
  1814. ["Goto running clock" org-clock-goto t]
  1815. "--"
  1816. ["Set Effort" org-agenda-set-effort t]
  1817. ["Change clocked effort" org-clock-modify-effort-estimate
  1818. (org-clock-is-active)])
  1819. ("Priority"
  1820. ["Set Priority" org-agenda-priority t]
  1821. ["Increase Priority" org-agenda-priority-up t]
  1822. ["Decrease Priority" org-agenda-priority-down t]
  1823. ["Show Priority" org-agenda-show-priority t])
  1824. ("Calendar/Diary"
  1825. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1826. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1827. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1828. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1829. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1830. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1831. "--"
  1832. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1833. "--"
  1834. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1835. "--"
  1836. ("MobileOrg"
  1837. ["Push Files and Views" org-mobile-push t]
  1838. ["Get Captured and Flagged" org-mobile-pull t]
  1839. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1840. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1841. "--"
  1842. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1843. "--"
  1844. ["Quit" org-agenda-quit t]
  1845. ["Exit and Release Buffers" org-agenda-exit t]
  1846. ))
  1847. ;;; Agenda undo
  1848. (defvar org-agenda-allow-remote-undo t
  1849. "Non-nil means allow remote undo from the agenda buffer.")
  1850. (defvar org-agenda-undo-list nil
  1851. "List of undoable operations in the agenda since last refresh.")
  1852. (defvar org-agenda-undo-has-started-in nil
  1853. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1854. (defvar org-agenda-pending-undo-list nil
  1855. "In a series of undo commands, this is the list of remaining undo items.")
  1856. (defun org-agenda-undo ()
  1857. "Undo a remote editing step in the agenda.
  1858. This undoes changes both in the agenda buffer and in the remote buffer
  1859. that have been changed along."
  1860. (interactive)
  1861. (or org-agenda-allow-remote-undo
  1862. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1863. (if (not (eq this-command last-command))
  1864. (setq org-agenda-undo-has-started-in nil
  1865. org-agenda-pending-undo-list org-agenda-undo-list))
  1866. (if (not org-agenda-pending-undo-list)
  1867. (error "No further undo information"))
  1868. (let* ((entry (pop org-agenda-pending-undo-list))
  1869. buf line cmd rembuf)
  1870. (setq cmd (pop entry) line (pop entry))
  1871. (setq rembuf (nth 2 entry))
  1872. (org-with-remote-undo rembuf
  1873. (while (bufferp (setq buf (pop entry)))
  1874. (if (pop entry)
  1875. (with-current-buffer buf
  1876. (let ((last-undo-buffer buf)
  1877. (inhibit-read-only t))
  1878. (unless (memq buf org-agenda-undo-has-started-in)
  1879. (push buf org-agenda-undo-has-started-in)
  1880. (make-local-variable 'pending-undo-list)
  1881. (undo-start))
  1882. (while (and pending-undo-list
  1883. (listp pending-undo-list)
  1884. (not (car pending-undo-list)))
  1885. (pop pending-undo-list))
  1886. (undo-more 1))))))
  1887. (org-goto-line line)
  1888. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1889. (defun org-verify-change-for-undo (l1 l2)
  1890. "Verify that a real change occurred between the undo lists L1 and L2."
  1891. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1892. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1893. (not (eq l1 l2)))
  1894. ;;; Agenda dispatch
  1895. (defvar org-agenda-restrict nil)
  1896. (defvar org-agenda-restrict-begin (make-marker))
  1897. (defvar org-agenda-restrict-end (make-marker))
  1898. (defvar org-agenda-last-dispatch-buffer nil)
  1899. (defvar org-agenda-overriding-restriction nil)
  1900. ;;;###autoload
  1901. (defun org-agenda (&optional arg keys restriction)
  1902. "Dispatch agenda commands to collect entries to the agenda buffer.
  1903. Prompts for a command to execute. Any prefix arg will be passed
  1904. on to the selected command. The default selections are:
  1905. a Call `org-agenda-list' to display the agenda for current day or week.
  1906. t Call `org-todo-list' to display the global todo list.
  1907. T Call `org-todo-list' to display the global todo list, select only
  1908. entries with a specific TODO keyword (the user gets a prompt).
  1909. m Call `org-tags-view' to display headlines with tags matching
  1910. a condition (the user is prompted for the condition).
  1911. M Like `m', but select only TODO entries, no ordinary headlines.
  1912. L Create a timeline for the current buffer.
  1913. e Export views to associated files.
  1914. s Search entries for keywords.
  1915. / Multi occur across all agenda files and also files listed
  1916. in `org-agenda-text-search-extra-files'.
  1917. < Restrict agenda commands to buffer, subtree, or region.
  1918. Press several times to get the desired effect.
  1919. > Remove a previous restriction.
  1920. # List \"stuck\" projects.
  1921. ! Configure what \"stuck\" means.
  1922. C Configure custom agenda commands.
  1923. More commands can be added by configuring the variable
  1924. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1925. searches can be pre-defined in this way.
  1926. If the current buffer is in Org-mode and visiting a file, you can also
  1927. first press `<' once to indicate that the agenda should be temporarily
  1928. \(until the next use of \\[org-agenda]) restricted to the current file.
  1929. Pressing `<' twice means to restrict to the current subtree or region
  1930. \(if active)."
  1931. (interactive "P")
  1932. (catch 'exit
  1933. (let* ((prefix-descriptions nil)
  1934. (org-agenda-window-setup (if (equal (buffer-name)
  1935. org-agenda-buffer-name)
  1936. 'current-window
  1937. org-agenda-window-setup))
  1938. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1939. (org-agenda-custom-commands
  1940. ;; normalize different versions
  1941. (delq nil
  1942. (mapcar
  1943. (lambda (x)
  1944. (cond ((stringp (cdr x))
  1945. (push x prefix-descriptions)
  1946. nil)
  1947. ((stringp (nth 1 x)) x)
  1948. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1949. (t (cons (car x) (cons "" (cdr x))))))
  1950. org-agenda-custom-commands)))
  1951. (buf (current-buffer))
  1952. (bfn (buffer-file-name (buffer-base-buffer)))
  1953. entry key type match lprops ans)
  1954. ;; Turn off restriction unless there is an overriding one,
  1955. (unless org-agenda-overriding-restriction
  1956. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1957. ;; There is a request to keep the file list in place
  1958. (put 'org-agenda-files 'org-restrict nil))
  1959. (setq org-agenda-restrict nil)
  1960. (move-marker org-agenda-restrict-begin nil)
  1961. (move-marker org-agenda-restrict-end nil))
  1962. ;; Delete old local properties
  1963. (put 'org-agenda-redo-command 'org-lprops nil)
  1964. ;; Delete previously set last-arguments
  1965. (put 'org-agenda-redo-command 'last-args nil)
  1966. ;; Remember where this call originated
  1967. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1968. (unless keys
  1969. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1970. keys (car ans)
  1971. restriction (cdr ans)))
  1972. ;; Establish the restriction, if any
  1973. (when (and (not org-agenda-overriding-restriction) restriction)
  1974. (put 'org-agenda-files 'org-restrict (list bfn))
  1975. (cond
  1976. ((eq restriction 'region)
  1977. (setq org-agenda-restrict t)
  1978. (move-marker org-agenda-restrict-begin (region-beginning))
  1979. (move-marker org-agenda-restrict-end (region-end)))
  1980. ((eq restriction 'subtree)
  1981. (save-excursion
  1982. (setq org-agenda-restrict t)
  1983. (org-back-to-heading t)
  1984. (move-marker org-agenda-restrict-begin (point))
  1985. (move-marker org-agenda-restrict-end
  1986. (progn (org-end-of-subtree t)))))))
  1987. ;; For example the todo list should not need it (but does...)
  1988. (cond
  1989. ((setq entry (assoc keys org-agenda-custom-commands))
  1990. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1991. (progn
  1992. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1993. lprops (nth 4 entry))
  1994. (put 'org-agenda-redo-command 'org-lprops lprops)
  1995. (cond
  1996. ((eq type 'agenda)
  1997. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1998. ((eq type 'alltodo)
  1999. (org-let lprops '(org-todo-list current-prefix-arg)))
  2000. ((eq type 'search)
  2001. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2002. ((eq type 'stuck)
  2003. (org-let lprops '(org-agenda-list-stuck-projects
  2004. current-prefix-arg)))
  2005. ((eq type 'tags)
  2006. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2007. ((eq type 'tags-todo)
  2008. (org-let lprops '(org-tags-view '(4) match)))
  2009. ((eq type 'todo)
  2010. (org-let lprops '(org-todo-list match)))
  2011. ((eq type 'tags-tree)
  2012. (org-check-for-org-mode)
  2013. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2014. ((eq type 'todo-tree)
  2015. (org-check-for-org-mode)
  2016. (org-let lprops
  2017. '(org-occur (concat "^" outline-regexp "[ \t]*"
  2018. (regexp-quote match) "\\>"))))
  2019. ((eq type 'occur-tree)
  2020. (org-check-for-org-mode)
  2021. (org-let lprops '(org-occur match)))
  2022. ((functionp type)
  2023. (org-let lprops '(funcall type match)))
  2024. ((fboundp type)
  2025. (org-let lprops '(funcall type match)))
  2026. (t (error "Invalid custom agenda command type %s" type))))
  2027. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2028. ((equal keys "C")
  2029. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2030. (customize-variable 'org-agenda-custom-commands))
  2031. ((equal keys "a") (call-interactively 'org-agenda-list))
  2032. ((equal keys "s") (call-interactively 'org-search-view))
  2033. ((equal keys "t") (call-interactively 'org-todo-list))
  2034. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2035. ((equal keys "m") (call-interactively 'org-tags-view))
  2036. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2037. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2038. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2039. (org-add-hook
  2040. 'post-command-hook
  2041. (lambda ()
  2042. (unless (current-message)
  2043. (let* ((m (org-agenda-get-any-marker))
  2044. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2045. (when note
  2046. (message (concat
  2047. "FLAGGING-NOTE ([?] for more info): "
  2048. (org-add-props
  2049. (replace-regexp-in-string
  2050. "\\\\n" "//"
  2051. (copy-sequence note))
  2052. nil 'face 'org-warning)))))))
  2053. t t))
  2054. ((equal keys "L")
  2055. (unless (org-mode-p)
  2056. (error "This is not an Org-mode file"))
  2057. (unless restriction
  2058. (put 'org-agenda-files 'org-restrict (list bfn))
  2059. (org-call-with-arg 'org-timeline arg)))
  2060. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2061. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2062. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2063. (t (error "Invalid agenda key"))))))
  2064. (defun org-agenda-append-agenda ()
  2065. "Append another agenda view to the current one.
  2066. This function allows interactive building of block agendas.
  2067. Agenda views are separated by `org-agenda-block-separator'."
  2068. (interactive)
  2069. (unless (string= (buffer-name) org-agenda-buffer-name)
  2070. (error "Can only append from within agenda buffer"))
  2071. (let ((org-agenda-multi t))
  2072. (org-agenda)
  2073. (widen)))
  2074. (defun org-agenda-normalize-custom-commands (cmds)
  2075. (delq nil
  2076. (mapcar
  2077. (lambda (x)
  2078. (cond ((stringp (cdr x)) nil)
  2079. ((stringp (nth 1 x)) x)
  2080. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2081. (t (cons (car x) (cons "" (cdr x))))))
  2082. cmds)))
  2083. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2084. "The user interface for selecting an agenda command."
  2085. (catch 'exit
  2086. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2087. (restrict-ok (and bfn (org-mode-p)))
  2088. (region-p (org-region-active-p))
  2089. (custom org-agenda-custom-commands)
  2090. (selstring "")
  2091. restriction second-time
  2092. c entry key type match prefixes rmheader header-end custom1 desc
  2093. line lines left right n n1)
  2094. (save-window-excursion
  2095. (delete-other-windows)
  2096. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2097. (erase-buffer)
  2098. (insert (eval-when-compile
  2099. (let ((header
  2100. "
  2101. Press key for an agenda command: < Buffer, subtree/region restriction
  2102. -------------------------------- > Remove restriction
  2103. a Agenda for current week or day e Export agenda views
  2104. t List of all TODO entries T Entries with special TODO kwd
  2105. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2106. L Timeline for current buffer # List stuck projects (!=configure)
  2107. s Search for keywords C Configure custom agenda commands
  2108. / Multi-occur ? Find :FLAGGED: entries
  2109. ")
  2110. (start 0))
  2111. (while (string-match
  2112. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2113. header start)
  2114. (setq start (match-end 0))
  2115. (add-text-properties (match-beginning 2) (match-end 2)
  2116. '(face bold) header))
  2117. header)))
  2118. (setq header-end (move-marker (make-marker) (point)))
  2119. (while t
  2120. (setq custom1 custom)
  2121. (when (eq rmheader t)
  2122. (org-goto-line 1)
  2123. (re-search-forward ":" nil t)
  2124. (delete-region (match-end 0) (point-at-eol))
  2125. (forward-char 1)
  2126. (looking-at "-+")
  2127. (delete-region (match-end 0) (point-at-eol))
  2128. (move-marker header-end (match-end 0)))
  2129. (goto-char header-end)
  2130. (delete-region (point) (point-max))
  2131. ;; Produce all the lines that describe custom commands and prefixes
  2132. (setq lines nil)
  2133. (while (setq entry (pop custom1))
  2134. (setq key (car entry) desc (nth 1 entry)
  2135. type (nth 2 entry)
  2136. match (nth 3 entry))
  2137. (if (> (length key) 1)
  2138. (add-to-list 'prefixes (string-to-char key))
  2139. (setq line
  2140. (format
  2141. "%-4s%-14s"
  2142. (org-add-props (copy-sequence key)
  2143. '(face bold))
  2144. (cond
  2145. ((string-match "\\S-" desc) desc)
  2146. ((eq type 'agenda) "Agenda for current week or day")
  2147. ((eq type 'alltodo) "List of all TODO entries")
  2148. ((eq type 'search) "Word search")
  2149. ((eq type 'stuck) "List of stuck projects")
  2150. ((eq type 'todo) "TODO keyword")
  2151. ((eq type 'tags) "Tags query")
  2152. ((eq type 'tags-todo) "Tags (TODO)")
  2153. ((eq type 'tags-tree) "Tags tree")
  2154. ((eq type 'todo-tree) "TODO kwd tree")
  2155. ((eq type 'occur-tree) "Occur tree")
  2156. ((functionp type) (if (symbolp type)
  2157. (symbol-name type)
  2158. "Lambda expression"))
  2159. (t "???"))))
  2160. (if org-agenda-menu-show-matcher
  2161. (setq line
  2162. (concat line ": "
  2163. (cond
  2164. ((stringp match)
  2165. (setq match (copy-sequence match))
  2166. (org-add-props match nil 'face 'org-warning))
  2167. (match
  2168. (format "set of %d commands" (length match)))
  2169. (t ""))))
  2170. (if (org-string-nw-p match)
  2171. (add-text-properties
  2172. 0 (length line) (list 'help-echo
  2173. (concat "Matcher: "match)) line)))
  2174. (push line lines)))
  2175. (setq lines (nreverse lines))
  2176. (when prefixes
  2177. (mapc (lambda (x)
  2178. (push
  2179. (format "%s %s"
  2180. (org-add-props (char-to-string x)
  2181. nil 'face 'bold)
  2182. (or (cdr (assoc (concat selstring
  2183. (char-to-string x))
  2184. prefix-descriptions))
  2185. "Prefix key"))
  2186. lines))
  2187. prefixes))
  2188. ;; Check if we should display in two columns
  2189. (if org-agenda-menu-two-column
  2190. (progn
  2191. (setq n (length lines)
  2192. n1 (+ (/ n 2) (mod n 2))
  2193. right (nthcdr n1 lines)
  2194. left (copy-sequence lines))
  2195. (setcdr (nthcdr (1- n1) left) nil))
  2196. (setq left lines right nil))
  2197. (while left
  2198. (insert "\n" (pop left))
  2199. (when right
  2200. (if (< (current-column) 40)
  2201. (move-to-column 40 t)
  2202. (insert " "))
  2203. (insert (pop right))))
  2204. ;; Make the window the right size
  2205. (goto-char (point-min))
  2206. (if second-time
  2207. (if (not (pos-visible-in-window-p (point-max)))
  2208. (org-fit-window-to-buffer))
  2209. (setq second-time t)
  2210. (org-fit-window-to-buffer))
  2211. ;; Ask for selection
  2212. (message "Press key for agenda command%s:"
  2213. (if (or restrict-ok org-agenda-overriding-restriction)
  2214. (if org-agenda-overriding-restriction
  2215. " (restriction lock active)"
  2216. (if restriction
  2217. (format " (restricted to %s)" restriction)
  2218. " (unrestricted)"))
  2219. ""))
  2220. (setq c (read-char-exclusive))
  2221. (message "")
  2222. (cond
  2223. ((assoc (char-to-string c) custom)
  2224. (setq selstring (concat selstring (char-to-string c)))
  2225. (throw 'exit (cons selstring restriction)))
  2226. ((memq c prefixes)
  2227. (setq selstring (concat selstring (char-to-string c))
  2228. prefixes nil
  2229. rmheader (or rmheader t)
  2230. custom (delq nil (mapcar
  2231. (lambda (x)
  2232. (if (or (= (length (car x)) 1)
  2233. (/= (string-to-char (car x)) c))
  2234. nil
  2235. (cons (substring (car x) 1) (cdr x))))
  2236. custom))))
  2237. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2238. (message "Restriction is only possible in Org-mode buffers")
  2239. (ding) (sit-for 1))
  2240. ((eq c ?1)
  2241. (org-agenda-remove-restriction-lock 'noupdate)
  2242. (setq restriction 'buffer))
  2243. ((eq c ?0)
  2244. (org-agenda-remove-restriction-lock 'noupdate)
  2245. (setq restriction (if region-p 'region 'subtree)))
  2246. ((eq c ?<)
  2247. (org-agenda-remove-restriction-lock 'noupdate)
  2248. (setq restriction
  2249. (cond
  2250. ((eq restriction 'buffer)
  2251. (if region-p 'region 'subtree))
  2252. ((memq restriction '(subtree region))
  2253. nil)
  2254. (t 'buffer))))
  2255. ((eq c ?>)
  2256. (org-agenda-remove-restriction-lock 'noupdate)
  2257. (setq restriction nil))
  2258. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2259. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2260. ((and (> (length selstring) 0) (eq c ?\d))
  2261. (delete-window)
  2262. (org-agenda-get-restriction-and-command prefix-descriptions))
  2263. ((equal c ?q) (error "Abort"))
  2264. (t (error "Invalid key %c" c))))))))
  2265. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2266. (defvar org-agenda-last-arguments nil
  2267. "The arguments of the previous call to `org-agenda'.")
  2268. (defun org-agenda-run-series (name series)
  2269. (org-let (nth 1 series) '(org-prepare-agenda name))
  2270. (let* ((org-agenda-multi t)
  2271. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2272. (org-agenda-overriding-arguments
  2273. (or org-agenda-overriding-arguments
  2274. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2275. (get 'org-agenda-redo-command 'last-args))))
  2276. (cmds (car series))
  2277. (gprops (nth 1 series))
  2278. match ;; The byte compiler incorrectly complains about this. Keep it!
  2279. cmd type lprops)
  2280. (while (setq cmd (pop cmds))
  2281. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2282. (cond
  2283. ((eq type 'agenda)
  2284. (org-let2 gprops lprops
  2285. '(call-interactively 'org-agenda-list)))
  2286. ((eq type 'alltodo)
  2287. (org-let2 gprops lprops
  2288. '(call-interactively 'org-todo-list)))
  2289. ((eq type 'search)
  2290. (org-let2 gprops lprops
  2291. '(org-search-view current-prefix-arg match nil)))
  2292. ((eq type 'stuck)
  2293. (org-let2 gprops lprops
  2294. '(call-interactively 'org-agenda-list-stuck-projects)))
  2295. ((eq type 'tags)
  2296. (org-let2 gprops lprops
  2297. '(org-tags-view current-prefix-arg match)))
  2298. ((eq type 'tags-todo)
  2299. (org-let2 gprops lprops
  2300. '(org-tags-view '(4) match)))
  2301. ((eq type 'todo)
  2302. (org-let2 gprops lprops
  2303. '(org-todo-list match)))
  2304. ((fboundp type)
  2305. (org-let2 gprops lprops
  2306. '(funcall type match)))
  2307. (t (error "Invalid type in command series"))))
  2308. (widen)
  2309. (setq org-agenda-redo-command redo)
  2310. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2311. (goto-char (point-min)))
  2312. (org-fit-agenda-window)
  2313. (org-let (nth 1 series) '(org-finalize-agenda)))
  2314. ;;;###autoload
  2315. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2316. "Run an agenda command in batch mode and send the result to STDOUT.
  2317. If CMD-KEY is a string of length 1, it is used as a key in
  2318. `org-agenda-custom-commands' and triggers this command. If it is a
  2319. longer string it is used as a tags/todo match string.
  2320. Parameters are alternating variable names and values that will be bound
  2321. before running the agenda command."
  2322. (let (pars)
  2323. (while parameters
  2324. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2325. (if (> (length cmd-key) 2)
  2326. (eval (list 'let (nreverse pars)
  2327. (list 'org-tags-view nil cmd-key)))
  2328. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2329. (set-buffer org-agenda-buffer-name)
  2330. (princ (org-encode-for-stdout (buffer-string)))))
  2331. ;(defun org-encode-for-stdout (string)
  2332. ; (if (fboundp 'encode-coding-string)
  2333. ; (encode-coding-string string buffer-file-coding-system)
  2334. ; string))
  2335. (defun org-encode-for-stdout (string)
  2336. string)
  2337. (defvar org-agenda-info nil)
  2338. ;;;###autoload
  2339. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2340. "Run an agenda command in batch mode and send the result to STDOUT.
  2341. If CMD-KEY is a string of length 1, it is used as a key in
  2342. `org-agenda-custom-commands' and triggers this command. If it is a
  2343. longer string it is used as a tags/todo match string.
  2344. Parameters are alternating variable names and values that will be bound
  2345. before running the agenda command.
  2346. The output gives a line for each selected agenda item. Each
  2347. item is a list of comma-separated values, like this:
  2348. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2349. category The category of the item
  2350. head The headline, without TODO kwd, TAGS and PRIORITY
  2351. type The type of the agenda entry, can be
  2352. todo selected in TODO match
  2353. tagsmatch selected in tags match
  2354. diary imported from diary
  2355. deadline a deadline on given date
  2356. scheduled scheduled on given date
  2357. timestamp entry has timestamp on given date
  2358. closed entry was closed on given date
  2359. upcoming-deadline warning about deadline
  2360. past-scheduled forwarded scheduled item
  2361. block entry has date block including g. date
  2362. todo The todo keyword, if any
  2363. tags All tags including inherited ones, separated by colons
  2364. date The relevant date, like 2007-2-14
  2365. time The time, like 15:00-16:50
  2366. extra Sting with extra planning info
  2367. priority-l The priority letter if any was given
  2368. priority-n The computed numerical priority
  2369. agenda-day The day in the agenda where this is listed"
  2370. (let (pars)
  2371. (while parameters
  2372. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2373. (push (list 'org-agenda-remove-tags t) pars)
  2374. (if (> (length cmd-key) 2)
  2375. (eval (list 'let (nreverse pars)
  2376. (list 'org-tags-view nil cmd-key)))
  2377. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2378. (set-buffer org-agenda-buffer-name)
  2379. (let* ((lines (org-split-string (buffer-string) "\n"))
  2380. line)
  2381. (while (setq line (pop lines))
  2382. (catch 'next
  2383. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2384. (setq org-agenda-info
  2385. (org-fix-agenda-info (text-properties-at 0 line)))
  2386. (princ
  2387. (org-encode-for-stdout
  2388. (mapconcat 'org-agenda-export-csv-mapper
  2389. '(org-category txt type todo tags date time extra
  2390. priority-letter priority agenda-day)
  2391. ",")))
  2392. (princ "\n"))))))
  2393. (defun org-fix-agenda-info (props)
  2394. "Make sure all properties on an agenda item have a canonical form.
  2395. This ensures the export commands can easily use it."
  2396. (let (tmp re)
  2397. (when (setq tmp (plist-get props 'tags))
  2398. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2399. (when (setq tmp (plist-get props 'date))
  2400. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2401. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2402. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2403. (setq tmp (calendar-date-string tmp)))
  2404. (setq props (plist-put props 'date tmp)))
  2405. (when (setq tmp (plist-get props 'day))
  2406. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2407. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2408. (setq tmp (calendar-date-string tmp)))
  2409. (setq props (plist-put props 'day tmp))
  2410. (setq props (plist-put props 'agenda-day tmp)))
  2411. (when (setq tmp (plist-get props 'txt))
  2412. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2413. (plist-put props 'priority-letter (match-string 1 tmp))
  2414. (setq tmp (replace-match "" t t tmp)))
  2415. (when (and (setq re (plist-get props 'org-todo-regexp))
  2416. (setq re (concat "\\`\\.*" re " ?"))
  2417. (string-match re tmp))
  2418. (plist-put props 'todo (match-string 1 tmp))
  2419. (setq tmp (replace-match "" t t tmp)))
  2420. (plist-put props 'txt tmp)))
  2421. props)
  2422. (defun org-agenda-export-csv-mapper (prop)
  2423. (let ((res (plist-get org-agenda-info prop)))
  2424. (setq res
  2425. (cond
  2426. ((not res) "")
  2427. ((stringp res) res)
  2428. (t (prin1-to-string res))))
  2429. (while (string-match "," res)
  2430. (setq res (replace-match ";" t t res)))
  2431. (org-trim res)))
  2432. ;;;###autoload
  2433. (defun org-store-agenda-views (&rest parameters)
  2434. (interactive)
  2435. (eval (list 'org-batch-store-agenda-views)))
  2436. ;; FIXME, why is this a macro?????
  2437. ;;;###autoload
  2438. (defmacro org-batch-store-agenda-views (&rest parameters)
  2439. "Run all custom agenda commands that have a file argument."
  2440. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2441. (pop-up-frames nil)
  2442. (dir default-directory)
  2443. pars cmd thiscmdkey files opts cmd-or-set)
  2444. (while parameters
  2445. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2446. (setq pars (reverse pars))
  2447. (save-window-excursion
  2448. (while cmds
  2449. (setq cmd (pop cmds)
  2450. thiscmdkey (car cmd)
  2451. cmd-or-set (nth 2 cmd)
  2452. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2453. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2454. (if (stringp files) (setq files (list files)))
  2455. (when files
  2456. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2457. (list 'org-agenda nil thiscmdkey)))
  2458. (set-buffer org-agenda-buffer-name)
  2459. (while files
  2460. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2461. (list 'org-write-agenda
  2462. (expand-file-name (pop files) dir) nil t))))
  2463. (and (get-buffer org-agenda-buffer-name)
  2464. (kill-buffer org-agenda-buffer-name)))))))
  2465. (defun org-agenda-mark-header-line (pos)
  2466. "Mark the line at POS as an agenda structure header."
  2467. (save-excursion
  2468. (goto-char pos)
  2469. (put-text-property (point-at-bol) (point-at-eol)
  2470. 'org-agenda-structural-header t)
  2471. (when org-agenda-title-append
  2472. (put-text-property (point-at-bol) (point-at-eol)
  2473. 'org-agenda-title-append org-agenda-title-append))))
  2474. (defvar org-mobile-creating-agendas)
  2475. (defun org-write-agenda (file &optional open nosettings)
  2476. "Write the current buffer (an agenda view) as a file.
  2477. Depending on the extension of the file name, plain text (.txt),
  2478. HTML (.html or .htm) or Postscript (.ps) is produced.
  2479. If the extension is .ics, run icalendar export over all files used
  2480. to construct the agenda and limit the export to entries listed in the
  2481. agenda now.
  2482. With prefix argument OPEN, open the new file immediately.
  2483. If NOSETTINGS is given, do not scope the settings of
  2484. `org-agenda-exporter-settings' into the export commands. This is used when
  2485. the settings have already been scoped and we do not wish to overrule other,
  2486. higher priority settings."
  2487. (interactive "FWrite agenda to file: \nP")
  2488. (if (not (file-writable-p file))
  2489. (error "Cannot write agenda to file %s" file))
  2490. (org-let (if nosettings nil org-agenda-exporter-settings)
  2491. '(save-excursion
  2492. (save-window-excursion
  2493. (org-agenda-mark-filtered-text)
  2494. (let ((bs (copy-sequence (buffer-string))) beg)
  2495. (org-agenda-unmark-filtered-text)
  2496. (with-temp-buffer
  2497. (rename-buffer "Agenda View" t)
  2498. (set-buffer-modified-p nil)
  2499. (insert bs)
  2500. (org-agenda-remove-marked-text 'org-filtered)
  2501. (while (setq beg (text-property-any (point-min) (point-max)
  2502. 'org-filtered t))
  2503. (delete-region
  2504. beg (or (next-single-property-change beg 'org-filtered)
  2505. (point-max))))
  2506. (run-hooks 'org-agenda-before-write-hook)
  2507. (cond
  2508. ((org-bound-and-true-p org-mobile-creating-agendas)
  2509. (org-mobile-write-agenda-for-mobile file))
  2510. ((string-match "\\.html?\\'" file)
  2511. (require 'htmlize)
  2512. (set-buffer (htmlize-buffer (current-buffer)))
  2513. (when (and org-agenda-export-html-style
  2514. (string-match "<style>" org-agenda-export-html-style))
  2515. ;; replace <style> section with org-agenda-export-html-style
  2516. (goto-char (point-min))
  2517. (kill-region (- (search-forward "<style") 6)
  2518. (search-forward "</style>"))
  2519. (insert org-agenda-export-html-style))
  2520. (write-file file)
  2521. (kill-buffer (current-buffer))
  2522. (message "HTML written to %s" file))
  2523. ((string-match "\\.ps\\'" file)
  2524. (require 'ps-print)
  2525. (ps-print-buffer-with-faces file)
  2526. (message "Postscript written to %s" file))
  2527. ((string-match "\\.pdf\\'" file)
  2528. (require 'ps-print)
  2529. (ps-print-buffer-with-faces
  2530. (concat (file-name-sans-extension file) ".ps"))
  2531. (call-process "ps2pdf" nil nil nil
  2532. (expand-file-name
  2533. (concat (file-name-sans-extension file) ".ps"))
  2534. (expand-file-name file))
  2535. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2536. (message "PDF written to %s" file))
  2537. ((string-match "\\.ics\\'" file)
  2538. (require 'org-icalendar)
  2539. (let ((org-agenda-marker-table
  2540. (org-create-marker-find-array
  2541. (org-agenda-collect-markers)))
  2542. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2543. (org-combined-agenda-icalendar-file file))
  2544. (apply 'org-export-icalendar 'combine
  2545. (org-agenda-files nil 'ifmode))))
  2546. (t
  2547. (let ((bs (buffer-string)))
  2548. (find-file file)
  2549. (erase-buffer)
  2550. (insert bs)
  2551. (save-buffer 0)
  2552. (kill-buffer (current-buffer))
  2553. (message "Plain text written to %s" file))))))))
  2554. (set-buffer org-agenda-buffer-name))
  2555. (when open (org-open-file file)))
  2556. (defvar org-agenda-filter-overlays nil)
  2557. (defun org-agenda-mark-filtered-text ()
  2558. "Mark all text hidden by filtering with a text property."
  2559. (let ((inhibit-read-only t))
  2560. (mapc
  2561. (lambda (o)
  2562. (when (equal (overlay-buffer o) (current-buffer))
  2563. (put-text-property
  2564. (overlay-start o) (overlay-end o)
  2565. 'org-filtered t)))
  2566. org-agenda-filter-overlays)))
  2567. (defun org-agenda-unmark-filtered-text ()
  2568. "Remove the filtering text property."
  2569. (let ((inhibit-read-only t))
  2570. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2571. (defun org-agenda-remove-marked-text (property &optional value)
  2572. "Delete all text marked with VALUE of PROPERTY.
  2573. VALUE defaults to t."
  2574. (let (beg)
  2575. (setq value (or value t))
  2576. (while (setq beg (text-property-any (point-min) (point-max)
  2577. property value))
  2578. (delete-region
  2579. beg (or (next-single-property-change beg 'org-filtered)
  2580. (point-max))))))
  2581. (defun org-agenda-add-entry-text ()
  2582. "Add entry text to agenda lines.
  2583. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2584. entry text following headings shown in the agenda.
  2585. Drawers will be excluded, also the line with scheduling/deadline info."
  2586. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2587. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2588. (let (m txt)
  2589. (goto-char (point-min))
  2590. (while (not (eobp))
  2591. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2592. (beginning-of-line 2)
  2593. (setq txt (org-agenda-get-some-entry-text
  2594. m org-agenda-add-entry-text-maxlines " > "))
  2595. (end-of-line 1)
  2596. (if (string-match "\\S-" txt)
  2597. (insert "\n" txt)
  2598. (or (eobp) (forward-char 1))))))))
  2599. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2600. &rest keep)
  2601. "Extract entry text from MARKER, at most N-LINES lines.
  2602. This will ignore drawers etc, just get the text.
  2603. If INDENT is given, prefix every line with this string. If KEEP is
  2604. given, it is a list of symbols, defining stuff that should not be
  2605. removed from the entry content. Currently only `planning' is allowed here."
  2606. (let (txt drawer-re kwd-time-re ind)
  2607. (save-excursion
  2608. (with-current-buffer (marker-buffer marker)
  2609. (if (not (org-mode-p))
  2610. (setq txt "")
  2611. (save-excursion
  2612. (save-restriction
  2613. (widen)
  2614. (goto-char marker)
  2615. (end-of-line 1)
  2616. (setq txt (buffer-substring
  2617. (min (1+ (point)) (point-max))
  2618. (progn (outline-next-heading) (point)))
  2619. drawer-re org-drawer-regexp
  2620. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2621. ".*\n?"))
  2622. (with-temp-buffer
  2623. (insert txt)
  2624. (when org-agenda-add-entry-text-descriptive-links
  2625. (goto-char (point-min))
  2626. (while (org-activate-bracket-links (point-max))
  2627. (add-text-properties (match-beginning 0) (match-end 0)
  2628. '(face org-link))))
  2629. (goto-char (point-min))
  2630. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2631. (set-text-properties (match-beginning 0) (match-end 0)
  2632. nil))
  2633. (goto-char (point-min))
  2634. (while (re-search-forward drawer-re nil t)
  2635. (delete-region
  2636. (match-beginning 0)
  2637. (progn (re-search-forward
  2638. "^[ \t]*:END:.*\n?" nil 'move)
  2639. (point))))
  2640. (unless (member 'planning keep)
  2641. (goto-char (point-min))
  2642. (while (re-search-forward kwd-time-re nil t)
  2643. (replace-match "")))
  2644. (goto-char (point-min))
  2645. (when org-agenda-entry-text-exclude-regexps
  2646. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2647. (while (setq re (pop re-list))
  2648. (goto-char (point-min))
  2649. (while (re-search-forward re nil t)
  2650. (replace-match "")))))
  2651. (goto-char (point-max))
  2652. (skip-chars-backward " \t\n")
  2653. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2654. ;; find and remove min common indentation
  2655. (goto-char (point-min))
  2656. (untabify (point-min) (point-max))
  2657. (setq ind (org-get-indentation))
  2658. (while (not (eobp))
  2659. (unless (looking-at "[ \t]*$")
  2660. (setq ind (min ind (org-get-indentation))))
  2661. (beginning-of-line 2))
  2662. (goto-char (point-min))
  2663. (while (not (eobp))
  2664. (unless (looking-at "[ \t]*$")
  2665. (move-to-column ind)
  2666. (delete-region (point-at-bol) (point)))
  2667. (beginning-of-line 2))
  2668. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2669. (goto-char (point-min))
  2670. (when indent
  2671. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2672. (replace-match indent t t)))
  2673. (goto-char (point-min))
  2674. (while (looking-at "[ \t]*\n") (replace-match ""))
  2675. (goto-char (point-max))
  2676. (when (> (org-current-line)
  2677. n-lines)
  2678. (org-goto-line (1+ n-lines))
  2679. (backward-char 1))
  2680. (setq txt (buffer-substring (point-min) (point)))))))))
  2681. txt))
  2682. (defun org-agenda-collect-markers ()
  2683. "Collect the markers pointing to entries in the agenda buffer."
  2684. (let (m markers)
  2685. (save-excursion
  2686. (goto-char (point-min))
  2687. (while (not (eobp))
  2688. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2689. (org-get-at-bol 'org-marker)))
  2690. (push m markers))
  2691. (beginning-of-line 2)))
  2692. (nreverse markers)))
  2693. (defun org-create-marker-find-array (marker-list)
  2694. "Create a alist of files names with all marker positions in that file."
  2695. (let (f tbl m a p)
  2696. (while (setq m (pop marker-list))
  2697. (setq p (marker-position m)
  2698. f (buffer-file-name (or (buffer-base-buffer
  2699. (marker-buffer m))
  2700. (marker-buffer m))))
  2701. (if (setq a (assoc f tbl))
  2702. (push (marker-position m) (cdr a))
  2703. (push (list f p) tbl)))
  2704. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2705. tbl)))
  2706. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2707. (defun org-check-agenda-marker-table ()
  2708. "Check of the current entry is on the marker list."
  2709. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2710. a)
  2711. (and (setq a (assoc file org-agenda-marker-table))
  2712. (save-match-data
  2713. (save-excursion
  2714. (org-back-to-heading t)
  2715. (member (point) (cdr a)))))))
  2716. (defun org-check-for-org-mode ()
  2717. "Make sure current buffer is in org-mode. Error if not."
  2718. (or (org-mode-p)
  2719. (error "Cannot execute org-mode agenda command on buffer in %s"
  2720. major-mode)))
  2721. (defun org-fit-agenda-window ()
  2722. "Fit the window to the buffer size."
  2723. (and (memq org-agenda-window-setup '(reorganize-frame))
  2724. (fboundp 'fit-window-to-buffer)
  2725. (org-fit-window-to-buffer
  2726. nil
  2727. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2728. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2729. ;;; Agenda prepare and finalize
  2730. (defvar org-agenda-multi nil) ; dynamically scoped
  2731. (defvar org-agenda-buffer-name "*Org Agenda*")
  2732. (defvar org-pre-agenda-window-conf nil)
  2733. (defvar org-agenda-columns-active nil)
  2734. (defvar org-agenda-name nil)
  2735. (defvar org-agenda-filter nil)
  2736. (defvar org-agenda-filter-while-redo nil)
  2737. (defvar org-agenda-filter-preset nil
  2738. "A preset of the tags filter used for secondary agenda filtering.
  2739. This must be a list of strings, each string must be a single tag preceded
  2740. by \"+\" or \"-\".
  2741. This variable should not be set directly, but agenda custom commands can
  2742. bind it in the options section. The preset filter is a global property of
  2743. the entire agenda view. In a block agenda, it will not work reliably to
  2744. define a filter for one of the individual blocks. You need to set it in
  2745. the global options and expect it to be applied to the entire view.")
  2746. (defun org-prepare-agenda (&optional name)
  2747. (setq org-todo-keywords-for-agenda nil)
  2748. (setq org-done-keywords-for-agenda nil)
  2749. (setq org-drawers-for-agenda nil)
  2750. (unless org-agenda-persistent-filter
  2751. (setq org-agenda-filter nil))
  2752. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2753. (if org-agenda-multi
  2754. (progn
  2755. (setq buffer-read-only nil)
  2756. (goto-char (point-max))
  2757. (unless (or (bobp) org-agenda-compact-blocks)
  2758. (insert "\n"
  2759. (if (stringp org-agenda-block-separator)
  2760. org-agenda-block-separator
  2761. (make-string (window-width) org-agenda-block-separator))
  2762. "\n"))
  2763. (narrow-to-region (point) (point-max)))
  2764. (org-agenda-reset-markers)
  2765. (setq org-agenda-contributing-files nil)
  2766. (setq org-agenda-columns-active nil)
  2767. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2768. (setq org-todo-keywords-for-agenda
  2769. (org-uniquify org-todo-keywords-for-agenda))
  2770. (setq org-done-keywords-for-agenda
  2771. (org-uniquify org-done-keywords-for-agenda))
  2772. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2773. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2774. (awin (get-buffer-window abuf)))
  2775. (cond
  2776. ((equal (current-buffer) abuf) nil)
  2777. (awin (select-window awin))
  2778. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2779. ((equal org-agenda-window-setup 'current-window)
  2780. (switch-to-buffer abuf))
  2781. ((equal org-agenda-window-setup 'other-window)
  2782. (org-switch-to-buffer-other-window abuf))
  2783. ((equal org-agenda-window-setup 'other-frame)
  2784. (switch-to-buffer-other-frame abuf))
  2785. ((equal org-agenda-window-setup 'reorganize-frame)
  2786. (delete-other-windows)
  2787. (org-switch-to-buffer-other-window abuf)))
  2788. ;; additional test in case agenda is invoked from within agenda
  2789. ;; buffer via elisp link
  2790. (unless (equal (current-buffer) abuf)
  2791. (switch-to-buffer abuf)))
  2792. (setq buffer-read-only nil)
  2793. (let ((inhibit-read-only t)) (erase-buffer))
  2794. (org-agenda-mode)
  2795. (and name (not org-agenda-name)
  2796. (org-set-local 'org-agenda-name name)))
  2797. (setq buffer-read-only nil))
  2798. (defun org-finalize-agenda ()
  2799. "Finishing touch for the agenda buffer, called just before displaying it."
  2800. (unless org-agenda-multi
  2801. (save-excursion
  2802. (let ((inhibit-read-only t))
  2803. (goto-char (point-min))
  2804. (while (org-activate-bracket-links (point-max))
  2805. (add-text-properties (match-beginning 0) (match-end 0)
  2806. '(face org-link)))
  2807. (org-agenda-align-tags)
  2808. (unless org-agenda-with-colors
  2809. (remove-text-properties (point-min) (point-max) '(face nil))))
  2810. (if (and (boundp 'org-agenda-overriding-columns-format)
  2811. org-agenda-overriding-columns-format)
  2812. (org-set-local 'org-agenda-overriding-columns-format
  2813. org-agenda-overriding-columns-format))
  2814. (if (and (boundp 'org-agenda-view-columns-initially)
  2815. org-agenda-view-columns-initially)
  2816. (org-agenda-columns))
  2817. (when org-agenda-fontify-priorities
  2818. (org-agenda-fontify-priorities))
  2819. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2820. (org-agenda-dim-blocked-tasks))
  2821. (org-agenda-mark-clocking-task)
  2822. (when org-agenda-entry-text-mode
  2823. (org-agenda-entry-text-hide)
  2824. (org-agenda-entry-text-show))
  2825. (if (functionp 'org-habit-insert-consistency-graphs)
  2826. (org-habit-insert-consistency-graphs))
  2827. (run-hooks 'org-finalize-agenda-hook)
  2828. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2829. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2830. (org-agenda-filter-apply org-agenda-filter))
  2831. )))
  2832. (defun org-agenda-mark-clocking-task ()
  2833. "Mark the current clock entry in the agenda if it is present."
  2834. (mapc (lambda (o)
  2835. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2836. (delete-overlay o)))
  2837. (overlays-in (point-min) (point-max)))
  2838. (when (marker-buffer org-clock-hd-marker)
  2839. (save-excursion
  2840. (goto-char (point-min))
  2841. (let (s ov)
  2842. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2843. (goto-char s)
  2844. (when (equal (org-get-at-bol 'org-hd-marker)
  2845. org-clock-hd-marker)
  2846. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2847. (overlay-put ov 'type 'org-agenda-clocking)
  2848. (overlay-put ov 'face 'org-agenda-clocking)
  2849. (overlay-put ov 'help-echo
  2850. "The clock is running in this item")))))))
  2851. (defun org-agenda-fontify-priorities ()
  2852. "Make highest priority lines bold, and lowest italic."
  2853. (interactive)
  2854. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2855. (delete-overlay o)))
  2856. (overlays-in (point-min) (point-max)))
  2857. (save-excursion
  2858. (let ((inhibit-read-only t)
  2859. b e p ov h l)
  2860. (goto-char (point-min))
  2861. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2862. (setq h (or (get-char-property (point) 'org-highest-priority)
  2863. org-highest-priority)
  2864. l (or (get-char-property (point) 'org-lowest-priority)
  2865. org-lowest-priority)
  2866. p (string-to-char (match-string 1))
  2867. b (match-beginning 0)
  2868. e (if (eq org-agenda-fontify-priorities 'cookies)
  2869. (match-end 0)
  2870. (point-at-eol))
  2871. ov (make-overlay b e))
  2872. (overlay-put
  2873. ov 'face
  2874. (cond ((org-face-from-face-or-color
  2875. 'priority nil
  2876. (cdr (assoc p org-priority-faces))))
  2877. ((and (listp org-agenda-fontify-priorities)
  2878. (org-face-from-face-or-color
  2879. 'priority nil
  2880. (cdr (assoc p org-agenda-fontify-priorities)))))
  2881. ((equal p l) 'italic)
  2882. ((equal p h) 'bold)))
  2883. (overlay-put ov 'org-type 'org-priority)))))
  2884. (defun org-agenda-dim-blocked-tasks ()
  2885. "Dim currently blocked TODO's in the agenda display."
  2886. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2887. (delete-overlay o)))
  2888. (overlays-in (point-min) (point-max)))
  2889. (save-excursion
  2890. (let ((inhibit-read-only t)
  2891. (org-depend-tag-blocked nil)
  2892. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2893. org-blocked-by-checkboxes
  2894. invis1 b e p ov h l)
  2895. (goto-char (point-min))
  2896. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2897. (and pos (goto-char (1+ pos))))
  2898. (setq org-blocked-by-checkboxes nil invis1 invis)
  2899. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2900. (when (and marker
  2901. (not (with-current-buffer (marker-buffer marker)
  2902. (save-excursion
  2903. (goto-char marker)
  2904. (if (org-entry-get nil "NOBLOCKING")
  2905. t ;; Never block this entry
  2906. (run-hook-with-args-until-failure
  2907. 'org-blocker-hook
  2908. (list :type 'todo-state-change
  2909. :position marker
  2910. :from 'todo
  2911. :to 'done)))))))
  2912. (if org-blocked-by-checkboxes (setq invis1 nil))
  2913. (setq b (if invis1
  2914. (max (point-min) (1- (point-at-bol)))
  2915. (point-at-bol))
  2916. e (point-at-eol)
  2917. ov (make-overlay b e))
  2918. (if invis1
  2919. (overlay-put ov 'invisible t)
  2920. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2921. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2922. (defvar org-agenda-skip-function nil
  2923. "Function to be called at each match during agenda construction.
  2924. If this function returns nil, the current match should not be skipped.
  2925. Otherwise, the function must return a position from where the search
  2926. should be continued.
  2927. This may also be a Lisp form, it will be evaluated.
  2928. Never set this variable using `setq' or so, because then it will apply
  2929. to all future agenda commands. If you do want a global skipping condition,
  2930. use the option `org-agenda-skip-function-global' instead.
  2931. The correct usage for `org-agenda-skip-function' is to bind it with
  2932. `let' to scope it dynamically into the agenda-constructing command.
  2933. A good way to set it is through options in `org-agenda-custom-commands'.")
  2934. (defun org-agenda-skip ()
  2935. "Throw to `:skip' in places that should be skipped.
  2936. Also moves point to the end of the skipped region, so that search can
  2937. continue from there."
  2938. (let ((p (point-at-bol)) to)
  2939. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2940. (get-text-property p :org-archived)
  2941. (org-end-of-subtree t)
  2942. (throw :skip t))
  2943. (and org-agenda-skip-comment-trees
  2944. (get-text-property p :org-comment)
  2945. (org-end-of-subtree t)
  2946. (throw :skip t))
  2947. (if (equal (char-after p) ?#) (throw :skip t))
  2948. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2949. (org-agenda-skip-eval org-agenda-skip-function)))
  2950. (goto-char to)
  2951. (throw :skip t))))
  2952. (defun org-agenda-skip-eval (form)
  2953. "If FORM is a function or a list, call (or eval) is and return result.
  2954. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2955. and match data are returned to the previous state no matter what these
  2956. functions do."
  2957. (let (fp)
  2958. (and form
  2959. (or (setq fp (functionp form))
  2960. (consp form))
  2961. (save-excursion
  2962. (save-match-data
  2963. (if fp
  2964. (funcall form)
  2965. (eval form)))))))
  2966. (defvar org-agenda-markers nil
  2967. "List of all currently active markers created by `org-agenda'.")
  2968. (defvar org-agenda-last-marker-time (org-float-time)
  2969. "Creation time of the last agenda marker.")
  2970. (defun org-agenda-new-marker (&optional pos)
  2971. "Return a new agenda marker.
  2972. Org-mode keeps a list of these markers and resets them when they are
  2973. no longer in use."
  2974. (let ((m (copy-marker (or pos (point)))))
  2975. (setq org-agenda-last-marker-time (org-float-time))
  2976. (push m org-agenda-markers)
  2977. m))
  2978. (defun org-agenda-reset-markers ()
  2979. "Reset markers created by `org-agenda'."
  2980. (while org-agenda-markers
  2981. (move-marker (pop org-agenda-markers) nil)))
  2982. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2983. "Save relative positions of markers in region."
  2984. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2985. org-agenda-markers))
  2986. ;;; Entry text mode
  2987. (defun org-agenda-entry-text-show-here ()
  2988. "Add some text from the entry as context to the current line."
  2989. (let (m txt o)
  2990. (setq m (org-get-at-bol 'org-hd-marker))
  2991. (unless (marker-buffer m)
  2992. (error "No marker points to an entry here"))
  2993. (setq txt (concat "\n" (org-no-properties
  2994. (org-agenda-get-some-entry-text
  2995. m org-agenda-entry-text-maxlines " > "))))
  2996. (when (string-match "\\S-" txt)
  2997. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2998. (overlay-put o 'evaporate t)
  2999. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3000. (overlay-put o 'after-string txt))))
  3001. (defun org-agenda-entry-text-show ()
  3002. "Add entry context for all agenda lines."
  3003. (interactive)
  3004. (save-excursion
  3005. (goto-char (point-max))
  3006. (beginning-of-line 1)
  3007. (while (not (bobp))
  3008. (when (org-get-at-bol 'org-hd-marker)
  3009. (org-agenda-entry-text-show-here))
  3010. (beginning-of-line 0))))
  3011. (defun org-agenda-entry-text-hide ()
  3012. "Remove any shown entry context."
  3013. (delq nil
  3014. (mapcar (lambda (o)
  3015. (if (eq (overlay-get o 'org-overlay-type)
  3016. 'agenda-entry-content)
  3017. (progn (delete-overlay o) t)))
  3018. (overlays-in (point-min) (point-max)))))
  3019. (defun org-agenda-get-day-face (date)
  3020. "Return the face DATE should be displayed with."
  3021. (or (and (functionp org-agenda-day-face-function)
  3022. (funcall org-agenda-day-face-function date))
  3023. (cond ((org-agenda-todayp date)
  3024. 'org-agenda-date-today)
  3025. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3026. 'org-agenda-date-weekend)
  3027. (t 'org-agenda-date))))
  3028. ;;; Agenda timeline
  3029. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3030. (defun org-timeline (&optional include-all)
  3031. "Show a time-sorted view of the entries in the current org file.
  3032. Only entries with a time stamp of today or later will be listed. With
  3033. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3034. under the current date.
  3035. If the buffer contains an active region, only check the region for
  3036. dates."
  3037. (interactive "P")
  3038. (org-compile-prefix-format 'timeline)
  3039. (org-set-sorting-strategy 'timeline)
  3040. (let* ((dopast t)
  3041. (dotodo include-all)
  3042. (doclosed org-agenda-show-log)
  3043. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3044. (current-buffer))))
  3045. (date (calendar-current-date))
  3046. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3047. (end (if (org-region-active-p) (region-end) (point-max)))
  3048. (day-numbers (org-get-all-dates beg end 'no-ranges
  3049. t doclosed ; always include today
  3050. org-timeline-show-empty-dates))
  3051. (org-deadline-warning-days 0)
  3052. (org-agenda-only-exact-dates t)
  3053. (today (org-today))
  3054. (past t)
  3055. args
  3056. s e rtn d emptyp)
  3057. (setq org-agenda-redo-command
  3058. (list 'progn
  3059. (list 'org-switch-to-buffer-other-window (current-buffer))
  3060. (list 'org-timeline (list 'quote include-all))))
  3061. (if (not dopast)
  3062. ;; Remove past dates from the list of dates.
  3063. (setq day-numbers (delq nil (mapcar (lambda(x)
  3064. (if (>= x today) x nil))
  3065. day-numbers))))
  3066. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3067. (if doclosed (push :closed args))
  3068. (push :timestamp args)
  3069. (push :deadline args)
  3070. (push :scheduled args)
  3071. (push :sexp args)
  3072. (if dotodo (push :todo args))
  3073. (insert "Timeline of file " entry "\n")
  3074. (add-text-properties (point-min) (point)
  3075. (list 'face 'org-agenda-structure))
  3076. (org-agenda-mark-header-line (point-min))
  3077. (while (setq d (pop day-numbers))
  3078. (if (and (listp d) (eq (car d) :omitted))
  3079. (progn
  3080. (setq s (point))
  3081. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3082. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3083. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3084. (if (and (>= d today)
  3085. dopast
  3086. past)
  3087. (progn
  3088. (setq past nil)
  3089. (insert (make-string 79 ?-) "\n")))
  3090. (setq date (calendar-gregorian-from-absolute d))
  3091. (setq s (point))
  3092. (setq rtn (and (not emptyp)
  3093. (apply 'org-agenda-get-day-entries entry
  3094. date args)))
  3095. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3096. (progn
  3097. (insert
  3098. (if (stringp org-agenda-format-date)
  3099. (format-time-string org-agenda-format-date
  3100. (org-time-from-absolute date))
  3101. (funcall org-agenda-format-date date))
  3102. "\n")
  3103. (put-text-property s (1- (point)) 'face
  3104. (org-agenda-get-day-face date))
  3105. (put-text-property s (1- (point)) 'org-date-line t)
  3106. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3107. (if (equal d today)
  3108. (put-text-property s (1- (point)) 'org-today t))
  3109. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3110. (put-text-property s (1- (point)) 'day d)))))
  3111. (goto-char (point-min))
  3112. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3113. (point-min)))
  3114. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3115. (org-finalize-agenda)
  3116. (setq buffer-read-only t)))
  3117. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3118. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3119. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3120. not every single day in the range. If FORCE-TODAY is non-nil, make
  3121. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3122. inactive time stamps (those in square brackets) are included.
  3123. When EMPTY is non-nil, also include days without any entries."
  3124. (let ((re (concat
  3125. (if pre-re pre-re "")
  3126. (if inactive org-ts-regexp-both org-ts-regexp)))
  3127. dates dates1 date day day1 day2 ts1 ts2)
  3128. (if force-today
  3129. (setq dates (list (org-today))))
  3130. (save-excursion
  3131. (goto-char beg)
  3132. (while (re-search-forward re end t)
  3133. (setq day (time-to-days (org-time-string-to-time
  3134. (substring (match-string 1) 0 10))))
  3135. (or (memq day dates) (push day dates)))
  3136. (unless no-ranges
  3137. (goto-char beg)
  3138. (while (re-search-forward org-tr-regexp end t)
  3139. (setq ts1 (substring (match-string 1) 0 10)
  3140. ts2 (substring (match-string 2) 0 10)
  3141. day1 (time-to-days (org-time-string-to-time ts1))
  3142. day2 (time-to-days (org-time-string-to-time ts2)))
  3143. (while (< (setq day1 (1+ day1)) day2)
  3144. (or (memq day1 dates) (push day1 dates)))))
  3145. (setq dates (sort dates '<))
  3146. (when empty
  3147. (while (setq day (pop dates))
  3148. (setq day2 (car dates))
  3149. (push day dates1)
  3150. (when (and day2 empty)
  3151. (if (or (eq empty t)
  3152. (and (numberp empty) (<= (- day2 day) empty)))
  3153. (while (< (setq day (1+ day)) day2)
  3154. (push (list day) dates1))
  3155. (push (cons :omitted (- day2 day)) dates1))))
  3156. (setq dates (nreverse dates1)))
  3157. dates)))
  3158. ;;; Agenda Daily/Weekly
  3159. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3160. "Start day for the agenda view.
  3161. Custom commands can set this variable in the options section.")
  3162. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3163. (defvar org-agenda-current-span nil
  3164. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3165. (defvar org-include-all-loc nil) ; local variable
  3166. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3167. "List of types searched for when creating the daily/weekly agenda.
  3168. This variable is a list of symbols that controls the types of
  3169. items that appear in the daily/weekly agenda. Allowed symbols in this
  3170. list are are
  3171. :timestamp List items containing a date stamp or date range matching
  3172. the selected date. This includes sexp entries in
  3173. angular brackets.
  3174. :sexp List entries resulting from plain diary-like sexps.
  3175. :deadline List deadline due on that date. When the date is today,
  3176. also list any deadlines past due, or due within
  3177. `org-deadline-warning-days'. `:deadline' must appear before
  3178. `:scheduled' if the setting of
  3179. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3180. any effect.
  3181. :scheduled List all items which are scheduled for the given date.
  3182. The diary for *today* also contains items which were
  3183. scheduled earlier and are not yet marked DONE.
  3184. By default, all four types are turned on.
  3185. Never set this variable globally using `setq', because then it
  3186. will apply to all future agenda commands. Instead, bind it with
  3187. `let' to scope it dynamically into the the agenda-constructing
  3188. command. A good way to set it is through options in
  3189. `org-agenda-custom-commands'. For a more flexible (though
  3190. somewhat less efficient) way of determining what is included in
  3191. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3192. ;;;###autoload
  3193. (defun org-agenda-list (&optional include-all start-day span)
  3194. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3195. The view will be for the current day or week, but from the overview buffer
  3196. you will be able to go to other days/weeks.
  3197. With a numeric prefix argument in an interactive call, the agenda will
  3198. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3199. the number of days. SPAN defaults to `org-agenda-span'.
  3200. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3201. given in `org-agenda-start-on-weekday'."
  3202. (interactive "P")
  3203. (if (and (integerp include-all) (> include-all 0))
  3204. (setq span include-all include-all nil))
  3205. (setq start-day (or start-day org-agenda-start-day))
  3206. (if org-agenda-overriding-arguments
  3207. (setq include-all (car org-agenda-overriding-arguments)
  3208. start-day (nth 1 org-agenda-overriding-arguments)
  3209. span (nth 2 org-agenda-overriding-arguments)))
  3210. (if (stringp start-day)
  3211. ;; Convert to an absolute day number
  3212. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3213. (setq org-agenda-last-arguments (list include-all start-day span))
  3214. (org-compile-prefix-format 'agenda)
  3215. (org-set-sorting-strategy 'agenda)
  3216. (let* ((span (org-agenda-ndays-to-span
  3217. (or span org-agenda-ndays org-agenda-span)))
  3218. (today (org-today))
  3219. (sd (or start-day today))
  3220. (ndays (org-agenda-span-to-ndays span sd))
  3221. (org-agenda-start-on-weekday
  3222. (if (eq ndays 7)
  3223. org-agenda-start-on-weekday))
  3224. (thefiles (org-agenda-files nil 'ifmode))
  3225. (files thefiles)
  3226. (start (if (or (null org-agenda-start-on-weekday)
  3227. (< ndays 7))
  3228. sd
  3229. (let* ((nt (calendar-day-of-week
  3230. (calendar-gregorian-from-absolute sd)))
  3231. (n1 org-agenda-start-on-weekday)
  3232. (d (- nt n1)))
  3233. (- sd (+ (if (< d 0) 7 0) d)))))
  3234. (day-numbers (list start))
  3235. (day-cnt 0)
  3236. (inhibit-redisplay (not debug-on-error))
  3237. s e rtn rtnall file date d start-pos end-pos todayp
  3238. clocktable-start clocktable-end filter)
  3239. (setq org-agenda-redo-command
  3240. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3241. (dotimes (n (1- ndays))
  3242. (push (1+ (car day-numbers)) day-numbers))
  3243. (setq day-numbers (nreverse day-numbers))
  3244. (setq clocktable-start (car day-numbers)
  3245. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3246. (org-prepare-agenda "Day/Week")
  3247. (org-set-local 'org-starting-day (car day-numbers))
  3248. (org-set-local 'org-include-all-loc include-all)
  3249. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3250. (unless org-agenda-compact-blocks
  3251. (let* ((d1 (car day-numbers))
  3252. (d2 (org-last day-numbers))
  3253. (w1 (org-days-to-iso-week d1))
  3254. (w2 (org-days-to-iso-week d2)))
  3255. (setq s (point))
  3256. (if org-agenda-overriding-header
  3257. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3258. nil 'face 'org-agenda-structure) "\n")
  3259. (insert (org-agenda-span-name span)
  3260. "-agenda"
  3261. (if (< (- d2 d1) 350)
  3262. (if (= w1 w2)
  3263. (format " (W%02d)" w1)
  3264. (format " (W%02d-W%02d)" w1 w2))
  3265. "")
  3266. ":\n")))
  3267. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3268. 'org-date-line t))
  3269. (org-agenda-mark-header-line s))
  3270. (while (setq d (pop day-numbers))
  3271. (setq date (calendar-gregorian-from-absolute d)
  3272. s (point))
  3273. (if (or (setq todayp (= d today))
  3274. (and (not start-pos) (= d sd)))
  3275. (setq start-pos (point))
  3276. (if (and start-pos (not end-pos))
  3277. (setq end-pos (point))))
  3278. (setq files thefiles
  3279. rtnall nil)
  3280. (while (setq file (pop files))
  3281. (catch 'nextfile
  3282. (org-check-agenda-file file)
  3283. (let ((org-agenda-entry-types org-agenda-entry-types))
  3284. (unless org-agenda-include-deadlines
  3285. (setq org-agenda-entry-types
  3286. (delq :deadline org-agenda-entry-types)))
  3287. (cond
  3288. ((memq org-agenda-show-log '(only clockcheck))
  3289. (setq rtn (org-agenda-get-day-entries
  3290. file date :closed)))
  3291. (org-agenda-show-log
  3292. (setq rtn (apply 'org-agenda-get-day-entries
  3293. file date
  3294. (append '(:closed) org-agenda-entry-types))))
  3295. (t
  3296. (setq rtn (apply 'org-agenda-get-day-entries
  3297. file date
  3298. org-agenda-entry-types)))))
  3299. (setq rtnall (append rtnall rtn))))
  3300. (if org-agenda-include-diary
  3301. (let ((org-agenda-search-headline-for-time t))
  3302. (require 'diary-lib)
  3303. (setq rtn (org-get-entries-from-diary date))
  3304. (setq rtnall (append rtnall rtn))))
  3305. (if (or rtnall org-agenda-show-all-dates)
  3306. (progn
  3307. (setq day-cnt (1+ day-cnt))
  3308. (insert
  3309. (if (stringp org-agenda-format-date)
  3310. (format-time-string org-agenda-format-date
  3311. (org-time-from-absolute date))
  3312. (funcall org-agenda-format-date date))
  3313. "\n")
  3314. (put-text-property s (1- (point)) 'face
  3315. (org-agenda-get-day-face date))
  3316. (put-text-property s (1- (point)) 'org-date-line t)
  3317. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3318. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3319. (when todayp
  3320. (put-text-property s (1- (point)) 'org-today t))
  3321. (if rtnall (insert
  3322. (org-finalize-agenda-entries
  3323. (org-agenda-add-time-grid-maybe
  3324. rtnall ndays todayp))
  3325. "\n"))
  3326. (put-text-property s (1- (point)) 'day d)
  3327. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3328. (when (and org-agenda-clockreport-mode clocktable-start)
  3329. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3330. ;; the above line is to ensure the restricted range!
  3331. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3332. tbl)
  3333. (setq p (org-plist-delete p :block))
  3334. (setq p (plist-put p :tstart clocktable-start))
  3335. (setq p (plist-put p :tend clocktable-end))
  3336. (setq p (plist-put p :scope 'agenda))
  3337. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3338. (setq filter (or org-agenda-filter-while-redo
  3339. (get 'org-agenda-filter :preset-filter))))
  3340. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3341. (if (string-match "[<>=]" x)
  3342. ""
  3343. x))
  3344. filter ""))))
  3345. (setq tbl (apply 'org-get-clocktable p))
  3346. (insert tbl)))
  3347. (goto-char (point-min))
  3348. (or org-agenda-multi (org-fit-agenda-window))
  3349. (unless (and (pos-visible-in-window-p (point-min))
  3350. (pos-visible-in-window-p (point-max)))
  3351. (goto-char (1- (point-max)))
  3352. (recenter -1)
  3353. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3354. (progn
  3355. (goto-char (or start-pos 1))
  3356. (recenter 1))))
  3357. (goto-char (or start-pos 1))
  3358. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3359. (if (eq org-agenda-show-log 'clockcheck)
  3360. (org-agenda-show-clocking-issues))
  3361. (org-finalize-agenda)
  3362. (setq buffer-read-only t)
  3363. (message "")))
  3364. (defun org-agenda-ndays-to-span (n)
  3365. "Return a span symbol for a span of N days, or N if none matches."
  3366. (cond ((symbolp n) n)
  3367. ((= n 1) 'day)
  3368. ((= n 7) 'week)
  3369. (t n)))
  3370. (defun org-agenda-span-to-ndays (span start-day)
  3371. "Return ndays from SPAN starting at START-DAY."
  3372. (cond ((numberp span) span)
  3373. ((eq span 'day) 1)
  3374. ((eq span 'week) 7)
  3375. ((eq span 'month)
  3376. (let ((date (calendar-gregorian-from-absolute start-day)))
  3377. (calendar-last-day-of-month (car date) (caddr date))))
  3378. ((eq span 'year)
  3379. (let ((date (calendar-gregorian-from-absolute start-day)))
  3380. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3381. (defun org-agenda-span-name (span)
  3382. "Return a SPAN name."
  3383. (if (null span)
  3384. ""
  3385. (if (symbolp span)
  3386. (capitalize (symbol-name span))
  3387. (format "%d days" span))))
  3388. ;;; Agenda word search
  3389. (defvar org-agenda-search-history nil)
  3390. (defvar org-todo-only nil)
  3391. (defvar org-search-syntax-table nil
  3392. "Special syntax table for org-mode search.
  3393. In this table, we have single quotes not as word constituents, to
  3394. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3395. (defun org-search-syntax-table ()
  3396. (unless org-search-syntax-table
  3397. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3398. (modify-syntax-entry ?' "." org-search-syntax-table)
  3399. (modify-syntax-entry ?` "." org-search-syntax-table))
  3400. org-search-syntax-table)
  3401. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3402. ;;;###autoload
  3403. (defun org-search-view (&optional todo-only string edit-at)
  3404. "Show all entries that contain a phrase or words or regular expressions.
  3405. With optional prefix argument TODO-ONLY, only consider entries that are
  3406. TODO entries. The argument STRING can be used to pass a default search
  3407. string into this function. If EDIT-AT is non-nil, it means that the
  3408. user should get a chance to edit this string, with cursor at position
  3409. EDIT-AT.
  3410. The search string can be viewed either as a phrase that should be found as
  3411. is, or it can be broken into a number of snippets, each of which must match
  3412. in a Boolean way to select an entry. The default depends on the variable
  3413. `org-agenda-search-view-always-boolean'.
  3414. Even if this is turned off (the default) you can always switch to
  3415. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3416. The default is a direct search of the whole phrase, where each space in
  3417. the search string can expand to an arbitrary amount of whitespace,
  3418. including newlines.
  3419. If using a Boolean search, the search string is split on whitespace and
  3420. each snippet is searched separately, with logical AND to select an entry.
  3421. Words prefixed with a minus must *not* occur in the entry. Words without
  3422. a prefix or prefixed with a plus must occur in the entry. Matching is
  3423. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3424. match whole words, not parts of a word) if
  3425. `org-agenda-search-view-force-full-words' is set (default is nil).
  3426. Boolean search snippets enclosed by curly braces are interpreted as
  3427. regular expressions that must or (when preceded with \"-\") must not
  3428. match in the entry. Snippets enclosed into double quotes will be taken
  3429. as a whole, to include whitespace.
  3430. - If the search string starts with an asterisk, search only in headlines.
  3431. - If (possibly after the leading star) the search string starts with an
  3432. exclamation mark, this also means to look at TODO entries only, an effect
  3433. that can also be achieved with a prefix argument.
  3434. - If (possibly after star and exclamation mark) the search string starts
  3435. with a colon, this will mean that the (non-regexp) snippets of the
  3436. Boolean search must match as full words.
  3437. This command searches the agenda files, and in addition the files listed
  3438. in `org-agenda-text-search-extra-files'."
  3439. (interactive "P")
  3440. (org-compile-prefix-format 'search)
  3441. (org-set-sorting-strategy 'search)
  3442. (org-prepare-agenda "SEARCH")
  3443. (let* ((props (list 'face nil
  3444. 'done-face 'org-agenda-done
  3445. 'org-not-done-regexp org-not-done-regexp
  3446. 'org-todo-regexp org-todo-regexp
  3447. 'org-complex-heading-regexp org-complex-heading-regexp
  3448. 'mouse-face 'highlight
  3449. 'help-echo (format "mouse-2 or RET jump to location")))
  3450. (full-words org-agenda-search-view-force-full-words)
  3451. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3452. regexp rtn rtnall files file pos
  3453. marker category tags c neg re boolean
  3454. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3455. (unless (and (not edit-at)
  3456. (stringp string)
  3457. (string-match "\\S-" string))
  3458. (setq string (read-string
  3459. (if org-agenda-search-view-always-boolean
  3460. "[+-]Word/{Regexp} ...: "
  3461. "Phrase, or [+-]Word/{Regexp} ...: ")
  3462. (cond
  3463. ((integerp edit-at) (cons string edit-at))
  3464. (edit-at string))
  3465. 'org-agenda-search-history)))
  3466. (org-set-local 'org-todo-only todo-only)
  3467. (setq org-agenda-redo-command
  3468. (list 'org-search-view (if todo-only t nil) string
  3469. '(if current-prefix-arg 1 nil)))
  3470. (setq org-agenda-query-string string)
  3471. (if (equal (string-to-char string) ?*)
  3472. (setq hdl-only t
  3473. words (substring string 1))
  3474. (setq words string))
  3475. (when (equal (string-to-char words) ?!)
  3476. (setq todo-only t
  3477. words (substring words 1)))
  3478. (when (equal (string-to-char words) ?:)
  3479. (setq full-words t
  3480. words (substring words 1)))
  3481. (if (or org-agenda-search-view-always-boolean
  3482. (member (string-to-char words) '(?- ?+ ?\{)))
  3483. (setq boolean t))
  3484. (setq words (org-split-string words))
  3485. (let (www w)
  3486. (while (setq w (pop words))
  3487. (while (and (string-match "\\\\\\'" w) words)
  3488. (setq w (concat (substring w 0 -1) " " (pop words))))
  3489. (push w www))
  3490. (setq words (nreverse www) www nil)
  3491. (while (setq w (pop words))
  3492. (when (and (string-match "\\`[-+]?{" w)
  3493. (not (string-match "}\\'" w)))
  3494. (while (and words (not (string-match "}\\'" (car words))))
  3495. (setq w (concat w " " (pop words))))
  3496. (setq w (concat w " " (pop words))))
  3497. (push w www))
  3498. (setq words (nreverse www)))
  3499. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3500. (when boolean
  3501. (let (wds w)
  3502. (while (setq w (pop words))
  3503. (if (or (equal (substring w 0 1) "\"")
  3504. (and (> (length w) 1)
  3505. (member (substring w 0 1) '("+" "-"))
  3506. (equal (substring w 1 2) "\"")))
  3507. (while (and words (not (equal (substring w -1) "\"")))
  3508. (setq w (concat w " " (pop words)))))
  3509. (and (string-match "\\`\\([-+]?\\)\"" w)
  3510. (setq w (replace-match "\\1" nil nil w)))
  3511. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3512. (push w wds))
  3513. (setq words (nreverse wds))))
  3514. (if boolean
  3515. (mapc (lambda (w)
  3516. (setq c (string-to-char w))
  3517. (if (equal c ?-)
  3518. (setq neg t w (substring w 1))
  3519. (if (equal c ?+)
  3520. (setq neg nil w (substring w 1))
  3521. (setq neg nil)))
  3522. (if (string-match "\\`{.*}\\'" w)
  3523. (setq re (substring w 1 -1))
  3524. (if full-words
  3525. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3526. (setq re (regexp-quote (downcase w)))))
  3527. (if neg (push re regexps-) (push re regexps+)))
  3528. words)
  3529. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3530. regexps+))
  3531. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3532. (if (not regexps+)
  3533. (setq regexp (concat "^" org-outline-regexp))
  3534. (setq regexp (pop regexps+))
  3535. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3536. regexp))))
  3537. (setq files (org-agenda-files nil 'ifmode))
  3538. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3539. (pop org-agenda-text-search-extra-files)
  3540. (setq files (org-add-archive-files files)))
  3541. (setq files (append files org-agenda-text-search-extra-files)
  3542. rtnall nil)
  3543. (while (setq file (pop files))
  3544. (setq ee nil)
  3545. (catch 'nextfile
  3546. (org-check-agenda-file file)
  3547. (setq buffer (if (file-exists-p file)
  3548. (org-get-agenda-file-buffer file)
  3549. (error "No such file %s" file)))
  3550. (if (not buffer)
  3551. ;; If file does not exist, make sure an error message is sent
  3552. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3553. file))))
  3554. (with-current-buffer buffer
  3555. (with-syntax-table (org-search-syntax-table)
  3556. (unless (org-mode-p)
  3557. (error "Agenda file %s is not in `org-mode'" file))
  3558. (let ((case-fold-search t))
  3559. (save-excursion
  3560. (save-restriction
  3561. (if org-agenda-restrict
  3562. (narrow-to-region org-agenda-restrict-begin
  3563. org-agenda-restrict-end)
  3564. (widen))
  3565. (goto-char (point-min))
  3566. (unless (or (org-on-heading-p)
  3567. (outline-next-heading))
  3568. (throw 'nextfile t))
  3569. (goto-char (max (point-min) (1- (point))))
  3570. (while (re-search-forward regexp nil t)
  3571. (org-back-to-heading t)
  3572. (skip-chars-forward "* ")
  3573. (setq beg (point-at-bol)
  3574. beg1 (point)
  3575. end (progn (outline-next-heading) (point)))
  3576. (catch :skip
  3577. (goto-char beg)
  3578. (org-agenda-skip)
  3579. (setq str (buffer-substring-no-properties
  3580. (point-at-bol)
  3581. (if hdl-only (point-at-eol) end)))
  3582. (mapc (lambda (wr) (when (string-match wr str)
  3583. (goto-char (1- end))
  3584. (throw :skip t)))
  3585. regexps-)
  3586. (mapc (lambda (wr) (unless (string-match wr str)
  3587. (goto-char (1- end))
  3588. (throw :skip t)))
  3589. (if todo-only
  3590. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3591. regexps+)
  3592. regexps+))
  3593. (goto-char beg)
  3594. (setq marker (org-agenda-new-marker (point))
  3595. category (org-get-category)
  3596. tags (org-get-tags-at (point))
  3597. txt (org-format-agenda-item
  3598. ""
  3599. (buffer-substring-no-properties
  3600. beg1 (point-at-eol))
  3601. category tags))
  3602. (org-add-props txt props
  3603. 'org-marker marker 'org-hd-marker marker
  3604. 'org-todo-regexp org-todo-regexp
  3605. 'org-complex-heading-regexp org-complex-heading-regexp
  3606. 'priority 1000 'org-category category
  3607. 'type "search")
  3608. (push txt ee)
  3609. (goto-char (1- end))))))))))
  3610. (setq rtn (nreverse ee))
  3611. (setq rtnall (append rtnall rtn)))
  3612. (if org-agenda-overriding-header
  3613. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3614. nil 'face 'org-agenda-structure) "\n")
  3615. (insert "Search words: ")
  3616. (add-text-properties (point-min) (1- (point))
  3617. (list 'face 'org-agenda-structure))
  3618. (setq pos (point))
  3619. (insert string "\n")
  3620. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3621. (setq pos (point))
  3622. (unless org-agenda-multi
  3623. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3624. (add-text-properties pos (1- (point))
  3625. (list 'face 'org-agenda-structure))))
  3626. (org-agenda-mark-header-line (point-min))
  3627. (when rtnall
  3628. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3629. (goto-char (point-min))
  3630. (or org-agenda-multi (org-fit-agenda-window))
  3631. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3632. (org-finalize-agenda)
  3633. (setq buffer-read-only t)))
  3634. ;;; Agenda TODO list
  3635. (defvar org-select-this-todo-keyword nil)
  3636. (defvar org-last-arg nil)
  3637. ;;;###autoload
  3638. (defun org-todo-list (arg)
  3639. "Show all (not done) TODO entries from all agenda file in a single list.
  3640. The prefix arg can be used to select a specific TODO keyword and limit
  3641. the list to these. When using \\[universal-argument], you will be prompted
  3642. for a keyword. A numeric prefix directly selects the Nth keyword in
  3643. `org-todo-keywords-1'."
  3644. (interactive "P")
  3645. (org-compile-prefix-format 'todo)
  3646. (org-set-sorting-strategy 'todo)
  3647. (org-prepare-agenda "TODO")
  3648. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3649. (let* ((today (org-today))
  3650. (date (calendar-gregorian-from-absolute today))
  3651. (kwds org-todo-keywords-for-agenda)
  3652. (completion-ignore-case t)
  3653. (org-select-this-todo-keyword
  3654. (if (stringp arg) arg
  3655. (and arg (integerp arg) (> arg 0)
  3656. (nth (1- arg) kwds))))
  3657. rtn rtnall files file pos)
  3658. (when (equal arg '(4))
  3659. (setq org-select-this-todo-keyword
  3660. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3661. (mapcar 'list kwds) nil nil)))
  3662. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3663. (org-set-local 'org-last-arg arg)
  3664. (setq org-agenda-redo-command
  3665. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3666. (setq files (org-agenda-files nil 'ifmode)
  3667. rtnall nil)
  3668. (while (setq file (pop files))
  3669. (catch 'nextfile
  3670. (org-check-agenda-file file)
  3671. (setq rtn (org-agenda-get-day-entries file date :todo))
  3672. (setq rtnall (append rtnall rtn))))
  3673. (if org-agenda-overriding-header
  3674. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3675. nil 'face 'org-agenda-structure) "\n")
  3676. (insert "Global list of TODO items of type: ")
  3677. (add-text-properties (point-min) (1- (point))
  3678. (list 'face 'org-agenda-structure
  3679. 'short-heading
  3680. (concat "ToDo: "
  3681. (or org-select-this-todo-keyword "ALL"))))
  3682. (org-agenda-mark-header-line (point-min))
  3683. (setq pos (point))
  3684. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3685. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3686. (setq pos (point))
  3687. (unless org-agenda-multi
  3688. (insert "Available with `N r': (0)ALL")
  3689. (let ((n 0) s)
  3690. (mapc (lambda (x)
  3691. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3692. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3693. (insert "\n "))
  3694. (insert " " s))
  3695. kwds))
  3696. (insert "\n"))
  3697. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3698. (org-agenda-mark-header-line (point-min))
  3699. (when rtnall
  3700. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3701. (goto-char (point-min))
  3702. (or org-agenda-multi (org-fit-agenda-window))
  3703. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3704. (org-finalize-agenda)
  3705. (setq buffer-read-only t)))
  3706. ;;; Agenda tags match
  3707. ;;;###autoload
  3708. (defun org-tags-view (&optional todo-only match)
  3709. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3710. The prefix arg TODO-ONLY limits the search to TODO entries."
  3711. (interactive "P")
  3712. (org-compile-prefix-format 'tags)
  3713. (org-set-sorting-strategy 'tags)
  3714. (let* ((org-tags-match-list-sublevels
  3715. org-tags-match-list-sublevels)
  3716. (completion-ignore-case t)
  3717. rtn rtnall files file pos matcher
  3718. buffer)
  3719. (when (and (stringp match) (not (string-match "\\S-" match)))
  3720. (setq match nil))
  3721. (setq matcher (org-make-tags-matcher match)
  3722. match (car matcher) matcher (cdr matcher))
  3723. (org-prepare-agenda (concat "TAGS " match))
  3724. (setq org-agenda-query-string match)
  3725. (setq org-agenda-redo-command
  3726. (list 'org-tags-view (list 'quote todo-only)
  3727. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3728. (setq files (org-agenda-files nil 'ifmode)
  3729. rtnall nil)
  3730. (while (setq file (pop files))
  3731. (catch 'nextfile
  3732. (org-check-agenda-file file)
  3733. (setq buffer (if (file-exists-p file)
  3734. (org-get-agenda-file-buffer file)
  3735. (error "No such file %s" file)))
  3736. (if (not buffer)
  3737. ;; If file does not exist, error message to agenda
  3738. (setq rtn (list
  3739. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3740. rtnall (append rtnall rtn))
  3741. (with-current-buffer buffer
  3742. (unless (org-mode-p)
  3743. (error "Agenda file %s is not in `org-mode'" file))
  3744. (save-excursion
  3745. (save-restriction
  3746. (if org-agenda-restrict
  3747. (narrow-to-region org-agenda-restrict-begin
  3748. org-agenda-restrict-end)
  3749. (widen))
  3750. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3751. (setq rtnall (append rtnall rtn))))))))
  3752. (if org-agenda-overriding-header
  3753. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3754. nil 'face 'org-agenda-structure) "\n")
  3755. (insert "Headlines with TAGS match: ")
  3756. (add-text-properties (point-min) (1- (point))
  3757. (list 'face 'org-agenda-structure
  3758. 'short-heading
  3759. (concat "Match: " match)))
  3760. (setq pos (point))
  3761. (insert match "\n")
  3762. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3763. (setq pos (point))
  3764. (unless org-agenda-multi
  3765. (insert "Press `C-u r' to search again with new search string\n"))
  3766. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3767. (org-agenda-mark-header-line (point-min))
  3768. (when rtnall
  3769. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3770. (goto-char (point-min))
  3771. (or org-agenda-multi (org-fit-agenda-window))
  3772. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3773. (org-finalize-agenda)
  3774. (setq buffer-read-only t)))
  3775. ;;; Agenda Finding stuck projects
  3776. (defvar org-agenda-skip-regexp nil
  3777. "Regular expression used in skipping subtrees for the agenda.
  3778. This is basically a temporary global variable that can be set and then
  3779. used by user-defined selections using `org-agenda-skip-function'.")
  3780. (defvar org-agenda-overriding-header nil
  3781. "When this is set during todo and tags searches, will replace header.
  3782. This variable should not be set directly, but custom commands can bind it
  3783. in the options section.")
  3784. (defun org-agenda-skip-entry-when-regexp-matches ()
  3785. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3786. If yes, it returns the end position of this entry, causing agenda commands
  3787. to skip the entry but continuing the search in the subtree. This is a
  3788. function that can be put into `org-agenda-skip-function' for the duration
  3789. of a command."
  3790. (let ((end (save-excursion (org-end-of-subtree t)))
  3791. skip)
  3792. (save-excursion
  3793. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3794. (and skip end)))
  3795. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3796. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3797. If yes, it returns the end position of this tree, causing agenda commands
  3798. to skip this subtree. This is a function that can be put into
  3799. `org-agenda-skip-function' for the duration of a command."
  3800. (let ((end (save-excursion (org-end-of-subtree t)))
  3801. skip)
  3802. (save-excursion
  3803. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3804. (and skip end)))
  3805. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3806. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3807. If yes, it returns the end position of the current entry (NOT the tree),
  3808. causing agenda commands to skip the entry but continuing the search in
  3809. the subtree. This is a function that can be put into
  3810. `org-agenda-skip-function' for the duration of a command. An important
  3811. use of this function is for the stuck project list."
  3812. (let ((end (save-excursion (org-end-of-subtree t)))
  3813. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3814. skip)
  3815. (save-excursion
  3816. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3817. (and skip entry-end)))
  3818. (defun org-agenda-skip-entry-if (&rest conditions)
  3819. "Skip entry if any of CONDITIONS is true.
  3820. See `org-agenda-skip-if' for details."
  3821. (org-agenda-skip-if nil conditions))
  3822. (defun org-agenda-skip-subtree-if (&rest conditions)
  3823. "Skip entry if any of CONDITIONS is true.
  3824. See `org-agenda-skip-if' for details."
  3825. (org-agenda-skip-if t conditions))
  3826. (defun org-agenda-skip-if (subtree conditions)
  3827. "Checks current entity for CONDITIONS.
  3828. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3829. the entry, i.e. the text before the next heading is checked.
  3830. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3831. from different tests. Valid conditions are:
  3832. scheduled Check if there is a scheduled cookie
  3833. notscheduled Check if there is no scheduled cookie
  3834. deadline Check if there is a deadline
  3835. notdeadline Check if there is no deadline
  3836. timestamp Check if there is a timestamp (also deadline or scheduled)
  3837. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3838. regexp Check if regexp matches
  3839. notregexp Check if regexp does not match.
  3840. todo Check if TODO keyword matches
  3841. nottodo Check if TODO keyword does not match
  3842. The regexp is taken from the conditions list, it must come right after
  3843. the `regexp' or `notregexp' element.
  3844. `todo' and `nottodo' accept as an argument a list of todo
  3845. keywords, which may include \"*\" to match any todo keyword.
  3846. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3847. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3848. Instead of a list a keyword class may be given
  3849. (org-agenda-skip-entry-if 'nottodo 'done)
  3850. would skip entries that haven't been marked with any of \"DONE\"
  3851. keywords. Possible classes are: `todo', `done', `any'.
  3852. If any of these conditions is met, this function returns the end point of
  3853. the entity, causing the search to continue from there. This is a function
  3854. that can be put into `org-agenda-skip-function' for the duration of a command."
  3855. (let (beg end m)
  3856. (org-back-to-heading t)
  3857. (setq beg (point)
  3858. end (if subtree
  3859. (progn (org-end-of-subtree t) (point))
  3860. (progn (outline-next-heading) (1- (point)))))
  3861. (goto-char beg)
  3862. (and
  3863. (or
  3864. (and (memq 'scheduled conditions)
  3865. (re-search-forward org-scheduled-time-regexp end t))
  3866. (and (memq 'notscheduled conditions)
  3867. (not (re-search-forward org-scheduled-time-regexp end t)))
  3868. (and (memq 'deadline conditions)
  3869. (re-search-forward org-deadline-time-regexp end t))
  3870. (and (memq 'notdeadline conditions)
  3871. (not (re-search-forward org-deadline-time-regexp end t)))
  3872. (and (memq 'timestamp conditions)
  3873. (re-search-forward org-ts-regexp end t))
  3874. (and (memq 'nottimestamp conditions)
  3875. (not (re-search-forward org-ts-regexp end t)))
  3876. (and (setq m (memq 'regexp conditions))
  3877. (stringp (nth 1 m))
  3878. (re-search-forward (nth 1 m) end t))
  3879. (and (setq m (memq 'notregexp conditions))
  3880. (stringp (nth 1 m))
  3881. (not (re-search-forward (nth 1 m) end t)))
  3882. (and (or
  3883. (setq m (memq 'todo conditions))
  3884. (setq m (memq 'nottodo conditions)))
  3885. (org-agenda-skip-if-todo m end)))
  3886. end)))
  3887. (defun org-agenda-skip-if-todo (args end)
  3888. "Helper function for `org-agenda-skip-if', do not use it directly.
  3889. ARGS is a list with first element either `todo' or `nottodo'.
  3890. The remainder is either a list of TODO keywords, or a state symbol
  3891. `todo' or `done' or `any'."
  3892. (let ((kw (car args))
  3893. (arg (cadr args))
  3894. todo-wds todo-re)
  3895. (setq todo-wds
  3896. (org-uniquify
  3897. (cond
  3898. ((listp arg) ;; list of keywords
  3899. (if (member "*" arg)
  3900. (mapcar 'substring-no-properties org-todo-keywords-1)
  3901. arg))
  3902. ((symbolp arg) ;; keyword class name
  3903. (cond
  3904. ((eq arg 'todo)
  3905. (org-delete-all org-done-keywords
  3906. (mapcar 'substring-no-properties
  3907. org-todo-keywords-1)))
  3908. ((eq arg 'done) org-done-keywords)
  3909. ((eq arg 'any)
  3910. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3911. (setq todo-re
  3912. (concat "^\\*+[ \t]+\\<\\("
  3913. (mapconcat 'identity todo-wds "\\|")
  3914. "\\)\\>"))
  3915. (if (eq kw 'todo)
  3916. (re-search-forward todo-re end t)
  3917. (not (re-search-forward todo-re end t)))))
  3918. ;;;###autoload
  3919. (defun org-agenda-list-stuck-projects (&rest ignore)
  3920. "Create agenda view for projects that are stuck.
  3921. Stuck projects are project that have no next actions. For the definitions
  3922. of what a project is and how to check if it stuck, customize the variable
  3923. `org-stuck-projects'."
  3924. (interactive)
  3925. (let* ((org-agenda-skip-function
  3926. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3927. ;; We could have used org-agenda-skip-if here.
  3928. (org-agenda-overriding-header
  3929. (or org-agenda-overriding-header "List of stuck projects: "))
  3930. (matcher (nth 0 org-stuck-projects))
  3931. (todo (nth 1 org-stuck-projects))
  3932. (todo-wds (if (member "*" todo)
  3933. (progn
  3934. (org-prepare-agenda-buffers (org-agenda-files
  3935. nil 'ifmode))
  3936. (org-delete-all
  3937. org-done-keywords-for-agenda
  3938. (copy-sequence org-todo-keywords-for-agenda)))
  3939. todo))
  3940. (todo-re (concat "^\\*+[ \t]+\\("
  3941. (mapconcat 'identity todo-wds "\\|")
  3942. "\\)\\>"))
  3943. (tags (nth 2 org-stuck-projects))
  3944. (tags-re (if (member "*" tags)
  3945. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3946. (if tags
  3947. (concat "^\\*+ .*:\\("
  3948. (mapconcat 'identity tags "\\|")
  3949. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3950. (gen-re (nth 3 org-stuck-projects))
  3951. (re-list
  3952. (delq nil
  3953. (list
  3954. (if todo todo-re)
  3955. (if tags tags-re)
  3956. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3957. gen-re)))))
  3958. (setq org-agenda-skip-regexp
  3959. (if re-list
  3960. (mapconcat 'identity re-list "\\|")
  3961. (error "No information how to identify unstuck projects")))
  3962. (org-tags-view nil matcher)
  3963. (with-current-buffer org-agenda-buffer-name
  3964. (setq org-agenda-redo-command
  3965. '(org-agenda-list-stuck-projects
  3966. (or current-prefix-arg org-last-arg))))))
  3967. ;;; Diary integration
  3968. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3969. (defvar list-diary-entries-hook)
  3970. (defvar diary-time-regexp)
  3971. (defun org-get-entries-from-diary (date)
  3972. "Get the (Emacs Calendar) diary entries for DATE."
  3973. (require 'diary-lib)
  3974. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3975. (diary-display-hook '(fancy-diary-display))
  3976. (diary-display-function 'fancy-diary-display)
  3977. (pop-up-frames nil)
  3978. (list-diary-entries-hook
  3979. (cons 'org-diary-default-entry list-diary-entries-hook))
  3980. (diary-file-name-prefix-function nil) ; turn this feature off
  3981. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3982. entries
  3983. (org-disable-agenda-to-diary t))
  3984. (save-excursion
  3985. (save-window-excursion
  3986. (funcall (if (fboundp 'diary-list-entries)
  3987. 'diary-list-entries 'list-diary-entries)
  3988. date 1)))
  3989. (if (not (get-buffer diary-fancy-buffer))
  3990. (setq entries nil)
  3991. (with-current-buffer diary-fancy-buffer
  3992. (setq buffer-read-only nil)
  3993. (if (zerop (buffer-size))
  3994. ;; No entries
  3995. (setq entries nil)
  3996. ;; Omit the date and other unnecessary stuff
  3997. (org-agenda-cleanup-fancy-diary)
  3998. ;; Add prefix to each line and extend the text properties
  3999. (if (zerop (buffer-size))
  4000. (setq entries nil)
  4001. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4002. (setq entries
  4003. (with-temp-buffer
  4004. (insert entries) (goto-char (point-min))
  4005. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4006. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4007. (replace-match (concat "; " (match-string 1)))))
  4008. (buffer-string)))))
  4009. (set-buffer-modified-p nil)
  4010. (kill-buffer diary-fancy-buffer)))
  4011. (when entries
  4012. (setq entries (org-split-string entries "\n"))
  4013. (setq entries
  4014. (mapcar
  4015. (lambda (x)
  4016. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4017. ;; Extend the text properties to the beginning of the line
  4018. (org-add-props x (text-properties-at (1- (length x)) x)
  4019. 'type "diary" 'date date 'face 'org-agenda-diary))
  4020. entries)))))
  4021. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4022. "Hook run when the fancy diary buffer is cleaned up.")
  4023. (defun org-agenda-cleanup-fancy-diary ()
  4024. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4025. This gets rid of the date, the underline under the date, and
  4026. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4027. date. It also removes lines that contain only whitespace."
  4028. (goto-char (point-min))
  4029. (if (looking-at ".*?:[ \t]*")
  4030. (progn
  4031. (replace-match "")
  4032. (re-search-forward "\n=+$" nil t)
  4033. (replace-match "")
  4034. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4035. (re-search-forward "\n=+$" nil t)
  4036. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4037. (goto-char (point-min))
  4038. (while (re-search-forward "^ +\n" nil t)
  4039. (replace-match ""))
  4040. (goto-char (point-min))
  4041. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4042. (replace-match ""))
  4043. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4044. ;; Make sure entries from the diary have the right text properties.
  4045. (eval-after-load "diary-lib"
  4046. '(if (boundp 'diary-modify-entry-list-string-function)
  4047. ;; We can rely on the hook, nothing to do
  4048. nil
  4049. ;; Hook not available, must use advice to make this work
  4050. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4051. "Make the position visible."
  4052. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4053. (stringp string)
  4054. buffer-file-name)
  4055. (setq string (org-modify-diary-entry-string string))))))
  4056. (defun org-modify-diary-entry-string (string)
  4057. "Add text properties to string, allowing org-mode to act on it."
  4058. (org-add-props string nil
  4059. 'mouse-face 'highlight
  4060. 'help-echo (if buffer-file-name
  4061. (format "mouse-2 or RET jump to diary file %s"
  4062. (abbreviate-file-name buffer-file-name))
  4063. "")
  4064. 'org-agenda-diary-link t
  4065. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4066. (defun org-diary-default-entry ()
  4067. "Add a dummy entry to the diary.
  4068. Needed to avoid empty dates which mess up holiday display."
  4069. ;; Catch the error if dealing with the new add-to-diary-alist
  4070. (when org-disable-agenda-to-diary
  4071. (condition-case nil
  4072. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4073. (error
  4074. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4075. (defun org-add-to-diary-list (&rest args)
  4076. (if (fboundp 'diary-add-to-list)
  4077. (apply 'diary-add-to-list args)
  4078. (apply 'add-to-diary-list args)))
  4079. (defvar org-diary-last-run-time nil)
  4080. ;;;###autoload
  4081. (defun org-diary (&rest args)
  4082. "Return diary information from org-files.
  4083. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4084. It accesses org files and extracts information from those files to be
  4085. listed in the diary. The function accepts arguments specifying what
  4086. items should be listed. For a list of arguments allowed here, see the
  4087. variable `org-agenda-entry-types'.
  4088. The call in the diary file should look like this:
  4089. &%%(org-diary) ~/path/to/some/orgfile.org
  4090. Use a separate line for each org file to check. Or, if you omit the file name,
  4091. all files listed in `org-agenda-files' will be checked automatically:
  4092. &%%(org-diary)
  4093. If you don't give any arguments (as in the example above), the default
  4094. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4095. So the example above may also be written as
  4096. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4097. The function expects the lisp variables `entry' and `date' to be provided
  4098. by the caller, because this is how the calendar works. Don't use this
  4099. function from a program - use `org-agenda-get-day-entries' instead."
  4100. (when (> (- (org-float-time)
  4101. org-agenda-last-marker-time)
  4102. 5)
  4103. (org-agenda-reset-markers))
  4104. (org-compile-prefix-format 'agenda)
  4105. (org-set-sorting-strategy 'agenda)
  4106. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4107. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4108. (list entry)
  4109. (org-agenda-files t)))
  4110. (time (org-float-time))
  4111. file rtn results)
  4112. (when (or (not org-diary-last-run-time)
  4113. (> (- time
  4114. org-diary-last-run-time)
  4115. 3))
  4116. (org-prepare-agenda-buffers files))
  4117. (setq org-diary-last-run-time time)
  4118. ;; If this is called during org-agenda, don't return any entries to
  4119. ;; the calendar. Org Agenda will list these entries itself.
  4120. (if org-disable-agenda-to-diary (setq files nil))
  4121. (while (setq file (pop files))
  4122. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4123. (setq results (append results rtn)))
  4124. (if results
  4125. (concat (org-finalize-agenda-entries results) "\n"))))
  4126. ;;; Agenda entry finders
  4127. (defun org-agenda-get-day-entries (file date &rest args)
  4128. "Does the work for `org-diary' and `org-agenda'.
  4129. FILE is the path to a file to be checked for entries. DATE is date like
  4130. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4131. which kind of entries should be extracted. For details about these, see
  4132. the documentation of `org-diary'."
  4133. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4134. (let* ((org-startup-folded nil)
  4135. (org-startup-align-all-tables nil)
  4136. (buffer (if (file-exists-p file)
  4137. (org-get-agenda-file-buffer file)
  4138. (error "No such file %s" file)))
  4139. arg results rtn deadline-results)
  4140. (if (not buffer)
  4141. ;; If file does not exist, make sure an error message ends up in diary
  4142. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4143. (with-current-buffer buffer
  4144. (unless (org-mode-p)
  4145. (error "Agenda file %s is not in `org-mode'" file))
  4146. (let ((case-fold-search nil))
  4147. (save-excursion
  4148. (save-restriction
  4149. (if org-agenda-restrict
  4150. (narrow-to-region org-agenda-restrict-begin
  4151. org-agenda-restrict-end)
  4152. (widen))
  4153. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4154. (while (setq arg (pop args))
  4155. (cond
  4156. ((and (eq arg :todo)
  4157. (equal date (calendar-gregorian-from-absolute
  4158. (org-today))))
  4159. (setq rtn (org-agenda-get-todos))
  4160. (setq results (append results rtn)))
  4161. ((eq arg :timestamp)
  4162. (setq rtn (org-agenda-get-blocks))
  4163. (setq results (append results rtn))
  4164. (setq rtn (org-agenda-get-timestamps))
  4165. (setq results (append results rtn)))
  4166. ((eq arg :sexp)
  4167. (setq rtn (org-agenda-get-sexps))
  4168. (setq results (append results rtn)))
  4169. ((eq arg :scheduled)
  4170. (setq rtn (org-agenda-get-scheduled deadline-results))
  4171. (setq results (append results rtn)))
  4172. ((eq arg :closed)
  4173. (setq rtn (org-agenda-get-progress))
  4174. (setq results (append results rtn)))
  4175. ((eq arg :deadline)
  4176. (setq rtn (org-agenda-get-deadlines))
  4177. (setq deadline-results (copy-sequence rtn))
  4178. (setq results (append results rtn))))))))
  4179. results))))
  4180. (defun org-agenda-get-todos ()
  4181. "Return the TODO information for agenda display."
  4182. (let* ((props (list 'face nil
  4183. 'done-face 'org-agenda-done
  4184. 'org-not-done-regexp org-not-done-regexp
  4185. 'org-todo-regexp org-todo-regexp
  4186. 'org-complex-heading-regexp org-complex-heading-regexp
  4187. 'mouse-face 'highlight
  4188. 'help-echo
  4189. (format "mouse-2 or RET jump to org file %s"
  4190. (abbreviate-file-name buffer-file-name))))
  4191. (regexp (concat "^\\*+[ \t]+\\("
  4192. (if org-select-this-todo-keyword
  4193. (if (equal org-select-this-todo-keyword "*")
  4194. org-todo-regexp
  4195. (concat "\\<\\("
  4196. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4197. "\\)\\>"))
  4198. org-not-done-regexp)
  4199. "[^\n\r]*\\)"))
  4200. marker priority category tags todo-state
  4201. ee txt beg end)
  4202. (goto-char (point-min))
  4203. (while (re-search-forward regexp nil t)
  4204. (catch :skip
  4205. (save-match-data
  4206. (beginning-of-line)
  4207. (org-agenda-skip)
  4208. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4209. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4210. (goto-char (1+ beg))
  4211. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4212. (throw :skip nil)))
  4213. (goto-char (match-beginning 1))
  4214. (setq marker (org-agenda-new-marker (match-beginning 0))
  4215. category (org-get-category)
  4216. txt (match-string 1)
  4217. tags (org-get-tags-at (point))
  4218. txt (org-format-agenda-item "" txt category tags)
  4219. priority (1+ (org-get-priority txt))
  4220. todo-state (org-get-todo-state))
  4221. (org-add-props txt props
  4222. 'org-marker marker 'org-hd-marker marker
  4223. 'priority priority 'org-category category
  4224. 'type "todo" 'todo-state todo-state)
  4225. (push txt ee)
  4226. (if org-agenda-todo-list-sublevels
  4227. (goto-char (match-end 1))
  4228. (org-end-of-subtree 'invisible))))
  4229. (nreverse ee)))
  4230. (defun org-agenda-todo-custom-ignore-p (time n)
  4231. "Check whether timestamp is farther away then n number of days.
  4232. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4233. `org-agenda-todo-ignore-scheduled' or
  4234. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4235. (let ((days (org-days-to-time time)))
  4236. (if (>= n 0)
  4237. (>= days n)
  4238. (<= days n))))
  4239. ;;;###autoload
  4240. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4241. (&optional end)
  4242. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4243. (when (or org-agenda-todo-ignore-with-date
  4244. org-agenda-todo-ignore-scheduled
  4245. org-agenda-todo-ignore-deadlines
  4246. org-agenda-todo-ignore-timestamp)
  4247. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4248. (save-excursion
  4249. (or (and org-agenda-todo-ignore-with-date
  4250. (re-search-forward org-ts-regexp end t))
  4251. (and org-agenda-todo-ignore-scheduled
  4252. (re-search-forward org-scheduled-time-regexp end t)
  4253. (cond
  4254. ((eq org-agenda-todo-ignore-scheduled 'future)
  4255. (> (org-days-to-time (match-string 1)) 0))
  4256. ((eq org-agenda-todo-ignore-scheduled 'past)
  4257. (<= (org-days-to-time (match-string 1)) 0))
  4258. ((numberp org-agenda-todo-ignore-scheduled)
  4259. (org-agenda-todo-custom-ignore-p
  4260. (match-string 1) org-agenda-todo-ignore-scheduled))
  4261. (t)))
  4262. (and org-agenda-todo-ignore-deadlines
  4263. (re-search-forward org-deadline-time-regexp end t)
  4264. (cond
  4265. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4266. ((eq org-agenda-todo-ignore-deadlines 'far)
  4267. (not (org-deadline-close (match-string 1))))
  4268. ((eq org-agenda-todo-ignore-deadlines 'future)
  4269. (> (org-days-to-time (match-string 1)) 0))
  4270. ((eq org-agenda-todo-ignore-deadlines 'past)
  4271. (<= (org-days-to-time (match-string 1)) 0))
  4272. ((numberp org-agenda-todo-ignore-deadlines)
  4273. (org-agenda-todo-custom-ignore-p
  4274. (match-string 1) org-agenda-todo-ignore-deadlines))
  4275. (t (org-deadline-close (match-string 1)))))
  4276. (and org-agenda-todo-ignore-timestamp
  4277. (let ((buffer (current-buffer))
  4278. (regexp
  4279. (concat
  4280. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4281. (start (point)))
  4282. ;; Copy current buffer into a temporary one
  4283. (with-temp-buffer
  4284. (insert-buffer-substring buffer start end)
  4285. (goto-char (point-min))
  4286. ;; Delete SCHEDULED and DEADLINE items
  4287. (while (re-search-forward regexp end t)
  4288. (delete-region (match-beginning 0) (match-end 0)))
  4289. (goto-char (point-min))
  4290. ;; No search for timestamp left
  4291. (when (re-search-forward org-ts-regexp nil t)
  4292. (cond
  4293. ((eq org-agenda-todo-ignore-timestamp 'future)
  4294. (> (org-days-to-time (match-string 1)) 0))
  4295. ((eq org-agenda-todo-ignore-timestamp 'past)
  4296. (<= (org-days-to-time (match-string 1)) 0))
  4297. ((numberp org-agenda-todo-ignore-timestamp)
  4298. (org-agenda-todo-custom-ignore-p
  4299. (match-string 1) org-agenda-todo-ignore-timestamp))
  4300. (t))))))))))
  4301. (defconst org-agenda-no-heading-message
  4302. "No heading for this item in buffer or region.")
  4303. (defun org-agenda-get-timestamps ()
  4304. "Return the date stamp information for agenda display."
  4305. (let* ((props (list 'face nil
  4306. 'org-not-done-regexp org-not-done-regexp
  4307. 'org-todo-regexp org-todo-regexp
  4308. 'org-complex-heading-regexp org-complex-heading-regexp
  4309. 'mouse-face 'highlight
  4310. 'help-echo
  4311. (format "mouse-2 or RET jump to org file %s"
  4312. (abbreviate-file-name buffer-file-name))))
  4313. (d1 (calendar-absolute-from-gregorian date))
  4314. (remove-re
  4315. (concat
  4316. (regexp-quote
  4317. (format-time-string
  4318. "<%Y-%m-%d"
  4319. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4320. ".*?>"))
  4321. (regexp
  4322. (concat
  4323. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4324. (regexp-quote
  4325. (substring
  4326. (format-time-string
  4327. (car org-time-stamp-formats)
  4328. (apply 'encode-time ; DATE bound by calendar
  4329. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4330. 1 11))
  4331. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4332. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4333. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4334. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4335. todo-state end-of-match show-all)
  4336. (goto-char (point-min))
  4337. (while (setq end-of-match (re-search-forward regexp nil t))
  4338. (setq b0 (match-beginning 0)
  4339. b3 (match-beginning 3) e3 (match-end 3)
  4340. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4341. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4342. (member todo-state
  4343. org-agenda-repeating-timestamp-show-all)))
  4344. (catch :skip
  4345. (and (org-at-date-range-p) (throw :skip nil))
  4346. (org-agenda-skip)
  4347. (if (and (match-end 1)
  4348. (not (= d1 (org-time-string-to-absolute
  4349. (match-string 1) d1 nil show-all))))
  4350. (throw :skip nil))
  4351. (if (and e3
  4352. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4353. (throw :skip nil))
  4354. (setq tmp (buffer-substring (max (point-min)
  4355. (- b0 org-ds-keyword-length))
  4356. b0)
  4357. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4358. inactivep (= (char-after b0) ?\[)
  4359. deadlinep (string-match org-deadline-regexp tmp)
  4360. scheduledp (string-match org-scheduled-regexp tmp)
  4361. closedp (and org-agenda-include-inactive-timestamps
  4362. (string-match org-closed-string tmp))
  4363. clockp (and org-agenda-include-inactive-timestamps
  4364. (or (string-match org-clock-string tmp)
  4365. (string-match "]-+\\'" tmp)))
  4366. donep (member todo-state org-done-keywords))
  4367. (if (or scheduledp deadlinep closedp clockp
  4368. (and donep org-agenda-skip-timestamp-if-done))
  4369. (throw :skip t))
  4370. (if (string-match ">" timestr)
  4371. ;; substring should only run to end of time stamp
  4372. (setq timestr (substring timestr 0 (match-end 0))))
  4373. (setq marker (org-agenda-new-marker b0)
  4374. category (org-get-category b0))
  4375. (save-excursion
  4376. (if (not (re-search-backward "^\\*+ " nil t))
  4377. (setq txt org-agenda-no-heading-message)
  4378. (goto-char (match-beginning 0))
  4379. (setq hdmarker (org-agenda-new-marker)
  4380. tags (org-get-tags-at))
  4381. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4382. (setq head (or (match-string 1) ""))
  4383. (setq txt (org-format-agenda-item
  4384. (if inactivep org-agenda-inactive-leader nil)
  4385. head category tags timestr
  4386. remove-re)))
  4387. (setq priority (org-get-priority txt))
  4388. (org-add-props txt props
  4389. 'org-marker marker 'org-hd-marker hdmarker)
  4390. (org-add-props txt nil 'priority priority
  4391. 'org-category category 'date date
  4392. 'todo-state todo-state
  4393. 'type "timestamp")
  4394. (push txt ee))
  4395. (if org-agenda-skip-additional-timestamps-same-entry
  4396. (outline-next-heading)
  4397. (goto-char end-of-match))))
  4398. (nreverse ee)))
  4399. (defun org-agenda-get-sexps ()
  4400. "Return the sexp information for agenda display."
  4401. (require 'diary-lib)
  4402. (let* ((props (list 'mouse-face 'highlight
  4403. 'help-echo
  4404. (format "mouse-2 or RET jump to org file %s"
  4405. (abbreviate-file-name buffer-file-name))))
  4406. (regexp "^&?%%(")
  4407. marker category ee txt tags entry result beg b sexp sexp-entry
  4408. todo-state)
  4409. (goto-char (point-min))
  4410. (while (re-search-forward regexp nil t)
  4411. (catch :skip
  4412. (org-agenda-skip)
  4413. (setq beg (match-beginning 0))
  4414. (goto-char (1- (match-end 0)))
  4415. (setq b (point))
  4416. (forward-sexp 1)
  4417. (setq sexp (buffer-substring b (point)))
  4418. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4419. (org-trim (match-string 1))
  4420. ""))
  4421. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4422. (when result
  4423. (setq marker (org-agenda-new-marker beg)
  4424. category (org-get-category beg)
  4425. todo-state (org-get-todo-state))
  4426. (dolist (r (if (stringp result)
  4427. (list result)
  4428. result)) ;; we expect a list here
  4429. (if (string-match "\\S-" r)
  4430. (setq txt r)
  4431. (setq txt "SEXP entry returned empty string"))
  4432. (setq txt (org-format-agenda-item
  4433. "" txt category tags 'time))
  4434. (org-add-props txt props 'org-marker marker)
  4435. (org-add-props txt nil
  4436. 'org-category category 'date date 'todo-state todo-state
  4437. 'type "sexp")
  4438. (push txt ee)))))
  4439. (nreverse ee)))
  4440. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4441. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4442. The order of the first 2 times 3 arguments depends on the variable
  4443. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4444. So for American calendars, give this as MONTH DAY YEAR, for European as
  4445. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4446. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4447. is any number of ISO weeks in the block period for which the item should
  4448. be skipped."
  4449. (let* ((date1 (calendar-absolute-from-gregorian
  4450. (org-order-calendar-date-args m1 d1 y1)))
  4451. (date2 (calendar-absolute-from-gregorian
  4452. (org-order-calendar-date-args m2 d2 y2)))
  4453. (d (calendar-absolute-from-gregorian date)))
  4454. (and
  4455. (<= date1 d)
  4456. (<= d date2)
  4457. (= (calendar-day-of-week date) dayname)
  4458. (or (not skip-weeks)
  4459. (progn
  4460. (require 'cal-iso)
  4461. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4462. entry)))
  4463. (defalias 'org-get-closed 'org-agenda-get-progress)
  4464. (defun org-agenda-get-progress ()
  4465. "Return the logged TODO entries for agenda display."
  4466. (let* ((props (list 'mouse-face 'highlight
  4467. 'org-not-done-regexp org-not-done-regexp
  4468. 'org-todo-regexp org-todo-regexp
  4469. 'org-complex-heading-regexp org-complex-heading-regexp
  4470. 'help-echo
  4471. (format "mouse-2 or RET jump to org file %s"
  4472. (abbreviate-file-name buffer-file-name))))
  4473. (items (if (consp org-agenda-show-log)
  4474. org-agenda-show-log
  4475. (if (eq org-agenda-show-log 'clockcheck)
  4476. '(clock)
  4477. org-agenda-log-mode-items)))
  4478. (parts
  4479. (delq nil
  4480. (list
  4481. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4482. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4483. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4484. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4485. (error "`org-agenda-log-mode-items' is empty")))
  4486. (regexp (concat
  4487. "\\(" parts-re "\\)"
  4488. " *\\["
  4489. (regexp-quote
  4490. (substring
  4491. (format-time-string
  4492. (car org-time-stamp-formats)
  4493. (apply 'encode-time ; DATE bound by calendar
  4494. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4495. 1 11))))
  4496. (org-agenda-search-headline-for-time nil)
  4497. marker hdmarker priority category tags closedp statep clockp state
  4498. ee txt extra timestr rest clocked)
  4499. (goto-char (point-min))
  4500. (while (re-search-forward regexp nil t)
  4501. (catch :skip
  4502. (org-agenda-skip)
  4503. (setq marker (org-agenda-new-marker (match-beginning 0))
  4504. closedp (equal (match-string 1) org-closed-string)
  4505. statep (equal (string-to-char (match-string 1)) ?-)
  4506. clockp (not (or closedp statep))
  4507. state (and statep (match-string 2))
  4508. category (org-get-category (match-beginning 0))
  4509. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4510. )
  4511. (when (string-match "\\]" timestr)
  4512. ;; substring should only run to end of time stamp
  4513. (setq rest (substring timestr (match-end 0))
  4514. timestr (substring timestr 0 (match-end 0)))
  4515. (if (and (not closedp) (not statep)
  4516. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4517. (progn (setq timestr (concat (substring timestr 0 -1)
  4518. "-" (match-string 1 rest) "]"))
  4519. (setq clocked (match-string 2 rest)))
  4520. (setq clocked "-")))
  4521. (save-excursion
  4522. (setq extra
  4523. (cond
  4524. ((not org-agenda-log-mode-add-notes) nil)
  4525. (statep
  4526. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4527. (match-string 1)))
  4528. (clockp
  4529. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4530. (match-string 1)))))
  4531. (if (not (re-search-backward "^\\*+ " nil t))
  4532. (setq txt org-agenda-no-heading-message)
  4533. (goto-char (match-beginning 0))
  4534. (setq hdmarker (org-agenda-new-marker)
  4535. tags (org-get-tags-at))
  4536. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4537. (setq txt (match-string 1))
  4538. (when extra
  4539. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4540. (setq txt (concat (substring txt 0 (match-beginning 1))
  4541. " - " extra " " (match-string 2 txt)))
  4542. (setq txt (concat txt " - " extra))))
  4543. (setq txt (org-format-agenda-item
  4544. (cond
  4545. (closedp "Closed: ")
  4546. (statep (concat "State: (" state ")"))
  4547. (t (concat "Clocked: (" clocked ")")))
  4548. txt category tags timestr)))
  4549. (setq priority 100000)
  4550. (org-add-props txt props
  4551. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4552. 'priority priority 'org-category category
  4553. 'type "closed" 'date date
  4554. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4555. (push txt ee))
  4556. (goto-char (point-at-eol))))
  4557. (nreverse ee)))
  4558. (defun org-agenda-show-clocking-issues ()
  4559. "Add overlays, showing issues with clocking.
  4560. See also the user option `org-agenda-clock-consistency-checks'."
  4561. (interactive)
  4562. (let* ((pl org-agenda-clock-consistency-checks)
  4563. (re (concat "^[ \t]*"
  4564. org-clock-string
  4565. "[ \t]+"
  4566. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4567. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4568. (tlstart 0.)
  4569. (tlend 0.)
  4570. (maxtime (org-hh:mm-string-to-minutes
  4571. (or (plist-get pl :max-duration) "24:00")))
  4572. (mintime (org-hh:mm-string-to-minutes
  4573. (or (plist-get pl :min-duration) 0)))
  4574. (maxgap (org-hh:mm-string-to-minutes
  4575. ;; default 30:00 means never complain
  4576. (or (plist-get pl :max-gap) "30:00")))
  4577. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4578. (plist-get pl :gap-ok-around)))
  4579. (def-face (or (plist-get pl :default-face)
  4580. '((:background "DarkRed") (:foreground "white"))))
  4581. issue face m te ts dt ov)
  4582. (goto-char (point-min))
  4583. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4584. (setq issue nil face def-face)
  4585. (catch 'next
  4586. (setq m (org-get-at-bol 'org-marker)
  4587. te nil ts nil)
  4588. (unless (and m (markerp m))
  4589. (setq issue "No valid clock line") (throw 'next t))
  4590. (org-with-point-at m
  4591. (save-excursion
  4592. (goto-char (point-at-bol))
  4593. (unless (looking-at re)
  4594. (error "No valid Clock line")
  4595. (throw 'next t))
  4596. (unless (match-end 3)
  4597. (setq issue "No end time"
  4598. face (or (plist-get pl :no-end-time-face) face))
  4599. (throw 'next t))
  4600. (setq ts (match-string 1)
  4601. te (match-string 3)
  4602. ts (org-float-time
  4603. (apply 'encode-time (org-parse-time-string ts)))
  4604. te (org-float-time
  4605. (apply 'encode-time (org-parse-time-string te)))
  4606. dt (- te ts))))
  4607. (cond
  4608. ((> dt (* 60 maxtime))
  4609. ;; a very long clocking chunk
  4610. (setq issue (format "Clocking interval is very long: %s"
  4611. (org-minutes-to-hh:mm-string
  4612. (floor (/ (float dt) 60.))))
  4613. face (or (plist-get pl :long-face) face)))
  4614. ((< dt (* 60 mintime))
  4615. ;; a very short clocking chunk
  4616. (setq issue (format "Clocking interval is very short: %s"
  4617. (org-minutes-to-hh:mm-string
  4618. (floor (/ (float dt) 60.))))
  4619. face (or (plist-get pl :short-face) face)))
  4620. ((and (> tlend 0) (< ts tlend))
  4621. ;; Two clock entries are overlapping
  4622. (setq issue (format "Clocking overlap: %d minutes"
  4623. (/ (- tlend ts) 60))
  4624. face (or (plist-get pl :overlap-face) face)))
  4625. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4626. ;; There is a gap, lets see if we need to report it
  4627. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4628. (setq issue (format "Clocking gap: %d minutes"
  4629. (/ (- ts tlend) 60))
  4630. face (or (plist-get pl :gap-face) face))))
  4631. (t nil)))
  4632. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4633. (when issue
  4634. ;; OK, there was some issue, add an overlay to show the issue
  4635. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4636. (overlay-put ov 'before-string
  4637. (concat
  4638. (org-add-props
  4639. (format "%-43s" (concat " " issue))
  4640. nil
  4641. 'face face)
  4642. "\n"))
  4643. (overlay-put ov 'evaporate t)))))
  4644. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4645. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4646. (catch 'exit
  4647. (unless ok-list
  4648. ;; there are no OK times for gaps...
  4649. (throw 'exit nil))
  4650. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4651. ;; This is more than 24 hours, so it is OK.
  4652. ;; because we have at least one OK time, that must be in the
  4653. ;; 24 hour interval.
  4654. (throw 'exit t))
  4655. ;; We have a shorter gap.
  4656. ;; Now we have to get the minute of the day when these times are
  4657. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4658. (t2dec (decode-time (seconds-to-time t2)))
  4659. ;; compute the minute on the day
  4660. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4661. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4662. (when (< min2 min1)
  4663. ;; if min2 is smaller than min1, this means it is on the next day.
  4664. ;; Wrap it to after midnight.
  4665. (setq min2 (+ min2 1440)))
  4666. ;; Now check if any of the OK times is in the gap
  4667. (mapc (lambda (x)
  4668. ;; Wrap the time to after midnight if necessary
  4669. (if (< x min1) (setq x (+ x 1440)))
  4670. ;; Check if in interval
  4671. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4672. ok-list)
  4673. ;; Nope, this gap is not OK
  4674. nil)))
  4675. (defun org-agenda-get-deadlines ()
  4676. "Return the deadline information for agenda display."
  4677. (let* ((props (list 'mouse-face 'highlight
  4678. 'org-not-done-regexp org-not-done-regexp
  4679. 'org-todo-regexp org-todo-regexp
  4680. 'org-complex-heading-regexp org-complex-heading-regexp
  4681. 'help-echo
  4682. (format "mouse-2 or RET jump to org file %s"
  4683. (abbreviate-file-name buffer-file-name))))
  4684. (regexp org-deadline-time-regexp)
  4685. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4686. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4687. d2 diff dfrac wdays pos pos1 category tags
  4688. suppress-prewarning
  4689. ee txt head face s todo-state show-all upcomingp donep timestr)
  4690. (goto-char (point-min))
  4691. (while (re-search-forward regexp nil t)
  4692. (setq suppress-prewarning nil)
  4693. (catch :skip
  4694. (org-agenda-skip)
  4695. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4696. (save-match-data
  4697. (string-match org-scheduled-time-regexp
  4698. (buffer-substring (point-at-bol)
  4699. (point-at-eol)))))
  4700. (setq suppress-prewarning
  4701. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4702. org-agenda-skip-deadline-prewarning-if-scheduled
  4703. 0)))
  4704. (setq s (match-string 1)
  4705. txt nil
  4706. pos (1- (match-beginning 1))
  4707. todo-state (save-match-data (org-get-todo-state))
  4708. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4709. (member todo-state
  4710. org-agenda-repeating-timestamp-show-all))
  4711. d2 (org-time-string-to-absolute
  4712. (match-string 1) d1 'past show-all)
  4713. diff (- d2 d1)
  4714. wdays (if suppress-prewarning
  4715. (let ((org-deadline-warning-days suppress-prewarning))
  4716. (org-get-wdays s))
  4717. (org-get-wdays s))
  4718. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4719. upcomingp (and todayp (> diff 0)))
  4720. ;; When to show a deadline in the calendar:
  4721. ;; If the expiration is within wdays warning time.
  4722. ;; Past-due deadlines are only shown on the current date
  4723. (if (and (or (and (<= diff wdays)
  4724. (and todayp (not org-agenda-only-exact-dates)))
  4725. (= diff 0)))
  4726. (save-excursion
  4727. ;; (setq todo-state (org-get-todo-state))
  4728. (setq donep (member todo-state org-done-keywords))
  4729. (if (and donep
  4730. (or org-agenda-skip-deadline-if-done
  4731. (not (= diff 0))))
  4732. (setq txt nil)
  4733. (setq category (org-get-category))
  4734. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4735. (setq txt org-agenda-no-heading-message)
  4736. (goto-char (match-end 0))
  4737. (setq pos1 (match-beginning 0))
  4738. (setq tags (org-get-tags-at pos1))
  4739. (setq head (buffer-substring-no-properties
  4740. (point)
  4741. (progn (skip-chars-forward "^\r\n")
  4742. (point))))
  4743. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4744. (setq timestr
  4745. (concat (substring s (match-beginning 1)) " "))
  4746. (setq timestr 'time))
  4747. (setq txt (org-format-agenda-item
  4748. (if (= diff 0)
  4749. (car org-agenda-deadline-leaders)
  4750. (if (functionp
  4751. (nth 1 org-agenda-deadline-leaders))
  4752. (funcall
  4753. (nth 1 org-agenda-deadline-leaders)
  4754. diff date)
  4755. (format (nth 1 org-agenda-deadline-leaders)
  4756. diff)))
  4757. head category tags
  4758. (if (not (= diff 0)) nil timestr)))))
  4759. (when txt
  4760. (setq face (org-agenda-deadline-face dfrac wdays))
  4761. (org-add-props txt props
  4762. 'org-marker (org-agenda-new-marker pos)
  4763. 'org-hd-marker (org-agenda-new-marker pos1)
  4764. 'priority (+ (- diff)
  4765. (org-get-priority txt))
  4766. 'org-category category
  4767. 'todo-state todo-state
  4768. 'type (if upcomingp "upcoming-deadline" "deadline")
  4769. 'date (if upcomingp date d2)
  4770. 'face (if donep 'org-agenda-done face)
  4771. 'undone-face face 'done-face 'org-agenda-done)
  4772. (push txt ee))))))
  4773. (nreverse ee)))
  4774. (defun org-agenda-deadline-face (fraction &optional wdays)
  4775. "Return the face to displaying a deadline item.
  4776. FRACTION is what fraction of the head-warning time has passed."
  4777. (if (equal wdays 0) (setq fraction 1.))
  4778. (let ((faces org-agenda-deadline-faces) f)
  4779. (catch 'exit
  4780. (while (setq f (pop faces))
  4781. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4782. (defun org-agenda-get-scheduled (&optional deadline-results)
  4783. "Return the scheduled information for agenda display."
  4784. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4785. 'org-todo-regexp org-todo-regexp
  4786. 'org-complex-heading-regexp org-complex-heading-regexp
  4787. 'done-face 'org-agenda-done
  4788. 'mouse-face 'highlight
  4789. 'help-echo
  4790. (format "mouse-2 or RET jump to org file %s"
  4791. (abbreviate-file-name buffer-file-name))))
  4792. (regexp org-scheduled-time-regexp)
  4793. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4794. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4795. mm
  4796. (deadline-position-alist
  4797. (mapcar (lambda (a) (and (setq mm (get-text-property
  4798. 0 'org-hd-marker a))
  4799. (cons (marker-position mm) a)))
  4800. deadline-results))
  4801. d2 diff pos pos1 category tags donep
  4802. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4803. (goto-char (point-min))
  4804. (while (re-search-forward regexp nil t)
  4805. (catch :skip
  4806. (org-agenda-skip)
  4807. (setq s (match-string 1)
  4808. txt nil
  4809. pos (1- (match-beginning 1))
  4810. todo-state (save-match-data (org-get-todo-state))
  4811. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4812. (member todo-state
  4813. org-agenda-repeating-timestamp-show-all))
  4814. d2 (org-time-string-to-absolute
  4815. (match-string 1) d1 'past show-all)
  4816. diff (- d2 d1))
  4817. (setq pastschedp (and todayp (< diff 0)))
  4818. ;; When to show a scheduled item in the calendar:
  4819. ;; If it is on or past the date.
  4820. (when (or (and (< diff 0)
  4821. (< (abs diff) org-scheduled-past-days)
  4822. (and todayp (not org-agenda-only-exact-dates)))
  4823. (= diff 0))
  4824. (save-excursion
  4825. (setq donep (member todo-state org-done-keywords))
  4826. (if (and donep
  4827. (or org-agenda-skip-scheduled-if-done
  4828. (not (= diff 0))
  4829. (and (functionp 'org-is-habit-p)
  4830. (org-is-habit-p))))
  4831. (setq txt nil)
  4832. (setq habitp (and (functionp 'org-is-habit-p)
  4833. (org-is-habit-p)))
  4834. (setq category (org-get-category))
  4835. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4836. (setq txt org-agenda-no-heading-message)
  4837. (goto-char (match-end 0))
  4838. (setq pos1 (match-beginning 0))
  4839. (if habitp
  4840. (if (or (not org-habit-show-habits)
  4841. (and (not todayp)
  4842. org-habit-show-habits-only-for-today))
  4843. (throw :skip nil))
  4844. (if (and
  4845. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4846. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4847. pastschedp))
  4848. (setq mm (assoc pos1 deadline-position-alist)))
  4849. (throw :skip nil)))
  4850. (setq tags (org-get-tags-at))
  4851. (setq head (buffer-substring-no-properties
  4852. (point)
  4853. (progn (skip-chars-forward "^\r\n") (point))))
  4854. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4855. (setq timestr
  4856. (concat (substring s (match-beginning 1)) " "))
  4857. (setq timestr 'time))
  4858. (setq txt (org-format-agenda-item
  4859. (if (= diff 0)
  4860. (car org-agenda-scheduled-leaders)
  4861. (format (nth 1 org-agenda-scheduled-leaders)
  4862. (- 1 diff)))
  4863. head category tags
  4864. (if (not (= diff 0)) nil timestr)
  4865. nil habitp))))
  4866. (when txt
  4867. (setq face
  4868. (cond
  4869. ((and (not habitp) pastschedp)
  4870. 'org-scheduled-previously)
  4871. (todayp 'org-scheduled-today)
  4872. (t 'org-scheduled))
  4873. habitp (and habitp (org-habit-parse-todo)))
  4874. (org-add-props txt props
  4875. 'undone-face face
  4876. 'face (if donep 'org-agenda-done face)
  4877. 'org-marker (org-agenda-new-marker pos)
  4878. 'org-hd-marker (org-agenda-new-marker pos1)
  4879. 'type (if pastschedp "past-scheduled" "scheduled")
  4880. 'date (if pastschedp d2 date)
  4881. 'priority (if habitp
  4882. (org-habit-get-priority habitp)
  4883. (+ 94 (- 5 diff) (org-get-priority txt)))
  4884. 'org-category category
  4885. 'org-habit-p habitp
  4886. 'todo-state todo-state)
  4887. (push txt ee))))))
  4888. (nreverse ee)))
  4889. (defun org-agenda-get-blocks ()
  4890. "Return the date-range information for agenda display."
  4891. (let* ((props (list 'face nil
  4892. 'org-not-done-regexp org-not-done-regexp
  4893. 'org-todo-regexp org-todo-regexp
  4894. 'org-complex-heading-regexp org-complex-heading-regexp
  4895. 'mouse-face 'highlight
  4896. 'help-echo
  4897. (format "mouse-2 or RET jump to org file %s"
  4898. (abbreviate-file-name buffer-file-name))))
  4899. (regexp org-tr-regexp)
  4900. (d0 (calendar-absolute-from-gregorian date))
  4901. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4902. head donep)
  4903. (goto-char (point-min))
  4904. (while (re-search-forward regexp nil t)
  4905. (catch :skip
  4906. (org-agenda-skip)
  4907. (setq pos (point))
  4908. (let ((start-time (match-string 1))
  4909. (end-time (match-string 2)))
  4910. (setq s1 (match-string 1)
  4911. s2 (match-string 2)
  4912. d1 (time-to-days (org-time-string-to-time s1))
  4913. d2 (time-to-days (org-time-string-to-time s2)))
  4914. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4915. ;; Only allow days between the limits, because the normal
  4916. ;; date stamps will catch the limits.
  4917. (save-excursion
  4918. (setq todo-state (org-get-todo-state))
  4919. (setq donep (member todo-state org-done-keywords))
  4920. (if (and donep org-agenda-skip-timestamp-if-done)
  4921. (throw :skip t))
  4922. (setq marker (org-agenda-new-marker (point)))
  4923. (setq category (org-get-category))
  4924. (if (not (re-search-backward "^\\*+ " nil t))
  4925. (setq txt org-agenda-no-heading-message)
  4926. (goto-char (match-beginning 0))
  4927. (setq hdmarker (org-agenda-new-marker (point)))
  4928. (setq tags (org-get-tags-at))
  4929. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4930. (setq head (match-string 1))
  4931. (let ((remove-re
  4932. (if org-agenda-remove-timeranges-from-blocks
  4933. (concat
  4934. "<" (regexp-quote s1) ".*?>"
  4935. "--"
  4936. "<" (regexp-quote s2) ".*?>")
  4937. nil)))
  4938. (setq txt (org-format-agenda-item
  4939. (format
  4940. (nth (if (= d1 d2) 0 1)
  4941. org-agenda-timerange-leaders)
  4942. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4943. head category tags
  4944. (cond ((= d1 d0)
  4945. (concat "<" start-time ">"))
  4946. ((= d2 d0)
  4947. (concat "<" end-time ">"))
  4948. (t nil))
  4949. remove-re))))
  4950. (org-add-props txt props
  4951. 'org-marker marker 'org-hd-marker hdmarker
  4952. 'type "block" 'date date
  4953. 'todo-state todo-state
  4954. 'priority (org-get-priority txt) 'org-category category)
  4955. (push txt ee))))
  4956. (goto-char pos)))
  4957. ;; Sort the entries by expiration date.
  4958. (nreverse ee)))
  4959. ;;; Agenda presentation and sorting
  4960. (defvar org-prefix-has-time nil
  4961. "A flag, set by `org-compile-prefix-format'.
  4962. The flag is set if the currently compiled format contains a `%t'.")
  4963. (defvar org-prefix-has-tag nil
  4964. "A flag, set by `org-compile-prefix-format'.
  4965. The flag is set if the currently compiled format contains a `%T'.")
  4966. (defvar org-prefix-has-effort nil
  4967. "A flag, set by `org-compile-prefix-format'.
  4968. The flag is set if the currently compiled format contains a `%e'.")
  4969. (defvar org-prefix-category-length nil
  4970. "Used by `org-compile-prefix-format' to remember the category field width.")
  4971. (defvar org-prefix-category-max-length nil
  4972. "Used by `org-compile-prefix-format' to remember the category field width.")
  4973. (defun org-agenda-get-category-icon (category)
  4974. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4975. (dolist (entry org-agenda-category-icon-alist)
  4976. (when (org-string-match-p (car entry) category)
  4977. (if (listp (cadr entry))
  4978. (return (cadr entry))
  4979. (return (apply 'create-image (cdr entry)))))))
  4980. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4981. remove-re habitp)
  4982. "Format TXT to be inserted into the agenda buffer.
  4983. In particular, it adds the prefix and corresponding text properties. EXTRA
  4984. must be a string and replaces the `%s' specifier in the prefix format.
  4985. CATEGORY (string, symbol or nil) may be used to overrule the default
  4986. category taken from local variable or file name. It will replace the `%c'
  4987. specifier in the format. DOTIME, when non-nil, indicates that a
  4988. time-of-day should be extracted from TXT for sorting of this entry, and for
  4989. the `%t' specifier in the format. When DOTIME is a string, this string is
  4990. searched for a time before TXT is. TAGS can be the tags of the headline.
  4991. Any match of REMOVE-RE will be removed from TXT."
  4992. (save-match-data
  4993. ;; Diary entries sometimes have extra whitespace at the beginning
  4994. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4995. ;; Fix the tags part in txt
  4996. (setq txt (org-agenda-fix-displayed-tags
  4997. txt tags
  4998. org-agenda-show-inherited-tags
  4999. org-agenda-hide-tags-regexp))
  5000. (let* ((category (or category
  5001. (if (stringp org-category)
  5002. org-category
  5003. (and org-category (symbol-name org-category)))
  5004. (if buffer-file-name
  5005. (file-name-sans-extension
  5006. (file-name-nondirectory buffer-file-name))
  5007. "")))
  5008. (category-icon (org-agenda-get-category-icon category))
  5009. (category-icon (if category-icon
  5010. (propertize " " 'display category-icon)
  5011. ""))
  5012. ;; time, tag, effort are needed for the eval of the prefix format
  5013. (tag (if tags (nth (1- (length tags)) tags) ""))
  5014. time effort neffort
  5015. (ts (if dotime (concat
  5016. (if (stringp dotime) dotime "")
  5017. (and org-agenda-search-headline-for-time txt))))
  5018. (time-of-day (and dotime (org-get-time-of-day ts)))
  5019. stamp plain s0 s1 s2 rtn srp l
  5020. duration thecategory)
  5021. (and (org-mode-p) buffer-file-name
  5022. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5023. (when (and dotime time-of-day)
  5024. ;; Extract starting and ending time and move them to prefix
  5025. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5026. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5027. (setq s0 (match-string 0 ts)
  5028. srp (and stamp (match-end 3))
  5029. s1 (match-string (if plain 1 2) ts)
  5030. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5031. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5032. ;; them, we might want to remove them there to avoid duplication.
  5033. ;; The user can turn this off with a variable.
  5034. (if (and org-prefix-has-time
  5035. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5036. (string-match (concat (regexp-quote s0) " *") txt)
  5037. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5038. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5039. (= (match-beginning 0) 0)
  5040. t))
  5041. (setq txt (replace-match "" nil nil txt))))
  5042. ;; Normalize the time(s) to 24 hour
  5043. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5044. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5045. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5046. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5047. (setq s2
  5048. (org-minutes-to-hh:mm-string
  5049. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5050. ;; Compute the duration
  5051. (when s2
  5052. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5053. (org-hh:mm-string-to-minutes s1)))))
  5054. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5055. txt)
  5056. ;; Tags are in the string
  5057. (if (or (eq org-agenda-remove-tags t)
  5058. (and org-agenda-remove-tags
  5059. org-prefix-has-tag))
  5060. (setq txt (replace-match "" t t txt))
  5061. (setq txt (replace-match
  5062. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5063. (match-string 2 txt))
  5064. t t txt))))
  5065. (when (org-mode-p)
  5066. (setq effort
  5067. (condition-case nil
  5068. (org-get-effort
  5069. (or (get-text-property 0 'org-hd-marker txt)
  5070. (get-text-property 0 'org-marker txt)))
  5071. (error nil)))
  5072. (when effort
  5073. (setq neffort (org-duration-string-to-minutes effort)
  5074. effort (setq effort (concat "[" effort "]" )))))
  5075. (when remove-re
  5076. (while (string-match remove-re txt)
  5077. (setq txt (replace-match "" t t txt))))
  5078. ;; Set org-heading property on `txt' to mark the start of the
  5079. ;; heading.
  5080. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5081. ;; Prepare the variables needed in the eval of the compiled format
  5082. (setq time (cond (s2 (concat
  5083. (org-agenda-time-of-day-to-ampm-maybe s1)
  5084. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5085. (if org-agenda-timegrid-use-ampm " ")))
  5086. (s1 (concat
  5087. (org-agenda-time-of-day-to-ampm-maybe s1)
  5088. (if org-agenda-timegrid-use-ampm
  5089. "........ "
  5090. "......")))
  5091. (t ""))
  5092. extra (or (and (not habitp) extra) "")
  5093. category (if (symbolp category) (symbol-name category) category)
  5094. thecategory (copy-sequence category))
  5095. (if (string-match org-bracket-link-regexp category)
  5096. (progn
  5097. (setq l (if (match-end 3)
  5098. (- (match-end 3) (match-beginning 3))
  5099. (- (match-end 1) (match-beginning 1))))
  5100. (when (< l (or org-prefix-category-length 0))
  5101. (setq category (copy-sequence category))
  5102. (org-add-props category nil
  5103. 'extra-space (make-string
  5104. (- org-prefix-category-length l 1) ?\ ))))
  5105. (if (and org-prefix-category-max-length
  5106. (>= (length category) org-prefix-category-max-length))
  5107. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5108. ;; Evaluate the compiled format
  5109. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5110. ;; And finally add the text properties
  5111. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5112. (org-add-props rtn nil
  5113. 'org-category (if thecategory (downcase thecategory) category)
  5114. 'tags (mapcar 'org-downcase-keep-props tags)
  5115. 'org-highest-priority org-highest-priority
  5116. 'org-lowest-priority org-lowest-priority
  5117. 'time-of-day time-of-day
  5118. 'duration duration
  5119. 'effort effort
  5120. 'effort-minutes neffort
  5121. 'txt txt
  5122. 'time time
  5123. 'extra extra
  5124. 'dotime dotime))))
  5125. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5126. "Remove tags string from TXT, and add a modified list of tags.
  5127. The modified list may contain inherited tags, and tags matched by
  5128. `org-agenda-hide-tags-regexp' will be removed."
  5129. (when (or add-inherited hide-re)
  5130. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5131. (setq txt (substring txt 0 (match-beginning 0))))
  5132. (setq tags
  5133. (delq nil
  5134. (mapcar (lambda (tg)
  5135. (if (or (and hide-re (string-match hide-re tg))
  5136. (and (not add-inherited)
  5137. (get-text-property 0 'inherited tg)))
  5138. nil
  5139. tg))
  5140. tags)))
  5141. (when tags
  5142. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5143. i)
  5144. (setq txt (concat txt " :"
  5145. (mapconcat
  5146. (lambda (x)
  5147. (setq i (get-text-property 0 'inherited x))
  5148. (if (and have-i (not i))
  5149. (progn
  5150. (setq have-i nil)
  5151. (concat ":" x))
  5152. x))
  5153. tags ":")
  5154. (if have-i "::" ":"))))))
  5155. txt)
  5156. (defun org-downcase-keep-props (s)
  5157. (let ((props (text-properties-at 0 s)))
  5158. (setq s (downcase s))
  5159. (add-text-properties 0 (length s) props s)
  5160. s))
  5161. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5162. (defvar org-agenda-sorting-strategy-selected nil)
  5163. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5164. (catch 'exit
  5165. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5166. ((and todayp (member 'today (car org-agenda-time-grid))))
  5167. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5168. ((member 'weekly (car org-agenda-time-grid)))
  5169. (t (throw 'exit list)))
  5170. (let* ((have (delq nil (mapcar
  5171. (lambda (x) (get-text-property 1 'time-of-day x))
  5172. list)))
  5173. (string (nth 1 org-agenda-time-grid))
  5174. (gridtimes (nth 2 org-agenda-time-grid))
  5175. (req (car org-agenda-time-grid))
  5176. (remove (member 'remove-match req))
  5177. new time)
  5178. (if (and (member 'require-timed req) (not have))
  5179. ;; don't show empty grid
  5180. (throw 'exit list))
  5181. (while (setq time (pop gridtimes))
  5182. (unless (and remove (member time have))
  5183. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5184. (push (org-format-agenda-item
  5185. nil string "" nil
  5186. (concat (substring time 0 -2) ":" (substring time -2)))
  5187. new)
  5188. (put-text-property
  5189. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5190. (when (and todayp org-agenda-show-current-time-in-grid)
  5191. (push (org-format-agenda-item
  5192. nil
  5193. org-agenda-current-time-string
  5194. "" nil
  5195. (format-time-string "%H:%M "))
  5196. new)
  5197. (put-text-property
  5198. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5199. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5200. (append new list)
  5201. (append list new)))))
  5202. (defun org-compile-prefix-format (key)
  5203. "Compile the prefix format into a Lisp form that can be evaluated.
  5204. The resulting form is returned and stored in the variable
  5205. `org-prefix-format-compiled'."
  5206. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5207. org-prefix-category-length nil org-prefix-has-effort nil)
  5208. (let ((s (cond
  5209. ((stringp org-agenda-prefix-format)
  5210. org-agenda-prefix-format)
  5211. ((assq key org-agenda-prefix-format)
  5212. (cdr (assq key org-agenda-prefix-format)))
  5213. (t " %-12:c%?-12t% s")))
  5214. (start 0)
  5215. varform vars var e c f opt)
  5216. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5217. s start)
  5218. (setq var (or (cdr (assoc (match-string 4 s)
  5219. '(("c" . category) ("t" . time) ("s" . extra)
  5220. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5221. 'eval)
  5222. c (or (match-string 3 s) "")
  5223. opt (match-beginning 1)
  5224. start (1+ (match-beginning 0)))
  5225. (if (equal var 'time) (setq org-prefix-has-time t))
  5226. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5227. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5228. (setq f (concat "%" (match-string 2 s) "s"))
  5229. (when (equal var 'category)
  5230. (setq org-prefix-category-length
  5231. (floor (abs (string-to-number (match-string 2 s)))))
  5232. (setq org-prefix-category-max-length
  5233. (let ((x (match-string 2 s)))
  5234. (save-match-data
  5235. (if (string-match "\\.[0-9]+" x)
  5236. (string-to-number (substring (match-string 0 x) 1)))))))
  5237. (if (eq var 'eval)
  5238. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5239. (if opt
  5240. (setq varform
  5241. `(if (equal "" ,var)
  5242. ""
  5243. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5244. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5245. (setq s (replace-match "%s" t nil s))
  5246. (push varform vars))
  5247. (setq vars (nreverse vars))
  5248. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5249. (defun org-set-sorting-strategy (key)
  5250. (if (symbolp (car org-agenda-sorting-strategy))
  5251. ;; the old format
  5252. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5253. (setq org-agenda-sorting-strategy-selected
  5254. (or (cdr (assq key org-agenda-sorting-strategy))
  5255. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5256. '(time-up category-keep priority-down)))))
  5257. (defun org-get-time-of-day (s &optional string mod24)
  5258. "Check string S for a time of day.
  5259. If found, return it as a military time number between 0 and 2400.
  5260. If not found, return nil.
  5261. The optional STRING argument forces conversion into a 5 character wide string
  5262. HH:MM."
  5263. (save-match-data
  5264. (when
  5265. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5266. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5267. (let* ((h (string-to-number (match-string 1 s)))
  5268. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5269. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5270. (am-p (equal ampm "am"))
  5271. (h1 (cond ((not ampm) h)
  5272. ((= h 12) (if am-p 0 12))
  5273. (t (+ h (if am-p 0 12)))))
  5274. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5275. (mod h1 24) h1))
  5276. (t0 (+ (* 100 h2) m))
  5277. (t1 (concat (if (>= h1 24) "+" " ")
  5278. (if (and org-agenda-time-leading-zero
  5279. (< t0 1000)) "0" "")
  5280. (if (< t0 100) "0" "")
  5281. (if (< t0 10) "0" "")
  5282. (int-to-string t0))))
  5283. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5284. (defvar org-agenda-before-sorting-filter-function nil
  5285. "Function to be applied to agenda items prior to sorting.
  5286. Prior to sorting also means just before they are inserted into the agenda.
  5287. To aid sorting, you may revisit the original entries and add more text
  5288. properties which will later be used by the sorting functions.
  5289. The function should take a string argument, an agenda line.
  5290. It has access to the text properties in that line, which contain among
  5291. other things, the property `org-hd-marker' that points to the entry
  5292. where the line comes from. Note that not all lines going into the agenda
  5293. have this property, only most.
  5294. The function should return the modified string. It is probably best
  5295. to ONLY change text properties.
  5296. You can also use this function as a filter, by returning nil for lines
  5297. you don't want to have in the agenda at all. For this application, you
  5298. could bind the variable in the options section of a custom command.")
  5299. (defun org-finalize-agenda-entries (list &optional nosort)
  5300. "Sort and concatenate the agenda items."
  5301. (setq list (mapcar 'org-agenda-highlight-todo list))
  5302. (if nosort
  5303. list
  5304. (when org-agenda-before-sorting-filter-function
  5305. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5306. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5307. (defun org-agenda-highlight-todo (x)
  5308. (let ((org-done-keywords org-done-keywords-for-agenda)
  5309. (case-fold-search nil)
  5310. re)
  5311. (if (eq x 'line)
  5312. (save-excursion
  5313. (beginning-of-line 1)
  5314. (setq re (org-get-at-bol 'org-todo-regexp))
  5315. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5316. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5317. (add-text-properties (match-beginning 0) (match-end 1)
  5318. (list 'face (org-get-todo-face 1)))
  5319. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5320. (delete-region (match-beginning 1) (1- (match-end 0)))
  5321. (goto-char (match-beginning 1))
  5322. (insert (format org-agenda-todo-keyword-format s)))))
  5323. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5324. (setq re (get-text-property 0 'org-todo-regexp x))
  5325. (when (and re
  5326. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5327. x (or pl 0)) pl))
  5328. (add-text-properties
  5329. (or (match-end 1) (match-end 0)) (match-end 0)
  5330. (list 'face (org-get-todo-face (match-string 2 x)))
  5331. x)
  5332. (when (match-end 1)
  5333. (setq x (concat (substring x 0 (match-end 1))
  5334. (format org-agenda-todo-keyword-format
  5335. (match-string 2 x))
  5336. (org-add-props " " (text-properties-at 0 x))
  5337. (substring x (match-end 3)))))))
  5338. x)))
  5339. (defsubst org-cmp-priority (a b)
  5340. "Compare the priorities of string A and B."
  5341. (let ((pa (or (get-text-property 1 'priority a) 0))
  5342. (pb (or (get-text-property 1 'priority b) 0)))
  5343. (cond ((> pa pb) +1)
  5344. ((< pa pb) -1)
  5345. (t nil))))
  5346. (defsubst org-cmp-effort (a b)
  5347. "Compare the priorities of string A and B."
  5348. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5349. (ea (or (get-text-property 1 'effort-minutes a) def))
  5350. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5351. (cond ((> ea eb) +1)
  5352. ((< ea eb) -1)
  5353. (t nil))))
  5354. (defsubst org-cmp-category (a b)
  5355. "Compare the string values of categories of strings A and B."
  5356. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5357. (cb (or (get-text-property 1 'org-category b) "")))
  5358. (cond ((string-lessp ca cb) -1)
  5359. ((string-lessp cb ca) +1)
  5360. (t nil))))
  5361. (defsubst org-cmp-todo-state (a b)
  5362. "Compare the todo states of strings A and B."
  5363. (let* ((ma (or (get-text-property 1 'org-marker a)
  5364. (get-text-property 1 'org-hd-marker a)))
  5365. (mb (or (get-text-property 1 'org-marker b)
  5366. (get-text-property 1 'org-hd-marker b)))
  5367. (fa (and ma (marker-buffer ma)))
  5368. (fb (and mb (marker-buffer mb)))
  5369. (todo-kwds
  5370. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5371. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5372. (ta (or (get-text-property 1 'todo-state a) ""))
  5373. (tb (or (get-text-property 1 'todo-state b) ""))
  5374. (la (- (length (member ta todo-kwds))))
  5375. (lb (- (length (member tb todo-kwds))))
  5376. (donepa (member ta org-done-keywords-for-agenda))
  5377. (donepb (member tb org-done-keywords-for-agenda)))
  5378. (cond ((and donepa (not donepb)) -1)
  5379. ((and (not donepa) donepb) +1)
  5380. ((< la lb) -1)
  5381. ((< lb la) +1)
  5382. (t nil))))
  5383. (defsubst org-cmp-alpha (a b)
  5384. "Compare the headlines, alphabetically."
  5385. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5386. (plb (text-property-any 0 (length b) 'org-heading t b))
  5387. (ta (and pla (substring a pla)))
  5388. (tb (and plb (substring b plb))))
  5389. (when pla
  5390. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5391. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5392. (setq ta (substring ta (match-end 0))))
  5393. (setq ta (downcase ta)))
  5394. (when plb
  5395. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5396. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5397. (setq tb (substring tb (match-end 0))))
  5398. (setq tb (downcase tb)))
  5399. (cond ((not ta) +1)
  5400. ((not tb) -1)
  5401. ((string-lessp ta tb) -1)
  5402. ((string-lessp tb ta) +1)
  5403. (t nil))))
  5404. (defsubst org-cmp-tag (a b)
  5405. "Compare the string values of the first tags of A and B."
  5406. (let ((ta (car (last (get-text-property 1 'tags a))))
  5407. (tb (car (last (get-text-property 1 'tags b)))))
  5408. (cond ((not ta) +1)
  5409. ((not tb) -1)
  5410. ((string-lessp ta tb) -1)
  5411. ((string-lessp tb ta) +1)
  5412. (t nil))))
  5413. (defsubst org-cmp-time (a b)
  5414. "Compare the time-of-day values of strings A and B."
  5415. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5416. (ta (or (get-text-property 1 'time-of-day a) def))
  5417. (tb (or (get-text-property 1 'time-of-day b) def)))
  5418. (cond ((< ta tb) -1)
  5419. ((< tb ta) +1)
  5420. (t nil))))
  5421. (defsubst org-cmp-habit-p (a b)
  5422. "Compare the todo states of strings A and B."
  5423. (let ((ha (get-text-property 1 'org-habit-p a))
  5424. (hb (get-text-property 1 'org-habit-p b)))
  5425. (cond ((and ha (not hb)) -1)
  5426. ((and (not ha) hb) +1)
  5427. (t nil))))
  5428. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5429. (defun org-entries-lessp (a b)
  5430. "Predicate for sorting agenda entries."
  5431. ;; The following variables will be used when the form is evaluated.
  5432. ;; So even though the compiler complains, keep them.
  5433. (let* ((ss org-agenda-sorting-strategy-selected)
  5434. (time-up (and (org-em 'time-up 'time-down ss)
  5435. (org-cmp-time a b)))
  5436. (time-down (if time-up (- time-up) nil))
  5437. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5438. (org-cmp-priority a b)))
  5439. (priority-down (if priority-up (- priority-up) nil))
  5440. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5441. (org-cmp-effort a b)))
  5442. (effort-down (if effort-up (- effort-up) nil))
  5443. (category-up (and (or (org-em 'category-up 'category-down ss)
  5444. (memq 'category-keep ss))
  5445. (org-cmp-category a b)))
  5446. (category-down (if category-up (- category-up) nil))
  5447. (category-keep (if category-up +1 nil))
  5448. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5449. (org-cmp-tag a b)))
  5450. (tag-down (if tag-up (- tag-up) nil))
  5451. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5452. (org-cmp-todo-state a b)))
  5453. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5454. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5455. (org-cmp-habit-p a b)))
  5456. (habit-down (if habit-up (- habit-up) nil))
  5457. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5458. (org-cmp-alpha a b)))
  5459. (alpha-down (if alpha-up (- alpha-up) nil))
  5460. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5461. user-defined-up user-defined-down)
  5462. (if (and need-user-cmp org-agenda-cmp-user-defined
  5463. (functionp org-agenda-cmp-user-defined))
  5464. (setq user-defined-up
  5465. (funcall org-agenda-cmp-user-defined a b)
  5466. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5467. (cdr (assoc
  5468. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5469. '((-1 . t) (1 . nil) (nil . nil))))))
  5470. ;;; Agenda restriction lock
  5471. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5472. "Overlay to mark the headline to which agenda commands are restricted.")
  5473. (overlay-put org-agenda-restriction-lock-overlay
  5474. 'face 'org-agenda-restriction-lock)
  5475. (overlay-put org-agenda-restriction-lock-overlay
  5476. 'help-echo "Agendas are currently limited to this subtree.")
  5477. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5478. (defun org-agenda-set-restriction-lock (&optional type)
  5479. "Set restriction lock for agenda, to current subtree or file.
  5480. Restriction will be the file if TYPE is `file', or if type is the
  5481. universal prefix '(4), or if the cursor is before the first headline
  5482. in the file. Otherwise, restriction will be to the current subtree."
  5483. (interactive "P")
  5484. (and (equal type '(4)) (setq type 'file))
  5485. (setq type (cond
  5486. (type type)
  5487. ((org-at-heading-p) 'subtree)
  5488. ((condition-case nil (org-back-to-heading t) (error nil))
  5489. 'subtree)
  5490. (t 'file)))
  5491. (if (eq type 'subtree)
  5492. (progn
  5493. (setq org-agenda-restrict t)
  5494. (setq org-agenda-overriding-restriction 'subtree)
  5495. (put 'org-agenda-files 'org-restrict
  5496. (list (buffer-file-name (buffer-base-buffer))))
  5497. (org-back-to-heading t)
  5498. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5499. (move-marker org-agenda-restrict-begin (point))
  5500. (move-marker org-agenda-restrict-end
  5501. (save-excursion (org-end-of-subtree t)))
  5502. (message "Locking agenda restriction to subtree"))
  5503. (put 'org-agenda-files 'org-restrict
  5504. (list (buffer-file-name (buffer-base-buffer))))
  5505. (setq org-agenda-restrict nil)
  5506. (setq org-agenda-overriding-restriction 'file)
  5507. (move-marker org-agenda-restrict-begin nil)
  5508. (move-marker org-agenda-restrict-end nil)
  5509. (message "Locking agenda restriction to file"))
  5510. (setq current-prefix-arg nil)
  5511. (org-agenda-maybe-redo))
  5512. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5513. "Remove the agenda restriction lock."
  5514. (interactive "P")
  5515. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5516. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5517. (setq org-agenda-overriding-restriction nil)
  5518. (setq org-agenda-restrict nil)
  5519. (put 'org-agenda-files 'org-restrict nil)
  5520. (move-marker org-agenda-restrict-begin nil)
  5521. (move-marker org-agenda-restrict-end nil)
  5522. (setq current-prefix-arg nil)
  5523. (message "Agenda restriction lock removed")
  5524. (or noupdate (org-agenda-maybe-redo)))
  5525. (defun org-agenda-maybe-redo ()
  5526. "If there is any window showing the agenda view, update it."
  5527. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5528. (w0 (selected-window)))
  5529. (when w
  5530. (select-window w)
  5531. (org-agenda-redo)
  5532. (select-window w0)
  5533. (if org-agenda-overriding-restriction
  5534. (message "Agenda view shifted to new %s restriction"
  5535. org-agenda-overriding-restriction)
  5536. (message "Agenda restriction lock removed")))))
  5537. ;;; Agenda commands
  5538. (defun org-agenda-check-type (error &rest types)
  5539. "Check if agenda buffer is of allowed type.
  5540. If ERROR is non-nil, throw an error, otherwise just return nil."
  5541. (if (memq org-agenda-type types)
  5542. t
  5543. (if error
  5544. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5545. nil)))
  5546. (defun org-agenda-quit ()
  5547. "Exit agenda by removing the window or the buffer."
  5548. (interactive)
  5549. (if org-agenda-columns-active
  5550. (org-columns-quit)
  5551. (let ((buf (current-buffer)))
  5552. (if (eq org-agenda-window-setup 'other-frame)
  5553. (progn
  5554. (kill-buffer buf)
  5555. (org-agenda-reset-markers)
  5556. (org-columns-remove-overlays)
  5557. (setq org-agenda-archives-mode nil)
  5558. (delete-frame))
  5559. (and (not (eq org-agenda-window-setup 'current-window))
  5560. (not (one-window-p))
  5561. (delete-window))
  5562. (kill-buffer buf)
  5563. (org-agenda-reset-markers)
  5564. (org-columns-remove-overlays)
  5565. (setq org-agenda-archives-mode nil)))
  5566. ;; Maybe restore the pre-agenda window configuration.
  5567. (and org-agenda-restore-windows-after-quit
  5568. (not (eq org-agenda-window-setup 'other-frame))
  5569. org-pre-agenda-window-conf
  5570. (set-window-configuration org-pre-agenda-window-conf))))
  5571. (defun org-agenda-exit ()
  5572. "Exit agenda by removing the window or the buffer.
  5573. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5574. Org-mode buffers visited directly by the user will not be touched."
  5575. (interactive)
  5576. (org-release-buffers org-agenda-new-buffers)
  5577. (setq org-agenda-new-buffers nil)
  5578. (org-agenda-quit))
  5579. (defun org-agenda-execute (arg)
  5580. "Execute another agenda command, keeping same window.
  5581. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5582. in the agenda."
  5583. (interactive "P")
  5584. (let ((org-agenda-window-setup 'current-window))
  5585. (org-agenda arg)))
  5586. (defun org-agenda-redo ()
  5587. "Rebuild Agenda.
  5588. When this is the global TODO list, a prefix argument will be interpreted."
  5589. (interactive)
  5590. (let* ((org-agenda-keep-modes t)
  5591. (filter org-agenda-filter)
  5592. (preset (get 'org-agenda-filter :preset-filter))
  5593. (org-agenda-filter-while-redo (or filter preset))
  5594. (cols org-agenda-columns-active)
  5595. (line (org-current-line))
  5596. (window-line (- line (org-current-line (window-start))))
  5597. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5598. (put 'org-agenda-filter :preset-filter nil)
  5599. (and cols (org-columns-quit))
  5600. (message "Rebuilding agenda buffer...")
  5601. (org-let lprops '(eval org-agenda-redo-command))
  5602. (setq org-agenda-undo-list nil
  5603. org-agenda-pending-undo-list nil)
  5604. (message "Rebuilding agenda buffer...done")
  5605. (put 'org-agenda-filter :preset-filter preset)
  5606. (and (or filter preset) (org-agenda-filter-apply filter))
  5607. (and cols (called-interactively-p 'any) (org-agenda-columns))
  5608. (org-goto-line line)
  5609. (recenter window-line)))
  5610. (defvar org-global-tags-completion-table nil)
  5611. (defvar org-agenda-filter-form nil)
  5612. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5613. "Keep only those lines in the agenda buffer that have a specific tag.
  5614. The tag is selected with its fast selection letter, as configured.
  5615. With prefix argument STRIP, remove all lines that do have the tag.
  5616. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5617. used to narrow the search - the interactive user can also press `-' or `+'
  5618. to switch to narrowing."
  5619. (interactive "P")
  5620. (let* ((alist org-tag-alist-for-agenda)
  5621. (tag-chars (mapconcat
  5622. (lambda (x) (if (and (not (symbolp (car x)))
  5623. (cdr x))
  5624. (char-to-string (cdr x))
  5625. ""))
  5626. alist ""))
  5627. (efforts (org-split-string
  5628. (or (cdr (assoc (concat org-effort-property "_ALL")
  5629. org-global-properties))
  5630. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5631. "")))
  5632. (effort-op org-agenda-filter-effort-default-operator)
  5633. (effort-prompt "")
  5634. (inhibit-read-only t)
  5635. (current org-agenda-filter)
  5636. maybe-refresh a n tag)
  5637. (unless char
  5638. (message
  5639. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5640. (if narrow "Narrow" "Filter") tag-chars
  5641. (if org-agenda-auto-exclude-function "[RET], " ""))
  5642. (setq char (read-char)))
  5643. (when (member char '(?+ ?-))
  5644. ;; Narrowing down
  5645. (cond ((equal char ?-) (setq strip t narrow t))
  5646. ((equal char ?+) (setq strip nil narrow t)))
  5647. (message
  5648. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5649. (setq char (read-char)))
  5650. (when (member char '(?< ?> ?= ??))
  5651. ;; An effort operator
  5652. (setq effort-op (char-to-string char))
  5653. (setq alist nil) ; to make sure it will be interpreted as effort.
  5654. (unless (equal char ??)
  5655. (loop for i from 0 to 9 do
  5656. (setq effort-prompt
  5657. (concat
  5658. effort-prompt " ["
  5659. (if (= i 9) "0" (int-to-string (1+ i)))
  5660. "]" (nth i efforts))))
  5661. (message "Effort%s: %s " effort-op effort-prompt)
  5662. (setq char (read-char))
  5663. (when (or (< char ?0) (> char ?9))
  5664. (error "Need 1-9,0 to select effort" ))))
  5665. (when (equal char ?\t)
  5666. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5667. (org-set-local 'org-global-tags-completion-table
  5668. (org-global-tags-completion-table)))
  5669. (let ((completion-ignore-case t))
  5670. (setq tag (org-icompleting-read
  5671. "Tag: " org-global-tags-completion-table))))
  5672. (cond
  5673. ((equal char ?\r)
  5674. (org-agenda-filter-by-tag-show-all)
  5675. (when org-agenda-auto-exclude-function
  5676. (setq org-agenda-filter '())
  5677. (dolist (tag (org-agenda-get-represented-tags))
  5678. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5679. (if modifier
  5680. (push modifier org-agenda-filter))))
  5681. (if (not (null org-agenda-filter))
  5682. (org-agenda-filter-apply org-agenda-filter)))
  5683. (setq maybe-refresh t))
  5684. ((equal char ?/)
  5685. (org-agenda-filter-by-tag-show-all)
  5686. (when (get 'org-agenda-filter :preset-filter)
  5687. (org-agenda-filter-apply org-agenda-filter))
  5688. (setq maybe-refresh t))
  5689. ((or (equal char ?\ )
  5690. (setq a (rassoc char alist))
  5691. (and (>= char ?0) (<= char ?9)
  5692. (setq n (if (= char ?0) 9 (- char ?0 1))
  5693. tag (concat effort-op (nth n efforts))
  5694. a (cons tag nil)))
  5695. (and (= char ??)
  5696. (setq tag "?eff")
  5697. a (cons tag nil))
  5698. (and tag (setq a (cons tag nil))))
  5699. (org-agenda-filter-by-tag-show-all)
  5700. (setq tag (car a))
  5701. (setq org-agenda-filter
  5702. (cons (concat (if strip "-" "+") tag)
  5703. (if narrow current nil)))
  5704. (org-agenda-filter-apply org-agenda-filter)
  5705. (setq maybe-refresh t))
  5706. (t (error "Invalid tag selection character %c" char)))
  5707. (when (and maybe-refresh
  5708. (eq org-agenda-clockreport-mode 'with-filter))
  5709. (org-agenda-redo))))
  5710. (defun org-agenda-get-represented-tags ()
  5711. "Get a list of all tags currently represented in the agenda."
  5712. (let (p tags)
  5713. (save-excursion
  5714. (goto-char (point-min))
  5715. (while (setq p (next-single-property-change (point) 'tags))
  5716. (goto-char p)
  5717. (mapc (lambda (x) (add-to-list 'tags x))
  5718. (get-text-property (point) 'tags))))
  5719. tags))
  5720. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5721. "Refine the current filter. See `org-agenda-filter-by-tag."
  5722. (interactive "P")
  5723. (org-agenda-filter-by-tag strip char 'refine))
  5724. (defun org-agenda-filter-make-matcher ()
  5725. "Create the form that tests a line for the agenda filter."
  5726. (let (f f1)
  5727. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5728. org-agenda-filter))
  5729. (if (member x '("-" "+"))
  5730. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5731. (if (string-match "[<=>?]" x)
  5732. (setq f1 (org-agenda-filter-effort-form x))
  5733. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5734. (if (equal (string-to-char x) ?-)
  5735. (setq f1 (list 'not f1))))
  5736. (push f1 f))
  5737. (cons 'and (nreverse f))))
  5738. (defun org-agenda-filter-effort-form (e)
  5739. "Return the form to compare the effort of the current line with what E says.
  5740. E looks like \"+<2:25\"."
  5741. (let (op)
  5742. (setq e (substring e 1))
  5743. (setq op (string-to-char e) e (substring e 1))
  5744. (setq op (cond ((equal op ?<) '<=)
  5745. ((equal op ?>) '>=)
  5746. ((equal op ??) op)
  5747. (t '=)))
  5748. (list 'org-agenda-compare-effort (list 'quote op)
  5749. (org-duration-string-to-minutes e))))
  5750. (defun org-agenda-compare-effort (op value)
  5751. "Compare the effort of the current line with VALUE, using OP.
  5752. If the line does not have an effort defined, return nil."
  5753. (let ((eff (org-get-at-bol 'effort-minutes)))
  5754. (if (equal op ??)
  5755. (not eff)
  5756. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5757. value))))
  5758. (defun org-agenda-filter-apply (filter)
  5759. "Set FILTER as the new agenda filter and apply it."
  5760. (let (tags)
  5761. (setq org-agenda-filter filter
  5762. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5763. (org-agenda-set-mode-name)
  5764. (save-excursion
  5765. (goto-char (point-min))
  5766. (while (not (eobp))
  5767. (if (org-get-at-bol 'org-marker)
  5768. (progn
  5769. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5770. (if (not (eval org-agenda-filter-form))
  5771. (org-agenda-filter-by-tag-hide-line))
  5772. (beginning-of-line 2))
  5773. (beginning-of-line 2))))
  5774. (if (get-char-property (point) 'invisible)
  5775. (org-agenda-previous-line))))
  5776. (defun org-agenda-filter-by-tag-hide-line ()
  5777. (let (ov)
  5778. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5779. (point-at-eol)))
  5780. (overlay-put ov 'invisible t)
  5781. (overlay-put ov 'type 'tags-filter)
  5782. (push ov org-agenda-filter-overlays)))
  5783. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5784. (setq pos (or pos (point)))
  5785. (save-excursion
  5786. (dolist (ov (overlays-at pos))
  5787. (when (and (overlay-get ov 'invisible)
  5788. (eq (overlay-get ov 'type) 'tags-filter))
  5789. (goto-char pos)
  5790. (if (< (overlay-start ov) (point-at-eol))
  5791. (move-overlay ov (point-at-eol)
  5792. (overlay-end ov)))))))
  5793. (defun org-agenda-filter-by-tag-show-all ()
  5794. (mapc 'delete-overlay org-agenda-filter-overlays)
  5795. (setq org-agenda-filter-overlays nil)
  5796. (setq org-agenda-filter nil)
  5797. (setq org-agenda-filter-form nil)
  5798. (org-agenda-set-mode-name))
  5799. (defun org-agenda-manipulate-query-add ()
  5800. "Manipulate the query by adding a search term with positive selection.
  5801. Positive selection means the term must be matched for selection of an entry."
  5802. (interactive)
  5803. (org-agenda-manipulate-query ?\[))
  5804. (defun org-agenda-manipulate-query-subtract ()
  5805. "Manipulate the query by adding a search term with negative selection.
  5806. Negative selection means term must not be matched for selection of an entry."
  5807. (interactive)
  5808. (org-agenda-manipulate-query ?\]))
  5809. (defun org-agenda-manipulate-query-add-re ()
  5810. "Manipulate the query by adding a search regexp with positive selection.
  5811. Positive selection means the regexp must match for selection of an entry."
  5812. (interactive)
  5813. (org-agenda-manipulate-query ?\{))
  5814. (defun org-agenda-manipulate-query-subtract-re ()
  5815. "Manipulate the query by adding a search regexp with negative selection.
  5816. Negative selection means regexp must not match for selection of an entry."
  5817. (interactive)
  5818. (org-agenda-manipulate-query ?\}))
  5819. (defun org-agenda-manipulate-query (char)
  5820. (cond
  5821. ((memq org-agenda-type '(timeline agenda))
  5822. (let ((org-agenda-include-inactive-timestamps t))
  5823. (org-agenda-redo))
  5824. (message "Display now includes inactive timestamps as well"))
  5825. ((eq org-agenda-type 'search)
  5826. (org-add-to-string
  5827. 'org-agenda-query-string
  5828. (if org-agenda-last-search-view-search-was-boolean
  5829. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5830. (?\{ . " +{}") (?\} . " -{}"))))
  5831. " "))
  5832. (setq org-agenda-redo-command
  5833. (list 'org-search-view
  5834. org-todo-only
  5835. org-agenda-query-string
  5836. (+ (length org-agenda-query-string)
  5837. (if (member char '(?\{ ?\})) 0 1))))
  5838. (set-register org-agenda-query-register org-agenda-query-string)
  5839. (org-agenda-redo))
  5840. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5841. org-agenda-type))))
  5842. (defun org-add-to-string (var string)
  5843. (set var (concat (symbol-value var) string)))
  5844. (defun org-agenda-goto-date (date)
  5845. "Jump to DATE in agenda."
  5846. (interactive (list (let ((org-read-date-prefer-future
  5847. (eval org-agenda-jump-prefer-future)))
  5848. (org-read-date))))
  5849. (org-agenda-list nil date))
  5850. (defun org-agenda-goto-today ()
  5851. "Go to today."
  5852. (interactive)
  5853. (org-agenda-check-type t 'timeline 'agenda)
  5854. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5855. (cond
  5856. (tdpos (goto-char tdpos))
  5857. ((eq org-agenda-type 'agenda)
  5858. (let* ((sd (org-agenda-compute-starting-span
  5859. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5860. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5861. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5862. (org-agenda-redo)
  5863. (org-agenda-find-same-or-today-or-agenda)))
  5864. (t (error "Cannot find today")))))
  5865. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5866. (goto-char
  5867. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5868. (text-property-any (point-min) (point-max) 'org-today t)
  5869. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5870. (point-min))))
  5871. (defun org-agenda-later (arg)
  5872. "Go forward in time by thee current span.
  5873. With prefix ARG, go forward that many times the current span."
  5874. (interactive "p")
  5875. (org-agenda-check-type t 'agenda)
  5876. (let* ((span org-agenda-current-span)
  5877. (sd org-starting-day)
  5878. (greg (calendar-gregorian-from-absolute sd))
  5879. (cnt (org-get-at-bol 'org-day-cnt))
  5880. greg2)
  5881. (cond
  5882. ((eq span 'day)
  5883. (setq sd (+ arg sd)))
  5884. ((eq span 'week)
  5885. (setq sd (+ (* 7 arg) sd)))
  5886. ((eq span 'month)
  5887. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5888. sd (calendar-absolute-from-gregorian greg2))
  5889. (setcar greg2 (1+ (car greg2))))
  5890. ((eq span 'year)
  5891. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5892. sd (calendar-absolute-from-gregorian greg2))
  5893. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5894. (t
  5895. (setq sd (+ (* span arg) sd))))
  5896. (let ((org-agenda-overriding-arguments
  5897. (list (car org-agenda-last-arguments) sd span t)))
  5898. (org-agenda-redo)
  5899. (org-agenda-find-same-or-today-or-agenda cnt))))
  5900. (defun org-agenda-earlier (arg)
  5901. "Go backward in time by the current span.
  5902. With prefix ARG, go backward that many times the current span."
  5903. (interactive "p")
  5904. (org-agenda-later (- arg)))
  5905. (defun org-agenda-view-mode-dispatch ()
  5906. "Call one of the view mode commands."
  5907. (interactive)
  5908. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5909. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5910. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5911. [E]ntryText")
  5912. (let ((a (read-char-exclusive)))
  5913. (case a
  5914. (?\ (call-interactively 'org-agenda-reset-view))
  5915. (?d (call-interactively 'org-agenda-day-view))
  5916. (?w (call-interactively 'org-agenda-week-view))
  5917. (?m (call-interactively 'org-agenda-month-view))
  5918. (?y (call-interactively 'org-agenda-year-view))
  5919. (?l (call-interactively 'org-agenda-log-mode))
  5920. (?L (org-agenda-log-mode '(4)))
  5921. (?c (org-agenda-log-mode 'clockcheck))
  5922. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5923. (?a (call-interactively 'org-agenda-archives-mode))
  5924. (?A (org-agenda-archives-mode 'files))
  5925. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5926. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5927. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5928. (?D (call-interactively 'org-agenda-toggle-diary))
  5929. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5930. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5931. (org-agenda-check-type t 'timeline 'agenda)
  5932. (org-agenda-redo))
  5933. (message "Display now includes inactive timestamps as well"))
  5934. (?q (message "Abort"))
  5935. (otherwise (error "Invalid key" )))))
  5936. (defun org-agenda-reset-view ()
  5937. "Switch to default view for agenda."
  5938. (interactive)
  5939. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5940. (defun org-agenda-day-view (&optional day-of-year)
  5941. "Switch to daily view for agenda.
  5942. With argument DAY-OF-YEAR, switch to that day of the year."
  5943. (interactive "P")
  5944. (org-agenda-change-time-span 'day day-of-year))
  5945. (defun org-agenda-week-view (&optional iso-week)
  5946. "Switch to daily view for agenda.
  5947. With argument ISO-WEEK, switch to the corresponding ISO week.
  5948. If ISO-WEEK has more then 2 digits, only the last two encode the
  5949. week. Any digits before this encode a year. So 200712 means
  5950. week 12 of year 2007. Years in the range 1938-2037 can also be
  5951. written as 2-digit years."
  5952. (interactive "P")
  5953. (org-agenda-change-time-span 'week iso-week))
  5954. (defun org-agenda-month-view (&optional month)
  5955. "Switch to monthly view for agenda.
  5956. With argument MONTH, switch to that month."
  5957. (interactive "P")
  5958. (org-agenda-change-time-span 'month month))
  5959. (defun org-agenda-year-view (&optional year)
  5960. "Switch to yearly view for agenda.
  5961. With argument YEAR, switch to that year.
  5962. If MONTH has more then 2 digits, only the last two encode the
  5963. month. Any digits before this encode a year. So 200712 means
  5964. December year 2007. Years in the range 1938-2037 can also be
  5965. written as 2-digit years."
  5966. (interactive "P")
  5967. (when year
  5968. (setq year (org-small-year-to-year year)))
  5969. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5970. (org-agenda-change-time-span 'year year)
  5971. (error "Abort")))
  5972. (defun org-agenda-change-time-span (span &optional n)
  5973. "Change the agenda view to SPAN.
  5974. SPAN may be `day', `week', `month', `year'."
  5975. (org-agenda-check-type t 'agenda)
  5976. (if (and (not n) (equal org-agenda-current-span span))
  5977. (error "Viewing span is already \"%s\"" span))
  5978. (let* ((sd (or (org-get-at-bol 'day)
  5979. org-starting-day))
  5980. (sd (org-agenda-compute-starting-span sd span n))
  5981. (org-agenda-overriding-arguments
  5982. (or org-agenda-overriding-arguments
  5983. (list (car org-agenda-last-arguments) sd span t))))
  5984. (org-agenda-redo)
  5985. (org-agenda-find-same-or-today-or-agenda))
  5986. (org-agenda-set-mode-name)
  5987. (message "Switched to %s view" span))
  5988. (defun org-agenda-compute-starting-span (sd span &optional n)
  5989. "Compute starting date for agenda.
  5990. SPAN may be `day', `week', `month', `year'. The return value
  5991. is a cons cell with the starting date and the number of days,
  5992. so that the date SD will be in that range."
  5993. (let* ((greg (calendar-gregorian-from-absolute sd))
  5994. (dg (nth 1 greg))
  5995. (mg (car greg))
  5996. (yg (nth 2 greg)))
  5997. (cond
  5998. ((eq span 'day)
  5999. (when n
  6000. (setq sd (+ (calendar-absolute-from-gregorian
  6001. (list mg 1 yg))
  6002. n -1))))
  6003. ((eq span 'week)
  6004. (let* ((nt (calendar-day-of-week
  6005. (calendar-gregorian-from-absolute sd)))
  6006. (d (if org-agenda-start-on-weekday
  6007. (- nt org-agenda-start-on-weekday)
  6008. 0))
  6009. y1)
  6010. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6011. (when n
  6012. (require 'cal-iso)
  6013. (when (> n 99)
  6014. (setq y1 (org-small-year-to-year (/ n 100))
  6015. n (mod n 100)))
  6016. (setq sd
  6017. (calendar-absolute-from-iso
  6018. (list n 1
  6019. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6020. ((eq span 'month)
  6021. (let (y1)
  6022. (when (and n (> n 99))
  6023. (setq y1 (org-small-year-to-year (/ n 100))
  6024. n (mod n 100)))
  6025. (setq sd (calendar-absolute-from-gregorian
  6026. (list (or n mg) 1 (or y1 yg))))))
  6027. ((eq span 'year)
  6028. (setq sd (calendar-absolute-from-gregorian
  6029. (list 1 1 (or n yg))))))
  6030. sd))
  6031. (defun org-agenda-next-date-line (&optional arg)
  6032. "Jump to the next line indicating a date in agenda buffer."
  6033. (interactive "p")
  6034. (org-agenda-check-type t 'agenda 'timeline)
  6035. (beginning-of-line 1)
  6036. ;; This does not work if user makes date format that starts with a blank
  6037. (if (looking-at "^\\S-") (forward-char 1))
  6038. (if (not (re-search-forward "^\\S-" nil t arg))
  6039. (progn
  6040. (backward-char 1)
  6041. (error "No next date after this line in this buffer")))
  6042. (goto-char (match-beginning 0)))
  6043. (defun org-agenda-previous-date-line (&optional arg)
  6044. "Jump to the previous line indicating a date in agenda buffer."
  6045. (interactive "p")
  6046. (org-agenda-check-type t 'agenda 'timeline)
  6047. (beginning-of-line 1)
  6048. (if (not (re-search-backward "^\\S-" nil t arg))
  6049. (error "No previous date before this line in this buffer")))
  6050. ;; Initialize the highlight
  6051. (defvar org-hl (make-overlay 1 1))
  6052. (overlay-put org-hl 'face 'highlight)
  6053. (defun org-highlight (begin end &optional buffer)
  6054. "Highlight a region with overlay."
  6055. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6056. (defun org-unhighlight ()
  6057. "Detach overlay INDEX."
  6058. (org-detach-overlay org-hl))
  6059. ;; FIXME this is currently not used.
  6060. (defun org-highlight-until-next-command (beg end &optional buffer)
  6061. "Move the highlight overlay to BEG/END, remove it before the next command."
  6062. (org-highlight beg end buffer)
  6063. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6064. (defun org-unhighlight-once ()
  6065. "Remove the highlight from its position, and this function from the hook."
  6066. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6067. (org-unhighlight))
  6068. (defun org-agenda-follow-mode ()
  6069. "Toggle follow mode in an agenda buffer."
  6070. (interactive)
  6071. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6072. (org-agenda-set-mode-name)
  6073. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6074. (org-agenda-show))
  6075. (message "Follow mode is %s"
  6076. (if org-agenda-follow-mode "on" "off")))
  6077. (defun org-agenda-entry-text-mode (&optional arg)
  6078. "Toggle entry text mode in an agenda buffer."
  6079. (interactive "P")
  6080. (setq org-agenda-entry-text-mode (or (integerp arg)
  6081. (not org-agenda-entry-text-mode)))
  6082. (org-agenda-entry-text-hide)
  6083. (and org-agenda-entry-text-mode
  6084. (let ((org-agenda-entry-text-maxlines
  6085. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6086. (org-agenda-entry-text-show)))
  6087. (org-agenda-set-mode-name)
  6088. (message "Entry text mode is %s. Maximum number of lines is %d"
  6089. (if org-agenda-entry-text-mode "on" "off")
  6090. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6091. (defun org-agenda-clockreport-mode (&optional with-filter)
  6092. "Toggle clocktable mode in an agenda buffer.
  6093. With prefix arg WITH-FILTER, make the clocktable respect the current
  6094. agenda filter."
  6095. (interactive "P")
  6096. (org-agenda-check-type t 'agenda)
  6097. (if with-filter
  6098. (setq org-agenda-clockreport-mode 'with-filter)
  6099. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6100. (org-agenda-set-mode-name)
  6101. (org-agenda-redo)
  6102. (message "Clocktable mode is %s"
  6103. (if org-agenda-clockreport-mode "on" "off")))
  6104. (defun org-agenda-log-mode (&optional special)
  6105. "Toggle log mode in an agenda buffer.
  6106. With argument SPECIAL, show all possible log items, not only the ones
  6107. configured in `org-agenda-log-mode-items'.
  6108. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6109. (interactive "P")
  6110. (org-agenda-check-type t 'agenda 'timeline)
  6111. (setq org-agenda-show-log
  6112. (cond
  6113. ((equal special '(16)) 'only)
  6114. ((eq special 'clockcheck)
  6115. (if (eq org-agenda-show-log 'clockcheck)
  6116. nil 'clockcheck))
  6117. (special '(closed clock state))
  6118. (t (not org-agenda-show-log))))
  6119. (org-agenda-set-mode-name)
  6120. (org-agenda-redo)
  6121. (message "Log mode is %s"
  6122. (if org-agenda-show-log "on" "off")))
  6123. (defun org-agenda-archives-mode (&optional with-files)
  6124. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6125. When called with a prefix argument, include all archive files as well."
  6126. (interactive "P")
  6127. (setq org-agenda-archives-mode
  6128. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6129. (org-agenda-set-mode-name)
  6130. (org-agenda-redo)
  6131. (message
  6132. "%s"
  6133. (cond
  6134. ((eq org-agenda-archives-mode nil)
  6135. "No archives are included")
  6136. ((eq org-agenda-archives-mode 'trees)
  6137. (format "Trees with :%s: tag are included" org-archive-tag))
  6138. ((eq org-agenda-archives-mode t)
  6139. (format "Trees with :%s: tag and all active archive files are included"
  6140. org-archive-tag)))))
  6141. (defun org-agenda-toggle-diary ()
  6142. "Toggle diary inclusion in an agenda buffer."
  6143. (interactive)
  6144. (org-agenda-check-type t 'agenda)
  6145. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6146. (org-agenda-redo)
  6147. (org-agenda-set-mode-name)
  6148. (message "Diary inclusion turned %s"
  6149. (if org-agenda-include-diary "on" "off")))
  6150. (defun org-agenda-toggle-deadlines ()
  6151. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6152. (interactive)
  6153. (org-agenda-check-type t 'agenda)
  6154. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6155. (org-agenda-redo)
  6156. (org-agenda-set-mode-name)
  6157. (message "Deadlines inclusion turned %s"
  6158. (if org-agenda-include-deadlines "on" "off")))
  6159. (defun org-agenda-toggle-time-grid ()
  6160. "Toggle time grid in an agenda buffer."
  6161. (interactive)
  6162. (org-agenda-check-type t 'agenda)
  6163. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6164. (org-agenda-redo)
  6165. (org-agenda-set-mode-name)
  6166. (message "Time-grid turned %s"
  6167. (if org-agenda-use-time-grid "on" "off")))
  6168. (defun org-agenda-set-mode-name ()
  6169. "Set the mode name to indicate all the small mode settings."
  6170. (setq mode-name
  6171. (list "Org-Agenda"
  6172. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6173. " "
  6174. '(:eval (org-agenda-span-name org-agenda-current-span))
  6175. (if org-agenda-follow-mode " Follow" "")
  6176. (if org-agenda-entry-text-mode " ETxt" "")
  6177. (if org-agenda-include-diary " Diary" "")
  6178. (if org-agenda-include-deadlines " Ddl" "")
  6179. (if org-agenda-use-time-grid " Grid" "")
  6180. (if (and (boundp 'org-habit-show-habits)
  6181. org-habit-show-habits) " Habit" "")
  6182. (cond
  6183. ((consp org-agenda-show-log) " LogAll")
  6184. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6185. (org-agenda-show-log " Log")
  6186. (t ""))
  6187. (if (or org-agenda-filter (get 'org-agenda-filter
  6188. :preset-filter))
  6189. (concat " {" (mapconcat
  6190. 'identity
  6191. (append (get 'org-agenda-filter
  6192. :preset-filter)
  6193. org-agenda-filter) "") "}")
  6194. "")
  6195. (if org-agenda-archives-mode
  6196. (if (eq org-agenda-archives-mode t)
  6197. " Archives"
  6198. (format " :%s:" org-archive-tag))
  6199. "")
  6200. (if org-agenda-clockreport-mode
  6201. (if (eq org-agenda-clockreport-mode 'with-filter)
  6202. " Clock{}" " Clock")
  6203. "")))
  6204. (force-mode-line-update))
  6205. (defun org-agenda-post-command-hook ()
  6206. (setq org-agenda-type
  6207. (or (get-text-property (point) 'org-agenda-type)
  6208. (get-text-property (max (point-min) (1- (point)))
  6209. 'org-agenda-type))))
  6210. (defun org-agenda-next-line ()
  6211. "Move cursor to the next line, and show if follow mode is active."
  6212. (interactive)
  6213. (call-interactively 'next-line)
  6214. (org-agenda-do-context-action))
  6215. (defun org-agenda-previous-line ()
  6216. "Move cursor to the previous line, and show if follow-mode is active."
  6217. (interactive)
  6218. (call-interactively 'previous-line)
  6219. (org-agenda-do-context-action))
  6220. (defun org-agenda-do-context-action ()
  6221. "Show outline path and, maybe, follow mode window."
  6222. (let ((m (org-get-at-bol 'org-marker)))
  6223. (if (and org-agenda-follow-mode m)
  6224. (org-agenda-show))
  6225. (if (and m org-agenda-show-outline-path)
  6226. (org-with-point-at m
  6227. (org-display-outline-path t)))))
  6228. (defun org-agenda-show-priority ()
  6229. "Show the priority of the current item.
  6230. This priority is composed of the main priority given with the [#A] cookies,
  6231. and by additional input from the age of a schedules or deadline entry."
  6232. (interactive)
  6233. (let* ((pri (org-get-at-bol 'priority)))
  6234. (message "Priority is %d" (if pri pri -1000))))
  6235. (defun org-agenda-show-tags ()
  6236. "Show the tags applicable to the current item."
  6237. (interactive)
  6238. (let* ((tags (org-get-at-bol 'tags)))
  6239. (if tags
  6240. (message "Tags are :%s:"
  6241. (org-no-properties (mapconcat 'identity tags ":")))
  6242. (message "No tags associated with this line"))))
  6243. (defun org-agenda-goto (&optional highlight)
  6244. "Go to the Org-mode file which contains the item at point."
  6245. (interactive)
  6246. (let* ((marker (or (org-get-at-bol 'org-marker)
  6247. (org-agenda-error)))
  6248. (buffer (marker-buffer marker))
  6249. (pos (marker-position marker)))
  6250. (switch-to-buffer-other-window buffer)
  6251. (widen)
  6252. (push-mark)
  6253. (goto-char pos)
  6254. (when (org-mode-p)
  6255. (org-show-context 'agenda)
  6256. (save-excursion
  6257. (and (outline-next-heading)
  6258. (org-flag-heading nil)))) ; show the next heading
  6259. (when (outline-invisible-p)
  6260. (show-entry)) ; display invisible text
  6261. (recenter (/ (window-height) 2))
  6262. (run-hooks 'org-agenda-after-show-hook)
  6263. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6264. (defvar org-agenda-after-show-hook nil
  6265. "Normal hook run after an item has been shown from the agenda.
  6266. Point is in the buffer where the item originated.")
  6267. (defun org-agenda-kill ()
  6268. "Kill the entry or subtree belonging to the current agenda entry."
  6269. (interactive)
  6270. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6271. (let* ((marker (or (org-get-at-bol 'org-marker)
  6272. (org-agenda-error)))
  6273. (buffer (marker-buffer marker))
  6274. (pos (marker-position marker))
  6275. (type (org-get-at-bol 'type))
  6276. dbeg dend (n 0) conf)
  6277. (org-with-remote-undo buffer
  6278. (with-current-buffer buffer
  6279. (save-excursion
  6280. (goto-char pos)
  6281. (if (and (org-mode-p) (not (member type '("sexp"))))
  6282. (setq dbeg (progn (org-back-to-heading t) (point))
  6283. dend (org-end-of-subtree t t))
  6284. (setq dbeg (point-at-bol)
  6285. dend (min (point-max) (1+ (point-at-eol)))))
  6286. (goto-char dbeg)
  6287. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6288. (setq conf (or (eq t org-agenda-confirm-kill)
  6289. (and (numberp org-agenda-confirm-kill)
  6290. (> n org-agenda-confirm-kill))))
  6291. (and conf
  6292. (not (y-or-n-p
  6293. (format "Delete entry with %d lines in buffer \"%s\"? "
  6294. n (buffer-name buffer))))
  6295. (error "Abort"))
  6296. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6297. (with-current-buffer buffer (delete-region dbeg dend))
  6298. (message "Agenda item and source killed"))))
  6299. (defvar org-archive-default-command)
  6300. (defun org-agenda-archive-default ()
  6301. "Archive the entry or subtree belonging to the current agenda entry."
  6302. (interactive)
  6303. (require 'org-archive)
  6304. (org-agenda-archive-with org-archive-default-command))
  6305. (defun org-agenda-archive-default-with-confirmation ()
  6306. "Archive the entry or subtree belonging to the current agenda entry."
  6307. (interactive)
  6308. (require 'org-archive)
  6309. (org-agenda-archive-with org-archive-default-command 'confirm))
  6310. (defun org-agenda-archive ()
  6311. "Archive the entry or subtree belonging to the current agenda entry."
  6312. (interactive)
  6313. (org-agenda-archive-with 'org-archive-subtree))
  6314. (defun org-agenda-archive-to-archive-sibling ()
  6315. "Move the entry to the archive sibling."
  6316. (interactive)
  6317. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6318. (defun org-agenda-archive-with (cmd &optional confirm)
  6319. "Move the entry to the archive sibling."
  6320. (interactive)
  6321. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6322. (let* ((marker (or (org-get-at-bol 'org-marker)
  6323. (org-agenda-error)))
  6324. (buffer (marker-buffer marker))
  6325. (pos (marker-position marker)))
  6326. (org-with-remote-undo buffer
  6327. (with-current-buffer buffer
  6328. (if (org-mode-p)
  6329. (if (and confirm
  6330. (not (y-or-n-p "Archive this subtree or entry? ")))
  6331. (error "Abort")
  6332. (save-excursion
  6333. (goto-char pos)
  6334. (org-remove-subtree-entries-from-agenda)
  6335. (org-back-to-heading t)
  6336. (funcall cmd)))
  6337. (error "Archiving works only in Org-mode files"))))))
  6338. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6339. "Remove all lines in the agenda that correspond to a given subtree.
  6340. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6341. If this information is not given, the function uses the tree at point."
  6342. (let ((buf (or buf (current-buffer))) m p)
  6343. (save-excursion
  6344. (unless (and beg end)
  6345. (org-back-to-heading t)
  6346. (setq beg (point))
  6347. (org-end-of-subtree t)
  6348. (setq end (point)))
  6349. (set-buffer (get-buffer org-agenda-buffer-name))
  6350. (save-excursion
  6351. (goto-char (point-max))
  6352. (beginning-of-line 1)
  6353. (while (not (bobp))
  6354. (when (and (setq m (org-get-at-bol 'org-marker))
  6355. (equal buf (marker-buffer m))
  6356. (setq p (marker-position m))
  6357. (>= p beg)
  6358. (< p end))
  6359. (let ((inhibit-read-only t))
  6360. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6361. (beginning-of-line 0))))))
  6362. (defun org-agenda-refile (&optional goto rfloc no-update)
  6363. "Refile the item at point."
  6364. (interactive "P")
  6365. (if (equal goto '(16))
  6366. (org-refile-goto-last-stored)
  6367. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6368. (org-agenda-error)))
  6369. (buffer (marker-buffer marker))
  6370. (pos (marker-position marker))
  6371. (rfloc (or rfloc
  6372. (org-refile-get-location
  6373. (if goto "Goto" "Refile to") buffer
  6374. org-refile-allow-creating-parent-nodes))))
  6375. (with-current-buffer buffer
  6376. (save-excursion
  6377. (save-restriction
  6378. (widen)
  6379. (goto-char marker)
  6380. (org-remove-subtree-entries-from-agenda)
  6381. (org-refile goto buffer rfloc)))))
  6382. (unless no-update (org-agenda-redo))))
  6383. (defun org-agenda-open-link (&optional arg)
  6384. "Follow the link in the current line, if any.
  6385. This looks for a link in the displayed line in the agenda. It also looks
  6386. at the text of the entry itself."
  6387. (interactive "P")
  6388. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6389. (org-get-at-bol 'org-marker)))
  6390. (buffer (and marker (marker-buffer marker)))
  6391. (prefix (buffer-substring
  6392. (point-at-bol) (point-at-eol))))
  6393. (cond
  6394. (buffer
  6395. (with-current-buffer buffer
  6396. (save-excursion
  6397. (save-restriction
  6398. (widen)
  6399. (goto-char marker)
  6400. (org-offer-links-in-entry arg prefix)))))
  6401. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6402. (save-excursion
  6403. (beginning-of-line 1)
  6404. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6405. (org-open-link-from-string (match-string 1)))
  6406. (t (error "No link to open here")))))
  6407. (defun org-agenda-copy-local-variable (var)
  6408. "Get a variable from a referenced buffer and install it here."
  6409. (let ((m (org-get-at-bol 'org-marker)))
  6410. (when (and m (buffer-live-p (marker-buffer m)))
  6411. (org-set-local var (with-current-buffer (marker-buffer m)
  6412. (symbol-value var))))))
  6413. (defun org-agenda-switch-to (&optional delete-other-windows)
  6414. "Go to the Org-mode file which contains the item at point."
  6415. (interactive)
  6416. (if (and org-return-follows-link
  6417. (not (org-get-at-bol 'org-marker))
  6418. (org-in-regexp org-bracket-link-regexp))
  6419. (org-open-link-from-string (match-string 0))
  6420. (let* ((marker (or (org-get-at-bol 'org-marker)
  6421. (org-agenda-error)))
  6422. (buffer (marker-buffer marker))
  6423. (pos (marker-position marker)))
  6424. (switch-to-buffer buffer)
  6425. (and delete-other-windows (delete-other-windows))
  6426. (widen)
  6427. (goto-char pos)
  6428. (when (org-mode-p)
  6429. (org-show-context 'agenda)
  6430. (save-excursion
  6431. (and (outline-next-heading)
  6432. (org-flag-heading nil))) ; show the next heading
  6433. (when (outline-invisible-p)
  6434. (show-entry)))))) ; display invisible text
  6435. (defun org-agenda-goto-mouse (ev)
  6436. "Go to the Org-mode file which contains the item at the mouse click."
  6437. (interactive "e")
  6438. (mouse-set-point ev)
  6439. (org-agenda-goto))
  6440. (defun org-agenda-show (&optional full-entry)
  6441. "Display the Org-mode file which contains the item at point.
  6442. With prefix argument FULL-ENTRY, make the entire entry visible
  6443. if it was hidden in the outline."
  6444. (interactive "P")
  6445. (let ((win (selected-window)))
  6446. (if full-entry
  6447. (let ((org-show-entry-below t))
  6448. (org-agenda-goto t))
  6449. (org-agenda-goto t))
  6450. (select-window win)))
  6451. (defvar org-agenda-show-window nil)
  6452. (defun org-agenda-show-and-scroll-up ()
  6453. "Display the Org-mode file which contains the item at point.
  6454. When called repeatedly, scroll the window that is displaying the buffer."
  6455. (interactive)
  6456. (let ((win (selected-window)))
  6457. (if (and (window-live-p org-agenda-show-window)
  6458. (eq this-command last-command))
  6459. (progn
  6460. (select-window org-agenda-show-window)
  6461. (ignore-errors (scroll-up)))
  6462. (org-agenda-goto t)
  6463. (show-subtree)
  6464. (setq org-agenda-show-window (selected-window)))
  6465. (select-window win)))
  6466. (defun org-agenda-show-scroll-down ()
  6467. "Scroll down the window showing the agenda."
  6468. (interactive)
  6469. (let ((win (selected-window)))
  6470. (when (window-live-p org-agenda-show-window)
  6471. (select-window org-agenda-show-window)
  6472. (ignore-errors (scroll-down))
  6473. (select-window win))))
  6474. (defun org-agenda-show-1 (&optional more)
  6475. "Display the Org-mode file which contains the item at point.
  6476. The prefix arg selects the amount of information to display:
  6477. 0 hide the subtree
  6478. 1 just show the entry according to defaults.
  6479. 2 show the children view
  6480. 3 show the subtree view
  6481. 4 show the entire subtree and any LOGBOOK drawers
  6482. 5 show the entire subtree and any drawers
  6483. With prefix argument FULL-ENTRY, make the entire entry visible
  6484. if it was hidden in the outline."
  6485. (interactive "p")
  6486. (let ((win (selected-window)))
  6487. (org-agenda-goto t)
  6488. (org-recenter-heading 1)
  6489. (cond
  6490. ((= more 0)
  6491. (hide-subtree)
  6492. (save-excursion
  6493. (org-back-to-heading)
  6494. (run-hook-with-args 'org-cycle-hook 'folded))
  6495. (message "Remote: FOLDED"))
  6496. ((and (called-interactively-p 'any) (= more 1))
  6497. (message "Remote: show with default settings"))
  6498. ((= more 2)
  6499. (show-entry)
  6500. (show-children)
  6501. (save-excursion
  6502. (org-back-to-heading)
  6503. (run-hook-with-args 'org-cycle-hook 'children))
  6504. (message "Remote: CHILDREN"))
  6505. ((= more 3)
  6506. (show-subtree)
  6507. (save-excursion
  6508. (org-back-to-heading)
  6509. (run-hook-with-args 'org-cycle-hook 'subtree))
  6510. (message "Remote: SUBTREE"))
  6511. ((= more 4)
  6512. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6513. (org-drawer-regexp
  6514. (concat "^[ \t]*:\\("
  6515. (mapconcat 'regexp-quote org-drawers "\\|")
  6516. "\\):[ \t]*$")))
  6517. (show-subtree)
  6518. (save-excursion
  6519. (org-back-to-heading)
  6520. (org-cycle-hide-drawers 'subtree)))
  6521. (message "Remote: SUBTREE AND LOGBOOK"))
  6522. ((> more 4)
  6523. (show-subtree)
  6524. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6525. (select-window win)))
  6526. (defun org-recenter-heading (n)
  6527. (save-excursion
  6528. (org-back-to-heading)
  6529. (recenter n)))
  6530. (defvar org-agenda-cycle-counter nil)
  6531. (defun org-agenda-cycle-show (&optional n)
  6532. "Show the current entry in another window, with default settings.
  6533. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6534. When use repeatedly in immediate succession, the remote entry will cycle
  6535. through visibility
  6536. children -> subtree -> folded
  6537. When called with a numeric prefix arg, that arg will be passed through to
  6538. `org-agenda-show-1'. For the interpretation of that argument, see the
  6539. docstring of `org-agenda-show-1'."
  6540. (interactive "P")
  6541. (if (integerp n)
  6542. (setq org-agenda-cycle-counter n)
  6543. (if (not (eq last-command this-command))
  6544. (setq org-agenda-cycle-counter 1)
  6545. (if (equal org-agenda-cycle-counter 0)
  6546. (setq org-agenda-cycle-counter 2)
  6547. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6548. (if (> org-agenda-cycle-counter 3)
  6549. (setq org-agenda-cycle-counter 0)))))
  6550. (org-agenda-show-1 org-agenda-cycle-counter))
  6551. (defun org-agenda-recenter (arg)
  6552. "Display the Org-mode file which contains the item at point and recenter."
  6553. (interactive "P")
  6554. (let ((win (selected-window)))
  6555. (org-agenda-goto t)
  6556. (recenter arg)
  6557. (select-window win)))
  6558. (defun org-agenda-show-mouse (ev)
  6559. "Display the Org-mode file which contains the item at the mouse click."
  6560. (interactive "e")
  6561. (mouse-set-point ev)
  6562. (org-agenda-show))
  6563. (defun org-agenda-check-no-diary ()
  6564. "Check if the entry is a diary link and abort if yes."
  6565. (if (org-get-at-bol 'org-agenda-diary-link)
  6566. (org-agenda-error)))
  6567. (defun org-agenda-error ()
  6568. (error "Command not allowed in this line"))
  6569. (defun org-agenda-tree-to-indirect-buffer ()
  6570. "Show the subtree corresponding to the current entry in an indirect buffer.
  6571. This calls the command `org-tree-to-indirect-buffer' from the original
  6572. Org-mode buffer.
  6573. With numerical prefix arg ARG, go up to this level and then take that tree.
  6574. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6575. use the dedicated frame)."
  6576. (interactive)
  6577. (org-agenda-check-no-diary)
  6578. (let* ((marker (or (org-get-at-bol 'org-marker)
  6579. (org-agenda-error)))
  6580. (buffer (marker-buffer marker))
  6581. (pos (marker-position marker)))
  6582. (with-current-buffer buffer
  6583. (save-excursion
  6584. (goto-char pos)
  6585. (call-interactively 'org-tree-to-indirect-buffer)))))
  6586. (defvar org-last-heading-marker (make-marker)
  6587. "Marker pointing to the headline that last changed its TODO state
  6588. by a remote command from the agenda.")
  6589. (defun org-agenda-todo-nextset ()
  6590. "Switch TODO entry to next sequence."
  6591. (interactive)
  6592. (org-agenda-todo 'nextset))
  6593. (defun org-agenda-todo-previousset ()
  6594. "Switch TODO entry to previous sequence."
  6595. (interactive)
  6596. (org-agenda-todo 'previousset))
  6597. (defun org-agenda-todo (&optional arg)
  6598. "Cycle TODO state of line at point, also in Org-mode file.
  6599. This changes the line at point, all other lines in the agenda referring to
  6600. the same tree node, and the headline of the tree node in the Org-mode file."
  6601. (interactive "P")
  6602. (org-agenda-check-no-diary)
  6603. (let* ((col (current-column))
  6604. (marker (or (org-get-at-bol 'org-marker)
  6605. (org-agenda-error)))
  6606. (buffer (marker-buffer marker))
  6607. (pos (marker-position marker))
  6608. (hdmarker (org-get-at-bol 'org-hd-marker))
  6609. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6610. (inhibit-read-only t)
  6611. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6612. (org-with-remote-undo buffer
  6613. (with-current-buffer buffer
  6614. (widen)
  6615. (goto-char pos)
  6616. (org-show-context 'agenda)
  6617. (save-excursion
  6618. (and (outline-next-heading)
  6619. (org-flag-heading nil))) ; show the next heading
  6620. (let ((current-prefix-arg arg))
  6621. (call-interactively 'org-todo))
  6622. (and (bolp) (forward-char 1))
  6623. (setq newhead (org-get-heading))
  6624. (when (and (org-bound-and-true-p
  6625. org-agenda-headline-snapshot-before-repeat)
  6626. (not (equal org-agenda-headline-snapshot-before-repeat
  6627. newhead))
  6628. todayp)
  6629. (setq newhead org-agenda-headline-snapshot-before-repeat
  6630. just-one t))
  6631. (save-excursion
  6632. (org-back-to-heading)
  6633. (move-marker org-last-heading-marker (point))))
  6634. (beginning-of-line 1)
  6635. (save-excursion
  6636. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6637. (org-move-to-column col))))
  6638. (defun org-agenda-add-note (&optional arg)
  6639. "Add a time-stamped note to the entry at point."
  6640. (interactive "P")
  6641. (org-agenda-check-no-diary)
  6642. (let* ((marker (or (org-get-at-bol 'org-marker)
  6643. (org-agenda-error)))
  6644. (buffer (marker-buffer marker))
  6645. (pos (marker-position marker))
  6646. (hdmarker (org-get-at-bol 'org-hd-marker))
  6647. (inhibit-read-only t))
  6648. (with-current-buffer buffer
  6649. (widen)
  6650. (goto-char pos)
  6651. (org-show-context 'agenda)
  6652. (save-excursion
  6653. (and (outline-next-heading)
  6654. (org-flag-heading nil))) ; show the next heading
  6655. (org-add-note))))
  6656. (defun org-agenda-change-all-lines (newhead hdmarker
  6657. &optional fixface just-this)
  6658. "Change all lines in the agenda buffer which match HDMARKER.
  6659. The new content of the line will be NEWHEAD (as modified by
  6660. `org-format-agenda-item'). HDMARKER is checked with
  6661. `equal' against all `org-hd-marker' text properties in the file.
  6662. If FIXFACE is non-nil, the face of each item is modified according to
  6663. the new TODO state.
  6664. If JUST-THIS is non-nil, change just the current line, not all.
  6665. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6666. (let* ((inhibit-read-only t)
  6667. (line (org-current-line))
  6668. (thetags (with-current-buffer (marker-buffer hdmarker)
  6669. (save-excursion (save-restriction (widen)
  6670. (goto-char hdmarker)
  6671. (org-get-tags-at)))))
  6672. props m pl undone-face done-face finish new dotime cat tags)
  6673. (save-excursion
  6674. (goto-char (point-max))
  6675. (beginning-of-line 1)
  6676. (while (not finish)
  6677. (setq finish (bobp))
  6678. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6679. (or (not just-this) (= (org-current-line) line))
  6680. (equal m hdmarker))
  6681. (setq props (text-properties-at (point))
  6682. dotime (org-get-at-bol 'dotime)
  6683. cat (org-get-at-bol 'org-category)
  6684. tags thetags
  6685. new (org-format-agenda-item (org-get-at-bol 'extra)
  6686. newhead cat tags dotime)
  6687. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6688. undone-face (org-get-at-bol 'undone-face)
  6689. done-face (org-get-at-bol 'done-face))
  6690. (beginning-of-line 1)
  6691. (cond
  6692. ((equal new "")
  6693. (and (looking-at ".*\n?") (replace-match "")))
  6694. ((looking-at ".*")
  6695. (replace-match new t t)
  6696. (beginning-of-line 1)
  6697. (add-text-properties (point-at-bol) (point-at-eol) props)
  6698. (when fixface
  6699. (add-text-properties
  6700. (point-at-bol) (point-at-eol)
  6701. (list 'face
  6702. (if org-last-todo-state-is-todo
  6703. undone-face done-face))))
  6704. (org-agenda-highlight-todo 'line)
  6705. (beginning-of-line 1))
  6706. (t (error "Line update did not work"))))
  6707. (beginning-of-line 0)))
  6708. (org-finalize-agenda)))
  6709. (defun org-agenda-align-tags (&optional line)
  6710. "Align all tags in agenda items to `org-agenda-tags-column'."
  6711. (let ((inhibit-read-only t) l c)
  6712. (save-excursion
  6713. (goto-char (if line (point-at-bol) (point-min)))
  6714. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6715. (if line (point-at-eol) nil) t)
  6716. (add-text-properties
  6717. (match-beginning 2) (match-end 2)
  6718. (list 'face (delq nil (let ((prop (get-text-property
  6719. (match-beginning 2) 'face)))
  6720. (or (listp prop) (setq prop (list prop)))
  6721. (if (memq 'org-tag prop)
  6722. prop
  6723. (cons 'org-tag prop))))))
  6724. (setq l (- (match-end 2) (match-beginning 2))
  6725. c (if (< org-agenda-tags-column 0)
  6726. (- (abs org-agenda-tags-column) l)
  6727. org-agenda-tags-column))
  6728. (delete-region (match-beginning 1) (match-end 1))
  6729. (goto-char (match-beginning 1))
  6730. (insert (org-add-props
  6731. (make-string (max 1 (- c (current-column))) ?\ )
  6732. (plist-put (copy-sequence (text-properties-at (point)))
  6733. 'face nil))))
  6734. (goto-char (point-min))
  6735. (org-font-lock-add-tag-faces (point-max)))))
  6736. (defun org-agenda-priority-up ()
  6737. "Increase the priority of line at point, also in Org-mode file."
  6738. (interactive)
  6739. (org-agenda-priority 'up))
  6740. (defun org-agenda-priority-down ()
  6741. "Decrease the priority of line at point, also in Org-mode file."
  6742. (interactive)
  6743. (org-agenda-priority 'down))
  6744. (defun org-agenda-priority (&optional force-direction)
  6745. "Set the priority of line at point, also in Org-mode file.
  6746. This changes the line at point, all other lines in the agenda referring to
  6747. the same tree node, and the headline of the tree node in the Org-mode file."
  6748. (interactive)
  6749. (unless org-enable-priority-commands
  6750. (error "Priority commands are disabled"))
  6751. (org-agenda-check-no-diary)
  6752. (let* ((marker (or (org-get-at-bol 'org-marker)
  6753. (org-agenda-error)))
  6754. (hdmarker (org-get-at-bol 'org-hd-marker))
  6755. (buffer (marker-buffer hdmarker))
  6756. (pos (marker-position hdmarker))
  6757. (inhibit-read-only t)
  6758. newhead)
  6759. (org-with-remote-undo buffer
  6760. (with-current-buffer buffer
  6761. (widen)
  6762. (goto-char pos)
  6763. (org-show-context 'agenda)
  6764. (save-excursion
  6765. (and (outline-next-heading)
  6766. (org-flag-heading nil))) ; show the next heading
  6767. (funcall 'org-priority force-direction)
  6768. (end-of-line 1)
  6769. (setq newhead (org-get-heading)))
  6770. (org-agenda-change-all-lines newhead hdmarker)
  6771. (beginning-of-line 1))))
  6772. ;; FIXME: should fix the tags property of the agenda line.
  6773. (defun org-agenda-set-tags (&optional tag onoff)
  6774. "Set tags for the current headline."
  6775. (interactive)
  6776. (org-agenda-check-no-diary)
  6777. (if (and (org-region-active-p) (called-interactively-p 'any))
  6778. (call-interactively 'org-change-tag-in-region)
  6779. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6780. (org-agenda-error)))
  6781. (buffer (marker-buffer hdmarker))
  6782. (pos (marker-position hdmarker))
  6783. (inhibit-read-only t)
  6784. newhead)
  6785. (org-with-remote-undo buffer
  6786. (with-current-buffer buffer
  6787. (widen)
  6788. (goto-char pos)
  6789. (save-excursion
  6790. (org-show-context 'agenda))
  6791. (save-excursion
  6792. (and (outline-next-heading)
  6793. (org-flag-heading nil))) ; show the next heading
  6794. (goto-char pos)
  6795. (if tag
  6796. (org-toggle-tag tag onoff)
  6797. (call-interactively 'org-set-tags))
  6798. (end-of-line 1)
  6799. (setq newhead (org-get-heading)))
  6800. (org-agenda-change-all-lines newhead hdmarker)
  6801. (beginning-of-line 1)))))
  6802. (defun org-agenda-set-property ()
  6803. "Set a property for the current headline."
  6804. (interactive)
  6805. (org-agenda-check-no-diary)
  6806. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6807. (org-agenda-error)))
  6808. (buffer (marker-buffer hdmarker))
  6809. (pos (marker-position hdmarker))
  6810. (inhibit-read-only t)
  6811. newhead)
  6812. (org-with-remote-undo buffer
  6813. (with-current-buffer buffer
  6814. (widen)
  6815. (goto-char pos)
  6816. (save-excursion
  6817. (org-show-context 'agenda))
  6818. (save-excursion
  6819. (and (outline-next-heading)
  6820. (org-flag-heading nil))) ; show the next heading
  6821. (goto-char pos)
  6822. (call-interactively 'org-set-property)))))
  6823. (defun org-agenda-set-effort ()
  6824. "Set the effort property for the current headline."
  6825. (interactive)
  6826. (org-agenda-check-no-diary)
  6827. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6828. (org-agenda-error)))
  6829. (buffer (marker-buffer hdmarker))
  6830. (pos (marker-position hdmarker))
  6831. (inhibit-read-only t)
  6832. newhead)
  6833. (org-with-remote-undo buffer
  6834. (with-current-buffer buffer
  6835. (widen)
  6836. (goto-char pos)
  6837. (save-excursion
  6838. (org-show-context 'agenda))
  6839. (save-excursion
  6840. (and (outline-next-heading)
  6841. (org-flag-heading nil))) ; show the next heading
  6842. (goto-char pos)
  6843. (call-interactively 'org-set-effort)
  6844. (end-of-line 1)))))
  6845. (defun org-agenda-toggle-archive-tag ()
  6846. "Toggle the archive tag for the current entry."
  6847. (interactive)
  6848. (org-agenda-check-no-diary)
  6849. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6850. (org-agenda-error)))
  6851. (buffer (marker-buffer hdmarker))
  6852. (pos (marker-position hdmarker))
  6853. (inhibit-read-only t)
  6854. newhead)
  6855. (org-with-remote-undo buffer
  6856. (with-current-buffer buffer
  6857. (widen)
  6858. (goto-char pos)
  6859. (org-show-context 'agenda)
  6860. (save-excursion
  6861. (and (outline-next-heading)
  6862. (org-flag-heading nil))) ; show the next heading
  6863. (call-interactively 'org-toggle-archive-tag)
  6864. (end-of-line 1)
  6865. (setq newhead (org-get-heading)))
  6866. (org-agenda-change-all-lines newhead hdmarker)
  6867. (beginning-of-line 1))))
  6868. (defun org-agenda-do-date-later (arg)
  6869. (interactive "P")
  6870. (cond
  6871. ((or (equal arg '(16))
  6872. (memq last-command
  6873. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6874. (setq this-command 'org-agenda-date-later-minutes)
  6875. (org-agenda-date-later-minutes 1))
  6876. ((or (equal arg '(4))
  6877. (memq last-command
  6878. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6879. (setq this-command 'org-agenda-date-later-hours)
  6880. (org-agenda-date-later-hours 1))
  6881. (t
  6882. (org-agenda-date-later (prefix-numeric-value arg)))))
  6883. (defun org-agenda-do-date-earlier (arg)
  6884. (interactive "P")
  6885. (cond
  6886. ((or (equal arg '(16))
  6887. (memq last-command
  6888. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6889. (setq this-command 'org-agenda-date-earlier-minutes)
  6890. (org-agenda-date-earlier-minutes 1))
  6891. ((or (equal arg '(4))
  6892. (memq last-command
  6893. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6894. (setq this-command 'org-agenda-date-earlier-hours)
  6895. (org-agenda-date-earlier-hours 1))
  6896. (t
  6897. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6898. (defun org-agenda-date-later (arg &optional what)
  6899. "Change the date of this item to ARG day(s) later."
  6900. (interactive "p")
  6901. (org-agenda-check-type t 'agenda 'timeline)
  6902. (org-agenda-check-no-diary)
  6903. (let* ((marker (or (org-get-at-bol 'org-marker)
  6904. (org-agenda-error)))
  6905. (buffer (marker-buffer marker))
  6906. (pos (marker-position marker)))
  6907. (org-with-remote-undo buffer
  6908. (with-current-buffer buffer
  6909. (widen)
  6910. (goto-char pos)
  6911. (if (not (org-at-timestamp-p))
  6912. (error "Cannot find time stamp"))
  6913. (org-timestamp-change arg (or what 'day)))
  6914. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6915. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6916. (defun org-agenda-date-earlier (arg &optional what)
  6917. "Change the date of this item to ARG day(s) earlier."
  6918. (interactive "p")
  6919. (org-agenda-date-later (- arg) what))
  6920. (defun org-agenda-date-later-minutes (arg)
  6921. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6922. (interactive "p")
  6923. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6924. (org-agenda-date-later arg 'minute))
  6925. (defun org-agenda-date-earlier-minutes (arg)
  6926. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6927. (interactive "p")
  6928. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6929. (org-agenda-date-earlier arg 'minute))
  6930. (defun org-agenda-date-later-hours (arg)
  6931. "Change the time of this item, in hour steps."
  6932. (interactive "p")
  6933. (org-agenda-date-later arg 'hour))
  6934. (defun org-agenda-date-earlier-hours (arg)
  6935. "Change the time of this item, in hour steps."
  6936. (interactive "p")
  6937. (org-agenda-date-earlier arg 'hour))
  6938. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6939. "Show new date stamp via text properties."
  6940. ;; We use text properties to make this undoable
  6941. (let ((inhibit-read-only t)
  6942. (buffer-invisibility-spec))
  6943. (setq stamp (concat " " prefix " => " stamp))
  6944. (save-excursion
  6945. (goto-char (point-max))
  6946. (while (not (bobp))
  6947. (when (equal marker (org-get-at-bol 'org-marker))
  6948. (org-move-to-column (- (window-width) (length stamp)) t)
  6949. (org-agenda-fix-tags-filter-overlays-at (point))
  6950. (if (featurep 'xemacs)
  6951. ;; Use `duplicable' property to trigger undo recording
  6952. (let ((ex (make-extent nil nil))
  6953. (gl (make-glyph stamp)))
  6954. (set-glyph-face gl 'secondary-selection)
  6955. (set-extent-properties
  6956. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6957. (insert-extent ex (1- (point)) (point-at-eol)))
  6958. (add-text-properties
  6959. (1- (point)) (point-at-eol)
  6960. (list 'display (org-add-props stamp nil
  6961. 'face 'secondary-selection))))
  6962. (beginning-of-line 1))
  6963. (beginning-of-line 0)))))
  6964. (defun org-agenda-date-prompt (arg)
  6965. "Change the date of this item. Date is prompted for, with default today.
  6966. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6967. be used to request time specification in the time stamp."
  6968. (interactive "P")
  6969. (org-agenda-check-type t 'agenda 'timeline)
  6970. (org-agenda-check-no-diary)
  6971. (let* ((marker (or (org-get-at-bol 'org-marker)
  6972. (org-agenda-error)))
  6973. (buffer (marker-buffer marker))
  6974. (pos (marker-position marker)))
  6975. (org-with-remote-undo buffer
  6976. (with-current-buffer buffer
  6977. (widen)
  6978. (goto-char pos)
  6979. (if (not (org-at-timestamp-p t))
  6980. (error "Cannot find time stamp"))
  6981. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6982. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6983. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6984. (defun org-agenda-schedule (arg &optional time)
  6985. "Schedule the item at point.
  6986. Arg is passed through to `org-schedule'."
  6987. (interactive "P")
  6988. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6989. (org-agenda-check-no-diary)
  6990. (let* ((marker (or (org-get-at-bol 'org-marker)
  6991. (org-agenda-error)))
  6992. (type (marker-insertion-type marker))
  6993. (buffer (marker-buffer marker))
  6994. (pos (marker-position marker))
  6995. (org-insert-labeled-timestamps-at-point nil)
  6996. ts)
  6997. (set-marker-insertion-type marker t)
  6998. (org-with-remote-undo buffer
  6999. (with-current-buffer buffer
  7000. (widen)
  7001. (goto-char pos)
  7002. (setq ts (org-schedule arg time)))
  7003. (org-agenda-show-new-time marker ts "S"))
  7004. (message "Item scheduled for %s" ts)))
  7005. (defun org-agenda-deadline (arg &optional time)
  7006. "Schedule the item at point.
  7007. Arg is passed through to `org-deadline'."
  7008. (interactive "P")
  7009. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7010. (org-agenda-check-no-diary)
  7011. (let* ((marker (or (org-get-at-bol 'org-marker)
  7012. (org-agenda-error)))
  7013. (buffer (marker-buffer marker))
  7014. (pos (marker-position marker))
  7015. (org-insert-labeled-timestamps-at-point nil)
  7016. ts)
  7017. (org-with-remote-undo buffer
  7018. (with-current-buffer buffer
  7019. (widen)
  7020. (goto-char pos)
  7021. (setq ts (org-deadline arg time)))
  7022. (org-agenda-show-new-time marker ts "D"))
  7023. (message "Deadline for this item set to %s" ts)))
  7024. (defun org-agenda-action ()
  7025. "Select entry for agenda action, or execute an agenda action.
  7026. This command prompts for another letter. Valid inputs are:
  7027. m Mark the entry at point for an agenda action
  7028. s Schedule the marked entry to the date at the cursor
  7029. d Set the deadline of the marked entry to the date at the cursor
  7030. r Call `org-remember' with cursor date as the default date
  7031. c Call `org-capture' with cursor date as the default date
  7032. SPC Show marked entry in other window
  7033. TAB Visit marked entry in other window
  7034. The cursor may be at a date in the calendar, or in the Org agenda."
  7035. (interactive)
  7036. (let (ans)
  7037. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7038. (setq ans (read-char-exclusive))
  7039. (cond
  7040. ((equal ans ?m)
  7041. ;; Mark this entry
  7042. (if (eq major-mode 'org-agenda-mode)
  7043. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7044. (org-get-at-bol 'org-marker))))
  7045. (if m
  7046. (progn
  7047. (move-marker org-agenda-action-marker
  7048. (marker-position m) (marker-buffer m))
  7049. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7050. (error "Don't know which entry to mark")))
  7051. (error "This command works only in the agenda")))
  7052. ((equal ans ?s)
  7053. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7054. ((equal ans ?d)
  7055. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7056. ((equal ans ?r)
  7057. (org-agenda-do-action '(org-remember) t))
  7058. ((equal ans ?c)
  7059. (org-agenda-do-action '(org-capture) t))
  7060. ((equal ans ?\ )
  7061. (let ((cw (selected-window)))
  7062. (org-switch-to-buffer-other-window
  7063. (marker-buffer org-agenda-action-marker))
  7064. (goto-char org-agenda-action-marker)
  7065. (org-show-context 'agenda)
  7066. (select-window cw)))
  7067. ((equal ans ?\C-i)
  7068. (org-switch-to-buffer-other-window
  7069. (marker-buffer org-agenda-action-marker))
  7070. (goto-char org-agenda-action-marker)
  7071. (org-show-context 'agenda))
  7072. (t (error "Invalid agenda action %c" ans)))))
  7073. (defun org-agenda-do-action (form &optional current-buffer)
  7074. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7075. (let ((org-overriding-default-time (org-get-cursor-date)))
  7076. (if current-buffer
  7077. (eval form)
  7078. (if (not (marker-buffer org-agenda-action-marker))
  7079. (error "No entry has been selected for agenda action")
  7080. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7081. (save-excursion
  7082. (save-restriction
  7083. (widen)
  7084. (goto-char org-agenda-action-marker)
  7085. (eval form))))))))
  7086. (defun org-agenda-clock-in (&optional arg)
  7087. "Start the clock on the currently selected item."
  7088. (interactive "P")
  7089. (org-agenda-check-no-diary)
  7090. (if (equal arg '(4))
  7091. (org-clock-in arg)
  7092. (let* ((marker (or (org-get-at-bol 'org-marker)
  7093. (org-agenda-error)))
  7094. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7095. marker))
  7096. (pos (marker-position marker))
  7097. newhead)
  7098. (org-with-remote-undo (marker-buffer marker)
  7099. (with-current-buffer (marker-buffer marker)
  7100. (widen)
  7101. (goto-char pos)
  7102. (org-show-context 'agenda)
  7103. (org-show-entry)
  7104. (org-cycle-hide-drawers 'children)
  7105. (org-clock-in arg)
  7106. (setq newhead (org-get-heading)))
  7107. (org-agenda-change-all-lines newhead hdmarker)))))
  7108. (defun org-agenda-clock-out ()
  7109. "Stop the currently running clock."
  7110. (interactive)
  7111. (unless (marker-buffer org-clock-marker)
  7112. (error "No running clock"))
  7113. (let ((marker (make-marker)) newhead)
  7114. (org-with-remote-undo (marker-buffer org-clock-marker)
  7115. (with-current-buffer (marker-buffer org-clock-marker)
  7116. (save-excursion
  7117. (save-restriction
  7118. (widen)
  7119. (goto-char org-clock-marker)
  7120. (org-back-to-heading t)
  7121. (move-marker marker (point))
  7122. (org-clock-out)
  7123. (setq newhead (org-get-heading))))))
  7124. (org-agenda-change-all-lines newhead marker)
  7125. (move-marker marker nil)))
  7126. (defun org-agenda-clock-cancel (&optional arg)
  7127. "Cancel the currently running clock."
  7128. (interactive "P")
  7129. (unless (marker-buffer org-clock-marker)
  7130. (error "No running clock"))
  7131. (org-with-remote-undo (marker-buffer org-clock-marker)
  7132. (org-clock-cancel)))
  7133. (defun org-agenda-clock-goto ()
  7134. "Jump to the currently clocked in task within the agenda.
  7135. If the currently clocked in task is not listed in the agenda
  7136. buffer, display it in another window."
  7137. (interactive)
  7138. (let (pos)
  7139. (mapc (lambda (o)
  7140. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7141. (setq pos (overlay-start o))))
  7142. (overlays-in (point-min) (point-max)))
  7143. (cond (pos (goto-char pos))
  7144. ;; If the currently clocked entry is not in the agenda
  7145. ;; buffer, we visit it in another window:
  7146. (org-clock-current-task
  7147. (org-switch-to-buffer-other-window (org-clock-goto)))
  7148. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7149. (defun org-agenda-diary-entry-in-org-file ()
  7150. "Make a diary entry in the file `org-agenda-diary-file'."
  7151. (let (d1 d2 char (text "") dp1 dp2)
  7152. (if (equal (buffer-name) "*Calendar*")
  7153. (setq d1 (calendar-cursor-to-date t)
  7154. d2 (car calendar-mark-ring))
  7155. (setq dp1 (get-text-property (point-at-bol) 'day))
  7156. (unless dp1 (error "No date defined in current line"))
  7157. (setq d1 (calendar-gregorian-from-absolute dp1)
  7158. d2 (and (ignore-errors (mark))
  7159. (save-excursion
  7160. (goto-char (mark))
  7161. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7162. (calendar-gregorian-from-absolute dp2))))
  7163. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7164. (setq char (read-char-exclusive))
  7165. (cond
  7166. ((equal char ?d)
  7167. (setq text (read-string "Day entry: "))
  7168. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7169. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7170. ((equal char ?a)
  7171. (setq d1 (list (car d1) (nth 1 d1)
  7172. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7173. (nth 2 d1))))
  7174. (setq text (read-string "Anniversary (use %d to show years): "))
  7175. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7176. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7177. ((equal char ?b)
  7178. (setq text (read-string "Block entry: "))
  7179. (unless (and d1 d2 (not (equal d1 d2)))
  7180. (error "No block of days selected"))
  7181. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7182. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7183. ((equal char ?j)
  7184. (org-switch-to-buffer-other-window
  7185. (find-file-noselect org-agenda-diary-file))
  7186. (require 'org-datetree)
  7187. (org-datetree-find-date-create d1)
  7188. (org-reveal t))
  7189. (t (error "Invalid selection character `%c'" char)))))
  7190. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7191. "Where in `org-agenda-diary-file' should new entries be added?
  7192. Valid values:
  7193. date-tree in the date tree, as child of the date
  7194. top-level as top-level entries at the end of the file."
  7195. :group 'org-agenda
  7196. :type '(choice
  7197. (const :tag "in a date tree" date-tree)
  7198. (const :tag "as top level at end of file" top-level)))
  7199. (defcustom org-agenda-insert-diary-extract-time nil
  7200. "Non-nil means extract any time specification from the diary entry."
  7201. :group 'org-agenda
  7202. :type 'boolean)
  7203. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7204. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7205. If TEXT is not empty, it will become the headline of the new entry, and
  7206. the resulting entry will not be shown. When TEXT is empty, switch to
  7207. `org-agenda-diary-file' and let the user finish the entry there."
  7208. (let ((cw (current-window-configuration)))
  7209. (org-switch-to-buffer-other-window
  7210. (find-file-noselect org-agenda-diary-file))
  7211. (widen)
  7212. (goto-char (point-min))
  7213. (cond
  7214. ((eq type 'anniversary)
  7215. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7216. (progn
  7217. (or (org-on-heading-p t)
  7218. (progn
  7219. (outline-next-heading)
  7220. (insert "* Anniversaries\n\n")
  7221. (beginning-of-line -1)))))
  7222. (outline-next-heading)
  7223. (org-back-over-empty-lines)
  7224. (backward-char 1)
  7225. (insert "\n")
  7226. (require 'diary-lib)
  7227. (let ((calendar-date-display-form
  7228. (if (if (boundp 'calendar-date-style)
  7229. (eq calendar-date-style 'european)
  7230. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7231. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7232. '(day " " month " " year)
  7233. '(month " " day " " year))))
  7234. (insert (format "%%%%(diary-anniversary %s) %s"
  7235. (calendar-date-string d1 nil t) text))))
  7236. ((eq type 'day)
  7237. (let ((org-prefix-has-time t)
  7238. (org-agenda-time-leading-zero t)
  7239. fmt time time2)
  7240. (if org-agenda-insert-diary-extract-time
  7241. ;; Use org-format-agenda-item to parse text for a time-range and
  7242. ;; remove it. FIXME: This is a hack, we should refactor
  7243. ;; that function to make time extraction available separately
  7244. (setq fmt (org-format-agenda-item nil text nil nil t)
  7245. time (get-text-property 0 'time fmt)
  7246. time2 (if (> (length time) 0)
  7247. ;; split-string removes trailing ...... if
  7248. ;; no end time given. First space
  7249. ;; separates time from date.
  7250. (concat " " (car (split-string time "\\.")))
  7251. nil)
  7252. text (get-text-property 0 'txt fmt)))
  7253. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7254. (org-agenda-insert-diary-as-top-level text)
  7255. (require 'org-datetree)
  7256. (org-datetree-find-date-create d1)
  7257. (org-agenda-insert-diary-make-new-entry text))
  7258. (org-insert-time-stamp (org-time-from-absolute
  7259. (calendar-absolute-from-gregorian d1))
  7260. nil nil nil nil time2))
  7261. (end-of-line 0))
  7262. ((eq type 'block)
  7263. (if (> (calendar-absolute-from-gregorian d1)
  7264. (calendar-absolute-from-gregorian d2))
  7265. (setq d1 (prog1 d2 (setq d2 d1))))
  7266. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7267. (org-agenda-insert-diary-as-top-level text)
  7268. (require 'org-datetree)
  7269. (org-datetree-find-date-create d1)
  7270. (org-agenda-insert-diary-make-new-entry text))
  7271. (org-insert-time-stamp (org-time-from-absolute
  7272. (calendar-absolute-from-gregorian d1)))
  7273. (insert "--")
  7274. (org-insert-time-stamp (org-time-from-absolute
  7275. (calendar-absolute-from-gregorian d2)))
  7276. (end-of-line 0)))
  7277. (if (string-match "\\S-" text)
  7278. (progn
  7279. (set-window-configuration cw)
  7280. (message "%s entry added to %s"
  7281. (capitalize (symbol-name type))
  7282. (abbreviate-file-name org-agenda-diary-file)))
  7283. (org-reveal t)
  7284. (message "Please finish entry here"))))
  7285. (defun org-agenda-insert-diary-as-top-level (text)
  7286. "Make new entry as a top-level entry at the end of the file.
  7287. Add TEXT as headline, and position the cursor in the second line so that
  7288. a timestamp can be added there."
  7289. (widen)
  7290. (goto-char (point-max))
  7291. (or (bolp) (insert "\n"))
  7292. (insert "* " text "\n")
  7293. (if org-adapt-indentation (org-indent-to-column 2)))
  7294. (defun org-agenda-insert-diary-make-new-entry (text)
  7295. "Make new entry as last child of current entry.
  7296. Add TEXT as headline, and position the cursor in the second line so that
  7297. a timestamp can be added there."
  7298. (let ((org-show-following-heading t)
  7299. (org-show-siblings t)
  7300. (org-show-hierarchy-above t)
  7301. (org-show-entry-below t)
  7302. col)
  7303. (outline-next-heading)
  7304. (org-back-over-empty-lines)
  7305. (or (looking-at "[ \t]*$")
  7306. (progn (insert "\n") (backward-char 1)))
  7307. (org-insert-heading nil t)
  7308. (org-do-demote)
  7309. (setq col (current-column))
  7310. (insert text "\n")
  7311. (if org-adapt-indentation (org-indent-to-column col))
  7312. (let ((org-show-following-heading t)
  7313. (org-show-siblings t)
  7314. (org-show-hierarchy-above t)
  7315. (org-show-entry-below t))
  7316. (org-show-context))))
  7317. (defun org-agenda-diary-entry ()
  7318. "Make a diary entry, like the `i' command from the calendar.
  7319. All the standard commands work: block, weekly etc.
  7320. When `org-agenda-diary-file' points to a file,
  7321. `org-agenda-diary-entry-in-org-file' is called instead to create
  7322. entries in that Org-mode file."
  7323. (interactive)
  7324. (org-agenda-check-type t 'agenda 'timeline)
  7325. (if (not (eq org-agenda-diary-file 'diary-file))
  7326. (org-agenda-diary-entry-in-org-file)
  7327. (require 'diary-lib)
  7328. (let* ((char (progn
  7329. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7330. (read-char-exclusive)))
  7331. (cmd (cdr (assoc char
  7332. '((?d . insert-diary-entry)
  7333. (?w . insert-weekly-diary-entry)
  7334. (?m . insert-monthly-diary-entry)
  7335. (?y . insert-yearly-diary-entry)
  7336. (?a . insert-anniversary-diary-entry)
  7337. (?b . insert-block-diary-entry)
  7338. (?c . insert-cyclic-diary-entry)))))
  7339. (oldf (symbol-function 'calendar-cursor-to-date))
  7340. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7341. (point (point))
  7342. (mark (or (mark t) (point))))
  7343. (unless cmd
  7344. (error "No command associated with <%c>" char))
  7345. (unless (and (get-text-property point 'day)
  7346. (or (not (equal ?b char))
  7347. (get-text-property mark 'day)))
  7348. (error "Don't know which date to use for diary entry"))
  7349. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7350. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7351. (let ((calendar-mark-ring
  7352. (list (calendar-gregorian-from-absolute
  7353. (or (get-text-property mark 'day)
  7354. (get-text-property point 'day))))))
  7355. (unwind-protect
  7356. (progn
  7357. (fset 'calendar-cursor-to-date
  7358. (lambda (&optional error dummy)
  7359. (calendar-gregorian-from-absolute
  7360. (get-text-property point 'day))))
  7361. (call-interactively cmd))
  7362. (fset 'calendar-cursor-to-date oldf))))))
  7363. (defun org-agenda-execute-calendar-command (cmd)
  7364. "Execute a calendar command from the agenda, with the date associated to
  7365. the cursor position."
  7366. (org-agenda-check-type t 'agenda 'timeline)
  7367. (require 'diary-lib)
  7368. (unless (get-text-property (point) 'day)
  7369. (error "Don't know which date to use for calendar command"))
  7370. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7371. (point (point))
  7372. (date (calendar-gregorian-from-absolute
  7373. (get-text-property point 'day)))
  7374. ;; the following 2 vars are needed in the calendar
  7375. (displayed-month (car date))
  7376. (displayed-year (nth 2 date)))
  7377. (unwind-protect
  7378. (progn
  7379. (fset 'calendar-cursor-to-date
  7380. (lambda (&optional error dummy)
  7381. (calendar-gregorian-from-absolute
  7382. (get-text-property point 'day))))
  7383. (call-interactively cmd))
  7384. (fset 'calendar-cursor-to-date oldf))))
  7385. (defun org-agenda-phases-of-moon ()
  7386. "Display the phases of the moon for the 3 months around the cursor date."
  7387. (interactive)
  7388. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7389. (defun org-agenda-holidays ()
  7390. "Display the holidays for the 3 months around the cursor date."
  7391. (interactive)
  7392. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7393. (defvar calendar-longitude)
  7394. (defvar calendar-latitude)
  7395. (defvar calendar-location-name)
  7396. (defun org-agenda-sunrise-sunset (arg)
  7397. "Display sunrise and sunset for the cursor date.
  7398. Latitude and longitude can be specified with the variables
  7399. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7400. argument, latitude and longitude will be prompted for."
  7401. (interactive "P")
  7402. (require 'solar)
  7403. (let ((calendar-longitude (if arg nil calendar-longitude))
  7404. (calendar-latitude (if arg nil calendar-latitude))
  7405. (calendar-location-name
  7406. (if arg "the given coordinates" calendar-location-name)))
  7407. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7408. (defun org-agenda-goto-calendar ()
  7409. "Open the Emacs calendar with the date at the cursor."
  7410. (interactive)
  7411. (org-agenda-check-type t 'agenda 'timeline)
  7412. (let* ((day (or (get-text-property (point) 'day)
  7413. (error "Don't know which date to open in calendar")))
  7414. (date (calendar-gregorian-from-absolute day))
  7415. (calendar-move-hook nil)
  7416. (calendar-view-holidays-initially-flag nil)
  7417. (calendar-view-diary-initially-flag nil))
  7418. (calendar)
  7419. (calendar-goto-date date)))
  7420. ;;;###autoload
  7421. (defun org-calendar-goto-agenda ()
  7422. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7423. This is a command that has to be installed in `calendar-mode-map'."
  7424. (interactive)
  7425. (org-agenda-list nil (calendar-absolute-from-gregorian
  7426. (calendar-cursor-to-date))
  7427. nil))
  7428. (defun org-agenda-convert-date ()
  7429. (interactive)
  7430. (org-agenda-check-type t 'agenda 'timeline)
  7431. (let ((day (get-text-property (point) 'day))
  7432. date s)
  7433. (unless day
  7434. (error "Don't know which date to convert"))
  7435. (setq date (calendar-gregorian-from-absolute day))
  7436. (setq s (concat
  7437. "Gregorian: " (calendar-date-string date) "\n"
  7438. "ISO: " (calendar-iso-date-string date) "\n"
  7439. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7440. "Julian: " (calendar-julian-date-string date) "\n"
  7441. "Astron. JD: " (calendar-astro-date-string date)
  7442. " (Julian date number at noon UTC)\n"
  7443. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7444. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7445. "French: " (calendar-french-date-string date) "\n"
  7446. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7447. "Mayan: " (calendar-mayan-date-string date) "\n"
  7448. "Coptic: " (calendar-coptic-date-string date) "\n"
  7449. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7450. "Persian: " (calendar-persian-date-string date) "\n"
  7451. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7452. (with-output-to-temp-buffer "*Dates*"
  7453. (princ s))
  7454. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7455. ;;; Bulk commands
  7456. (defvar org-agenda-bulk-marked-entries nil
  7457. "List of markers that refer to marked entries in the agenda.")
  7458. (defun org-agenda-bulk-marked-p ()
  7459. (eq (get-char-property (point-at-bol) 'type)
  7460. 'org-marked-entry-overlay))
  7461. (defun org-agenda-bulk-mark (&optional arg)
  7462. "Mark the entry at point for future bulk action."
  7463. (interactive "p")
  7464. (dotimes (i (max arg 1))
  7465. (unless (org-get-at-bol 'org-agenda-diary-link)
  7466. (let* ((m (org-get-at-bol 'org-hd-marker))
  7467. ov)
  7468. (unless (org-agenda-bulk-marked-p)
  7469. (unless m (error "Nothing to mark at point"))
  7470. (push m org-agenda-bulk-marked-entries)
  7471. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7472. (org-overlay-display ov "> "
  7473. (org-get-todo-face "TODO")
  7474. 'evaporate)
  7475. (overlay-put ov 'type 'org-marked-entry-overlay))
  7476. (beginning-of-line 2)
  7477. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7478. (beginning-of-line 2))
  7479. (message "%d entries marked for bulk action"
  7480. (length org-agenda-bulk-marked-entries))))))
  7481. (defun org-agenda-bulk-mark-regexp (regexp)
  7482. "Mark entries match REGEXP."
  7483. (interactive "sMark entries matching regexp: ")
  7484. (let (entries-marked)
  7485. (save-excursion
  7486. (goto-char (point-min))
  7487. (goto-char (next-single-property-change (point) 'txt))
  7488. (while (re-search-forward regexp nil t)
  7489. (when (string-match regexp (get-text-property (point) 'txt))
  7490. (setq entries-marked (+ entries-marked 1))
  7491. (call-interactively 'org-agenda-bulk-mark))))
  7492. (if (not entries-marked)
  7493. (message "No entry matching this regexp."))))
  7494. (defun org-agenda-bulk-unmark ()
  7495. "Unmark the entry at point for future bulk action."
  7496. (interactive)
  7497. (when (org-agenda-bulk-marked-p)
  7498. (org-agenda-bulk-remove-overlays
  7499. (point-at-bol) (+ 2 (point-at-bol)))
  7500. (setq org-agenda-bulk-marked-entries
  7501. (delete (org-get-at-bol 'org-hd-marker)
  7502. org-agenda-bulk-marked-entries)))
  7503. (beginning-of-line 2)
  7504. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7505. (beginning-of-line 2))
  7506. (message "%d entries marked for bulk action"
  7507. (length org-agenda-bulk-marked-entries)))
  7508. (defun org-agenda-bulk-toggle ()
  7509. "Toggle marking the entry at point for bulk action."
  7510. (interactive)
  7511. (if (org-agenda-bulk-marked-p)
  7512. (org-agenda-bulk-unmark)
  7513. (org-agenda-bulk-mark)))
  7514. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7515. "Remove the mark overlays between BEG and END in the agenda buffer.
  7516. BEG and END default to the buffer limits.
  7517. This only removes the overlays, it does not remove the markers
  7518. from the list in `org-agenda-bulk-marked-entries'."
  7519. (interactive)
  7520. (mapc (lambda (ov)
  7521. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7522. (delete-overlay ov)))
  7523. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7524. (defun org-agenda-bulk-remove-all-marks ()
  7525. "Remove all marks in the agenda buffer.
  7526. This will remove the markers, and the overlays."
  7527. (interactive)
  7528. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7529. (setq org-agenda-bulk-marked-entries nil)
  7530. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7531. (defun org-agenda-bulk-action (&optional arg)
  7532. "Execute an remote-editing action on all marked entries.
  7533. The prefix arg is passed through to the command if possible."
  7534. (interactive "P")
  7535. ;; Make sure we have markers, and only valid ones
  7536. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7537. (mapc
  7538. (lambda (m)
  7539. (unless (and (markerp m)
  7540. (marker-buffer m)
  7541. (buffer-live-p (marker-buffer m))
  7542. (marker-position m))
  7543. (error "Marker %s for bulk command is invalid" m)))
  7544. org-agenda-bulk-marked-entries)
  7545. ;; Prompt for the bulk command
  7546. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline [f]unction")
  7547. (let* ((action (read-char-exclusive))
  7548. (org-log-refile (if org-log-refile 'time nil))
  7549. (entries (reverse org-agenda-bulk-marked-entries))
  7550. redo-at-end
  7551. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7552. (cond
  7553. ((equal action ?$)
  7554. (setq cmd '(org-agenda-archive)))
  7555. ((equal action ?A)
  7556. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7557. ((member action '(?r ?w))
  7558. (setq rfloc (org-refile-get-location
  7559. "Refile to"
  7560. (marker-buffer (car org-agenda-bulk-marked-entries))
  7561. org-refile-allow-creating-parent-nodes))
  7562. (if (nth 3 rfloc)
  7563. (setcar (nthcdr 3 rfloc)
  7564. (move-marker (make-marker) (nth 3 rfloc)
  7565. (or (get-file-buffer (nth 1 rfloc))
  7566. (find-buffer-visiting (nth 1 rfloc))
  7567. (error "This should not happen")))))
  7568. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7569. redo-at-end t))
  7570. ((equal action ?t)
  7571. (setq state (org-icompleting-read
  7572. "Todo state: "
  7573. (with-current-buffer (marker-buffer (car entries))
  7574. (mapcar 'list org-todo-keywords-1))))
  7575. (setq cmd `(let ((org-inhibit-blocking t)
  7576. (org-inhibit-logging 'note))
  7577. (org-agenda-todo ,state))))
  7578. ((memq action '(?- ?+))
  7579. (setq tag (org-icompleting-read
  7580. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7581. (with-current-buffer (marker-buffer (car entries))
  7582. (delq nil
  7583. (mapcar (lambda (x)
  7584. (if (stringp (car x)) x)) org-tag-alist)))))
  7585. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7586. ((memq action '(?s ?d))
  7587. (let* ((date (unless arg
  7588. (org-read-date
  7589. nil nil nil
  7590. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7591. (ans (if arg nil org-read-date-final-answer))
  7592. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7593. (setq cmd `(let* ((bound (fboundp 'read-string))
  7594. (old (and bound (symbol-function 'read-string))))
  7595. (unwind-protect
  7596. (progn
  7597. (fset 'read-string (lambda (&rest ignore) ,ans))
  7598. (eval '(,c1 arg)))
  7599. (if bound
  7600. (fset 'read-string old)
  7601. (fmakunbound 'read-string)))))))
  7602. ((equal action ?S)
  7603. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7604. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7605. (let ((days (read-number
  7606. (format "Scatter tasks across how many %sdays: "
  7607. (if arg "week" "")) 7)))
  7608. (setq cmd
  7609. `(let ((distance (1+ (random ,days))))
  7610. (if arg
  7611. (let ((dist distance)
  7612. (day-of-week
  7613. (calendar-day-of-week
  7614. (calendar-gregorian-from-absolute (org-today)))))
  7615. (dotimes (i (1+ dist))
  7616. (while (member day-of-week org-agenda-weekend-days)
  7617. (incf distance)
  7618. (incf day-of-week)
  7619. (if (= day-of-week 7)
  7620. (setq day-of-week 0)))
  7621. (incf day-of-week)
  7622. (if (= day-of-week 7)
  7623. (setq day-of-week 0)))))
  7624. ;; silently fail when try to replan a sexp entry
  7625. (condition-case nil
  7626. (let* ((date (calendar-gregorian-from-absolute
  7627. (+ (org-today) distance)))
  7628. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7629. (nth 2 date))))
  7630. (org-agenda-schedule nil time))
  7631. (error nil)))))))
  7632. ((equal action ?f)
  7633. (setq cmd (list (intern
  7634. (org-icompleting-read "Function: "
  7635. obarray 'fboundp t nil nil)))))
  7636. (t (error "Invalid bulk action")))
  7637. ;; Sort the markers, to make sure that parents are handled before children
  7638. (setq entries (sort entries
  7639. (lambda (a b)
  7640. (cond
  7641. ((equal (marker-buffer a) (marker-buffer b))
  7642. (< (marker-position a) (marker-position b)))
  7643. (t
  7644. (string< (buffer-name (marker-buffer a))
  7645. (buffer-name (marker-buffer b))))))))
  7646. ;; Now loop over all markers and apply cmd
  7647. (while (setq e (pop entries))
  7648. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7649. (if (not pos)
  7650. (progn (message "Skipping removed entry at %s" e)
  7651. (setq cntskip (1+ cntskip)))
  7652. (goto-char pos)
  7653. (eval cmd)
  7654. (setq org-agenda-bulk-marked-entries
  7655. (delete e org-agenda-bulk-marked-entries))
  7656. (setq cnt (1+ cnt))))
  7657. (setq org-agenda-bulk-marked-entries nil)
  7658. (org-agenda-bulk-remove-all-marks)
  7659. (when redo-at-end (org-agenda-redo))
  7660. (message "Acted on %d entries%s"
  7661. cnt
  7662. (if (= cntskip 0)
  7663. ""
  7664. (format ", skipped %d (disappeared before their turn)"
  7665. cntskip)))))
  7666. ;;; Flagging notes
  7667. (defun org-agenda-show-the-flagging-note ()
  7668. "Display the flagging note in the other window.
  7669. When called a second time in direct sequence, offer to remove the FLAGGING
  7670. tag and (if present) the flagging note."
  7671. (interactive)
  7672. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7673. (win (selected-window))
  7674. note heading newhead)
  7675. (unless hdmarker
  7676. (error "No linked entry at point"))
  7677. (if (and (eq this-command last-command)
  7678. (y-or-n-p "Unflag and remove any flagging note? "))
  7679. (progn
  7680. (org-agenda-remove-flag hdmarker)
  7681. (let ((win (get-buffer-window "*Flagging Note*")))
  7682. (and win (delete-window win)))
  7683. (message "Entry unflaged"))
  7684. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7685. (unless note
  7686. (error "No flagging note"))
  7687. (org-kill-new note)
  7688. (org-switch-to-buffer-other-window "*Flagging Note*")
  7689. (erase-buffer)
  7690. (insert note)
  7691. (goto-char (point-min))
  7692. (while (re-search-forward "\\\\n" nil t)
  7693. (replace-match "\n" t t))
  7694. (goto-char (point-min))
  7695. (select-window win)
  7696. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7697. (defun org-agenda-remove-flag (marker)
  7698. "Remove the FLAGGED tag and any flagging note in the entry."
  7699. (let (newhead)
  7700. (org-with-point-at marker
  7701. (org-toggle-tag "FLAGGED" 'off)
  7702. (org-entry-delete nil "THEFLAGGINGNOTE")
  7703. (setq newhead (org-get-heading)))
  7704. (org-agenda-change-all-lines newhead marker)
  7705. (message "Entry unflaged")))
  7706. (defun org-agenda-get-any-marker (&optional pos)
  7707. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7708. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7709. ;;; Appointment reminders
  7710. (defvar appt-time-msg-list)
  7711. ;;;###autoload
  7712. (defun org-agenda-to-appt (&optional refresh filter)
  7713. "Activate appointments found in `org-agenda-files'.
  7714. With a \\[universal-argument] prefix, refresh the list of
  7715. appointments.
  7716. If FILTER is t, interactively prompt the user for a regular
  7717. expression, and filter out entries that don't match it.
  7718. If FILTER is a string, use this string as a regular expression
  7719. for filtering entries out.
  7720. FILTER can also be an alist with the car of each cell being
  7721. either 'headline or 'category. For example:
  7722. '((headline \"IMPORTANT\")
  7723. (category \"Work\"))
  7724. will only add headlines containing IMPORTANT or headlines
  7725. belonging to the \"Work\" category."
  7726. (interactive "P")
  7727. (if refresh (setq appt-time-msg-list nil))
  7728. (if (eq filter t)
  7729. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7730. (let* ((cnt 0) ; count added events
  7731. (org-agenda-new-buffers nil)
  7732. (org-deadline-warning-days 0)
  7733. ;; Do not use `org-today' here because appt only takes
  7734. ;; time and without date as argument, so it may pass wrong
  7735. ;; information otherwise
  7736. (today (org-date-to-gregorian
  7737. (time-to-days (current-time))))
  7738. (org-agenda-restrict nil)
  7739. (files (org-agenda-files 'unrestricted)) entries file)
  7740. ;; Get all entries which may contain an appt
  7741. (org-prepare-agenda-buffers files)
  7742. (while (setq file (pop files))
  7743. (setq entries
  7744. (append entries
  7745. (org-agenda-get-day-entries
  7746. file today :timestamp :scheduled :deadline))))
  7747. (setq entries (delq nil entries))
  7748. ;; Map thru entries and find if we should filter them out
  7749. (mapc
  7750. (lambda(x)
  7751. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7752. (cat (get-text-property 1 'org-category x))
  7753. (tod (get-text-property 1 'time-of-day x))
  7754. (ok (or (null filter)
  7755. (and (stringp filter) (string-match filter evt))
  7756. (and (listp filter)
  7757. (or (string-match
  7758. (cadr (assoc 'category filter)) cat)
  7759. (string-match
  7760. (cadr (assoc 'headline filter)) evt))))))
  7761. ;; FIXME: Shall we remove text-properties for the appt text?
  7762. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7763. (when (and ok tod)
  7764. (setq tod (concat "00" (number-to-string tod))
  7765. tod (when (string-match
  7766. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7767. (concat (match-string 1 tod) ":"
  7768. (match-string 2 tod))))
  7769. (appt-add tod evt)
  7770. (setq cnt (1+ cnt))))) entries)
  7771. (org-release-buffers org-agenda-new-buffers)
  7772. (if (eq cnt 0)
  7773. (message "No event to add")
  7774. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7775. (defun org-agenda-todayp (date)
  7776. "Does DATE mean today, when considering `org-extend-today-until'?"
  7777. (let ((today (org-today))
  7778. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7779. date)))
  7780. (eq date today)))
  7781. (provide 'org-agenda)
  7782. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7783. ;;; org-agenda.el ends here