org-agenda.el 391 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2017 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'org)
  43. (require 'org-macs)
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-columns-remove-overlays "org-colview" ())
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-agenda-columns "org-colview" ())
  74. (declare-function org-add-archive-files "org-archive" (files))
  75. (declare-function org-capture "org-capture" (&optional goto keys))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task)
  78. (defvar org-current-tag-alist)
  79. (defvar org-mobile-force-id-on-agenda-items)
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. \\='((ps-print-color-p \\='black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in a temporary buffer before writing the agenda to an export file.
  143. A useful function for this hook is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which is the default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style nil
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header."
  199. :group 'org-agenda-export
  200. :group 'org-export-html
  201. :type '(choice
  202. (const nil)
  203. (string)))
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const timestamp-up) (const timestamp-down)
  216. (const scheduled-up) (const scheduled-down)
  217. (const deadline-up) (const deadline-down)
  218. (const ts-up) (const ts-down)
  219. (const tsia-up) (const tsia-down)
  220. (const category-keep) (const category-up) (const category-down)
  221. (const tag-down) (const tag-up)
  222. (const priority-up) (const priority-down)
  223. (const todo-state-up) (const todo-state-down)
  224. (const effort-up) (const effort-down)
  225. (const habit-up) (const habit-down)
  226. (const alpha-up) (const alpha-down)
  227. (const user-defined-up) (const user-defined-down))
  228. "Sorting choices.")
  229. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  230. ;; the new variable `org-agenda-tag-filter-preset'.
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  233. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  234. "List of types searched for when creating the daily/weekly agenda.
  235. This variable is a list of symbols that controls the types of
  236. items that appear in the daily/weekly agenda. Allowed symbols in this
  237. list are are
  238. :timestamp List items containing a date stamp or date range matching
  239. the selected date. This includes sexp entries in angular
  240. brackets.
  241. :sexp List entries resulting from plain diary-like sexps.
  242. :deadline List deadline due on that date. When the date is today,
  243. also list any deadlines past due, or due within
  244. `org-deadline-warning-days'. `:deadline' must appear before
  245. `:scheduled' if the setting of
  246. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  247. any effect.
  248. :deadline* Same as above, but only include the deadline if it has an
  249. hour specification as [h]h:mm.
  250. :scheduled List all items which are scheduled for the given date.
  251. The diary for *today* also contains items which were
  252. scheduled earlier and are not yet marked DONE.
  253. :scheduled* Same as above, but only include the scheduled item if it
  254. has an hour specification as [h]h:mm.
  255. By default, all four non-starred types are turned on.
  256. When :scheduled* or :deadline* are included, :schedule or :deadline
  257. will be ignored.
  258. Never set this variable globally using `setq', because then it
  259. will apply to all future agenda commands. Instead, bind it with
  260. `let' to scope it dynamically into the agenda-constructing
  261. command. A good way to set it is through options in
  262. `org-agenda-custom-commands'. For a more flexible (though
  263. somewhat less efficient) way of determining what is included in
  264. the daily/weekly agenda, see `org-agenda-skip-function'.")
  265. (defconst org-agenda-custom-commands-local-options
  266. `(repeat :tag "Local settings for this command. Remember to quote values"
  267. (choice :tag "Setting"
  268. (list :tag "Heading for this block"
  269. (const org-agenda-overriding-header)
  270. (string :tag "Headline"))
  271. (list :tag "Files to be searched"
  272. (const org-agenda-files)
  273. (list
  274. (const :format "" quote)
  275. (repeat (file))))
  276. (list :tag "Sorting strategy"
  277. (const org-agenda-sorting-strategy)
  278. (list
  279. (const :format "" quote)
  280. (repeat
  281. ,org-sorting-choice)))
  282. (list :tag "Prefix format"
  283. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  284. (string))
  285. (list :tag "Number of days in agenda"
  286. (const org-agenda-span)
  287. (choice (const :tag "Day" day)
  288. (const :tag "Week" week)
  289. (const :tag "Fortnight" fortnight)
  290. (const :tag "Month" month)
  291. (const :tag "Year" year)
  292. (integer :tag "Custom")))
  293. (list :tag "Fixed starting date"
  294. (const org-agenda-start-day)
  295. (string :value "2007-11-01"))
  296. (list :tag "Start on day of week"
  297. (const org-agenda-start-on-weekday)
  298. (choice :value 1
  299. (const :tag "Today" nil)
  300. (integer :tag "Weekday No.")))
  301. (list :tag "Include data from diary"
  302. (const org-agenda-include-diary)
  303. (boolean))
  304. (list :tag "Deadline Warning days"
  305. (const org-deadline-warning-days)
  306. (integer :value 1))
  307. (list :tag "Category filter preset"
  308. (const org-agenda-category-filter-preset)
  309. (list
  310. (const :format "" quote)
  311. (repeat
  312. (string :tag "+category or -category"))))
  313. (list :tag "Tags filter preset"
  314. (const org-agenda-tag-filter-preset)
  315. (list
  316. (const :format "" quote)
  317. (repeat
  318. (string :tag "+tag or -tag"))))
  319. (list :tag "Effort filter preset"
  320. (const org-agenda-effort-filter-preset)
  321. (list
  322. (const :format "" quote)
  323. (repeat
  324. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  325. (list :tag "Regexp filter preset"
  326. (const org-agenda-regexp-filter-preset)
  327. (list
  328. (const :format "" quote)
  329. (repeat
  330. (string :tag "+regexp or -regexp"))))
  331. (list :tag "Set daily/weekly entry types"
  332. (const org-agenda-entry-types)
  333. (list
  334. (const :format "" quote)
  335. (set :greedy t :value ,org-agenda-entry-types
  336. (const :deadline)
  337. (const :scheduled)
  338. (const :deadline*)
  339. (const :scheduled*)
  340. (const :timestamp)
  341. (const :sexp))))
  342. (list :tag "Standard skipping condition"
  343. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  344. (const org-agenda-skip-function)
  345. (list
  346. (const :format "" quote)
  347. (list
  348. (choice
  349. :tag "Skipping range"
  350. (const :tag "Skip entry" org-agenda-skip-entry-if)
  351. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  352. (repeat :inline t :tag "Conditions for skipping"
  353. (choice
  354. :tag "Condition type"
  355. (list :tag "Regexp matches" :inline t
  356. (const :format "" 'regexp)
  357. (regexp))
  358. (list :tag "Regexp does not match" :inline t
  359. (const :format "" 'notregexp)
  360. (regexp))
  361. (list :tag "TODO state is" :inline t
  362. (const 'todo)
  363. (choice
  364. (const :tag "Any not-done state" 'todo)
  365. (const :tag "Any done state" 'done)
  366. (const :tag "Any state" 'any)
  367. (list :tag "Keyword list"
  368. (const :format "" quote)
  369. (repeat (string :tag "Keyword")))))
  370. (list :tag "TODO state is not" :inline t
  371. (const 'nottodo)
  372. (choice
  373. (const :tag "Any not-done state" 'todo)
  374. (const :tag "Any done state" 'done)
  375. (const :tag "Any state" 'any)
  376. (list :tag "Keyword list"
  377. (const :format "" quote)
  378. (repeat (string :tag "Keyword")))))
  379. (const :tag "scheduled" 'scheduled)
  380. (const :tag "not scheduled" 'notscheduled)
  381. (const :tag "deadline" 'deadline)
  382. (const :tag "no deadline" 'notdeadline)
  383. (const :tag "timestamp" 'timestamp)
  384. (const :tag "no timestamp" 'nottimestamp))))))
  385. (list :tag "Non-standard skipping condition"
  386. :value (org-agenda-skip-function)
  387. (const org-agenda-skip-function)
  388. (sexp :tag "Function or form (quoted!)"))
  389. (list :tag "Any variable"
  390. (variable :tag "Variable")
  391. (sexp :tag "Value (sexp)"))))
  392. "Selection of examples for agenda command settings.
  393. This will be spliced into the custom type of
  394. `org-agenda-custom-commands'.")
  395. (defcustom org-agenda-custom-commands
  396. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  397. "Custom commands for the agenda.
  398. \\<org-mode-map>
  399. These commands will be offered on the splash screen displayed by the
  400. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  401. (key desc type match settings files)
  402. key The key (one or more characters as a string) to be associated
  403. with the command.
  404. desc A description of the command, when omitted or nil, a default
  405. description is built using MATCH.
  406. type The command type, any of the following symbols:
  407. agenda The daily/weekly agenda.
  408. todo Entries with a specific TODO keyword, in all agenda files.
  409. search Entries containing search words entry or headline.
  410. tags Tags/Property/TODO match in all agenda files.
  411. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  412. todo-tree Sparse tree of specific TODO keyword in *current* file.
  413. tags-tree Sparse tree with all tags matches in *current* file.
  414. occur-tree Occur sparse tree for *current* file.
  415. ... A user-defined function.
  416. match What to search for:
  417. - a single keyword for TODO keyword searches
  418. - a tags match expression for tags searches
  419. - a word search expression for text searches.
  420. - a regular expression for occur searches
  421. For all other commands, this should be the empty string.
  422. settings A list of option settings, similar to that in a let form, so like
  423. this: ((opt1 val1) (opt2 val2) ...). The values will be
  424. evaluated at the moment of execution, so quote them when needed.
  425. files A list of files file to write the produced agenda buffer to
  426. with the command `org-store-agenda-views'.
  427. If a file name ends in \".html\", an HTML version of the buffer
  428. is written out. If it ends in \".ps\", a postscript version is
  429. produced. Otherwise, only the plain text is written to the file.
  430. You can also define a set of commands, to create a composite agenda buffer.
  431. In this case, an entry looks like this:
  432. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  433. where
  434. desc A description string to be displayed in the dispatcher menu.
  435. cmd An agenda command, similar to the above. However, tree commands
  436. are not allowed, but instead you can get agenda and global todo list.
  437. So valid commands for a set are:
  438. (agenda \"\" settings)
  439. (alltodo \"\" settings)
  440. (stuck \"\" settings)
  441. (todo \"match\" settings files)
  442. (search \"match\" settings files)
  443. (tags \"match\" settings files)
  444. (tags-todo \"match\" settings files)
  445. Each command can carry a list of options, and another set of options can be
  446. given for the whole set of commands. Individual command options take
  447. precedence over the general options.
  448. When using several characters as key to a command, the first characters
  449. are prefix commands. For the dispatcher to display useful information, you
  450. should provide a description for the prefix, like
  451. (setq org-agenda-custom-commands
  452. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  453. (\"hl\" tags \"+HOME+Lisa\")
  454. (\"hp\" tags \"+HOME+Peter\")
  455. (\"hk\" tags \"+HOME+Kim\")))"
  456. :group 'org-agenda-custom-commands
  457. :type `(repeat
  458. (choice :value ("x" "Describe command here" tags "" nil)
  459. (list :tag "Single command"
  460. (string :tag "Access Key(s) ")
  461. (option (string :tag "Description"))
  462. (choice
  463. (const :tag "Agenda" agenda)
  464. (const :tag "TODO list" alltodo)
  465. (const :tag "Search words" search)
  466. (const :tag "Stuck projects" stuck)
  467. (const :tag "Tags/Property match (all agenda files)" tags)
  468. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  469. (const :tag "TODO keyword search (all agenda files)" todo)
  470. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  471. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  472. (const :tag "Occur tree (current buffer)" occur-tree)
  473. (sexp :tag "Other, user-defined function"))
  474. (string :tag "Match (only for some commands)")
  475. ,org-agenda-custom-commands-local-options
  476. (option (repeat :tag "Export" (file :tag "Export to"))))
  477. (list :tag "Command series, all agenda files"
  478. (string :tag "Access Key(s)")
  479. (string :tag "Description ")
  480. (repeat :tag "Component"
  481. (choice
  482. (list :tag "Agenda"
  483. (const :format "" agenda)
  484. (const :tag "" :format "" "")
  485. ,org-agenda-custom-commands-local-options)
  486. (list :tag "TODO list (all keywords)"
  487. (const :format "" alltodo)
  488. (const :tag "" :format "" "")
  489. ,org-agenda-custom-commands-local-options)
  490. (list :tag "Search words"
  491. (const :format "" search)
  492. (string :tag "Match")
  493. ,org-agenda-custom-commands-local-options)
  494. (list :tag "Stuck projects"
  495. (const :format "" stuck)
  496. (const :tag "" :format "" "")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "Tags search"
  499. (const :format "" tags)
  500. (string :tag "Match")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Tags search, TODO entries only"
  503. (const :format "" tags-todo)
  504. (string :tag "Match")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "TODO keyword search"
  507. (const :format "" todo)
  508. (string :tag "Match")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "Other, user-defined function"
  511. (symbol :tag "function")
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)))
  514. (repeat :tag "Settings for entire command set"
  515. (list (variable :tag "Any variable")
  516. (sexp :tag "Value")))
  517. (option (repeat :tag "Export" (file :tag "Export to"))))
  518. (cons :tag "Prefix key documentation"
  519. (string :tag "Access Key(s)")
  520. (string :tag "Description ")))))
  521. (defcustom org-agenda-query-register ?o
  522. "The register holding the current query string.
  523. The purpose of this is that if you construct a query string interactively,
  524. you can then use it to define a custom command."
  525. :group 'org-agenda-custom-commands
  526. :type 'character)
  527. (defcustom org-stuck-projects
  528. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  529. "How to identify stuck projects.
  530. This is a list of four items:
  531. 1. A tags/todo/property matcher string that is used to identify a project.
  532. See the manual for a description of tag and property searches.
  533. The entire tree below a headline matched by this is considered one project.
  534. 2. A list of TODO keywords identifying non-stuck projects.
  535. If the project subtree contains any headline with one of these todo
  536. keywords, the project is considered to be not stuck. If you specify
  537. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  538. 3. A list of tags identifying non-stuck projects.
  539. If the project subtree contains any headline with one of these tags,
  540. the project is considered to be not stuck. If you specify \"*\" as
  541. a tag, any tag will mark the project unstuck. Note that this is about
  542. the explicit presence of a tag somewhere in the subtree, inherited
  543. tags do not count here. If inherited tags make a project not stuck,
  544. use \"-TAG\" in the tags part of the matcher under (1.) above.
  545. 4. An arbitrary regular expression matching non-stuck projects.
  546. If the project turns out to be not stuck, search continues also in the
  547. subtree to see if any of the subtasks have project status.
  548. See also the variable `org-tags-match-list-sublevels' which applies
  549. to projects matched by this search as well.
  550. After defining this variable, you may use `\\[org-agenda-list-stuck-projects]'
  551. \(bound to `C-c a #') to produce the list."
  552. :group 'org-agenda-custom-commands
  553. :type '(list
  554. (string :tag "Tags/TODO match to identify a project")
  555. (repeat :tag "Projects are *not* stuck if they have an entry with \
  556. TODO keyword any of" (string))
  557. (repeat :tag "Projects are *not* stuck if they have an entry with \
  558. TAG being any of" (string))
  559. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  560. the subtree")))
  561. (defgroup org-agenda-skip nil
  562. "Options concerning skipping parts of agenda files."
  563. :tag "Org Agenda Skip"
  564. :group 'org-agenda)
  565. (defcustom org-agenda-skip-function-global nil
  566. "Function to be called at each match during agenda construction.
  567. If this function returns nil, the current match should not be skipped.
  568. If the function decided to skip an agenda match, is must return the
  569. buffer position from which the search should be continued.
  570. This may also be a Lisp form, which will be evaluated.
  571. This variable will be applied to every agenda match, including
  572. tags/property searches and TODO lists. So try to make the test function
  573. do its checking as efficiently as possible. To implement a skipping
  574. condition just for specific agenda commands, use the variable
  575. `org-agenda-skip-function' which can be set in the options section
  576. of custom agenda commands."
  577. :group 'org-agenda-skip
  578. :type 'sexp)
  579. (defgroup org-agenda-daily/weekly nil
  580. "Options concerning the daily/weekly agenda."
  581. :tag "Org Agenda Daily/Weekly"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-todo-list nil
  584. "Options concerning the global todo list agenda view."
  585. :tag "Org Agenda Todo List"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-match-view nil
  588. "Options concerning the general tags/property/todo match agenda view."
  589. :tag "Org Agenda Match View"
  590. :group 'org-agenda)
  591. (defgroup org-agenda-search-view nil
  592. "Options concerning the search agenda view."
  593. :tag "Org Agenda Search View"
  594. :group 'org-agenda)
  595. (defvar org-agenda-archives-mode nil
  596. "Non-nil means the agenda will include archived items.
  597. If this is the symbol `trees', trees in the selected agenda scope
  598. that are marked with the ARCHIVE tag will be included anyway. When this is
  599. t, also all archive files associated with the current selection of agenda
  600. files will be included.")
  601. (defcustom org-agenda-restriction-lock-highlight-subtree t
  602. "Non-nil means highlight the whole subtree when restriction is active.
  603. Otherwise only highlight the headline. Highlighting the whole subtree is
  604. useful to ensure no edits happen beyond the restricted region."
  605. :group 'org-agenda
  606. :type 'boolean)
  607. (defcustom org-agenda-skip-comment-trees t
  608. "Non-nil means skip trees that start with the COMMENT keyword.
  609. When nil, these trees are also scanned by agenda commands."
  610. :group 'org-agenda-skip
  611. :type 'boolean)
  612. (defcustom org-agenda-todo-list-sublevels t
  613. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  614. When nil, the sublevels of a TODO entry are not checked, resulting in
  615. potentially much shorter TODO lists."
  616. :group 'org-agenda-skip
  617. :group 'org-agenda-todo-list
  618. :type 'boolean)
  619. (defcustom org-agenda-todo-ignore-with-date nil
  620. "Non-nil means don't show entries with a date in the global todo list.
  621. You can use this if you prefer to mark mere appointments with a TODO keyword,
  622. but don't want them to show up in the TODO list.
  623. When this is set, it also covers deadlines and scheduled items, the settings
  624. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  625. will be ignored.
  626. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  627. :group 'org-agenda-skip
  628. :group 'org-agenda-todo-list
  629. :type 'boolean)
  630. (defcustom org-agenda-todo-ignore-timestamp nil
  631. "Non-nil means don't show entries with a timestamp.
  632. This applies when creating the global todo list.
  633. Valid values are:
  634. past Don't show entries for today or in the past.
  635. future Don't show entries with a timestamp in the future.
  636. The idea behind this is that if it has a future
  637. timestamp, you don't want to think about it until the
  638. date.
  639. all Don't show any entries with a timestamp in the global todo list.
  640. The idea behind this is that by setting a timestamp, you
  641. have already \"taken care\" of this item.
  642. This variable can also have an integer as a value. If positive (N),
  643. todos with a timestamp N or more days in the future will be ignored. If
  644. negative (-N), todos with a timestamp N or more days in the past will be
  645. ignored. If 0, todos with a timestamp either today or in the future will
  646. be ignored. For example, a value of -1 will exclude todos with a
  647. timestamp in the past (yesterday or earlier), while a value of 7 will
  648. exclude todos with a timestamp a week or more in the future.
  649. See also `org-agenda-todo-ignore-with-date'.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  651. to make his option also apply to the tags-todo list."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :version "24.1"
  655. :type '(choice
  656. (const :tag "Ignore future timestamp todos" future)
  657. (const :tag "Ignore past or present timestamp todos" past)
  658. (const :tag "Ignore all timestamp todos" all)
  659. (const :tag "Show timestamp todos" nil)
  660. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  661. (defcustom org-agenda-todo-ignore-scheduled nil
  662. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  663. This applies when creating the global todo list.
  664. Valid values are:
  665. past Don't show entries scheduled today or in the past.
  666. future Don't show entries scheduled in the future.
  667. The idea behind this is that by scheduling it, you don't want to
  668. think about it until the scheduled date.
  669. all Don't show any scheduled entries in the global todo list.
  670. The idea behind this is that by scheduling it, you have already
  671. \"taken care\" of this item.
  672. t Same as `all', for backward compatibility.
  673. This variable can also have an integer as a value. See
  674. `org-agenda-todo-ignore-timestamp' for more details.
  675. See also `org-agenda-todo-ignore-with-date'.
  676. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  677. to make his option also apply to the tags-todo list."
  678. :group 'org-agenda-skip
  679. :group 'org-agenda-todo-list
  680. :type '(choice
  681. (const :tag "Ignore future-scheduled todos" future)
  682. (const :tag "Ignore past- or present-scheduled todos" past)
  683. (const :tag "Ignore all scheduled todos" all)
  684. (const :tag "Ignore all scheduled todos (compatibility)" t)
  685. (const :tag "Show scheduled todos" nil)
  686. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  687. (defcustom org-agenda-todo-ignore-deadlines nil
  688. "Non-nil means ignore some deadline TODO items when making TODO list.
  689. There are different motivations for using different values, please think
  690. carefully when configuring this variable.
  691. This applies when creating the global TODO list.
  692. Valid values are:
  693. near Don't show near deadline entries. A deadline is near when it is
  694. closer than `org-deadline-warning-days' days. The idea behind this
  695. is that such items will appear in the agenda anyway.
  696. far Don't show TODO entries where a deadline has been defined, but
  697. is not going to happen anytime soon. This is useful if you want to use
  698. the TODO list to figure out what to do now.
  699. past Don't show entries with a deadline timestamp for today or in the past.
  700. future Don't show entries with a deadline timestamp in the future, not even
  701. when they become `near' ones. Use it with caution.
  702. all Ignore all TODO entries that do have a deadline.
  703. t Same as `near', for backward compatibility.
  704. This variable can also have an integer as a value. See
  705. `org-agenda-todo-ignore-timestamp' for more details.
  706. See also `org-agenda-todo-ignore-with-date'.
  707. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  708. to make his option also apply to the tags-todo list."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-todo-list
  711. :type '(choice
  712. (const :tag "Ignore near deadlines" near)
  713. (const :tag "Ignore near deadlines (compatibility)" t)
  714. (const :tag "Ignore far deadlines" far)
  715. (const :tag "Ignore all TODOs with a deadlines" all)
  716. (const :tag "Show all TODOs, even if they have a deadline" nil)
  717. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  718. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  719. "Time unit to use when possibly ignoring an agenda item.
  720. See the docstring of various `org-agenda-todo-ignore-*' options.
  721. The default is to compare time stamps using days. An item is thus
  722. considered to be in the future if it is at least one day after today.
  723. Non-nil means to compare time stamps using seconds. An item is then
  724. considered future if it has a time value later than current time."
  725. :group 'org-agenda-skip
  726. :group 'org-agenda-todo-list
  727. :version "24.4"
  728. :package-version '(Org . "8.0")
  729. :type '(choice
  730. (const :tag "Compare time with days" nil)
  731. (const :tag "Compare time with seconds" t)))
  732. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  733. "Non-nil means honor todo-list ignores options also in tags-todo search.
  734. The variables
  735. `org-agenda-todo-ignore-with-date',
  736. `org-agenda-todo-ignore-timestamp',
  737. `org-agenda-todo-ignore-scheduled',
  738. `org-agenda-todo-ignore-deadlines'
  739. make the global TODO list skip entries that have time stamps of certain
  740. kinds. If this option is set, the same options will also apply for the
  741. tags-todo search, which is the general tags/property matcher
  742. restricted to unfinished TODO entries only."
  743. :group 'org-agenda-skip
  744. :group 'org-agenda-todo-list
  745. :group 'org-agenda-match-view
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-scheduled-if-done nil
  748. "Non-nil means don't show scheduled items in agenda when they are done.
  749. This is relevant for the daily/weekly agenda, not for the TODO list. It
  750. applies only to the actual date of the scheduling. Warnings about an item
  751. with a past scheduling dates are always turned off when the item is DONE."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  756. "Non-nil means skip scheduling line if same entry shows because of deadline.
  757. In the agenda of today, an entry can show up multiple times
  758. because it is both scheduled and has a nearby deadline, and maybe
  759. a plain time stamp as well.
  760. When this variable is nil, the entry will be shown several times.
  761. When set to t, then only the deadline is shown and the fact that
  762. the entry is scheduled today or was scheduled previously is not
  763. shown.
  764. When set to the symbol `not-today', skip scheduled previously,
  765. but not scheduled today.
  766. When set to the symbol `repeated-after-deadline', skip scheduled
  767. items if they are repeated beyond the current deadline."
  768. :group 'org-agenda-skip
  769. :group 'org-agenda-daily/weekly
  770. :type '(choice
  771. (const :tag "Never" nil)
  772. (const :tag "Always" t)
  773. (const :tag "Not when scheduled today" not-today)
  774. (const :tag "When repeated past deadline" repeated-after-deadline)))
  775. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  776. "Non-nil means skip timestamp line if same entry shows because of deadline.
  777. In the agenda of today, an entry can show up multiple times
  778. because it has both a plain timestamp and has a nearby deadline.
  779. When this variable is t, then only the deadline is shown and the
  780. fact that the entry has a timestamp for or including today is not
  781. shown. When this variable is nil, the entry will be shown
  782. several times."
  783. :group 'org-agenda-skip
  784. :group 'org-agenda-daily/weekly
  785. :version "24.1"
  786. :type '(choice
  787. (const :tag "Never" nil)
  788. (const :tag "Always" t)))
  789. (defcustom org-agenda-skip-deadline-if-done nil
  790. "Non-nil means don't show deadlines when the corresponding item is done.
  791. When nil, the deadline is still shown and should give you a happy feeling.
  792. This is relevant for the daily/weekly agenda. It applies only to the
  793. actual date of the deadline. Warnings about approaching and past-due
  794. deadlines are always turned off when the item is DONE."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  799. "Non-nil means skip deadline prewarning when entry is also scheduled.
  800. This will apply on all days where a prewarning for the deadline would
  801. be shown, but not at the day when the entry is actually due. On that day,
  802. the deadline will be shown anyway.
  803. This variable may be set to nil, t, the symbol `pre-scheduled',
  804. or a number which will then give the number of days before the actual
  805. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  806. eliminates the deadline prewarning only prior to the scheduled date.
  807. This can be used in a workflow where the first showing of the deadline will
  808. trigger you to schedule it, and then you don't want to be reminded of it
  809. because you will take care of it on the day when scheduled."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Always show prewarning" nil)
  815. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  816. (const :tag "Remove prewarning if entry is scheduled" t)
  817. (integer :tag "Restart prewarning N days before deadline")))
  818. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  819. "Non-nil means skip scheduled delay when entry also has a deadline.
  820. This variable may be set to nil, t, the symbol `post-deadline',
  821. or a number which will then give the number of days after the actual
  822. scheduled date when the delay should expire. The symbol `post-deadline'
  823. eliminates the schedule delay when the date is posterior to the deadline."
  824. :group 'org-agenda-skip
  825. :group 'org-agenda-daily/weekly
  826. :version "24.4"
  827. :package-version '(Org . "8.0")
  828. :type '(choice
  829. (const :tag "Always honor delay" nil)
  830. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  831. (const :tag "Ignore delay if entry has a deadline" t)
  832. (integer :tag "Honor delay up until N days after the scheduled date")))
  833. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  834. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  835. When non-nil, after the search for timestamps has matched once in an
  836. entry, the rest of the entry will not be searched."
  837. :group 'org-agenda-skip
  838. :type 'boolean)
  839. (defcustom org-agenda-skip-timestamp-if-done nil
  840. "Non-nil means don't select item by timestamp or -range if it is DONE."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :type 'boolean)
  844. (defcustom org-agenda-dim-blocked-tasks t
  845. "Non-nil means dim blocked tasks in the agenda display.
  846. This causes some overhead during agenda construction, but if you
  847. have turned on `org-enforce-todo-dependencies',
  848. `org-enforce-todo-checkbox-dependencies', or any other blocking
  849. mechanism, this will create useful feedback in the agenda.
  850. Instead of t, this variable can also have the value `invisible'.
  851. Then blocked tasks will be invisible and only become visible when
  852. they become unblocked. An exemption to this behavior is when a task is
  853. blocked because of unchecked checkboxes below it. Since checkboxes do
  854. not show up in the agenda views, making this task invisible you remove any
  855. trace from agenda views that there is something to do. Therefore, a task
  856. that is blocked because of checkboxes will never be made invisible, it
  857. will only be dimmed."
  858. :group 'org-agenda-daily/weekly
  859. :group 'org-agenda-todo-list
  860. :version "24.3"
  861. :type '(choice
  862. (const :tag "Do not dim" nil)
  863. (const :tag "Dim to a gray face" t)
  864. (const :tag "Make invisible" invisible)))
  865. (defgroup org-agenda-startup nil
  866. "Options concerning initial settings in the Agenda in Org Mode."
  867. :tag "Org Agenda Startup"
  868. :group 'org-agenda)
  869. (defcustom org-agenda-menu-show-matcher t
  870. "Non-nil means show the match string in the agenda dispatcher menu.
  871. When nil, the matcher string is not shown, but is put into the help-echo
  872. property so than moving the mouse over the command shows it.
  873. Setting it to nil is good if matcher strings are very long and/or if
  874. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  875. :group 'org-agenda
  876. :version "24.1"
  877. :type 'boolean)
  878. (defcustom org-agenda-menu-two-columns nil
  879. "Non-nil means, use two columns to show custom commands in the dispatcher.
  880. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  881. to nil."
  882. :group 'org-agenda
  883. :version "24.1"
  884. :type 'boolean)
  885. (defcustom org-agenda-finalize-hook nil
  886. "Hook run just before displaying an agenda buffer.
  887. The buffer is still writable when the hook is called.
  888. You can modify some of the buffer substrings but you should be
  889. extra careful not to modify the text properties of the agenda
  890. headlines as the agenda display heavily relies on them."
  891. :group 'org-agenda-startup
  892. :type 'hook)
  893. (defcustom org-agenda-mouse-1-follows-link nil
  894. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  895. A longer mouse click will still set point. Needs to be set
  896. before org.el is loaded."
  897. :group 'org-agenda-startup
  898. :type 'boolean)
  899. (defcustom org-agenda-start-with-follow-mode nil
  900. "The initial value of follow mode in a newly created agenda window."
  901. :group 'org-agenda-startup
  902. :type 'boolean)
  903. (defcustom org-agenda-follow-indirect nil
  904. "Non-nil means `org-agenda-follow-mode' displays only the
  905. current item's tree, in an indirect buffer."
  906. :group 'org-agenda
  907. :version "24.1"
  908. :type 'boolean)
  909. (defcustom org-agenda-show-outline-path t
  910. "Non-nil means show outline path in echo area after line motion."
  911. :group 'org-agenda-startup
  912. :type 'boolean)
  913. (defcustom org-agenda-start-with-entry-text-mode nil
  914. "The initial value of entry-text-mode in a newly created agenda window."
  915. :group 'org-agenda-startup
  916. :type 'boolean)
  917. (defcustom org-agenda-entry-text-maxlines 5
  918. "Number of text lines to be added when `E' is pressed in the agenda.
  919. Note that this variable only used during agenda display. To add entry text
  920. when exporting the agenda, configure the variable
  921. `org-agenda-add-entry-text-maxlines'."
  922. :group 'org-agenda
  923. :type 'integer)
  924. (defcustom org-agenda-entry-text-exclude-regexps nil
  925. "List of regular expressions to clean up entry text.
  926. The complete matches of all regular expressions in this list will be
  927. removed from entry text before it is shown in the agenda."
  928. :group 'org-agenda
  929. :type '(repeat (regexp)))
  930. (defcustom org-agenda-entry-text-leaders " > "
  931. "Text prepended to the entry text in agenda buffers."
  932. :version "24.4"
  933. :package-version '(Org . "8.0")
  934. :group 'org-agenda
  935. :type 'string)
  936. (defvar org-agenda-entry-text-cleanup-hook nil
  937. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  938. This cleanup is done in a temporary buffer, so the function may inspect and
  939. change the entire buffer.
  940. Some default stuff like drawers and scheduling/deadline dates will already
  941. have been removed when this is called, as will any matches for regular
  942. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  943. (defvar org-agenda-include-inactive-timestamps nil
  944. "Non-nil means include inactive time stamps in agenda and timeline.
  945. Dynamically scoped.")
  946. (defgroup org-agenda-windows nil
  947. "Options concerning the windows used by the Agenda in Org Mode."
  948. :tag "Org Agenda Windows"
  949. :group 'org-agenda)
  950. (defcustom org-agenda-window-setup 'reorganize-frame
  951. "How the agenda buffer should be displayed.
  952. Possible values for this option are:
  953. current-window Show agenda in the current window, keeping all other windows.
  954. other-window Use `switch-to-buffer-other-window' to display agenda.
  955. only-window Show agenda, deleting all other windows.
  956. reorganize-frame Show only two windows on the current frame, the current
  957. window and the agenda.
  958. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  959. Also, when exiting the agenda, kill that frame.
  960. See also the variable `org-agenda-restore-windows-after-quit'."
  961. :group 'org-agenda-windows
  962. :type '(choice
  963. (const current-window)
  964. (const other-frame)
  965. (const other-window)
  966. (const only-window)
  967. (const reorganize-frame)))
  968. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  969. "The min and max height of the agenda window as a fraction of frame height.
  970. The value of the variable is a cons cell with two numbers between 0 and 1.
  971. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  972. :group 'org-agenda-windows
  973. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  974. (defcustom org-agenda-restore-windows-after-quit nil
  975. "Non-nil means restore window configuration upon exiting agenda.
  976. Before the window configuration is changed for displaying the agenda,
  977. the current status is recorded. When the agenda is exited with
  978. `q' or `x' and this option is set, the old state is restored. If
  979. `org-agenda-window-setup' is `other-frame', the value of this
  980. option will be ignored."
  981. :group 'org-agenda-windows
  982. :type 'boolean)
  983. (defcustom org-agenda-span 'week
  984. "Number of days to include in overview display.
  985. Can be day, week, month, year, or any number of days.
  986. Custom commands can set this variable in the options section."
  987. :group 'org-agenda-daily/weekly
  988. :type '(choice (const :tag "Day" day)
  989. (const :tag "Week" week)
  990. (const :tag "Fortnight" fortnight)
  991. (const :tag "Month" month)
  992. (const :tag "Year" year)
  993. (integer :tag "Custom")))
  994. (defcustom org-agenda-start-on-weekday 1
  995. "Non-nil means start the overview always on the specified weekday.
  996. 0 denotes Sunday, 1 denotes Monday, etc.
  997. When nil, always start on the current day.
  998. Custom commands can set this variable in the options section."
  999. :group 'org-agenda-daily/weekly
  1000. :type '(choice (const :tag "Today" nil)
  1001. (integer :tag "Weekday No.")))
  1002. (defcustom org-agenda-show-all-dates t
  1003. "Non-nil means `org-agenda' shows every day in the selected range.
  1004. When nil, only the days which actually have entries are shown."
  1005. :group 'org-agenda-daily/weekly
  1006. :type 'boolean)
  1007. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1008. "Format string for displaying dates in the agenda.
  1009. Used by the daily/weekly agenda and by the timeline. This should be
  1010. a format string understood by `format-time-string', or a function returning
  1011. the formatted date as a string. The function must take a single argument,
  1012. a calendar-style date list like (month day year)."
  1013. :group 'org-agenda-daily/weekly
  1014. :type '(choice
  1015. (string :tag "Format string")
  1016. (function :tag "Function")))
  1017. (defun org-agenda-format-date-aligned (date)
  1018. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1019. This function makes sure that dates are aligned for easy reading."
  1020. (require 'cal-iso)
  1021. (let* ((dayname (calendar-day-name date))
  1022. (day (cadr date))
  1023. (day-of-week (calendar-day-of-week date))
  1024. (month (car date))
  1025. (monthname (calendar-month-name month))
  1026. (year (nth 2 date))
  1027. (iso-week (org-days-to-iso-week
  1028. (calendar-absolute-from-gregorian date)))
  1029. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1030. (1- year))
  1031. ((and (= month 12) (<= iso-week 1))
  1032. (1+ year))
  1033. (t year)))
  1034. (weekstring (if (= day-of-week 1)
  1035. (format " W%02d" iso-week)
  1036. "")))
  1037. (format "%-10s %2d %s %4d%s"
  1038. dayname day monthname year weekstring)))
  1039. (defcustom org-agenda-time-leading-zero nil
  1040. "Non-nil means use leading zero for military times in agenda.
  1041. For example, 9:30am would become 09:30 rather than 9:30."
  1042. :group 'org-agenda-daily/weekly
  1043. :version "24.1"
  1044. :type 'boolean)
  1045. (defcustom org-agenda-timegrid-use-ampm nil
  1046. "When set, show AM/PM style timestamps on the timegrid."
  1047. :group 'org-agenda
  1048. :version "24.1"
  1049. :type 'boolean)
  1050. (defun org-agenda-time-of-day-to-ampm (time)
  1051. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1052. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1053. (minute (substring time -2))
  1054. (ampm "am"))
  1055. (cond
  1056. ((equal hour-number 12)
  1057. (setq ampm "pm"))
  1058. ((> hour-number 12)
  1059. (setq ampm "pm")
  1060. (setq hour-number (- hour-number 12))))
  1061. (concat
  1062. (if org-agenda-time-leading-zero
  1063. (format "%02d" hour-number)
  1064. (format "%02s" (number-to-string hour-number)))
  1065. ":" minute ampm)))
  1066. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1067. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1068. (if org-agenda-timegrid-use-ampm
  1069. (org-agenda-time-of-day-to-ampm time)
  1070. time))
  1071. (defcustom org-agenda-weekend-days '(6 0)
  1072. "Which days are weekend?
  1073. These days get the special face `org-agenda-date-weekend' in the agenda
  1074. and timeline buffers."
  1075. :group 'org-agenda-daily/weekly
  1076. :type '(set :greedy t
  1077. (const :tag "Monday" 1)
  1078. (const :tag "Tuesday" 2)
  1079. (const :tag "Wednesday" 3)
  1080. (const :tag "Thursday" 4)
  1081. (const :tag "Friday" 5)
  1082. (const :tag "Saturday" 6)
  1083. (const :tag "Sunday" 0)))
  1084. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1085. "Non-nil means jump to today when moving a past date forward in time.
  1086. When using S-right in the agenda to move a a date forward, and the date
  1087. stamp currently points to the past, the first key press will move it
  1088. to today. WHen nil, just move one day forward even if the date stays
  1089. in the past."
  1090. :group 'org-agenda-daily/weekly
  1091. :version "24.1"
  1092. :type 'boolean)
  1093. (defcustom org-agenda-include-diary nil
  1094. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1095. Custom commands can set this variable in the options section."
  1096. :group 'org-agenda-daily/weekly
  1097. :type 'boolean)
  1098. (defcustom org-agenda-include-deadlines t
  1099. "If non-nil, include entries within their deadline warning period.
  1100. Custom commands can set this variable in the options section."
  1101. :group 'org-agenda-daily/weekly
  1102. :version "24.1"
  1103. :type 'boolean)
  1104. (defcustom org-agenda-show-future-repeats t
  1105. "Non-nil shows repeated entries in the future part of the agenda.
  1106. When set to the symbol `next' only the first future repeat is shown."
  1107. :group 'org-agenda-daily/weekly
  1108. :type '(choice
  1109. (const :tag "Show all repeated entries" t)
  1110. (const :tag "Show next repeated entry" next)
  1111. (const :tag "Do not show repeated entries" nil))
  1112. :version "25.2"
  1113. :package-version '(Org . "9.1")
  1114. :safe #'symbolp)
  1115. (defcustom org-agenda-prefer-last-repeat nil
  1116. "Non-nil sets date for repeated entries to their last repeat.
  1117. When non-nil, show a repeated entry at its latest repeat date,
  1118. possibly being today, instead of its base date, even if it wasn't
  1119. marked as done. This setting is useful if you do not always mark
  1120. repeated entries as done and, yet, consider that reaching repeat
  1121. date starts the task anew.
  1122. When set to a list of strings, prefer last repeats only for
  1123. entries with these TODO keywords."
  1124. :group 'org-agenda-daily/weekly
  1125. :type '(choice
  1126. (const :tag "Prefer last repeat" t)
  1127. (const :tag "Prefer base date" nil)
  1128. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1129. (string :tag "TODO keyword")))
  1130. :version "25.2"
  1131. :package-version '(Org . "9.1")
  1132. :safe (lambda (x) (or (booleanp x) (consp x))))
  1133. (defcustom org-scheduled-past-days 10000
  1134. "Number of days to continue listing scheduled items not marked DONE.
  1135. When an item is scheduled on a date, it shows up in the agenda on
  1136. this day and will be listed until it is marked done or for the
  1137. number of days given here."
  1138. :group 'org-agenda-daily/weekly
  1139. :type 'integer)
  1140. (defcustom org-agenda-log-mode-items '(closed clock)
  1141. "List of items that should be shown in agenda log mode.
  1142. \\<org-agenda-mode-map>\
  1143. This list may contain the following symbols:
  1144. closed Show entries that have been closed on that day.
  1145. clock Show entries that have received clocked time on that day.
  1146. state Show all logged state changes.
  1147. Note that instead of changing this variable, you can also press \
  1148. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1149. the agenda to display all available LOG items temporarily."
  1150. :group 'org-agenda-daily/weekly
  1151. :type '(set :greedy t (const closed) (const clock) (const state)))
  1152. (defcustom org-agenda-clock-consistency-checks
  1153. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1154. :gap-ok-around ("4:00")
  1155. :default-face ((:background "DarkRed") (:foreground "white"))
  1156. :overlap-face nil :gap-face nil :no-end-time-face nil
  1157. :long-face nil :short-face nil)
  1158. "This is a property list, with the following keys:
  1159. :max-duration Mark clocking chunks that are longer than this time.
  1160. This is a time string like \"HH:MM\", or the number
  1161. of minutes as an integer.
  1162. :min-duration Mark clocking chunks that are shorter that this.
  1163. This is a time string like \"HH:MM\", or the number
  1164. of minutes as an integer.
  1165. :max-gap Mark gaps between clocking chunks that are longer than
  1166. this duration. A number of minutes, or a string
  1167. like \"HH:MM\".
  1168. :gap-ok-around List of times during the day which are usually not working
  1169. times. When a gap is detected, but the gap contains any
  1170. of these times, the gap is *not* reported. For example,
  1171. if this is (\"4:00\" \"13:00\") then gaps that contain
  1172. 4:00 in the morning (i.e. the night) and 13:00
  1173. (i.e. a typical lunch time) do not cause a warning.
  1174. You should have at least one time during the night in this
  1175. list, or otherwise the first task each morning will trigger
  1176. a warning because it follows a long gap.
  1177. Furthermore, the following properties can be used to define faces for
  1178. issue display.
  1179. :default-face the default face, if the specific face is undefined
  1180. :overlap-face face for overlapping clocks
  1181. :gap-face face for gaps between clocks
  1182. :no-end-time-face face for incomplete clocks
  1183. :long-face face for clock intervals that are too long
  1184. :short-face face for clock intervals that are too short"
  1185. :group 'org-agenda-daily/weekly
  1186. :group 'org-clock
  1187. :version "24.1"
  1188. :type 'plist)
  1189. (defcustom org-agenda-log-mode-add-notes t
  1190. "Non-nil means add first line of notes to log entries in agenda views.
  1191. If a log item like a state change or a clock entry is associated with
  1192. notes, the first line of these notes will be added to the entry in the
  1193. agenda display."
  1194. :group 'org-agenda-daily/weekly
  1195. :type 'boolean)
  1196. (defcustom org-agenda-start-with-log-mode nil
  1197. "The initial value of log-mode in a newly created agenda window.
  1198. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1199. explanations on the possible values."
  1200. :group 'org-agenda-startup
  1201. :group 'org-agenda-daily/weekly
  1202. :type '(choice (const :tag "Don't show log items" nil)
  1203. (const :tag "Show only log items" only)
  1204. (const :tag "Show all possible log items" clockcheck)
  1205. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1206. (choice (const :tag "Show closed log items" closed)
  1207. (const :tag "Show clocked log items" clock)
  1208. (const :tag "Show all logged state changes" state)))))
  1209. (defcustom org-agenda-start-with-clockreport-mode nil
  1210. "The initial value of clockreport-mode in a newly created agenda window."
  1211. :group 'org-agenda-startup
  1212. :group 'org-agenda-daily/weekly
  1213. :type 'boolean)
  1214. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1215. "Property list with parameters for the clocktable in clockreport mode.
  1216. This is the display mode that shows a clock table in the daily/weekly
  1217. agenda, the properties for this dynamic block can be set here.
  1218. The usual clocktable parameters are allowed here, but you cannot set
  1219. the properties :name, :tstart, :tend, :block, and :scope - these will
  1220. be overwritten to make sure the content accurately reflects the
  1221. current display in the agenda."
  1222. :group 'org-agenda-daily/weekly
  1223. :type 'plist)
  1224. (defcustom org-agenda-search-view-always-boolean nil
  1225. "Non-nil means the search string is interpreted as individual parts.
  1226. The search string for search view can either be interpreted as a phrase,
  1227. or as a list of snippets that define a boolean search for a number of
  1228. strings.
  1229. When this is non-nil, the string will be split on whitespace, and each
  1230. snippet will be searched individually, and all must match in order to
  1231. select an entry. A snippet is then a single string of non-white
  1232. characters, or a string in double quotes, or a regexp in {} braces.
  1233. If a snippet is preceded by \"-\", the snippet must *not* match.
  1234. \"+\" is syntactic sugar for positive selection. Each snippet may
  1235. be found as a full word or a partial word, but see the variable
  1236. `org-agenda-search-view-force-full-words'.
  1237. When this is nil, search will look for the entire search phrase as one,
  1238. with each space character matching any amount of whitespace, including
  1239. line breaks.
  1240. Even when this is nil, you can still switch to Boolean search dynamically
  1241. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1242. is a regexp marked with braces like \"{abc}\", this will also switch to
  1243. boolean search."
  1244. :group 'org-agenda-search-view
  1245. :version "24.1"
  1246. :type 'boolean)
  1247. (defvaralias 'org-agenda-search-view-search-words-only
  1248. 'org-agenda-search-view-always-boolean)
  1249. (defcustom org-agenda-search-view-force-full-words nil
  1250. "Non-nil means, search words must be matches as complete words.
  1251. When nil, they may also match part of a word."
  1252. :group 'org-agenda-search-view
  1253. :version "24.1"
  1254. :type 'boolean)
  1255. (defcustom org-agenda-search-view-max-outline-level 0
  1256. "Maximum outline level to display in search view.
  1257. E.g. when this is set to 1, the search view will only
  1258. show headlines of level 1. When set to 0, the default
  1259. value, don't limit agenda view by outline level."
  1260. :group 'org-agenda-search-view
  1261. :version "24.4"
  1262. :package-version '(Org . "8.3")
  1263. :type 'integer)
  1264. (defgroup org-agenda-time-grid nil
  1265. "Options concerning the time grid in the Org Agenda."
  1266. :tag "Org Agenda Time Grid"
  1267. :group 'org-agenda)
  1268. (defcustom org-agenda-search-headline-for-time t
  1269. "Non-nil means search headline for a time-of-day.
  1270. If the headline contains a time-of-day in one format or another, it will
  1271. be used to sort the entry into the time sequence of items for a day.
  1272. Some people have time stamps in the headline that refer to the creation
  1273. time or so, and then this produces an unwanted side effect. If this is
  1274. the case for your, use this variable to turn off searching the headline
  1275. for a time."
  1276. :group 'org-agenda-time-grid
  1277. :type 'boolean)
  1278. (defcustom org-agenda-use-time-grid t
  1279. "Non-nil means show a time grid in the agenda schedule.
  1280. A time grid is a set of lines for specific times (like every two hours between
  1281. 8:00 and 20:00). The items scheduled for a day at specific times are
  1282. sorted in between these lines.
  1283. For details about when the grid will be shown, and what it will look like, see
  1284. the variable `org-agenda-time-grid'."
  1285. :group 'org-agenda-time-grid
  1286. :type 'boolean)
  1287. (defcustom org-agenda-time-grid
  1288. '((daily today require-timed)
  1289. "----------------"
  1290. (800 1000 1200 1400 1600 1800 2000))
  1291. "The settings for time grid for agenda display.
  1292. This is a list of three items. The first item is again a list. It contains
  1293. symbols specifying conditions when the grid should be displayed:
  1294. daily if the agenda shows a single day
  1295. weekly if the agenda shows an entire week
  1296. today show grid on current date, independent of daily/weekly display
  1297. require-timed show grid only if at least one item has a time specification
  1298. remove-match skip grid times already present in an entry
  1299. The second item is a string which will be placed behind the grid time.
  1300. The third item is a list of integers, indicating the times that should have
  1301. a grid line."
  1302. :group 'org-agenda-time-grid
  1303. :type
  1304. '(list
  1305. (set :greedy t :tag "Grid Display Options"
  1306. (const :tag "Show grid in single day agenda display" daily)
  1307. (const :tag "Show grid in weekly agenda display" weekly)
  1308. (const :tag "Always show grid for today" today)
  1309. (const :tag "Show grid only if any timed entries are present"
  1310. require-timed)
  1311. (const :tag "Skip grid times already present in an entry"
  1312. remove-match))
  1313. (string :tag "Grid String")
  1314. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1315. (defcustom org-agenda-show-current-time-in-grid t
  1316. "Non-nil means show the current time in the time grid."
  1317. :group 'org-agenda-time-grid
  1318. :version "24.1"
  1319. :type 'boolean)
  1320. (defcustom org-agenda-current-time-string
  1321. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1322. "The string for the current time marker in the agenda."
  1323. :group 'org-agenda-time-grid
  1324. :version "24.1"
  1325. :type 'string)
  1326. (defgroup org-agenda-sorting nil
  1327. "Options concerning sorting in the Org Agenda."
  1328. :tag "Org Agenda Sorting"
  1329. :group 'org-agenda)
  1330. (defcustom org-agenda-sorting-strategy
  1331. '((agenda habit-down time-up priority-down category-keep)
  1332. (todo priority-down category-keep)
  1333. (tags priority-down category-keep)
  1334. (search category-keep))
  1335. "Sorting structure for the agenda items of a single day.
  1336. This is a list of symbols which will be used in sequence to determine
  1337. if an entry should be listed before another entry. The following
  1338. symbols are recognized:
  1339. time-up Put entries with time-of-day indications first, early first
  1340. time-down Put entries with time-of-day indications first, late first
  1341. timestamp-up Sort by any timestamp, early first
  1342. timestamp-down Sort by any timestamp, late first
  1343. scheduled-up Sort by scheduled timestamp, early first
  1344. scheduled-down Sort by scheduled timestamp, late first
  1345. deadline-up Sort by deadline timestamp, early first
  1346. deadline-down Sort by deadline timestamp, late first
  1347. ts-up Sort by active timestamp, early first
  1348. ts-down Sort by active timestamp, late first
  1349. tsia-up Sort by inactive timestamp, early first
  1350. tsia-down Sort by inactive timestamp, late first
  1351. category-keep Keep the default order of categories, corresponding to the
  1352. sequence in `org-agenda-files'.
  1353. category-up Sort alphabetically by category, A-Z.
  1354. category-down Sort alphabetically by category, Z-A.
  1355. tag-up Sort alphabetically by last tag, A-Z.
  1356. tag-down Sort alphabetically by last tag, Z-A.
  1357. priority-up Sort numerically by priority, high priority last.
  1358. priority-down Sort numerically by priority, high priority first.
  1359. todo-state-up Sort by todo state, tasks that are done last.
  1360. todo-state-down Sort by todo state, tasks that are done first.
  1361. effort-up Sort numerically by estimated effort, high effort last.
  1362. effort-down Sort numerically by estimated effort, high effort first.
  1363. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1364. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1365. habit-up Put entries that are habits first
  1366. habit-down Put entries that are habits last
  1367. alpha-up Sort headlines alphabetically
  1368. alpha-down Sort headlines alphabetically, reversed
  1369. The different possibilities will be tried in sequence, and testing stops
  1370. if one comparison returns a \"not-equal\". For example, the default
  1371. '(time-up category-keep priority-down)
  1372. means: Pull out all entries having a specified time of day and sort them,
  1373. in order to make a time schedule for the current day the first thing in the
  1374. agenda listing for the day. Of the entries without a time indication, keep
  1375. the grouped in categories, don't sort the categories, but keep them in
  1376. the sequence given in `org-agenda-files'. Within each category sort by
  1377. priority.
  1378. Leaving out `category-keep' would mean that items will be sorted across
  1379. categories by priority.
  1380. Instead of a single list, this can also be a set of list for specific
  1381. contents, with a context symbol in the car of the list, any of
  1382. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1383. Custom commands can bind this variable in the options section."
  1384. :group 'org-agenda-sorting
  1385. :type `(choice
  1386. (repeat :tag "General" ,org-sorting-choice)
  1387. (list :tag "Individually"
  1388. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1389. (repeat ,org-sorting-choice))
  1390. (cons (const :tag "Strategy for TODO lists" todo)
  1391. (repeat ,org-sorting-choice))
  1392. (cons (const :tag "Strategy for Tags matches" tags)
  1393. (repeat ,org-sorting-choice))
  1394. (cons (const :tag "Strategy for search matches" search)
  1395. (repeat ,org-sorting-choice)))))
  1396. (defcustom org-agenda-cmp-user-defined nil
  1397. "A function to define the comparison `user-defined'.
  1398. This function must receive two arguments, agenda entry a and b.
  1399. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1400. the user comparison, return nil.
  1401. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1402. part of an agenda sorting strategy."
  1403. :group 'org-agenda-sorting
  1404. :type 'symbol)
  1405. (defcustom org-sort-agenda-notime-is-late t
  1406. "Non-nil means items without time are considered late.
  1407. This is only relevant for sorting. When t, items which have no explicit
  1408. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1409. do have a time. When nil, the default time is before 0:00. You can use this
  1410. option to decide if the schedule for today should come before or after timeless
  1411. agenda entries."
  1412. :group 'org-agenda-sorting
  1413. :type 'boolean)
  1414. (defcustom org-sort-agenda-noeffort-is-high t
  1415. "Non-nil means items without effort estimate are sorted as high effort.
  1416. This also applies when filtering an agenda view with respect to the
  1417. < or > effort operator. Then, tasks with no effort defined will be treated
  1418. as tasks with high effort.
  1419. When nil, such items are sorted as 0 minutes effort."
  1420. :group 'org-agenda-sorting
  1421. :type 'boolean)
  1422. (defgroup org-agenda-line-format nil
  1423. "Options concerning the entry prefix in the Org agenda display."
  1424. :tag "Org Agenda Line Format"
  1425. :group 'org-agenda)
  1426. (defcustom org-agenda-prefix-format
  1427. '((agenda . " %i %-12:c%?-12t% s")
  1428. (timeline . " % s")
  1429. (todo . " %i %-12:c")
  1430. (tags . " %i %-12:c")
  1431. (search . " %i %-12:c"))
  1432. "Format specifications for the prefix of items in the agenda views.
  1433. An alist with five entries, each for the different agenda types. The
  1434. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1435. The values are format strings.
  1436. This format works similar to a printf format, with the following meaning:
  1437. %c the category of the item, \"Diary\" for entries from the diary,
  1438. or as given by the CATEGORY keyword or derived from the file name
  1439. %e the effort required by the item
  1440. %l the level of the item (insert X space(s) if item is of level X)
  1441. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1442. %T the last tag of the item (ignore inherited tags, which come first)
  1443. %t the HH:MM time-of-day specification if one applies to the entry
  1444. %s Scheduling/Deadline information, a short string
  1445. %b show breadcrumbs, i.e., the names of the higher levels
  1446. %(expression) Eval EXPRESSION and replace the control string
  1447. by the result
  1448. All specifiers work basically like the standard `%s' of printf, but may
  1449. contain two additional characters: a question mark just after the `%'
  1450. and a whitespace/punctuation character just before the final letter.
  1451. If the first character after `%' is a question mark, the entire field
  1452. will only be included if the corresponding value applies to the current
  1453. entry. This is useful for fields which should have fixed width when
  1454. present, but zero width when absent. For example, \"%?-12t\" will
  1455. result in a 12 character time field if a time of the day is specified,
  1456. but will completely disappear in entries which do not contain a time.
  1457. If there is punctuation or whitespace character just before the
  1458. final format letter, this character will be appended to the field
  1459. value if the value is not empty. For example, the format
  1460. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1461. the category is empty, no additional colon is inserted.
  1462. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1463. which means:
  1464. - Indent the line with two space characters
  1465. - Give the category a 12 chars wide field, padded with whitespace on
  1466. the right (because of `-'). Append a colon if there is a category
  1467. (because of `:').
  1468. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1469. time, don't put in an empty field, just skip it (because of '?').
  1470. - Finally, put the scheduling information.
  1471. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1472. `org-agenda-remove-tags'.
  1473. Custom commands can set this variable in the options section."
  1474. :type '(choice
  1475. (string :tag "General format")
  1476. (list :greedy t :tag "View dependent"
  1477. (cons (const agenda) (string :tag "Format"))
  1478. (cons (const timeline) (string :tag "Format"))
  1479. (cons (const todo) (string :tag "Format"))
  1480. (cons (const tags) (string :tag "Format"))
  1481. (cons (const search) (string :tag "Format"))))
  1482. :group 'org-agenda-line-format)
  1483. (defvar org-prefix-format-compiled nil
  1484. "The compiled prefix format and associated variables.
  1485. This is a list where first element is a list of variable bindings, and second
  1486. element is the compiled format expression. See the variable
  1487. `org-agenda-prefix-format'.")
  1488. (defcustom org-agenda-todo-keyword-format "%-1s"
  1489. "Format for the TODO keyword in agenda lines.
  1490. Set this to something like \"%-12s\" if you want all TODO keywords
  1491. to occupy a fixed space in the agenda display."
  1492. :group 'org-agenda-line-format
  1493. :type 'string)
  1494. (defcustom org-agenda-diary-sexp-prefix nil
  1495. "A regexp that matches part of a diary sexp entry
  1496. which should be treated as scheduling/deadline information in
  1497. `org-agenda'.
  1498. For example, you can use this to extract the `diary-remind-message' from
  1499. `diary-remind' entries."
  1500. :group 'org-agenda-line-format
  1501. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1502. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1503. "Text preceding timerange entries in the agenda view.
  1504. This is a list with two strings. The first applies when the range
  1505. is entirely on one day. The second applies if the range spans several days.
  1506. The strings may have two \"%d\" format specifiers which will be filled
  1507. with the sequence number of the days, and the total number of days in the
  1508. range, respectively."
  1509. :group 'org-agenda-line-format
  1510. :type '(list
  1511. (string :tag "Deadline today ")
  1512. (choice :tag "Deadline relative"
  1513. (string :tag "Format string")
  1514. (function))))
  1515. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1516. "Text preceding scheduled items in the agenda view.
  1517. This is a list with two strings. The first applies when the item is
  1518. scheduled on the current day. The second applies when it has been scheduled
  1519. previously, it may contain a %d indicating that this is the nth time that
  1520. this item is scheduled, due to automatic rescheduling of unfinished items
  1521. for the following day. So this number is one larger than the number of days
  1522. that passed since this item was scheduled first."
  1523. :group 'org-agenda-line-format
  1524. :version "24.4"
  1525. :package-version '(Org . "8.0")
  1526. :type '(list
  1527. (string :tag "Scheduled today ")
  1528. (string :tag "Scheduled previously")))
  1529. (defcustom org-agenda-inactive-leader "["
  1530. "Text preceding item pulled into the agenda by inactive time stamps.
  1531. These entries are added to the agenda when pressing \"[\"."
  1532. :group 'org-agenda-line-format
  1533. :version "24.1"
  1534. :type 'string)
  1535. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1536. "Text preceding deadline items in the agenda view.
  1537. This is a list with three strings. The first applies when the item has its
  1538. deadline on the current day. The second applies when the deadline is in the
  1539. future, the third one when it is in the past. The strings may contain %d
  1540. to capture the number of days."
  1541. :group 'org-agenda-line-format
  1542. :version "24.4"
  1543. :package-version '(Org . "8.0")
  1544. :type '(list
  1545. (string :tag "Deadline today ")
  1546. (string :tag "Deadline in the future ")
  1547. (string :tag "Deadline in the past ")))
  1548. (defcustom org-agenda-remove-times-when-in-prefix t
  1549. "Non-nil means remove duplicate time specifications in agenda items.
  1550. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1551. time-of-day specification in a headline or diary entry is extracted and
  1552. placed into the prefix. If this option is non-nil, the original specification
  1553. \(a timestamp or -range, or just a plain time(range) specification like
  1554. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1555. cluttered.
  1556. The option can be t or nil. It may also be the symbol `beg', indicating
  1557. that the time should only be removed when it is located at the beginning of
  1558. the headline/diary entry."
  1559. :group 'org-agenda-line-format
  1560. :type '(choice
  1561. (const :tag "Always" t)
  1562. (const :tag "Never" nil)
  1563. (const :tag "When at beginning of entry" beg)))
  1564. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1565. "Non-nil means remove time ranges specifications in agenda
  1566. items that span on several days."
  1567. :group 'org-agenda-line-format
  1568. :version "24.1"
  1569. :type 'boolean)
  1570. (defcustom org-agenda-default-appointment-duration nil
  1571. "Default duration for appointments that only have a starting time.
  1572. When nil, no duration is specified in such cases.
  1573. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1574. :group 'org-agenda-line-format
  1575. :type '(choice
  1576. (integer :tag "Minutes")
  1577. (const :tag "No default duration")))
  1578. (defcustom org-agenda-show-inherited-tags t
  1579. "Non-nil means show inherited tags in each agenda line.
  1580. When this option is set to `always', it take precedences over
  1581. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1582. in every agenda.
  1583. When this option is set to t (the default), inherited tags are
  1584. shown when they are available, i.e. when the value of
  1585. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1586. given agenda type.
  1587. This can be set to a list of agenda types in which the agenda
  1588. must display the inherited tags. Available types are `todo',
  1589. `agenda', `search' and `timeline'.
  1590. When set to nil, never show inherited tags in agenda lines."
  1591. :group 'org-agenda-line-format
  1592. :group 'org-agenda
  1593. :version "24.3"
  1594. :type '(choice
  1595. (const :tag "Show inherited tags when available" t)
  1596. (const :tag "Always show inherited tags" always)
  1597. (repeat :tag "Show inherited tags only in selected agenda types"
  1598. (symbol :tag "Agenda type"))))
  1599. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1600. "List of agenda view types where to use tag inheritance.
  1601. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1602. controlled by `org-use-tag-inheritance'. In other agenda types,
  1603. `org-use-tag-inheritance' is not used for the selection of the
  1604. agenda entries. Still, you may want the agenda to be aware of
  1605. the inherited tags anyway, e.g. for later tag filtering.
  1606. Allowed value are `todo', `search', `timeline' and `agenda'.
  1607. This variable has no effect if `org-agenda-show-inherited-tags'
  1608. is set to `always'. In that case, the agenda is aware of those
  1609. tags.
  1610. The default value sets tags in every agenda type. Setting this
  1611. option to nil will speed up non-tags agenda view a lot."
  1612. :group 'org-agenda
  1613. :version "24.3"
  1614. :type '(choice
  1615. (const :tag "Use tag inheritance in all agenda types" t)
  1616. (repeat :tag "Use tag inheritance in selected agenda types"
  1617. (symbol :tag "Agenda type"))))
  1618. (defcustom org-agenda-hide-tags-regexp nil
  1619. "Regular expression used to filter away specific tags in agenda views.
  1620. This means that these tags will be present, but not be shown in the agenda
  1621. line. Secondary filtering will still work on the hidden tags.
  1622. Nil means don't hide any tags."
  1623. :group 'org-agenda-line-format
  1624. :type '(choice
  1625. (const :tag "Hide none" nil)
  1626. (string :tag "Regexp ")))
  1627. (defcustom org-agenda-remove-tags nil
  1628. "Non-nil means remove the tags from the headline copy in the agenda.
  1629. When this is the symbol `prefix', only remove tags when
  1630. `org-agenda-prefix-format' contains a `%T' specifier."
  1631. :group 'org-agenda-line-format
  1632. :type '(choice
  1633. (const :tag "Always" t)
  1634. (const :tag "Never" nil)
  1635. (const :tag "When prefix format contains %T" prefix)))
  1636. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1637. 'org-agenda-remove-tags)
  1638. (defcustom org-agenda-tags-column -80
  1639. "Shift tags in agenda items to this column.
  1640. If this number is positive, it specifies the column. If it is negative,
  1641. it means that the tags should be flushright to that column. For example,
  1642. -80 works well for a normal 80 character screen."
  1643. :group 'org-agenda-line-format
  1644. :type 'integer)
  1645. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1646. (defcustom org-agenda-fontify-priorities 'cookies
  1647. "Non-nil means highlight low and high priorities in agenda.
  1648. When t, the highest priority entries are bold, lowest priority italic.
  1649. However, settings in `org-priority-faces' will overrule these faces.
  1650. When this variable is the symbol `cookies', only fontify the
  1651. cookies, not the entire task.
  1652. This may also be an association list of priority faces, whose
  1653. keys are the character values of `org-highest-priority',
  1654. `org-default-priority', and `org-lowest-priority' (the default values
  1655. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1656. color as a string, or a list like `(:background \"Red\")'.
  1657. If it is a color, the variable `org-faces-easy-properties'
  1658. determines if it is a foreground or a background color."
  1659. :group 'org-agenda-line-format
  1660. :type '(choice
  1661. (const :tag "Never" nil)
  1662. (const :tag "Defaults" t)
  1663. (const :tag "Cookies only" cookies)
  1664. (repeat :tag "Specify"
  1665. (list (character :tag "Priority" :value ?A)
  1666. (choice :tag "Face "
  1667. (string :tag "Color")
  1668. (sexp :tag "Face"))))))
  1669. (defcustom org-agenda-day-face-function nil
  1670. "Function called to determine what face should be used to display a day.
  1671. The only argument passed to that function is the day. It should
  1672. returns a face, or nil if does not want to specify a face and let
  1673. the normal rules apply."
  1674. :group 'org-agenda-line-format
  1675. :version "24.1"
  1676. :type '(choice (const nil) (function)))
  1677. (defcustom org-agenda-category-icon-alist nil
  1678. "Alist of category icon to be displayed in agenda views.
  1679. Each entry should have the following format:
  1680. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1681. Where CATEGORY-REGEXP is a regexp matching the categories where
  1682. the icon should be displayed.
  1683. FILE-OR-DATA either a file path or a string containing image data.
  1684. The other fields can be omitted safely if not needed:
  1685. TYPE indicates the image type.
  1686. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1687. image data.
  1688. PROPS are additional image attributes to assign to the image,
  1689. like, e.g. `:ascent center'.
  1690. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1691. If you want to set the display properties yourself, just put a
  1692. list as second element:
  1693. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1694. For example, to display a 16px horizontal space for Emacs
  1695. category, you can use:
  1696. (\"Emacs\" \\='(space . (:width (16))))"
  1697. :group 'org-agenda-line-format
  1698. :version "24.1"
  1699. :type '(alist :key-type (string :tag "Regexp matching category")
  1700. :value-type (choice (list :tag "Icon"
  1701. (string :tag "File or data")
  1702. (symbol :tag "Type")
  1703. (boolean :tag "Data?")
  1704. (repeat :tag "Extra image properties" :inline t symbol))
  1705. (list :tag "Display properties" sexp))))
  1706. (defgroup org-agenda-column-view nil
  1707. "Options concerning column view in the agenda."
  1708. :tag "Org Agenda Column View"
  1709. :group 'org-agenda)
  1710. (defcustom org-agenda-view-columns-initially nil
  1711. "When non-nil, switch to columns view right after creating the agenda."
  1712. :group 'org-agenda-column-view
  1713. :type 'boolean
  1714. :version "25.2"
  1715. :package-version '(Org . "9.0")
  1716. :safe #'booleanp)
  1717. (defcustom org-agenda-columns-show-summaries t
  1718. "Non-nil means show summaries for columns displayed in the agenda view."
  1719. :group 'org-agenda-column-view
  1720. :type 'boolean)
  1721. (defcustom org-agenda-columns-compute-summary-properties t
  1722. "Non-nil means recompute all summary properties before column view.
  1723. When column view in the agenda is listing properties that have a summary
  1724. operator, it can go to all relevant buffers and recompute the summaries
  1725. there. This can mean overhead for the agenda column view, but is necessary
  1726. to have thing up to date.
  1727. As a special case, a CLOCKSUM property also makes sure that the clock
  1728. computations are current."
  1729. :group 'org-agenda-column-view
  1730. :type 'boolean)
  1731. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1732. "Non-nil means the duration of an appointment will add to day effort.
  1733. The property to which appointment durations will be added is the one given
  1734. in the option `org-effort-property'. If an appointment does not have
  1735. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1736. is not set, an appointment without end time will not contribute to the time
  1737. estimate."
  1738. :group 'org-agenda-column-view
  1739. :type 'boolean)
  1740. (defcustom org-agenda-auto-exclude-function nil
  1741. "A function called with a tag to decide if it is filtered on \
  1742. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1743. The sole argument to the function, which is called once for each
  1744. possible tag, is a string giving the name of the tag. The
  1745. function should return either nil if the tag should be included
  1746. as normal, or \"-<TAG>\" to exclude the tag.
  1747. Note that for the purpose of tag filtering, only the lower-case version of
  1748. all tags will be considered, so that this function will only ever see
  1749. the lower-case version of all tags."
  1750. :group 'org-agenda
  1751. :type '(choice (const nil) (function)))
  1752. (defcustom org-agenda-bulk-custom-functions nil
  1753. "Alist of characters and custom functions for bulk actions.
  1754. For example, this value makes those two functions available:
  1755. \\='((?R set-category)
  1756. (?C bulk-cut))
  1757. With selected entries in an agenda buffer, `B R' will call
  1758. the custom function `set-category' on the selected entries.
  1759. Note that functions in this alist don't need to be quoted."
  1760. :type '(alist :key-type character :value-type (group function))
  1761. :version "24.1"
  1762. :group 'org-agenda)
  1763. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1764. "Execute BODY with point at location given by `org-hd-marker' property.
  1765. If STRING is non-nil, the text property will be fetched from position 0
  1766. in that string. If STRING is nil, it will be fetched from the beginning
  1767. of the current line."
  1768. (org-with-gensyms (marker)
  1769. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1770. 'org-hd-marker ,string)))
  1771. (with-current-buffer (marker-buffer ,marker)
  1772. (save-excursion
  1773. (goto-char ,marker)
  1774. ,@body)))))
  1775. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1776. (defun org-add-agenda-custom-command (entry)
  1777. "Replace or add a command in `org-agenda-custom-commands'.
  1778. This is mostly for hacking and trying a new command - once the command
  1779. works you probably want to add it to `org-agenda-custom-commands' for good."
  1780. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1781. (if ass
  1782. (setcdr ass (cdr entry))
  1783. (push entry org-agenda-custom-commands))))
  1784. ;;; Define the org-agenda-mode
  1785. (defvar org-agenda-mode-map (make-sparse-keymap)
  1786. "Keymap for `org-agenda-mode'.")
  1787. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1788. (defvar org-agenda-menu) ; defined later in this file.
  1789. (defvar org-agenda-restrict nil) ; defined later in this file.
  1790. (defvar org-agenda-follow-mode nil)
  1791. (defvar org-agenda-entry-text-mode nil)
  1792. (defvar org-agenda-clockreport-mode nil)
  1793. (defvar org-agenda-show-log nil)
  1794. (defvar org-agenda-redo-command nil)
  1795. (defvar org-agenda-query-string nil)
  1796. (defvar org-agenda-mode-hook nil
  1797. "Hook run after `org-agenda-mode' is turned on.
  1798. The buffer is still writable when this hook is called.")
  1799. (defvar org-agenda-type nil)
  1800. (defvar org-agenda-force-single-file nil)
  1801. (defvar org-agenda-bulk-marked-entries nil
  1802. "List of markers that refer to marked entries in the agenda.")
  1803. (defvar org-agenda-current-date nil
  1804. "Active date when building the agenda.")
  1805. ;;; Multiple agenda buffers support
  1806. (defcustom org-agenda-sticky nil
  1807. "Non-nil means agenda q key will bury agenda buffers.
  1808. Agenda commands will then show existing buffer instead of generating new ones.
  1809. When nil, `q' will kill the single agenda buffer."
  1810. :group 'org-agenda
  1811. :version "24.3"
  1812. :type 'boolean)
  1813. ;;;###autoload
  1814. (defun org-toggle-sticky-agenda (&optional arg)
  1815. "Toggle `org-agenda-sticky'."
  1816. (interactive "P")
  1817. (let ((new-value (if arg
  1818. (> (prefix-numeric-value arg) 0)
  1819. (not org-agenda-sticky))))
  1820. (if (equal new-value org-agenda-sticky)
  1821. (and (called-interactively-p 'interactive)
  1822. (message "Sticky agenda was already %s"
  1823. (if org-agenda-sticky "enabled" "disabled")))
  1824. (setq org-agenda-sticky new-value)
  1825. (org-agenda-kill-all-agenda-buffers)
  1826. (and (called-interactively-p 'interactive)
  1827. (message "Sticky agenda %s"
  1828. (if org-agenda-sticky "enabled" "disabled"))))))
  1829. (defvar org-agenda-buffer nil
  1830. "Agenda buffer currently being generated.")
  1831. (defvar org-agenda-last-prefix-arg nil)
  1832. (defvar org-agenda-this-buffer-name nil)
  1833. (defvar org-agenda-doing-sticky-redo nil)
  1834. (defvar org-agenda-this-buffer-is-sticky nil)
  1835. (defvar org-agenda-last-indirect-buffer nil
  1836. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1837. (defconst org-agenda-local-vars
  1838. '(org-agenda-this-buffer-name
  1839. org-agenda-undo-list
  1840. org-agenda-pending-undo-list
  1841. org-agenda-follow-mode
  1842. org-agenda-entry-text-mode
  1843. org-agenda-clockreport-mode
  1844. org-agenda-show-log
  1845. org-agenda-redo-command
  1846. org-agenda-query-string
  1847. org-agenda-type
  1848. org-agenda-bulk-marked-entries
  1849. org-agenda-undo-has-started-in
  1850. org-agenda-info
  1851. org-agenda-pre-window-conf
  1852. org-agenda-columns-active
  1853. org-agenda-tag-filter
  1854. org-agenda-category-filter
  1855. org-agenda-top-headline-filter
  1856. org-agenda-regexp-filter
  1857. org-agenda-effort-filter
  1858. org-agenda-markers
  1859. org-agenda-last-search-view-search-was-boolean
  1860. org-agenda-last-indirect-buffer
  1861. org-agenda-filtered-by-category
  1862. org-agenda-filter-form
  1863. org-agenda-cycle-counter
  1864. org-agenda-last-prefix-arg)
  1865. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1866. (defun org-agenda-mode ()
  1867. "Mode for time-sorted view on action items in Org files.
  1868. The following commands are available:
  1869. \\{org-agenda-mode-map}"
  1870. (interactive)
  1871. (cond (org-agenda-doing-sticky-redo
  1872. ;; Refreshing sticky agenda-buffer
  1873. ;;
  1874. ;; Preserve the value of `org-agenda-local-vars' variables,
  1875. ;; while letting `kill-all-local-variables' kill the rest
  1876. (let ((save (buffer-local-variables)))
  1877. (kill-all-local-variables)
  1878. (mapc 'make-local-variable org-agenda-local-vars)
  1879. (dolist (elem save)
  1880. (let ((var (car elem))
  1881. (val (cdr elem)))
  1882. (when (and val
  1883. (member var org-agenda-local-vars))
  1884. (set var val)))))
  1885. (setq-local org-agenda-this-buffer-is-sticky t))
  1886. (org-agenda-sticky
  1887. ;; Creating a sticky Agenda buffer for the first time
  1888. (kill-all-local-variables)
  1889. (mapc 'make-local-variable org-agenda-local-vars)
  1890. (setq-local org-agenda-this-buffer-is-sticky t))
  1891. (t
  1892. ;; Creating a non-sticky agenda buffer
  1893. (kill-all-local-variables)
  1894. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1895. (setq org-agenda-undo-list nil
  1896. org-agenda-pending-undo-list nil
  1897. org-agenda-bulk-marked-entries nil)
  1898. (setq major-mode 'org-agenda-mode)
  1899. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1900. (setq-local font-lock-global-modes (list 'not major-mode))
  1901. (setq mode-name "Org-Agenda")
  1902. (setq indent-tabs-mode nil)
  1903. (use-local-map org-agenda-mode-map)
  1904. (easy-menu-add org-agenda-menu)
  1905. (if org-startup-truncated (setq truncate-lines t))
  1906. (setq-local line-move-visual nil)
  1907. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1908. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1909. ;; Make sure properties are removed when copying text
  1910. (add-hook 'filter-buffer-substring-functions
  1911. (lambda (fun start end delete)
  1912. (substring-no-properties (funcall fun start end delete)))
  1913. nil t)
  1914. (unless org-agenda-keep-modes
  1915. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1916. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1917. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1918. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1919. (add-to-invisibility-spec '(org-filtered))
  1920. (add-to-invisibility-spec '(org-link))
  1921. (easy-menu-change
  1922. '("Agenda") "Agenda Files"
  1923. (append
  1924. (list
  1925. (vector
  1926. (if (get 'org-agenda-files 'org-restrict)
  1927. "Restricted to single file"
  1928. "Edit File List")
  1929. '(org-edit-agenda-file-list)
  1930. (not (get 'org-agenda-files 'org-restrict)))
  1931. "--")
  1932. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1933. (org-agenda-set-mode-name)
  1934. (apply
  1935. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1936. (list 'org-agenda-mode-hook)))
  1937. (substitute-key-definition 'undo 'org-agenda-undo
  1938. org-agenda-mode-map global-map)
  1939. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1940. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1941. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1942. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1944. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1945. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1946. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1947. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1948. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1949. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1950. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1951. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1952. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1953. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1954. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1955. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1956. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1957. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1958. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1959. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1960. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1962. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1963. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1964. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1965. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1966. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1967. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1968. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1969. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1971. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1972. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1974. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1975. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1976. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1977. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1978. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1979. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1980. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1981. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1982. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1983. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1984. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1985. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1986. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1987. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1988. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1989. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1990. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1991. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1992. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1993. (while l (org-defkey org-agenda-mode-map
  1994. (int-to-string (pop l)) 'digit-argument)))
  1995. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1996. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1997. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1998. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1999. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2000. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2001. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2002. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2003. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2004. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  2005. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2007. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2008. 'org-clock-modify-effort-estimate)
  2009. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2010. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2011. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2012. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2013. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2014. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2015. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2016. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2017. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2018. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2019. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2020. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2021. (substitute-key-definition 'next-line 'org-agenda-next-line
  2022. org-agenda-mode-map global-map)
  2023. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2024. org-agenda-mode-map global-map)
  2025. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2026. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2027. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2028. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2029. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2030. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2031. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2032. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2033. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2034. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2035. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2036. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2038. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2039. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2040. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2041. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2042. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2043. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2044. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2045. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2046. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2047. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2048. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2049. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2050. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2051. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2052. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2053. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2054. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2055. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2056. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2057. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2058. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2059. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2060. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2061. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2062. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2063. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2064. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2065. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2066. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2067. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2068. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2069. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2070. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2071. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2072. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2073. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2074. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2075. (when org-agenda-mouse-1-follows-link
  2076. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2077. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2078. '("Agenda"
  2079. ("Agenda Files")
  2080. "--"
  2081. ("Agenda Dates"
  2082. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2083. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2084. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2085. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2086. "--"
  2087. ("View"
  2088. ["Day View" org-agenda-day-view
  2089. :active (org-agenda-check-type nil 'agenda)
  2090. :style radio :selected (eq org-agenda-current-span 'day)
  2091. :keys "v d (or just d)"]
  2092. ["Week View" org-agenda-week-view
  2093. :active (org-agenda-check-type nil 'agenda)
  2094. :style radio :selected (eq org-agenda-current-span 'week)
  2095. :keys "v w"]
  2096. ["Fortnight View" org-agenda-fortnight-view
  2097. :active (org-agenda-check-type nil 'agenda)
  2098. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2099. :keys "v f"]
  2100. ["Month View" org-agenda-month-view
  2101. :active (org-agenda-check-type nil 'agenda)
  2102. :style radio :selected (eq org-agenda-current-span 'month)
  2103. :keys "v m"]
  2104. ["Year View" org-agenda-year-view
  2105. :active (org-agenda-check-type nil 'agenda)
  2106. :style radio :selected (eq org-agenda-current-span 'year)
  2107. :keys "v y"]
  2108. "--"
  2109. ["Include Diary" org-agenda-toggle-diary
  2110. :style toggle :selected org-agenda-include-diary
  2111. :active (org-agenda-check-type nil 'agenda)]
  2112. ["Include Deadlines" org-agenda-toggle-deadlines
  2113. :style toggle :selected org-agenda-include-deadlines
  2114. :active (org-agenda-check-type nil 'agenda)]
  2115. ["Use Time Grid" org-agenda-toggle-time-grid
  2116. :style toggle :selected org-agenda-use-time-grid
  2117. :active (org-agenda-check-type nil 'agenda)]
  2118. "--"
  2119. ["Show clock report" org-agenda-clockreport-mode
  2120. :style toggle :selected org-agenda-clockreport-mode
  2121. :active (org-agenda-check-type nil 'agenda)]
  2122. ["Show some entry text" org-agenda-entry-text-mode
  2123. :style toggle :selected org-agenda-entry-text-mode
  2124. :active t]
  2125. "--"
  2126. ["Show Logbook entries" org-agenda-log-mode
  2127. :style toggle :selected org-agenda-show-log
  2128. :active (org-agenda-check-type nil 'agenda 'timeline)
  2129. :keys "v l (or just l)"]
  2130. ["Include archived trees" org-agenda-archives-mode
  2131. :style toggle :selected org-agenda-archives-mode :active t
  2132. :keys "v a"]
  2133. ["Include archive files" (org-agenda-archives-mode t)
  2134. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2135. :keys "v A"]
  2136. "--"
  2137. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2138. ["Write view to file" org-agenda-write t]
  2139. ["Rebuild buffer" org-agenda-redo t]
  2140. ["Save all Org buffers" org-save-all-org-buffers t]
  2141. "--"
  2142. ["Show original entry" org-agenda-show t]
  2143. ["Go To (other window)" org-agenda-goto t]
  2144. ["Go To (this window)" org-agenda-switch-to t]
  2145. ["Capture with cursor date" org-agenda-capture t]
  2146. ["Follow Mode" org-agenda-follow-mode
  2147. :style toggle :selected org-agenda-follow-mode :active t]
  2148. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2149. "--"
  2150. ("TODO"
  2151. ["Cycle TODO" org-agenda-todo t]
  2152. ["Next TODO set" org-agenda-todo-nextset t]
  2153. ["Previous TODO set" org-agenda-todo-previousset t]
  2154. ["Add note" org-agenda-add-note t])
  2155. ("Archive/Refile/Delete"
  2156. ["Archive default" org-agenda-archive-default t]
  2157. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2158. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2159. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2160. ["Archive subtree" org-agenda-archive t]
  2161. "--"
  2162. ["Refile" org-agenda-refile t]
  2163. "--"
  2164. ["Delete subtree" org-agenda-kill t])
  2165. ("Bulk action"
  2166. ["Mark entry" org-agenda-bulk-mark t]
  2167. ["Mark all" org-agenda-bulk-mark-all t]
  2168. ["Unmark entry" org-agenda-bulk-unmark t]
  2169. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2170. ["Toggle mark" org-agenda-bulk-toggle t]
  2171. ["Toggle all" org-agenda-bulk-toggle-all t]
  2172. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2173. ["Act on all marked" org-agenda-bulk-action t]
  2174. "--"
  2175. ("Tags and Properties"
  2176. ["Show all Tags" org-agenda-show-tags t]
  2177. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2178. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2179. "--"
  2180. ["Column View" org-columns t])
  2181. ("Deadline/Schedule"
  2182. ["Schedule" org-agenda-schedule t]
  2183. ["Set Deadline" org-agenda-deadline t]
  2184. "--"
  2185. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2188. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2189. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2190. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2191. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2192. ("Clock and Effort"
  2193. ["Clock in" org-agenda-clock-in t]
  2194. ["Clock out" org-agenda-clock-out t]
  2195. ["Clock cancel" org-agenda-clock-cancel t]
  2196. ["Goto running clock" org-clock-goto t]
  2197. "--"
  2198. ["Set Effort" org-agenda-set-effort t]
  2199. ["Change clocked effort" org-clock-modify-effort-estimate
  2200. (org-clock-is-active)])
  2201. ("Priority"
  2202. ["Set Priority" org-agenda-priority t]
  2203. ["Increase Priority" org-agenda-priority-up t]
  2204. ["Decrease Priority" org-agenda-priority-down t]
  2205. ["Show Priority" org-show-priority t])
  2206. ("Calendar/Diary"
  2207. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2208. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2209. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2210. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2211. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2212. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2213. "--"
  2214. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2215. "--"
  2216. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2217. "--"
  2218. ("MobileOrg"
  2219. ["Push Files and Views" org-mobile-push t]
  2220. ["Get Captured and Flagged" org-mobile-pull t]
  2221. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2222. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2223. "--"
  2224. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2225. "--"
  2226. ["Quit" org-agenda-quit t]
  2227. ["Exit and Release Buffers" org-agenda-exit t]
  2228. ))
  2229. ;;; Agenda undo
  2230. (defvar org-agenda-allow-remote-undo t
  2231. "Non-nil means allow remote undo from the agenda buffer.")
  2232. (defvar org-agenda-undo-has-started-in nil
  2233. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2234. (defun org-agenda-undo ()
  2235. "Undo a remote editing step in the agenda.
  2236. This undoes changes both in the agenda buffer and in the remote buffer
  2237. that have been changed along."
  2238. (interactive)
  2239. (or org-agenda-allow-remote-undo
  2240. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2241. (if (not (eq this-command last-command))
  2242. (setq org-agenda-undo-has-started-in nil
  2243. org-agenda-pending-undo-list org-agenda-undo-list))
  2244. (if (not org-agenda-pending-undo-list)
  2245. (user-error "No further undo information"))
  2246. (let* ((entry (pop org-agenda-pending-undo-list))
  2247. buf line cmd rembuf)
  2248. (setq cmd (pop entry) line (pop entry))
  2249. (setq rembuf (nth 2 entry))
  2250. (org-with-remote-undo rembuf
  2251. (while (bufferp (setq buf (pop entry)))
  2252. (if (pop entry)
  2253. (with-current-buffer buf
  2254. (let ((last-undo-buffer buf)
  2255. (inhibit-read-only t))
  2256. (unless (memq buf org-agenda-undo-has-started-in)
  2257. (push buf org-agenda-undo-has-started-in)
  2258. (make-local-variable 'pending-undo-list)
  2259. (undo-start))
  2260. (while (and pending-undo-list
  2261. (listp pending-undo-list)
  2262. (not (car pending-undo-list)))
  2263. (pop pending-undo-list))
  2264. (undo-more 1))))))
  2265. (org-goto-line line)
  2266. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2267. (defun org-verify-change-for-undo (l1 l2)
  2268. "Verify that a real change occurred between the undo lists L1 and L2."
  2269. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2270. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2271. (not (eq l1 l2)))
  2272. ;;; Agenda dispatch
  2273. (defvar org-agenda-restrict-begin (make-marker))
  2274. (defvar org-agenda-restrict-end (make-marker))
  2275. (defvar org-agenda-last-dispatch-buffer nil)
  2276. (defvar org-agenda-overriding-restriction nil)
  2277. (defcustom org-agenda-custom-commands-contexts nil
  2278. "Alist of custom agenda keys and contextual rules.
  2279. For example, if you have a custom agenda command \"p\" and you
  2280. want this command to be accessible only from plain text files,
  2281. use this:
  2282. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2283. Here are the available contexts definitions:
  2284. in-file: command displayed only in matching files
  2285. in-mode: command displayed only in matching modes
  2286. not-in-file: command not displayed in matching files
  2287. not-in-mode: command not displayed in matching modes
  2288. in-buffer: command displayed only in matching buffers
  2289. not-in-buffer: command not displayed in matching buffers
  2290. [function]: a custom function taking no argument
  2291. If you define several checks, the agenda command will be
  2292. accessible if there is at least one valid check.
  2293. You can also bind a key to another agenda custom command
  2294. depending on contextual rules.
  2295. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2296. Here it means: in .txt files, use \"p\" as the key for the
  2297. agenda command otherwise associated with \"q\". (The command
  2298. originally associated with \"q\" is not displayed to avoid
  2299. duplicates.)"
  2300. :version "24.3"
  2301. :group 'org-agenda-custom-commands
  2302. :type '(repeat (list :tag "Rule"
  2303. (string :tag " Agenda key")
  2304. (string :tag "Replace by command")
  2305. (repeat :tag "Available when"
  2306. (choice
  2307. (cons :tag "Condition"
  2308. (choice
  2309. (const :tag "In file" in-file)
  2310. (const :tag "Not in file" not-in-file)
  2311. (const :tag "In buffer" in-buffer)
  2312. (const :tag "Not in buffer" not-in-buffer)
  2313. (const :tag "In mode" in-mode)
  2314. (const :tag "Not in mode" not-in-mode))
  2315. (regexp))
  2316. (function :tag "Custom function"))))))
  2317. (defcustom org-agenda-max-entries nil
  2318. "Maximum number of entries to display in an agenda.
  2319. This can be nil (no limit) or an integer or an alist of agenda
  2320. types with an associated number of entries to display in this
  2321. type."
  2322. :version "24.4"
  2323. :package-version '(Org . "8.0")
  2324. :group 'org-agenda-custom-commands
  2325. :type '(choice (symbol :tag "No limit" nil)
  2326. (integer :tag "Max number of entries")
  2327. (repeat
  2328. (cons (choice :tag "Agenda type"
  2329. (const agenda)
  2330. (const todo)
  2331. (const tags)
  2332. (const search)
  2333. (const timeline))
  2334. (integer :tag "Max number of entries")))))
  2335. (defcustom org-agenda-max-todos nil
  2336. "Maximum number of TODOs to display in an agenda.
  2337. This can be nil (no limit) or an integer or an alist of agenda
  2338. types with an associated number of entries to display in this
  2339. type."
  2340. :version "24.4"
  2341. :package-version '(Org . "8.0")
  2342. :group 'org-agenda-custom-commands
  2343. :type '(choice (symbol :tag "No limit" nil)
  2344. (integer :tag "Max number of TODOs")
  2345. (repeat
  2346. (cons (choice :tag "Agenda type"
  2347. (const agenda)
  2348. (const todo)
  2349. (const tags)
  2350. (const search)
  2351. (const timeline))
  2352. (integer :tag "Max number of TODOs")))))
  2353. (defcustom org-agenda-max-tags nil
  2354. "Maximum number of tagged entries to display in an agenda.
  2355. This can be nil (no limit) or an integer or an alist of agenda
  2356. types with an associated number of entries to display in this
  2357. type."
  2358. :version "24.4"
  2359. :package-version '(Org . "8.0")
  2360. :group 'org-agenda-custom-commands
  2361. :type '(choice (symbol :tag "No limit" nil)
  2362. (integer :tag "Max number of tagged entries")
  2363. (repeat
  2364. (cons (choice :tag "Agenda type"
  2365. (const agenda)
  2366. (const todo)
  2367. (const tags)
  2368. (const search)
  2369. (const timeline))
  2370. (integer :tag "Max number of tagged entries")))))
  2371. (defcustom org-agenda-max-effort nil
  2372. "Maximum cumulated effort duration for the agenda.
  2373. This can be nil (no limit) or a number of minutes (as an integer)
  2374. or an alist of agenda types with an associated number of minutes
  2375. to limit entries to in this type."
  2376. :version "24.4"
  2377. :package-version '(Org . "8.0")
  2378. :group 'org-agenda-custom-commands
  2379. :type '(choice (symbol :tag "No limit" nil)
  2380. (integer :tag "Max number of minutes")
  2381. (repeat
  2382. (cons (choice :tag "Agenda type"
  2383. (const agenda)
  2384. (const todo)
  2385. (const tags)
  2386. (const search)
  2387. (const timeline))
  2388. (integer :tag "Max number of minutes")))))
  2389. (defvar org-agenda-keep-restricted-file-list nil)
  2390. (defvar org-keys nil)
  2391. (defvar org-match nil)
  2392. ;;;###autoload
  2393. (defun org-agenda (&optional arg org-keys restriction)
  2394. "Dispatch agenda commands to collect entries to the agenda buffer.
  2395. Prompts for a command to execute. Any prefix arg will be passed
  2396. on to the selected command. The default selections are:
  2397. a Call `org-agenda-list' to display the agenda for current day or week.
  2398. t Call `org-todo-list' to display the global todo list.
  2399. T Call `org-todo-list' to display the global todo list, select only
  2400. entries with a specific TODO keyword (the user gets a prompt).
  2401. m Call `org-tags-view' to display headlines with tags matching
  2402. a condition (the user is prompted for the condition).
  2403. M Like `m', but select only TODO entries, no ordinary headlines.
  2404. e Export views to associated files.
  2405. s Search entries for keywords.
  2406. S Search entries for keywords, only with TODO keywords.
  2407. / Multi occur across all agenda files and also files listed
  2408. in `org-agenda-text-search-extra-files'.
  2409. < Restrict agenda commands to buffer, subtree, or region.
  2410. Press several times to get the desired effect.
  2411. > Remove a previous restriction.
  2412. # List \"stuck\" projects.
  2413. ! Configure what \"stuck\" means.
  2414. C Configure custom agenda commands.
  2415. More commands can be added by configuring the variable
  2416. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2417. searches can be pre-defined in this way.
  2418. If the current buffer is in Org mode and visiting a file, you can also
  2419. first press `<' once to indicate that the agenda should be temporarily
  2420. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2421. Pressing `<' twice means to restrict to the current subtree or region
  2422. \(if active)."
  2423. (interactive "P")
  2424. (catch 'exit
  2425. (let* ((prefix-descriptions nil)
  2426. (org-agenda-buffer-name org-agenda-buffer-name)
  2427. (org-agenda-window-setup (if (equal (buffer-name)
  2428. org-agenda-buffer-name)
  2429. 'current-window
  2430. org-agenda-window-setup))
  2431. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2432. (org-agenda-custom-commands
  2433. ;; normalize different versions
  2434. (delq nil
  2435. (mapcar
  2436. (lambda (x)
  2437. (cond ((stringp (cdr x))
  2438. (push x prefix-descriptions)
  2439. nil)
  2440. ((stringp (nth 1 x)) x)
  2441. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2442. (t (cons (car x) (cons "" (cdr x))))))
  2443. org-agenda-custom-commands)))
  2444. (org-agenda-custom-commands
  2445. (org-contextualize-keys
  2446. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2447. (buf (current-buffer))
  2448. (bfn (buffer-file-name (buffer-base-buffer)))
  2449. entry key type org-match lprops ans)
  2450. ;; Turn off restriction unless there is an overriding one,
  2451. (unless org-agenda-overriding-restriction
  2452. (unless org-agenda-keep-restricted-file-list
  2453. ;; There is a request to keep the file list in place
  2454. (put 'org-agenda-files 'org-restrict nil))
  2455. (setq org-agenda-restrict nil)
  2456. (move-marker org-agenda-restrict-begin nil)
  2457. (move-marker org-agenda-restrict-end nil))
  2458. ;; Delete old local properties
  2459. (put 'org-agenda-redo-command 'org-lprops nil)
  2460. ;; Delete previously set last-arguments
  2461. (put 'org-agenda-redo-command 'last-args nil)
  2462. ;; Remember where this call originated
  2463. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2464. (unless org-keys
  2465. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2466. org-keys (car ans)
  2467. restriction (cdr ans)))
  2468. ;; If we have sticky agenda buffers, set a name for the buffer,
  2469. ;; depending on the invoking keys. The user may still set this
  2470. ;; as a command option, which will overwrite what we do here.
  2471. (if org-agenda-sticky
  2472. (setq org-agenda-buffer-name
  2473. (format "*Org Agenda(%s)*" org-keys)))
  2474. ;; Establish the restriction, if any
  2475. (when (and (not org-agenda-overriding-restriction) restriction)
  2476. (put 'org-agenda-files 'org-restrict (list bfn))
  2477. (cond
  2478. ((eq restriction 'region)
  2479. (setq org-agenda-restrict (current-buffer))
  2480. (move-marker org-agenda-restrict-begin (region-beginning))
  2481. (move-marker org-agenda-restrict-end (region-end)))
  2482. ((eq restriction 'subtree)
  2483. (save-excursion
  2484. (setq org-agenda-restrict (current-buffer))
  2485. (org-back-to-heading t)
  2486. (move-marker org-agenda-restrict-begin (point))
  2487. (move-marker org-agenda-restrict-end
  2488. (progn (org-end-of-subtree t)))))))
  2489. ;; For example the todo list should not need it (but does...)
  2490. (cond
  2491. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2492. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2493. (progn
  2494. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2495. lprops (nth 4 entry))
  2496. (if org-agenda-sticky
  2497. (setq org-agenda-buffer-name
  2498. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2499. (format "*Org Agenda(%s)*" org-keys))))
  2500. (put 'org-agenda-redo-command 'org-lprops lprops)
  2501. (cond
  2502. ((eq type 'agenda)
  2503. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2504. ((eq type 'agenda*)
  2505. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2506. ((eq type 'alltodo)
  2507. (org-let lprops '(org-todo-list current-prefix-arg)))
  2508. ((eq type 'search)
  2509. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2510. ((eq type 'stuck)
  2511. (org-let lprops '(org-agenda-list-stuck-projects
  2512. current-prefix-arg)))
  2513. ((eq type 'tags)
  2514. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2515. ((eq type 'tags-todo)
  2516. (org-let lprops '(org-tags-view '(4) org-match)))
  2517. ((eq type 'todo)
  2518. (org-let lprops '(org-todo-list org-match)))
  2519. ((eq type 'tags-tree)
  2520. (org-check-for-org-mode)
  2521. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2522. ((eq type 'todo-tree)
  2523. (org-check-for-org-mode)
  2524. (org-let lprops
  2525. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2526. (regexp-quote org-match) "\\>"))))
  2527. ((eq type 'occur-tree)
  2528. (org-check-for-org-mode)
  2529. (org-let lprops '(org-occur org-match)))
  2530. ((functionp type)
  2531. (org-let lprops '(funcall type org-match)))
  2532. ((fboundp type)
  2533. (org-let lprops '(funcall type org-match)))
  2534. (t (user-error "Invalid custom agenda command type %s" type))))
  2535. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2536. ((equal org-keys "C")
  2537. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2538. (customize-variable 'org-agenda-custom-commands))
  2539. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2540. ((equal org-keys "s") (call-interactively 'org-search-view))
  2541. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2542. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2543. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2544. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2545. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2546. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2547. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2548. (add-hook
  2549. 'post-command-hook
  2550. (lambda ()
  2551. (unless (current-message)
  2552. (let* ((m (org-agenda-get-any-marker))
  2553. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2554. (when note
  2555. (message (concat
  2556. "FLAGGING-NOTE ([?] for more info): "
  2557. (org-add-props
  2558. (replace-regexp-in-string
  2559. "\\\\n" "//"
  2560. (copy-sequence note))
  2561. nil 'face 'org-warning)))))))
  2562. t t))
  2563. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2564. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2565. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2566. (t (user-error "Invalid agenda key"))))))
  2567. (defvar org-agenda-multi)
  2568. (defun org-agenda-append-agenda ()
  2569. "Append another agenda view to the current one.
  2570. This function allows interactive building of block agendas.
  2571. Agenda views are separated by `org-agenda-block-separator'."
  2572. (interactive)
  2573. (unless (derived-mode-p 'org-agenda-mode)
  2574. (user-error "Can only append from within agenda buffer"))
  2575. (let ((org-agenda-multi t))
  2576. (org-agenda)
  2577. (widen)
  2578. (org-agenda-finalize)
  2579. (setq buffer-read-only t)
  2580. (org-agenda-fit-window-to-buffer)))
  2581. (defun org-agenda-normalize-custom-commands (cmds)
  2582. "Normalize custom commands CMDS."
  2583. (delq nil
  2584. (mapcar
  2585. (lambda (x)
  2586. (cond ((stringp (cdr x)) nil)
  2587. ((stringp (nth 1 x)) x)
  2588. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2589. (t (cons (car x) (cons "" (cdr x))))))
  2590. cmds)))
  2591. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2592. "The user interface for selecting an agenda command."
  2593. (catch 'exit
  2594. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2595. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2596. (region-p (org-region-active-p))
  2597. (custom org-agenda-custom-commands)
  2598. (selstring "")
  2599. restriction second-time
  2600. c entry key type match prefixes rmheader header-end custom1 desc
  2601. line lines left right n n1)
  2602. (save-window-excursion
  2603. (delete-other-windows)
  2604. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2605. (erase-buffer)
  2606. (insert (eval-when-compile
  2607. (let ((header
  2608. "Press key for an agenda command:
  2609. -------------------------------- < Buffer, subtree/region restriction
  2610. a Agenda for current week or day > Remove restriction
  2611. t List of all TODO entries e Export agenda views
  2612. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2613. s Search for keywords M Like m, but only TODO entries
  2614. / Multi-occur S Like s, but only TODO entries
  2615. ? Find :FLAGGED: entries C Configure custom agenda commands
  2616. * Toggle sticky agenda views # List stuck projects (!=configure)
  2617. ")
  2618. (start 0))
  2619. (while (string-match
  2620. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2621. header start)
  2622. (setq start (match-end 0))
  2623. (add-text-properties (match-beginning 2) (match-end 2)
  2624. '(face bold) header))
  2625. header)))
  2626. (setq header-end (point-marker))
  2627. (while t
  2628. (setq custom1 custom)
  2629. (when (eq rmheader t)
  2630. (org-goto-line 1)
  2631. (re-search-forward ":" nil t)
  2632. (delete-region (match-end 0) (point-at-eol))
  2633. (forward-char 1)
  2634. (looking-at "-+")
  2635. (delete-region (match-end 0) (point-at-eol))
  2636. (move-marker header-end (match-end 0)))
  2637. (goto-char header-end)
  2638. (delete-region (point) (point-max))
  2639. ;; Produce all the lines that describe custom commands and prefixes
  2640. (setq lines nil)
  2641. (while (setq entry (pop custom1))
  2642. (setq key (car entry) desc (nth 1 entry)
  2643. type (nth 2 entry)
  2644. match (nth 3 entry))
  2645. (if (> (length key) 1)
  2646. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2647. (setq line
  2648. (format
  2649. "%-4s%-14s"
  2650. (org-add-props (copy-sequence key)
  2651. '(face bold))
  2652. (cond
  2653. ((string-match "\\S-" desc) desc)
  2654. ((eq type 'agenda) "Agenda for current week or day")
  2655. ((eq type 'agenda*) "Appointments for current week or day")
  2656. ((eq type 'alltodo) "List of all TODO entries")
  2657. ((eq type 'search) "Word search")
  2658. ((eq type 'stuck) "List of stuck projects")
  2659. ((eq type 'todo) "TODO keyword")
  2660. ((eq type 'tags) "Tags query")
  2661. ((eq type 'tags-todo) "Tags (TODO)")
  2662. ((eq type 'tags-tree) "Tags tree")
  2663. ((eq type 'todo-tree) "TODO kwd tree")
  2664. ((eq type 'occur-tree) "Occur tree")
  2665. ((functionp type) (if (symbolp type)
  2666. (symbol-name type)
  2667. "Lambda expression"))
  2668. (t "???"))))
  2669. (if org-agenda-menu-show-matcher
  2670. (setq line
  2671. (concat line ": "
  2672. (cond
  2673. ((stringp match)
  2674. (setq match (copy-sequence match))
  2675. (org-add-props match nil 'face 'org-warning))
  2676. ((listp type)
  2677. (format "set of %d commands" (length type))))))
  2678. (if (org-string-nw-p match)
  2679. (add-text-properties
  2680. 0 (length line) (list 'help-echo
  2681. (concat "Matcher: " match)) line)))
  2682. (push line lines)))
  2683. (setq lines (nreverse lines))
  2684. (when prefixes
  2685. (mapc (lambda (x)
  2686. (push
  2687. (format "%s %s"
  2688. (org-add-props (char-to-string x)
  2689. nil 'face 'bold)
  2690. (or (cdr (assoc (concat selstring
  2691. (char-to-string x))
  2692. prefix-descriptions))
  2693. "Prefix key"))
  2694. lines))
  2695. prefixes))
  2696. ;; Check if we should display in two columns
  2697. (if org-agenda-menu-two-columns
  2698. (progn
  2699. (setq n (length lines)
  2700. n1 (+ (/ n 2) (mod n 2))
  2701. right (nthcdr n1 lines)
  2702. left (copy-sequence lines))
  2703. (setcdr (nthcdr (1- n1) left) nil))
  2704. (setq left lines right nil))
  2705. (while left
  2706. (insert "\n" (pop left))
  2707. (when right
  2708. (if (< (current-column) 40)
  2709. (move-to-column 40 t)
  2710. (insert " "))
  2711. (insert (pop right))))
  2712. ;; Make the window the right size
  2713. (goto-char (point-min))
  2714. (if second-time
  2715. (if (not (pos-visible-in-window-p (point-max)))
  2716. (org-fit-window-to-buffer))
  2717. (setq second-time t)
  2718. (org-fit-window-to-buffer))
  2719. ;; Ask for selection
  2720. (message "Press key for agenda command%s:"
  2721. (if (or restrict-ok org-agenda-overriding-restriction)
  2722. (if org-agenda-overriding-restriction
  2723. " (restriction lock active)"
  2724. (if restriction
  2725. (format " (restricted to %s)" restriction)
  2726. " (unrestricted)"))
  2727. ""))
  2728. (setq c (read-char-exclusive))
  2729. (message "")
  2730. (cond
  2731. ((assoc (char-to-string c) custom)
  2732. (setq selstring (concat selstring (char-to-string c)))
  2733. (throw 'exit (cons selstring restriction)))
  2734. ((memq c prefixes)
  2735. (setq selstring (concat selstring (char-to-string c))
  2736. prefixes nil
  2737. rmheader (or rmheader t)
  2738. custom (delq nil (mapcar
  2739. (lambda (x)
  2740. (if (or (= (length (car x)) 1)
  2741. (/= (string-to-char (car x)) c))
  2742. nil
  2743. (cons (substring (car x) 1) (cdr x))))
  2744. custom))))
  2745. ((eq c ?*)
  2746. (call-interactively 'org-toggle-sticky-agenda)
  2747. (sit-for 2))
  2748. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2749. (message "Restriction is only possible in Org buffers")
  2750. (ding) (sit-for 1))
  2751. ((eq c ?1)
  2752. (org-agenda-remove-restriction-lock 'noupdate)
  2753. (setq restriction 'buffer))
  2754. ((eq c ?0)
  2755. (org-agenda-remove-restriction-lock 'noupdate)
  2756. (setq restriction (if region-p 'region 'subtree)))
  2757. ((eq c ?<)
  2758. (org-agenda-remove-restriction-lock 'noupdate)
  2759. (setq restriction
  2760. (cond
  2761. ((eq restriction 'buffer)
  2762. (if region-p 'region 'subtree))
  2763. ((memq restriction '(subtree region))
  2764. nil)
  2765. (t 'buffer))))
  2766. ((eq c ?>)
  2767. (org-agenda-remove-restriction-lock 'noupdate)
  2768. (setq restriction nil))
  2769. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2770. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2771. ((and (> (length selstring) 0) (eq c ?\d))
  2772. (delete-window)
  2773. (org-agenda-get-restriction-and-command prefix-descriptions))
  2774. ((equal c ?q) (error "Abort"))
  2775. (t (user-error "Invalid key %c" c))))))))
  2776. (defun org-agenda-fit-window-to-buffer ()
  2777. "Fit the window to the buffer size."
  2778. (and (memq org-agenda-window-setup '(reorganize-frame))
  2779. (fboundp 'fit-window-to-buffer)
  2780. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2781. (= (car org-agenda-window-frame-fractions) 1.0))
  2782. (delete-other-windows)
  2783. (org-fit-window-to-buffer
  2784. nil
  2785. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2786. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2787. (defvar org-cmd nil)
  2788. (defvar org-agenda-overriding-cmd nil)
  2789. (defvar org-agenda-overriding-arguments nil)
  2790. (defvar org-agenda-overriding-cmd-arguments nil)
  2791. (defun org-agenda-run-series (name series)
  2792. "Run agenda NAME as a SERIES of agenda commands."
  2793. (org-let (nth 1 series) '(org-agenda-prepare name))
  2794. ;; We need to reset agenda markers here, because when constructing a
  2795. ;; block agenda, the individual blocks do not do that.
  2796. (org-agenda-reset-markers)
  2797. (let* ((org-agenda-multi t)
  2798. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2799. (cmds (car series))
  2800. (gprops (nth 1 series))
  2801. match ;; The byte compiler incorrectly complains about this. Keep it!
  2802. org-cmd type lprops)
  2803. (while (setq org-cmd (pop cmds))
  2804. (setq type (car org-cmd))
  2805. (setq match (eval (nth 1 org-cmd)))
  2806. (setq lprops (nth 2 org-cmd))
  2807. (let ((org-agenda-overriding-arguments
  2808. (if (eq org-agenda-overriding-cmd org-cmd)
  2809. (or org-agenda-overriding-arguments
  2810. org-agenda-overriding-cmd-arguments))))
  2811. (cond
  2812. ((eq type 'agenda)
  2813. (org-let2 gprops lprops
  2814. '(call-interactively 'org-agenda-list)))
  2815. ((eq type 'agenda*)
  2816. (org-let2 gprops lprops
  2817. '(funcall 'org-agenda-list nil nil t)))
  2818. ((eq type 'alltodo)
  2819. (org-let2 gprops lprops
  2820. '(call-interactively 'org-todo-list)))
  2821. ((eq type 'search)
  2822. (org-let2 gprops lprops
  2823. '(org-search-view current-prefix-arg match nil)))
  2824. ((eq type 'stuck)
  2825. (org-let2 gprops lprops
  2826. '(call-interactively 'org-agenda-list-stuck-projects)))
  2827. ((eq type 'tags)
  2828. (org-let2 gprops lprops
  2829. '(org-tags-view current-prefix-arg match)))
  2830. ((eq type 'tags-todo)
  2831. (org-let2 gprops lprops
  2832. '(org-tags-view '(4) match)))
  2833. ((eq type 'todo)
  2834. (org-let2 gprops lprops
  2835. '(org-todo-list match)))
  2836. ((fboundp type)
  2837. (org-let2 gprops lprops
  2838. '(funcall type match)))
  2839. (t (error "Invalid type in command series")))))
  2840. (widen)
  2841. (let ((inhibit-read-only t))
  2842. (add-text-properties (point-min) (point-max)
  2843. `(org-series t org-series-redo-cmd ,redo)))
  2844. (setq org-agenda-redo-command redo)
  2845. (goto-char (point-min)))
  2846. (org-agenda-fit-window-to-buffer)
  2847. (org-let (nth 1 series) '(org-agenda-finalize)))
  2848. ;;;###autoload
  2849. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2850. "Run an agenda command in batch mode and send the result to STDOUT.
  2851. If CMD-KEY is a string of length 1, it is used as a key in
  2852. `org-agenda-custom-commands' and triggers this command. If it is a
  2853. longer string it is used as a tags/todo match string.
  2854. Parameters are alternating variable names and values that will be bound
  2855. before running the agenda command."
  2856. (org-eval-in-environment (org-make-parameter-alist parameters)
  2857. (let (org-agenda-sticky)
  2858. (if (> (length cmd-key) 1)
  2859. (org-tags-view nil cmd-key)
  2860. (org-agenda nil cmd-key))))
  2861. (set-buffer org-agenda-buffer-name)
  2862. (princ (buffer-string)))
  2863. (defvar org-agenda-info nil)
  2864. ;;;###autoload
  2865. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2866. "Run an agenda command in batch mode and send the result to STDOUT.
  2867. If CMD-KEY is a string of length 1, it is used as a key in
  2868. `org-agenda-custom-commands' and triggers this command. If it is a
  2869. longer string it is used as a tags/todo match string.
  2870. Parameters are alternating variable names and values that will be bound
  2871. before running the agenda command.
  2872. The output gives a line for each selected agenda item. Each
  2873. item is a list of comma-separated values, like this:
  2874. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2875. category The category of the item
  2876. head The headline, without TODO kwd, TAGS and PRIORITY
  2877. type The type of the agenda entry, can be
  2878. todo selected in TODO match
  2879. tagsmatch selected in tags match
  2880. diary imported from diary
  2881. deadline a deadline on given date
  2882. scheduled scheduled on given date
  2883. timestamp entry has timestamp on given date
  2884. closed entry was closed on given date
  2885. upcoming-deadline warning about deadline
  2886. past-scheduled forwarded scheduled item
  2887. block entry has date block including g. date
  2888. todo The todo keyword, if any
  2889. tags All tags including inherited ones, separated by colons
  2890. date The relevant date, like 2007-2-14
  2891. time The time, like 15:00-16:50
  2892. extra Sting with extra planning info
  2893. priority-l The priority letter if any was given
  2894. priority-n The computed numerical priority
  2895. agenda-day The day in the agenda where this is listed"
  2896. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2897. (org-make-parameter-alist parameters))
  2898. (if (> (length cmd-key) 2)
  2899. (org-tags-view nil cmd-key)
  2900. (org-agenda nil cmd-key)))
  2901. (set-buffer org-agenda-buffer-name)
  2902. (let* ((lines (org-split-string (buffer-string) "\n"))
  2903. line)
  2904. (while (setq line (pop lines))
  2905. (catch 'next
  2906. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2907. (setq org-agenda-info
  2908. (org-fix-agenda-info (text-properties-at 0 line)))
  2909. (princ
  2910. (mapconcat 'org-agenda-export-csv-mapper
  2911. '(org-category txt type todo tags date time extra
  2912. priority-letter priority agenda-day)
  2913. ","))
  2914. (princ "\n")))))
  2915. (defun org-fix-agenda-info (props)
  2916. "Make sure all properties on an agenda item have a canonical form.
  2917. This ensures the export commands can easily use it."
  2918. (let (tmp re)
  2919. (when (setq tmp (plist-get props 'tags))
  2920. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2921. (when (setq tmp (plist-get props 'date))
  2922. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2923. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2924. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2925. (setq tmp (calendar-date-string tmp)))
  2926. (setq props (plist-put props 'date tmp)))
  2927. (when (setq tmp (plist-get props 'day))
  2928. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2929. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2930. (setq tmp (calendar-date-string tmp)))
  2931. (setq props (plist-put props 'day tmp))
  2932. (setq props (plist-put props 'agenda-day tmp)))
  2933. (when (setq tmp (plist-get props 'txt))
  2934. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2935. (plist-put props 'priority-letter (match-string 1 tmp))
  2936. (setq tmp (replace-match "" t t tmp)))
  2937. (when (and (setq re (plist-get props 'org-todo-regexp))
  2938. (setq re (concat "\\`\\.*" re " ?"))
  2939. (let ((case-fold-search nil)) (string-match re tmp)))
  2940. (plist-put props 'todo (match-string 1 tmp))
  2941. (setq tmp (replace-match "" t t tmp)))
  2942. (plist-put props 'txt tmp)))
  2943. props)
  2944. (defun org-agenda-export-csv-mapper (prop)
  2945. (let ((res (plist-get org-agenda-info prop)))
  2946. (setq res
  2947. (cond
  2948. ((not res) "")
  2949. ((stringp res) res)
  2950. (t (prin1-to-string res))))
  2951. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2952. ;;;###autoload
  2953. (defun org-store-agenda-views (&rest parameters)
  2954. "Store agenda views."
  2955. (interactive)
  2956. (eval (list 'org-batch-store-agenda-views)))
  2957. ;;;###autoload
  2958. (defmacro org-batch-store-agenda-views (&rest parameters)
  2959. "Run all custom agenda commands that have a file argument."
  2960. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2961. (pop-up-frames nil)
  2962. (dir default-directory)
  2963. (pars (org-make-parameter-alist parameters))
  2964. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2965. (save-window-excursion
  2966. (while cmds
  2967. (setq cmd (pop cmds)
  2968. thiscmdkey (car cmd)
  2969. thiscmdcmd (cdr cmd)
  2970. match (nth 2 thiscmdcmd)
  2971. bufname (if org-agenda-sticky
  2972. (or (and (stringp match)
  2973. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2974. (format "*Org Agenda(%s)*" thiscmdkey))
  2975. org-agenda-buffer-name)
  2976. cmd-or-set (nth 2 cmd)
  2977. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2978. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2979. (if (stringp files) (setq files (list files)))
  2980. (when files
  2981. (org-eval-in-environment (append org-agenda-exporter-settings
  2982. opts pars)
  2983. (org-agenda nil thiscmdkey))
  2984. (set-buffer bufname)
  2985. (while files
  2986. (org-eval-in-environment (append org-agenda-exporter-settings
  2987. opts pars)
  2988. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2989. (and (get-buffer bufname)
  2990. (kill-buffer bufname)))))))
  2991. (defvar org-agenda-current-span nil
  2992. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2993. (defun org-agenda-mark-header-line (pos)
  2994. "Mark the line at POS as an agenda structure header."
  2995. (save-excursion
  2996. (goto-char pos)
  2997. (put-text-property (point-at-bol) (point-at-eol)
  2998. 'org-agenda-structural-header t)
  2999. (when org-agenda-title-append
  3000. (put-text-property (point-at-bol) (point-at-eol)
  3001. 'org-agenda-title-append org-agenda-title-append))))
  3002. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3003. (defvar org-agenda-write-buffer-name "Agenda View")
  3004. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3005. "Write the current buffer (an agenda view) as a file.
  3006. Depending on the extension of the file name, plain text (.txt),
  3007. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3008. If the extension is .ics, translate visible agenda into iCalendar
  3009. format. If the extension is .org, collect all subtrees
  3010. corresponding to the agenda entries and add them in an .org file.
  3011. With prefix argument OPEN, open the new file immediately. If
  3012. NOSETTINGS is given, do not scope the settings of
  3013. `org-agenda-exporter-settings' into the export commands. This is
  3014. used when the settings have already been scoped and we do not
  3015. wish to overrule other, higher priority settings. If
  3016. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3017. the agenda to write."
  3018. (interactive "FWrite agenda to file: \nP")
  3019. (if (or (not (file-writable-p file))
  3020. (and (file-exists-p file)
  3021. (if (called-interactively-p 'any)
  3022. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3023. (user-error "Cannot write agenda to file %s" file))
  3024. (org-let (if nosettings nil org-agenda-exporter-settings)
  3025. '(save-excursion
  3026. (save-window-excursion
  3027. (let ((bs (copy-sequence (buffer-string)))
  3028. (extension (file-name-extension file))
  3029. beg content)
  3030. (with-temp-buffer
  3031. (rename-buffer org-agenda-write-buffer-name t)
  3032. (set-buffer-modified-p nil)
  3033. (insert bs)
  3034. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3035. (run-hooks 'org-agenda-before-write-hook)
  3036. (cond
  3037. ((bound-and-true-p org-mobile-creating-agendas)
  3038. (org-mobile-write-agenda-for-mobile file))
  3039. ((string= "org" extension)
  3040. (let (content p m message-log-max)
  3041. (goto-char (point-min))
  3042. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3043. (goto-char p)
  3044. (setq m (get-text-property (point) 'org-hd-marker))
  3045. (when m
  3046. (push (save-excursion
  3047. (set-buffer (marker-buffer m))
  3048. (goto-char m)
  3049. (org-copy-subtree 1 nil t t)
  3050. org-subtree-clip)
  3051. content)))
  3052. (find-file file)
  3053. (erase-buffer)
  3054. (dolist (s content) (org-paste-subtree 1 s))
  3055. (write-file file)
  3056. (kill-buffer (current-buffer))
  3057. (message "Org file written to %s" file)))
  3058. ((member extension '("html" "htm"))
  3059. (require 'htmlize)
  3060. (set-buffer (htmlize-buffer (current-buffer)))
  3061. (when org-agenda-export-html-style
  3062. ;; replace <style> section with org-agenda-export-html-style
  3063. (goto-char (point-min))
  3064. (kill-region (- (search-forward "<style") 6)
  3065. (search-forward "</style>"))
  3066. (insert org-agenda-export-html-style))
  3067. (write-file file)
  3068. (kill-buffer (current-buffer))
  3069. (message "HTML written to %s" file))
  3070. ((string= "ps" extension)
  3071. (require 'ps-print)
  3072. (ps-print-buffer-with-faces file)
  3073. (message "Postscript written to %s" file))
  3074. ((string= "pdf" extension)
  3075. (require 'ps-print)
  3076. (ps-print-buffer-with-faces
  3077. (concat (file-name-sans-extension file) ".ps"))
  3078. (call-process "ps2pdf" nil nil nil
  3079. (expand-file-name
  3080. (concat (file-name-sans-extension file) ".ps"))
  3081. (expand-file-name file))
  3082. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3083. (message "PDF written to %s" file))
  3084. ((string= "ics" extension)
  3085. (require 'ox-icalendar)
  3086. (org-icalendar-export-current-agenda (expand-file-name file)))
  3087. (t
  3088. (let ((bs (buffer-string)))
  3089. (find-file file)
  3090. (erase-buffer)
  3091. (insert bs)
  3092. (save-buffer 0)
  3093. (kill-buffer (current-buffer))
  3094. (message "Plain text written to %s" file))))))))
  3095. (set-buffer (or agenda-bufname
  3096. (and (called-interactively-p 'any) (buffer-name))
  3097. org-agenda-buffer-name)))
  3098. (when open (org-open-file file)))
  3099. (defun org-agenda-remove-marked-text (property &optional value)
  3100. "Delete all text marked with VALUE of PROPERTY.
  3101. VALUE defaults to t."
  3102. (let (beg)
  3103. (setq value (or value t))
  3104. (while (setq beg (text-property-any (point-min) (point-max)
  3105. property value))
  3106. (delete-region
  3107. beg (or (next-single-property-change beg property)
  3108. (point-max))))))
  3109. (defun org-agenda-add-entry-text ()
  3110. "Add entry text to agenda lines.
  3111. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3112. entry text following headings shown in the agenda.
  3113. Drawers will be excluded, also the line with scheduling/deadline info."
  3114. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3115. (not (bound-and-true-p org-mobile-creating-agendas)))
  3116. (let (m txt)
  3117. (goto-char (point-min))
  3118. (while (not (eobp))
  3119. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3120. (beginning-of-line 2)
  3121. (setq txt (org-agenda-get-some-entry-text
  3122. m org-agenda-add-entry-text-maxlines " > "))
  3123. (end-of-line 1)
  3124. (if (string-match "\\S-" txt)
  3125. (insert "\n" txt)
  3126. (or (eobp) (forward-char 1))))))))
  3127. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3128. &rest keep)
  3129. "Extract entry text from MARKER, at most N-LINES lines.
  3130. This will ignore drawers etc, just get the text.
  3131. If INDENT is given, prefix every line with this string. If KEEP is
  3132. given, it is a list of symbols, defining stuff that should not be
  3133. removed from the entry content. Currently only `planning' is allowed here."
  3134. (let (txt drawer-re kwd-time-re ind)
  3135. (save-excursion
  3136. (with-current-buffer (marker-buffer marker)
  3137. (if (not (derived-mode-p 'org-mode))
  3138. (setq txt "")
  3139. (org-with-wide-buffer
  3140. (goto-char marker)
  3141. (end-of-line 1)
  3142. (setq txt (buffer-substring
  3143. (min (1+ (point)) (point-max))
  3144. (progn (outline-next-heading) (point)))
  3145. drawer-re org-drawer-regexp
  3146. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3147. ".*\n?"))
  3148. (with-temp-buffer
  3149. (insert txt)
  3150. (when org-agenda-add-entry-text-descriptive-links
  3151. (goto-char (point-min))
  3152. (while (org-activate-bracket-links (point-max))
  3153. (add-text-properties (match-beginning 0) (match-end 0)
  3154. '(face org-link))))
  3155. (goto-char (point-min))
  3156. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3157. (set-text-properties (match-beginning 0) (match-end 0)
  3158. nil))
  3159. (goto-char (point-min))
  3160. (while (re-search-forward drawer-re nil t)
  3161. (delete-region
  3162. (match-beginning 0)
  3163. (progn (re-search-forward
  3164. "^[ \t]*:END:.*\n?" nil 'move)
  3165. (point))))
  3166. (unless (member 'planning keep)
  3167. (goto-char (point-min))
  3168. (while (re-search-forward kwd-time-re nil t)
  3169. (replace-match "")))
  3170. (goto-char (point-min))
  3171. (when org-agenda-entry-text-exclude-regexps
  3172. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3173. (while (setq re (pop re-list))
  3174. (goto-char (point-min))
  3175. (while (re-search-forward re nil t)
  3176. (replace-match "")))))
  3177. (goto-char (point-max))
  3178. (skip-chars-backward " \t\n")
  3179. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3180. ;; find and remove min common indentation
  3181. (goto-char (point-min))
  3182. (untabify (point-min) (point-max))
  3183. (setq ind (org-get-indentation))
  3184. (while (not (eobp))
  3185. (unless (looking-at "[ \t]*$")
  3186. (setq ind (min ind (org-get-indentation))))
  3187. (beginning-of-line 2))
  3188. (goto-char (point-min))
  3189. (while (not (eobp))
  3190. (unless (looking-at "[ \t]*$")
  3191. (move-to-column ind)
  3192. (delete-region (point-at-bol) (point)))
  3193. (beginning-of-line 2))
  3194. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3195. (goto-char (point-min))
  3196. (when indent
  3197. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3198. (replace-match indent t t)))
  3199. (goto-char (point-min))
  3200. (while (looking-at "[ \t]*\n") (replace-match ""))
  3201. (goto-char (point-max))
  3202. (when (> (org-current-line)
  3203. n-lines)
  3204. (org-goto-line (1+ n-lines))
  3205. (backward-char 1))
  3206. (setq txt (buffer-substring (point-min) (point))))))))
  3207. txt))
  3208. (defun org-check-for-org-mode ()
  3209. "Make sure current buffer is in org-mode. Error if not."
  3210. (or (derived-mode-p 'org-mode)
  3211. (error "Cannot execute Org agenda command on buffer in %s"
  3212. major-mode)))
  3213. ;;; Agenda prepare and finalize
  3214. (defvar org-agenda-multi nil) ; dynamically scoped
  3215. (defvar org-agenda-pre-window-conf nil)
  3216. (defvar org-agenda-columns-active nil)
  3217. (defvar org-agenda-name nil)
  3218. (defvar org-agenda-tag-filter nil)
  3219. (defvar org-agenda-category-filter nil)
  3220. (defvar org-agenda-regexp-filter nil)
  3221. (defvar org-agenda-effort-filter nil)
  3222. (defvar org-agenda-top-headline-filter nil)
  3223. (defvar org-agenda-tag-filter-preset nil
  3224. "A preset of the tags filter used for secondary agenda filtering.
  3225. This must be a list of strings, each string must be a single tag preceded
  3226. by \"+\" or \"-\".
  3227. This variable should not be set directly, but agenda custom commands can
  3228. bind it in the options section. The preset filter is a global property of
  3229. the entire agenda view. In a block agenda, it will not work reliably to
  3230. define a filter for one of the individual blocks. You need to set it in
  3231. the global options and expect it to be applied to the entire view.")
  3232. (defvar org-agenda-category-filter-preset nil
  3233. "A preset of the category filter used for secondary agenda filtering.
  3234. This must be a list of strings, each string must be a single category
  3235. preceded by \"+\" or \"-\".
  3236. This variable should not be set directly, but agenda custom commands can
  3237. bind it in the options section. The preset filter is a global property of
  3238. the entire agenda view. In a block agenda, it will not work reliably to
  3239. define a filter for one of the individual blocks. You need to set it in
  3240. the global options and expect it to be applied to the entire view.")
  3241. (defvar org-agenda-regexp-filter-preset nil
  3242. "A preset of the regexp filter used for secondary agenda filtering.
  3243. This must be a list of strings, each string must be a single regexp
  3244. preceded by \"+\" or \"-\".
  3245. This variable should not be set directly, but agenda custom commands can
  3246. bind it in the options section. The preset filter is a global property of
  3247. the entire agenda view. In a block agenda, it will not work reliably to
  3248. define a filter for one of the individual blocks. You need to set it in
  3249. the global options and expect it to be applied to the entire view.")
  3250. (defvar org-agenda-effort-filter-preset nil
  3251. "A preset of the effort condition used for secondary agenda filtering.
  3252. This must be a list of strings, each string must be a single regexp
  3253. preceded by \"+\" or \"-\".
  3254. This variable should not be set directly, but agenda custom commands can
  3255. bind it in the options section. The preset filter is a global property of
  3256. the entire agenda view. In a block agenda, it will not work reliably to
  3257. define a filter for one of the individual blocks. You need to set it in
  3258. the global options and expect it to be applied to the entire view.")
  3259. (defun org-agenda-use-sticky-p ()
  3260. "Return non-nil if an agenda buffer named
  3261. `org-agenda-buffer-name' exists and should be shown instead of
  3262. generating a new one."
  3263. (and
  3264. ;; turned off by user
  3265. org-agenda-sticky
  3266. ;; For multi-agenda buffer already exists
  3267. (not org-agenda-multi)
  3268. ;; buffer found
  3269. (get-buffer org-agenda-buffer-name)
  3270. ;; C-u parameter is same as last call
  3271. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3272. (and
  3273. (equal current-prefix-arg
  3274. org-agenda-last-prefix-arg)
  3275. ;; In case user turned stickiness on, while having existing
  3276. ;; Agenda buffer active, don't reuse that buffer, because it
  3277. ;; does not have org variables local
  3278. org-agenda-this-buffer-is-sticky))))
  3279. (defun org-agenda-prepare-window (abuf filter-alist)
  3280. "Setup agenda buffer in the window.
  3281. ABUF is the buffer for the agenda window.
  3282. FILTER-ALIST is an alist of filters we need to apply when
  3283. `org-agenda-persistent-filter' is non-nil."
  3284. (let* ((awin (get-buffer-window abuf)) wconf)
  3285. (cond
  3286. ((equal (current-buffer) abuf) nil)
  3287. (awin (select-window awin))
  3288. ((not (setq wconf (current-window-configuration))))
  3289. ((eq org-agenda-window-setup 'current-window)
  3290. (pop-to-buffer-same-window abuf))
  3291. ((eq org-agenda-window-setup 'other-window)
  3292. (org-switch-to-buffer-other-window abuf))
  3293. ((eq org-agenda-window-setup 'other-frame)
  3294. (switch-to-buffer-other-frame abuf))
  3295. ((eq org-agenda-window-setup 'only-window)
  3296. (delete-other-windows)
  3297. (pop-to-buffer-same-window abuf))
  3298. ((eq org-agenda-window-setup 'reorganize-frame)
  3299. (delete-other-windows)
  3300. (org-switch-to-buffer-other-window abuf)))
  3301. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3302. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3303. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3304. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3305. ;; Additional test in case agenda is invoked from within agenda
  3306. ;; buffer via elisp link.
  3307. (unless (equal (current-buffer) abuf)
  3308. (pop-to-buffer-same-window abuf))
  3309. (setq org-agenda-pre-window-conf
  3310. (or wconf org-agenda-pre-window-conf))))
  3311. (defun org-agenda-prepare (&optional name)
  3312. (let ((filter-alist (if org-agenda-persistent-filter
  3313. (with-current-buffer
  3314. (get-buffer-create org-agenda-buffer-name)
  3315. (list `(tag . ,org-agenda-tag-filter)
  3316. `(re . ,org-agenda-regexp-filter)
  3317. `(effort . ,org-agenda-effort-filter)
  3318. `(cat . ,org-agenda-category-filter))))))
  3319. (if (org-agenda-use-sticky-p)
  3320. (progn
  3321. (put 'org-agenda-tag-filter :preset-filter nil)
  3322. (put 'org-agenda-category-filter :preset-filter nil)
  3323. (put 'org-agenda-regexp-filter :preset-filter nil)
  3324. ;; Popup existing buffer
  3325. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3326. filter-alist)
  3327. (message "Sticky Agenda buffer, use `r' to refresh")
  3328. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3329. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3330. (setq org-todo-keywords-for-agenda nil)
  3331. (put 'org-agenda-tag-filter :preset-filter
  3332. org-agenda-tag-filter-preset)
  3333. (put 'org-agenda-category-filter :preset-filter
  3334. org-agenda-category-filter-preset)
  3335. (put 'org-agenda-regexp-filter :preset-filter
  3336. org-agenda-regexp-filter-preset)
  3337. (put 'org-agenda-effort-filter :preset-filter
  3338. org-agenda-effort-filter-preset)
  3339. (if org-agenda-multi
  3340. (progn
  3341. (setq buffer-read-only nil)
  3342. (goto-char (point-max))
  3343. (unless (or (bobp) org-agenda-compact-blocks
  3344. (not org-agenda-block-separator))
  3345. (insert "\n"
  3346. (if (stringp org-agenda-block-separator)
  3347. org-agenda-block-separator
  3348. (make-string (window-width) org-agenda-block-separator))
  3349. "\n"))
  3350. (narrow-to-region (point) (point-max)))
  3351. (setq org-done-keywords-for-agenda nil)
  3352. ;; Setting any org variables that are in org-agenda-local-vars
  3353. ;; list need to be done after the prepare call
  3354. (org-agenda-prepare-window
  3355. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3356. (setq buffer-read-only nil)
  3357. (org-agenda-reset-markers)
  3358. (let ((inhibit-read-only t)) (erase-buffer))
  3359. (org-agenda-mode)
  3360. (setq org-agenda-buffer (current-buffer))
  3361. (setq org-agenda-contributing-files nil)
  3362. (setq org-agenda-columns-active nil)
  3363. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3364. (setq org-todo-keywords-for-agenda
  3365. (org-uniquify org-todo-keywords-for-agenda))
  3366. (setq org-done-keywords-for-agenda
  3367. (org-uniquify org-done-keywords-for-agenda))
  3368. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3369. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3370. (and name (not org-agenda-name)
  3371. (setq-local org-agenda-name name)))
  3372. (setq buffer-read-only nil))))
  3373. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3374. (defun org-agenda-finalize ()
  3375. "Finishing touch for the agenda buffer, called just before displaying it."
  3376. (unless org-agenda-multi
  3377. (save-excursion
  3378. (let ((inhibit-read-only t))
  3379. (goto-char (point-min))
  3380. (save-excursion
  3381. (while (org-activate-bracket-links (point-max))
  3382. (add-text-properties (match-beginning 0) (match-end 0)
  3383. '(face org-link))))
  3384. (save-excursion
  3385. (while (org-activate-plain-links (point-max))
  3386. (add-text-properties (match-beginning 0) (match-end 0)
  3387. '(face org-link))))
  3388. (unless (eq org-agenda-remove-tags t)
  3389. (org-agenda-align-tags))
  3390. (unless org-agenda-with-colors
  3391. (remove-text-properties (point-min) (point-max) '(face nil)))
  3392. (if (and (boundp 'org-agenda-overriding-columns-format)
  3393. org-agenda-overriding-columns-format)
  3394. (setq-local org-agenda-overriding-columns-format
  3395. org-agenda-overriding-columns-format))
  3396. (if (and (boundp 'org-agenda-view-columns-initially)
  3397. org-agenda-view-columns-initially)
  3398. (org-agenda-columns))
  3399. (when org-agenda-fontify-priorities
  3400. (org-agenda-fontify-priorities))
  3401. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3402. (org-agenda-dim-blocked-tasks))
  3403. (org-agenda-mark-clocking-task)
  3404. (when org-agenda-entry-text-mode
  3405. (org-agenda-entry-text-hide)
  3406. (org-agenda-entry-text-show))
  3407. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3408. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3409. (org-habit-insert-consistency-graphs))
  3410. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3411. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3412. (and (listp org-agenda-show-inherited-tags)
  3413. (memq org-agenda-type org-agenda-show-inherited-tags))
  3414. (and (eq org-agenda-show-inherited-tags t)
  3415. (or (eq org-agenda-use-tag-inheritance t)
  3416. (and (listp org-agenda-use-tag-inheritance)
  3417. (not (memq org-agenda-type
  3418. org-agenda-use-tag-inheritance))))))
  3419. (let (mrk)
  3420. (save-excursion
  3421. (goto-char (point-min))
  3422. (while (equal (forward-line) 0)
  3423. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3424. (put-text-property (point-at-bol) (point-at-eol)
  3425. 'tags (org-with-point-at mrk
  3426. (delete-dups
  3427. (mapcar 'downcase (org-get-tags-at))))))))))
  3428. (run-hooks 'org-agenda-finalize-hook)
  3429. (when org-agenda-top-headline-filter
  3430. (org-agenda-filter-top-headline-apply
  3431. org-agenda-top-headline-filter))
  3432. (when org-agenda-tag-filter
  3433. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3434. (when (get 'org-agenda-tag-filter :preset-filter)
  3435. (org-agenda-filter-apply
  3436. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3437. (when org-agenda-category-filter
  3438. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3439. (when (get 'org-agenda-category-filter :preset-filter)
  3440. (org-agenda-filter-apply
  3441. (get 'org-agenda-category-filter :preset-filter) 'category))
  3442. (when org-agenda-regexp-filter
  3443. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3444. (when (get 'org-agenda-regexp-filter :preset-filter)
  3445. (org-agenda-filter-apply
  3446. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3447. (when org-agenda-effort-filter
  3448. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3449. (when (get 'org-agenda-effort-filter :preset-filter)
  3450. (org-agenda-filter-apply
  3451. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3452. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3453. (defun org-agenda-mark-clocking-task ()
  3454. "Mark the current clock entry in the agenda if it is present."
  3455. ;; We need to widen when `org-agenda-finalize' is called from
  3456. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3457. (when (bound-and-true-p org-clock-current-task)
  3458. (save-restriction
  3459. (widen)
  3460. (org-agenda-unmark-clocking-task)
  3461. (when (marker-buffer org-clock-hd-marker)
  3462. (save-excursion
  3463. (goto-char (point-min))
  3464. (let (s ov)
  3465. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3466. (goto-char s)
  3467. (when (equal (org-get-at-bol 'org-hd-marker)
  3468. org-clock-hd-marker)
  3469. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3470. (overlay-put ov 'type 'org-agenda-clocking)
  3471. (overlay-put ov 'face 'org-agenda-clocking)
  3472. (overlay-put ov 'help-echo
  3473. "The clock is running in this item")))))))))
  3474. (defun org-agenda-unmark-clocking-task ()
  3475. "Unmark the current clocking task."
  3476. (mapc (lambda (o)
  3477. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3478. (delete-overlay o)))
  3479. (overlays-in (point-min) (point-max))))
  3480. (defun org-agenda-fontify-priorities ()
  3481. "Make highest priority lines bold, and lowest italic."
  3482. (interactive)
  3483. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3484. (delete-overlay o)))
  3485. (overlays-in (point-min) (point-max)))
  3486. (save-excursion
  3487. (let (b e p ov h l)
  3488. (goto-char (point-min))
  3489. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3490. (setq h (or (get-char-property (point) 'org-highest-priority)
  3491. org-highest-priority)
  3492. l (or (get-char-property (point) 'org-lowest-priority)
  3493. org-lowest-priority)
  3494. p (string-to-char (match-string 1))
  3495. b (match-beginning 0)
  3496. e (if (eq org-agenda-fontify-priorities 'cookies)
  3497. (match-end 0)
  3498. (point-at-eol))
  3499. ov (make-overlay b e))
  3500. (overlay-put
  3501. ov 'face
  3502. (let ((special-face
  3503. (cond ((org-face-from-face-or-color
  3504. 'priority 'org-priority
  3505. (cdr (assoc p org-priority-faces))))
  3506. ((and (listp org-agenda-fontify-priorities)
  3507. (org-face-from-face-or-color
  3508. 'priority 'org-priority
  3509. (cdr (assoc p org-agenda-fontify-priorities)))))
  3510. ((equal p l) 'italic)
  3511. ((equal p h) 'bold))))
  3512. (if special-face (list special-face 'org-priority) 'org-priority)))
  3513. (overlay-put ov 'org-type 'org-priority)))))
  3514. (defvar org-depend-tag-blocked)
  3515. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3516. "Dim currently blocked TODOs in the agenda display.
  3517. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3518. dimming them."
  3519. (interactive "P")
  3520. (when (called-interactively-p 'interactive)
  3521. (message "Dim or hide blocked tasks..."))
  3522. (dolist (o (overlays-in (point-min) (point-max)))
  3523. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3524. (delete-overlay o)))
  3525. (save-excursion
  3526. (let ((inhibit-read-only t)
  3527. (org-depend-tag-blocked nil)
  3528. org-blocked-by-checkboxes)
  3529. (goto-char (point-min))
  3530. (while (let ((pos (text-property-not-all
  3531. (point) (point-max) 'todo-state nil)))
  3532. (when pos (goto-char pos)))
  3533. (setq org-blocked-by-checkboxes nil)
  3534. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3535. (when (and (markerp marker)
  3536. (with-current-buffer (marker-buffer marker)
  3537. (save-excursion (goto-char marker)
  3538. (org-entry-blocked-p))))
  3539. ;; Entries blocked by checkboxes cannot be made invisible.
  3540. ;; See `org-agenda-dim-blocked-tasks' for details.
  3541. (let* ((really-invisible
  3542. (and (not org-blocked-by-checkboxes)
  3543. (or invisible (eq org-agenda-dim-blocked-tasks
  3544. 'invisible))))
  3545. (ov (make-overlay (if really-invisible (line-end-position 0)
  3546. (line-beginning-position))
  3547. (line-end-position))))
  3548. (if really-invisible (overlay-put ov 'invisible t)
  3549. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3550. (overlay-put ov 'org-type 'org-blocked-todo))))
  3551. (forward-line))))
  3552. (when (called-interactively-p 'interactive)
  3553. (message "Dim or hide blocked tasks...done")))
  3554. (defvar org-agenda-skip-function nil
  3555. "Function to be called at each match during agenda construction.
  3556. If this function returns nil, the current match should not be skipped.
  3557. Otherwise, the function must return a position from where the search
  3558. should be continued.
  3559. This may also be a Lisp form, it will be evaluated.
  3560. Never set this variable using `setq' or so, because then it will apply
  3561. to all future agenda commands. If you do want a global skipping condition,
  3562. use the option `org-agenda-skip-function-global' instead.
  3563. The correct usage for `org-agenda-skip-function' is to bind it with
  3564. `let' to scope it dynamically into the agenda-constructing command.
  3565. A good way to set it is through options in `org-agenda-custom-commands'.")
  3566. (defun org-agenda-skip ()
  3567. "Throw to `:skip' in places that should be skipped.
  3568. Also moves point to the end of the skipped region, so that search can
  3569. continue from there."
  3570. (let ((p (point-at-bol)) to)
  3571. (when (or
  3572. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3573. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3574. (get-text-property p :org-archived)
  3575. (org-end-of-subtree t))
  3576. (and org-agenda-skip-comment-trees
  3577. (get-text-property p :org-comment)
  3578. (org-end-of-subtree t))
  3579. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3580. (org-agenda-skip-eval org-agenda-skip-function)))
  3581. (goto-char to))
  3582. (org-in-src-block-p t))
  3583. (throw :skip t))))
  3584. (defun org-agenda-skip-eval (form)
  3585. "If FORM is a function or a list, call (or eval) it and return the result.
  3586. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3587. and match data are returned to the previous state no matter what these
  3588. functions do."
  3589. (let (fp)
  3590. (and form
  3591. (or (setq fp (functionp form))
  3592. (consp form))
  3593. (save-excursion
  3594. (save-match-data
  3595. (if fp
  3596. (funcall form)
  3597. (eval form)))))))
  3598. (defvar org-agenda-markers nil
  3599. "List of all currently active markers created by `org-agenda'.")
  3600. (defvar org-agenda-last-marker-time (float-time)
  3601. "Creation time of the last agenda marker.")
  3602. (defun org-agenda-new-marker (&optional pos)
  3603. "Return a new agenda marker.
  3604. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3605. these markers and resets them when they are no longer in use."
  3606. (let ((m (copy-marker (or pos (point)) t)))
  3607. (setq org-agenda-last-marker-time (float-time))
  3608. (if org-agenda-buffer
  3609. (with-current-buffer org-agenda-buffer
  3610. (push m org-agenda-markers))
  3611. (push m org-agenda-markers))
  3612. m))
  3613. (defun org-agenda-reset-markers ()
  3614. "Reset markers created by `org-agenda'."
  3615. (while org-agenda-markers
  3616. (move-marker (pop org-agenda-markers) nil)))
  3617. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3618. "Save relative positions of markers in region.
  3619. This check for agenda markers in all agenda buffers currently active."
  3620. (dolist (buf (buffer-list))
  3621. (with-current-buffer buf
  3622. (when (eq major-mode 'org-agenda-mode)
  3623. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3624. org-agenda-markers)))))
  3625. ;;; Entry text mode
  3626. (defun org-agenda-entry-text-show-here ()
  3627. "Add some text from the entry as context to the current line."
  3628. (let (m txt o)
  3629. (setq m (org-get-at-bol 'org-hd-marker))
  3630. (unless (marker-buffer m)
  3631. (error "No marker points to an entry here"))
  3632. (setq txt (concat "\n" (org-no-properties
  3633. (org-agenda-get-some-entry-text
  3634. m org-agenda-entry-text-maxlines
  3635. org-agenda-entry-text-leaders))))
  3636. (when (string-match "\\S-" txt)
  3637. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3638. (overlay-put o 'evaporate t)
  3639. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3640. (overlay-put o 'after-string txt))))
  3641. (defun org-agenda-entry-text-show ()
  3642. "Add entry context for all agenda lines."
  3643. (interactive)
  3644. (save-excursion
  3645. (goto-char (point-max))
  3646. (beginning-of-line 1)
  3647. (while (not (bobp))
  3648. (when (org-get-at-bol 'org-hd-marker)
  3649. (org-agenda-entry-text-show-here))
  3650. (beginning-of-line 0))))
  3651. (defun org-agenda-entry-text-hide ()
  3652. "Remove any shown entry context."
  3653. (delq nil
  3654. (mapcar (lambda (o)
  3655. (if (eq (overlay-get o 'org-overlay-type)
  3656. 'agenda-entry-content)
  3657. (progn (delete-overlay o) t)))
  3658. (overlays-in (point-min) (point-max)))))
  3659. (defun org-agenda-get-day-face (date)
  3660. "Return the face DATE should be displayed with."
  3661. (cond ((and (functionp org-agenda-day-face-function)
  3662. (funcall org-agenda-day-face-function date)))
  3663. ((org-agenda-today-p date) 'org-agenda-date-today)
  3664. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3665. 'org-agenda-date-weekend)
  3666. (t 'org-agenda-date)))
  3667. (defvar org-agenda-show-log-scoped)
  3668. ;;; Agenda Daily/Weekly
  3669. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3670. "Start day for the agenda view.
  3671. Custom commands can set this variable in the options section.
  3672. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3673. input allowed when reading a date through the Org calendar.
  3674. See the docstring of `org-read-date' for details.")
  3675. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3676. (defvar org-arg-loc nil) ; local variable
  3677. (defvar org-agenda-buffer-tmp-name nil)
  3678. ;;;###autoload
  3679. (defun org-agenda-list (&optional arg start-day span with-hour)
  3680. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3681. The view will be for the current day or week, but from the overview buffer
  3682. you will be able to go to other days/weeks.
  3683. With a numeric prefix argument in an interactive call, the agenda will
  3684. span ARG days. Lisp programs should instead specify SPAN to change
  3685. the number of days. SPAN defaults to `org-agenda-span'.
  3686. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3687. given in `org-agenda-start-on-weekday'.
  3688. When WITH-HOUR is non-nil, only include scheduled and deadline
  3689. items if they have an hour specification like [h]h:mm."
  3690. (interactive "P")
  3691. (if org-agenda-overriding-arguments
  3692. (setq arg (car org-agenda-overriding-arguments)
  3693. start-day (nth 1 org-agenda-overriding-arguments)
  3694. span (nth 2 org-agenda-overriding-arguments)))
  3695. (if (and (integerp arg) (> arg 0))
  3696. (setq span arg arg nil))
  3697. (catch 'exit
  3698. (setq org-agenda-buffer-name
  3699. (or org-agenda-buffer-tmp-name
  3700. (if org-agenda-sticky
  3701. (cond ((and org-keys (stringp org-match))
  3702. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3703. (org-keys
  3704. (format "*Org Agenda(%s)*" org-keys))
  3705. (t "*Org Agenda(a)*")))
  3706. org-agenda-buffer-name))
  3707. (org-agenda-prepare "Day/Week")
  3708. (setq start-day (or start-day org-agenda-start-day))
  3709. (if (stringp start-day)
  3710. ;; Convert to an absolute day number
  3711. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3712. (org-compile-prefix-format 'agenda)
  3713. (org-set-sorting-strategy 'agenda)
  3714. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3715. (today (org-today))
  3716. (sd (or start-day today))
  3717. (ndays (org-agenda-span-to-ndays span sd))
  3718. (org-agenda-start-on-weekday
  3719. (if (or (eq ndays 7) (eq ndays 14))
  3720. org-agenda-start-on-weekday))
  3721. (thefiles (org-agenda-files nil 'ifmode))
  3722. (files thefiles)
  3723. (start (if (or (null org-agenda-start-on-weekday)
  3724. (< ndays 7))
  3725. sd
  3726. (let* ((nt (calendar-day-of-week
  3727. (calendar-gregorian-from-absolute sd)))
  3728. (n1 org-agenda-start-on-weekday)
  3729. (d (- nt n1)))
  3730. (- sd (+ (if (< d 0) 7 0) d)))))
  3731. (day-numbers (list start))
  3732. (day-cnt 0)
  3733. (inhibit-redisplay (not debug-on-error))
  3734. (org-agenda-show-log-scoped org-agenda-show-log)
  3735. s e rtn rtnall file date d start-pos end-pos todayp
  3736. clocktable-start clocktable-end filter)
  3737. (setq org-agenda-redo-command
  3738. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3739. (dotimes (n (1- ndays))
  3740. (push (1+ (car day-numbers)) day-numbers))
  3741. (setq day-numbers (nreverse day-numbers))
  3742. (setq clocktable-start (car day-numbers)
  3743. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3744. (setq-local org-starting-day (car day-numbers))
  3745. (setq-local org-arg-loc arg)
  3746. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3747. (unless org-agenda-compact-blocks
  3748. (let* ((d1 (car day-numbers))
  3749. (d2 (org-last day-numbers))
  3750. (w1 (org-days-to-iso-week d1))
  3751. (w2 (org-days-to-iso-week d2)))
  3752. (setq s (point))
  3753. (if org-agenda-overriding-header
  3754. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3755. nil 'face 'org-agenda-structure) "\n")
  3756. (insert (org-agenda-span-name span)
  3757. "-agenda"
  3758. (if (< (- d2 d1) 350)
  3759. (if (= w1 w2)
  3760. (format " (W%02d)" w1)
  3761. (format " (W%02d-W%02d)" w1 w2))
  3762. "")
  3763. ":\n")))
  3764. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3765. 'org-date-line t))
  3766. (org-agenda-mark-header-line s))
  3767. (while (setq d (pop day-numbers))
  3768. (setq date (calendar-gregorian-from-absolute d)
  3769. s (point))
  3770. (if (or (setq todayp (= d today))
  3771. (and (not start-pos) (= d sd)))
  3772. (setq start-pos (point))
  3773. (if (and start-pos (not end-pos))
  3774. (setq end-pos (point))))
  3775. (setq files thefiles
  3776. rtnall nil)
  3777. (while (setq file (pop files))
  3778. (catch 'nextfile
  3779. (org-check-agenda-file file)
  3780. (let ((org-agenda-entry-types org-agenda-entry-types))
  3781. ;; Starred types override non-starred equivalents
  3782. (when (member :deadline* org-agenda-entry-types)
  3783. (setq org-agenda-entry-types
  3784. (delq :deadline org-agenda-entry-types)))
  3785. (when (member :scheduled* org-agenda-entry-types)
  3786. (setq org-agenda-entry-types
  3787. (delq :scheduled org-agenda-entry-types)))
  3788. ;; Honor with-hour
  3789. (when with-hour
  3790. (when (member :deadline org-agenda-entry-types)
  3791. (setq org-agenda-entry-types
  3792. (delq :deadline org-agenda-entry-types))
  3793. (push :deadline* org-agenda-entry-types))
  3794. (when (member :scheduled org-agenda-entry-types)
  3795. (setq org-agenda-entry-types
  3796. (delq :scheduled org-agenda-entry-types))
  3797. (push :scheduled* org-agenda-entry-types)))
  3798. (unless org-agenda-include-deadlines
  3799. (setq org-agenda-entry-types
  3800. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3801. (cond
  3802. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3803. (setq rtn (org-agenda-get-day-entries
  3804. file date :closed)))
  3805. (org-agenda-show-log-scoped
  3806. (setq rtn (apply 'org-agenda-get-day-entries
  3807. file date
  3808. (append '(:closed) org-agenda-entry-types))))
  3809. (t
  3810. (setq rtn (apply 'org-agenda-get-day-entries
  3811. file date
  3812. org-agenda-entry-types)))))
  3813. (setq rtnall (append rtnall rtn)))) ;; all entries
  3814. (if org-agenda-include-diary
  3815. (let ((org-agenda-search-headline-for-time t))
  3816. (require 'diary-lib)
  3817. (setq rtn (org-get-entries-from-diary date))
  3818. (setq rtnall (append rtnall rtn))))
  3819. (if (or rtnall org-agenda-show-all-dates)
  3820. (progn
  3821. (setq day-cnt (1+ day-cnt))
  3822. (insert
  3823. (if (stringp org-agenda-format-date)
  3824. (format-time-string org-agenda-format-date
  3825. (org-time-from-absolute date))
  3826. (funcall org-agenda-format-date date))
  3827. "\n")
  3828. (put-text-property s (1- (point)) 'face
  3829. (org-agenda-get-day-face date))
  3830. (put-text-property s (1- (point)) 'org-date-line t)
  3831. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3832. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3833. (when todayp
  3834. (put-text-property s (1- (point)) 'org-today t))
  3835. (setq rtnall
  3836. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3837. (if rtnall (insert ;; all entries
  3838. (org-agenda-finalize-entries rtnall 'agenda)
  3839. "\n"))
  3840. (put-text-property s (1- (point)) 'day d)
  3841. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3842. (when (and org-agenda-clockreport-mode clocktable-start)
  3843. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3844. ;; the above line is to ensure the restricted range!
  3845. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3846. tbl)
  3847. (setq p (org-plist-delete p :block))
  3848. (setq p (plist-put p :tstart clocktable-start))
  3849. (setq p (plist-put p :tend clocktable-end))
  3850. (setq p (plist-put p :scope 'agenda))
  3851. (setq tbl (apply 'org-clock-get-clocktable p))
  3852. (insert tbl)))
  3853. (goto-char (point-min))
  3854. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3855. (unless (and (pos-visible-in-window-p (point-min))
  3856. (pos-visible-in-window-p (point-max)))
  3857. (goto-char (1- (point-max)))
  3858. (recenter -1)
  3859. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3860. (progn
  3861. (goto-char (or start-pos 1))
  3862. (recenter 1))))
  3863. (goto-char (or start-pos 1))
  3864. (add-text-properties (point-min) (point-max)
  3865. `(org-agenda-type agenda
  3866. org-last-args (,arg ,start-day ,span)
  3867. org-redo-cmd ,org-agenda-redo-command
  3868. org-series-cmd ,org-cmd))
  3869. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3870. (org-agenda-show-clocking-issues))
  3871. (org-agenda-finalize)
  3872. (setq buffer-read-only t)
  3873. (message ""))))
  3874. (defun org-agenda-ndays-to-span (n)
  3875. "Return a span symbol for a span of N days, or N if none matches."
  3876. (cond ((symbolp n) n)
  3877. ((= n 1) 'day)
  3878. ((= n 7) 'week)
  3879. ((= n 14) 'fortnight)
  3880. (t n)))
  3881. (defun org-agenda-span-to-ndays (span &optional start-day)
  3882. "Return ndays from SPAN, possibly starting at START-DAY.
  3883. START-DAY is an absolute time value."
  3884. (cond ((numberp span) span)
  3885. ((eq span 'day) 1)
  3886. ((eq span 'week) 7)
  3887. ((eq span 'fortnight) 14)
  3888. ((eq span 'month)
  3889. (let ((date (calendar-gregorian-from-absolute start-day)))
  3890. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3891. ((eq span 'year)
  3892. (let ((date (calendar-gregorian-from-absolute start-day)))
  3893. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3894. (defun org-agenda-span-name (span)
  3895. "Return a SPAN name."
  3896. (if (null span)
  3897. ""
  3898. (if (symbolp span)
  3899. (capitalize (symbol-name span))
  3900. (format "%d days" span))))
  3901. ;;; Agenda word search
  3902. (defvar org-agenda-search-history nil)
  3903. (defvar org-search-syntax-table nil
  3904. "Special syntax table for Org search.
  3905. In this table, we have single quotes not as word constituents, to
  3906. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3907. (defvar org-mode-syntax-table) ; From org.el
  3908. (defun org-search-syntax-table ()
  3909. (unless org-search-syntax-table
  3910. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3911. (modify-syntax-entry ?' "." org-search-syntax-table)
  3912. (modify-syntax-entry ?` "." org-search-syntax-table))
  3913. org-search-syntax-table)
  3914. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3915. ;;;###autoload
  3916. (defun org-search-view (&optional todo-only string edit-at)
  3917. "Show all entries that contain a phrase or words or regular expressions.
  3918. With optional prefix argument TODO-ONLY, only consider entries that are
  3919. TODO entries. The argument STRING can be used to pass a default search
  3920. string into this function. If EDIT-AT is non-nil, it means that the
  3921. user should get a chance to edit this string, with cursor at position
  3922. EDIT-AT.
  3923. The search string can be viewed either as a phrase that should be found as
  3924. is, or it can be broken into a number of snippets, each of which must match
  3925. in a Boolean way to select an entry. The default depends on the variable
  3926. `org-agenda-search-view-always-boolean'.
  3927. Even if this is turned off (the default) you can always switch to
  3928. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3929. The default is a direct search of the whole phrase, where each space in
  3930. the search string can expand to an arbitrary amount of whitespace,
  3931. including newlines.
  3932. If using a Boolean search, the search string is split on whitespace and
  3933. each snippet is searched separately, with logical AND to select an entry.
  3934. Words prefixed with a minus must *not* occur in the entry. Words without
  3935. a prefix or prefixed with a plus must occur in the entry. Matching is
  3936. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3937. match whole words, not parts of a word) if
  3938. `org-agenda-search-view-force-full-words' is set (default is nil).
  3939. Boolean search snippets enclosed by curly braces are interpreted as
  3940. regular expressions that must or (when preceded with \"-\") must not
  3941. match in the entry. Snippets enclosed into double quotes will be taken
  3942. as a whole, to include whitespace.
  3943. - If the search string starts with an asterisk, search only in headlines.
  3944. - If (possibly after the leading star) the search string starts with an
  3945. exclamation mark, this also means to look at TODO entries only, an effect
  3946. that can also be achieved with a prefix argument.
  3947. - If (possibly after star and exclamation mark) the search string starts
  3948. with a colon, this will mean that the (non-regexp) snippets of the
  3949. Boolean search must match as full words.
  3950. This command searches the agenda files, and in addition the files listed
  3951. in `org-agenda-text-search-extra-files'."
  3952. (interactive "P")
  3953. (if org-agenda-overriding-arguments
  3954. (setq todo-only (car org-agenda-overriding-arguments)
  3955. string (nth 1 org-agenda-overriding-arguments)
  3956. edit-at (nth 2 org-agenda-overriding-arguments)))
  3957. (let* ((props (list 'face nil
  3958. 'done-face 'org-agenda-done
  3959. 'org-not-done-regexp org-not-done-regexp
  3960. 'org-todo-regexp org-todo-regexp
  3961. 'org-complex-heading-regexp org-complex-heading-regexp
  3962. 'mouse-face 'highlight
  3963. 'help-echo (format "mouse-2 or RET jump to location")))
  3964. (full-words org-agenda-search-view-force-full-words)
  3965. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3966. regexp rtn rtnall files file pos inherited-tags
  3967. marker category level tags c neg re boolean
  3968. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3969. (unless (and (not edit-at)
  3970. (stringp string)
  3971. (string-match "\\S-" string))
  3972. (setq string (read-string
  3973. (if org-agenda-search-view-always-boolean
  3974. "[+-]Word/{Regexp} ...: "
  3975. "Phrase or [+-]Word/{Regexp} ...: ")
  3976. (cond
  3977. ((integerp edit-at) (cons string edit-at))
  3978. (edit-at string))
  3979. 'org-agenda-search-history)))
  3980. (catch 'exit
  3981. (if org-agenda-sticky
  3982. (setq org-agenda-buffer-name
  3983. (if (stringp string)
  3984. (format "*Org Agenda(%s:%s)*"
  3985. (or org-keys (or (and todo-only "S") "s")) string)
  3986. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3987. (org-agenda-prepare "SEARCH")
  3988. (org-compile-prefix-format 'search)
  3989. (org-set-sorting-strategy 'search)
  3990. (setq org-agenda-redo-command
  3991. (list 'org-search-view (if todo-only t nil)
  3992. (list 'if 'current-prefix-arg nil string)))
  3993. (setq org-agenda-query-string string)
  3994. (if (equal (string-to-char string) ?*)
  3995. (setq hdl-only t
  3996. words (substring string 1))
  3997. (setq words string))
  3998. (when (equal (string-to-char words) ?!)
  3999. (setq todo-only t
  4000. words (substring words 1)))
  4001. (when (equal (string-to-char words) ?:)
  4002. (setq full-words t
  4003. words (substring words 1)))
  4004. (if (or org-agenda-search-view-always-boolean
  4005. (member (string-to-char words) '(?- ?+ ?\{)))
  4006. (setq boolean t))
  4007. (setq words (org-split-string words))
  4008. (let (www w)
  4009. (while (setq w (pop words))
  4010. (while (and (string-match "\\\\\\'" w) words)
  4011. (setq w (concat (substring w 0 -1) " " (pop words))))
  4012. (push w www))
  4013. (setq words (nreverse www) www nil)
  4014. (while (setq w (pop words))
  4015. (when (and (string-match "\\`[-+]?{" w)
  4016. (not (string-match "}\\'" w)))
  4017. (while (and words (not (string-match "}\\'" (car words))))
  4018. (setq w (concat w " " (pop words))))
  4019. (setq w (concat w " " (pop words))))
  4020. (push w www))
  4021. (setq words (nreverse www)))
  4022. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4023. (when boolean
  4024. (let (wds w)
  4025. (while (setq w (pop words))
  4026. (if (or (equal (substring w 0 1) "\"")
  4027. (and (> (length w) 1)
  4028. (member (substring w 0 1) '("+" "-"))
  4029. (equal (substring w 1 2) "\"")))
  4030. (while (and words (not (equal (substring w -1) "\"")))
  4031. (setq w (concat w " " (pop words)))))
  4032. (and (string-match "\\`\\([-+]?\\)\"" w)
  4033. (setq w (replace-match "\\1" nil nil w)))
  4034. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4035. (push w wds))
  4036. (setq words (nreverse wds))))
  4037. (if boolean
  4038. (mapc (lambda (w)
  4039. (setq c (string-to-char w))
  4040. (if (equal c ?-)
  4041. (setq neg t w (substring w 1))
  4042. (if (equal c ?+)
  4043. (setq neg nil w (substring w 1))
  4044. (setq neg nil)))
  4045. (if (string-match "\\`{.*}\\'" w)
  4046. (setq re (substring w 1 -1))
  4047. (if full-words
  4048. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4049. (setq re (regexp-quote (downcase w)))))
  4050. (if neg (push re regexps-) (push re regexps+)))
  4051. words)
  4052. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4053. regexps+))
  4054. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4055. (if (not regexps+)
  4056. (setq regexp org-outline-regexp-bol)
  4057. (setq regexp (pop regexps+))
  4058. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4059. regexp))))
  4060. (setq files (org-agenda-files nil 'ifmode))
  4061. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4062. (pop org-agenda-text-search-extra-files)
  4063. (setq files (org-add-archive-files files)))
  4064. (setq files (append files org-agenda-text-search-extra-files)
  4065. rtnall nil)
  4066. (while (setq file (pop files))
  4067. (setq ee nil)
  4068. (catch 'nextfile
  4069. (org-check-agenda-file file)
  4070. (setq buffer (if (file-exists-p file)
  4071. (org-get-agenda-file-buffer file)
  4072. (error "No such file %s" file)))
  4073. (if (not buffer)
  4074. ;; If file does not exist, make sure an error message is sent
  4075. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4076. file))))
  4077. (with-current-buffer buffer
  4078. (with-syntax-table (org-search-syntax-table)
  4079. (unless (derived-mode-p 'org-mode)
  4080. (error "Agenda file %s is not in `org-mode'" file))
  4081. (let ((case-fold-search t))
  4082. (save-excursion
  4083. (save-restriction
  4084. (if (eq buffer org-agenda-restrict)
  4085. (narrow-to-region org-agenda-restrict-begin
  4086. org-agenda-restrict-end)
  4087. (widen))
  4088. (goto-char (point-min))
  4089. (unless (or (org-at-heading-p)
  4090. (outline-next-heading))
  4091. (throw 'nextfile t))
  4092. (goto-char (max (point-min) (1- (point))))
  4093. (while (re-search-forward regexp nil t)
  4094. (org-back-to-heading t)
  4095. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4096. (> (org-reduced-level (org-outline-level))
  4097. org-agenda-search-view-max-outline-level)
  4098. (forward-line -1)
  4099. (org-back-to-heading t)))
  4100. (skip-chars-forward "* ")
  4101. (setq beg (point-at-bol)
  4102. beg1 (point)
  4103. end (progn
  4104. (outline-next-heading)
  4105. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4106. (> (org-reduced-level (org-outline-level))
  4107. org-agenda-search-view-max-outline-level)
  4108. (forward-line 1)
  4109. (outline-next-heading)))
  4110. (point)))
  4111. (catch :skip
  4112. (goto-char beg)
  4113. (org-agenda-skip)
  4114. (setq str (buffer-substring-no-properties
  4115. (point-at-bol)
  4116. (if hdl-only (point-at-eol) end)))
  4117. (mapc (lambda (wr) (when (string-match wr str)
  4118. (goto-char (1- end))
  4119. (throw :skip t)))
  4120. regexps-)
  4121. (mapc (lambda (wr) (unless (string-match wr str)
  4122. (goto-char (1- end))
  4123. (throw :skip t)))
  4124. (if todo-only
  4125. (cons (concat "^\\*+[ \t]+"
  4126. org-not-done-regexp)
  4127. regexps+)
  4128. regexps+))
  4129. (goto-char beg)
  4130. (setq marker (org-agenda-new-marker (point))
  4131. category (org-get-category)
  4132. level (make-string (org-reduced-level (org-outline-level)) ? )
  4133. inherited-tags
  4134. (or (eq org-agenda-show-inherited-tags 'always)
  4135. (and (listp org-agenda-show-inherited-tags)
  4136. (memq 'todo org-agenda-show-inherited-tags))
  4137. (and (eq org-agenda-show-inherited-tags t)
  4138. (or (eq org-agenda-use-tag-inheritance t)
  4139. (memq 'todo org-agenda-use-tag-inheritance))))
  4140. tags (org-get-tags-at nil (not inherited-tags))
  4141. txt (org-agenda-format-item
  4142. ""
  4143. (buffer-substring-no-properties
  4144. beg1 (point-at-eol))
  4145. level category tags t))
  4146. (org-add-props txt props
  4147. 'org-marker marker 'org-hd-marker marker
  4148. 'org-todo-regexp org-todo-regexp
  4149. 'level level
  4150. 'org-complex-heading-regexp org-complex-heading-regexp
  4151. 'priority 1000
  4152. 'type "search")
  4153. (push txt ee)
  4154. (goto-char (1- end))))))))))
  4155. (setq rtn (nreverse ee))
  4156. (setq rtnall (append rtnall rtn)))
  4157. (if org-agenda-overriding-header
  4158. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4159. nil 'face 'org-agenda-structure) "\n")
  4160. (insert "Search words: ")
  4161. (add-text-properties (point-min) (1- (point))
  4162. (list 'face 'org-agenda-structure))
  4163. (setq pos (point))
  4164. (insert string "\n")
  4165. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4166. (setq pos (point))
  4167. (unless org-agenda-multi
  4168. (insert (substitute-command-keys "\
  4169. Press `\\[org-agenda-manipulate-query-add]', \
  4170. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4171. `\\[org-agenda-manipulate-query-add-re]', \
  4172. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4173. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4174. (add-text-properties pos (1- (point))
  4175. (list 'face 'org-agenda-structure))))
  4176. (org-agenda-mark-header-line (point-min))
  4177. (when rtnall
  4178. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4179. (goto-char (point-min))
  4180. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4181. (add-text-properties (point-min) (point-max)
  4182. `(org-agenda-type search
  4183. org-last-args (,todo-only ,string ,edit-at)
  4184. org-redo-cmd ,org-agenda-redo-command
  4185. org-series-cmd ,org-cmd))
  4186. (org-agenda-finalize)
  4187. (setq buffer-read-only t))))
  4188. ;;; Agenda TODO list
  4189. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4190. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4191. (concat
  4192. (if (or (equal keywords "ALL") (not keywords))
  4193. (propertize "ALL" 'face 'warning)
  4194. (mapconcat
  4195. (lambda (kw)
  4196. (propertize kw 'face (org-get-todo-face kw)))
  4197. (org-split-string keywords "|")
  4198. "|"))
  4199. "\n"))
  4200. (defvar org-select-this-todo-keyword nil)
  4201. (defvar org-last-arg nil)
  4202. ;;;###autoload
  4203. (defun org-todo-list (&optional arg)
  4204. "Show all (not done) TODO entries from all agenda file in a single list.
  4205. The prefix arg can be used to select a specific TODO keyword and limit
  4206. the list to these. When using `\\[universal-argument]', you will be prompted
  4207. for a keyword. A numeric prefix directly selects the Nth keyword in
  4208. `org-todo-keywords-1'."
  4209. (interactive "P")
  4210. (if org-agenda-overriding-arguments
  4211. (setq arg org-agenda-overriding-arguments))
  4212. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4213. (let* ((today (org-today))
  4214. (date (calendar-gregorian-from-absolute today))
  4215. (kwds org-todo-keywords-for-agenda)
  4216. (completion-ignore-case t)
  4217. (org-select-this-todo-keyword
  4218. (if (stringp arg) arg
  4219. (and arg (integerp arg) (> arg 0)
  4220. (nth (1- arg) kwds))))
  4221. rtn rtnall files file pos)
  4222. (when (equal arg '(4))
  4223. (setq org-select-this-todo-keyword
  4224. (completing-read "Keyword (or KWD1|K2D2|...): "
  4225. (mapcar #'list kwds) nil nil)))
  4226. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4227. (catch 'exit
  4228. (if org-agenda-sticky
  4229. (setq org-agenda-buffer-name
  4230. (if (stringp org-select-this-todo-keyword)
  4231. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4232. org-select-this-todo-keyword)
  4233. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4234. (org-agenda-prepare "TODO")
  4235. (org-compile-prefix-format 'todo)
  4236. (org-set-sorting-strategy 'todo)
  4237. (setq org-agenda-redo-command
  4238. `(org-todo-list (or (and (numberp current-prefix-arg)
  4239. current-prefix-arg)
  4240. ,org-select-this-todo-keyword
  4241. current-prefix-arg ,arg)))
  4242. (setq files (org-agenda-files nil 'ifmode)
  4243. rtnall nil)
  4244. (while (setq file (pop files))
  4245. (catch 'nextfile
  4246. (org-check-agenda-file file)
  4247. (setq rtn (org-agenda-get-day-entries file date :todo))
  4248. (setq rtnall (append rtnall rtn))))
  4249. (if org-agenda-overriding-header
  4250. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4251. nil 'face 'org-agenda-structure) "\n")
  4252. (insert "Global list of TODO items of type: ")
  4253. (add-text-properties (point-min) (1- (point))
  4254. (list 'face 'org-agenda-structure
  4255. 'short-heading
  4256. (concat "ToDo: "
  4257. (or org-select-this-todo-keyword "ALL"))))
  4258. (org-agenda-mark-header-line (point-min))
  4259. (insert (org-agenda-propertize-selected-todo-keywords
  4260. org-select-this-todo-keyword))
  4261. (setq pos (point))
  4262. (unless org-agenda-multi
  4263. (insert (substitute-command-keys "Available with \
  4264. `N \\[org-agenda-redo]': (0)[ALL]"))
  4265. (let ((n 0) s)
  4266. (mapc (lambda (x)
  4267. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4268. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4269. (insert "\n "))
  4270. (insert " " s))
  4271. kwds))
  4272. (insert "\n"))
  4273. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4274. (org-agenda-mark-header-line (point-min))
  4275. (when rtnall
  4276. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4277. (goto-char (point-min))
  4278. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4279. (add-text-properties (point-min) (point-max)
  4280. `(org-agenda-type todo
  4281. org-last-args ,arg
  4282. org-redo-cmd ,org-agenda-redo-command
  4283. org-series-cmd ,org-cmd))
  4284. (org-agenda-finalize)
  4285. (setq buffer-read-only t))))
  4286. ;;; Agenda tags match
  4287. ;;;###autoload
  4288. (defun org-tags-view (&optional todo-only match)
  4289. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4290. The prefix arg TODO-ONLY limits the search to TODO entries."
  4291. (interactive "P")
  4292. (if org-agenda-overriding-arguments
  4293. (setq todo-only (car org-agenda-overriding-arguments)
  4294. match (nth 1 org-agenda-overriding-arguments)))
  4295. (let* ((org-tags-match-list-sublevels
  4296. org-tags-match-list-sublevels)
  4297. (completion-ignore-case t)
  4298. rtn rtnall files file pos matcher
  4299. buffer)
  4300. (when (and (stringp match) (not (string-match "\\S-" match)))
  4301. (setq match nil))
  4302. (catch 'exit
  4303. (if org-agenda-sticky
  4304. (setq org-agenda-buffer-name
  4305. (if (stringp match)
  4306. (format "*Org Agenda(%s:%s)*"
  4307. (or org-keys (or (and todo-only "M") "m")) match)
  4308. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4309. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4310. ;; expanding tags within `org-make-tags-matcher'
  4311. (org-agenda-prepare (concat "TAGS " match))
  4312. (setq org--matcher-tags-todo-only todo-only
  4313. matcher (org-make-tags-matcher match)
  4314. match (car matcher)
  4315. matcher (cdr matcher))
  4316. (org-compile-prefix-format 'tags)
  4317. (org-set-sorting-strategy 'tags)
  4318. (setq org-agenda-query-string match)
  4319. (setq org-agenda-redo-command
  4320. (list 'org-tags-view
  4321. `(quote ,org--matcher-tags-todo-only)
  4322. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4323. (setq files (org-agenda-files nil 'ifmode)
  4324. rtnall nil)
  4325. (while (setq file (pop files))
  4326. (catch 'nextfile
  4327. (org-check-agenda-file file)
  4328. (setq buffer (if (file-exists-p file)
  4329. (org-get-agenda-file-buffer file)
  4330. (error "No such file %s" file)))
  4331. (if (not buffer)
  4332. ;; If file does not exist, error message to agenda
  4333. (setq rtn (list
  4334. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4335. rtnall (append rtnall rtn))
  4336. (with-current-buffer buffer
  4337. (unless (derived-mode-p 'org-mode)
  4338. (error "Agenda file %s is not in `org-mode'" file))
  4339. (save-excursion
  4340. (save-restriction
  4341. (if (eq buffer org-agenda-restrict)
  4342. (narrow-to-region org-agenda-restrict-begin
  4343. org-agenda-restrict-end)
  4344. (widen))
  4345. (setq rtn (org-scan-tags 'agenda
  4346. matcher
  4347. org--matcher-tags-todo-only))
  4348. (setq rtnall (append rtnall rtn))))))))
  4349. (if org-agenda-overriding-header
  4350. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4351. nil 'face 'org-agenda-structure) "\n")
  4352. (insert "Headlines with TAGS match: ")
  4353. (add-text-properties (point-min) (1- (point))
  4354. (list 'face 'org-agenda-structure
  4355. 'short-heading
  4356. (concat "Match: " match)))
  4357. (setq pos (point))
  4358. (insert match "\n")
  4359. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4360. (setq pos (point))
  4361. (unless org-agenda-multi
  4362. (insert (substitute-command-keys
  4363. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4364. to search again with new search string\n")))
  4365. (add-text-properties pos (1- (point))
  4366. (list 'face 'org-agenda-structure)))
  4367. (org-agenda-mark-header-line (point-min))
  4368. (when rtnall
  4369. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4370. (goto-char (point-min))
  4371. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4372. (add-text-properties
  4373. (point-min) (point-max)
  4374. `(org-agenda-type tags
  4375. org-last-args (,org--matcher-tags-todo-only ,match)
  4376. org-redo-cmd ,org-agenda-redo-command
  4377. org-series-cmd ,org-cmd))
  4378. (org-agenda-finalize)
  4379. (setq buffer-read-only t))))
  4380. ;;; Agenda Finding stuck projects
  4381. (defvar org-agenda-skip-regexp nil
  4382. "Regular expression used in skipping subtrees for the agenda.
  4383. This is basically a temporary global variable that can be set and then
  4384. used by user-defined selections using `org-agenda-skip-function'.")
  4385. (defvar org-agenda-overriding-header nil
  4386. "When set during agenda, todo and tags searches it replaces the header.
  4387. This variable should not be set directly, but custom commands can bind it
  4388. in the options section.")
  4389. (defun org-agenda-skip-entry-when-regexp-matches ()
  4390. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4391. If yes, it returns the end position of this entry, causing agenda commands
  4392. to skip the entry but continuing the search in the subtree. This is a
  4393. function that can be put into `org-agenda-skip-function' for the duration
  4394. of a command."
  4395. (let ((end (save-excursion (org-end-of-subtree t)))
  4396. skip)
  4397. (save-excursion
  4398. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4399. (and skip end)))
  4400. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4401. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4402. If yes, it returns the end position of this tree, causing agenda commands
  4403. to skip this subtree. This is a function that can be put into
  4404. `org-agenda-skip-function' for the duration of a command."
  4405. (let ((end (save-excursion (org-end-of-subtree t)))
  4406. skip)
  4407. (save-excursion
  4408. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4409. (and skip end)))
  4410. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4411. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4412. If yes, it returns the end position of the current entry (NOT the tree),
  4413. causing agenda commands to skip the entry but continuing the search in
  4414. the subtree. This is a function that can be put into
  4415. `org-agenda-skip-function' for the duration of a command. An important
  4416. use of this function is for the stuck project list."
  4417. (let ((end (save-excursion (org-end-of-subtree t)))
  4418. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4419. skip)
  4420. (save-excursion
  4421. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4422. (and skip entry-end)))
  4423. (defun org-agenda-skip-entry-if (&rest conditions)
  4424. "Skip entry if any of CONDITIONS is true.
  4425. See `org-agenda-skip-if' for details."
  4426. (org-agenda-skip-if nil conditions))
  4427. (defun org-agenda-skip-subtree-if (&rest conditions)
  4428. "Skip subtree if any of CONDITIONS is true.
  4429. See `org-agenda-skip-if' for details."
  4430. (org-agenda-skip-if t conditions))
  4431. (defun org-agenda-skip-if (subtree conditions)
  4432. "Checks current entity for CONDITIONS.
  4433. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4434. the entry (i.e. the text before the next heading) is checked.
  4435. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4436. from different tests. Valid conditions are:
  4437. scheduled Check if there is a scheduled cookie
  4438. notscheduled Check if there is no scheduled cookie
  4439. deadline Check if there is a deadline
  4440. notdeadline Check if there is no deadline
  4441. timestamp Check if there is a timestamp (also deadline or scheduled)
  4442. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4443. regexp Check if regexp matches
  4444. notregexp Check if regexp does not match.
  4445. todo Check if TODO keyword matches
  4446. nottodo Check if TODO keyword does not match
  4447. The regexp is taken from the conditions list, it must come right after
  4448. the `regexp' or `notregexp' element.
  4449. `todo' and `nottodo' accept as an argument a list of todo
  4450. keywords, which may include \"*\" to match any todo keyword.
  4451. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4452. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4453. Instead of a list, a keyword class may be given. For example:
  4454. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4455. would skip entries that haven't been marked with any of \"DONE\"
  4456. keywords. Possible classes are: `todo', `done', `any'.
  4457. If any of these conditions is met, this function returns the end point of
  4458. the entity, causing the search to continue from there. This is a function
  4459. that can be put into `org-agenda-skip-function' for the duration of a command."
  4460. (let (beg end m)
  4461. (org-back-to-heading t)
  4462. (setq beg (point)
  4463. end (if subtree
  4464. (progn (org-end-of-subtree t) (point))
  4465. (progn (outline-next-heading) (1- (point)))))
  4466. (goto-char beg)
  4467. (and
  4468. (or
  4469. (and (memq 'scheduled conditions)
  4470. (re-search-forward org-scheduled-time-regexp end t))
  4471. (and (memq 'notscheduled conditions)
  4472. (not (re-search-forward org-scheduled-time-regexp end t)))
  4473. (and (memq 'deadline conditions)
  4474. (re-search-forward org-deadline-time-regexp end t))
  4475. (and (memq 'notdeadline conditions)
  4476. (not (re-search-forward org-deadline-time-regexp end t)))
  4477. (and (memq 'timestamp conditions)
  4478. (re-search-forward org-ts-regexp end t))
  4479. (and (memq 'nottimestamp conditions)
  4480. (not (re-search-forward org-ts-regexp end t)))
  4481. (and (setq m (memq 'regexp conditions))
  4482. (stringp (nth 1 m))
  4483. (re-search-forward (nth 1 m) end t))
  4484. (and (setq m (memq 'notregexp conditions))
  4485. (stringp (nth 1 m))
  4486. (not (re-search-forward (nth 1 m) end t)))
  4487. (and (or
  4488. (setq m (memq 'nottodo conditions))
  4489. (setq m (memq 'todo-unblocked conditions))
  4490. (setq m (memq 'nottodo-unblocked conditions))
  4491. (setq m (memq 'todo conditions)))
  4492. (org-agenda-skip-if-todo m end)))
  4493. end)))
  4494. (defun org-agenda-skip-if-todo (args end)
  4495. "Helper function for `org-agenda-skip-if', do not use it directly.
  4496. ARGS is a list with first element either `todo', `nottodo',
  4497. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4498. a list of TODO keywords, or a state symbol `todo' or `done' or
  4499. `any'."
  4500. (let ((kw (car args))
  4501. (arg (cadr args))
  4502. todo-wds todo-re)
  4503. (setq todo-wds
  4504. (org-uniquify
  4505. (cond
  4506. ((listp arg) ;; list of keywords
  4507. (if (member "*" arg)
  4508. (mapcar 'substring-no-properties org-todo-keywords-1)
  4509. arg))
  4510. ((symbolp arg) ;; keyword class name
  4511. (cond
  4512. ((eq arg 'todo)
  4513. (org-delete-all org-done-keywords
  4514. (mapcar 'substring-no-properties
  4515. org-todo-keywords-1)))
  4516. ((eq arg 'done) org-done-keywords)
  4517. ((eq arg 'any)
  4518. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4519. (setq todo-re
  4520. (concat "^\\*+[ \t]+\\<\\("
  4521. (mapconcat 'identity todo-wds "\\|")
  4522. "\\)\\>"))
  4523. (cond
  4524. ((eq kw 'todo) (re-search-forward todo-re end t))
  4525. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4526. ((eq kw 'todo-unblocked)
  4527. (catch 'unblocked
  4528. (while (re-search-forward todo-re end t)
  4529. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4530. nil))
  4531. ((eq kw 'nottodo-unblocked)
  4532. (catch 'unblocked
  4533. (while (re-search-forward todo-re end t)
  4534. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4535. t))
  4536. )))
  4537. ;;;###autoload
  4538. (defun org-agenda-list-stuck-projects (&rest ignore)
  4539. "Create agenda view for projects that are stuck.
  4540. Stuck projects are project that have no next actions. For the definitions
  4541. of what a project is and how to check if it stuck, customize the variable
  4542. `org-stuck-projects'."
  4543. (interactive)
  4544. (let* ((org-agenda-skip-function
  4545. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4546. ;; We could have used org-agenda-skip-if here.
  4547. (org-agenda-overriding-header
  4548. (or org-agenda-overriding-header "List of stuck projects: "))
  4549. (matcher (nth 0 org-stuck-projects))
  4550. (todo (nth 1 org-stuck-projects))
  4551. (todo-wds (if (member "*" todo)
  4552. (progn
  4553. (org-agenda-prepare-buffers (org-agenda-files
  4554. nil 'ifmode))
  4555. (org-delete-all
  4556. org-done-keywords-for-agenda
  4557. (copy-sequence org-todo-keywords-for-agenda)))
  4558. todo))
  4559. (todo-re (concat "^\\*+[ \t]+\\("
  4560. (mapconcat 'identity todo-wds "\\|")
  4561. "\\)\\>"))
  4562. (tags (nth 2 org-stuck-projects))
  4563. (tags-re (if (member "*" tags)
  4564. (concat org-outline-regexp-bol
  4565. ".*:[[:alnum:]_@#%]+:[ \t]*$")
  4566. (if tags
  4567. (concat org-outline-regexp-bol
  4568. ".*:\\("
  4569. (mapconcat #'identity tags "\\|")
  4570. "\\):[[:alnum:]_@#%:]*[ \t]*$"))))
  4571. (gen-re (nth 3 org-stuck-projects))
  4572. (re-list
  4573. (delq nil
  4574. (list
  4575. (if todo todo-re)
  4576. (if tags tags-re)
  4577. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4578. gen-re)))))
  4579. (setq org-agenda-skip-regexp
  4580. (if re-list
  4581. (mapconcat 'identity re-list "\\|")
  4582. (error "No information how to identify unstuck projects")))
  4583. (org-tags-view nil matcher)
  4584. (setq org-agenda-buffer-name (buffer-name))
  4585. (with-current-buffer org-agenda-buffer-name
  4586. (setq org-agenda-redo-command
  4587. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4588. ;;; Diary integration
  4589. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4590. (defvar diary-list-entries-hook)
  4591. (defvar diary-time-regexp)
  4592. (defun org-get-entries-from-diary (date)
  4593. "Get the (Emacs Calendar) diary entries for DATE."
  4594. (require 'diary-lib)
  4595. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4596. (diary-display-function 'diary-fancy-display)
  4597. (pop-up-frames nil)
  4598. (diary-list-entries-hook
  4599. (cons 'org-diary-default-entry diary-list-entries-hook))
  4600. (diary-file-name-prefix nil) ; turn this feature off
  4601. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4602. entries
  4603. (org-disable-agenda-to-diary t))
  4604. (save-excursion
  4605. (save-window-excursion
  4606. (funcall (if (fboundp 'diary-list-entries)
  4607. 'diary-list-entries 'list-diary-entries)
  4608. date 1)))
  4609. (if (not (get-buffer diary-fancy-buffer))
  4610. (setq entries nil)
  4611. (with-current-buffer diary-fancy-buffer
  4612. (setq buffer-read-only nil)
  4613. (if (zerop (buffer-size))
  4614. ;; No entries
  4615. (setq entries nil)
  4616. ;; Omit the date and other unnecessary stuff
  4617. (org-agenda-cleanup-fancy-diary)
  4618. ;; Add prefix to each line and extend the text properties
  4619. (if (zerop (buffer-size))
  4620. (setq entries nil)
  4621. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4622. (setq entries
  4623. (with-temp-buffer
  4624. (insert entries) (goto-char (point-min))
  4625. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4626. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4627. (replace-match (concat "; " (match-string 1)))))
  4628. (buffer-string)))))
  4629. (set-buffer-modified-p nil)
  4630. (kill-buffer diary-fancy-buffer)))
  4631. (when entries
  4632. (setq entries (org-split-string entries "\n"))
  4633. (setq entries
  4634. (mapcar
  4635. (lambda (x)
  4636. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4637. ;; Extend the text properties to the beginning of the line
  4638. (org-add-props x (text-properties-at (1- (length x)) x)
  4639. 'type "diary" 'date date 'face 'org-agenda-diary))
  4640. entries)))))
  4641. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4642. "Hook run when the fancy diary buffer is cleaned up.")
  4643. (defun org-agenda-cleanup-fancy-diary ()
  4644. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4645. This gets rid of the date, the underline under the date, and
  4646. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4647. date. It also removes lines that contain only whitespace."
  4648. (goto-char (point-min))
  4649. (if (looking-at ".*?:[ \t]*")
  4650. (progn
  4651. (replace-match "")
  4652. (re-search-forward "\n=+$" nil t)
  4653. (replace-match "")
  4654. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4655. (re-search-forward "\n=+$" nil t)
  4656. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4657. (goto-char (point-min))
  4658. (while (re-search-forward "^ +\n" nil t)
  4659. (replace-match ""))
  4660. (goto-char (point-min))
  4661. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4662. (replace-match ""))
  4663. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4664. ;; Make sure entries from the diary have the right text properties.
  4665. (eval-after-load "diary-lib"
  4666. '(if (boundp 'diary-modify-entry-list-string-function)
  4667. ;; We can rely on the hook, nothing to do
  4668. nil
  4669. ;; Hook not available, must use advice to make this work
  4670. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4671. "Make the position visible."
  4672. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4673. (stringp string)
  4674. buffer-file-name)
  4675. (setq string (org-modify-diary-entry-string string))))))
  4676. (defun org-modify-diary-entry-string (string)
  4677. "Add text properties to string, allowing Org to act on it."
  4678. (org-add-props string nil
  4679. 'mouse-face 'highlight
  4680. 'help-echo (if buffer-file-name
  4681. (format "mouse-2 or RET jump to diary file %s"
  4682. (abbreviate-file-name buffer-file-name))
  4683. "")
  4684. 'org-agenda-diary-link t
  4685. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4686. (defun org-diary-default-entry ()
  4687. "Add a dummy entry to the diary.
  4688. Needed to avoid empty dates which mess up holiday display."
  4689. ;; Catch the error if dealing with the new add-to-diary-alist
  4690. (when org-disable-agenda-to-diary
  4691. (condition-case nil
  4692. (org-add-to-diary-list original-date "Org mode dummy" "")
  4693. (error
  4694. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4695. (defun org-add-to-diary-list (&rest args)
  4696. (if (fboundp 'diary-add-to-list)
  4697. (apply 'diary-add-to-list args)
  4698. (apply 'add-to-diary-list args)))
  4699. (defvar org-diary-last-run-time nil)
  4700. ;;;###autoload
  4701. (defun org-diary (&rest args)
  4702. "Return diary information from org files.
  4703. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4704. It accesses org files and extracts information from those files to be
  4705. listed in the diary. The function accepts arguments specifying what
  4706. items should be listed. For a list of arguments allowed here, see the
  4707. variable `org-agenda-entry-types'.
  4708. The call in the diary file should look like this:
  4709. &%%(org-diary) ~/path/to/some/orgfile.org
  4710. Use a separate line for each org file to check. Or, if you omit the file name,
  4711. all files listed in `org-agenda-files' will be checked automatically:
  4712. &%%(org-diary)
  4713. If you don't give any arguments (as in the example above), the default value
  4714. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4715. So the example above may also be written as
  4716. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4717. The function expects the lisp variables `entry' and `date' to be provided
  4718. by the caller, because this is how the calendar works. Don't use this
  4719. function from a program - use `org-agenda-get-day-entries' instead."
  4720. (when (> (- (float-time)
  4721. org-agenda-last-marker-time)
  4722. 5)
  4723. ;; I am not sure if this works with sticky agendas, because the marker
  4724. ;; list is then no longer a global variable.
  4725. (org-agenda-reset-markers))
  4726. (org-compile-prefix-format 'agenda)
  4727. (org-set-sorting-strategy 'agenda)
  4728. (setq args (or args org-agenda-entry-types))
  4729. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4730. (list entry)
  4731. (org-agenda-files t)))
  4732. (time (float-time))
  4733. file rtn results)
  4734. (when (or (not org-diary-last-run-time)
  4735. (> (- time
  4736. org-diary-last-run-time)
  4737. 3))
  4738. (org-agenda-prepare-buffers files))
  4739. (setq org-diary-last-run-time time)
  4740. ;; If this is called during org-agenda, don't return any entries to
  4741. ;; the calendar. Org Agenda will list these entries itself.
  4742. (if org-disable-agenda-to-diary (setq files nil))
  4743. (while (setq file (pop files))
  4744. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4745. (setq results (append results rtn)))
  4746. (when results
  4747. (setq results
  4748. (mapcar (lambda (i) (replace-regexp-in-string
  4749. org-bracket-link-regexp "\\3" i)) results))
  4750. (concat (org-agenda-finalize-entries results) "\n"))))
  4751. ;;; Agenda entry finders
  4752. (defun org-agenda--timestamp-to-absolute (&rest args)
  4753. "Call `org-time-string-to-absolute' with ARGS.
  4754. However, throw `:skip' whenever an error is raised."
  4755. (condition-case e
  4756. (apply #'org-time-string-to-absolute args)
  4757. (org-diary-sexp-no-match (throw :skip nil))
  4758. (error
  4759. (message "%s; Skipping entry" (error-message-string e))
  4760. (throw :skip nil))))
  4761. (defun org-agenda-get-day-entries (file date &rest args)
  4762. "Does the work for `org-diary' and `org-agenda'.
  4763. FILE is the path to a file to be checked for entries. DATE is date like
  4764. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4765. which kind of entries should be extracted. For details about these, see
  4766. the documentation of `org-diary'."
  4767. (let* ((org-startup-folded nil)
  4768. (org-startup-align-all-tables nil)
  4769. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4770. (error "No such file %s" file))))
  4771. (if (not buffer)
  4772. ;; If file does not exist, signal it in diary nonetheless.
  4773. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4774. (with-current-buffer buffer
  4775. (unless (derived-mode-p 'org-mode)
  4776. (error "Agenda file %s is not in `org-mode'" file))
  4777. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4778. (setf org-agenda-current-date date)
  4779. (save-excursion
  4780. (save-restriction
  4781. (if (eq buffer org-agenda-restrict)
  4782. (narrow-to-region org-agenda-restrict-begin
  4783. org-agenda-restrict-end)
  4784. (widen))
  4785. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4786. ;; first in order to populate DEADLINES before passing it.
  4787. ;;
  4788. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4789. ;; guarding us from modifying `org-agenda-entry-types'.
  4790. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4791. (when (and (memq :scheduled args) (memq :scheduled* args))
  4792. (setf args (delq :scheduled* args)))
  4793. (cond
  4794. ((memq :deadline args)
  4795. (setf args (cons :deadline
  4796. (delq :deadline (delq :deadline* args)))))
  4797. ((memq :deadline* args)
  4798. (setf args (cons :deadline* (delq :deadline* args)))))
  4799. ;; Collect list of headlines. Return them flattened.
  4800. (let ((case-fold-search nil) results deadlines)
  4801. (dolist (arg args (apply #'nconc (nreverse results)))
  4802. (pcase arg
  4803. ((and :todo (guard (org-agenda-today-p date)))
  4804. (push (org-agenda-get-todos) results))
  4805. (:timestamp
  4806. (push (org-agenda-get-blocks) results)
  4807. (push (org-agenda-get-timestamps deadlines) results))
  4808. (:sexp
  4809. (push (org-agenda-get-sexps) results))
  4810. (:scheduled
  4811. (push (org-agenda-get-scheduled deadlines) results))
  4812. (:scheduled*
  4813. (push (org-agenda-get-scheduled deadlines t) results))
  4814. (:closed
  4815. (push (org-agenda-get-progress) results))
  4816. (:deadline
  4817. (setf deadlines (org-agenda-get-deadlines))
  4818. (push deadlines results))
  4819. (:deadline*
  4820. (setf deadlines (org-agenda-get-deadlines t))
  4821. (push deadlines results)))))))))))
  4822. (defsubst org-em (x y list)
  4823. "Is X or Y a member of LIST?"
  4824. (or (memq x list) (memq y list)))
  4825. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4826. (defvar org-agenda-sorting-strategy-selected nil)
  4827. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4828. "Retrieve timestamp information for sorting agenda views.
  4829. Given a point or marker POM, returns a cons cell of the timestamp
  4830. and the timestamp type relevant for the sorting strategy in
  4831. `org-agenda-sorting-strategy-selected'."
  4832. (let (ts ts-date-type)
  4833. (save-match-data
  4834. (cond ((org-em 'scheduled-up 'scheduled-down
  4835. org-agenda-sorting-strategy-selected)
  4836. (setq ts (org-entry-get pom "SCHEDULED")
  4837. ts-date-type " scheduled"))
  4838. ((org-em 'deadline-up 'deadline-down
  4839. org-agenda-sorting-strategy-selected)
  4840. (setq ts (org-entry-get pom "DEADLINE")
  4841. ts-date-type " deadline"))
  4842. ((org-em 'ts-up 'ts-down
  4843. org-agenda-sorting-strategy-selected)
  4844. (setq ts (org-entry-get pom "TIMESTAMP")
  4845. ts-date-type " timestamp"))
  4846. ((org-em 'tsia-up 'tsia-down
  4847. org-agenda-sorting-strategy-selected)
  4848. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4849. ts-date-type " timestamp_ia"))
  4850. ((org-em 'timestamp-up 'timestamp-down
  4851. org-agenda-sorting-strategy-selected)
  4852. (setq ts (or (org-entry-get pom "SCHEDULED")
  4853. (org-entry-get pom "DEADLINE")
  4854. (org-entry-get pom "TIMESTAMP")
  4855. (org-entry-get pom "TIMESTAMP_IA"))
  4856. ts-date-type ""))
  4857. (t (setq ts-date-type "")))
  4858. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4859. ts-date-type))))
  4860. (defun org-agenda-get-todos ()
  4861. "Return the TODO information for agenda display."
  4862. (let* ((props (list 'face nil
  4863. 'done-face 'org-agenda-done
  4864. 'org-not-done-regexp org-not-done-regexp
  4865. 'org-todo-regexp org-todo-regexp
  4866. 'org-complex-heading-regexp org-complex-heading-regexp
  4867. 'mouse-face 'highlight
  4868. 'help-echo
  4869. (format "mouse-2 or RET jump to org file %s"
  4870. (abbreviate-file-name buffer-file-name))))
  4871. (case-fold-search nil)
  4872. (regexp (format org-heading-keyword-regexp-format
  4873. (cond
  4874. ((and org-select-this-todo-keyword
  4875. (equal org-select-this-todo-keyword "*"))
  4876. org-todo-regexp)
  4877. (org-select-this-todo-keyword
  4878. (concat "\\("
  4879. (mapconcat 'identity
  4880. (org-split-string
  4881. org-select-this-todo-keyword
  4882. "|")
  4883. "\\|") "\\)"))
  4884. (t org-not-done-regexp))))
  4885. marker priority category level tags todo-state
  4886. ts-date ts-date-type ts-date-pair
  4887. ee txt beg end inherited-tags todo-state-end-pos)
  4888. (goto-char (point-min))
  4889. (while (re-search-forward regexp nil t)
  4890. (catch :skip
  4891. (save-match-data
  4892. (beginning-of-line)
  4893. (org-agenda-skip)
  4894. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4895. (unless (and (setq todo-state (org-get-todo-state))
  4896. (setq todo-state-end-pos (match-end 2)))
  4897. (goto-char end)
  4898. (throw :skip nil))
  4899. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4900. (goto-char (1+ beg))
  4901. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4902. (throw :skip nil)))
  4903. (goto-char (match-beginning 2))
  4904. (setq marker (org-agenda-new-marker (match-beginning 0))
  4905. category (org-get-category)
  4906. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4907. ts-date (car ts-date-pair)
  4908. ts-date-type (cdr ts-date-pair)
  4909. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4910. inherited-tags
  4911. (or (eq org-agenda-show-inherited-tags 'always)
  4912. (and (listp org-agenda-show-inherited-tags)
  4913. (memq 'todo org-agenda-show-inherited-tags))
  4914. (and (eq org-agenda-show-inherited-tags t)
  4915. (or (eq org-agenda-use-tag-inheritance t)
  4916. (memq 'todo org-agenda-use-tag-inheritance))))
  4917. tags (org-get-tags-at nil (not inherited-tags))
  4918. level (make-string (org-reduced-level (org-outline-level)) ? )
  4919. txt (org-agenda-format-item "" txt level category tags t)
  4920. priority (1+ (org-get-priority txt)))
  4921. (org-add-props txt props
  4922. 'org-marker marker 'org-hd-marker marker
  4923. 'priority priority
  4924. 'level level
  4925. 'ts-date ts-date
  4926. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4927. (push txt ee)
  4928. (if org-agenda-todo-list-sublevels
  4929. (goto-char todo-state-end-pos)
  4930. (org-end-of-subtree 'invisible))))
  4931. (nreverse ee)))
  4932. (defun org-agenda-todo-custom-ignore-p (time n)
  4933. "Check whether timestamp is farther away than n number of days.
  4934. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4935. `org-agenda-todo-ignore-scheduled' or
  4936. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4937. (let ((days (org-time-stamp-to-now
  4938. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4939. (if (>= n 0)
  4940. (>= days n)
  4941. (<= days n))))
  4942. ;;;###autoload
  4943. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4944. (&optional end)
  4945. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4946. (when (or org-agenda-todo-ignore-with-date
  4947. org-agenda-todo-ignore-scheduled
  4948. org-agenda-todo-ignore-deadlines
  4949. org-agenda-todo-ignore-timestamp)
  4950. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4951. (save-excursion
  4952. (or (and org-agenda-todo-ignore-with-date
  4953. (re-search-forward org-ts-regexp end t))
  4954. (and org-agenda-todo-ignore-scheduled
  4955. (re-search-forward org-scheduled-time-regexp end t)
  4956. (cond
  4957. ((eq org-agenda-todo-ignore-scheduled 'future)
  4958. (> (org-time-stamp-to-now
  4959. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4960. ((eq org-agenda-todo-ignore-scheduled 'past)
  4961. (<= (org-time-stamp-to-now
  4962. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4963. ((numberp org-agenda-todo-ignore-scheduled)
  4964. (org-agenda-todo-custom-ignore-p
  4965. (match-string 1) org-agenda-todo-ignore-scheduled))
  4966. (t)))
  4967. (and org-agenda-todo-ignore-deadlines
  4968. (re-search-forward org-deadline-time-regexp end t)
  4969. (cond
  4970. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4971. ((eq org-agenda-todo-ignore-deadlines 'far)
  4972. (not (org-deadline-close-p (match-string 1))))
  4973. ((eq org-agenda-todo-ignore-deadlines 'future)
  4974. (> (org-time-stamp-to-now
  4975. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4976. ((eq org-agenda-todo-ignore-deadlines 'past)
  4977. (<= (org-time-stamp-to-now
  4978. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4979. ((numberp org-agenda-todo-ignore-deadlines)
  4980. (org-agenda-todo-custom-ignore-p
  4981. (match-string 1) org-agenda-todo-ignore-deadlines))
  4982. (t (org-deadline-close-p (match-string 1)))))
  4983. (and org-agenda-todo-ignore-timestamp
  4984. (let ((buffer (current-buffer))
  4985. (regexp
  4986. (concat
  4987. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4988. (start (point)))
  4989. ;; Copy current buffer into a temporary one
  4990. (with-temp-buffer
  4991. (insert-buffer-substring buffer start end)
  4992. (goto-char (point-min))
  4993. ;; Delete SCHEDULED and DEADLINE items
  4994. (while (re-search-forward regexp end t)
  4995. (delete-region (match-beginning 0) (match-end 0)))
  4996. (goto-char (point-min))
  4997. ;; No search for timestamp left
  4998. (when (re-search-forward org-ts-regexp nil t)
  4999. (cond
  5000. ((eq org-agenda-todo-ignore-timestamp 'future)
  5001. (> (org-time-stamp-to-now
  5002. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5003. ((eq org-agenda-todo-ignore-timestamp 'past)
  5004. (<= (org-time-stamp-to-now
  5005. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5006. ((numberp org-agenda-todo-ignore-timestamp)
  5007. (org-agenda-todo-custom-ignore-p
  5008. (match-string 1) org-agenda-todo-ignore-timestamp))
  5009. (t))))))))))
  5010. (defun org-agenda-get-timestamps (&optional deadlines)
  5011. "Return the date stamp information for agenda display.
  5012. Optional argument DEADLINES is a list of deadline items to be
  5013. displayed in agenda view."
  5014. (let* ((props (list 'face 'org-agenda-calendar-event
  5015. 'org-not-done-regexp org-not-done-regexp
  5016. 'org-todo-regexp org-todo-regexp
  5017. 'org-complex-heading-regexp org-complex-heading-regexp
  5018. 'mouse-face 'highlight
  5019. 'help-echo
  5020. (format "mouse-2 or RET jump to Org file %s"
  5021. (abbreviate-file-name buffer-file-name))))
  5022. (current (calendar-absolute-from-gregorian date))
  5023. (today (org-today))
  5024. (deadline-position-alist
  5025. (mapcar (lambda (d)
  5026. (let ((m (get-text-property 0 'org-hd-marker d)))
  5027. (and m (marker-position m))))
  5028. deadlines))
  5029. ;; Match time-stamps set to current date, time-stamps with
  5030. ;; a repeater, and S-exp time-stamps.
  5031. (regexp
  5032. (concat
  5033. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5034. (regexp-quote
  5035. (substring
  5036. (format-time-string
  5037. (car org-time-stamp-formats)
  5038. (apply #'encode-time ; DATE bound by calendar
  5039. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5040. 1 11))
  5041. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5042. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5043. timestamp-items)
  5044. (goto-char (point-min))
  5045. (while (re-search-forward regexp nil t)
  5046. ;; Skip date ranges, scheduled and deadlines, which are handled
  5047. ;; specially. Also skip time-stamps before first headline as
  5048. ;; there would be no entry to add to the agenda. Eventually,
  5049. ;; ignore clock entries.
  5050. (catch :skip
  5051. (save-match-data
  5052. (when (or (org-at-date-range-p)
  5053. (org-at-planning-p)
  5054. (org-before-first-heading-p)
  5055. (and org-agenda-include-inactive-timestamps
  5056. (org-at-clock-log-p)))
  5057. (throw :skip nil))
  5058. (org-agenda-skip))
  5059. (let* ((pos (match-beginning 0))
  5060. (repeat (match-string 1))
  5061. (sexp-entry (match-string 3))
  5062. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5063. (save-excursion
  5064. (goto-char pos)
  5065. (looking-at org-ts-regexp-both)
  5066. (match-string 0))))
  5067. (todo-state (org-get-todo-state))
  5068. (warntime (get-text-property (point) 'org-appt-warntime))
  5069. (done? (member todo-state org-done-keywords)))
  5070. ;; Possibly skip done tasks.
  5071. (when (and done? org-agenda-skip-timestamp-if-done)
  5072. (throw :skip t))
  5073. ;; S-exp entry doesn't match current day: skip it.
  5074. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5075. (throw :skip nil))
  5076. ;; A repeating time stamp is shown at its base date, and at
  5077. ;; every repeated date in the future.
  5078. (when repeat
  5079. (let* ((past
  5080. (if (or (eq org-agenda-prefer-last-repeat t)
  5081. (member todo-state org-agenda-prefer-last-repeat))
  5082. (org-agenda--timestamp-to-absolute
  5083. repeat today 'past (current-buffer) pos)
  5084. (org-agenda--timestamp-to-absolute repeat)))
  5085. (future
  5086. (cond
  5087. ((<= current today) past)
  5088. ((not org-agenda-show-future-repeats) past)
  5089. (t
  5090. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5091. (1+ today)
  5092. current)))
  5093. (org-agenda--timestamp-to-absolute
  5094. repeat base 'future (current-buffer) pos))))))
  5095. (when (and (/= current past) (/= current future))
  5096. (throw :skip nil))))
  5097. (save-excursion
  5098. (re-search-backward org-outline-regexp-bol nil t)
  5099. ;; Possibly skip time-stamp when a deadline is set.
  5100. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5101. (assq (point) deadline-position-alist))
  5102. (throw :skip nil))
  5103. (let* ((category (org-get-category pos))
  5104. (inherited-tags
  5105. (or (eq org-agenda-show-inherited-tags 'always)
  5106. (and (consp org-agenda-show-inherited-tags)
  5107. (memq 'agenda org-agenda-show-inherited-tags))
  5108. (and (eq org-agenda-show-inherited-tags t)
  5109. (or (eq org-agenda-use-tag-inheritance t)
  5110. (memq 'agenda
  5111. org-agenda-use-tag-inheritance)))))
  5112. (tags (org-get-tags-at nil (not inherited-tags)))
  5113. (level (make-string (org-reduced-level (org-outline-level))
  5114. ?\s))
  5115. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5116. (match-string 1)))
  5117. (inactive? (= (char-after pos) ?\[))
  5118. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5119. (item
  5120. (org-agenda-format-item
  5121. (and inactive? org-agenda-inactive-leader)
  5122. head level category tags time-stamp org-ts-regexp habit?)))
  5123. (org-add-props item props
  5124. 'priority (if habit?
  5125. (org-habit-get-priority (org-habit-parse-todo))
  5126. (org-get-priority item))
  5127. 'org-marker (org-agenda-new-marker pos)
  5128. 'org-hd-marker (org-agenda-new-marker)
  5129. 'date date
  5130. 'level level
  5131. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5132. current)
  5133. 'todo-state todo-state
  5134. 'warntime warntime
  5135. 'type "timestamp")
  5136. (push item timestamp-items))))
  5137. (when org-agenda-skip-additional-timestamps-same-entry
  5138. (outline-next-heading))))
  5139. (nreverse timestamp-items)))
  5140. (defun org-agenda-get-sexps ()
  5141. "Return the sexp information for agenda display."
  5142. (require 'diary-lib)
  5143. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5144. 'mouse-face 'highlight
  5145. 'help-echo
  5146. (format "mouse-2 or RET jump to org file %s"
  5147. (abbreviate-file-name buffer-file-name))))
  5148. (regexp "^&?%%(")
  5149. marker category extra level ee txt tags entry
  5150. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5151. (goto-char (point-min))
  5152. (while (re-search-forward regexp nil t)
  5153. (catch :skip
  5154. (org-agenda-skip)
  5155. (setq beg (match-beginning 0))
  5156. (goto-char (1- (match-end 0)))
  5157. (setq b (point))
  5158. (forward-sexp 1)
  5159. (setq sexp (buffer-substring b (point)))
  5160. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5161. (org-trim (match-string 1))
  5162. ""))
  5163. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5164. (when result
  5165. (setq marker (org-agenda-new-marker beg)
  5166. level (make-string (org-reduced-level (org-outline-level)) ? )
  5167. category (org-get-category beg)
  5168. inherited-tags
  5169. (or (eq org-agenda-show-inherited-tags 'always)
  5170. (and (listp org-agenda-show-inherited-tags)
  5171. (memq 'agenda org-agenda-show-inherited-tags))
  5172. (and (eq org-agenda-show-inherited-tags t)
  5173. (or (eq org-agenda-use-tag-inheritance t)
  5174. (memq 'agenda org-agenda-use-tag-inheritance))))
  5175. tags (org-get-tags-at nil (not inherited-tags))
  5176. todo-state (org-get-todo-state)
  5177. warntime (get-text-property (point) 'org-appt-warntime)
  5178. extra nil)
  5179. (dolist (r (if (stringp result)
  5180. (list result)
  5181. result)) ;; we expect a list here
  5182. (when (and org-agenda-diary-sexp-prefix
  5183. (string-match org-agenda-diary-sexp-prefix r))
  5184. (setq extra (match-string 0 r)
  5185. r (replace-match "" nil nil r)))
  5186. (if (string-match "\\S-" r)
  5187. (setq txt r)
  5188. (setq txt "SEXP entry returned empty string"))
  5189. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5190. (org-add-props txt props 'org-marker marker
  5191. 'date date 'todo-state todo-state
  5192. 'level level 'type "sexp" 'warntime warntime)
  5193. (push txt ee)))))
  5194. (nreverse ee)))
  5195. ;; Calendar sanity: define some functions that are independent of
  5196. ;; `calendar-date-style'.
  5197. (defun org-anniversary (year month day &optional mark)
  5198. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5199. (with-no-warnings
  5200. (let ((calendar-date-style 'iso))
  5201. (diary-anniversary year month day mark))))
  5202. (defun org-cyclic (N year month day &optional mark)
  5203. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5204. (with-no-warnings
  5205. (let ((calendar-date-style 'iso))
  5206. (diary-cyclic N year month day mark))))
  5207. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5208. "Like `diary-block', but with fixed (ISO) order of arguments."
  5209. (with-no-warnings
  5210. (let ((calendar-date-style 'iso))
  5211. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5212. (defun org-date (year month day &optional mark)
  5213. "Like `diary-date', but with fixed (ISO) order of arguments."
  5214. (with-no-warnings
  5215. (let ((calendar-date-style 'iso))
  5216. (diary-date year month day mark))))
  5217. ;; Define the `org-class' function
  5218. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5219. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5220. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5221. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5222. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5223. `holidays', then any date that is known by the Emacs calendar to be a
  5224. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5225. then those holidays will be skipped."
  5226. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5227. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5228. (d (calendar-absolute-from-gregorian date))
  5229. (h (when skip-weeks (calendar-check-holidays date))))
  5230. (and
  5231. (<= date1 d)
  5232. (<= d date2)
  5233. (= (calendar-day-of-week date) dayname)
  5234. (or (not skip-weeks)
  5235. (progn
  5236. (require 'cal-iso)
  5237. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5238. (not (or (and h (memq 'holidays skip-weeks))
  5239. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5240. entry)))
  5241. (defalias 'org-get-closed 'org-agenda-get-progress)
  5242. (defun org-agenda-get-progress ()
  5243. "Return the logged TODO entries for agenda display."
  5244. (let* ((props (list 'mouse-face 'highlight
  5245. 'org-not-done-regexp org-not-done-regexp
  5246. 'org-todo-regexp org-todo-regexp
  5247. 'org-complex-heading-regexp org-complex-heading-regexp
  5248. 'help-echo
  5249. (format "mouse-2 or RET jump to org file %s"
  5250. (abbreviate-file-name buffer-file-name))))
  5251. (items (if (consp org-agenda-show-log-scoped)
  5252. org-agenda-show-log-scoped
  5253. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5254. '(clock)
  5255. org-agenda-log-mode-items)))
  5256. (parts
  5257. (delq nil
  5258. (list
  5259. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5260. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5261. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5262. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5263. (error "`org-agenda-log-mode-items' is empty")))
  5264. (regexp (concat
  5265. "\\(" parts-re "\\)"
  5266. " *\\["
  5267. (regexp-quote
  5268. (substring
  5269. (format-time-string
  5270. (car org-time-stamp-formats)
  5271. (apply 'encode-time ; DATE bound by calendar
  5272. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5273. 1 11))))
  5274. (org-agenda-search-headline-for-time nil)
  5275. marker hdmarker priority category level tags closedp
  5276. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5277. (goto-char (point-min))
  5278. (while (re-search-forward regexp nil t)
  5279. (catch :skip
  5280. (org-agenda-skip)
  5281. (setq marker (org-agenda-new-marker (match-beginning 0))
  5282. closedp (equal (match-string 1) org-closed-string)
  5283. statep (equal (string-to-char (match-string 1)) ?-)
  5284. clockp (not (or closedp statep))
  5285. state (and statep (match-string 2))
  5286. category (org-get-category (match-beginning 0))
  5287. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5288. (when (string-match "\\]" timestr)
  5289. ;; substring should only run to end of time stamp
  5290. (setq rest (substring timestr (match-end 0))
  5291. timestr (substring timestr 0 (match-end 0)))
  5292. (if (and (not closedp) (not statep)
  5293. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5294. rest))
  5295. (progn (setq timestr (concat (substring timestr 0 -1)
  5296. "-" (match-string 1 rest) "]"))
  5297. (setq clocked (match-string 2 rest)))
  5298. (setq clocked "-")))
  5299. (save-excursion
  5300. (setq extra
  5301. (cond
  5302. ((not org-agenda-log-mode-add-notes) nil)
  5303. (statep
  5304. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5305. (match-string 1)))
  5306. (clockp
  5307. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5308. (match-string 1)))))
  5309. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5310. (throw :skip nil)
  5311. (goto-char (match-beginning 0))
  5312. (setq hdmarker (org-agenda-new-marker)
  5313. inherited-tags
  5314. (or (eq org-agenda-show-inherited-tags 'always)
  5315. (and (listp org-agenda-show-inherited-tags)
  5316. (memq 'todo org-agenda-show-inherited-tags))
  5317. (and (eq org-agenda-show-inherited-tags t)
  5318. (or (eq org-agenda-use-tag-inheritance t)
  5319. (memq 'todo org-agenda-use-tag-inheritance))))
  5320. tags (org-get-tags-at nil (not inherited-tags))
  5321. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5322. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5323. (setq txt (match-string 1))
  5324. (when extra
  5325. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5326. (setq txt (concat (substring txt 0 (match-beginning 1))
  5327. " - " extra " " (match-string 2 txt)))
  5328. (setq txt (concat txt " - " extra))))
  5329. (setq txt (org-agenda-format-item
  5330. (cond
  5331. (closedp "Closed: ")
  5332. (statep (concat "State: (" state ")"))
  5333. (t (concat "Clocked: (" clocked ")")))
  5334. txt level category tags timestr)))
  5335. (setq priority 100000)
  5336. (org-add-props txt props
  5337. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5338. 'priority priority 'level level
  5339. 'type "closed" 'date date
  5340. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5341. (push txt ee))
  5342. (goto-char (point-at-eol))))
  5343. (nreverse ee)))
  5344. (defun org-agenda-show-clocking-issues ()
  5345. "Add overlays, showing issues with clocking.
  5346. See also the user option `org-agenda-clock-consistency-checks'."
  5347. (interactive)
  5348. (let* ((org-time-clocksum-use-effort-durations nil)
  5349. (pl org-agenda-clock-consistency-checks)
  5350. (re (concat "^[ \t]*"
  5351. org-clock-string
  5352. "[ \t]+"
  5353. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5354. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5355. (tlstart 0.)
  5356. (tlend 0.)
  5357. (maxtime (org-hh:mm-string-to-minutes
  5358. (or (plist-get pl :max-duration) "24:00")))
  5359. (mintime (org-hh:mm-string-to-minutes
  5360. (or (plist-get pl :min-duration) 0)))
  5361. (maxgap (org-hh:mm-string-to-minutes
  5362. ;; default 30:00 means never complain
  5363. (or (plist-get pl :max-gap) "30:00")))
  5364. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5365. (plist-get pl :gap-ok-around)))
  5366. (def-face (or (plist-get pl :default-face)
  5367. '((:background "DarkRed") (:foreground "white"))))
  5368. issue face m te ts dt ov)
  5369. (goto-char (point-min))
  5370. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5371. (setq issue nil face def-face)
  5372. (catch 'next
  5373. (setq m (org-get-at-bol 'org-marker)
  5374. te nil ts nil)
  5375. (unless (and m (markerp m))
  5376. (setq issue "No valid clock line") (throw 'next t))
  5377. (org-with-point-at m
  5378. (save-excursion
  5379. (goto-char (point-at-bol))
  5380. (unless (looking-at re)
  5381. (error "No valid Clock line")
  5382. (throw 'next t))
  5383. (unless (match-end 3)
  5384. (setq issue "No end time"
  5385. face (or (plist-get pl :no-end-time-face) face))
  5386. (throw 'next t))
  5387. (setq ts (match-string 1)
  5388. te (match-string 3)
  5389. ts (float-time
  5390. (apply #'encode-time (org-parse-time-string ts)))
  5391. te (float-time
  5392. (apply #'encode-time (org-parse-time-string te)))
  5393. dt (- te ts))))
  5394. (cond
  5395. ((> dt (* 60 maxtime))
  5396. ;; a very long clocking chunk
  5397. (setq issue (format "Clocking interval is very long: %s"
  5398. (org-minutes-to-clocksum-string
  5399. (floor (/ (float dt) 60.))))
  5400. face (or (plist-get pl :long-face) face)))
  5401. ((< dt (* 60 mintime))
  5402. ;; a very short clocking chunk
  5403. (setq issue (format "Clocking interval is very short: %s"
  5404. (org-minutes-to-clocksum-string
  5405. (floor (/ (float dt) 60.))))
  5406. face (or (plist-get pl :short-face) face)))
  5407. ((and (> tlend 0) (< ts tlend))
  5408. ;; Two clock entries are overlapping
  5409. (setq issue (format "Clocking overlap: %d minutes"
  5410. (/ (- tlend ts) 60))
  5411. face (or (plist-get pl :overlap-face) face)))
  5412. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5413. ;; There is a gap, lets see if we need to report it
  5414. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5415. (setq issue (format "Clocking gap: %d minutes"
  5416. (/ (- ts tlend) 60))
  5417. face (or (plist-get pl :gap-face) face))))
  5418. (t nil)))
  5419. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5420. (when issue
  5421. ;; OK, there was some issue, add an overlay to show the issue
  5422. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5423. (overlay-put ov 'before-string
  5424. (concat
  5425. (org-add-props
  5426. (format "%-43s" (concat " " issue))
  5427. nil
  5428. 'face face)
  5429. "\n"))
  5430. (overlay-put ov 'evaporate t)))))
  5431. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5432. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5433. (catch 'exit
  5434. (unless ok-list
  5435. ;; there are no OK times for gaps...
  5436. (throw 'exit nil))
  5437. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5438. ;; This is more than 24 hours, so it is OK.
  5439. ;; because we have at least one OK time, that must be in the
  5440. ;; 24 hour interval.
  5441. (throw 'exit t))
  5442. ;; We have a shorter gap.
  5443. ;; Now we have to get the minute of the day when these times are
  5444. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5445. (t2dec (decode-time (seconds-to-time t2)))
  5446. ;; compute the minute on the day
  5447. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5448. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5449. (when (< min2 min1)
  5450. ;; if min2 is smaller than min1, this means it is on the next day.
  5451. ;; Wrap it to after midnight.
  5452. (setq min2 (+ min2 1440)))
  5453. ;; Now check if any of the OK times is in the gap
  5454. (mapc (lambda (x)
  5455. ;; Wrap the time to after midnight if necessary
  5456. (if (< x min1) (setq x (+ x 1440)))
  5457. ;; Check if in interval
  5458. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5459. ok-list)
  5460. ;; Nope, this gap is not OK
  5461. nil)))
  5462. (defun org-agenda-get-deadlines (&optional with-hour)
  5463. "Return the deadline information for agenda display.
  5464. When WITH-HOUR is non-nil, only return deadlines with an hour
  5465. specification like [h]h:mm."
  5466. (let* ((props (list 'mouse-face 'highlight
  5467. 'org-not-done-regexp org-not-done-regexp
  5468. 'org-todo-regexp org-todo-regexp
  5469. 'org-complex-heading-regexp org-complex-heading-regexp
  5470. 'help-echo
  5471. (format "mouse-2 or RET jump to org file %s"
  5472. (abbreviate-file-name buffer-file-name))))
  5473. (regexp (if with-hour
  5474. org-deadline-time-hour-regexp
  5475. org-deadline-time-regexp))
  5476. (today (org-today))
  5477. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5478. (current (calendar-absolute-from-gregorian date))
  5479. deadline-items)
  5480. (goto-char (point-min))
  5481. (while (re-search-forward regexp nil t)
  5482. (catch :skip
  5483. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5484. (org-agenda-skip)
  5485. (let* ((s (match-string 1))
  5486. (pos (1- (match-beginning 1)))
  5487. (todo-state (save-match-data (org-get-todo-state)))
  5488. (done? (member todo-state org-done-keywords))
  5489. ;; DEADLINE is the deadline date for the entry. It is
  5490. ;; either the base date or the last repeat, according
  5491. ;; to `org-agenda-prefer-last-repeat'.
  5492. (deadline
  5493. (if (or (eq org-agenda-prefer-last-repeat t)
  5494. (member todo-state org-agenda-prefer-last-repeat))
  5495. (org-agenda--timestamp-to-absolute
  5496. s today 'past (current-buffer) pos)
  5497. (org-agenda--timestamp-to-absolute s)))
  5498. ;; REPEAT is the future repeat closest from CURRENT,
  5499. ;; according to `org-agenda-show-future-repeats'. If
  5500. ;; the latter is nil, or if the time stamp has no
  5501. ;; repeat part, default to DEADLINE.
  5502. (repeat
  5503. (cond
  5504. ((<= current today) deadline)
  5505. ((not org-agenda-show-future-repeats) deadline)
  5506. (t
  5507. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5508. (1+ today)
  5509. current)))
  5510. (org-agenda--timestamp-to-absolute
  5511. s base 'future (current-buffer) pos)))))
  5512. (diff (- deadline current))
  5513. (suppress-prewarning
  5514. (let ((scheduled
  5515. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5516. (org-entry-get nil "SCHEDULED"))))
  5517. (cond
  5518. ((not scheduled) nil)
  5519. ;; The current item has a scheduled date, so
  5520. ;; evaluate its prewarning lead time.
  5521. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5522. ;; Use global prewarning-restart lead time.
  5523. org-agenda-skip-deadline-prewarning-if-scheduled)
  5524. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5525. 'pre-scheduled)
  5526. ;; Set pre-warning to no earlier than SCHEDULED.
  5527. (min (- deadline
  5528. (org-agenda--timestamp-to-absolute scheduled))
  5529. org-deadline-warning-days))
  5530. ;; Set pre-warning to deadline.
  5531. (t 0))))
  5532. (wdays (if suppress-prewarning
  5533. (let ((org-deadline-warning-days suppress-prewarning))
  5534. (org-get-wdays s))
  5535. (org-get-wdays s))))
  5536. ;; Display deadlines items at base date (DEADLINE), today,
  5537. ;; if deadline is overdue or if the expiration of the
  5538. ;; upcoming deadline is within WDAYS warning time. Also,
  5539. ;; show any repeat past today.
  5540. (when (or (and (/= current deadline)
  5541. (/= current today)
  5542. (/= current repeat))
  5543. (and today?
  5544. (> deadline current)
  5545. (> diff wdays)))
  5546. (throw :skip nil))
  5547. ;; Possibly skip done tasks.
  5548. (when (and done?
  5549. (or org-agenda-skip-deadline-if-done
  5550. (/= deadline current)))
  5551. (throw :skip nil))
  5552. (save-excursion
  5553. (re-search-backward "^\\*+[ \t]+" nil t)
  5554. (goto-char (match-end 0))
  5555. (let* ((category (org-get-category))
  5556. (level (make-string (org-reduced-level (org-outline-level))
  5557. ?\s))
  5558. (head (buffer-substring (point) (line-end-position)))
  5559. (inherited-tags
  5560. (or (eq org-agenda-show-inherited-tags 'always)
  5561. (and (listp org-agenda-show-inherited-tags)
  5562. (memq 'agenda org-agenda-show-inherited-tags))
  5563. (and (eq org-agenda-show-inherited-tags t)
  5564. (or (eq org-agenda-use-tag-inheritance t)
  5565. (memq 'agenda
  5566. org-agenda-use-tag-inheritance)))))
  5567. (tags (org-get-tags-at nil (not inherited-tags)))
  5568. (time
  5569. (cond
  5570. ;; No time of day designation if it is only
  5571. ;; a reminder.
  5572. ((and (/= current deadline) (/= current repeat)) nil)
  5573. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5574. (concat (substring s (match-beginning 1)) " "))
  5575. (t 'time)))
  5576. (item
  5577. (org-agenda-format-item
  5578. ;; Insert appropriate suffixes before deadlines.
  5579. ;; Those only apply to today agenda.
  5580. (pcase-let ((`(,now ,future ,past)
  5581. org-agenda-deadline-leaders))
  5582. (cond
  5583. ((and today? (< deadline today)) (format past (- diff)))
  5584. ((and today? (> deadline today)) (format future diff))
  5585. (t now)))
  5586. head level category tags time))
  5587. (face (org-agenda-deadline-face
  5588. (- 1 (/ (float diff) (max wdays 1)))))
  5589. (upcoming? (and today? (> deadline today)))
  5590. (warntime (get-text-property (point) 'org-appt-warntime)))
  5591. (org-add-props item props
  5592. 'org-marker (org-agenda-new-marker pos)
  5593. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5594. 'warntime warntime
  5595. 'level level
  5596. 'ts-date deadline
  5597. 'priority
  5598. ;; Adjust priority to today reminders about deadlines.
  5599. ;; Overdue deadlines get the highest priority
  5600. ;; increase, then imminent deadlines and eventually
  5601. ;; more distant deadlines.
  5602. (let ((adjust (if today? (- diff) 0)))
  5603. (+ adjust (org-get-priority item)))
  5604. 'todo-state todo-state
  5605. 'type (if upcoming? "upcoming-deadline" "deadline")
  5606. 'date (if upcoming? date deadline)
  5607. 'face (if done? 'org-agenda-done face)
  5608. 'undone-face face
  5609. 'done-face 'org-agenda-done)
  5610. (push item deadline-items))))))
  5611. (nreverse deadline-items)))
  5612. (defun org-agenda-deadline-face (fraction)
  5613. "Return the face to displaying a deadline item.
  5614. FRACTION is what fraction of the head-warning time has passed."
  5615. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5616. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5617. "Return the scheduled information for agenda display.
  5618. Optional argument DEADLINES is a list of deadline items to be
  5619. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5620. scheduled items with an hour specification like [h]h:mm."
  5621. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5622. 'org-todo-regexp org-todo-regexp
  5623. 'org-complex-heading-regexp org-complex-heading-regexp
  5624. 'done-face 'org-agenda-done
  5625. 'mouse-face 'highlight
  5626. 'help-echo
  5627. (format "mouse-2 or RET jump to Org file %s"
  5628. (abbreviate-file-name buffer-file-name))))
  5629. (regexp (if with-hour
  5630. org-scheduled-time-hour-regexp
  5631. org-scheduled-time-regexp))
  5632. (today (org-today))
  5633. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5634. (current (calendar-absolute-from-gregorian date))
  5635. (deadline-pos
  5636. (mapcar (lambda (d)
  5637. (let ((m (get-text-property 0 'org-hd-marker d)))
  5638. (and m (marker-position m))))
  5639. deadlines))
  5640. scheduled-items)
  5641. (goto-char (point-min))
  5642. (while (re-search-forward regexp nil t)
  5643. (catch :skip
  5644. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5645. (org-agenda-skip)
  5646. (let* ((s (match-string 1))
  5647. (pos (1- (match-beginning 1)))
  5648. (todo-state (save-match-data (org-get-todo-state)))
  5649. (donep (member todo-state org-done-keywords))
  5650. ;; SCHEDULE is the scheduled date for the entry. It is
  5651. ;; either the bare date or the last repeat, according
  5652. ;; to `org-agenda-prefer-last-repeat'.
  5653. (schedule
  5654. (if (or (eq org-agenda-prefer-last-repeat t)
  5655. (member todo-state org-agenda-prefer-last-repeat))
  5656. (org-agenda--timestamp-to-absolute
  5657. s today 'past (current-buffer) pos)
  5658. (org-agenda--timestamp-to-absolute s)))
  5659. ;; REPEAT is the future repeat closest from CURRENT,
  5660. ;; according to `org-agenda-show-future-repeats'. If
  5661. ;; the latter is nil, or if the time stamp has no
  5662. ;; repeat part, default to SCHEDULE.
  5663. (repeat
  5664. (cond
  5665. ((<= current today) schedule)
  5666. ((not org-agenda-show-future-repeats) schedule)
  5667. (t
  5668. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5669. (1+ today)
  5670. current)))
  5671. (org-agenda--timestamp-to-absolute
  5672. s base 'future (current-buffer) pos)))))
  5673. (diff (- current schedule))
  5674. (warntime (get-text-property (point) 'org-appt-warntime))
  5675. (pastschedp (< schedule today))
  5676. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5677. (suppress-delay
  5678. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5679. (org-entry-get nil "DEADLINE"))))
  5680. (cond
  5681. ((not deadline) nil)
  5682. ;; The current item has a deadline date, so
  5683. ;; evaluate its delay time.
  5684. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5685. ;; Use global delay time.
  5686. (- org-agenda-skip-scheduled-delay-if-deadline))
  5687. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5688. 'post-deadline)
  5689. ;; Set delay to no later than DEADLINE.
  5690. (min (- schedule
  5691. (org-agenda--timestamp-to-absolute deadline))
  5692. org-scheduled-delay-days))
  5693. (t 0))))
  5694. (ddays
  5695. (cond
  5696. ;; Nullify delay when a repeater triggered already
  5697. ;; and the delay is of the form --Xd.
  5698. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5699. (> current schedule))
  5700. 0)
  5701. (suppress-delay
  5702. (let ((org-scheduled-delay-days suppress-delay))
  5703. (org-get-wdays s t t)))
  5704. (t (org-get-wdays s t)))))
  5705. ;; Display scheduled items at base date (SCHEDULE), today if
  5706. ;; scheduled before the current date, and at any repeat past
  5707. ;; today. However, skip delayed items and items that have
  5708. ;; been displayed for more than `org-scheduled-past-days'.
  5709. (unless (and todayp
  5710. habitp
  5711. (bound-and-true-p org-habit-show-all-today))
  5712. (when (or (and (> ddays 0) (< diff ddays))
  5713. (> diff org-scheduled-past-days)
  5714. (> schedule current)
  5715. (and (/= current schedule)
  5716. (/= current today)
  5717. (/= current repeat)))
  5718. (throw :skip nil)))
  5719. ;; Possibly skip done tasks.
  5720. (when (and donep
  5721. (or org-agenda-skip-scheduled-if-done
  5722. (/= schedule current)))
  5723. (throw :skip nil))
  5724. ;; Skip entry if it already appears as a deadline, per
  5725. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5726. ;; doesn't apply to habits.
  5727. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5728. ((guard
  5729. (or (not (memq (line-beginning-position 0) deadline-pos))
  5730. habitp))
  5731. nil)
  5732. (`repeated-after-deadline
  5733. (let ((deadline (time-to-days
  5734. (org-get-deadline-time (point)))))
  5735. (and (<= schedule deadline) (> current deadline))))
  5736. (`not-today pastschedp)
  5737. (`t t)
  5738. (_ nil))
  5739. (throw :skip nil))
  5740. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5741. ;; only show them for today. Also skip done habits.
  5742. (when (and habitp
  5743. (or donep
  5744. (not (bound-and-true-p org-habit-show-habits))
  5745. (and (not todayp)
  5746. (bound-and-true-p
  5747. org-habit-show-habits-only-for-today))))
  5748. (throw :skip nil))
  5749. (save-excursion
  5750. (re-search-backward "^\\*+[ \t]+" nil t)
  5751. (goto-char (match-end 0))
  5752. (let* ((category (org-get-category))
  5753. (inherited-tags
  5754. (or (eq org-agenda-show-inherited-tags 'always)
  5755. (and (listp org-agenda-show-inherited-tags)
  5756. (memq 'agenda org-agenda-show-inherited-tags))
  5757. (and (eq org-agenda-show-inherited-tags t)
  5758. (or (eq org-agenda-use-tag-inheritance t)
  5759. (memq 'agenda
  5760. org-agenda-use-tag-inheritance)))))
  5761. (tags (org-get-tags-at nil (not inherited-tags)))
  5762. (level (make-string (org-reduced-level (org-outline-level))
  5763. ?\s))
  5764. (head (buffer-substring (point) (line-end-position)))
  5765. (time
  5766. (cond
  5767. ;; No time of day designation if it is only
  5768. ;; a reminder.
  5769. ((and (/= current schedule) (/= current repeat)) nil)
  5770. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5771. (concat (substring s (match-beginning 1)) " "))
  5772. (t 'time)))
  5773. (item
  5774. (org-agenda-format-item
  5775. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5776. ;; Show a reminder of a past scheduled today.
  5777. (if (and todayp pastschedp)
  5778. (format past (1+ diff))
  5779. first))
  5780. head level category tags time nil habitp))
  5781. (face (cond ((and (not habitp) pastschedp)
  5782. 'org-scheduled-previously)
  5783. (todayp 'org-scheduled-today)
  5784. (t 'org-scheduled)))
  5785. (habitp (and habitp (org-habit-parse-todo))))
  5786. (org-add-props item props
  5787. 'undone-face face
  5788. 'face (if donep 'org-agenda-done face)
  5789. 'org-marker (org-agenda-new-marker pos)
  5790. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5791. 'type (if pastschedp "past-scheduled" "scheduled")
  5792. 'date (if pastschedp schedule date)
  5793. 'ts-date schedule
  5794. 'warntime warntime
  5795. 'level level
  5796. 'priority (if habitp (org-habit-get-priority habitp)
  5797. (+ 99 diff (org-get-priority item)))
  5798. 'org-habit-p habitp
  5799. 'todo-state todo-state)
  5800. (push item scheduled-items))))))
  5801. (nreverse scheduled-items)))
  5802. (defun org-agenda-get-blocks ()
  5803. "Return the date-range information for agenda display."
  5804. (let* ((props (list 'face nil
  5805. 'org-not-done-regexp org-not-done-regexp
  5806. 'org-todo-regexp org-todo-regexp
  5807. 'org-complex-heading-regexp org-complex-heading-regexp
  5808. 'mouse-face 'highlight
  5809. 'help-echo
  5810. (format "mouse-2 or RET jump to org file %s"
  5811. (abbreviate-file-name buffer-file-name))))
  5812. (regexp org-tr-regexp)
  5813. (d0 (calendar-absolute-from-gregorian date))
  5814. marker hdmarker ee txt d1 d2 s1 s2 category
  5815. level todo-state tags pos head donep inherited-tags)
  5816. (goto-char (point-min))
  5817. (while (re-search-forward regexp nil t)
  5818. (catch :skip
  5819. (org-agenda-skip)
  5820. (setq pos (point))
  5821. (let ((start-time (match-string 1))
  5822. (end-time (match-string 2)))
  5823. (setq s1 (match-string 1)
  5824. s2 (match-string 2)
  5825. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5826. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5827. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5828. ;; Only allow days between the limits, because the normal
  5829. ;; date stamps will catch the limits.
  5830. (save-excursion
  5831. (setq todo-state (org-get-todo-state))
  5832. (setq donep (member todo-state org-done-keywords))
  5833. (if (and donep org-agenda-skip-timestamp-if-done)
  5834. (throw :skip t))
  5835. (setq marker (org-agenda-new-marker (point))
  5836. category (org-get-category))
  5837. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5838. (throw :skip nil)
  5839. (goto-char (match-beginning 0))
  5840. (setq hdmarker (org-agenda-new-marker (point))
  5841. inherited-tags
  5842. (or (eq org-agenda-show-inherited-tags 'always)
  5843. (and (listp org-agenda-show-inherited-tags)
  5844. (memq 'agenda org-agenda-show-inherited-tags))
  5845. (and (eq org-agenda-show-inherited-tags t)
  5846. (or (eq org-agenda-use-tag-inheritance t)
  5847. (memq 'agenda org-agenda-use-tag-inheritance))))
  5848. tags (org-get-tags-at nil (not inherited-tags)))
  5849. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5850. (looking-at "\\*+[ \t]+\\(.*\\)")
  5851. (setq head (match-string 1))
  5852. (let ((remove-re
  5853. (if org-agenda-remove-timeranges-from-blocks
  5854. (concat
  5855. "<" (regexp-quote s1) ".*?>"
  5856. "--"
  5857. "<" (regexp-quote s2) ".*?>")
  5858. nil)))
  5859. (setq txt (org-agenda-format-item
  5860. (format
  5861. (nth (if (= d1 d2) 0 1)
  5862. org-agenda-timerange-leaders)
  5863. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5864. head level category tags
  5865. (cond ((and (= d1 d0) (= d2 d0))
  5866. (concat "<" start-time ">--<" end-time ">"))
  5867. ((= d1 d0)
  5868. (concat "<" start-time ">"))
  5869. ((= d2 d0)
  5870. (concat "<" end-time ">")))
  5871. remove-re))))
  5872. (org-add-props txt props
  5873. 'org-marker marker 'org-hd-marker hdmarker
  5874. 'type "block" 'date date
  5875. 'level level
  5876. 'todo-state todo-state
  5877. 'priority (org-get-priority txt))
  5878. (push txt ee))))
  5879. (goto-char pos)))
  5880. ;; Sort the entries by expiration date.
  5881. (nreverse ee)))
  5882. ;;; Agenda presentation and sorting
  5883. (defvar org-prefix-has-time nil
  5884. "A flag, set by `org-compile-prefix-format'.
  5885. The flag is set if the currently compiled format contains a `%t'.")
  5886. (defvar org-prefix-has-tag nil
  5887. "A flag, set by `org-compile-prefix-format'.
  5888. The flag is set if the currently compiled format contains a `%T'.")
  5889. (defvar org-prefix-has-effort nil
  5890. "A flag, set by `org-compile-prefix-format'.
  5891. The flag is set if the currently compiled format contains a `%e'.")
  5892. (defvar org-prefix-has-breadcrumbs nil
  5893. "A flag, set by `org-compile-prefix-format'.
  5894. The flag is set if the currently compiled format contains a `%b'.")
  5895. (defvar org-prefix-category-length nil
  5896. "Used by `org-compile-prefix-format' to remember the category field width.")
  5897. (defvar org-prefix-category-max-length nil
  5898. "Used by `org-compile-prefix-format' to remember the category field width.")
  5899. (defun org-agenda-get-category-icon (category)
  5900. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5901. (cl-dolist (entry org-agenda-category-icon-alist)
  5902. (when (string-match-p (car entry) category)
  5903. (if (listp (cadr entry))
  5904. (cl-return (cadr entry))
  5905. (cl-return (apply #'create-image (cdr entry)))))))
  5906. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5907. remove-re habitp)
  5908. "Format TXT to be inserted into the agenda buffer.
  5909. In particular, add the prefix and corresponding text properties.
  5910. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5911. LEVEL may be a string to replace the `%l' specifier.
  5912. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5913. category taken from local variable or file name. It will replace the `%c'
  5914. specifier in the format.
  5915. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5916. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5917. When DOTIME is a string, this string is searched for a time before TXT is.
  5918. TAGS can be the tags of the headline.
  5919. Any match of REMOVE-RE will be removed from TXT."
  5920. ;; We keep the org-prefix-* variable values along with a compiled
  5921. ;; formatter, so that multiple agendas existing at the same time do
  5922. ;; not step on each other toes.
  5923. ;;
  5924. ;; It was inconvenient to make these variables buffer local in
  5925. ;; Agenda buffers, because this function expects to be called with
  5926. ;; the buffer where item comes from being current, and not agenda
  5927. ;; buffer
  5928. (let* ((bindings (car org-prefix-format-compiled))
  5929. (formatter (cadr org-prefix-format-compiled)))
  5930. (cl-loop for (var value) in bindings
  5931. do (set var value))
  5932. (save-match-data
  5933. ;; Diary entries sometimes have extra whitespace at the beginning
  5934. (setq txt (org-trim txt))
  5935. ;; Fix the tags part in txt
  5936. (setq txt (org-agenda-fix-displayed-tags
  5937. txt tags
  5938. org-agenda-show-inherited-tags
  5939. org-agenda-hide-tags-regexp))
  5940. (let* ((category (or category
  5941. (if buffer-file-name
  5942. (file-name-sans-extension
  5943. (file-name-nondirectory buffer-file-name))
  5944. "")))
  5945. (category-icon (org-agenda-get-category-icon category))
  5946. (category-icon (if category-icon
  5947. (propertize " " 'display category-icon)
  5948. ""))
  5949. (effort (and (not (string= txt ""))
  5950. (get-text-property 1 'effort txt)))
  5951. ;; time, tag, effort are needed for the eval of the prefix format
  5952. (tag (if tags (nth (1- (length tags)) tags) ""))
  5953. time
  5954. (ts (if dotime (concat
  5955. (if (stringp dotime) dotime "")
  5956. (and org-agenda-search-headline-for-time txt))))
  5957. (time-of-day (and dotime (org-get-time-of-day ts)))
  5958. stamp plain s0 s1 s2 rtn srp l
  5959. duration breadcrumbs)
  5960. (and (derived-mode-p 'org-mode) buffer-file-name
  5961. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5962. (when (and dotime time-of-day)
  5963. ;; Extract starting and ending time and move them to prefix
  5964. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5965. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5966. (setq s0 (match-string 0 ts)
  5967. srp (and stamp (match-end 3))
  5968. s1 (match-string (if plain 1 2) ts)
  5969. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5970. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5971. ;; them, we might want to remove them there to avoid duplication.
  5972. ;; The user can turn this off with a variable.
  5973. (if (and org-prefix-has-time
  5974. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5975. (string-match (concat (regexp-quote s0) " *") txt)
  5976. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5977. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5978. (= (match-beginning 0) 0)
  5979. t))
  5980. (setq txt (replace-match "" nil nil txt))))
  5981. ;; Normalize the time(s) to 24 hour
  5982. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5983. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5984. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5985. (let (org-time-clocksum-use-effort-durations)
  5986. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5987. (setq s2
  5988. (org-minutes-to-clocksum-string
  5989. (+ (org-hh:mm-string-to-minutes s1)
  5990. org-agenda-default-appointment-duration)))))
  5991. ;; Compute the duration
  5992. (when s2
  5993. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5994. (org-hh:mm-string-to-minutes s1)))))
  5995. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  5996. ;; Tags are in the string
  5997. (if (or (eq org-agenda-remove-tags t)
  5998. (and org-agenda-remove-tags
  5999. org-prefix-has-tag))
  6000. (setq txt (replace-match "" t t txt))
  6001. (setq txt (replace-match
  6002. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6003. (match-string 2 txt))
  6004. t t txt))))
  6005. (when remove-re
  6006. (while (string-match remove-re txt)
  6007. (setq txt (replace-match "" t t txt))))
  6008. ;; Set org-heading property on `txt' to mark the start of the
  6009. ;; heading.
  6010. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6011. ;; Prepare the variables needed in the eval of the compiled format
  6012. (if org-prefix-has-breadcrumbs
  6013. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6014. (let ((s (org-display-outline-path nil nil "->" t)))
  6015. (if (eq "" s) "" (concat s "->"))))))
  6016. (setq time (cond (s2 (concat
  6017. (org-agenda-time-of-day-to-ampm-maybe s1)
  6018. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6019. (if org-agenda-timegrid-use-ampm " ")))
  6020. (s1 (concat
  6021. (org-agenda-time-of-day-to-ampm-maybe s1)
  6022. (if org-agenda-timegrid-use-ampm
  6023. "........ "
  6024. "......")))
  6025. (t ""))
  6026. extra (or (and (not habitp) extra) "")
  6027. category (if (symbolp category) (symbol-name category) category)
  6028. level (or level ""))
  6029. (if (string-match org-bracket-link-regexp category)
  6030. (progn
  6031. (setq l (if (match-end 3)
  6032. (- (match-end 3) (match-beginning 3))
  6033. (- (match-end 1) (match-beginning 1))))
  6034. (when (< l (or org-prefix-category-length 0))
  6035. (setq category (copy-sequence category))
  6036. (org-add-props category nil
  6037. 'extra-space (make-string
  6038. (- org-prefix-category-length l 1) ?\ ))))
  6039. (if (and org-prefix-category-max-length
  6040. (>= (length category) org-prefix-category-max-length))
  6041. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6042. ;; Evaluate the compiled format
  6043. (setq rtn (concat (eval formatter) txt))
  6044. ;; And finally add the text properties
  6045. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6046. (org-add-props rtn nil
  6047. 'org-category category
  6048. 'tags (mapcar 'org-downcase-keep-props tags)
  6049. 'org-highest-priority org-highest-priority
  6050. 'org-lowest-priority org-lowest-priority
  6051. 'time-of-day time-of-day
  6052. 'duration duration
  6053. 'breadcrumbs breadcrumbs
  6054. 'txt txt
  6055. 'level level
  6056. 'time time
  6057. 'extra extra
  6058. 'format org-prefix-format-compiled
  6059. 'dotime dotime)))))
  6060. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6061. "Remove tags string from TXT, and add a modified list of tags.
  6062. The modified list may contain inherited tags, and tags matched by
  6063. `org-agenda-hide-tags-regexp' will be removed."
  6064. (when (or add-inherited hide-re)
  6065. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6066. (setq txt (substring txt 0 (match-beginning 0))))
  6067. (setq tags
  6068. (delq nil
  6069. (mapcar (lambda (tg)
  6070. (if (or (and hide-re (string-match hide-re tg))
  6071. (and (not add-inherited)
  6072. (get-text-property 0 'inherited tg)))
  6073. nil
  6074. tg))
  6075. tags)))
  6076. (when tags
  6077. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6078. i)
  6079. (setq txt (concat txt " :"
  6080. (mapconcat
  6081. (lambda (x)
  6082. (setq i (get-text-property 0 'inherited x))
  6083. (if (and have-i (not i))
  6084. (progn
  6085. (setq have-i nil)
  6086. (concat ":" x))
  6087. x))
  6088. tags ":")
  6089. (if have-i "::" ":"))))))
  6090. txt)
  6091. (defun org-downcase-keep-props (s)
  6092. (let ((props (text-properties-at 0 s)))
  6093. (setq s (downcase s))
  6094. (add-text-properties 0 (length s) props s)
  6095. s))
  6096. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6097. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6098. "Add a time-grid for agenda items which need it.
  6099. LIST is the list of agenda items formatted by `org-agenda-list'.
  6100. NDAYS is the span of the current agenda view.
  6101. TODAYP is t when the current agenda view is on today."
  6102. (catch 'exit
  6103. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6104. ((and todayp (member 'today (car org-agenda-time-grid))))
  6105. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6106. ((member 'weekly (car org-agenda-time-grid)))
  6107. (t (throw 'exit list)))
  6108. (let* ((have (delq nil (mapcar
  6109. (lambda (x) (get-text-property 1 'time-of-day x))
  6110. list)))
  6111. (string (nth 1 org-agenda-time-grid))
  6112. (gridtimes (nth 2 org-agenda-time-grid))
  6113. (req (car org-agenda-time-grid))
  6114. (remove (member 'remove-match req))
  6115. new time)
  6116. (if (and (member 'require-timed req) (not have))
  6117. ;; don't show empty grid
  6118. (throw 'exit list))
  6119. (while (setq time (pop gridtimes))
  6120. (unless (and remove (member time have))
  6121. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6122. (push (org-agenda-format-item
  6123. nil string nil "" nil
  6124. (concat (substring time 0 -2) ":" (substring time -2)))
  6125. new)
  6126. (put-text-property
  6127. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6128. (when (and todayp org-agenda-show-current-time-in-grid)
  6129. (push (org-agenda-format-item
  6130. nil org-agenda-current-time-string nil "" nil
  6131. (format-time-string "%H:%M "))
  6132. new)
  6133. (put-text-property
  6134. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6135. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6136. (append new list)
  6137. (append list new)))))
  6138. (defun org-compile-prefix-format (key)
  6139. "Compile the prefix format into a Lisp form that can be evaluated.
  6140. The resulting form and associated variable bindings is returned
  6141. and stored in the variable `org-prefix-format-compiled'."
  6142. (setq org-prefix-has-time nil
  6143. org-prefix-has-tag nil
  6144. org-prefix-category-length nil
  6145. org-prefix-has-effort nil
  6146. org-prefix-has-breadcrumbs nil)
  6147. (let ((s (cond
  6148. ((stringp org-agenda-prefix-format)
  6149. org-agenda-prefix-format)
  6150. ((assq key org-agenda-prefix-format)
  6151. (cdr (assq key org-agenda-prefix-format)))
  6152. (t " %-12:c%?-12t% s")))
  6153. (start 0)
  6154. varform vars var e c f opt)
  6155. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6156. s start)
  6157. (setq var (or (cdr (assoc (match-string 4 s)
  6158. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6159. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6160. 'eval)
  6161. c (or (match-string 3 s) "")
  6162. opt (match-beginning 1)
  6163. start (1+ (match-beginning 0)))
  6164. (if (eq var 'time) (setq org-prefix-has-time t))
  6165. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6166. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6167. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6168. (setq f (concat "%" (match-string 2 s) "s"))
  6169. (when (eq var 'category)
  6170. (setq org-prefix-category-length
  6171. (floor (abs (string-to-number (match-string 2 s)))))
  6172. (setq org-prefix-category-max-length
  6173. (let ((x (match-string 2 s)))
  6174. (save-match-data
  6175. (if (string-match "\\.[0-9]+" x)
  6176. (string-to-number (substring (match-string 0 x) 1)))))))
  6177. (if (eq var 'eval)
  6178. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6179. (if opt
  6180. (setq varform
  6181. `(if (or (equal "" ,var) (equal nil ,var))
  6182. ""
  6183. (format ,f (concat ,var ,c))))
  6184. (setq varform
  6185. `(format ,f (if (or (equal ,var "")
  6186. (equal ,var nil)) ""
  6187. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6188. (setq s (replace-match "%s" t nil s))
  6189. (push varform vars))
  6190. (setq vars (nreverse vars))
  6191. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6192. (setq org-prefix-format-compiled
  6193. (list
  6194. `((org-prefix-has-time ,org-prefix-has-time)
  6195. (org-prefix-has-tag ,org-prefix-has-tag)
  6196. (org-prefix-category-length ,org-prefix-category-length)
  6197. (org-prefix-has-effort ,org-prefix-has-effort)
  6198. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6199. `(format ,s ,@vars))))))
  6200. (defun org-set-sorting-strategy (key)
  6201. (if (symbolp (car org-agenda-sorting-strategy))
  6202. ;; the old format
  6203. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6204. (setq org-agenda-sorting-strategy-selected
  6205. (or (cdr (assq key org-agenda-sorting-strategy))
  6206. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6207. '(time-up category-keep priority-down)))))
  6208. (defun org-get-time-of-day (s &optional string mod24)
  6209. "Check string S for a time of day.
  6210. If found, return it as a military time number between 0 and 2400.
  6211. If not found, return nil.
  6212. The optional STRING argument forces conversion into a 5 character wide string
  6213. HH:MM."
  6214. (save-match-data
  6215. (when
  6216. (and
  6217. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6218. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6219. (not (eq (get-text-property 1 'face s) 'org-link)))
  6220. (let* ((h (string-to-number (match-string 1 s)))
  6221. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6222. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6223. (am-p (equal ampm "am"))
  6224. (h1 (cond ((not ampm) h)
  6225. ((= h 12) (if am-p 0 12))
  6226. (t (+ h (if am-p 0 12)))))
  6227. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6228. (mod h1 24) h1))
  6229. (t0 (+ (* 100 h2) m))
  6230. (t1 (concat (if (>= h1 24) "+" " ")
  6231. (if (and org-agenda-time-leading-zero
  6232. (< t0 1000)) "0" "")
  6233. (if (< t0 100) "0" "")
  6234. (if (< t0 10) "0" "")
  6235. (int-to-string t0))))
  6236. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6237. (defvar org-agenda-before-sorting-filter-function nil
  6238. "Function to be applied to agenda items prior to sorting.
  6239. Prior to sorting also means just before they are inserted into the agenda.
  6240. To aid sorting, you may revisit the original entries and add more text
  6241. properties which will later be used by the sorting functions.
  6242. The function should take a string argument, an agenda line.
  6243. It has access to the text properties in that line, which contain among
  6244. other things, the property `org-hd-marker' that points to the entry
  6245. where the line comes from. Note that not all lines going into the agenda
  6246. have this property, only most.
  6247. The function should return the modified string. It is probably best
  6248. to ONLY change text properties.
  6249. You can also use this function as a filter, by returning nil for lines
  6250. you don't want to have in the agenda at all. For this application, you
  6251. could bind the variable in the options section of a custom command.")
  6252. (defun org-agenda-finalize-entries (list &optional type)
  6253. "Sort, limit and concatenate the LIST of agenda items.
  6254. The optional argument TYPE tells the agenda type."
  6255. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6256. (cdr (assoc type org-agenda-max-effort)))
  6257. (t org-agenda-max-effort)))
  6258. (max-todo (cond ((listp org-agenda-max-todos)
  6259. (cdr (assoc type org-agenda-max-todos)))
  6260. (t org-agenda-max-todos)))
  6261. (max-tags (cond ((listp org-agenda-max-tags)
  6262. (cdr (assoc type org-agenda-max-tags)))
  6263. (t org-agenda-max-tags)))
  6264. (max-entries (cond ((listp org-agenda-max-entries)
  6265. (cdr (assoc type org-agenda-max-entries)))
  6266. (t org-agenda-max-entries))))
  6267. (when org-agenda-before-sorting-filter-function
  6268. (setq list
  6269. (delq nil
  6270. (mapcar
  6271. org-agenda-before-sorting-filter-function list))))
  6272. (setq list (mapcar 'org-agenda-highlight-todo list)
  6273. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6274. (when max-effort
  6275. (setq list (org-agenda-limit-entries
  6276. list 'effort-minutes max-effort
  6277. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6278. 32767 -1))))))
  6279. (when max-todo
  6280. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6281. (when max-tags
  6282. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6283. (when max-entries
  6284. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6285. (mapconcat 'identity list "\n")))
  6286. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6287. "Limit the number of agenda entries."
  6288. (let ((include (and limit (< limit 0))))
  6289. (if limit
  6290. (let ((fun (or fn (lambda (p) (if p 1))))
  6291. (lim 0))
  6292. (delq nil
  6293. (mapcar
  6294. (lambda (e)
  6295. (let ((pval (funcall
  6296. fun (get-text-property (1- (length e))
  6297. prop e))))
  6298. (if pval (setq lim (+ lim pval)))
  6299. (cond ((and pval (<= lim (abs limit))) e)
  6300. ((and include (not pval)) e))))
  6301. list)))
  6302. list)))
  6303. (defun org-agenda-limit-interactively (remove)
  6304. "In agenda, interactively limit entries to various maximums."
  6305. (interactive "P")
  6306. (if remove
  6307. (progn (setq org-agenda-max-entries nil
  6308. org-agenda-max-todos nil
  6309. org-agenda-max-tags nil
  6310. org-agenda-max-effort nil)
  6311. (org-agenda-redo))
  6312. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6313. (msg (cond ((= max ?E) "How many minutes? ")
  6314. ((= max ?e) "How many entries? ")
  6315. ((= max ?t) "How many TODO entries? ")
  6316. ((= max ?T) "How many tagged entries? ")
  6317. (t (user-error "Wrong input"))))
  6318. (num (string-to-number (read-from-minibuffer msg))))
  6319. (cond ((equal max ?e)
  6320. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6321. ((equal max ?t)
  6322. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6323. ((equal max ?T)
  6324. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6325. ((equal max ?E)
  6326. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6327. (org-agenda-fit-window-to-buffer))
  6328. (defun org-agenda-highlight-todo (x)
  6329. (let ((org-done-keywords org-done-keywords-for-agenda)
  6330. (case-fold-search nil)
  6331. re)
  6332. (if (eq x 'line)
  6333. (save-excursion
  6334. (beginning-of-line 1)
  6335. (setq re (org-get-at-bol 'org-todo-regexp))
  6336. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6337. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6338. (add-text-properties (match-beginning 0) (match-end 1)
  6339. (list 'face (org-get-todo-face 1)))
  6340. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6341. (delete-region (match-beginning 1) (1- (match-end 0)))
  6342. (goto-char (match-beginning 1))
  6343. (insert (format org-agenda-todo-keyword-format s)))))
  6344. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6345. (setq re (get-text-property 0 'org-todo-regexp x))
  6346. (when (and re
  6347. ;; Test `pl' because if there's no heading content,
  6348. ;; there's no point matching to highlight. Note
  6349. ;; that if we didn't test `pl' first, and there
  6350. ;; happened to be no keyword from `org-todo-regexp'
  6351. ;; on this heading line, then the `equal' comparison
  6352. ;; afterwards would spuriously succeed in the case
  6353. ;; where `pl' is nil -- causing an args-out-of-range
  6354. ;; error when we try to add text properties to text
  6355. ;; that isn't there.
  6356. pl
  6357. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6358. x pl) pl))
  6359. (add-text-properties
  6360. (or (match-end 1) (match-end 0)) (match-end 0)
  6361. (list 'face (org-get-todo-face (match-string 2 x)))
  6362. x)
  6363. (when (match-end 1)
  6364. (setq x (concat (substring x 0 (match-end 1))
  6365. (format org-agenda-todo-keyword-format
  6366. (match-string 2 x))
  6367. (org-add-props " " (text-properties-at 0 x))
  6368. (substring x (match-end 3)))))))
  6369. x)))
  6370. (defsubst org-cmp-values (a b property)
  6371. "Compare the numeric value of text PROPERTY for string A and B."
  6372. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6373. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6374. (cond ((> pa pb) +1)
  6375. ((< pa pb) -1))))
  6376. (defsubst org-cmp-effort (a b)
  6377. "Compare the effort values of string A and B."
  6378. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6379. ;; `effort-minutes' property is not directly accessible from
  6380. ;; the strings, but is stored as a property in `txt'.
  6381. (ea (or (get-text-property
  6382. 0 'effort-minutes (get-text-property 0 'txt a))
  6383. def))
  6384. (eb (or (get-text-property
  6385. 0 'effort-minutes (get-text-property 0 'txt b))
  6386. def)))
  6387. (cond ((> ea eb) +1)
  6388. ((< ea eb) -1))))
  6389. (defsubst org-cmp-category (a b)
  6390. "Compare the string values of categories of strings A and B."
  6391. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6392. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6393. (cond ((string-lessp ca cb) -1)
  6394. ((string-lessp cb ca) +1))))
  6395. (defsubst org-cmp-todo-state (a b)
  6396. "Compare the todo states of strings A and B."
  6397. (let* ((ma (or (get-text-property 1 'org-marker a)
  6398. (get-text-property 1 'org-hd-marker a)))
  6399. (mb (or (get-text-property 1 'org-marker b)
  6400. (get-text-property 1 'org-hd-marker b)))
  6401. (fa (and ma (marker-buffer ma)))
  6402. (fb (and mb (marker-buffer mb)))
  6403. (todo-kwds
  6404. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6405. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6406. (ta (or (get-text-property 1 'todo-state a) ""))
  6407. (tb (or (get-text-property 1 'todo-state b) ""))
  6408. (la (- (length (member ta todo-kwds))))
  6409. (lb (- (length (member tb todo-kwds))))
  6410. (donepa (member ta org-done-keywords-for-agenda))
  6411. (donepb (member tb org-done-keywords-for-agenda)))
  6412. (cond ((and donepa (not donepb)) -1)
  6413. ((and (not donepa) donepb) +1)
  6414. ((< la lb) -1)
  6415. ((< lb la) +1))))
  6416. (defsubst org-cmp-alpha (a b)
  6417. "Compare the headlines, alphabetically."
  6418. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6419. (plb (text-property-any 0 (length b) 'org-heading t b))
  6420. (ta (and pla (substring a pla)))
  6421. (tb (and plb (substring b plb)))
  6422. (case-fold-search nil))
  6423. (when pla
  6424. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6425. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6426. (setq ta (substring ta (match-end 0))))
  6427. (setq ta (downcase ta)))
  6428. (when plb
  6429. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6430. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6431. (setq tb (substring tb (match-end 0))))
  6432. (setq tb (downcase tb)))
  6433. (cond ((not ta) +1)
  6434. ((not tb) -1)
  6435. ((string-lessp ta tb) -1)
  6436. ((string-lessp tb ta) +1))))
  6437. (defsubst org-cmp-tag (a b)
  6438. "Compare the string values of the first tags of A and B."
  6439. (let ((ta (car (last (get-text-property 1 'tags a))))
  6440. (tb (car (last (get-text-property 1 'tags b)))))
  6441. (cond ((not ta) +1)
  6442. ((not tb) -1)
  6443. ((string-lessp ta tb) -1)
  6444. ((string-lessp tb ta) +1))))
  6445. (defsubst org-cmp-time (a b)
  6446. "Compare the time-of-day values of strings A and B."
  6447. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6448. (ta (or (get-text-property 1 'time-of-day a) def))
  6449. (tb (or (get-text-property 1 'time-of-day b) def)))
  6450. (cond ((< ta tb) -1)
  6451. ((< tb ta) +1))))
  6452. (defsubst org-cmp-ts (a b type)
  6453. "Compare the timestamps values of entries A and B.
  6454. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6455. \"timestamp_ia\", compare within each of these type. When TYPE
  6456. is the empty string, compare all timestamps without respect of
  6457. their type."
  6458. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6459. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6460. (get-text-property 1 'ts-date a))
  6461. def))
  6462. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6463. (get-text-property 1 'ts-date b))
  6464. def)))
  6465. (cond ((< ta tb) -1)
  6466. ((< tb ta) +1))))
  6467. (defsubst org-cmp-habit-p (a b)
  6468. "Compare the todo states of strings A and B."
  6469. (let ((ha (get-text-property 1 'org-habit-p a))
  6470. (hb (get-text-property 1 'org-habit-p b)))
  6471. (cond ((and ha (not hb)) -1)
  6472. ((and (not ha) hb) +1))))
  6473. (defun org-entries-lessp (a b)
  6474. "Predicate for sorting agenda entries."
  6475. ;; The following variables will be used when the form is evaluated.
  6476. ;; So even though the compiler complains, keep them.
  6477. (let* ((ss org-agenda-sorting-strategy-selected)
  6478. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6479. (org-cmp-ts a b "")))
  6480. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6481. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6482. (org-cmp-ts a b "scheduled")))
  6483. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6484. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6485. (org-cmp-ts a b "deadline")))
  6486. (deadline-down (if deadline-up (- deadline-up) nil))
  6487. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6488. (org-cmp-ts a b "timestamp_ia")))
  6489. (tsia-down (if tsia-up (- tsia-up) nil))
  6490. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6491. (org-cmp-ts a b "timestamp")))
  6492. (ts-down (if ts-up (- ts-up) nil))
  6493. (time-up (and (org-em 'time-up 'time-down ss)
  6494. (org-cmp-time a b)))
  6495. (time-down (if time-up (- time-up) nil))
  6496. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6497. (org-cmp-values a b 'org-stats)))
  6498. (stats-down (if stats-up (- stats-up) nil))
  6499. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6500. (org-cmp-values a b 'priority)))
  6501. (priority-down (if priority-up (- priority-up) nil))
  6502. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6503. (org-cmp-effort a b)))
  6504. (effort-down (if effort-up (- effort-up) nil))
  6505. (category-up (and (or (org-em 'category-up 'category-down ss)
  6506. (memq 'category-keep ss))
  6507. (org-cmp-category a b)))
  6508. (category-down (if category-up (- category-up) nil))
  6509. (category-keep (if category-up +1 nil))
  6510. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6511. (org-cmp-tag a b)))
  6512. (tag-down (if tag-up (- tag-up) nil))
  6513. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6514. (org-cmp-todo-state a b)))
  6515. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6516. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6517. (org-cmp-habit-p a b)))
  6518. (habit-down (if habit-up (- habit-up) nil))
  6519. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6520. (org-cmp-alpha a b)))
  6521. (alpha-down (if alpha-up (- alpha-up) nil))
  6522. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6523. user-defined-up user-defined-down)
  6524. (if (and need-user-cmp org-agenda-cmp-user-defined
  6525. (functionp org-agenda-cmp-user-defined))
  6526. (setq user-defined-up
  6527. (funcall org-agenda-cmp-user-defined a b)
  6528. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6529. (cdr (assoc
  6530. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6531. '((-1 . t) (1 . nil) (nil . nil))))))
  6532. ;;; Agenda restriction lock
  6533. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6534. "Overlay to mark the headline to which agenda commands are restricted.")
  6535. (overlay-put org-agenda-restriction-lock-overlay
  6536. 'face 'org-agenda-restriction-lock)
  6537. (overlay-put org-agenda-restriction-lock-overlay
  6538. 'help-echo "Agendas are currently limited to this subtree.")
  6539. (delete-overlay org-agenda-restriction-lock-overlay)
  6540. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6541. "Set the restriction lock to the agenda item at point from within the agenda.
  6542. When called with a `\\[universal-argument]' prefix, restrict to
  6543. the file which contains the item.
  6544. Argument ARG is the prefix argument."
  6545. (interactive "P")
  6546. (unless (derived-mode-p 'org-agenda-mode)
  6547. (user-error "Not in an Org agenda buffer"))
  6548. (let* ((marker (or (org-get-at-bol 'org-marker)
  6549. (org-agenda-error)))
  6550. (buffer (marker-buffer marker))
  6551. (pos (marker-position marker)))
  6552. (with-current-buffer buffer
  6553. (goto-char pos)
  6554. (org-agenda-set-restriction-lock arg))))
  6555. ;;;###autoload
  6556. (defun org-agenda-set-restriction-lock (&optional type)
  6557. "Set restriction lock for agenda, to current subtree or file.
  6558. Restriction will be the file if TYPE is `file', or if type is the
  6559. universal prefix \\='(4), or if the cursor is before the first headline
  6560. in the file. Otherwise, restriction will be to the current subtree."
  6561. (interactive "P")
  6562. (org-agenda-remove-restriction-lock 'noupdate)
  6563. (and (equal type '(4)) (setq type 'file))
  6564. (setq type (cond
  6565. (type type)
  6566. ((org-at-heading-p) 'subtree)
  6567. ((condition-case nil (org-back-to-heading t) (error nil))
  6568. 'subtree)
  6569. (t 'file)))
  6570. (if (eq type 'subtree)
  6571. (progn
  6572. (setq org-agenda-restrict (current-buffer))
  6573. (setq org-agenda-overriding-restriction 'subtree)
  6574. (put 'org-agenda-files 'org-restrict
  6575. (list (buffer-file-name (buffer-base-buffer))))
  6576. (org-back-to-heading t)
  6577. (move-overlay org-agenda-restriction-lock-overlay
  6578. (point)
  6579. (if org-agenda-restriction-lock-highlight-subtree
  6580. (save-excursion (org-end-of-subtree t t) (point))
  6581. (point-at-eol)))
  6582. (move-marker org-agenda-restrict-begin (point))
  6583. (move-marker org-agenda-restrict-end
  6584. (save-excursion (org-end-of-subtree t t)))
  6585. (message "Locking agenda restriction to subtree"))
  6586. (put 'org-agenda-files 'org-restrict
  6587. (list (buffer-file-name (buffer-base-buffer))))
  6588. (setq org-agenda-restrict nil)
  6589. (setq org-agenda-overriding-restriction 'file)
  6590. (move-marker org-agenda-restrict-begin nil)
  6591. (move-marker org-agenda-restrict-end nil)
  6592. (message "Locking agenda restriction to file"))
  6593. (setq current-prefix-arg nil)
  6594. (org-agenda-maybe-redo))
  6595. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6596. "Remove the agenda restriction lock."
  6597. (interactive "P")
  6598. (delete-overlay org-agenda-restriction-lock-overlay)
  6599. (delete-overlay org-speedbar-restriction-lock-overlay)
  6600. (setq org-agenda-overriding-restriction nil)
  6601. (setq org-agenda-restrict nil)
  6602. (put 'org-agenda-files 'org-restrict nil)
  6603. (move-marker org-agenda-restrict-begin nil)
  6604. (move-marker org-agenda-restrict-end nil)
  6605. (setq current-prefix-arg nil)
  6606. (message "Agenda restriction lock removed")
  6607. (or noupdate (org-agenda-maybe-redo)))
  6608. (defun org-agenda-maybe-redo ()
  6609. "If there is any window showing the agenda view, update it."
  6610. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6611. org-agenda-buffer-name)
  6612. t))
  6613. (w0 (selected-window)))
  6614. (when w
  6615. (select-window w)
  6616. (org-agenda-redo)
  6617. (select-window w0)
  6618. (if org-agenda-overriding-restriction
  6619. (message "Agenda view shifted to new %s restriction"
  6620. org-agenda-overriding-restriction)
  6621. (message "Agenda restriction lock removed")))))
  6622. ;;; Agenda commands
  6623. (defun org-agenda-check-type (error &rest types)
  6624. "Check if agenda buffer is of allowed type.
  6625. If ERROR is non-nil, throw an error, otherwise just return nil.
  6626. Allowed types are `agenda' `timeline' `todo' `tags' `search'."
  6627. (if (not org-agenda-type)
  6628. (error "No Org agenda currently displayed")
  6629. (if (memq org-agenda-type types)
  6630. t
  6631. (if error
  6632. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6633. nil))))
  6634. (defun org-agenda-Quit ()
  6635. "Exit the agenda, killing the agenda buffer.
  6636. Like `org-agenda-quit', but kill the buffer even when
  6637. `org-agenda-sticky' is non-nil."
  6638. (interactive)
  6639. (org-agenda--quit))
  6640. (defun org-agenda-quit ()
  6641. "Exit the agenda.
  6642. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6643. instead of killing it.
  6644. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6645. the pre-agenda window configuration.
  6646. When column view is active, exit column view instead of the
  6647. agenda."
  6648. (interactive)
  6649. (org-agenda--quit org-agenda-sticky))
  6650. (defun org-agenda--quit (&optional bury)
  6651. (if org-agenda-columns-active
  6652. (org-columns-quit)
  6653. (let ((wconf org-agenda-pre-window-conf)
  6654. (buf (current-buffer))
  6655. (org-agenda-last-indirect-window
  6656. (and (eq org-indirect-buffer-display 'other-window)
  6657. org-agenda-last-indirect-buffer
  6658. (get-buffer-window org-agenda-last-indirect-buffer))))
  6659. (cond
  6660. ((eq org-agenda-window-setup 'other-frame)
  6661. (delete-frame))
  6662. ((and org-agenda-restore-windows-after-quit
  6663. wconf)
  6664. ;; Maybe restore the pre-agenda window configuration. Reset
  6665. ;; `org-agenda-pre-window-conf' before running
  6666. ;; `set-window-configuration', which loses the current buffer.
  6667. (setq org-agenda-pre-window-conf nil)
  6668. (set-window-configuration wconf))
  6669. (t
  6670. (when org-agenda-last-indirect-window
  6671. (delete-window org-agenda-last-indirect-window))
  6672. (and (not (eq org-agenda-window-setup 'current-window))
  6673. (not (one-window-p))
  6674. (delete-window))))
  6675. (if bury
  6676. ;; Set the agenda buffer as the current buffer instead of
  6677. ;; passing it as an argument to `bury-buffer' so that
  6678. ;; `bury-buffer' removes it from the window.
  6679. (with-current-buffer buf
  6680. (bury-buffer))
  6681. (kill-buffer buf)
  6682. (setq org-agenda-archives-mode nil
  6683. org-agenda-buffer nil)))))
  6684. (defun org-agenda-exit ()
  6685. "Exit the agenda, killing Org buffers loaded by the agenda.
  6686. Like `org-agenda-Quit', but kill any buffers that were created by
  6687. the agenda. Org buffers visited directly by the user will not be
  6688. touched. Also, exit the agenda even if it is in column view."
  6689. (interactive)
  6690. (when org-agenda-columns-active
  6691. (org-columns-quit))
  6692. (org-release-buffers org-agenda-new-buffers)
  6693. (setq org-agenda-new-buffers nil)
  6694. (org-agenda-Quit))
  6695. (defun org-agenda-kill-all-agenda-buffers ()
  6696. "Kill all buffers in `org-agenda-mode'.
  6697. This is used when toggling sticky agendas."
  6698. (interactive)
  6699. (let (blist)
  6700. (dolist (buf (buffer-list))
  6701. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6702. (push buf blist)))
  6703. (mapc 'kill-buffer blist)))
  6704. (defun org-agenda-execute (arg)
  6705. "Execute another agenda command, keeping same window.
  6706. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6707. in the agenda."
  6708. (interactive "P")
  6709. (let ((org-agenda-window-setup 'current-window))
  6710. (org-agenda arg)))
  6711. (defun org-agenda-redo (&optional all)
  6712. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6713. (interactive "P")
  6714. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6715. (cpa (unless (eq all t) current-prefix-arg))
  6716. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6717. (org-agenda-sticky nil)
  6718. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6719. org-agenda-buffer-name))
  6720. (org-agenda-keep-modes t)
  6721. (tag-filter org-agenda-tag-filter)
  6722. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6723. (top-hl-filter org-agenda-top-headline-filter)
  6724. (cat-filter org-agenda-category-filter)
  6725. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6726. (re-filter org-agenda-regexp-filter)
  6727. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6728. (effort-filter org-agenda-effort-filter)
  6729. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6730. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6731. (cols org-agenda-columns-active)
  6732. (line (org-current-line))
  6733. (window-line (- line (org-current-line (window-start))))
  6734. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6735. (redo-cmd (get-text-property p 'org-redo-cmd))
  6736. (last-args (get-text-property p 'org-last-args))
  6737. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6738. (org-agenda-overriding-cmd-arguments
  6739. (unless (eq all t)
  6740. (cond ((listp last-args)
  6741. (cons (or cpa (car last-args)) (cdr last-args)))
  6742. ((stringp last-args)
  6743. last-args))))
  6744. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6745. (put 'org-agenda-tag-filter :preset-filter nil)
  6746. (put 'org-agenda-category-filter :preset-filter nil)
  6747. (put 'org-agenda-regexp-filter :preset-filter nil)
  6748. (put 'org-agenda-effort-filter :preset-filter nil)
  6749. (and cols (org-columns-quit))
  6750. (message "Rebuilding agenda buffer...")
  6751. (if series-redo-cmd
  6752. (eval series-redo-cmd)
  6753. (org-let lprops redo-cmd))
  6754. (setq org-agenda-undo-list nil
  6755. org-agenda-pending-undo-list nil
  6756. org-agenda-tag-filter tag-filter
  6757. org-agenda-category-filter cat-filter
  6758. org-agenda-regexp-filter re-filter
  6759. org-agenda-effort-filter effort-filter
  6760. org-agenda-top-headline-filter top-hl-filter)
  6761. (message "Rebuilding agenda buffer...done")
  6762. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6763. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6764. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6765. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6766. (let ((tag (or tag-filter tag-preset))
  6767. (cat (or cat-filter cat-preset))
  6768. (effort (or effort-filter effort-preset))
  6769. (re (or re-filter re-preset)))
  6770. (when tag (org-agenda-filter-apply tag 'tag t))
  6771. (when cat (org-agenda-filter-apply cat 'category))
  6772. (when effort (org-agenda-filter-apply effort 'effort))
  6773. (when re (org-agenda-filter-apply re 'regexp)))
  6774. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6775. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6776. (org-goto-line line)
  6777. (recenter window-line)))
  6778. (defvar org-global-tags-completion-table nil)
  6779. (defvar org-agenda-filter-form nil)
  6780. (defvar org-agenda-filtered-by-category nil)
  6781. (defun org-agenda-filter-by-category (strip)
  6782. "Filter lines in the agenda buffer that have a specific category.
  6783. The category is that of the current line.
  6784. Without prefix argument, keep only the lines of that category.
  6785. With a prefix argument, exclude the lines of that category.
  6786. "
  6787. (interactive "P")
  6788. (if (and org-agenda-filtered-by-category
  6789. org-agenda-category-filter)
  6790. (org-agenda-filter-show-all-cat)
  6791. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6792. (cond
  6793. ((and cat strip)
  6794. (org-agenda-filter-apply
  6795. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6796. (cat
  6797. (org-agenda-filter-apply
  6798. (setq org-agenda-category-filter
  6799. (list (concat "+" cat))) 'category))
  6800. (t (error "No category at point"))))))
  6801. (defun org-find-top-headline (&optional pos)
  6802. "Find the topmost parent headline and return it."
  6803. (save-excursion
  6804. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6805. (if pos (goto-char pos))
  6806. ;; Skip up to the topmost parent
  6807. (while (ignore-errors (outline-up-heading 1) t))
  6808. (ignore-errors
  6809. (nth 4 (org-heading-components))))))
  6810. (defvar org-agenda-filtered-by-top-headline nil)
  6811. (defun org-agenda-filter-by-top-headline (strip)
  6812. "Keep only those lines that are descendants from the same top headline.
  6813. The top headline is that of the current line."
  6814. (interactive "P")
  6815. (if org-agenda-filtered-by-top-headline
  6816. (progn
  6817. (setq org-agenda-filtered-by-top-headline nil
  6818. org-agenda-top-headline-filter nil)
  6819. (org-agenda-filter-show-all-top-filter))
  6820. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6821. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6822. (error "No top-level headline at point")))))
  6823. (defvar org-agenda-regexp-filter nil)
  6824. (defun org-agenda-filter-by-regexp (strip)
  6825. "Filter agenda entries by a regular expression.
  6826. Regexp filters are cumulative.
  6827. With no prefix argument, keep entries matching the regexp.
  6828. With one prefix argument, filter out entries matching the regexp.
  6829. With two prefix arguments, remove the regexp filters."
  6830. (interactive "P")
  6831. (if (not (equal strip '(16)))
  6832. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6833. (read-from-minibuffer
  6834. (if (equal strip '(4))
  6835. "Filter out entries matching regexp: "
  6836. "Narrow to entries matching regexp: ")))))
  6837. (push flt org-agenda-regexp-filter)
  6838. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6839. (org-agenda-filter-show-all-re)
  6840. (message "Regexp filter removed")))
  6841. (defvar org-agenda-effort-filter nil)
  6842. (defun org-agenda-filter-by-effort (strip)
  6843. "Filter agenda entries by effort.
  6844. With no prefix argument, keep entries matching the effort condition.
  6845. With one prefix argument, filter out entries matching the condition.
  6846. With two prefix arguments, remove the effort filters."
  6847. (interactive "P")
  6848. (cond
  6849. ((member strip '(nil 4))
  6850. (let* ((efforts (split-string
  6851. (or (cdr (assoc (concat org-effort-property "_ALL")
  6852. org-global-properties))
  6853. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6854. ;; XXX: the following handles only up to 10 different
  6855. ;; effort values.
  6856. (allowed-keys (if (null efforts) nil
  6857. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6858. (number-sequence 1 (length efforts)))))
  6859. (op nil))
  6860. (while (not (memq op '(?< ?> ?=)))
  6861. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6862. ;; Select appropriate duration. Ignore non-digit characters.
  6863. (let ((prompt
  6864. (apply #'format
  6865. (concat "Effort %c "
  6866. (mapconcat (lambda (s) (concat "[%d]" s))
  6867. efforts
  6868. " "))
  6869. op allowed-keys))
  6870. (eff -1))
  6871. (while (not (memq eff allowed-keys))
  6872. (message prompt)
  6873. (setq eff (- (read-char-exclusive) 48)))
  6874. (setq org-agenda-effort-filter
  6875. (list (concat (if strip "-" "+")
  6876. (char-to-string op)
  6877. ;; Numbering is 1 2 3 ... 9 0, but we want
  6878. ;; 0 1 2 ... 8 9.
  6879. (nth (mod (1- eff) 10) efforts)))))
  6880. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6881. (t (org-agenda-filter-show-all-effort)
  6882. (message "Effort filter removed"))))
  6883. (defun org-agenda-filter-remove-all ()
  6884. "Remove all filters from the current agenda buffer."
  6885. (interactive)
  6886. (when org-agenda-tag-filter
  6887. (org-agenda-filter-show-all-tag))
  6888. (when org-agenda-category-filter
  6889. (org-agenda-filter-show-all-cat))
  6890. (when org-agenda-regexp-filter
  6891. (org-agenda-filter-show-all-re))
  6892. (when org-agenda-top-headline-filter
  6893. (org-agenda-filter-show-all-top-filter))
  6894. (when org-agenda-effort-filter
  6895. (org-agenda-filter-show-all-effort))
  6896. (org-agenda-finalize))
  6897. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6898. "Keep only those lines in the agenda buffer that have a specific tag.
  6899. The tag is selected with its fast selection letter, as configured.
  6900. With a `\\[universal-argument]' prefix, exclude the agenda search.
  6901. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  6902. i.e. don't
  6903. filter on all its group members.
  6904. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  6905. should be used to exclude the search - the interactive user can
  6906. also press `-' or `+' to switch between filtering and excluding."
  6907. (interactive "P")
  6908. (let* ((alist org-tag-alist-for-agenda)
  6909. (tag-chars (mapconcat
  6910. (lambda (x) (if (and (not (symbolp (car x)))
  6911. (cdr x))
  6912. (char-to-string (cdr x))
  6913. ""))
  6914. org-tag-alist-for-agenda ""))
  6915. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  6916. (string-to-list tag-chars)))
  6917. (exclude (or exclude (equal arg '(4))))
  6918. (expand (not (equal arg '(16))))
  6919. (inhibit-read-only t)
  6920. (current org-agenda-tag-filter)
  6921. a n tag)
  6922. (unless char
  6923. (while (not (memq char valid-char-list))
  6924. (message
  6925. "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  6926. (if exclude "Exclude" "Filter") tag-chars
  6927. (if org-agenda-auto-exclude-function "[RET], " "")
  6928. (if expand "" ", no grouptag expand"))
  6929. (setq char (read-char-exclusive))
  6930. ;; Excluding or filtering down
  6931. (cond ((eq char ?-) (setq exclude t))
  6932. ((eq char ?+) (setq exclude nil)))))
  6933. (when (eq char ?\t)
  6934. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6935. (setq-local org-global-tags-completion-table
  6936. (org-global-tags-completion-table)))
  6937. (let ((completion-ignore-case t))
  6938. (setq tag (completing-read
  6939. "Tag: " org-global-tags-completion-table))))
  6940. (cond
  6941. ((eq char ?\r)
  6942. (org-agenda-filter-show-all-tag)
  6943. (when org-agenda-auto-exclude-function
  6944. (setq org-agenda-tag-filter nil)
  6945. (dolist (tag (org-agenda-get-represented-tags))
  6946. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6947. (if modifier
  6948. (push modifier org-agenda-tag-filter))))
  6949. (if (not (null org-agenda-tag-filter))
  6950. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  6951. ((eq char ?/)
  6952. (org-agenda-filter-show-all-tag)
  6953. (when (get 'org-agenda-tag-filter :preset-filter)
  6954. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  6955. ((eq char ?.)
  6956. (setq org-agenda-tag-filter
  6957. (mapcar (lambda(tag) (concat "+" tag))
  6958. (org-get-at-bol 'tags)))
  6959. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  6960. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  6961. ((or (eq char ?\s)
  6962. (setq a (rassoc char alist))
  6963. (and tag (setq a (cons tag nil))))
  6964. (org-agenda-filter-show-all-tag)
  6965. (setq tag (car a))
  6966. (setq org-agenda-tag-filter
  6967. (cons (concat (if exclude "-" "+") tag)
  6968. current))
  6969. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  6970. (t (error "Invalid tag selection character %c" char)))))
  6971. (defun org-agenda-get-represented-tags ()
  6972. "Get a list of all tags currently represented in the agenda."
  6973. (let (p tags)
  6974. (save-excursion
  6975. (goto-char (point-min))
  6976. (while (setq p (next-single-property-change (point) 'tags))
  6977. (goto-char p)
  6978. (mapc (lambda (x) (add-to-list 'tags x))
  6979. (get-text-property (point) 'tags))))
  6980. tags))
  6981. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  6982. "Create the form that tests a line for agenda filter. Optional
  6983. argument EXPAND can be used for the TYPE tag and will expand the
  6984. tags in the FILTER if any of the tags in FILTER are grouptags."
  6985. (let (f f1)
  6986. (cond
  6987. ;; Tag filter
  6988. ((eq type 'tag)
  6989. (setq filter
  6990. (delete-dups
  6991. (append (get 'org-agenda-tag-filter :preset-filter)
  6992. filter)))
  6993. (dolist (x filter)
  6994. (let ((op (string-to-char x)))
  6995. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  6996. (setq x (list x)))
  6997. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  6998. (push f1 f))))
  6999. ;; Category filter
  7000. ((eq type 'category)
  7001. (setq filter
  7002. (delete-dups
  7003. (append (get 'org-agenda-category-filter :preset-filter)
  7004. filter)))
  7005. (dolist (x filter)
  7006. (if (equal "-" (substring x 0 1))
  7007. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7008. (setq f1 (list 'equal (substring x 1) 'cat)))
  7009. (push f1 f)))
  7010. ;; Regexp filter
  7011. ((eq type 'regexp)
  7012. (setq filter
  7013. (delete-dups
  7014. (append (get 'org-agenda-regexp-filter :preset-filter)
  7015. filter)))
  7016. (dolist (x filter)
  7017. (if (equal "-" (substring x 0 1))
  7018. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7019. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7020. (push f1 f)))
  7021. ;; Effort filter
  7022. ((eq type 'effort)
  7023. (setq filter
  7024. (delete-dups
  7025. (append (get 'org-agenda-effort-filter :preset-filter)
  7026. filter)))
  7027. (dolist (x filter)
  7028. (push (org-agenda-filter-effort-form x) f))))
  7029. (cons 'and (nreverse f))))
  7030. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7031. "Return a form associated to tag-expression TAGS.
  7032. Build a form testing a line for agenda filter for
  7033. tag-expressions. OP is an operator of type CHAR that allows the
  7034. function to set the right switches in the returned form."
  7035. (let (form)
  7036. ;; Any of the expressions can match if OP is +, all must match if
  7037. ;; the operator is -.
  7038. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7039. (let* ((tag (substring x 1))
  7040. (f (cond
  7041. ((string= "" tag) '(not tags))
  7042. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7043. ;; TAG is a regexp.
  7044. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7045. (t (list 'member (downcase tag) 'tags)))))
  7046. (push (if (eq op ?-) (list 'not f) f) form)))))
  7047. (defun org-agenda-filter-effort-form (e)
  7048. "Return the form to compare the effort of the current line with what E says.
  7049. E looks like \"+<2:25\"."
  7050. (let (op)
  7051. (setq e (substring e 1))
  7052. (setq op (string-to-char e) e (substring e 1))
  7053. (setq op (cond ((equal op ?<) '<=)
  7054. ((equal op ?>) '>=)
  7055. ((equal op ??) op)
  7056. (t '=)))
  7057. (list 'org-agenda-compare-effort (list 'quote op)
  7058. (org-duration-string-to-minutes e))))
  7059. (defun org-agenda-compare-effort (op value)
  7060. "Compare the effort of the current line with VALUE, using OP.
  7061. If the line does not have an effort defined, return nil."
  7062. ;; `effort-minutes' property cannot be extracted directly from
  7063. ;; current line but is stored as a property in `txt'.
  7064. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7065. (funcall op
  7066. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7067. value)))
  7068. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7069. "Expand group tags in FILTER for the agenda.
  7070. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7071. (if org-group-tags
  7072. (let ((case-fold-search t) rtn)
  7073. (mapc
  7074. (lambda (f)
  7075. (let (f0 dir)
  7076. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7077. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7078. (setq dir (if no-operator "" "+") f0 f))
  7079. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7080. (org-tags-expand f0 t t))
  7081. rtn))))
  7082. filter)
  7083. (reverse rtn))
  7084. filter))
  7085. (defun org-agenda-filter-apply (filter type &optional expand)
  7086. "Set FILTER as the new agenda filter and apply it. Optional
  7087. argument EXPAND can be used for the TYPE tag and will expand the
  7088. tags in the FILTER if any of the tags in FILTER are grouptags."
  7089. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7090. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7091. (let (tags cat txt)
  7092. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7093. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7094. ;; category is used as the filter:
  7095. (setq org-agenda-filtered-by-category
  7096. (and (eq type 'category)
  7097. (not (equal (substring (car filter) 0 1) "-"))))
  7098. (org-agenda-set-mode-name)
  7099. (save-excursion
  7100. (goto-char (point-min))
  7101. (while (not (eobp))
  7102. (if (org-get-at-bol 'org-marker)
  7103. (progn
  7104. (setq tags (org-get-at-bol 'tags)
  7105. cat (org-get-at-eol 'org-category 1)
  7106. txt (org-get-at-bol 'txt))
  7107. (if (not (eval org-agenda-filter-form))
  7108. (org-agenda-filter-hide-line type))
  7109. (beginning-of-line 2))
  7110. (beginning-of-line 2))))
  7111. (if (get-char-property (point) 'invisible)
  7112. (ignore-errors (org-agenda-previous-line)))))
  7113. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7114. "Filter by top headline HL."
  7115. (org-agenda-set-mode-name)
  7116. (save-excursion
  7117. (goto-char (point-min))
  7118. (while (not (eobp))
  7119. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7120. (tophl (and pos (org-find-top-headline pos))))
  7121. (if (and tophl (funcall (if negative 'identity 'not)
  7122. (string= hl tophl)))
  7123. (org-agenda-filter-hide-line 'top-headline)))
  7124. (beginning-of-line 2)))
  7125. (if (get-char-property (point) 'invisible)
  7126. (org-agenda-previous-line))
  7127. (setq org-agenda-top-headline-filter hl
  7128. org-agenda-filtered-by-top-headline t))
  7129. (defun org-agenda-filter-hide-line (type)
  7130. "Hide lines with TYPE in the agenda buffer."
  7131. (let* ((b (max (point-min) (1- (point-at-bol))))
  7132. (e (point-at-eol)))
  7133. (let ((inhibit-read-only t))
  7134. (add-text-properties
  7135. b e `(invisible org-filtered org-filter-type ,type)))))
  7136. (defun org-agenda-remove-filter (type)
  7137. (interactive)
  7138. "Remove filter of type TYPE from the agenda buffer."
  7139. (save-excursion
  7140. (goto-char (point-min))
  7141. (let ((inhibit-read-only t) pos)
  7142. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7143. (goto-char pos)
  7144. (remove-text-properties
  7145. (point) (next-single-property-change (point) 'org-filter-type)
  7146. `(invisible org-filtered org-filter-type ,type))))
  7147. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7148. (setq org-agenda-filter-form nil)
  7149. (org-agenda-set-mode-name)
  7150. (org-agenda-finalize)))
  7151. (defun org-agenda-filter-show-all-tag nil
  7152. (org-agenda-remove-filter 'tag))
  7153. (defun org-agenda-filter-show-all-re nil
  7154. (org-agenda-remove-filter 'regexp))
  7155. (defun org-agenda-filter-show-all-effort nil
  7156. (org-agenda-remove-filter 'effort))
  7157. (defun org-agenda-filter-show-all-cat nil
  7158. (org-agenda-remove-filter 'category))
  7159. (defun org-agenda-filter-show-all-top-filter nil
  7160. (org-agenda-remove-filter 'top-headline))
  7161. (defun org-agenda-manipulate-query-add ()
  7162. "Manipulate the query by adding a search term with positive selection.
  7163. Positive selection means the term must be matched for selection of an entry."
  7164. (interactive)
  7165. (org-agenda-manipulate-query ?\[))
  7166. (defun org-agenda-manipulate-query-subtract ()
  7167. "Manipulate the query by adding a search term with negative selection.
  7168. Negative selection means term must not be matched for selection of an entry."
  7169. (interactive)
  7170. (org-agenda-manipulate-query ?\]))
  7171. (defun org-agenda-manipulate-query-add-re ()
  7172. "Manipulate the query by adding a search regexp with positive selection.
  7173. Positive selection means the regexp must match for selection of an entry."
  7174. (interactive)
  7175. (org-agenda-manipulate-query ?\{))
  7176. (defun org-agenda-manipulate-query-subtract-re ()
  7177. "Manipulate the query by adding a search regexp with negative selection.
  7178. Negative selection means regexp must not match for selection of an entry."
  7179. (interactive)
  7180. (org-agenda-manipulate-query ?\}))
  7181. (defun org-agenda-manipulate-query (char)
  7182. (cond
  7183. ((memq org-agenda-type '(timeline agenda))
  7184. (let ((org-agenda-include-inactive-timestamps t))
  7185. (org-agenda-redo))
  7186. (message "Display now includes inactive timestamps as well"))
  7187. ((eq org-agenda-type 'search)
  7188. (org-add-to-string
  7189. 'org-agenda-query-string
  7190. (if org-agenda-last-search-view-search-was-boolean
  7191. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7192. (?\{ . " +{}") (?\} . " -{}"))))
  7193. " "))
  7194. (setq org-agenda-redo-command
  7195. (list 'org-search-view
  7196. (car (get-text-property (min (1- (point-max)) (point))
  7197. 'org-last-args))
  7198. org-agenda-query-string
  7199. (+ (length org-agenda-query-string)
  7200. (if (member char '(?\{ ?\})) 0 1))))
  7201. (set-register org-agenda-query-register org-agenda-query-string)
  7202. (let ((org-agenda-overriding-arguments
  7203. (cdr org-agenda-redo-command)))
  7204. (org-agenda-redo)))
  7205. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7206. org-agenda-type))))
  7207. (defun org-add-to-string (var string)
  7208. (set var (concat (symbol-value var) string)))
  7209. (defun org-agenda-goto-date (span)
  7210. "Jump to DATE in agenda."
  7211. (interactive "P")
  7212. (let* ((org-read-date-prefer-future
  7213. (eval org-agenda-jump-prefer-future))
  7214. (date (org-read-date))
  7215. (day (time-to-days (org-time-string-to-time date)))
  7216. (org-agenda-sticky-orig org-agenda-sticky)
  7217. (org-agenda-buffer-tmp-name (buffer-name))
  7218. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7219. (0-arg (or current-prefix-arg (car args)))
  7220. (2-arg (nth 2 args))
  7221. (with-hour-p (nth 4 org-agenda-redo-command))
  7222. (newcmd (list 'org-agenda-list 0-arg date
  7223. (org-agenda-span-to-ndays
  7224. 2-arg (org-time-string-to-absolute date))
  7225. with-hour-p))
  7226. (newargs (cdr newcmd))
  7227. (inhibit-read-only t)
  7228. org-agenda-sticky)
  7229. (if (not (org-agenda-check-type t 'agenda))
  7230. (error "Not available in non-agenda views")
  7231. (add-text-properties (point-min) (point-max)
  7232. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7233. (org-agenda-redo)
  7234. (goto-char (point-min))
  7235. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7236. (save-excursion (move-beginning-of-line 2) (eobp))))
  7237. (move-beginning-of-line 2))
  7238. (setq org-agenda-sticky org-agenda-sticky-orig
  7239. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7240. (defun org-agenda-goto-today ()
  7241. "Go to today."
  7242. (interactive)
  7243. (org-agenda-check-type t 'timeline 'agenda)
  7244. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7245. (curspan (nth 2 args))
  7246. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7247. (cond
  7248. (tdpos (goto-char tdpos))
  7249. ((eq org-agenda-type 'agenda)
  7250. (let* ((sd (org-agenda-compute-starting-span
  7251. (org-today) (or curspan org-agenda-span)))
  7252. (org-agenda-overriding-arguments args))
  7253. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7254. (org-agenda-redo)
  7255. (org-agenda-find-same-or-today-or-agenda)))
  7256. (t (error "Cannot find today")))))
  7257. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7258. (goto-char
  7259. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7260. (text-property-any (point-min) (point-max) 'org-today t)
  7261. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7262. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7263. (org-agenda-backward-block))
  7264. (point-min))))
  7265. (defun org-agenda-backward-block ()
  7266. "Move backward by one agenda block."
  7267. (interactive)
  7268. (org-agenda-forward-block 'backward))
  7269. (defun org-agenda-forward-block (&optional backward)
  7270. "Move forward by one agenda block.
  7271. When optional argument BACKWARD is set, go backward"
  7272. (interactive)
  7273. (cond ((not (derived-mode-p 'org-agenda-mode))
  7274. (user-error
  7275. "Cannot execute this command outside of org-agenda-mode buffers"))
  7276. ((looking-at (if backward "\\`" "\\'"))
  7277. (message "Already at the %s block" (if backward "first" "last")))
  7278. (t (let ((pos (prog1 (point)
  7279. (ignore-errors (if backward (backward-char 1)
  7280. (move-end-of-line 1)))))
  7281. (f (if backward
  7282. 'previous-single-property-change
  7283. 'next-single-property-change))
  7284. moved dest)
  7285. (while (and (setq dest (funcall
  7286. f (point) 'org-agenda-structural-header))
  7287. (not (get-text-property
  7288. (point) 'org-agenda-structural-header)))
  7289. (setq moved t)
  7290. (goto-char dest))
  7291. (if moved (move-beginning-of-line 1)
  7292. (goto-char (if backward (point-min) (point-max)))
  7293. (move-beginning-of-line 1)
  7294. (message "No %s block" (if backward "previous" "further")))))))
  7295. (defun org-agenda-later (arg)
  7296. "Go forward in time by the current span.
  7297. With prefix ARG, go forward that many times the current span."
  7298. (interactive "p")
  7299. (org-agenda-check-type t 'agenda)
  7300. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7301. (span (or (nth 2 args) org-agenda-current-span))
  7302. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7303. (greg (calendar-gregorian-from-absolute sd))
  7304. (cnt (org-get-at-bol 'org-day-cnt))
  7305. greg2)
  7306. (cond
  7307. ((numberp span)
  7308. (setq sd (+ (* span arg) sd)))
  7309. ((eq span 'day)
  7310. (setq sd (+ arg sd)))
  7311. ((eq span 'week)
  7312. (setq sd (+ (* 7 arg) sd)))
  7313. ((eq span 'fortnight)
  7314. (setq sd (+ (* 14 arg) sd)))
  7315. ((eq span 'month)
  7316. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7317. sd (calendar-absolute-from-gregorian greg2))
  7318. (setcar greg2 (1+ (car greg2))))
  7319. ((eq span 'year)
  7320. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7321. sd (calendar-absolute-from-gregorian greg2))
  7322. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7323. (t
  7324. (setq sd (+ (* span arg) sd))))
  7325. (let ((org-agenda-overriding-cmd
  7326. ;; `cmd' may have been set by `org-agenda-run-series' which
  7327. ;; uses `org-agenda-overriding-cmd' to decide whether
  7328. ;; overriding is allowed for `cmd'
  7329. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7330. (org-agenda-overriding-arguments
  7331. (list (car args) sd span)))
  7332. (org-agenda-redo)
  7333. (org-agenda-find-same-or-today-or-agenda cnt))))
  7334. (defun org-agenda-earlier (arg)
  7335. "Go backward in time by the current span.
  7336. With prefix ARG, go backward that many times the current span."
  7337. (interactive "p")
  7338. (org-agenda-later (- arg)))
  7339. (defun org-agenda-view-mode-dispatch ()
  7340. "Call one of the view mode commands."
  7341. (interactive)
  7342. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7343. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7344. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7345. (pcase (read-char-exclusive)
  7346. (?\ (call-interactively 'org-agenda-reset-view))
  7347. (?d (call-interactively 'org-agenda-day-view))
  7348. (?w (call-interactively 'org-agenda-week-view))
  7349. (?t (call-interactively 'org-agenda-fortnight-view))
  7350. (?m (call-interactively 'org-agenda-month-view))
  7351. (?y (call-interactively 'org-agenda-year-view))
  7352. (?l (call-interactively 'org-agenda-log-mode))
  7353. (?L (org-agenda-log-mode '(4)))
  7354. (?c (org-agenda-log-mode 'clockcheck))
  7355. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7356. (?a (call-interactively 'org-agenda-archives-mode))
  7357. (?A (org-agenda-archives-mode 'files))
  7358. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7359. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7360. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7361. (?D (call-interactively 'org-agenda-toggle-diary))
  7362. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7363. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7364. (org-agenda-check-type t 'timeline 'agenda)
  7365. (org-agenda-redo))
  7366. (message "Display now includes inactive timestamps as well"))
  7367. (?q (message "Abort"))
  7368. (key (user-error "Invalid key: %s" key))))
  7369. (defun org-agenda-reset-view ()
  7370. "Switch to default view for agenda."
  7371. (interactive)
  7372. (org-agenda-change-time-span org-agenda-span))
  7373. (defun org-agenda-day-view (&optional day-of-month)
  7374. "Switch to daily view for agenda.
  7375. With argument DAY-OF-MONTH, switch to that day of the month."
  7376. (interactive "P")
  7377. (org-agenda-change-time-span 'day day-of-month))
  7378. (defun org-agenda-week-view (&optional iso-week)
  7379. "Switch to weekly view for agenda.
  7380. With argument ISO-WEEK, switch to the corresponding ISO week.
  7381. If ISO-WEEK has more then 2 digits, only the last two encode
  7382. the week. Any digits before this encode a year. So 200712
  7383. means week 12 of year 2007. Years ranging from 70 years ago
  7384. to 30 years in the future can also be written as 2-digit years."
  7385. (interactive "P")
  7386. (org-agenda-change-time-span 'week iso-week))
  7387. (defun org-agenda-fortnight-view (&optional iso-week)
  7388. "Switch to fortnightly view for agenda.
  7389. With argument ISO-WEEK, switch to the corresponding ISO week.
  7390. If ISO-WEEK has more then 2 digits, only the last two encode
  7391. the week. Any digits before this encode a year. So 200712
  7392. means week 12 of year 2007. Years ranging from 70 years ago
  7393. to 30 years in the future can also be written as 2-digit years."
  7394. (interactive "P")
  7395. (org-agenda-change-time-span 'fortnight iso-week))
  7396. (defun org-agenda-month-view (&optional month)
  7397. "Switch to monthly view for agenda.
  7398. With argument MONTH, switch to that month. If MONTH has more
  7399. then 2 digits, only the last two encode the month. Any digits
  7400. before this encode a year. So 200712 means December year 2007.
  7401. Years ranging from 70 years ago to 30 years in the future can
  7402. also be written as 2-digit years."
  7403. (interactive "P")
  7404. (org-agenda-change-time-span 'month month))
  7405. (defun org-agenda-year-view (&optional year)
  7406. "Switch to yearly view for agenda.
  7407. With argument YEAR, switch to that year. Years ranging from 70
  7408. years ago to 30 years in the future can also be written as
  7409. 2-digit years."
  7410. (interactive "P")
  7411. (when year
  7412. (setq year (org-small-year-to-year year)))
  7413. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7414. (org-agenda-change-time-span 'year year)
  7415. (error "Abort")))
  7416. (defun org-agenda-change-time-span (span &optional n)
  7417. "Change the agenda view to SPAN.
  7418. SPAN may be `day', `week', `fortnight', `month', `year'."
  7419. (org-agenda-check-type t 'agenda)
  7420. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7421. (curspan (nth 2 args)))
  7422. (if (and (not n) (equal curspan span))
  7423. (error "Viewing span is already \"%s\"" span))
  7424. (let* ((sd (or (org-get-at-bol 'day)
  7425. (nth 1 args)
  7426. org-starting-day))
  7427. (sd (org-agenda-compute-starting-span sd span n))
  7428. (org-agenda-overriding-cmd
  7429. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7430. (org-agenda-overriding-arguments
  7431. (list (car args) sd span)))
  7432. (org-agenda-redo)
  7433. (org-agenda-find-same-or-today-or-agenda))
  7434. (org-agenda-set-mode-name)
  7435. (message "Switched to %s view" span)))
  7436. (defun org-agenda-compute-starting-span (sd span &optional n)
  7437. "Compute starting date for agenda.
  7438. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7439. is a cons cell with the starting date and the number of days,
  7440. so that the date SD will be in that range."
  7441. (let* ((greg (calendar-gregorian-from-absolute sd))
  7442. (dg (nth 1 greg))
  7443. (mg (car greg))
  7444. (yg (nth 2 greg)))
  7445. (cond
  7446. ((eq span 'day)
  7447. (when n
  7448. (setq sd (+ (calendar-absolute-from-gregorian
  7449. (list mg 1 yg))
  7450. n -1))))
  7451. ((or (eq span 'week) (eq span 'fortnight))
  7452. (let* ((nt (calendar-day-of-week
  7453. (calendar-gregorian-from-absolute sd)))
  7454. (d (if org-agenda-start-on-weekday
  7455. (- nt org-agenda-start-on-weekday)
  7456. 0))
  7457. y1)
  7458. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7459. (when n
  7460. (require 'cal-iso)
  7461. (when (> n 99)
  7462. (setq y1 (org-small-year-to-year (/ n 100))
  7463. n (mod n 100)))
  7464. (setq sd
  7465. (calendar-iso-to-absolute
  7466. (list n 1
  7467. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7468. ((eq span 'month)
  7469. (let (y1)
  7470. (when (and n (> n 99))
  7471. (setq y1 (org-small-year-to-year (/ n 100))
  7472. n (mod n 100)))
  7473. (setq sd (calendar-absolute-from-gregorian
  7474. (list (or n mg) 1 (or y1 yg))))))
  7475. ((eq span 'year)
  7476. (setq sd (calendar-absolute-from-gregorian
  7477. (list 1 1 (or n yg))))))
  7478. sd))
  7479. (defun org-agenda-next-date-line (&optional arg)
  7480. "Jump to the next line indicating a date in agenda buffer."
  7481. (interactive "p")
  7482. (org-agenda-check-type t 'agenda 'timeline)
  7483. (beginning-of-line 1)
  7484. ;; This does not work if user makes date format that starts with a blank
  7485. (if (looking-at "^\\S-") (forward-char 1))
  7486. (if (not (re-search-forward "^\\S-" nil t arg))
  7487. (progn
  7488. (backward-char 1)
  7489. (error "No next date after this line in this buffer")))
  7490. (goto-char (match-beginning 0)))
  7491. (defun org-agenda-previous-date-line (&optional arg)
  7492. "Jump to the previous line indicating a date in agenda buffer."
  7493. (interactive "p")
  7494. (org-agenda-check-type t 'agenda 'timeline)
  7495. (beginning-of-line 1)
  7496. (if (not (re-search-backward "^\\S-" nil t arg))
  7497. (error "No previous date before this line in this buffer")))
  7498. ;; Initialize the highlight
  7499. (defvar org-hl (make-overlay 1 1))
  7500. (overlay-put org-hl 'face 'highlight)
  7501. (defun org-highlight (begin end &optional buffer)
  7502. "Highlight a region with overlay."
  7503. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7504. (defun org-unhighlight ()
  7505. "Detach overlay INDEX."
  7506. (delete-overlay org-hl))
  7507. (defun org-unhighlight-once ()
  7508. "Remove the highlight from its position, and this function from the hook."
  7509. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7510. (org-unhighlight))
  7511. (defvar org-agenda-pre-follow-window-conf nil)
  7512. (defun org-agenda-follow-mode ()
  7513. "Toggle follow mode in an agenda buffer."
  7514. (interactive)
  7515. (unless org-agenda-follow-mode
  7516. (setq org-agenda-pre-follow-window-conf
  7517. (current-window-configuration)))
  7518. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7519. (unless org-agenda-follow-mode
  7520. (set-window-configuration org-agenda-pre-follow-window-conf))
  7521. (org-agenda-set-mode-name)
  7522. (org-agenda-do-context-action)
  7523. (message "Follow mode is %s"
  7524. (if org-agenda-follow-mode "on" "off")))
  7525. (defun org-agenda-entry-text-mode (&optional arg)
  7526. "Toggle entry text mode in an agenda buffer."
  7527. (interactive "P")
  7528. (if (or org-agenda-tag-filter
  7529. org-agenda-category-filter
  7530. org-agenda-regexp-filter
  7531. org-agenda-top-headline-filter)
  7532. (user-error "Can't show entry text in filtered views")
  7533. (setq org-agenda-entry-text-mode (or (integerp arg)
  7534. (not org-agenda-entry-text-mode)))
  7535. (org-agenda-entry-text-hide)
  7536. (and org-agenda-entry-text-mode
  7537. (let ((org-agenda-entry-text-maxlines
  7538. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7539. (org-agenda-entry-text-show)))
  7540. (org-agenda-set-mode-name)
  7541. (message "Entry text mode is %s%s"
  7542. (if org-agenda-entry-text-mode "on" "off")
  7543. (if (not org-agenda-entry-text-mode) ""
  7544. (format " (maximum number of lines is %d)"
  7545. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7546. (defun org-agenda-clockreport-mode ()
  7547. "Toggle clocktable mode in an agenda buffer."
  7548. (interactive)
  7549. (org-agenda-check-type t 'agenda)
  7550. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7551. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7552. (org-agenda-set-mode-name)
  7553. (org-agenda-redo)
  7554. (message "Clocktable mode is %s"
  7555. (if org-agenda-clockreport-mode "on" "off")))
  7556. (defun org-agenda-log-mode (&optional special)
  7557. "Toggle log mode in an agenda buffer.
  7558. With argument SPECIAL, show all possible log items, not only the ones
  7559. configured in `org-agenda-log-mode-items'.
  7560. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7561. log items, nothing else."
  7562. (interactive "P")
  7563. (org-agenda-check-type t 'agenda 'timeline)
  7564. (setq org-agenda-show-log
  7565. (cond
  7566. ((equal special '(16)) 'only)
  7567. ((eq special 'clockcheck)
  7568. (if (eq org-agenda-show-log 'clockcheck)
  7569. nil 'clockcheck))
  7570. (special '(closed clock state))
  7571. (t (not org-agenda-show-log))))
  7572. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7573. (org-agenda-set-mode-name)
  7574. (org-agenda-redo)
  7575. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7576. (defun org-agenda-archives-mode (&optional with-files)
  7577. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7578. When called with a prefix argument, include all archive files as well."
  7579. (interactive "P")
  7580. (setq org-agenda-archives-mode
  7581. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7582. (org-agenda-set-mode-name)
  7583. (org-agenda-redo)
  7584. (message
  7585. "%s"
  7586. (cond
  7587. ((eq org-agenda-archives-mode nil)
  7588. "No archives are included")
  7589. ((eq org-agenda-archives-mode 'trees)
  7590. (format "Trees with :%s: tag are included" org-archive-tag))
  7591. ((eq org-agenda-archives-mode t)
  7592. (format "Trees with :%s: tag and all active archive files are included"
  7593. org-archive-tag)))))
  7594. (defun org-agenda-toggle-diary ()
  7595. "Toggle diary inclusion in an agenda buffer."
  7596. (interactive)
  7597. (org-agenda-check-type t 'agenda)
  7598. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7599. (org-agenda-redo)
  7600. (org-agenda-set-mode-name)
  7601. (message "Diary inclusion turned %s"
  7602. (if org-agenda-include-diary "on" "off")))
  7603. (defun org-agenda-toggle-deadlines ()
  7604. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7605. (interactive)
  7606. (org-agenda-check-type t 'agenda)
  7607. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7608. (org-agenda-redo)
  7609. (org-agenda-set-mode-name)
  7610. (message "Deadlines inclusion turned %s"
  7611. (if org-agenda-include-deadlines "on" "off")))
  7612. (defun org-agenda-toggle-time-grid ()
  7613. "Toggle time grid in an agenda buffer."
  7614. (interactive)
  7615. (org-agenda-check-type t 'agenda)
  7616. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7617. (org-agenda-redo)
  7618. (org-agenda-set-mode-name)
  7619. (message "Time-grid turned %s"
  7620. (if org-agenda-use-time-grid "on" "off")))
  7621. (defun org-agenda-set-mode-name ()
  7622. "Set the mode name to indicate all the small mode settings."
  7623. (setq mode-name
  7624. (list "Org-Agenda"
  7625. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7626. " "
  7627. '(:eval (org-agenda-span-name org-agenda-current-span))
  7628. (if org-agenda-follow-mode " Follow" "")
  7629. (if org-agenda-entry-text-mode " ETxt" "")
  7630. (if org-agenda-include-diary " Diary" "")
  7631. (if org-agenda-include-deadlines " Ddl" "")
  7632. (if org-agenda-use-time-grid " Grid" "")
  7633. (if (and (boundp 'org-habit-show-habits)
  7634. org-habit-show-habits) " Habit" "")
  7635. (cond
  7636. ((consp org-agenda-show-log) " LogAll")
  7637. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7638. (org-agenda-show-log " Log")
  7639. (t ""))
  7640. (if (or org-agenda-category-filter
  7641. (get 'org-agenda-category-filter :preset-filter))
  7642. '(:eval (propertize
  7643. (concat " <"
  7644. (mapconcat
  7645. 'identity
  7646. (append
  7647. (get 'org-agenda-category-filter :preset-filter)
  7648. org-agenda-category-filter)
  7649. "")
  7650. ">")
  7651. 'face 'org-agenda-filter-category
  7652. 'help-echo "Category used in filtering")) "")
  7653. (if (or org-agenda-tag-filter
  7654. (get 'org-agenda-tag-filter :preset-filter))
  7655. '(:eval (propertize
  7656. (concat " {"
  7657. (mapconcat
  7658. 'identity
  7659. (append
  7660. (get 'org-agenda-tag-filter :preset-filter)
  7661. org-agenda-tag-filter)
  7662. "")
  7663. "}")
  7664. 'face 'org-agenda-filter-tags
  7665. 'help-echo "Tags used in filtering")) "")
  7666. (if (or org-agenda-effort-filter
  7667. (get 'org-agenda-effort-filter :preset-filter))
  7668. '(:eval (propertize
  7669. (concat " {"
  7670. (mapconcat
  7671. 'identity
  7672. (append
  7673. (get 'org-agenda-effort-filter :preset-filter)
  7674. org-agenda-effort-filter)
  7675. "")
  7676. "}")
  7677. 'face 'org-agenda-filter-effort
  7678. 'help-echo "Effort conditions used in filtering")) "")
  7679. (if (or org-agenda-regexp-filter
  7680. (get 'org-agenda-regexp-filter :preset-filter))
  7681. '(:eval (propertize
  7682. (concat " ["
  7683. (mapconcat
  7684. 'identity
  7685. (append
  7686. (get 'org-agenda-regexp-filter :preset-filter)
  7687. org-agenda-regexp-filter)
  7688. "")
  7689. "]")
  7690. 'face 'org-agenda-filter-regexp
  7691. 'help-echo "Regexp used in filtering")) "")
  7692. (if org-agenda-archives-mode
  7693. (if (eq org-agenda-archives-mode t)
  7694. " Archives"
  7695. (format " :%s:" org-archive-tag))
  7696. "")
  7697. (if org-agenda-clockreport-mode " Clock" "")))
  7698. (force-mode-line-update))
  7699. (defun org-agenda-update-agenda-type ()
  7700. "Update the agenda type after each command."
  7701. (setq org-agenda-type
  7702. (or (get-text-property (point) 'org-agenda-type)
  7703. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7704. (defun org-agenda-next-line ()
  7705. "Move cursor to the next line, and show if follow mode is active."
  7706. (interactive)
  7707. (call-interactively 'next-line)
  7708. (org-agenda-do-context-action))
  7709. (defun org-agenda-previous-line ()
  7710. "Move cursor to the previous line, and show if follow-mode is active."
  7711. (interactive)
  7712. (call-interactively 'previous-line)
  7713. (org-agenda-do-context-action))
  7714. (defun org-agenda-next-item (n)
  7715. "Move cursor to next agenda item."
  7716. (interactive "p")
  7717. (let ((col (current-column)))
  7718. (dotimes (c n)
  7719. (when (next-single-property-change (point-at-eol) 'org-marker)
  7720. (move-end-of-line 1)
  7721. (goto-char (next-single-property-change (point) 'org-marker))))
  7722. (org-move-to-column col))
  7723. (org-agenda-do-context-action))
  7724. (defun org-agenda-previous-item (n)
  7725. "Move cursor to next agenda item."
  7726. (interactive "p")
  7727. (dotimes (c n)
  7728. (let ((col (current-column))
  7729. (goto (save-excursion
  7730. (move-end-of-line 0)
  7731. (previous-single-property-change (point) 'org-marker))))
  7732. (if goto (goto-char goto))
  7733. (org-move-to-column col)))
  7734. (org-agenda-do-context-action))
  7735. (defun org-agenda-do-context-action ()
  7736. "Show outline path and, maybe, follow mode window."
  7737. (let ((m (org-get-at-bol 'org-marker)))
  7738. (when (and (markerp m) (marker-buffer m))
  7739. (and org-agenda-follow-mode
  7740. (if org-agenda-follow-indirect
  7741. (org-agenda-tree-to-indirect-buffer nil)
  7742. (org-agenda-show)))
  7743. (and org-agenda-show-outline-path
  7744. (org-with-point-at m (org-display-outline-path t))))))
  7745. (defun org-agenda-show-tags ()
  7746. "Show the tags applicable to the current item."
  7747. (interactive)
  7748. (let* ((tags (org-get-at-bol 'tags)))
  7749. (if tags
  7750. (message "Tags are :%s:"
  7751. (org-no-properties (mapconcat 'identity tags ":")))
  7752. (message "No tags associated with this line"))))
  7753. (defun org-agenda-goto (&optional highlight)
  7754. "Go to the entry at point in the corresponding Org file."
  7755. (interactive)
  7756. (let* ((marker (or (org-get-at-bol 'org-marker)
  7757. (org-agenda-error)))
  7758. (buffer (marker-buffer marker))
  7759. (pos (marker-position marker)))
  7760. (switch-to-buffer-other-window buffer)
  7761. (widen)
  7762. (push-mark)
  7763. (goto-char pos)
  7764. (when (derived-mode-p 'org-mode)
  7765. (org-show-context 'agenda)
  7766. (recenter (/ (window-height) 2))
  7767. (org-back-to-heading t)
  7768. (let ((case-fold-search nil))
  7769. (when (re-search-forward org-complex-heading-regexp nil t)
  7770. (goto-char (match-beginning 4)))))
  7771. (run-hooks 'org-agenda-after-show-hook)
  7772. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7773. (defvar org-agenda-after-show-hook nil
  7774. "Normal hook run after an item has been shown from the agenda.
  7775. Point is in the buffer where the item originated.")
  7776. (defun org-agenda-kill ()
  7777. "Kill the entry or subtree belonging to the current agenda entry."
  7778. (interactive)
  7779. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7780. (let* ((bufname-orig (buffer-name))
  7781. (marker (or (org-get-at-bol 'org-marker)
  7782. (org-agenda-error)))
  7783. (buffer (marker-buffer marker))
  7784. (pos (marker-position marker))
  7785. (type (org-get-at-bol 'type))
  7786. dbeg dend (n 0) conf)
  7787. (org-with-remote-undo buffer
  7788. (with-current-buffer buffer
  7789. (save-excursion
  7790. (goto-char pos)
  7791. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7792. (setq dbeg (progn (org-back-to-heading t) (point))
  7793. dend (org-end-of-subtree t t))
  7794. (setq dbeg (point-at-bol)
  7795. dend (min (point-max) (1+ (point-at-eol)))))
  7796. (goto-char dbeg)
  7797. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7798. (setq conf (or (eq t org-agenda-confirm-kill)
  7799. (and (numberp org-agenda-confirm-kill)
  7800. (> n org-agenda-confirm-kill))))
  7801. (and conf
  7802. (not (y-or-n-p
  7803. (format "Delete entry with %d lines in buffer \"%s\"? "
  7804. n (buffer-name buffer))))
  7805. (error "Abort"))
  7806. (let ((org-agenda-buffer-name bufname-orig))
  7807. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7808. (with-current-buffer buffer (delete-region dbeg dend))
  7809. (message "Agenda item and source killed"))))
  7810. (defvar org-archive-default-command) ; defined in org-archive.el
  7811. (defun org-agenda-archive-default ()
  7812. "Archive the entry or subtree belonging to the current agenda entry."
  7813. (interactive)
  7814. (require 'org-archive)
  7815. (org-agenda-archive-with org-archive-default-command))
  7816. (defun org-agenda-archive-default-with-confirmation ()
  7817. "Archive the entry or subtree belonging to the current agenda entry."
  7818. (interactive)
  7819. (require 'org-archive)
  7820. (org-agenda-archive-with org-archive-default-command 'confirm))
  7821. (defun org-agenda-archive ()
  7822. "Archive the entry or subtree belonging to the current agenda entry."
  7823. (interactive)
  7824. (org-agenda-archive-with 'org-archive-subtree))
  7825. (defun org-agenda-archive-to-archive-sibling ()
  7826. "Move the entry to the archive sibling."
  7827. (interactive)
  7828. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7829. (defun org-agenda-archive-with (cmd &optional confirm)
  7830. "Move the entry to the archive sibling."
  7831. (interactive)
  7832. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7833. (let* ((bufname-orig (buffer-name))
  7834. (marker (or (org-get-at-bol 'org-marker)
  7835. (org-agenda-error)))
  7836. (buffer (marker-buffer marker))
  7837. (pos (marker-position marker)))
  7838. (org-with-remote-undo buffer
  7839. (with-current-buffer buffer
  7840. (if (derived-mode-p 'org-mode)
  7841. (if (and confirm
  7842. (not (y-or-n-p "Archive this subtree or entry? ")))
  7843. (error "Abort")
  7844. (save-window-excursion
  7845. (goto-char pos)
  7846. (let ((org-agenda-buffer-name bufname-orig))
  7847. (org-remove-subtree-entries-from-agenda))
  7848. (org-back-to-heading t)
  7849. (funcall cmd)))
  7850. (error "Archiving works only in Org files"))))))
  7851. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7852. "Remove all lines in the agenda that correspond to a given subtree.
  7853. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7854. If this information is not given, the function uses the tree at point."
  7855. (let ((buf (or buf (current-buffer))) m p)
  7856. (save-excursion
  7857. (unless (and beg end)
  7858. (org-back-to-heading t)
  7859. (setq beg (point))
  7860. (org-end-of-subtree t)
  7861. (setq end (point)))
  7862. (set-buffer (get-buffer org-agenda-buffer-name))
  7863. (save-excursion
  7864. (goto-char (point-max))
  7865. (beginning-of-line 1)
  7866. (while (not (bobp))
  7867. (when (and (setq m (org-get-at-bol 'org-marker))
  7868. (equal buf (marker-buffer m))
  7869. (setq p (marker-position m))
  7870. (>= p beg)
  7871. (< p end))
  7872. (let ((inhibit-read-only t))
  7873. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7874. (beginning-of-line 0))))))
  7875. (defun org-agenda-refile (&optional goto rfloc no-update)
  7876. "Refile the item at point.
  7877. When called with `\\[universal-argument] \\[universal-argument]', \
  7878. go to the location of the last
  7879. refiled item.
  7880. When called with `\\[universal-argument] \\[universal-argument] \
  7881. \\[universal-argument]' prefix or when GOTO is 0, clear
  7882. the refile cache.
  7883. RFLOC can be a refile location obtained in a different way.
  7884. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7885. (interactive "P")
  7886. (cond
  7887. ((member goto '(0 (64)))
  7888. (org-refile-cache-clear))
  7889. ((equal goto '(16))
  7890. (org-refile-goto-last-stored))
  7891. (t
  7892. (let* ((buffer-orig (buffer-name))
  7893. (marker (or (org-get-at-bol 'org-hd-marker)
  7894. (org-agenda-error)))
  7895. (buffer (marker-buffer marker))
  7896. (pos (marker-position marker))
  7897. (rfloc (or rfloc
  7898. (org-refile-get-location
  7899. (if goto "Goto" "Refile to") buffer
  7900. org-refile-allow-creating-parent-nodes))))
  7901. (with-current-buffer buffer
  7902. (org-with-wide-buffer
  7903. (goto-char marker)
  7904. (let ((org-agenda-buffer-name buffer-orig))
  7905. (org-remove-subtree-entries-from-agenda))
  7906. (org-refile goto buffer rfloc))))
  7907. (unless no-update (org-agenda-redo)))))
  7908. (defun org-agenda-open-link (&optional arg)
  7909. "Open the link(s) in the current entry, if any.
  7910. This looks for a link in the displayed line in the agenda.
  7911. It also looks at the text of the entry itself."
  7912. (interactive "P")
  7913. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7914. (org-get-at-bol 'org-marker)))
  7915. (buffer (and marker (marker-buffer marker)))
  7916. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7917. (lkall (and buffer (org-offer-links-in-entry
  7918. buffer marker arg prefix)))
  7919. (lk0 (car lkall))
  7920. (lk (if (stringp lk0) (list lk0) lk0))
  7921. (lkend (cdr lkall))
  7922. trg)
  7923. (cond
  7924. ((and buffer lk)
  7925. (mapcar (lambda(l)
  7926. (with-current-buffer buffer
  7927. (setq trg (and (string-match org-bracket-link-regexp l)
  7928. (match-string 1 l)))
  7929. (if (or (not trg) (string-match org-any-link-re trg))
  7930. (org-with-wide-buffer
  7931. (goto-char marker)
  7932. (when (search-forward l nil lkend)
  7933. (goto-char (match-beginning 0))
  7934. (org-open-at-point)))
  7935. ;; This is an internal link, widen the buffer
  7936. (switch-to-buffer-other-window buffer)
  7937. (widen)
  7938. (goto-char marker)
  7939. (when (search-forward l nil lkend)
  7940. (goto-char (match-beginning 0))
  7941. (org-open-at-point)))))
  7942. lk))
  7943. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7944. (save-excursion
  7945. (beginning-of-line 1)
  7946. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7947. (org-open-link-from-string (match-string 1)))
  7948. (t (message "No link to open here")))))
  7949. (defun org-agenda-copy-local-variable (var)
  7950. "Get a variable from a referenced buffer and install it here."
  7951. (let ((m (org-get-at-bol 'org-marker)))
  7952. (when (and m (buffer-live-p (marker-buffer m)))
  7953. (set (make-local-variable var)
  7954. (with-current-buffer (marker-buffer m)
  7955. (symbol-value var))))))
  7956. (defun org-agenda-switch-to (&optional delete-other-windows)
  7957. "Go to the Org mode file which contains the item at point.
  7958. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  7959. displayed Org file fills the frame."
  7960. (interactive)
  7961. (if (and org-return-follows-link
  7962. (not (org-get-at-bol 'org-marker))
  7963. (org-in-regexp org-bracket-link-regexp))
  7964. (org-open-link-from-string (match-string 0))
  7965. (let* ((marker (or (org-get-at-bol 'org-marker)
  7966. (org-agenda-error)))
  7967. (buffer (marker-buffer marker))
  7968. (pos (marker-position marker)))
  7969. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  7970. (pop-to-buffer-same-window buffer)
  7971. (when delete-other-windows (delete-other-windows))
  7972. (widen)
  7973. (goto-char pos)
  7974. (when (derived-mode-p 'org-mode)
  7975. (org-show-context 'agenda)
  7976. (run-hooks 'org-agenda-after-show-hook)))))
  7977. (defun org-agenda-goto-mouse (ev)
  7978. "Go to the Org file which contains the item at the mouse click."
  7979. (interactive "e")
  7980. (mouse-set-point ev)
  7981. (org-agenda-goto))
  7982. (defun org-agenda-show (&optional full-entry)
  7983. "Display the Org file which contains the item at point.
  7984. With prefix argument FULL-ENTRY, make the entire entry visible
  7985. if it was hidden in the outline."
  7986. (interactive "P")
  7987. (let ((win (selected-window)))
  7988. (org-agenda-goto t)
  7989. (when full-entry (org-show-entry))
  7990. (select-window win)))
  7991. (defvar org-agenda-show-window nil)
  7992. (defun org-agenda-show-and-scroll-up (&optional arg)
  7993. "Display the Org file which contains the item at point.
  7994. When called repeatedly, scroll the window that is displaying the buffer.
  7995. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  7996. `outline-show-subtree'
  7997. to display the item, so that drawers and logbooks stay folded."
  7998. (interactive "P")
  7999. (let ((win (selected-window)))
  8000. (if (and (window-live-p org-agenda-show-window)
  8001. (eq this-command last-command))
  8002. (progn
  8003. (select-window org-agenda-show-window)
  8004. (ignore-errors (scroll-up)))
  8005. (org-agenda-goto t)
  8006. (if arg (org-show-entry) (outline-show-subtree))
  8007. (setq org-agenda-show-window (selected-window)))
  8008. (select-window win)))
  8009. (defun org-agenda-show-scroll-down ()
  8010. "Scroll down the window showing the agenda."
  8011. (interactive)
  8012. (let ((win (selected-window)))
  8013. (when (window-live-p org-agenda-show-window)
  8014. (select-window org-agenda-show-window)
  8015. (ignore-errors (scroll-down))
  8016. (select-window win))))
  8017. (defun org-agenda-show-1 (&optional more)
  8018. "Display the Org file which contains the item at point.
  8019. The prefix arg selects the amount of information to display:
  8020. 0 hide the subtree
  8021. 1 just show the entry according to defaults.
  8022. 2 show the children view
  8023. 3 show the subtree view
  8024. 4 show the entire subtree and any LOGBOOK drawers
  8025. 5 show the entire subtree and any drawers
  8026. With prefix argument FULL-ENTRY, make the entire entry visible
  8027. if it was hidden in the outline."
  8028. (interactive "p")
  8029. (let ((win (selected-window)))
  8030. (org-agenda-goto t)
  8031. (org-back-to-heading)
  8032. (set-window-start (selected-window) (point-at-bol))
  8033. (cond
  8034. ((= more 0)
  8035. (outline-hide-subtree)
  8036. (save-excursion
  8037. (org-back-to-heading)
  8038. (run-hook-with-args 'org-cycle-hook 'folded))
  8039. (message "Remote: FOLDED"))
  8040. ((and (called-interactively-p 'any) (= more 1))
  8041. (message "Remote: show with default settings"))
  8042. ((= more 2)
  8043. (outline-show-entry)
  8044. (org-show-children)
  8045. (save-excursion
  8046. (org-back-to-heading)
  8047. (run-hook-with-args 'org-cycle-hook 'children))
  8048. (message "Remote: CHILDREN"))
  8049. ((= more 3)
  8050. (outline-show-subtree)
  8051. (save-excursion
  8052. (org-back-to-heading)
  8053. (run-hook-with-args 'org-cycle-hook 'subtree))
  8054. (message "Remote: SUBTREE"))
  8055. ((= more 4)
  8056. (outline-show-subtree)
  8057. (save-excursion
  8058. (org-back-to-heading)
  8059. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8060. (message "Remote: SUBTREE AND LOGBOOK"))
  8061. ((> more 4)
  8062. (outline-show-subtree)
  8063. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8064. (select-window win)))
  8065. (defvar org-agenda-cycle-counter nil)
  8066. (defun org-agenda-cycle-show (&optional n)
  8067. "Show the current entry in another window, with default settings.
  8068. Default settings are taken from `org-show-context-detail'. When
  8069. use repeatedly in immediate succession, the remote entry will
  8070. cycle through visibility
  8071. children -> subtree -> folded
  8072. When called with a numeric prefix arg, that arg will be passed through to
  8073. `org-agenda-show-1'. For the interpretation of that argument, see the
  8074. docstring of `org-agenda-show-1'."
  8075. (interactive "P")
  8076. (if (integerp n)
  8077. (setq org-agenda-cycle-counter n)
  8078. (if (not (eq last-command this-command))
  8079. (setq org-agenda-cycle-counter 1)
  8080. (if (equal org-agenda-cycle-counter 0)
  8081. (setq org-agenda-cycle-counter 2)
  8082. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8083. (if (> org-agenda-cycle-counter 3)
  8084. (setq org-agenda-cycle-counter 0)))))
  8085. (org-agenda-show-1 org-agenda-cycle-counter))
  8086. (defun org-agenda-recenter (arg)
  8087. "Display the Org file which contains the item at point and recenter."
  8088. (interactive "P")
  8089. (let ((win (selected-window)))
  8090. (org-agenda-goto t)
  8091. (recenter arg)
  8092. (select-window win)))
  8093. (defun org-agenda-show-mouse (ev)
  8094. "Display the Org file which contains the item at the mouse click."
  8095. (interactive "e")
  8096. (mouse-set-point ev)
  8097. (org-agenda-show))
  8098. (defun org-agenda-check-no-diary ()
  8099. "Check if the entry is a diary link and abort if yes."
  8100. (if (org-get-at-bol 'org-agenda-diary-link)
  8101. (org-agenda-error)))
  8102. (defun org-agenda-error ()
  8103. "Throw an error when a command is not allowed in the agenda."
  8104. (user-error "Command not allowed in this line"))
  8105. (defun org-agenda-tree-to-indirect-buffer (arg)
  8106. "Show the subtree corresponding to the current entry in an indirect buffer.
  8107. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8108. With a numerical prefix ARG, go up to this level and then take that tree.
  8109. With a negative numeric ARG, go up by this number of levels.
  8110. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8111. i.e. don't use
  8112. the dedicated frame."
  8113. (interactive "P")
  8114. (if current-prefix-arg
  8115. (org-agenda-do-tree-to-indirect-buffer arg)
  8116. (let ((agenda-buffer (buffer-name))
  8117. (agenda-window (selected-window))
  8118. (indirect-window
  8119. (and org-last-indirect-buffer
  8120. (get-buffer-window org-last-indirect-buffer))))
  8121. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8122. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8123. (eq org-indirect-buffer-display 'dedicated-frame))
  8124. (unwind-protect
  8125. (unless (and indirect-window (window-live-p indirect-window))
  8126. (setq indirect-window (split-window agenda-window)))
  8127. (and indirect-window (select-window indirect-window))
  8128. (switch-to-buffer org-last-indirect-buffer :norecord)
  8129. (fit-window-to-buffer indirect-window)))
  8130. (select-window (get-buffer-window agenda-buffer))
  8131. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8132. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8133. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8134. (org-agenda-check-no-diary)
  8135. (let* ((marker (or (org-get-at-bol 'org-marker)
  8136. (org-agenda-error)))
  8137. (buffer (marker-buffer marker))
  8138. (pos (marker-position marker)))
  8139. (with-current-buffer buffer
  8140. (save-excursion
  8141. (goto-char pos)
  8142. (funcall 'org-tree-to-indirect-buffer arg)))))
  8143. (defvar org-last-heading-marker (make-marker)
  8144. "Marker pointing to the headline that last changed its TODO state
  8145. by a remote command from the agenda.")
  8146. (defun org-agenda-todo-nextset ()
  8147. "Switch TODO entry to next sequence."
  8148. (interactive)
  8149. (org-agenda-todo 'nextset))
  8150. (defun org-agenda-todo-previousset ()
  8151. "Switch TODO entry to previous sequence."
  8152. (interactive)
  8153. (org-agenda-todo 'previousset))
  8154. (defun org-agenda-todo (&optional arg)
  8155. "Cycle TODO state of line at point, also in Org file.
  8156. This changes the line at point, all other lines in the agenda referring to
  8157. the same tree node, and the headline of the tree node in the Org file."
  8158. (interactive "P")
  8159. (org-agenda-check-no-diary)
  8160. (let* ((col (current-column))
  8161. (marker (or (org-get-at-bol 'org-marker)
  8162. (org-agenda-error)))
  8163. (buffer (marker-buffer marker))
  8164. (pos (marker-position marker))
  8165. (hdmarker (org-get-at-bol 'org-hd-marker))
  8166. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8167. (inhibit-read-only t)
  8168. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8169. (org-with-remote-undo buffer
  8170. (with-current-buffer buffer
  8171. (widen)
  8172. (goto-char pos)
  8173. (org-show-context 'agenda)
  8174. (let ((current-prefix-arg arg))
  8175. (call-interactively 'org-todo))
  8176. (and (bolp) (forward-char 1))
  8177. (setq newhead (org-get-heading))
  8178. (when (and (bound-and-true-p
  8179. org-agenda-headline-snapshot-before-repeat)
  8180. (not (equal org-agenda-headline-snapshot-before-repeat
  8181. newhead))
  8182. todayp)
  8183. (setq newhead org-agenda-headline-snapshot-before-repeat
  8184. just-one t))
  8185. (save-excursion
  8186. (org-back-to-heading)
  8187. (move-marker org-last-heading-marker (point))))
  8188. (beginning-of-line 1)
  8189. (save-window-excursion
  8190. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8191. (when (bound-and-true-p org-clock-out-when-done)
  8192. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8193. newhead)
  8194. (org-agenda-unmark-clocking-task))
  8195. (org-move-to-column col)
  8196. (org-agenda-mark-clocking-task))))
  8197. (defun org-agenda-add-note (&optional arg)
  8198. "Add a time-stamped note to the entry at point."
  8199. (interactive "P")
  8200. (org-agenda-check-no-diary)
  8201. (let* ((marker (or (org-get-at-bol 'org-marker)
  8202. (org-agenda-error)))
  8203. (buffer (marker-buffer marker))
  8204. (pos (marker-position marker))
  8205. (hdmarker (org-get-at-bol 'org-hd-marker))
  8206. (inhibit-read-only t))
  8207. (with-current-buffer buffer
  8208. (widen)
  8209. (goto-char pos)
  8210. (org-show-context 'agenda)
  8211. (org-add-note))))
  8212. (defun org-agenda-change-all-lines (newhead hdmarker
  8213. &optional fixface just-this)
  8214. "Change all lines in the agenda buffer which match HDMARKER.
  8215. The new content of the line will be NEWHEAD (as modified by
  8216. `org-agenda-format-item'). HDMARKER is checked with
  8217. `equal' against all `org-hd-marker' text properties in the file.
  8218. If FIXFACE is non-nil, the face of each item is modified according to
  8219. the new TODO state.
  8220. If JUST-THIS is non-nil, change just the current line, not all.
  8221. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8222. (let* ((inhibit-read-only t)
  8223. (line (org-current-line))
  8224. (org-agenda-buffer (current-buffer))
  8225. (thetags (with-current-buffer (marker-buffer hdmarker)
  8226. (org-with-wide-buffer
  8227. (goto-char hdmarker)
  8228. (org-get-tags-at))))
  8229. props m pl undone-face done-face finish new dotime level cat tags)
  8230. (save-excursion
  8231. (goto-char (point-max))
  8232. (beginning-of-line 1)
  8233. (while (not finish)
  8234. (setq finish (bobp))
  8235. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8236. (or (not just-this) (= (org-current-line) line))
  8237. (equal m hdmarker))
  8238. (setq props (text-properties-at (point))
  8239. dotime (org-get-at-bol 'dotime)
  8240. cat (org-get-at-eol 'org-category 1)
  8241. level (org-get-at-bol 'level)
  8242. tags thetags
  8243. new
  8244. (let ((org-prefix-format-compiled
  8245. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8246. org-prefix-format-compiled))
  8247. (extra (org-get-at-bol 'extra)))
  8248. (with-current-buffer (marker-buffer hdmarker)
  8249. (org-with-wide-buffer
  8250. (org-agenda-format-item extra newhead level cat tags dotime))))
  8251. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8252. undone-face (org-get-at-bol 'undone-face)
  8253. done-face (org-get-at-bol 'done-face))
  8254. (beginning-of-line 1)
  8255. (cond
  8256. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8257. ((looking-at ".*")
  8258. ;; When replacing the whole line, preserve bulk mark
  8259. ;; overlay, if any.
  8260. (let ((mark (catch :overlay
  8261. (dolist (o (overlays-in (point) (+ 2 (point))))
  8262. (when (eq (overlay-get o 'type)
  8263. 'org-marked-entry-overlay)
  8264. (throw :overlay o))))))
  8265. (replace-match new t t)
  8266. (beginning-of-line)
  8267. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8268. (add-text-properties (point-at-bol) (point-at-eol) props)
  8269. (when fixface
  8270. (add-text-properties
  8271. (point-at-bol) (point-at-eol)
  8272. (list 'face
  8273. (if org-last-todo-state-is-todo
  8274. undone-face done-face))))
  8275. (org-agenda-highlight-todo 'line)
  8276. (beginning-of-line 1))
  8277. (t (error "Line update did not work")))
  8278. (save-restriction
  8279. (narrow-to-region (point-at-bol) (point-at-eol))
  8280. (org-agenda-finalize)))
  8281. (beginning-of-line 0)))))
  8282. (defun org-agenda-align-tags (&optional line)
  8283. "Align all tags in agenda items to `org-agenda-tags-column'."
  8284. (let ((inhibit-read-only t) l c)
  8285. (save-excursion
  8286. (goto-char (if line (point-at-bol) (point-min)))
  8287. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8288. (if line (point-at-eol) nil) t)
  8289. (add-text-properties
  8290. (match-beginning 2) (match-end 2)
  8291. (list 'face (delq nil (let ((prop (get-text-property
  8292. (match-beginning 2) 'face)))
  8293. (or (listp prop) (setq prop (list prop)))
  8294. (if (memq 'org-tag prop)
  8295. prop
  8296. (cons 'org-tag prop))))))
  8297. (setq l (- (match-end 2) (match-beginning 2))
  8298. c (if (< org-agenda-tags-column 0)
  8299. (- (abs org-agenda-tags-column) l)
  8300. org-agenda-tags-column))
  8301. (delete-region (match-beginning 1) (match-end 1))
  8302. (goto-char (match-beginning 1))
  8303. (insert (org-add-props
  8304. (make-string (max 1 (- c (current-column))) ?\ )
  8305. (plist-put (copy-sequence (text-properties-at (point)))
  8306. 'face nil))))
  8307. (goto-char (point-min))
  8308. (org-font-lock-add-tag-faces (point-max)))))
  8309. (defun org-agenda-priority-up ()
  8310. "Increase the priority of line at point, also in Org file."
  8311. (interactive)
  8312. (org-agenda-priority 'up))
  8313. (defun org-agenda-priority-down ()
  8314. "Decrease the priority of line at point, also in Org file."
  8315. (interactive)
  8316. (org-agenda-priority 'down))
  8317. (defun org-agenda-priority (&optional force-direction)
  8318. "Set the priority of line at point, also in Org file.
  8319. This changes the line at point, all other lines in the agenda referring to
  8320. the same tree node, and the headline of the tree node in the Org file.
  8321. Called with a universal prefix arg, show the priority instead of setting it."
  8322. (interactive "P")
  8323. (if (equal force-direction '(4))
  8324. (org-show-priority)
  8325. (unless org-enable-priority-commands
  8326. (error "Priority commands are disabled"))
  8327. (org-agenda-check-no-diary)
  8328. (let* ((col (current-column))
  8329. (marker (or (org-get-at-bol 'org-marker)
  8330. (org-agenda-error)))
  8331. (hdmarker (org-get-at-bol 'org-hd-marker))
  8332. (buffer (marker-buffer hdmarker))
  8333. (pos (marker-position hdmarker))
  8334. (inhibit-read-only t)
  8335. newhead)
  8336. (org-with-remote-undo buffer
  8337. (with-current-buffer buffer
  8338. (widen)
  8339. (goto-char pos)
  8340. (org-show-context 'agenda)
  8341. (funcall 'org-priority force-direction)
  8342. (end-of-line 1)
  8343. (setq newhead (org-get-heading)))
  8344. (org-agenda-change-all-lines newhead hdmarker)
  8345. (org-move-to-column col)))))
  8346. ;; FIXME: should fix the tags property of the agenda line.
  8347. (defun org-agenda-set-tags (&optional tag onoff)
  8348. "Set tags for the current headline."
  8349. (interactive)
  8350. (org-agenda-check-no-diary)
  8351. (if (and (org-region-active-p) (called-interactively-p 'any))
  8352. (call-interactively 'org-change-tag-in-region)
  8353. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8354. (org-agenda-error)))
  8355. (buffer (marker-buffer hdmarker))
  8356. (pos (marker-position hdmarker))
  8357. (inhibit-read-only t)
  8358. newhead)
  8359. (org-with-remote-undo buffer
  8360. (with-current-buffer buffer
  8361. (widen)
  8362. (goto-char pos)
  8363. (org-show-context 'agenda)
  8364. (if tag
  8365. (org-toggle-tag tag onoff)
  8366. (call-interactively 'org-set-tags))
  8367. (end-of-line 1)
  8368. (setq newhead (org-get-heading)))
  8369. (org-agenda-change-all-lines newhead hdmarker)
  8370. (beginning-of-line 1)))))
  8371. (defun org-agenda-set-property ()
  8372. "Set a property for the current headline."
  8373. (interactive)
  8374. (org-agenda-check-no-diary)
  8375. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8376. (org-agenda-error)))
  8377. (buffer (marker-buffer hdmarker))
  8378. (pos (marker-position hdmarker))
  8379. (inhibit-read-only t)
  8380. newhead)
  8381. (org-with-remote-undo buffer
  8382. (with-current-buffer buffer
  8383. (widen)
  8384. (goto-char pos)
  8385. (org-show-context 'agenda)
  8386. (call-interactively 'org-set-property)))))
  8387. (defun org-agenda-set-effort ()
  8388. "Set the effort property for the current headline."
  8389. (interactive)
  8390. (org-agenda-check-no-diary)
  8391. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8392. (org-agenda-error)))
  8393. (buffer (marker-buffer hdmarker))
  8394. (pos (marker-position hdmarker))
  8395. (inhibit-read-only t)
  8396. newhead)
  8397. (org-with-remote-undo buffer
  8398. (with-current-buffer buffer
  8399. (widen)
  8400. (goto-char pos)
  8401. (org-show-context 'agenda)
  8402. (call-interactively 'org-set-effort)
  8403. (end-of-line 1)
  8404. (setq newhead (org-get-heading)))
  8405. (org-agenda-change-all-lines newhead hdmarker))))
  8406. (defun org-agenda-toggle-archive-tag ()
  8407. "Toggle the archive tag for the current entry."
  8408. (interactive)
  8409. (org-agenda-check-no-diary)
  8410. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8411. (org-agenda-error)))
  8412. (buffer (marker-buffer hdmarker))
  8413. (pos (marker-position hdmarker))
  8414. (inhibit-read-only t)
  8415. newhead)
  8416. (org-with-remote-undo buffer
  8417. (with-current-buffer buffer
  8418. (widen)
  8419. (goto-char pos)
  8420. (org-show-context 'agenda)
  8421. (call-interactively 'org-toggle-archive-tag)
  8422. (end-of-line 1)
  8423. (setq newhead (org-get-heading)))
  8424. (org-agenda-change-all-lines newhead hdmarker)
  8425. (beginning-of-line 1))))
  8426. (defun org-agenda-do-date-later (arg)
  8427. (interactive "P")
  8428. (cond
  8429. ((or (equal arg '(16))
  8430. (memq last-command
  8431. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8432. (setq this-command 'org-agenda-date-later-minutes)
  8433. (org-agenda-date-later-minutes 1))
  8434. ((or (equal arg '(4))
  8435. (memq last-command
  8436. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8437. (setq this-command 'org-agenda-date-later-hours)
  8438. (org-agenda-date-later-hours 1))
  8439. (t
  8440. (org-agenda-date-later (prefix-numeric-value arg)))))
  8441. (defun org-agenda-do-date-earlier (arg)
  8442. (interactive "P")
  8443. (cond
  8444. ((or (equal arg '(16))
  8445. (memq last-command
  8446. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8447. (setq this-command 'org-agenda-date-earlier-minutes)
  8448. (org-agenda-date-earlier-minutes 1))
  8449. ((or (equal arg '(4))
  8450. (memq last-command
  8451. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8452. (setq this-command 'org-agenda-date-earlier-hours)
  8453. (org-agenda-date-earlier-hours 1))
  8454. (t
  8455. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8456. (defun org-agenda-date-later (arg &optional what)
  8457. "Change the date of this item to ARG day(s) later."
  8458. (interactive "p")
  8459. (org-agenda-check-type t 'agenda 'timeline)
  8460. (org-agenda-check-no-diary)
  8461. (let* ((marker (or (org-get-at-bol 'org-marker)
  8462. (org-agenda-error)))
  8463. (buffer (marker-buffer marker))
  8464. (pos (marker-position marker))
  8465. cdate today)
  8466. (org-with-remote-undo buffer
  8467. (with-current-buffer buffer
  8468. (widen)
  8469. (goto-char pos)
  8470. (if (not (org-at-timestamp-p))
  8471. (error "Cannot find time stamp"))
  8472. (when (and org-agenda-move-date-from-past-immediately-to-today
  8473. (equal arg 1)
  8474. (or (not what) (eq what 'day))
  8475. (not (save-match-data (org-at-date-range-p))))
  8476. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8477. cdate (calendar-absolute-from-gregorian
  8478. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8479. today (org-today))
  8480. (if (> today cdate)
  8481. ;; immediately shift to today
  8482. (setq arg (- today cdate))))
  8483. (org-timestamp-change arg (or what 'day))
  8484. (when (and (org-at-date-range-p)
  8485. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8486. (let ((end org-last-changed-timestamp))
  8487. (org-timestamp-change arg (or what 'day))
  8488. (setq org-last-changed-timestamp
  8489. (concat org-last-changed-timestamp "--" end)))))
  8490. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8491. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8492. (defun org-agenda-date-earlier (arg &optional what)
  8493. "Change the date of this item to ARG day(s) earlier."
  8494. (interactive "p")
  8495. (org-agenda-date-later (- arg) what))
  8496. (defun org-agenda-date-later-minutes (arg)
  8497. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8498. (interactive "p")
  8499. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8500. (org-agenda-date-later arg 'minute))
  8501. (defun org-agenda-date-earlier-minutes (arg)
  8502. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8503. (interactive "p")
  8504. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8505. (org-agenda-date-earlier arg 'minute))
  8506. (defun org-agenda-date-later-hours (arg)
  8507. "Change the time of this item, in hour steps."
  8508. (interactive "p")
  8509. (org-agenda-date-later arg 'hour))
  8510. (defun org-agenda-date-earlier-hours (arg)
  8511. "Change the time of this item, in hour steps."
  8512. (interactive "p")
  8513. (org-agenda-date-earlier arg 'hour))
  8514. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8515. "Show new date stamp via text properties."
  8516. ;; We use text properties to make this undoable
  8517. (let ((inhibit-read-only t))
  8518. (setq stamp (concat prefix " => " stamp " "))
  8519. (save-excursion
  8520. (goto-char (point-max))
  8521. (while (not (bobp))
  8522. (when (equal marker (org-get-at-bol 'org-marker))
  8523. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8524. (org-move-to-column (- (window-width) (length stamp)) t)
  8525. (add-text-properties
  8526. (1- (point)) (point-at-eol)
  8527. (list 'display (org-add-props stamp nil
  8528. 'face '(secondary-selection default))))
  8529. (beginning-of-line 1))
  8530. (beginning-of-line 0)))))
  8531. (defun org-agenda-date-prompt (arg)
  8532. "Change the date of this item. Date is prompted for, with default today.
  8533. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8534. be used to request time specification in the time stamp."
  8535. (interactive "P")
  8536. (org-agenda-check-type t 'agenda 'timeline)
  8537. (org-agenda-check-no-diary)
  8538. (let* ((marker (or (org-get-at-bol 'org-marker)
  8539. (org-agenda-error)))
  8540. (buffer (marker-buffer marker))
  8541. (pos (marker-position marker)))
  8542. (org-with-remote-undo buffer
  8543. (with-current-buffer buffer
  8544. (widen)
  8545. (goto-char pos)
  8546. (if (not (org-at-timestamp-p t))
  8547. (error "Cannot find time stamp"))
  8548. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8549. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8550. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8551. (defun org-agenda-schedule (arg &optional time)
  8552. "Schedule the item at point.
  8553. ARG is passed through to `org-schedule'."
  8554. (interactive "P")
  8555. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8556. (org-agenda-check-no-diary)
  8557. (let* ((marker (or (org-get-at-bol 'org-marker)
  8558. (org-agenda-error)))
  8559. (type (marker-insertion-type marker))
  8560. (buffer (marker-buffer marker))
  8561. (pos (marker-position marker))
  8562. ts)
  8563. (set-marker-insertion-type marker t)
  8564. (org-with-remote-undo buffer
  8565. (with-current-buffer buffer
  8566. (widen)
  8567. (goto-char pos)
  8568. (setq ts (org-schedule arg time)))
  8569. (org-agenda-show-new-time marker ts " S"))
  8570. (message "%s" ts)))
  8571. (defun org-agenda-deadline (arg &optional time)
  8572. "Schedule the item at point.
  8573. ARG is passed through to `org-deadline'."
  8574. (interactive "P")
  8575. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8576. (org-agenda-check-no-diary)
  8577. (let* ((marker (or (org-get-at-bol 'org-marker)
  8578. (org-agenda-error)))
  8579. (buffer (marker-buffer marker))
  8580. (pos (marker-position marker))
  8581. ts)
  8582. (org-with-remote-undo buffer
  8583. (with-current-buffer buffer
  8584. (widen)
  8585. (goto-char pos)
  8586. (setq ts (org-deadline arg time)))
  8587. (org-agenda-show-new-time marker ts " D"))
  8588. (message "%s" ts)))
  8589. (defun org-agenda-clock-in (&optional arg)
  8590. "Start the clock on the currently selected item."
  8591. (interactive "P")
  8592. (org-agenda-check-no-diary)
  8593. (if (equal arg '(4))
  8594. (org-clock-in arg)
  8595. (let* ((marker (or (org-get-at-bol 'org-marker)
  8596. (org-agenda-error)))
  8597. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8598. (pos (marker-position marker))
  8599. (col (current-column))
  8600. newhead)
  8601. (org-with-remote-undo (marker-buffer marker)
  8602. (with-current-buffer (marker-buffer marker)
  8603. (widen)
  8604. (goto-char pos)
  8605. (org-show-context 'agenda)
  8606. (org-cycle-hide-drawers 'children)
  8607. (org-clock-in arg)
  8608. (setq newhead (org-get-heading)))
  8609. (org-agenda-change-all-lines newhead hdmarker))
  8610. (org-move-to-column col))))
  8611. (defun org-agenda-clock-out ()
  8612. "Stop the currently running clock."
  8613. (interactive)
  8614. (unless (marker-buffer org-clock-marker)
  8615. (error "No running clock"))
  8616. (let ((marker (make-marker)) (col (current-column)) newhead)
  8617. (org-with-remote-undo (marker-buffer org-clock-marker)
  8618. (with-current-buffer (marker-buffer org-clock-marker)
  8619. (org-with-wide-buffer
  8620. (goto-char org-clock-marker)
  8621. (org-back-to-heading t)
  8622. (move-marker marker (point))
  8623. (org-clock-out)
  8624. (setq newhead (org-get-heading)))))
  8625. (org-agenda-change-all-lines newhead marker)
  8626. (move-marker marker nil)
  8627. (org-move-to-column col)
  8628. (org-agenda-unmark-clocking-task)))
  8629. (defun org-agenda-clock-cancel (&optional arg)
  8630. "Cancel the currently running clock."
  8631. (interactive "P")
  8632. (unless (marker-buffer org-clock-marker)
  8633. (user-error "No running clock"))
  8634. (org-with-remote-undo (marker-buffer org-clock-marker)
  8635. (org-clock-cancel)))
  8636. (defun org-agenda-clock-goto ()
  8637. "Jump to the currently clocked in task within the agenda.
  8638. If the currently clocked in task is not listed in the agenda
  8639. buffer, display it in another window."
  8640. (interactive)
  8641. (let (pos)
  8642. (mapc (lambda (o)
  8643. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8644. (setq pos (overlay-start o))))
  8645. (overlays-in (point-min) (point-max)))
  8646. (cond (pos (goto-char pos))
  8647. ;; If the currently clocked entry is not in the agenda
  8648. ;; buffer, we visit it in another window:
  8649. ((bound-and-true-p org-clock-current-task)
  8650. (org-switch-to-buffer-other-window (org-clock-goto)))
  8651. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8652. (defun org-agenda-diary-entry-in-org-file ()
  8653. "Make a diary entry in the file `org-agenda-diary-file'."
  8654. (let (d1 d2 char (text "") dp1 dp2)
  8655. (if (equal (buffer-name) "*Calendar*")
  8656. (setq d1 (calendar-cursor-to-date t)
  8657. d2 (car calendar-mark-ring))
  8658. (setq dp1 (get-text-property (point-at-bol) 'day))
  8659. (unless dp1 (user-error "No date defined in current line"))
  8660. (setq d1 (calendar-gregorian-from-absolute dp1)
  8661. d2 (and (ignore-errors (mark))
  8662. (save-excursion
  8663. (goto-char (mark))
  8664. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8665. (calendar-gregorian-from-absolute dp2))))
  8666. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8667. (setq char (read-char-exclusive))
  8668. (cond
  8669. ((equal char ?d)
  8670. (setq text (read-string "Day entry: "))
  8671. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8672. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8673. ((equal char ?a)
  8674. (setq d1 (list (car d1) (nth 1 d1)
  8675. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8676. (nth 2 d1))))
  8677. (setq text (read-string "Anniversary (use %d to show years): "))
  8678. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8679. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8680. ((equal char ?b)
  8681. (setq text (read-string "Block entry: "))
  8682. (unless (and d1 d2 (not (equal d1 d2)))
  8683. (user-error "No block of days selected"))
  8684. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8685. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8686. ((equal char ?j)
  8687. (org-switch-to-buffer-other-window
  8688. (find-file-noselect org-agenda-diary-file))
  8689. (require 'org-datetree)
  8690. (org-datetree-find-date-create d1)
  8691. (org-reveal t))
  8692. (t (user-error "Invalid selection character `%c'" char)))))
  8693. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8694. "Where in `org-agenda-diary-file' should new entries be added?
  8695. Valid values:
  8696. date-tree in the date tree, as first child of the date
  8697. date-tree-last in the date tree, as last child of the date
  8698. top-level as top-level entries at the end of the file."
  8699. :group 'org-agenda
  8700. :type '(choice
  8701. (const :tag "first in a date tree" date-tree)
  8702. (const :tag "last in a date tree" date-tree-last)
  8703. (const :tag "as top level at end of file" top-level)))
  8704. (defcustom org-agenda-insert-diary-extract-time nil
  8705. "Non-nil means extract any time specification from the diary entry."
  8706. :group 'org-agenda
  8707. :version "24.1"
  8708. :type 'boolean)
  8709. (defcustom org-agenda-bulk-mark-char ">"
  8710. "A single-character string to be used as the bulk mark."
  8711. :group 'org-agenda
  8712. :version "24.1"
  8713. :type 'string)
  8714. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8715. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8716. If TEXT is not empty, it will become the headline of the new entry, and
  8717. the resulting entry will not be shown. When TEXT is empty, switch to
  8718. `org-agenda-diary-file' and let the user finish the entry there."
  8719. (let ((cw (current-window-configuration)))
  8720. (org-switch-to-buffer-other-window
  8721. (find-file-noselect org-agenda-diary-file))
  8722. (widen)
  8723. (goto-char (point-min))
  8724. (cond
  8725. ((eq type 'anniversary)
  8726. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8727. (progn
  8728. (or (org-at-heading-p t)
  8729. (progn
  8730. (outline-next-heading)
  8731. (insert "* Anniversaries\n\n")
  8732. (beginning-of-line -1)))))
  8733. (outline-next-heading)
  8734. (org-back-over-empty-lines)
  8735. (backward-char 1)
  8736. (insert "\n")
  8737. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8738. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8739. ((eq type 'day)
  8740. (let ((org-prefix-has-time t)
  8741. (org-agenda-time-leading-zero t)
  8742. fmt time time2)
  8743. (if org-agenda-insert-diary-extract-time
  8744. ;; Use org-agenda-format-item to parse text for a time-range and
  8745. ;; remove it. FIXME: This is a hack, we should refactor
  8746. ;; that function to make time extraction available separately
  8747. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8748. time (get-text-property 0 'time fmt)
  8749. time2 (if (> (length time) 0)
  8750. ;; split-string removes trailing ...... if
  8751. ;; no end time given. First space
  8752. ;; separates time from date.
  8753. (concat " " (car (split-string time "\\.")))
  8754. nil)
  8755. text (get-text-property 0 'txt fmt)))
  8756. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8757. (org-agenda-insert-diary-as-top-level text)
  8758. (require 'org-datetree)
  8759. (org-datetree-find-date-create d1)
  8760. (org-agenda-insert-diary-make-new-entry text))
  8761. (org-insert-time-stamp (org-time-from-absolute
  8762. (calendar-absolute-from-gregorian d1))
  8763. nil nil nil nil time2))
  8764. (end-of-line 0))
  8765. ((eq type 'block)
  8766. (if (> (calendar-absolute-from-gregorian d1)
  8767. (calendar-absolute-from-gregorian d2))
  8768. (setq d1 (prog1 d2 (setq d2 d1))))
  8769. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8770. (org-agenda-insert-diary-as-top-level text)
  8771. (require 'org-datetree)
  8772. (org-datetree-find-date-create d1)
  8773. (org-agenda-insert-diary-make-new-entry text))
  8774. (org-insert-time-stamp (org-time-from-absolute
  8775. (calendar-absolute-from-gregorian d1)))
  8776. (insert "--")
  8777. (org-insert-time-stamp (org-time-from-absolute
  8778. (calendar-absolute-from-gregorian d2)))
  8779. (end-of-line 0)))
  8780. (if (string-match "\\S-" text)
  8781. (progn
  8782. (set-window-configuration cw)
  8783. (message "%s entry added to %s"
  8784. (capitalize (symbol-name type))
  8785. (abbreviate-file-name org-agenda-diary-file)))
  8786. (org-reveal t)
  8787. (message "Please finish entry here"))))
  8788. (defun org-agenda-insert-diary-as-top-level (text)
  8789. "Make new entry as a top-level entry at the end of the file.
  8790. Add TEXT as headline, and position the cursor in the second line so that
  8791. a timestamp can be added there."
  8792. (widen)
  8793. (goto-char (point-max))
  8794. (unless (bolp) (insert "\n"))
  8795. (org-insert-heading nil t t)
  8796. (insert text)
  8797. (org-end-of-meta-data)
  8798. (unless (bolp) (insert "\n"))
  8799. (when org-adapt-indentation (indent-to-column 2)))
  8800. (defun org-agenda-insert-diary-make-new-entry (text)
  8801. "Make a new entry with TEXT as a child of the current subtree.
  8802. Position the point in the heading's first body line so that
  8803. a timestamp can be added there."
  8804. (cond
  8805. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8806. (end-of-line)
  8807. (org-insert-heading '(4) t)
  8808. (org-do-demote))
  8809. (t
  8810. (outline-next-heading)
  8811. (org-back-over-empty-lines)
  8812. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8813. (org-insert-heading nil t)
  8814. (org-do-demote)))
  8815. (let ((col (current-column)))
  8816. (insert text)
  8817. (org-end-of-meta-data)
  8818. ;; Ensure point is left on a blank line, at proper indentation.
  8819. (unless (bolp) (insert "\n"))
  8820. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8821. (when org-adapt-indentation (indent-to-column col)))
  8822. (org-show-set-visibility 'lineage))
  8823. (defun org-agenda-diary-entry ()
  8824. "Make a diary entry, like the `i' command from the calendar.
  8825. All the standard commands work: block, weekly etc.
  8826. When `org-agenda-diary-file' points to a file,
  8827. `org-agenda-diary-entry-in-org-file' is called instead to create
  8828. entries in that Org file."
  8829. (interactive)
  8830. (if (not (eq org-agenda-diary-file 'diary-file))
  8831. (org-agenda-diary-entry-in-org-file)
  8832. (require 'diary-lib)
  8833. (let* ((char (progn
  8834. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8835. (read-char-exclusive)))
  8836. (cmd (cdr (assoc char
  8837. '((?d . diary-insert-entry)
  8838. (?w . diary-insert-weekly-entry)
  8839. (?m . diary-insert-monthly-entry)
  8840. (?y . diary-insert-yearly-entry)
  8841. (?a . diary-insert-anniversary-entry)
  8842. (?b . diary-insert-block-entry)
  8843. (?c . diary-insert-cyclic-entry)))))
  8844. (oldf (symbol-function 'calendar-cursor-to-date))
  8845. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8846. (point (point))
  8847. (mark (or (mark t) (point))))
  8848. (unless cmd
  8849. (user-error "No command associated with <%c>" char))
  8850. (unless (and (get-text-property point 'day)
  8851. (or (not (equal ?b char))
  8852. (get-text-property mark 'day)))
  8853. (user-error "Don't know which date to use for diary entry"))
  8854. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8855. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8856. (let ((calendar-mark-ring
  8857. (list (calendar-gregorian-from-absolute
  8858. (or (get-text-property mark 'day)
  8859. (get-text-property point 'day))))))
  8860. (unwind-protect
  8861. (progn
  8862. (fset 'calendar-cursor-to-date
  8863. (lambda (&optional error dummy)
  8864. (calendar-gregorian-from-absolute
  8865. (get-text-property point 'day))))
  8866. (call-interactively cmd))
  8867. (fset 'calendar-cursor-to-date oldf))))))
  8868. (defun org-agenda-execute-calendar-command (cmd)
  8869. "Execute a calendar command from the agenda with date from cursor."
  8870. (org-agenda-check-type t 'agenda 'timeline)
  8871. (require 'diary-lib)
  8872. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8873. (user-error "Don't know which date to use for the calendar command"))
  8874. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8875. (point (point))
  8876. (date (calendar-gregorian-from-absolute
  8877. (get-text-property point 'day)))
  8878. ;; the following 2 vars are needed in the calendar
  8879. (displayed-month (car date))
  8880. (displayed-year (nth 2 date)))
  8881. (unwind-protect
  8882. (progn
  8883. (fset 'calendar-cursor-to-date
  8884. (lambda (&optional error dummy)
  8885. (calendar-gregorian-from-absolute
  8886. (get-text-property point 'day))))
  8887. (call-interactively cmd))
  8888. (fset 'calendar-cursor-to-date oldf))))
  8889. (defun org-agenda-phases-of-moon ()
  8890. "Display the phases of the moon for the 3 months around the cursor date."
  8891. (interactive)
  8892. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  8893. (defun org-agenda-holidays ()
  8894. "Display the holidays for the 3 months around the cursor date."
  8895. (interactive)
  8896. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  8897. (defvar calendar-longitude) ; defined in calendar.el
  8898. (defvar calendar-latitude) ; defined in calendar.el
  8899. (defvar calendar-location-name) ; defined in calendar.el
  8900. (defun org-agenda-sunrise-sunset (arg)
  8901. "Display sunrise and sunset for the cursor date.
  8902. Latitude and longitude can be specified with the variables
  8903. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8904. argument, latitude and longitude will be prompted for."
  8905. (interactive "P")
  8906. (require 'solar)
  8907. (let ((calendar-longitude (if arg nil calendar-longitude))
  8908. (calendar-latitude (if arg nil calendar-latitude))
  8909. (calendar-location-name
  8910. (if arg "the given coordinates" calendar-location-name)))
  8911. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8912. (defun org-agenda-goto-calendar ()
  8913. "Open the Emacs calendar with the date at the cursor."
  8914. (interactive)
  8915. (org-agenda-check-type t 'agenda 'timeline)
  8916. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8917. (user-error "Don't know which date to open in calendar")))
  8918. (date (calendar-gregorian-from-absolute day))
  8919. (calendar-move-hook nil)
  8920. (calendar-view-holidays-initially-flag nil)
  8921. (calendar-view-diary-initially-flag nil))
  8922. (calendar)
  8923. (calendar-goto-date date)))
  8924. ;;;###autoload
  8925. (defun org-calendar-goto-agenda ()
  8926. "Compute the Org agenda for the calendar date displayed at the cursor.
  8927. This is a command that has to be installed in `calendar-mode-map'."
  8928. (interactive)
  8929. ;; Temporarily disable sticky agenda since user clearly wants to
  8930. ;; refresh view anyway.
  8931. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  8932. (org-agenda-sticky nil))
  8933. (org-agenda-list nil (calendar-absolute-from-gregorian
  8934. (calendar-cursor-to-date))
  8935. nil)))
  8936. (defun org-agenda-convert-date ()
  8937. (interactive)
  8938. (org-agenda-check-type t 'agenda 'timeline)
  8939. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8940. date s)
  8941. (unless day
  8942. (user-error "Don't know which date to convert"))
  8943. (setq date (calendar-gregorian-from-absolute day))
  8944. (setq s (concat
  8945. "Gregorian: " (calendar-date-string date) "\n"
  8946. "ISO: " (calendar-iso-date-string date) "\n"
  8947. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8948. "Julian: " (calendar-julian-date-string date) "\n"
  8949. "Astron. JD: " (calendar-astro-date-string date)
  8950. " (Julian date number at noon UTC)\n"
  8951. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8952. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8953. "French: " (calendar-french-date-string date) "\n"
  8954. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  8955. "Mayan: " (calendar-mayan-date-string date) "\n"
  8956. "Coptic: " (calendar-coptic-date-string date) "\n"
  8957. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8958. "Persian: " (calendar-persian-date-string date) "\n"
  8959. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8960. (with-output-to-temp-buffer "*Dates*"
  8961. (princ s))
  8962. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8963. ;;; Bulk commands
  8964. (defun org-agenda-bulk-marked-p ()
  8965. "Non-nil when current entry is marked for bulk action."
  8966. (eq (get-char-property (point-at-bol) 'type)
  8967. 'org-marked-entry-overlay))
  8968. (defun org-agenda-bulk-mark (&optional arg)
  8969. "Mark the entry at point for future bulk action."
  8970. (interactive "p")
  8971. (dotimes (i (or arg 1))
  8972. (unless (org-get-at-bol 'org-agenda-diary-link)
  8973. (let* ((m (org-get-at-bol 'org-hd-marker))
  8974. ov)
  8975. (unless (org-agenda-bulk-marked-p)
  8976. (unless m (user-error "Nothing to mark at point"))
  8977. (push m org-agenda-bulk-marked-entries)
  8978. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8979. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8980. (org-get-todo-face "TODO")
  8981. 'evaporate)
  8982. (overlay-put ov 'type 'org-marked-entry-overlay))
  8983. (end-of-line 1)
  8984. (or (ignore-errors
  8985. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  8986. (beginning-of-line 2))
  8987. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8988. (beginning-of-line 2))
  8989. (message "%d entries marked for bulk action"
  8990. (length org-agenda-bulk-marked-entries))))))
  8991. (defun org-agenda-bulk-mark-all ()
  8992. "Mark all entries for future agenda bulk action."
  8993. (interactive)
  8994. (org-agenda-bulk-mark-regexp "."))
  8995. (defun org-agenda-bulk-mark-regexp (regexp)
  8996. "Mark entries matching REGEXP for future agenda bulk action."
  8997. (interactive "sMark entries matching regexp: ")
  8998. (let ((entries-marked 0) txt-at-point)
  8999. (save-excursion
  9000. (goto-char (point-min))
  9001. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9002. (while (and (re-search-forward regexp nil t)
  9003. (setq txt-at-point (get-text-property (point) 'txt)))
  9004. (if (get-char-property (point) 'invisible)
  9005. (beginning-of-line 2)
  9006. (when (string-match regexp txt-at-point)
  9007. (setq entries-marked (1+ entries-marked))
  9008. (call-interactively 'org-agenda-bulk-mark)))))
  9009. (if (not entries-marked)
  9010. (message "No entry matching this regexp."))))
  9011. (defun org-agenda-bulk-unmark (&optional arg)
  9012. "Unmark the entry at point for future bulk action."
  9013. (interactive "P")
  9014. (if arg
  9015. (org-agenda-bulk-unmark-all)
  9016. (cond ((org-agenda-bulk-marked-p)
  9017. (org-agenda-bulk-remove-overlays
  9018. (point-at-bol) (+ 2 (point-at-bol)))
  9019. (setq org-agenda-bulk-marked-entries
  9020. (delete (org-get-at-bol 'org-hd-marker)
  9021. org-agenda-bulk-marked-entries))
  9022. (end-of-line 1)
  9023. (or (ignore-errors
  9024. (goto-char (next-single-property-change (point) 'txt)))
  9025. (beginning-of-line 2))
  9026. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9027. (beginning-of-line 2))
  9028. (message "%d entries left marked for bulk action"
  9029. (length org-agenda-bulk-marked-entries)))
  9030. (t (message "No entry to unmark here")))))
  9031. (defun org-agenda-bulk-toggle-all ()
  9032. "Toggle all marks for bulk action."
  9033. (interactive)
  9034. (save-excursion
  9035. (goto-char (point-min))
  9036. (while (ignore-errors
  9037. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9038. (org-agenda-bulk-toggle))))
  9039. (defun org-agenda-bulk-toggle ()
  9040. "Toggle the mark at point for bulk action."
  9041. (interactive)
  9042. (if (org-agenda-bulk-marked-p)
  9043. (org-agenda-bulk-unmark)
  9044. (org-agenda-bulk-mark)))
  9045. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9046. "Remove the mark overlays between BEG and END in the agenda buffer.
  9047. BEG and END default to the buffer limits.
  9048. This only removes the overlays, it does not remove the markers
  9049. from the list in `org-agenda-bulk-marked-entries'."
  9050. (interactive)
  9051. (mapc (lambda (ov)
  9052. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9053. (delete-overlay ov)))
  9054. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9055. (defun org-agenda-bulk-unmark-all ()
  9056. "Remove all marks in the agenda buffer.
  9057. This will remove the markers and the overlays."
  9058. (interactive)
  9059. (if (null org-agenda-bulk-marked-entries)
  9060. (message "No entry to unmark")
  9061. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9062. (setq org-agenda-bulk-marked-entries nil)
  9063. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9064. (defcustom org-agenda-persistent-marks nil
  9065. "Non-nil means marked items will stay marked after a bulk action.
  9066. You can toggle this interactively by typing `p' when prompted for a
  9067. bulk action."
  9068. :group 'org-agenda
  9069. :version "24.1"
  9070. :type 'boolean)
  9071. (defun org-agenda-bulk-action (&optional arg)
  9072. "Execute an remote-editing action on all marked entries.
  9073. The prefix arg is passed through to the command if possible."
  9074. (interactive "P")
  9075. ;; Make sure we have markers, and only valid ones
  9076. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9077. (mapc
  9078. (lambda (m)
  9079. (unless (and (markerp m)
  9080. (marker-buffer m)
  9081. (buffer-live-p (marker-buffer m))
  9082. (marker-position m))
  9083. (user-error "Marker %s for bulk command is invalid" m)))
  9084. org-agenda-bulk-marked-entries)
  9085. ;; Prompt for the bulk command
  9086. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9087. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9088. "[S]catter [f]unction "
  9089. (when org-agenda-bulk-custom-functions
  9090. (concat " Custom: ["
  9091. (mapconcat (lambda(f) (char-to-string (car f)))
  9092. org-agenda-bulk-custom-functions "")
  9093. "]"))))
  9094. (catch 'exit
  9095. (let* ((action (read-char-exclusive))
  9096. (org-log-refile (if org-log-refile 'time nil))
  9097. (entries (reverse org-agenda-bulk-marked-entries))
  9098. (org-overriding-default-time
  9099. (if (get-text-property (point) 'org-agenda-date-header)
  9100. (org-get-cursor-date)))
  9101. redo-at-end
  9102. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9103. (cond
  9104. ((equal action ?p)
  9105. (let ((org-agenda-persistent-marks
  9106. (not org-agenda-persistent-marks)))
  9107. (org-agenda-bulk-action)
  9108. (throw 'exit nil)))
  9109. ((equal action ?$)
  9110. (setq cmd '(org-agenda-archive)))
  9111. ((equal action ?A)
  9112. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9113. ((member action '(?r ?w))
  9114. (setq rfloc (org-refile-get-location
  9115. "Refile to"
  9116. (marker-buffer (car entries))
  9117. org-refile-allow-creating-parent-nodes))
  9118. (if (nth 3 rfloc)
  9119. (setcar (nthcdr 3 rfloc)
  9120. (move-marker (make-marker) (nth 3 rfloc)
  9121. (or (get-file-buffer (nth 1 rfloc))
  9122. (find-buffer-visiting (nth 1 rfloc))
  9123. (error "This should not happen")))))
  9124. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9125. redo-at-end t))
  9126. ((equal action ?t)
  9127. (setq state (completing-read
  9128. "Todo state: "
  9129. (with-current-buffer (marker-buffer (car entries))
  9130. (mapcar #'list org-todo-keywords-1))))
  9131. (setq cmd `(let ((org-inhibit-blocking t)
  9132. (org-inhibit-logging 'note))
  9133. (org-agenda-todo ,state))))
  9134. ((memq action '(?- ?+))
  9135. (setq tag (completing-read
  9136. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9137. (with-current-buffer (marker-buffer (car entries))
  9138. (delq nil
  9139. (mapcar (lambda (x) (and (stringp (car x)) x))
  9140. org-current-tag-alist)))))
  9141. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9142. ((memq action '(?s ?d))
  9143. (let* ((time
  9144. (unless arg
  9145. (org-read-date
  9146. nil nil nil
  9147. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9148. org-overriding-default-time)))
  9149. (c1 (if (eq action ?s) 'org-agenda-schedule
  9150. 'org-agenda-deadline)))
  9151. ;; Make sure to not prompt for a note when bulk
  9152. ;; rescheduling as Org cannot cope with simultaneous Org.
  9153. ;; Besides, it could be annoying depending on the number
  9154. ;; of items re-scheduled.
  9155. (setq cmd `(eval '(let ((org-log-reschedule
  9156. (and org-log-reschedule 'time)))
  9157. (,c1 arg ,time))))))
  9158. ((equal action ?S)
  9159. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9160. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9161. (let ((days (read-number
  9162. (format "Scatter tasks across how many %sdays: "
  9163. (if arg "week" "")) 7)))
  9164. (setq cmd
  9165. `(let ((distance (1+ (random ,days))))
  9166. (if arg
  9167. (let ((dist distance)
  9168. (day-of-week
  9169. (calendar-day-of-week
  9170. (calendar-gregorian-from-absolute (org-today)))))
  9171. (dotimes (i (1+ dist))
  9172. (while (member day-of-week org-agenda-weekend-days)
  9173. (cl-incf distance)
  9174. (cl-incf day-of-week)
  9175. (when (= day-of-week 7)
  9176. (setq day-of-week 0)))
  9177. (cl-incf day-of-week)
  9178. (when (= day-of-week 7)
  9179. (setq day-of-week 0)))))
  9180. ;; silently fail when try to replan a sexp entry
  9181. (condition-case nil
  9182. (let* ((date (calendar-gregorian-from-absolute
  9183. (+ (org-today) distance)))
  9184. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9185. (nth 2 date))))
  9186. (org-agenda-schedule nil time))
  9187. (error nil)))))))
  9188. ((assoc action org-agenda-bulk-custom-functions)
  9189. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9190. redo-at-end t))
  9191. ((equal action ?f)
  9192. (setq cmd (list (intern
  9193. (completing-read "Function: "
  9194. obarray 'fboundp t nil nil)))))
  9195. (t (user-error "Invalid bulk action")))
  9196. ;; Sort the markers, to make sure that parents are handled before children
  9197. (setq entries (sort entries
  9198. (lambda (a b)
  9199. (cond
  9200. ((equal (marker-buffer a) (marker-buffer b))
  9201. (< (marker-position a) (marker-position b)))
  9202. (t
  9203. (string< (buffer-name (marker-buffer a))
  9204. (buffer-name (marker-buffer b))))))))
  9205. ;; Now loop over all markers and apply cmd
  9206. (while (setq e (pop entries))
  9207. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9208. (if (not pos)
  9209. (progn (message "Skipping removed entry at %s" e)
  9210. (setq cntskip (1+ cntskip)))
  9211. (goto-char pos)
  9212. (let (org-loop-over-headlines-in-active-region)
  9213. (eval cmd))
  9214. ;; `post-command-hook' is not run yet. We make sure any
  9215. ;; pending log note is processed.
  9216. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9217. (memq 'org-add-log-note post-command-hook))
  9218. (org-add-log-note))
  9219. (setq cnt (1+ cnt))))
  9220. (when redo-at-end (org-agenda-redo))
  9221. (unless org-agenda-persistent-marks
  9222. (org-agenda-bulk-unmark-all))
  9223. (message "Acted on %d entries%s%s"
  9224. cnt
  9225. (if (= cntskip 0)
  9226. ""
  9227. (format ", skipped %d (disappeared before their turn)"
  9228. cntskip))
  9229. (if (not org-agenda-persistent-marks)
  9230. "" " (kept marked)"))))))
  9231. (defun org-agenda-capture (&optional with-time)
  9232. "Call `org-capture' with the date at point.
  9233. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9234. current HH:MM time."
  9235. (interactive "P")
  9236. (if (not (eq major-mode 'org-agenda-mode))
  9237. (user-error "You cannot do this outside of agenda buffers")
  9238. (let ((org-overriding-default-time
  9239. (org-get-cursor-date (equal with-time 1))))
  9240. (call-interactively 'org-capture))))
  9241. ;;; Dragging agenda lines forward/backward
  9242. (defun org-agenda-reapply-filters ()
  9243. "Re-apply all agenda filters."
  9244. (mapcar
  9245. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9246. `((,org-agenda-tag-filter tag)
  9247. (,org-agenda-category-filter category)
  9248. (,org-agenda-regexp-filter regexp)
  9249. (,org-agenda-effort-filter effort)
  9250. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9251. (,(get 'org-agenda-category-filter :preset-filter) category)
  9252. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9253. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9254. (defun org-agenda-drag-line-forward (arg &optional backward)
  9255. "Drag an agenda line forward by ARG lines.
  9256. When the optional argument `backward' is non-nil, move backward."
  9257. (interactive "p")
  9258. (let ((inhibit-read-only t) lst line)
  9259. (if (or (not (get-text-property (point) 'txt))
  9260. (save-excursion
  9261. (dotimes (n arg)
  9262. (move-beginning-of-line (if backward 0 2))
  9263. (push (not (get-text-property (point) 'txt)) lst))
  9264. (delq nil lst)))
  9265. (message "Cannot move line forward")
  9266. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9267. (move-beginning-of-line 1)
  9268. (setq line (buffer-substring (point) end))
  9269. (delete-region (point) end)
  9270. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9271. (insert line)
  9272. (org-agenda-reapply-filters)
  9273. (org-agenda-mark-clocking-task)
  9274. (move-beginning-of-line 0)))))
  9275. (defun org-agenda-drag-line-backward (arg)
  9276. "Drag an agenda line backward by ARG lines."
  9277. (interactive "p")
  9278. (org-agenda-drag-line-forward arg t))
  9279. ;;; Flagging notes
  9280. (defun org-agenda-show-the-flagging-note ()
  9281. "Display the flagging note in the other window.
  9282. When called a second time in direct sequence, offer to remove the FLAGGING
  9283. tag and (if present) the flagging note."
  9284. (interactive)
  9285. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9286. (win (selected-window))
  9287. note heading newhead)
  9288. (unless hdmarker
  9289. (user-error "No linked entry at point"))
  9290. (if (and (eq this-command last-command)
  9291. (y-or-n-p "Unflag and remove any flagging note? "))
  9292. (progn
  9293. (org-agenda-remove-flag hdmarker)
  9294. (let ((win (get-buffer-window "*Flagging Note*")))
  9295. (and win (delete-window win)))
  9296. (message "Entry unflagged"))
  9297. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9298. (unless note
  9299. (user-error "No flagging note"))
  9300. (org-kill-new note)
  9301. (org-switch-to-buffer-other-window "*Flagging Note*")
  9302. (erase-buffer)
  9303. (insert note)
  9304. (goto-char (point-min))
  9305. (while (re-search-forward "\\\\n" nil t)
  9306. (replace-match "\n" t t))
  9307. (goto-char (point-min))
  9308. (select-window win)
  9309. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9310. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9311. tag and note")))))
  9312. (defun org-agenda-remove-flag (marker)
  9313. "Remove the FLAGGED tag and any flagging note in the entry."
  9314. (let (newhead)
  9315. (org-with-point-at marker
  9316. (org-toggle-tag "FLAGGED" 'off)
  9317. (org-entry-delete nil "THEFLAGGINGNOTE")
  9318. (setq newhead (org-get-heading)))
  9319. (org-agenda-change-all-lines newhead marker)
  9320. (message "Entry unflagged")))
  9321. (defun org-agenda-get-any-marker (&optional pos)
  9322. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9323. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9324. ;;; Appointment reminders
  9325. (defvar appt-time-msg-list) ; defined in appt.el
  9326. ;;;###autoload
  9327. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9328. "Activate appointments found in `org-agenda-files'.
  9329. With a `\\[universal-argument]' prefix, refresh the list of \
  9330. appointments.
  9331. If FILTER is t, interactively prompt the user for a regular
  9332. expression, and filter out entries that don't match it.
  9333. If FILTER is a string, use this string as a regular expression
  9334. for filtering entries out.
  9335. If FILTER is a function, filter out entries against which
  9336. calling the function returns nil. This function takes one
  9337. argument: an entry from `org-agenda-get-day-entries'.
  9338. FILTER can also be an alist with the car of each cell being
  9339. either `headline' or `category'. For example:
  9340. \\='((headline \"IMPORTANT\")
  9341. (category \"Work\"))
  9342. will only add headlines containing IMPORTANT or headlines
  9343. belonging to the \"Work\" category.
  9344. ARGS are symbols indicating what kind of entries to consider.
  9345. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9346. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9347. and :timestamp entries. See the docstring of `org-diary' for
  9348. details and examples.
  9349. If an entry has a APPT_WARNTIME property, its value will be used
  9350. to override `appt-message-warning-time'."
  9351. (interactive "P")
  9352. (if refresh (setq appt-time-msg-list nil))
  9353. (if (eq filter t)
  9354. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9355. (let* ((cnt 0) ; count added events
  9356. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9357. (org-agenda-new-buffers nil)
  9358. (org-deadline-warning-days 0)
  9359. ;; Do not use `org-today' here because appt only takes
  9360. ;; time and without date as argument, so it may pass wrong
  9361. ;; information otherwise
  9362. (today (org-date-to-gregorian
  9363. (time-to-days (current-time))))
  9364. (org-agenda-restrict nil)
  9365. (files (org-agenda-files 'unrestricted)) entries file
  9366. (org-agenda-buffer nil))
  9367. ;; Get all entries which may contain an appt
  9368. (org-agenda-prepare-buffers files)
  9369. (while (setq file (pop files))
  9370. (setq entries
  9371. (delq nil
  9372. (append entries
  9373. (apply 'org-agenda-get-day-entries
  9374. file today scope)))))
  9375. ;; Map thru entries and find if we should filter them out
  9376. (mapc
  9377. (lambda (x)
  9378. (let* ((evt (org-trim
  9379. (replace-regexp-in-string
  9380. org-bracket-link-regexp "\\3"
  9381. (or (get-text-property 1 'txt x) ""))))
  9382. (cat (get-text-property (1- (length x)) 'org-category x))
  9383. (tod (get-text-property 1 'time-of-day x))
  9384. (ok (or (null filter)
  9385. (and (stringp filter) (string-match filter evt))
  9386. (and (functionp filter) (funcall filter x))
  9387. (and (listp filter)
  9388. (let ((cat-filter (cadr (assq 'category filter)))
  9389. (evt-filter (cadr (assq 'headline filter))))
  9390. (or (and (stringp cat-filter)
  9391. (string-match cat-filter cat))
  9392. (and (stringp evt-filter)
  9393. (string-match evt-filter evt)))))))
  9394. (wrn (get-text-property 1 'warntime x)))
  9395. ;; FIXME: Shall we remove text-properties for the appt text?
  9396. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9397. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9398. (setq tod (concat "00" (number-to-string tod)))
  9399. (setq tod (when (string-match
  9400. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9401. (concat (match-string 1 tod) ":"
  9402. (match-string 2 tod))))
  9403. (when (if (version< emacs-version "23.3")
  9404. (appt-add tod evt)
  9405. (appt-add tod evt wrn))
  9406. (setq cnt (1+ cnt))))))
  9407. entries)
  9408. (org-release-buffers org-agenda-new-buffers)
  9409. (if (eq cnt 0)
  9410. (message "No event to add")
  9411. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9412. (defun org-agenda-today-p (date)
  9413. "Non nil when DATE means today.
  9414. DATE is either a list of the form (month day year) or a number of
  9415. days as returned by `calendar-absolute-from-gregorian' or
  9416. `org-today'. This function considers `org-extend-today-until'
  9417. when defining today."
  9418. (eq (org-today)
  9419. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9420. (defun org-agenda-todo-yesterday (&optional arg)
  9421. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9422. (interactive "P")
  9423. (let* ((org-use-effective-time t)
  9424. (hour (nth 2 (decode-time (org-current-time))))
  9425. (org-extend-today-until (1+ hour)))
  9426. (org-agenda-todo arg)))
  9427. (provide 'org-agenda)
  9428. ;;; org-agenda.el ends here