org-agenda.el 444 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: https://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 <https://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 'ol)
  43. (require 'org-fold-core)
  44. (require 'org)
  45. (require 'org-macs)
  46. (require 'org-refile)
  47. (declare-function diary-add-to-list "diary-lib"
  48. (date string specifier &optional marker globcolor literal))
  49. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  50. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  51. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  52. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  53. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  55. (declare-function calendar-french-date-string "cal-french" (&optional date))
  56. (declare-function calendar-goto-date "cal-move" (date))
  57. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  58. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  59. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  60. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  61. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  62. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  63. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  64. (declare-function calendar-check-holidays "holidays" (date))
  65. (declare-function org-columns-remove-overlays "org-colview" ())
  66. (declare-function org-datetree-find-date-create "org-datetree"
  67. (date &optional keep-restriction))
  68. (declare-function org-columns-quit "org-colview" ())
  69. (declare-function diary-date-display-form "diary-lib" (&optional type))
  70. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  71. (declare-function org-element-property "org-element" (property element))
  72. (declare-function org-element--cache-active-p "org-element"
  73. (&optional called-from-cache-change-func-p))
  74. (declare-function org-habit-insert-consistency-graphs
  75. "org-habit" (&optional line))
  76. (declare-function org-is-habit-p "org-habit" (&optional pom))
  77. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  78. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  79. (declare-function org-agenda-columns "org-colview" ())
  80. (declare-function org-add-archive-files "org-archive" (files))
  81. (declare-function org-capture "org-capture" (&optional goto keys))
  82. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  83. (declare-function org-element-type "org-element" (&optional element))
  84. (defvar calendar-mode-map)
  85. (defvar org-clock-current-task)
  86. (defvar org-current-tag-alist)
  87. (defvar org-mobile-force-id-on-agenda-items)
  88. (defvar org-habit-show-habits)
  89. (defvar org-habit-show-habits-only-for-today)
  90. (defvar org-habit-show-all-today)
  91. (defvar org-habit-scheduled-past-days)
  92. ;; Defined somewhere in this file, but used before definition.
  93. (defvar org-agenda-buffer-name "*Org Agenda*")
  94. (defvar org-agenda-title-append nil)
  95. (defvar org-agenda-overriding-header)
  96. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  97. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  98. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  99. (defvar org-agenda-undo-list nil
  100. "List of undoable operations in the agenda since last refresh.")
  101. (defvar org-agenda-pending-undo-list nil
  102. "In a series of undo commands, this is the list of remaining undo items.")
  103. (defcustom org-agenda-confirm-kill 1
  104. "When set, remote killing from the agenda buffer needs confirmation.
  105. When t, a confirmation is always needed. When a number N, confirmation is
  106. only needed when the text to be killed contains more than N non-white lines."
  107. :group 'org-agenda
  108. :type '(choice
  109. (const :tag "Never" nil)
  110. (const :tag "Always" t)
  111. (integer :tag "When more than N lines")))
  112. (defcustom org-agenda-compact-blocks nil
  113. "Non-nil means make the block agenda more compact.
  114. This is done globally by leaving out lines like the agenda span
  115. name and week number or the separator lines."
  116. :group 'org-agenda
  117. :type 'boolean)
  118. (defcustom org-agenda-block-separator ?=
  119. "The separator between blocks in the agenda.
  120. If this is a string, it will be used as the separator, with a newline added.
  121. If it is a character, it will be repeated to fill the window width.
  122. If nil the separator is disabled. In `org-agenda-custom-commands' this
  123. addresses the separator between the current and the previous block."
  124. :group 'org-agenda
  125. :type '(choice
  126. (const :tag "Disabled" nil)
  127. (character)
  128. (string)))
  129. (defgroup org-agenda-export nil
  130. "Options concerning exporting agenda views in Org mode."
  131. :tag "Org Agenda Export"
  132. :group 'org-agenda)
  133. (defcustom org-agenda-with-colors t
  134. "Non-nil means use colors in agenda views."
  135. :group 'org-agenda-export
  136. :type 'boolean)
  137. (defcustom org-agenda-exporter-settings nil
  138. ;; FIXME: Do we really want to evaluate those settings and thus force
  139. ;; the user to use `quote' all the time?
  140. "Alist of variable/value pairs that should be active during agenda export.
  141. This is a good place to set options for ps-print and for htmlize.
  142. Note that the way this is implemented, the values will be evaluated
  143. before assigned to the variables. So make sure to quote values you do
  144. *not* want evaluated, for example
  145. (setq org-agenda-exporter-settings
  146. \\='((ps-print-color-p \\='black-white)))"
  147. :group 'org-agenda-export
  148. :type '(repeat
  149. (list
  150. (variable)
  151. (sexp :tag "Value"))))
  152. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  153. "Hook run in a temporary buffer before writing the agenda to an export file.
  154. A useful function for this hook is `org-agenda-add-entry-text'."
  155. :group 'org-agenda-export
  156. :type 'hook
  157. :options '(org-agenda-add-entry-text))
  158. (defcustom org-agenda-add-entry-text-maxlines 0
  159. "Maximum number of entry text lines to be added to agenda.
  160. This is only relevant when `org-agenda-add-entry-text' is part of
  161. `org-agenda-before-write-hook', which is the default.
  162. When this is 0, nothing will happen. When it is greater than 0, it
  163. specifies the maximum number of lines that will be added for each entry
  164. that is listed in the agenda view.
  165. Note that this variable is not used during display, only when exporting
  166. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  167. and `org-agenda-entry-text-maxlines'."
  168. :group 'org-agenda
  169. :type 'integer)
  170. (defcustom org-agenda-add-entry-text-descriptive-links t
  171. "Non-nil means export org-links as descriptive links in agenda added text.
  172. This variable applies to the text added to the agenda when
  173. `org-agenda-add-entry-text-maxlines' is larger than 0.
  174. When this variable is nil, the URL will (also) be shown."
  175. :group 'org-agenda
  176. :type 'boolean)
  177. (defcustom org-agenda-export-html-style nil
  178. "The style specification for exported HTML Agenda files.
  179. If this variable contains a string, it will replace the default <style>
  180. section as produced by `htmlize'.
  181. Since there are different ways of setting style information, this variable
  182. needs to contain the full HTML structure to provide a style, including the
  183. surrounding HTML tags. The style specifications should include definitions
  184. the fonts used by the agenda, here is an example:
  185. <style type=\"text/css\">
  186. p { font-weight: normal; color: gray; }
  187. .org-agenda-structure {
  188. font-size: 110%;
  189. color: #003399;
  190. font-weight: 600;
  191. }
  192. .org-todo {
  193. color: #cc6666;
  194. font-weight: bold;
  195. }
  196. .org-agenda-done {
  197. color: #339933;
  198. }
  199. .org-done {
  200. color: #339933;
  201. }
  202. .title { text-align: center; }
  203. .todo, .deadline { color: red; }
  204. .done { color: green; }
  205. </style>
  206. or, if you want to keep the style in a file,
  207. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  208. As the value of this option simply gets inserted into the HTML <head> header,
  209. you can \"misuse\" it to also add other text to the header."
  210. :group 'org-agenda-export
  211. :group 'org-export-html
  212. :type '(choice
  213. (const nil)
  214. (string)))
  215. (defcustom org-agenda-persistent-filter nil
  216. "When set, keep filters from one agenda view to the next."
  217. :group 'org-agenda
  218. :type 'boolean)
  219. (defgroup org-agenda-custom-commands nil
  220. "Options concerning agenda views in Org mode."
  221. :tag "Org Agenda Custom Commands"
  222. :group 'org-agenda)
  223. (defconst org-sorting-choice
  224. '(choice
  225. (const time-up) (const time-down)
  226. (const timestamp-up) (const timestamp-down)
  227. (const scheduled-up) (const scheduled-down)
  228. (const deadline-up) (const deadline-down)
  229. (const ts-up) (const ts-down)
  230. (const tsia-up) (const tsia-down)
  231. (const category-keep) (const category-up) (const category-down)
  232. (const tag-down) (const tag-up)
  233. (const priority-up) (const priority-down)
  234. (const todo-state-up) (const todo-state-down)
  235. (const effort-up) (const effort-down)
  236. (const habit-up) (const habit-down)
  237. (const alpha-up) (const alpha-down)
  238. (const user-defined-up) (const user-defined-down))
  239. "Sorting choices.")
  240. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  241. ;; the new variable `org-agenda-tag-filter-preset'.
  242. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  243. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  244. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  245. "List of types searched for when creating the daily/weekly agenda.
  246. This variable is a list of symbols that controls the types of
  247. items that appear in the daily/weekly agenda. Allowed symbols in this
  248. list are
  249. :timestamp List items containing a date stamp or date range matching
  250. the selected date. This includes sexp entries in angular
  251. brackets.
  252. :sexp List entries resulting from plain diary-like sexps.
  253. :deadline List deadline due on that date. When the date is today,
  254. also list any deadlines past due, or due within
  255. `org-deadline-warning-days'.
  256. :deadline* Same as above, but only include the deadline if it has an
  257. hour specification as [h]h:mm.
  258. :scheduled List all items which are scheduled for the given date.
  259. The diary for *today* also contains items which were
  260. scheduled earlier and are not yet marked DONE.
  261. :scheduled* Same as above, but only include the scheduled item if it
  262. has an hour specification as [h]h:mm.
  263. By default, all four non-starred types are turned on.
  264. When :scheduled* or :deadline* are included, :schedule or :deadline
  265. will be ignored.
  266. Never set this variable globally using `setq', because then it
  267. will apply to all future agenda commands. Instead, bind it with
  268. `let' to scope it dynamically into the agenda-constructing
  269. command. A good way to set it is through options in
  270. `org-agenda-custom-commands'. For a more flexible (though
  271. somewhat less efficient) way of determining what is included in
  272. the daily/weekly agenda, see `org-agenda-skip-function'.")
  273. (defconst org-agenda-custom-commands-local-options
  274. `(repeat :tag "Local settings for this command. Remember to quote values"
  275. (choice :tag "Setting"
  276. (list :tag "Heading for this block"
  277. (const org-agenda-overriding-header)
  278. (string :tag "Headline"))
  279. (list :tag "Files to be searched"
  280. (const org-agenda-files)
  281. (list
  282. (const :format "" quote)
  283. (repeat (file))))
  284. (list :tag "Sorting strategy"
  285. (const org-agenda-sorting-strategy)
  286. (list
  287. (const :format "" quote)
  288. (repeat
  289. ,org-sorting-choice)))
  290. (list :tag "Prefix format"
  291. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  292. (string))
  293. (list :tag "Number of days in agenda"
  294. (const org-agenda-span)
  295. (list
  296. (const :format "" quote)
  297. (choice (const :tag "Day" day)
  298. (const :tag "Week" week)
  299. (const :tag "Fortnight" fortnight)
  300. (const :tag "Month" month)
  301. (const :tag "Year" year)
  302. (integer :tag "Custom"))))
  303. (list :tag "Fixed starting date"
  304. (const org-agenda-start-day)
  305. (string :value "2007-11-01"))
  306. (list :tag "Start on day of week"
  307. (const org-agenda-start-on-weekday)
  308. (choice :value 1
  309. (const :tag "Today" nil)
  310. (integer :tag "Weekday No.")))
  311. (list :tag "Include data from diary"
  312. (const org-agenda-include-diary)
  313. (boolean))
  314. (list :tag "Deadline Warning days"
  315. (const org-deadline-warning-days)
  316. (integer :value 1))
  317. (list :tag "Category filter preset"
  318. (const org-agenda-category-filter-preset)
  319. (list
  320. (const :format "" quote)
  321. (repeat
  322. (string :tag "+category or -category"))))
  323. (list :tag "Tags filter preset"
  324. (const org-agenda-tag-filter-preset)
  325. (list
  326. (const :format "" quote)
  327. (repeat
  328. (string :tag "+tag or -tag"))))
  329. (list :tag "Effort filter preset"
  330. (const org-agenda-effort-filter-preset)
  331. (list
  332. (const :format "" quote)
  333. (repeat
  334. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  335. (list :tag "Regexp filter preset"
  336. (const org-agenda-regexp-filter-preset)
  337. (list
  338. (const :format "" quote)
  339. (repeat
  340. (string :tag "+regexp or -regexp"))))
  341. (list :tag "Set daily/weekly entry types"
  342. (const org-agenda-entry-types)
  343. (list
  344. (const :format "" quote)
  345. (set :greedy t :value ,org-agenda-entry-types
  346. (const :deadline)
  347. (const :scheduled)
  348. (const :deadline*)
  349. (const :scheduled*)
  350. (const :timestamp)
  351. (const :sexp))))
  352. (list :tag "Columns format"
  353. (const org-overriding-columns-format)
  354. (string :tag "Format"))
  355. (list :tag "Standard skipping condition"
  356. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  357. (const org-agenda-skip-function)
  358. (list
  359. (const :format "" quote)
  360. (list
  361. (choice
  362. :tag "Skipping range"
  363. (const :tag "Skip entry" org-agenda-skip-entry-if)
  364. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  365. (repeat :inline t :tag "Conditions for skipping"
  366. (choice
  367. :tag "Condition type"
  368. (list :tag "Regexp matches" :inline t
  369. (const :format "" regexp)
  370. (regexp))
  371. (list :tag "Regexp does not match" :inline t
  372. (const :format "" notregexp)
  373. (regexp))
  374. (list :tag "TODO state is" :inline t
  375. (const todo)
  376. (choice
  377. (const :tag "Any not-done state" todo)
  378. (const :tag "Any done state" done)
  379. (const :tag "Any state" any)
  380. (list :tag "Keyword list"
  381. (const :format "" quote)
  382. (repeat (string :tag "Keyword")))))
  383. (list :tag "TODO state is not" :inline t
  384. (const nottodo)
  385. (choice
  386. (const :tag "Any not-done state" todo)
  387. (const :tag "Any done state" done)
  388. (const :tag "Any state" any)
  389. (list :tag "Keyword list"
  390. (const :format "" quote)
  391. (repeat (string :tag "Keyword")))))
  392. (const :tag "scheduled" scheduled)
  393. (const :tag "not scheduled" notscheduled)
  394. (const :tag "deadline" deadline)
  395. (const :tag "no deadline" notdeadline)
  396. (const :tag "timestamp" timestamp)
  397. (const :tag "no timestamp" nottimestamp))))))
  398. (list :tag "Non-standard skipping condition"
  399. :value (org-agenda-skip-function)
  400. (const org-agenda-skip-function)
  401. (sexp :tag "Function or form (quoted!)"))
  402. (list :tag "Any variable"
  403. (variable :tag "Variable")
  404. (sexp :tag "Value (sexp)"))))
  405. "Selection of examples for agenda command settings.
  406. This will be spliced into the custom type of
  407. `org-agenda-custom-commands'.")
  408. (defcustom org-agenda-custom-commands
  409. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  410. "Custom commands for the agenda.
  411. \\<org-mode-map>
  412. These commands will be offered on the splash screen displayed by the
  413. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  414. (key desc type match settings files)
  415. key The key (one or more characters as a string) to be associated
  416. with the command.
  417. desc A description of the command, when omitted or nil, a default
  418. description is built using MATCH.
  419. type The command type, any of the following symbols:
  420. agenda The daily/weekly agenda.
  421. todo Entries with a specific TODO keyword, in all agenda files.
  422. search Entries containing search words entry or headline.
  423. tags Tags/Property/TODO match in all agenda files.
  424. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  425. todo-tree Sparse tree of specific TODO keyword in *current* file.
  426. tags-tree Sparse tree with all tags matches in *current* file.
  427. occur-tree Occur sparse tree for *current* file.
  428. ... A user-defined function.
  429. match What to search for:
  430. - a single keyword for TODO keyword searches
  431. - a tags/property/todo match expression for searches
  432. - a word search expression for text searches.
  433. - a regular expression for occur searches
  434. For all other commands, this should be the empty string.
  435. settings A list of option settings, similar to that in a let form, so like
  436. this: ((opt1 val1) (opt2 val2) ...). The values will be
  437. evaluated at the moment of execution, so quote them when needed.
  438. files A list of files to write the produced agenda buffer to with
  439. the command `org-store-agenda-views'.
  440. If a file name ends in \".html\", an HTML version of the buffer
  441. is written out. If it ends in \".ps\", a postscript version is
  442. produced. Otherwise, only the plain text is written to the file.
  443. You can also define a set of commands, to create a composite agenda buffer.
  444. In this case, an entry looks like this:
  445. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  446. where
  447. desc A description string to be displayed in the dispatcher menu.
  448. cmd An agenda command, similar to the above. However, tree commands
  449. are not allowed, but instead you can get agenda and global todo list.
  450. So valid commands for a set are:
  451. (agenda \"\" settings)
  452. (alltodo \"\" settings)
  453. (stuck \"\" settings)
  454. (todo \"match\" settings files)
  455. (search \"match\" settings files)
  456. (tags \"match\" settings files)
  457. (tags-todo \"match\" settings files)
  458. Each command can carry a list of options, and another set of options can be
  459. given for the whole set of commands. Individual command options take
  460. precedence over the general options.
  461. When using several characters as key to a command, the first characters
  462. are prefix commands. For the dispatcher to display useful information, you
  463. should provide a description for the prefix, like
  464. (setq org-agenda-custom-commands
  465. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  466. (\"hl\" tags \"+HOME+Lisa\")
  467. (\"hp\" tags \"+HOME+Peter\")
  468. (\"hk\" tags \"+HOME+Kim\")))"
  469. :group 'org-agenda-custom-commands
  470. :type `(repeat
  471. (choice :value ("x" "Describe command here" tags "" nil)
  472. (list :tag "Single command"
  473. (string :tag "Access Key(s) ")
  474. (option (string :tag "Description"))
  475. (choice
  476. (const :tag "Agenda" agenda)
  477. (const :tag "TODO list" alltodo)
  478. (const :tag "Search words" search)
  479. (const :tag "Stuck projects" stuck)
  480. (const :tag "Tags/Property match (all agenda files)" tags)
  481. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  482. (const :tag "TODO keyword search (all agenda files)" todo)
  483. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  484. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  485. (const :tag "Occur tree (current buffer)" occur-tree)
  486. (sexp :tag "Other, user-defined function"))
  487. (string :tag "Match (only for some commands)")
  488. ,org-agenda-custom-commands-local-options
  489. (option (repeat :tag "Export" (file :tag "Export to"))))
  490. (list :tag "Command series, all agenda files"
  491. (string :tag "Access Key(s)")
  492. (string :tag "Description ")
  493. (repeat :tag "Component"
  494. (choice
  495. (list :tag "Agenda"
  496. (const :format "" agenda)
  497. (const :tag "" :format "" "")
  498. ,org-agenda-custom-commands-local-options)
  499. (list :tag "TODO list (all keywords)"
  500. (const :format "" alltodo)
  501. (const :tag "" :format "" "")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "Search words"
  504. (const :format "" search)
  505. (string :tag "Match")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "Stuck projects"
  508. (const :format "" stuck)
  509. (const :tag "" :format "" "")
  510. ,org-agenda-custom-commands-local-options)
  511. (list :tag "Tags/Property match (all agenda files)"
  512. (const :format "" tags)
  513. (string :tag "Match")
  514. ,org-agenda-custom-commands-local-options)
  515. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  516. (const :format "" tags-todo)
  517. (string :tag "Match")
  518. ,org-agenda-custom-commands-local-options)
  519. (list :tag "TODO keyword search"
  520. (const :format "" todo)
  521. (string :tag "Match")
  522. ,org-agenda-custom-commands-local-options)
  523. (list :tag "Other, user-defined function"
  524. (symbol :tag "function")
  525. (string :tag "Match")
  526. ,org-agenda-custom-commands-local-options)))
  527. (repeat :tag "Settings for entire command set"
  528. (list (variable :tag "Any variable")
  529. (sexp :tag "Value")))
  530. (option (repeat :tag "Export" (file :tag "Export to"))))
  531. (cons :tag "Prefix key documentation"
  532. (string :tag "Access Key(s)")
  533. (string :tag "Description ")))))
  534. (defcustom org-agenda-query-register ?o
  535. "The register holding the current query string.
  536. The purpose of this is that if you construct a query string interactively,
  537. you can then use it to define a custom command."
  538. :group 'org-agenda-custom-commands
  539. :type 'character)
  540. (defcustom org-stuck-projects
  541. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  542. "How to identify stuck projects.
  543. This is a list of four items:
  544. 1. A tags/todo/property matcher string that is used to identify a project.
  545. See the manual for a description of tag and property searches.
  546. The entire tree below a headline matched by this is considered one project.
  547. 2. A list of TODO keywords identifying non-stuck projects.
  548. If the project subtree contains any headline with one of these todo
  549. keywords, the project is considered to be not stuck. If you specify
  550. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  551. 3. A list of tags identifying non-stuck projects.
  552. If the project subtree contains any headline with one of these tags,
  553. the project is considered to be not stuck. If you specify \"*\" as
  554. a tag, any tag will mark the project unstuck. Note that this is about
  555. the explicit presence of a tag somewhere in the subtree, inherited
  556. tags do not count here. If inherited tags make a project not stuck,
  557. use \"-TAG\" in the tags part of the matcher under (1.) above.
  558. 4. An arbitrary regular expression matching non-stuck projects.
  559. If the project turns out to be not stuck, search continues also in the
  560. subtree to see if any of the subtasks have project status.
  561. See also the variable `org-tags-match-list-sublevels' which applies
  562. to projects matched by this search as well.
  563. After defining this variable, you may use `org-agenda-list-stuck-projects'
  564. \(bound to `\\[org-agenda] #') to produce the list."
  565. :group 'org-agenda-custom-commands
  566. :type '(list
  567. (string :tag "Tags/TODO match to identify a project")
  568. (repeat :tag "Projects are *not* stuck if they have an entry with \
  569. TODO keyword any of" (string))
  570. (repeat :tag "Projects are *not* stuck if they have an entry with \
  571. TAG being any of" (string))
  572. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  573. the subtree")))
  574. (defgroup org-agenda-skip nil
  575. "Options concerning skipping parts of agenda files."
  576. :tag "Org Agenda Skip"
  577. :group 'org-agenda)
  578. (defcustom org-agenda-skip-function-global nil
  579. "Function to be called at each match during agenda construction.
  580. If this function returns nil, the current match should not be skipped.
  581. If the function decided to skip an agenda match, is must return the
  582. buffer position from which the search should be continued.
  583. This may also be a Lisp form, which will be evaluated.
  584. This variable will be applied to every agenda match, including
  585. tags/property searches and TODO lists. So try to make the test function
  586. do its checking as efficiently as possible. To implement a skipping
  587. condition just for specific agenda commands, use the variable
  588. `org-agenda-skip-function' which can be set in the options section
  589. of custom agenda commands."
  590. :group 'org-agenda-skip
  591. :type 'sexp)
  592. (defgroup org-agenda-daily/weekly nil
  593. "Options concerning the daily/weekly agenda."
  594. :tag "Org Agenda Daily/Weekly"
  595. :group 'org-agenda)
  596. (defgroup org-agenda-todo-list nil
  597. "Options concerning the global todo list agenda view."
  598. :tag "Org Agenda Todo List"
  599. :group 'org-agenda)
  600. (defgroup org-agenda-match-view nil
  601. "Options concerning the general tags/property/todo match agenda view."
  602. :tag "Org Agenda Match View"
  603. :group 'org-agenda)
  604. (defgroup org-agenda-search-view nil
  605. "Options concerning the search agenda view."
  606. :tag "Org Agenda Search View"
  607. :group 'org-agenda)
  608. (defvar org-agenda-archives-mode nil
  609. "Non-nil means the agenda will include archived items.
  610. If this is the symbol `trees', trees in the selected agenda scope
  611. that are marked with the ARCHIVE tag will be included anyway. When this is
  612. t, also all archive files associated with the current selection of agenda
  613. files will be included.")
  614. (defcustom org-agenda-restriction-lock-highlight-subtree t
  615. "Non-nil means highlight the whole subtree when restriction is active.
  616. Otherwise only highlight the headline. Highlighting the whole subtree is
  617. useful to ensure no edits happen beyond the restricted region."
  618. :group 'org-agenda
  619. :type 'boolean)
  620. (defcustom org-agenda-skip-comment-trees t
  621. "Non-nil means skip trees that start with the COMMENT keyword.
  622. When nil, these trees are also scanned by agenda commands."
  623. :group 'org-agenda-skip
  624. :type 'boolean)
  625. (defcustom org-agenda-todo-list-sublevels t
  626. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  627. When nil, the sublevels of a TODO entry are not checked, resulting in
  628. potentially much shorter TODO lists."
  629. :group 'org-agenda-skip
  630. :group 'org-agenda-todo-list
  631. :type 'boolean)
  632. (defcustom org-agenda-todo-ignore-with-date nil
  633. "Non-nil means don't show entries with a date in the global todo list.
  634. You can use this if you prefer to mark mere appointments with a TODO keyword,
  635. but don't want them to show up in the TODO list.
  636. When this is set, it also covers deadlines and scheduled items, the settings
  637. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  638. will be ignored.
  639. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  640. :group 'org-agenda-skip
  641. :group 'org-agenda-todo-list
  642. :type 'boolean)
  643. (defcustom org-agenda-todo-ignore-timestamp nil
  644. "Non-nil means don't show entries with a timestamp.
  645. This applies when creating the global todo list.
  646. Valid values are:
  647. past Don't show entries for today or in the past.
  648. future Don't show entries with a timestamp in the future.
  649. The idea behind this is that if it has a future
  650. timestamp, you don't want to think about it until the
  651. date.
  652. all Don't show any entries with a timestamp in the global todo list.
  653. The idea behind this is that by setting a timestamp, you
  654. have already \"taken care\" of this item.
  655. This variable can also have an integer as a value. If positive (N),
  656. todos with a timestamp N or more days in the future will be ignored. If
  657. negative (-N), todos with a timestamp N or more days in the past will be
  658. ignored. If 0, todos with a timestamp either today or in the future will
  659. be ignored. For example, a value of -1 will exclude todos with a
  660. timestamp in the past (yesterday or earlier), while a value of 7 will
  661. exclude todos with a timestamp a week or more in the future.
  662. See also `org-agenda-todo-ignore-with-date'.
  663. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  664. to make his option also apply to the tags-todo list."
  665. :group 'org-agenda-skip
  666. :group 'org-agenda-todo-list
  667. :version "24.1"
  668. :type '(choice
  669. (const :tag "Ignore future timestamp todos" future)
  670. (const :tag "Ignore past or present timestamp todos" past)
  671. (const :tag "Ignore all timestamp todos" all)
  672. (const :tag "Show timestamp todos" nil)
  673. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  674. (defcustom org-agenda-todo-ignore-scheduled nil
  675. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  676. This applies when creating the global todo list.
  677. Valid values are:
  678. past Don't show entries scheduled today or in the past.
  679. future Don't show entries scheduled in the future.
  680. The idea behind this is that by scheduling it, you don't want to
  681. think about it until the scheduled date.
  682. all Don't show any scheduled entries in the global todo list.
  683. The idea behind this is that by scheduling it, you have already
  684. \"taken care\" of this item.
  685. t Same as `all', for backward compatibility.
  686. This variable can also have an integer as a value. See
  687. `org-agenda-todo-ignore-timestamp' for more details.
  688. See also `org-agenda-todo-ignore-with-date'.
  689. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  690. to make his option also apply to the tags-todo list."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-todo-list
  693. :type '(choice
  694. (const :tag "Ignore future-scheduled todos" future)
  695. (const :tag "Ignore past- or present-scheduled todos" past)
  696. (const :tag "Ignore all scheduled todos" all)
  697. (const :tag "Ignore all scheduled todos (compatibility)" t)
  698. (const :tag "Show scheduled todos" nil)
  699. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  700. (defcustom org-agenda-todo-ignore-deadlines nil
  701. "Non-nil means ignore some deadline TODO items when making TODO list.
  702. There are different motivations for using different values, please think
  703. carefully when configuring this variable.
  704. This applies when creating the global TODO list.
  705. Valid values are:
  706. near Don't show near deadline entries. A deadline is near when it is
  707. closer than `org-deadline-warning-days' days. The idea behind this
  708. is that such items will appear in the agenda anyway.
  709. far Don't show TODO entries where a deadline has been defined, but
  710. is not going to happen anytime soon. This is useful if you want to use
  711. the TODO list to figure out what to do now.
  712. past Don't show entries with a deadline timestamp for today or in the past.
  713. future Don't show entries with a deadline timestamp in the future, not even
  714. when they become `near' ones. Use it with caution.
  715. all Ignore all TODO entries that do have a deadline.
  716. t Same as `near', for backward compatibility.
  717. This variable can also have an integer as a value. See
  718. `org-agenda-todo-ignore-timestamp' for more details.
  719. See also `org-agenda-todo-ignore-with-date'.
  720. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  721. to make his option also apply to the tags-todo list."
  722. :group 'org-agenda-skip
  723. :group 'org-agenda-todo-list
  724. :type '(choice
  725. (const :tag "Ignore near deadlines" near)
  726. (const :tag "Ignore near deadlines (compatibility)" t)
  727. (const :tag "Ignore far deadlines" far)
  728. (const :tag "Ignore all TODOs with a deadlines" all)
  729. (const :tag "Show all TODOs, even if they have a deadline" nil)
  730. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  731. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  732. "Time unit to use when possibly ignoring an agenda item.
  733. See the docstring of various `org-agenda-todo-ignore-*' options.
  734. The default is to compare time stamps using days. An item is thus
  735. considered to be in the future if it is at least one day after today.
  736. Non-nil means to compare time stamps using seconds. An item is then
  737. considered future if it has a time value later than current time."
  738. :group 'org-agenda-skip
  739. :group 'org-agenda-todo-list
  740. :version "24.4"
  741. :package-version '(Org . "8.0")
  742. :type '(choice
  743. (const :tag "Compare time with days" nil)
  744. (const :tag "Compare time with seconds" t)))
  745. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  746. "Non-nil means honor todo-list ignores options also in tags-todo search.
  747. The variables
  748. `org-agenda-todo-ignore-with-date',
  749. `org-agenda-todo-ignore-timestamp',
  750. `org-agenda-todo-ignore-scheduled',
  751. `org-agenda-todo-ignore-deadlines'
  752. make the global TODO list skip entries that have time stamps of certain
  753. kinds. If this option is set, the same options will also apply for the
  754. tags-todo search, which is the general tags/property matcher
  755. restricted to unfinished TODO entries only."
  756. :group 'org-agenda-skip
  757. :group 'org-agenda-todo-list
  758. :group 'org-agenda-match-view
  759. :type 'boolean)
  760. (defcustom org-agenda-skip-scheduled-if-done nil
  761. "Non-nil means don't show scheduled items in agenda when they are done.
  762. This is relevant for the daily/weekly agenda, not for the TODO list. It
  763. applies only to the actual date of the scheduling. Warnings about an item
  764. with a past scheduling dates are always turned off when the item is DONE."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-daily/weekly
  767. :type 'boolean)
  768. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  769. "Non-nil means skip scheduling line if same entry shows because of deadline.
  770. In the agenda of today, an entry can show up multiple times
  771. because it is both scheduled and has a nearby deadline, and maybe
  772. a plain time stamp as well.
  773. When this variable is nil, the entry will be shown several times.
  774. When set to t, then only the deadline is shown and the fact that
  775. the entry is scheduled today or was scheduled previously is not
  776. shown.
  777. When set to the symbol `not-today', skip scheduled previously,
  778. but not scheduled today.
  779. When set to the symbol `repeated-after-deadline', skip scheduled
  780. items if they are repeated beyond the current deadline."
  781. :group 'org-agenda-skip
  782. :group 'org-agenda-daily/weekly
  783. :type '(choice
  784. (const :tag "Never" nil)
  785. (const :tag "Always" t)
  786. (const :tag "Not when scheduled today" not-today)
  787. (const :tag "When repeated past deadline" repeated-after-deadline)))
  788. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  789. "Non-nil means skip timestamp line if same entry shows because of deadline.
  790. In the agenda of today, an entry can show up multiple times
  791. because it has both a plain timestamp and has a nearby deadline.
  792. When this variable is t, then only the deadline is shown and the
  793. fact that the entry has a timestamp for or including today is not
  794. shown. When this variable is nil, the entry will be shown
  795. several times."
  796. :group 'org-agenda-skip
  797. :group 'org-agenda-daily/weekly
  798. :version "24.1"
  799. :type '(choice
  800. (const :tag "Never" nil)
  801. (const :tag "Always" t)))
  802. (defcustom org-agenda-skip-deadline-if-done nil
  803. "Non-nil means don't show deadlines when the corresponding item is done.
  804. When nil, the deadline is still shown and should give you a happy feeling.
  805. This is relevant for the daily/weekly agenda. It applies only to the
  806. actual date of the deadline. Warnings about approaching and past-due
  807. deadlines are always turned off when the item is DONE."
  808. :group 'org-agenda-skip
  809. :group 'org-agenda-daily/weekly
  810. :type 'boolean)
  811. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  812. "Non-nil means skip deadline prewarning when entry is also scheduled.
  813. This will apply on all days where a prewarning for the deadline would
  814. be shown, but not at the day when the entry is actually due. On that day,
  815. the deadline will be shown anyway.
  816. This variable may be set to nil, t, the symbol `pre-scheduled',
  817. or a number which will then give the number of days before the actual
  818. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  819. eliminates the deadline prewarning only prior to the scheduled date.
  820. This can be used in a workflow where the first showing of the deadline will
  821. trigger you to schedule it, and then you don't want to be reminded of it
  822. because you will take care of it on the day when scheduled."
  823. :group 'org-agenda-skip
  824. :group 'org-agenda-daily/weekly
  825. :version "24.1"
  826. :type '(choice
  827. (const :tag "Always show prewarning" nil)
  828. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  829. (const :tag "Remove prewarning if entry is scheduled" t)
  830. (integer :tag "Restart prewarning N days before deadline")))
  831. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  832. "Non-nil means skip scheduled delay when entry also has a deadline.
  833. This variable may be set to nil, t, the symbol `post-deadline',
  834. or a number which will then give the number of days after the actual
  835. scheduled date when the delay should expire. The symbol `post-deadline'
  836. eliminates the schedule delay when the date is posterior to the deadline."
  837. :group 'org-agenda-skip
  838. :group 'org-agenda-daily/weekly
  839. :version "24.4"
  840. :package-version '(Org . "8.0")
  841. :type '(choice
  842. (const :tag "Always honor delay" nil)
  843. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  844. (const :tag "Ignore delay if entry has a deadline" t)
  845. (integer :tag "Honor delay up until N days after the scheduled date")))
  846. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  847. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  848. When non-nil, after the search for timestamps has matched once in an
  849. entry, the rest of the entry will not be searched."
  850. :group 'org-agenda-skip
  851. :type 'boolean)
  852. (defcustom org-agenda-skip-timestamp-if-done nil
  853. "Non-nil means don't select item by timestamp or -range if it is DONE."
  854. :group 'org-agenda-skip
  855. :group 'org-agenda-daily/weekly
  856. :type 'boolean)
  857. (defcustom org-agenda-dim-blocked-tasks t
  858. "Non-nil means dim blocked tasks in the agenda display.
  859. This causes some overhead during agenda construction, but if you
  860. have turned on `org-enforce-todo-dependencies',
  861. `org-enforce-todo-checkbox-dependencies', or any other blocking
  862. mechanism, this will create useful feedback in the agenda.
  863. Instead of t, this variable can also have the value `invisible'.
  864. Then blocked tasks will be invisible and only become visible when
  865. they become unblocked. An exemption to this behavior is when a task is
  866. blocked because of unchecked checkboxes below it. Since checkboxes do
  867. not show up in the agenda views, making this task invisible you remove any
  868. trace from agenda views that there is something to do. Therefore, a task
  869. that is blocked because of checkboxes will never be made invisible, it
  870. will only be dimmed."
  871. :group 'org-agenda-daily/weekly
  872. :group 'org-agenda-todo-list
  873. :version "24.3"
  874. :type '(choice
  875. (const :tag "Do not dim" nil)
  876. (const :tag "Dim to a gray face" t)
  877. (const :tag "Make invisible" invisible)))
  878. (defgroup org-agenda-startup nil
  879. "Options concerning initial settings in the Agenda in Org Mode."
  880. :tag "Org Agenda Startup"
  881. :group 'org-agenda)
  882. (defcustom org-agenda-menu-show-matcher t
  883. "Non-nil means show the match string in the agenda dispatcher menu.
  884. When nil, the matcher string is not shown, but is put into the help-echo
  885. property so than moving the mouse over the command shows it.
  886. Setting it to nil is good if matcher strings are very long and/or if
  887. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  888. :group 'org-agenda
  889. :version "24.1"
  890. :type 'boolean)
  891. (defcustom org-agenda-menu-two-columns nil
  892. "Non-nil means, use two columns to show custom commands in the dispatcher.
  893. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  894. to nil."
  895. :group 'org-agenda
  896. :version "24.1"
  897. :type 'boolean)
  898. (defcustom org-agenda-finalize-hook nil
  899. "Hook run just before displaying an agenda buffer.
  900. The buffer is still writable when the hook is called.
  901. You can modify some of the buffer substrings but you should be
  902. extra careful not to modify the text properties of the agenda
  903. headlines as the agenda display heavily relies on them."
  904. :group 'org-agenda-startup
  905. :type 'hook)
  906. (defcustom org-agenda-filter-hook nil
  907. "Hook run just after filtering with `org-agenda-filter'."
  908. :group 'org-agenda-startup
  909. :package-version '(Org . "9.4")
  910. :type 'hook)
  911. (defcustom org-agenda-mouse-1-follows-link nil
  912. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  913. A longer mouse click will still set point. Needs to be set
  914. before org.el is loaded."
  915. :group 'org-agenda-startup
  916. :type 'boolean)
  917. (defcustom org-agenda-start-with-follow-mode nil
  918. "The initial value of follow mode in a newly created agenda window."
  919. :group 'org-agenda-startup
  920. :type 'boolean)
  921. (defcustom org-agenda-follow-indirect nil
  922. "Non-nil means `org-agenda-follow-mode' displays only the
  923. current item's tree, in an indirect buffer."
  924. :group 'org-agenda
  925. :version "24.1"
  926. :type 'boolean)
  927. (defcustom org-agenda-show-outline-path t
  928. "Non-nil means show outline path in echo area after line motion."
  929. :group 'org-agenda-startup
  930. :type 'boolean)
  931. (defcustom org-agenda-start-with-entry-text-mode nil
  932. "The initial value of entry-text-mode in a newly created agenda window."
  933. :group 'org-agenda-startup
  934. :type 'boolean)
  935. (defcustom org-agenda-entry-text-maxlines 5
  936. "Number of text lines to be added when `E' is pressed in the agenda.
  937. Note that this variable only used during agenda display. To add entry text
  938. when exporting the agenda, configure the variable
  939. `org-agenda-add-entry-text-maxlines'."
  940. :group 'org-agenda
  941. :type 'integer)
  942. (defcustom org-agenda-entry-text-exclude-regexps nil
  943. "List of regular expressions to clean up entry text.
  944. The complete matches of all regular expressions in this list will be
  945. removed from entry text before it is shown in the agenda."
  946. :group 'org-agenda
  947. :type '(repeat (regexp)))
  948. (defcustom org-agenda-entry-text-leaders " > "
  949. "Text prepended to the entry text in agenda buffers."
  950. :version "24.4"
  951. :package-version '(Org . "8.0")
  952. :group 'org-agenda
  953. :type 'string)
  954. (defvar org-agenda-entry-text-cleanup-hook nil
  955. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  956. This cleanup is done in a temporary buffer, so the function may inspect and
  957. change the entire buffer.
  958. Some default stuff like drawers and scheduling/deadline dates will already
  959. have been removed when this is called, as will any matches for regular
  960. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  961. (defvar org-agenda-include-inactive-timestamps nil
  962. "Non-nil means include inactive time stamps in agenda.
  963. Dynamically scoped.")
  964. (defgroup org-agenda-windows nil
  965. "Options concerning the windows used by the Agenda in Org Mode."
  966. :tag "Org Agenda Windows"
  967. :group 'org-agenda)
  968. (defcustom org-agenda-window-setup 'reorganize-frame
  969. "How the agenda buffer should be displayed.
  970. Possible values for this option are:
  971. current-window Show agenda in the current window, keeping all other windows.
  972. other-window Use `switch-to-buffer-other-window' to display agenda.
  973. only-window Show agenda, deleting all other windows.
  974. reorganize-frame Show only two windows on the current frame, the current
  975. window and the agenda.
  976. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  977. Also, when exiting the agenda, kill that frame.
  978. other-tab Use `switch-to-buffer-other-tab' to display the
  979. agenda, making use of the `tab-bar-mode' introduced
  980. in Emacs version 27.1. Also, kill that tab when
  981. exiting the agenda view.
  982. See also the variable `org-agenda-restore-windows-after-quit'."
  983. :group 'org-agenda-windows
  984. :type '(choice
  985. (const current-window)
  986. (const other-frame)
  987. (const other-tab)
  988. (const other-window)
  989. (const only-window)
  990. (const reorganize-frame))
  991. :package-version '(Org . "9.4"))
  992. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  993. "The min and max height of the agenda window as a fraction of frame height.
  994. The value of the variable is a cons cell with two numbers between 0 and 1.
  995. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  996. :group 'org-agenda-windows
  997. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  998. (defcustom org-agenda-restore-windows-after-quit nil
  999. "Non-nil means restore window configuration upon exiting agenda.
  1000. Before the window configuration is changed for displaying the
  1001. agenda, the current status is recorded. When the agenda is
  1002. exited with `q' or `x' and this option is set, the old state is
  1003. restored. If `org-agenda-window-setup' is `other-frame' or
  1004. `other-tab', the value of this option will be ignored."
  1005. :group 'org-agenda-windows
  1006. :type 'boolean)
  1007. (defcustom org-agenda-span 'week
  1008. "Number of days to include in overview display.
  1009. Can be day, week, month, year, or any number of days.
  1010. Custom commands can set this variable in the options section."
  1011. :group 'org-agenda-daily/weekly
  1012. :type '(choice (const :tag "Day" day)
  1013. (const :tag "Week" week)
  1014. (const :tag "Fortnight" fortnight)
  1015. (const :tag "Month" month)
  1016. (const :tag "Year" year)
  1017. (integer :tag "Custom")))
  1018. (defcustom org-agenda-start-on-weekday 1
  1019. "Non-nil means start the overview always on the specified weekday.
  1020. 0 denotes Sunday, 1 denotes Monday, etc.
  1021. When nil, always start on the current day.
  1022. Custom commands can set this variable in the options section."
  1023. :group 'org-agenda-daily/weekly
  1024. :type '(choice (const :tag "Today" nil)
  1025. (integer :tag "Weekday No.")))
  1026. (defcustom org-agenda-show-all-dates t
  1027. "Non-nil means `org-agenda' shows every day in the selected range.
  1028. When nil, only the days which actually have entries are shown."
  1029. :group 'org-agenda-daily/weekly
  1030. :type 'boolean)
  1031. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1032. "Format string for displaying dates in the agenda.
  1033. Used by the daily/weekly agenda. This should be a format string
  1034. understood by `format-time-string', or a function returning the
  1035. formatted date as a string. The function must take a single
  1036. argument, a calendar-style date list like (month day year)."
  1037. :group 'org-agenda-daily/weekly
  1038. :type '(choice
  1039. (string :tag "Format string")
  1040. (function :tag "Function")))
  1041. (defun org-agenda-end-of-line ()
  1042. "Go to the end of visible line."
  1043. (interactive)
  1044. (goto-char (line-end-position)))
  1045. (defun org-agenda-format-date-aligned (date)
  1046. "Format a DATE string for display in the daily/weekly agenda.
  1047. This function makes sure that dates are aligned for easy reading."
  1048. (require 'cal-iso)
  1049. (let* ((dayname (calendar-day-name date))
  1050. (day (cadr date))
  1051. (day-of-week (calendar-day-of-week date))
  1052. (month (car date))
  1053. (monthname (calendar-month-name month))
  1054. (year (nth 2 date))
  1055. (iso-week (org-days-to-iso-week
  1056. (calendar-absolute-from-gregorian date)))
  1057. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1058. ;; (1- year))
  1059. ;; ((and (= month 12) (<= iso-week 1))
  1060. ;; (1+ year))
  1061. ;; (t year)))
  1062. (weekstring (if (= day-of-week 1)
  1063. (format " W%02d" iso-week)
  1064. "")))
  1065. (format "%-10s %2d %s %4d%s"
  1066. dayname day monthname year weekstring)))
  1067. (defcustom org-agenda-time-leading-zero nil
  1068. "Non-nil means use leading zero for military times in agenda.
  1069. For example, 9:30am would become 09:30 rather than 9:30."
  1070. :group 'org-agenda-daily/weekly
  1071. :version "24.1"
  1072. :type 'boolean)
  1073. (defcustom org-agenda-timegrid-use-ampm nil
  1074. "When set, show AM/PM style timestamps on the timegrid."
  1075. :group 'org-agenda
  1076. :version "24.1"
  1077. :type 'boolean)
  1078. (defcustom org-agenda-clock-report-header nil
  1079. "Header for org agenda clock report mode"
  1080. :group 'org-agenda
  1081. :type '(choice
  1082. (string :tag "Header")
  1083. (const :tag "No header" nil))
  1084. :safe #'stringp
  1085. :package-version '(Org . "9.6"))
  1086. (defun org-agenda-time-of-day-to-ampm (time)
  1087. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1088. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1089. (minute (substring time -2))
  1090. (ampm "am"))
  1091. (cond
  1092. ((equal hour-number 12)
  1093. (setq ampm "pm"))
  1094. ((> hour-number 12)
  1095. (setq ampm "pm")
  1096. (setq hour-number (- hour-number 12))))
  1097. (concat
  1098. (if org-agenda-time-leading-zero
  1099. (format "%02d" hour-number)
  1100. (format "%02s" (number-to-string hour-number)))
  1101. ":" minute ampm)))
  1102. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1103. "Conditionally convert TIME to AM/PM format.
  1104. This is based on `org-agenda-timegrid-use-ampm'."
  1105. (if org-agenda-timegrid-use-ampm
  1106. (org-agenda-time-of-day-to-ampm time)
  1107. time))
  1108. (defcustom org-agenda-weekend-days '(6 0)
  1109. "Which days are weekend?
  1110. These days get the special face `org-agenda-date-weekend' in the agenda."
  1111. :group 'org-agenda-daily/weekly
  1112. :type '(set :greedy t
  1113. (const :tag "Monday" 1)
  1114. (const :tag "Tuesday" 2)
  1115. (const :tag "Wednesday" 3)
  1116. (const :tag "Thursday" 4)
  1117. (const :tag "Friday" 5)
  1118. (const :tag "Saturday" 6)
  1119. (const :tag "Sunday" 0)))
  1120. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1121. "Non-nil means jump to today when moving a past date forward in time.
  1122. When using S-right in the agenda to move a date forward, and the date
  1123. stamp currently points to the past, the first key press will move it
  1124. to today. When nil, just move one day forward even if the date stays
  1125. in the past."
  1126. :group 'org-agenda-daily/weekly
  1127. :version "24.1"
  1128. :type 'boolean)
  1129. (defcustom org-agenda-diary-file 'diary-file
  1130. "File to which to add new entries with the `i' key in agenda and calendar.
  1131. When this is the symbol `diary-file', the functionality in the Emacs
  1132. calendar will be used to add entries to the `diary-file'. But when this
  1133. points to a file, `org-agenda-diary-entry' will be used instead."
  1134. :group 'org-agenda
  1135. :type '(choice
  1136. (const :tag "The standard Emacs diary file" diary-file)
  1137. (file :tag "Special Org file diary entries")))
  1138. (defcustom org-agenda-include-diary nil
  1139. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1140. Custom commands can set this variable in the options section."
  1141. :group 'org-agenda-daily/weekly
  1142. :type 'boolean)
  1143. (defcustom org-agenda-include-deadlines t
  1144. "If non-nil, include entries within their deadline warning period.
  1145. Custom commands can set this variable in the options section."
  1146. :group 'org-agenda-daily/weekly
  1147. :version "24.1"
  1148. :type 'boolean)
  1149. (defcustom org-agenda-show-future-repeats t
  1150. "Non-nil shows repeated entries in the future part of the agenda.
  1151. When set to the symbol `next' only the first future repeat is shown."
  1152. :group 'org-agenda-daily/weekly
  1153. :type '(choice
  1154. (const :tag "Show all repeated entries" t)
  1155. (const :tag "Show next repeated entry" next)
  1156. (const :tag "Do not show repeated entries" nil))
  1157. :version "26.1"
  1158. :package-version '(Org . "9.1")
  1159. :safe #'symbolp)
  1160. (defcustom org-agenda-prefer-last-repeat nil
  1161. "Non-nil sets date for repeated entries to their last repeat.
  1162. When nil, display SCHEDULED and DEADLINE dates at their base
  1163. date, and in today's agenda, as a reminder. Display plain
  1164. time-stamps, on the other hand, at every repeat date in the past
  1165. in addition to the base date.
  1166. When non-nil, show a repeated entry at its latest repeat date,
  1167. possibly being today even if it wasn't marked as done. This
  1168. setting is useful if you do not always mark repeated entries as
  1169. done and, yet, consider that reaching repeat date starts the task
  1170. anew.
  1171. When set to a list of strings, prefer last repeats only for
  1172. entries with these TODO keywords."
  1173. :group 'org-agenda-daily/weekly
  1174. :type '(choice
  1175. (const :tag "Prefer last repeat" t)
  1176. (const :tag "Prefer base date" nil)
  1177. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1178. (string :tag "TODO keyword")))
  1179. :version "26.1"
  1180. :package-version '(Org . "9.1")
  1181. :safe (lambda (x) (or (booleanp x) (consp x))))
  1182. (defcustom org-scheduled-past-days 10000
  1183. "Number of days to continue listing scheduled items not marked DONE.
  1184. When an item is scheduled on a date, it shows up in the agenda on
  1185. this day and will be listed until it is marked done or for the
  1186. number of days given here."
  1187. :group 'org-agenda-daily/weekly
  1188. :type 'integer
  1189. :safe 'integerp)
  1190. (defcustom org-deadline-past-days 10000
  1191. "Number of days to warn about missed deadlines.
  1192. When an item has deadline on a date, it shows up in the agenda on
  1193. this day and will appear as a reminder until it is marked DONE or
  1194. for the number of days given here."
  1195. :group 'org-agenda-daily/weekly
  1196. :type 'integer
  1197. :version "26.1"
  1198. :package-version '(Org . "9.1")
  1199. :safe 'integerp)
  1200. (defcustom org-agenda-log-mode-items '(closed clock)
  1201. "List of items that should be shown in agenda log mode.
  1202. \\<org-agenda-mode-map>\
  1203. This list may contain the following symbols:
  1204. closed Show entries that have been closed on that day.
  1205. clock Show entries that have received clocked time on that day.
  1206. state Show all logged state changes.
  1207. Note that instead of changing this variable, you can also press \
  1208. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1209. the agenda to display all available LOG items temporarily."
  1210. :group 'org-agenda-daily/weekly
  1211. :type '(set :greedy t (const closed) (const clock) (const state)))
  1212. (defcustom org-agenda-clock-consistency-checks
  1213. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1214. :gap-ok-around ("4:00")
  1215. :default-face ((:background "DarkRed") (:foreground "white"))
  1216. :overlap-face nil :gap-face nil :no-end-time-face nil
  1217. :long-face nil :short-face nil)
  1218. "This is a property list, with the following keys:
  1219. :max-duration Mark clocking chunks that are longer than this time.
  1220. This is a time string like \"HH:MM\", or the number
  1221. of minutes as an integer.
  1222. :min-duration Mark clocking chunks that are shorter that this.
  1223. This is a time string like \"HH:MM\", or the number
  1224. of minutes as an integer.
  1225. :max-gap Mark gaps between clocking chunks that are longer than
  1226. this duration. A number of minutes, or a string
  1227. like \"HH:MM\".
  1228. :gap-ok-around List of times during the day which are usually not working
  1229. times. When a gap is detected, but the gap contains any
  1230. of these times, the gap is *not* reported. For example,
  1231. if this is (\"4:00\" \"13:00\") then gaps that contain
  1232. 4:00 in the morning (i.e. the night) and 13:00
  1233. (i.e. a typical lunch time) do not cause a warning.
  1234. You should have at least one time during the night in this
  1235. list, or otherwise the first task each morning will trigger
  1236. a warning because it follows a long gap.
  1237. Furthermore, the following properties can be used to define faces for
  1238. issue display.
  1239. :default-face the default face, if the specific face is undefined
  1240. :overlap-face face for overlapping clocks
  1241. :gap-face face for gaps between clocks
  1242. :no-end-time-face face for incomplete clocks
  1243. :long-face face for clock intervals that are too long
  1244. :short-face face for clock intervals that are too short"
  1245. :group 'org-agenda-daily/weekly
  1246. :group 'org-clock
  1247. :version "24.1"
  1248. :type 'plist)
  1249. (defcustom org-agenda-log-mode-add-notes t
  1250. "Non-nil means add first line of notes to log entries in agenda views.
  1251. If a log item like a state change or a clock entry is associated with
  1252. notes, the first line of these notes will be added to the entry in the
  1253. agenda display."
  1254. :group 'org-agenda-daily/weekly
  1255. :type 'boolean)
  1256. (defcustom org-agenda-start-with-log-mode nil
  1257. "The initial value of log-mode in a newly created agenda window.
  1258. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1259. explanations on the possible values."
  1260. :group 'org-agenda-startup
  1261. :group 'org-agenda-daily/weekly
  1262. :type '(choice (const :tag "Don't show log items" nil)
  1263. (const :tag "Show only log items" only)
  1264. (const :tag "Show all possible log items" clockcheck)
  1265. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1266. (choice (const :tag "Show closed log items" closed)
  1267. (const :tag "Show clocked log items" clock)
  1268. (const :tag "Show all logged state changes" state)))))
  1269. (defcustom org-agenda-start-with-clockreport-mode nil
  1270. "The initial value of clockreport-mode in a newly created agenda window."
  1271. :group 'org-agenda-startup
  1272. :group 'org-agenda-daily/weekly
  1273. :type 'boolean)
  1274. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1275. "Property list with parameters for the clocktable in clockreport mode.
  1276. This is the display mode that shows a clock table in the daily/weekly
  1277. agenda, the properties for this dynamic block can be set here.
  1278. The usual clocktable parameters are allowed here, but you cannot set
  1279. the properties :name, :tstart, :tend, :block, and :scope - these will
  1280. be overwritten to make sure the content accurately reflects the
  1281. current display in the agenda."
  1282. :group 'org-agenda-daily/weekly
  1283. :type 'plist)
  1284. (defvaralias 'org-agenda-search-view-search-words-only
  1285. 'org-agenda-search-view-always-boolean)
  1286. (defcustom org-agenda-search-view-always-boolean nil
  1287. "Non-nil means the search string is interpreted as individual parts.
  1288. The search string for search view can either be interpreted as a phrase,
  1289. or as a list of snippets that define a boolean search for a number of
  1290. strings.
  1291. When this is non-nil, the string will be split on whitespace, and each
  1292. snippet will be searched individually, and all must match in order to
  1293. select an entry. A snippet is then a single string of non-white
  1294. characters, or a string in double quotes, or a regexp in {} braces.
  1295. If a snippet is preceded by \"-\", the snippet must *not* match.
  1296. \"+\" is syntactic sugar for positive selection. Each snippet may
  1297. be found as a full word or a partial word, but see the variable
  1298. `org-agenda-search-view-force-full-words'.
  1299. When this is nil, search will look for the entire search phrase as one,
  1300. with each space character matching any amount of whitespace, including
  1301. line breaks.
  1302. Even when this is nil, you can still switch to Boolean search dynamically
  1303. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1304. is a regexp marked with braces like \"{abc}\", this will also switch to
  1305. boolean search."
  1306. :group 'org-agenda-search-view
  1307. :version "24.1"
  1308. :type 'boolean)
  1309. (defcustom org-agenda-search-view-force-full-words nil
  1310. "Non-nil means, search words must be matches as complete words.
  1311. When nil, they may also match part of a word."
  1312. :group 'org-agenda-search-view
  1313. :version "24.1"
  1314. :type 'boolean)
  1315. (defcustom org-agenda-search-view-max-outline-level 0
  1316. "Maximum outline level to display in search view.
  1317. E.g. when this is set to 1, the search view will only
  1318. show headlines of level 1. When set to 0, the default
  1319. value, don't limit agenda view by outline level."
  1320. :group 'org-agenda-search-view
  1321. :version "26.1"
  1322. :package-version '(Org . "8.3")
  1323. :type 'integer)
  1324. (defgroup org-agenda-time-grid nil
  1325. "Options concerning the time grid in the Org Agenda."
  1326. :tag "Org Agenda Time Grid"
  1327. :group 'org-agenda)
  1328. (defcustom org-agenda-search-headline-for-time t
  1329. "Non-nil means search headline for a time-of-day.
  1330. If the headline contains a time-of-day in one format or another, it will
  1331. be used to sort the entry into the time sequence of items for a day.
  1332. Some people have time stamps in the headline that refer to the creation
  1333. time or so, and then this produces an unwanted side effect. If this is
  1334. the case for your, use this variable to turn off searching the headline
  1335. for a time."
  1336. :group 'org-agenda-time-grid
  1337. :type 'boolean)
  1338. (defcustom org-agenda-use-time-grid t
  1339. "Non-nil means show a time grid in the agenda schedule.
  1340. A time grid is a set of lines for specific times (like every two hours between
  1341. 8:00 and 20:00). The items scheduled for a day at specific times are
  1342. sorted in between these lines.
  1343. For details about when the grid will be shown, and what it will look like, see
  1344. the variable `org-agenda-time-grid'."
  1345. :group 'org-agenda-time-grid
  1346. :type 'boolean)
  1347. (defcustom org-agenda-time-grid
  1348. '((daily today require-timed)
  1349. (800 1000 1200 1400 1600 1800 2000)
  1350. "......"
  1351. "----------------")
  1352. "The settings for time grid for agenda display.
  1353. This is a list of four items. The first item is again a list. It contains
  1354. symbols specifying conditions when the grid should be displayed:
  1355. daily if the agenda shows a single day
  1356. weekly if the agenda shows an entire week
  1357. today show grid on current date, independent of daily/weekly display
  1358. require-timed show grid only if at least one item has a time specification
  1359. remove-match skip grid times already present in an entry
  1360. The second item is a list of integers, indicating the times that
  1361. should have a grid line.
  1362. The third item is a string which will be placed right after the
  1363. times that have a grid line.
  1364. The fourth item is a string placed after the grid times. This
  1365. will align with agenda items."
  1366. :group 'org-agenda-time-grid
  1367. :type
  1368. '(list
  1369. (set :greedy t :tag "Grid Display Options"
  1370. (const :tag "Show grid in single day agenda display" daily)
  1371. (const :tag "Show grid in weekly agenda display" weekly)
  1372. (const :tag "Always show grid for today" today)
  1373. (const :tag "Show grid only if any timed entries are present"
  1374. require-timed)
  1375. (const :tag "Skip grid times already present in an entry"
  1376. remove-match))
  1377. (repeat :tag "Grid Times" (integer :tag "Time"))
  1378. (string :tag "Grid String (after agenda times)")
  1379. (string :tag "Grid String (aligns with agenda items)")))
  1380. (defcustom org-agenda-show-current-time-in-grid t
  1381. "Non-nil means show the current time in the time grid."
  1382. :group 'org-agenda-time-grid
  1383. :version "24.1"
  1384. :type 'boolean)
  1385. (defcustom org-agenda-current-time-string
  1386. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1387. "The string for the current time marker in the agenda."
  1388. :group 'org-agenda-time-grid
  1389. :version "24.1"
  1390. :type 'string)
  1391. (defgroup org-agenda-sorting nil
  1392. "Options concerning sorting in the Org Agenda."
  1393. :tag "Org Agenda Sorting"
  1394. :group 'org-agenda)
  1395. (defcustom org-agenda-sorting-strategy
  1396. '((agenda habit-down time-up priority-down category-keep)
  1397. (todo priority-down category-keep)
  1398. (tags priority-down category-keep)
  1399. (search category-keep))
  1400. "Sorting structure for the agenda items of a single day.
  1401. This is a list of symbols which will be used in sequence to determine
  1402. if an entry should be listed before another entry. The following
  1403. symbols are recognized:
  1404. time-up Put entries with time-of-day indications first, early first.
  1405. time-down Put entries with time-of-day indications first, late first.
  1406. timestamp-up Sort by any timestamp, early first.
  1407. timestamp-down Sort by any timestamp, late first.
  1408. scheduled-up Sort by scheduled timestamp, early first.
  1409. scheduled-down Sort by scheduled timestamp, late first.
  1410. deadline-up Sort by deadline timestamp, early first.
  1411. deadline-down Sort by deadline timestamp, late first.
  1412. ts-up Sort by active timestamp, early first.
  1413. ts-down Sort by active timestamp, late first.
  1414. tsia-up Sort by inactive timestamp, early first.
  1415. tsia-down Sort by inactive timestamp, late first.
  1416. category-keep Keep the default order of categories, corresponding to the
  1417. sequence in `org-agenda-files'.
  1418. category-up Sort alphabetically by category, A-Z.
  1419. category-down Sort alphabetically by category, Z-A.
  1420. tag-up Sort alphabetically by last tag, A-Z.
  1421. tag-down Sort alphabetically by last tag, Z-A.
  1422. priority-up Sort numerically by priority, high priority last.
  1423. priority-down Sort numerically by priority, high priority first.
  1424. todo-state-up Sort by todo state, tasks that are done last.
  1425. todo-state-down Sort by todo state, tasks that are done first.
  1426. effort-up Sort numerically by estimated effort, high effort last.
  1427. effort-down Sort numerically by estimated effort, high effort first.
  1428. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1429. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1430. habit-up Put entries that are habits first.
  1431. habit-down Put entries that are habits last.
  1432. alpha-up Sort headlines alphabetically.
  1433. alpha-down Sort headlines alphabetically, reversed.
  1434. The different possibilities will be tried in sequence, and testing stops
  1435. if one comparison returns a \"not-equal\". For example, the default
  1436. \\='(time-up category-keep priority-down)
  1437. means: Pull out all entries having a specified time of day and sort them,
  1438. in order to make a time schedule for the current day the first thing in the
  1439. agenda listing for the day. Of the entries without a time indication, keep
  1440. the grouped in categories, don't sort the categories, but keep them in
  1441. the sequence given in `org-agenda-files'. Within each category sort by
  1442. priority.
  1443. Leaving out `category-keep' would mean that items will be sorted across
  1444. categories by priority.
  1445. Instead of a single list, this can also be a set of list for specific
  1446. contents, with a context symbol in the car of the list, any of
  1447. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1448. Custom commands can bind this variable in the options section."
  1449. :group 'org-agenda-sorting
  1450. :type `(choice
  1451. (repeat :tag "General" ,org-sorting-choice)
  1452. (list :tag "Individually"
  1453. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1454. (repeat ,org-sorting-choice))
  1455. (cons (const :tag "Strategy for TODO lists" todo)
  1456. (repeat ,org-sorting-choice))
  1457. (cons (const :tag "Strategy for Tags matches" tags)
  1458. (repeat ,org-sorting-choice))
  1459. (cons (const :tag "Strategy for search matches" search)
  1460. (repeat ,org-sorting-choice)))))
  1461. (defcustom org-agenda-cmp-user-defined nil
  1462. "A function to define the comparison `user-defined'.
  1463. This function must receive two arguments, agenda entry a and b.
  1464. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1465. the user comparison, return nil.
  1466. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1467. part of an agenda sorting strategy."
  1468. :group 'org-agenda-sorting
  1469. :type 'symbol)
  1470. (defcustom org-agenda-sort-notime-is-late t
  1471. "Non-nil means items without time are considered late.
  1472. This is only relevant for sorting. When t, items which have no explicit
  1473. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1474. do have a time. When nil, the default time is before 0:00. You can use this
  1475. option to decide if the schedule for today should come before or after timeless
  1476. agenda entries."
  1477. :group 'org-agenda-sorting
  1478. :type 'boolean)
  1479. (defcustom org-agenda-sort-noeffort-is-high t
  1480. "Non-nil means items without effort estimate are sorted as high effort.
  1481. This also applies when filtering an agenda view with respect to the
  1482. < or > effort operator. Then, tasks with no effort defined will be treated
  1483. as tasks with high effort.
  1484. When nil, such items are sorted as 0 minutes effort."
  1485. :group 'org-agenda-sorting
  1486. :type 'boolean)
  1487. (defgroup org-agenda-line-format nil
  1488. "Options concerning the entry prefix in the Org agenda display."
  1489. :tag "Org Agenda Line Format"
  1490. :group 'org-agenda)
  1491. (defcustom org-agenda-prefix-format
  1492. '((agenda . " %i %-12:c%?-12t% s")
  1493. (todo . " %i %-12:c")
  1494. (tags . " %i %-12:c")
  1495. (search . " %i %-12:c"))
  1496. "Format specifications for the prefix of items in the agenda views.
  1497. An alist with one entry per agenda type. The keys of the
  1498. sublists are `agenda', `todo', `search' and `tags'. The values
  1499. are format strings.
  1500. This format works similar to a printf format, with the following meaning:
  1501. %c the category of the item, \"Diary\" for entries from the diary,
  1502. or as given by the CATEGORY keyword or derived from the file name
  1503. %e the effort required by the item
  1504. %l the level of the item (insert X space(s) if item is of level X)
  1505. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1506. %T the last tag of the item (ignore inherited tags, which come first)
  1507. %t the HH:MM time-of-day specification if one applies to the entry
  1508. %s Scheduling/Deadline information, a short string
  1509. %b show breadcrumbs, i.e., the names of the higher levels
  1510. %(expression) Eval EXPRESSION and replace the control string
  1511. by the result
  1512. All specifiers work basically like the standard `%s' of printf, but may
  1513. contain two additional characters: a question mark just after the `%'
  1514. and a whitespace/punctuation character just before the final letter.
  1515. If the first character after `%' is a question mark, the entire field
  1516. will only be included if the corresponding value applies to the current
  1517. entry. This is useful for fields which should have fixed width when
  1518. present, but zero width when absent. For example, \"%?-12t\" will
  1519. result in a 12 character time field if a time of the day is specified,
  1520. but will completely disappear in entries which do not contain a time.
  1521. If there is punctuation or whitespace character just before the
  1522. final format letter, this character will be appended to the field
  1523. value if the value is not empty. For example, the format
  1524. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1525. the category is empty, no additional colon is inserted.
  1526. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1527. which means:
  1528. - Indent the line with two space characters
  1529. - Give the category a 12 chars wide field, padded with whitespace on
  1530. the right (because of `-'). Append a colon if there is a category
  1531. (because of `:').
  1532. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1533. time, don't put in an empty field, just skip it (because of '?').
  1534. - Finally, put the scheduling information.
  1535. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1536. `org-agenda-remove-tags'.
  1537. Custom commands can set this variable in the options section."
  1538. :type '(choice
  1539. (string :tag "General format")
  1540. (list :greedy t :tag "View dependent"
  1541. (cons (const agenda) (string :tag "Format"))
  1542. (cons (const todo) (string :tag "Format"))
  1543. (cons (const tags) (string :tag "Format"))
  1544. (cons (const search) (string :tag "Format"))))
  1545. :group 'org-agenda-line-format
  1546. :version "26.1"
  1547. :package-version '(Org . "9.1"))
  1548. (defcustom org-agenda-breadcrumbs-separator "->"
  1549. "The separator of breadcrumbs in agenda lines."
  1550. :group 'org-agenda-line-format
  1551. :package-version '(Org . "9.3")
  1552. :type 'string
  1553. :safe #'stringp)
  1554. (defvar org-prefix-format-compiled nil
  1555. "The compiled prefix format and associated variables.
  1556. This is a list where first element is a list of variable bindings, and second
  1557. element is the compiled format expression. See the variable
  1558. `org-agenda-prefix-format'.")
  1559. (defcustom org-agenda-todo-keyword-format "%-1s"
  1560. "Format for the TODO keyword in agenda lines.
  1561. Set this to something like \"%-12s\" if you want all TODO keywords
  1562. to occupy a fixed space in the agenda display."
  1563. :group 'org-agenda-line-format
  1564. :type 'string)
  1565. (defcustom org-agenda-diary-sexp-prefix nil
  1566. "A regexp that matches part of a diary sexp entry
  1567. which should be treated as scheduling/deadline information in
  1568. `org-agenda'.
  1569. For example, you can use this to extract the `diary-remind-message' from
  1570. `diary-remind' entries."
  1571. :group 'org-agenda-line-format
  1572. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1573. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1574. "Text preceding timerange entries in the agenda view.
  1575. This is a list with two strings. The first applies when the range
  1576. is entirely on one day. The second applies if the range spans several days.
  1577. The strings may have two \"%d\" format specifiers which will be filled
  1578. with the sequence number of the days, and the total number of days in the
  1579. range, respectively."
  1580. :group 'org-agenda-line-format
  1581. :type '(list
  1582. (string :tag "Deadline today ")
  1583. (choice :tag "Deadline relative"
  1584. (string :tag "Format string")
  1585. (function))))
  1586. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1587. "Text preceding scheduled items in the agenda view.
  1588. This is a list with two strings. The first applies when the item is
  1589. scheduled on the current day. The second applies when it has been scheduled
  1590. previously, it may contain a %d indicating that this is the nth time that
  1591. this item is scheduled, due to automatic rescheduling of unfinished items
  1592. for the following day. So this number is one larger than the number of days
  1593. that passed since this item was scheduled first."
  1594. :group 'org-agenda-line-format
  1595. :version "24.4"
  1596. :package-version '(Org . "8.0")
  1597. :type '(list
  1598. (string :tag "Scheduled today ")
  1599. (string :tag "Scheduled previously")))
  1600. (defcustom org-agenda-inactive-leader "["
  1601. "Text preceding item pulled into the agenda by inactive time stamps.
  1602. These entries are added to the agenda when pressing \"[\"."
  1603. :group 'org-agenda-line-format
  1604. :version "24.1"
  1605. :type 'string)
  1606. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1607. "Text preceding deadline items in the agenda view.
  1608. This is a list with three strings. The first applies when the item has its
  1609. deadline on the current day. The second applies when the deadline is in the
  1610. future, the third one when it is in the past. The strings may contain %d
  1611. to capture the number of days."
  1612. :group 'org-agenda-line-format
  1613. :version "24.4"
  1614. :package-version '(Org . "8.0")
  1615. :type '(list
  1616. (string :tag "Deadline today ")
  1617. (string :tag "Deadline in the future ")
  1618. (string :tag "Deadline in the past ")))
  1619. (defcustom org-agenda-remove-times-when-in-prefix t
  1620. "Non-nil means remove duplicate time specifications in agenda items.
  1621. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1622. time-of-day specification in a headline or diary entry is extracted and
  1623. placed into the prefix. If this option is non-nil, the original specification
  1624. \(a timestamp or -range, or just a plain time(range) specification like
  1625. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1626. cluttered.
  1627. The option can be t or nil. It may also be the symbol `beg', indicating
  1628. that the time should only be removed when it is located at the beginning of
  1629. the headline/diary entry."
  1630. :group 'org-agenda-line-format
  1631. :type '(choice
  1632. (const :tag "Always" t)
  1633. (const :tag "Never" nil)
  1634. (const :tag "When at beginning of entry" beg)))
  1635. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1636. "Non-nil means remove time ranges specifications in agenda
  1637. items that span on several days."
  1638. :group 'org-agenda-line-format
  1639. :version "24.1"
  1640. :type 'boolean)
  1641. (defcustom org-agenda-default-appointment-duration nil
  1642. "Default duration for appointments that only have a starting time.
  1643. When nil, no duration is specified in such cases.
  1644. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1645. :group 'org-agenda-line-format
  1646. :type '(choice
  1647. (integer :tag "Minutes")
  1648. (const :tag "No default duration")))
  1649. (defcustom org-agenda-show-inherited-tags t
  1650. "Non-nil means show inherited tags in each agenda line.
  1651. When this option is set to `always', it takes precedence over
  1652. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1653. in every agenda.
  1654. When this option is set to t (the default), inherited tags are
  1655. shown when they are available, i.e. when the value of
  1656. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1657. given agenda type.
  1658. This can be set to a list of agenda types in which the agenda
  1659. must display the inherited tags. Available types are `todo',
  1660. `agenda' and `search'.
  1661. When set to nil, never show inherited tags in agenda lines."
  1662. :group 'org-agenda-line-format
  1663. :group 'org-agenda
  1664. :version "24.3"
  1665. :type '(choice
  1666. (const :tag "Show inherited tags when available" t)
  1667. (const :tag "Always show inherited tags" always)
  1668. (repeat :tag "Show inherited tags only in selected agenda types"
  1669. (symbol :tag "Agenda type"))))
  1670. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1671. "List of agenda view types where to use tag inheritance.
  1672. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1673. controlled by `org-use-tag-inheritance'. In other agenda types,
  1674. `org-use-tag-inheritance' is not used for the selection of the
  1675. agenda entries. Still, you may want the agenda to be aware of
  1676. the inherited tags anyway, e.g. for later tag filtering.
  1677. Allowed value are `todo', `search' and `agenda'.
  1678. This variable has no effect if `org-agenda-show-inherited-tags'
  1679. is set to `always'. In that case, the agenda is aware of those
  1680. tags.
  1681. The default value sets tags in every agenda type. Setting this
  1682. option to nil will speed up non-tags agenda view a lot."
  1683. :group 'org-agenda
  1684. :version "26.1"
  1685. :package-version '(Org . "9.1")
  1686. :type '(choice
  1687. (const :tag "Use tag inheritance in all agenda types" t)
  1688. (repeat :tag "Use tag inheritance in selected agenda types"
  1689. (symbol :tag "Agenda type"))))
  1690. (defcustom org-agenda-hide-tags-regexp nil
  1691. "Regular expression used to filter away specific tags in agenda views.
  1692. This means that these tags will be present, but not be shown in the agenda
  1693. line. Secondary filtering will still work on the hidden tags.
  1694. Nil means don't hide any tags."
  1695. :group 'org-agenda-line-format
  1696. :type '(choice
  1697. (const :tag "Hide none" nil)
  1698. (regexp :tag "Regexp ")))
  1699. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1700. 'org-agenda-remove-tags)
  1701. (defcustom org-agenda-remove-tags nil
  1702. "Non-nil means remove the tags from the headline copy in the agenda.
  1703. When this is the symbol `prefix', only remove tags when
  1704. `org-agenda-prefix-format' contains a `%T' specifier."
  1705. :group 'org-agenda-line-format
  1706. :type '(choice
  1707. (const :tag "Always" t)
  1708. (const :tag "Never" nil)
  1709. (const :tag "When prefix format contains %T" prefix)))
  1710. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1711. (defcustom org-agenda-tags-column 'auto
  1712. "Shift tags in agenda items to this column.
  1713. If set to `auto', tags will be automatically aligned to the right
  1714. edge of the window.
  1715. If set to a positive number, tags will be left-aligned to that
  1716. column. If set to a negative number, tags will be right-aligned
  1717. to that column. For example, -80 works well for a normal 80
  1718. character screen."
  1719. :group 'org-agenda-line-format
  1720. :type '(choice
  1721. (const :tag "Automatically align to right edge of window" auto)
  1722. (integer :tag "Specific column" -80))
  1723. :package-version '(Org . "9.1")
  1724. :version "26.1")
  1725. (defcustom org-agenda-fontify-priorities 'cookies
  1726. "Non-nil means highlight low and high priorities in agenda.
  1727. When t, the highest priority entries are bold, lowest priority italic.
  1728. However, settings in `org-priority-faces' will overrule these faces.
  1729. When this variable is the symbol `cookies', only fontify the
  1730. cookies, not the entire task.
  1731. This may also be an association list of priority faces, whose
  1732. keys are the character values of `org-priority-highest',
  1733. `org-priority-default', and `org-priority-lowest' (the default values
  1734. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1735. color as a string, or a list like `(:background \"Red\")'.
  1736. If it is a color, the variable `org-faces-easy-properties'
  1737. determines if it is a foreground or a background color."
  1738. :group 'org-agenda-line-format
  1739. :type '(choice
  1740. (const :tag "Never" nil)
  1741. (const :tag "Defaults" t)
  1742. (const :tag "Cookies only" cookies)
  1743. (repeat :tag "Specify"
  1744. (list (character :tag "Priority" :value ?A)
  1745. (choice :tag "Face "
  1746. (string :tag "Color")
  1747. (sexp :tag "Face"))))))
  1748. (defcustom org-agenda-day-face-function nil
  1749. "Function called to determine what face should be used to display a day.
  1750. The only argument passed to that function is the day. It should
  1751. returns a face, or nil if does not want to specify a face and let
  1752. the normal rules apply."
  1753. :group 'org-agenda-line-format
  1754. :version "24.1"
  1755. :type '(choice (const nil) (function)))
  1756. (defcustom org-agenda-category-icon-alist nil
  1757. "Alist of category icon to be displayed in agenda views.
  1758. Each entry should have the following format:
  1759. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1760. Where CATEGORY-REGEXP is a regexp matching the categories where
  1761. the icon should be displayed.
  1762. FILE-OR-DATA either a file path or a string containing image data.
  1763. The other fields can be omitted safely if not needed:
  1764. TYPE indicates the image type.
  1765. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1766. image data.
  1767. PROPS are additional image attributes to assign to the image,
  1768. like, e.g. `:ascent center'.
  1769. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1770. If you want to set the display properties yourself, just put a
  1771. list as second element:
  1772. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1773. For example, to display a 16px horizontal space for Emacs
  1774. category, you can use:
  1775. (\"Emacs\" \\='(space . (:width (16))))"
  1776. :group 'org-agenda-line-format
  1777. :version "24.1"
  1778. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1779. :value-type (choice (list :tag "Icon"
  1780. (string :tag "File or data")
  1781. (symbol :tag "Type")
  1782. (boolean :tag "Data?")
  1783. (repeat :tag "Extra image properties" :inline t sexp))
  1784. (list :tag "Display properties" sexp))))
  1785. (defgroup org-agenda-column-view nil
  1786. "Options concerning column view in the agenda."
  1787. :tag "Org Agenda Column View"
  1788. :group 'org-agenda)
  1789. (defcustom org-agenda-view-columns-initially nil
  1790. "When non-nil, switch to columns view right after creating the agenda."
  1791. :group 'org-agenda-column-view
  1792. :type 'boolean
  1793. :version "26.1"
  1794. :package-version '(Org . "9.0")
  1795. :safe #'booleanp)
  1796. (defcustom org-agenda-columns-show-summaries t
  1797. "Non-nil means show summaries for columns displayed in the agenda view."
  1798. :group 'org-agenda-column-view
  1799. :type 'boolean)
  1800. (defcustom org-agenda-columns-compute-summary-properties t
  1801. "Non-nil means recompute all summary properties before column view.
  1802. When column view in the agenda is listing properties that have a summary
  1803. operator, it can go to all relevant buffers and recompute the summaries
  1804. there. This can mean overhead for the agenda column view, but is necessary
  1805. to have thing up to date.
  1806. As a special case, a CLOCKSUM property also makes sure that the clock
  1807. computations are current."
  1808. :group 'org-agenda-column-view
  1809. :type 'boolean)
  1810. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1811. "Non-nil means the duration of an appointment will add to day effort.
  1812. The property to which appointment durations will be added is the one given
  1813. in the option `org-effort-property'. If an appointment does not have
  1814. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1815. is not set, an appointment without end time will not contribute to the time
  1816. estimate."
  1817. :group 'org-agenda-column-view
  1818. :type 'boolean)
  1819. (defcustom org-agenda-auto-exclude-function nil
  1820. "A function called with a tag to decide if it is filtered on \
  1821. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1822. The sole argument to the function, which is called once for each
  1823. possible tag, is a string giving the name of the tag. The
  1824. function should return either nil if the tag should be included
  1825. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1826. lines not carrying this tag.
  1827. Note that for the purpose of tag filtering, only the lower-case version of
  1828. all tags will be considered, so that this function will only ever see
  1829. the lower-case version of all tags."
  1830. :group 'org-agenda
  1831. :type '(choice (const nil) (function)))
  1832. (defcustom org-agenda-bulk-custom-functions nil
  1833. "Alist of characters and custom functions for bulk actions.
  1834. For example, this value makes those two functions available:
  1835. \\='((?R set-category)
  1836. (?C bulk-cut))
  1837. With selected entries in an agenda buffer, `B R' will call
  1838. the custom function `set-category' on the selected entries.
  1839. Note that functions in this alist don't need to be quoted.
  1840. You can also specify a function which collects arguments to be
  1841. used for each call to your bulk custom function. The argument
  1842. collecting function will be run once and should return a list of
  1843. arguments to pass to the bulk function. For example:
  1844. \\='((?R set-category get-category))
  1845. Now, `B R' will call the custom `get-category' which would prompt
  1846. the user once for a category. That category is then passed as an
  1847. argument to `set-category' for each entry it's called against."
  1848. :type
  1849. '(alist :key-type character
  1850. :value-type
  1851. (group (function :tag "Bulk Custom Function")
  1852. (choice (function :tag "Bulk Custom Argument Function")
  1853. (const :tag "No Bulk Custom Argument Function" nil))))
  1854. :package-version '(Org . "9.5")
  1855. :group 'org-agenda)
  1856. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1857. "Execute BODY with point at location given by `org-hd-marker' property.
  1858. If STRING is non-nil, the text property will be fetched from position 0
  1859. in that string. If STRING is nil, it will be fetched from the beginning
  1860. of the current line."
  1861. (declare (debug t))
  1862. (org-with-gensyms (marker)
  1863. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1864. 'org-hd-marker ,string)))
  1865. (with-current-buffer (marker-buffer ,marker)
  1866. (save-excursion
  1867. (goto-char ,marker)
  1868. ,@body)))))
  1869. (defun org-add-agenda-custom-command (entry)
  1870. "Replace or add a command in `org-agenda-custom-commands'.
  1871. This is mostly for hacking and trying a new command - once the command
  1872. works you probably want to add it to `org-agenda-custom-commands' for good."
  1873. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1874. (if ass
  1875. (setcdr ass (cdr entry))
  1876. (push entry org-agenda-custom-commands))))
  1877. (defmacro org-agenda--insert-overriding-header (default)
  1878. "Insert header into agenda view.
  1879. The inserted header depends on `org-agenda-overriding-header'.
  1880. If the empty string, don't insert a header. If any other string,
  1881. insert it as a header. If nil, insert DEFAULT, which should
  1882. evaluate to a string. If a function, call it and insert the
  1883. string that it returns."
  1884. (declare (debug (form)) (indent defun))
  1885. `(cond
  1886. ((not org-agenda-overriding-header) (insert ,default))
  1887. ((equal org-agenda-overriding-header "") nil)
  1888. ((stringp org-agenda-overriding-header)
  1889. (insert (propertize org-agenda-overriding-header
  1890. 'face 'org-agenda-structure)
  1891. "\n"))
  1892. ((functionp org-agenda-overriding-header)
  1893. (insert (funcall org-agenda-overriding-header)))
  1894. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1895. org-agenda-overriding-header))))
  1896. ;;; Define the org-agenda-mode
  1897. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1898. (defvar org-agenda-mode-map (make-sparse-keymap)
  1899. "Keymap for `org-agenda-mode'.")
  1900. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1901. (defvar org-agenda-menu) ; defined later in this file.
  1902. (defvar org-agenda-restrict nil)
  1903. (defvar org-agenda-follow-mode nil)
  1904. (defvar org-agenda-entry-text-mode nil)
  1905. (defvar org-agenda-clockreport-mode nil)
  1906. (defvar org-agenda-show-log nil
  1907. "When non-nil, show the log in the agenda.
  1908. Do not set this directly; instead use
  1909. `org-agenda-start-with-log-mode', which see.")
  1910. (defvar org-agenda-redo-command nil)
  1911. (defvar org-agenda-query-string nil)
  1912. (defvar org-agenda-mode-hook nil
  1913. "Hook run after `org-agenda-mode' is turned on.
  1914. The buffer is still writable when this hook is called.")
  1915. (defvar org-agenda-type nil)
  1916. (defvar org-agenda-force-single-file nil)
  1917. (defvar org-agenda-bulk-marked-entries nil
  1918. "List of markers that refer to marked entries in the agenda.")
  1919. (defvar org-agenda-current-date nil
  1920. "Active date when building the agenda.")
  1921. ;;; Multiple agenda buffers support
  1922. (defcustom org-agenda-sticky nil
  1923. "Non-nil means agenda q key will bury agenda buffers.
  1924. Agenda commands will then show existing buffer instead of generating new ones.
  1925. When nil, `q' will kill the single agenda buffer."
  1926. :group 'org-agenda
  1927. :version "24.3"
  1928. :type 'boolean)
  1929. ;;;###autoload
  1930. (defun org-toggle-sticky-agenda (&optional arg)
  1931. "Toggle `org-agenda-sticky'."
  1932. (interactive "P")
  1933. (let ((new-value (if arg
  1934. (> (prefix-numeric-value arg) 0)
  1935. (not org-agenda-sticky))))
  1936. (if (equal new-value org-agenda-sticky)
  1937. (and (called-interactively-p 'interactive)
  1938. (message "Sticky agenda was already %s"
  1939. (if org-agenda-sticky "enabled" "disabled")))
  1940. (setq org-agenda-sticky new-value)
  1941. (org-agenda-kill-all-agenda-buffers)
  1942. (and (called-interactively-p 'interactive)
  1943. (message "Sticky agenda %s"
  1944. (if org-agenda-sticky "enabled" "disabled"))))))
  1945. (defvar org-agenda-buffer nil
  1946. "Agenda buffer currently being generated.")
  1947. (defvar org-agenda-last-prefix-arg nil)
  1948. (defvar org-agenda-this-buffer-name nil)
  1949. (defvar org-agenda-doing-sticky-redo nil)
  1950. (defvar org-agenda-this-buffer-is-sticky nil)
  1951. (defvar org-agenda-last-indirect-buffer nil
  1952. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1953. (defconst org-agenda-local-vars
  1954. '(org-agenda-this-buffer-name
  1955. org-agenda-undo-list
  1956. org-agenda-pending-undo-list
  1957. org-agenda-follow-mode
  1958. org-agenda-entry-text-mode
  1959. org-agenda-clockreport-mode
  1960. org-agenda-show-log
  1961. org-agenda-redo-command
  1962. org-agenda-query-string
  1963. org-agenda-type
  1964. org-agenda-bulk-marked-entries
  1965. org-agenda-undo-has-started-in
  1966. org-agenda-info
  1967. org-agenda-pre-window-conf
  1968. org-agenda-columns-active
  1969. org-agenda-tag-filter
  1970. org-agenda-category-filter
  1971. org-agenda-top-headline-filter
  1972. org-agenda-regexp-filter
  1973. org-agenda-effort-filter
  1974. org-agenda-markers
  1975. org-agenda-last-search-view-search-was-boolean
  1976. org-agenda-last-indirect-buffer
  1977. org-agenda-filtered-by-category
  1978. org-agenda-filter-form
  1979. org-agenda-cycle-counter
  1980. org-agenda-last-prefix-arg)
  1981. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1982. (defun org-agenda-mode ()
  1983. "Mode for time-sorted view on action items in Org files.
  1984. The following commands are available:
  1985. \\{org-agenda-mode-map}"
  1986. (interactive)
  1987. (ignore-errors (require 'face-remap))
  1988. (let ((agenda-local-vars-to-keep
  1989. '(text-scale-mode-amount
  1990. text-scale-mode
  1991. text-scale-mode-lighter
  1992. face-remapping-alist))
  1993. (save (buffer-local-variables)))
  1994. (kill-all-local-variables)
  1995. (cl-flet ((reset-saved (var-set)
  1996. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1997. (dolist (elem save)
  1998. (pcase elem
  1999. (`(,var . ,val) ;ignore unbound variables
  2000. (when (and val (memq var var-set))
  2001. (set var val)))))))
  2002. (cond (org-agenda-doing-sticky-redo
  2003. ;; Refreshing sticky agenda-buffer
  2004. ;;
  2005. ;; Preserve the value of `org-agenda-local-vars' variables.
  2006. (mapc #'make-local-variable org-agenda-local-vars)
  2007. (reset-saved org-agenda-local-vars)
  2008. (setq-local org-agenda-this-buffer-is-sticky t))
  2009. (org-agenda-sticky
  2010. ;; Creating a sticky Agenda buffer for the first time
  2011. (mapc #'make-local-variable org-agenda-local-vars)
  2012. (setq-local org-agenda-this-buffer-is-sticky t))
  2013. (t
  2014. ;; Creating a non-sticky agenda buffer
  2015. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2016. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2017. (reset-saved agenda-local-vars-to-keep)))
  2018. (setq org-agenda-undo-list nil
  2019. org-agenda-pending-undo-list nil
  2020. org-agenda-bulk-marked-entries nil)
  2021. (setq major-mode 'org-agenda-mode)
  2022. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2023. (setq-local font-lock-global-modes (list 'not major-mode))
  2024. (setq mode-name "Org-Agenda")
  2025. (setq indent-tabs-mode nil)
  2026. (use-local-map org-agenda-mode-map)
  2027. (when org-startup-truncated (setq truncate-lines t))
  2028. (setq-local line-move-visual nil)
  2029. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2030. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2031. ;; Make sure properties are removed when copying text
  2032. (if (boundp 'filter-buffer-substring-functions)
  2033. (add-hook 'filter-buffer-substring-functions
  2034. (lambda (fun start end delete)
  2035. (substring-no-properties (funcall fun start end delete)))
  2036. nil t)
  2037. ;; Emacs >= 24.4.
  2038. (add-function :filter-return (local 'filter-buffer-substring-function)
  2039. #'substring-no-properties))
  2040. (unless org-agenda-keep-modes
  2041. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2042. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2043. org-agenda-show-log org-agenda-start-with-log-mode
  2044. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2045. (add-to-invisibility-spec '(org-filtered))
  2046. (org-fold-core-initialize `(,org-link--description-folding-spec
  2047. ,org-link--link-folding-spec))
  2048. (easy-menu-change
  2049. '("Agenda") "Agenda Files"
  2050. (append
  2051. (list
  2052. (vector
  2053. (if (get 'org-agenda-files 'org-restrict)
  2054. "Restricted to single file"
  2055. "Edit File List")
  2056. '(org-edit-agenda-file-list)
  2057. (not (get 'org-agenda-files 'org-restrict)))
  2058. "--")
  2059. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2060. (org-agenda-set-mode-name)
  2061. (run-mode-hooks 'org-agenda-mode-hook))
  2062. (substitute-key-definition #'undo #'org-agenda-undo
  2063. org-agenda-mode-map global-map)
  2064. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2065. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2066. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2067. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2068. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2069. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2070. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2071. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2072. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2073. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2074. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2075. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2076. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2077. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2078. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2079. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2080. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2081. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2082. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2083. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2085. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2086. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2087. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2088. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2089. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2090. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2091. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2092. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2093. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2094. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2095. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2096. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2097. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2099. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2100. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2101. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2103. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2104. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2105. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2106. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2107. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2108. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2109. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2110. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2111. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2112. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2113. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2114. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2115. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2116. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2117. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2118. (while l (org-defkey org-agenda-mode-map
  2119. (number-to-string (pop l)) #'digit-argument)))
  2120. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2121. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2122. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2123. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2124. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2125. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2126. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2127. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2128. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2129. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2130. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2131. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2132. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2133. #'org-clock-modify-effort-estimate)
  2134. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2135. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2136. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2137. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2138. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2139. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2140. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2141. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2142. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2143. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2144. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2145. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2146. (substitute-key-definition #'next-line #'org-agenda-next-line
  2147. org-agenda-mode-map global-map)
  2148. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2149. org-agenda-mode-map global-map)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2151. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2152. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2153. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2154. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2155. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2156. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2157. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2158. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2159. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2160. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2161. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2162. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2163. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2164. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2165. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2167. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2168. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2169. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2170. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2171. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2172. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2173. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2174. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2175. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2176. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2177. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2178. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2179. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2180. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2181. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2182. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2183. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2184. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2185. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2186. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2187. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2188. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2189. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2190. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2191. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2192. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2193. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2194. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2195. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2196. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2197. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2198. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2199. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2200. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2201. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2202. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2203. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2204. (when org-agenda-mouse-1-follows-link
  2205. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2206. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2207. '("Agenda"
  2208. ("Agenda Files")
  2209. "--"
  2210. ("Agenda Dates"
  2211. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2212. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2213. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2214. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2215. "--"
  2216. ("View"
  2217. ["Day View" org-agenda-day-view
  2218. :active (org-agenda-check-type nil 'agenda)
  2219. :style radio :selected (eq org-agenda-current-span 'day)
  2220. :keys "v d (or just d)"]
  2221. ["Week View" org-agenda-week-view
  2222. :active (org-agenda-check-type nil 'agenda)
  2223. :style radio :selected (eq org-agenda-current-span 'week)
  2224. :keys "v w"]
  2225. ["Fortnight View" org-agenda-fortnight-view
  2226. :active (org-agenda-check-type nil 'agenda)
  2227. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2228. :keys "v t"]
  2229. ["Month View" org-agenda-month-view
  2230. :active (org-agenda-check-type nil 'agenda)
  2231. :style radio :selected (eq org-agenda-current-span 'month)
  2232. :keys "v m"]
  2233. ["Year View" org-agenda-year-view
  2234. :active (org-agenda-check-type nil 'agenda)
  2235. :style radio :selected (eq org-agenda-current-span 'year)
  2236. :keys "v y"]
  2237. "--"
  2238. ["Include Diary" org-agenda-toggle-diary
  2239. :style toggle :selected org-agenda-include-diary
  2240. :active (org-agenda-check-type nil 'agenda)]
  2241. ["Include Deadlines" org-agenda-toggle-deadlines
  2242. :style toggle :selected org-agenda-include-deadlines
  2243. :active (org-agenda-check-type nil 'agenda)]
  2244. ["Use Time Grid" org-agenda-toggle-time-grid
  2245. :style toggle :selected org-agenda-use-time-grid
  2246. :active (org-agenda-check-type nil 'agenda)]
  2247. "--"
  2248. ["Show clock report" org-agenda-clockreport-mode
  2249. :style toggle :selected org-agenda-clockreport-mode
  2250. :active (org-agenda-check-type nil 'agenda)]
  2251. ["Show some entry text" org-agenda-entry-text-mode
  2252. :style toggle :selected org-agenda-entry-text-mode
  2253. :active t]
  2254. "--"
  2255. ["Show Logbook entries" org-agenda-log-mode
  2256. :style toggle :selected org-agenda-show-log
  2257. :active (org-agenda-check-type nil 'agenda)
  2258. :keys "v l (or just l)"]
  2259. ["Include archived trees" org-agenda-archives-mode
  2260. :style toggle :selected org-agenda-archives-mode :active t
  2261. :keys "v a"]
  2262. ["Include archive files" (org-agenda-archives-mode t)
  2263. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2264. :keys "v A"]
  2265. "--"
  2266. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2267. ("Filter current view"
  2268. ["with generic interface" org-agenda-filter t]
  2269. "--"
  2270. ["by category at cursor" org-agenda-filter-by-category t]
  2271. ["by tag" org-agenda-filter-by-tag t]
  2272. ["by effort" org-agenda-filter-by-effort t]
  2273. ["by regexp" org-agenda-filter-by-regexp t]
  2274. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2275. "--"
  2276. ["Remove all filtering" org-agenda-filter-remove-all t]
  2277. "--"
  2278. ["limit" org-agenda-limit-interactively t])
  2279. ["Rebuild buffer" org-agenda-redo t]
  2280. ["Write view to file" org-agenda-write t]
  2281. ["Save all Org buffers" org-save-all-org-buffers t]
  2282. "--"
  2283. ["Show original entry" org-agenda-show t]
  2284. ["Go To (other window)" org-agenda-goto t]
  2285. ["Go To (this window)" org-agenda-switch-to t]
  2286. ["Capture with cursor date" org-agenda-capture t]
  2287. ["Follow Mode" org-agenda-follow-mode
  2288. :style toggle :selected org-agenda-follow-mode :active t]
  2289. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2290. "--"
  2291. ("TODO"
  2292. ["Cycle TODO" org-agenda-todo t]
  2293. ["Next TODO set" org-agenda-todo-nextset t]
  2294. ["Previous TODO set" org-agenda-todo-previousset t]
  2295. ["Add note" org-agenda-add-note t])
  2296. ("Archive/Refile/Delete"
  2297. ["Archive default" org-agenda-archive-default t]
  2298. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2299. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2300. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2301. ["Archive subtree" org-agenda-archive t]
  2302. "--"
  2303. ["Refile" org-agenda-refile t]
  2304. "--"
  2305. ["Delete subtree" org-agenda-kill t])
  2306. ("Bulk action"
  2307. ["Mark entry" org-agenda-bulk-mark t]
  2308. ["Mark all" org-agenda-bulk-mark-all t]
  2309. ["Unmark entry" org-agenda-bulk-unmark t]
  2310. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2311. ["Toggle mark" org-agenda-bulk-toggle t]
  2312. ["Toggle all" org-agenda-bulk-toggle-all t]
  2313. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2314. ["Act on all marked" org-agenda-bulk-action t]
  2315. "--"
  2316. ("Tags and Properties"
  2317. ["Show all Tags" org-agenda-show-tags t]
  2318. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2319. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2320. "--"
  2321. ["Column View" org-columns t])
  2322. ("Deadline/Schedule"
  2323. ["Schedule" org-agenda-schedule t]
  2324. ["Set Deadline" org-agenda-deadline t]
  2325. "--"
  2326. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2327. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2328. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2329. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2330. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2331. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2332. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2333. ("Clock and Effort"
  2334. ["Clock in" org-agenda-clock-in t]
  2335. ["Clock out" org-agenda-clock-out t]
  2336. ["Clock cancel" org-agenda-clock-cancel t]
  2337. ["Goto running clock" org-clock-goto t]
  2338. "--"
  2339. ["Set Effort" org-agenda-set-effort t]
  2340. ["Change clocked effort" org-clock-modify-effort-estimate
  2341. (org-clock-is-active)])
  2342. ("Priority"
  2343. ["Set Priority" org-agenda-priority t]
  2344. ["Increase Priority" org-agenda-priority-up t]
  2345. ["Decrease Priority" org-agenda-priority-down t]
  2346. ["Show Priority" org-priority-show t])
  2347. ("Calendar/Diary"
  2348. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2349. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2350. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2351. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2352. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2353. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2354. "--"
  2355. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2356. "--"
  2357. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2358. "--"
  2359. ("MobileOrg"
  2360. ["Push Files and Views" org-mobile-push t]
  2361. ["Get Captured and Flagged" org-mobile-pull t]
  2362. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2363. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2364. "--"
  2365. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2366. "--"
  2367. ["Quit" org-agenda-quit t]
  2368. ["Exit and Release Buffers" org-agenda-exit t]
  2369. ))
  2370. ;;; Agenda undo
  2371. (defvar org-agenda-allow-remote-undo t
  2372. "Non-nil means allow remote undo from the agenda buffer.")
  2373. (defvar org-agenda-undo-has-started-in nil
  2374. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2375. (defun org-agenda-undo ()
  2376. "Undo a remote editing step in the agenda.
  2377. This undoes changes both in the agenda buffer and in the remote buffer
  2378. that have been changed along."
  2379. (interactive)
  2380. (or org-agenda-allow-remote-undo
  2381. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2382. (when (not (eq this-command last-command))
  2383. (setq org-agenda-undo-has-started-in nil
  2384. org-agenda-pending-undo-list org-agenda-undo-list))
  2385. (when (not org-agenda-pending-undo-list)
  2386. (user-error "No further undo information"))
  2387. (let* ((entry (pop org-agenda-pending-undo-list))
  2388. buf line cmd rembuf)
  2389. (setq cmd (pop entry) line (pop entry))
  2390. (setq rembuf (nth 2 entry))
  2391. (org-with-remote-undo rembuf
  2392. (while (bufferp (setq buf (pop entry)))
  2393. (when (pop entry)
  2394. (with-current-buffer buf
  2395. (let (;; (last-undo-buffer buf)
  2396. (inhibit-read-only t))
  2397. (unless (memq buf org-agenda-undo-has-started-in)
  2398. (push buf org-agenda-undo-has-started-in)
  2399. (make-local-variable 'pending-undo-list)
  2400. (undo-start))
  2401. (while (and pending-undo-list
  2402. (listp pending-undo-list)
  2403. (not (car pending-undo-list)))
  2404. (pop pending-undo-list))
  2405. (undo-more 1))))))
  2406. (org-goto-line line)
  2407. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2408. (defun org-verify-change-for-undo (l1 l2)
  2409. "Verify that a real change occurred between the undo lists L1 and L2."
  2410. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2411. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2412. (not (eq l1 l2)))
  2413. ;;; Agenda dispatch
  2414. (defvar org-agenda-restrict-begin (make-marker))
  2415. (defvar org-agenda-restrict-end (make-marker))
  2416. (defvar org-agenda-last-dispatch-buffer nil)
  2417. (defvar org-agenda-overriding-restriction nil)
  2418. (defcustom org-agenda-custom-commands-contexts nil
  2419. "Alist of custom agenda keys and contextual rules.
  2420. For example, if you have a custom agenda command \"p\" and you
  2421. want this command to be accessible only from plain text files,
  2422. use this:
  2423. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2424. Here are the available contexts definitions:
  2425. in-file: command displayed only in matching files
  2426. in-mode: command displayed only in matching modes
  2427. not-in-file: command not displayed in matching files
  2428. not-in-mode: command not displayed in matching modes
  2429. in-buffer: command displayed only in matching buffers
  2430. not-in-buffer: command not displayed in matching buffers
  2431. [function]: a custom function taking no argument
  2432. If you define several checks, the agenda command will be
  2433. accessible if there is at least one valid check.
  2434. You can also bind a key to another agenda custom command
  2435. depending on contextual rules.
  2436. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2437. Here it means: in .txt files, use \"p\" as the key for the
  2438. agenda command otherwise associated with \"q\". (The command
  2439. originally associated with \"q\" is not displayed to avoid
  2440. duplicates.)"
  2441. :version "24.3"
  2442. :group 'org-agenda-custom-commands
  2443. :type '(repeat (list :tag "Rule"
  2444. (string :tag " Agenda key")
  2445. (string :tag "Replace by command")
  2446. (repeat :tag "Available when"
  2447. (choice
  2448. (cons :tag "Condition"
  2449. (choice
  2450. (const :tag "In file" in-file)
  2451. (const :tag "Not in file" not-in-file)
  2452. (const :tag "In buffer" in-buffer)
  2453. (const :tag "Not in buffer" not-in-buffer)
  2454. (const :tag "In mode" in-mode)
  2455. (const :tag "Not in mode" not-in-mode))
  2456. (regexp))
  2457. (function :tag "Custom function"))))))
  2458. (defcustom org-agenda-max-entries nil
  2459. "Maximum number of entries to display in an agenda.
  2460. This can be nil (no limit) or an integer or an alist of agenda
  2461. types with an associated number of entries to display in this
  2462. type."
  2463. :version "24.4"
  2464. :package-version '(Org . "8.0")
  2465. :group 'org-agenda-custom-commands
  2466. :type '(choice (symbol :tag "No limit" nil)
  2467. (integer :tag "Max number of entries")
  2468. (repeat
  2469. (cons (choice :tag "Agenda type"
  2470. (const agenda)
  2471. (const todo)
  2472. (const tags)
  2473. (const search))
  2474. (integer :tag "Max number of entries")))))
  2475. (defcustom org-agenda-max-todos nil
  2476. "Maximum number of TODOs to display in an agenda.
  2477. This can be nil (no limit) or an integer or an alist of agenda
  2478. types with an associated number of entries to display in this
  2479. type."
  2480. :version "24.4"
  2481. :package-version '(Org . "8.0")
  2482. :group 'org-agenda-custom-commands
  2483. :type '(choice (symbol :tag "No limit" nil)
  2484. (integer :tag "Max number of TODOs")
  2485. (repeat
  2486. (cons (choice :tag "Agenda type"
  2487. (const agenda)
  2488. (const todo)
  2489. (const tags)
  2490. (const search))
  2491. (integer :tag "Max number of TODOs")))))
  2492. (defcustom org-agenda-max-tags nil
  2493. "Maximum number of tagged entries to display in an agenda.
  2494. This can be nil (no limit) or an integer or an alist of agenda
  2495. types with an associated number of entries to display in this
  2496. type."
  2497. :version "24.4"
  2498. :package-version '(Org . "8.0")
  2499. :group 'org-agenda-custom-commands
  2500. :type '(choice (symbol :tag "No limit" nil)
  2501. (integer :tag "Max number of tagged entries")
  2502. (repeat
  2503. (cons (choice :tag "Agenda type"
  2504. (const agenda)
  2505. (const todo)
  2506. (const tags)
  2507. (const search))
  2508. (integer :tag "Max number of tagged entries")))))
  2509. (defcustom org-agenda-max-effort nil
  2510. "Maximum cumulated effort duration for the agenda.
  2511. This can be nil (no limit) or a number of minutes (as an integer)
  2512. or an alist of agenda types with an associated number of minutes
  2513. to limit entries to in this type."
  2514. :version "24.4"
  2515. :package-version '(Org . "8.0")
  2516. :group 'org-agenda-custom-commands
  2517. :type '(choice (symbol :tag "No limit" nil)
  2518. (integer :tag "Max number of minutes")
  2519. (repeat
  2520. (cons (choice :tag "Agenda type"
  2521. (const agenda)
  2522. (const todo)
  2523. (const tags)
  2524. (const search))
  2525. (integer :tag "Max number of minutes")))))
  2526. (defvar org-agenda-keep-restricted-file-list nil)
  2527. (defvar org-keys nil)
  2528. (defvar org-match nil)
  2529. ;;;###autoload
  2530. (defun org-agenda (&optional arg keys restriction)
  2531. "Dispatch agenda commands to collect entries to the agenda buffer.
  2532. Prompts for a command to execute. Any prefix arg will be passed
  2533. on to the selected command. The default selections are:
  2534. a Call `org-agenda-list' to display the agenda for current day or week.
  2535. t Call `org-todo-list' to display the global todo list.
  2536. T Call `org-todo-list' to display the global todo list, select only
  2537. entries with a specific TODO keyword (the user gets a prompt).
  2538. m Call `org-tags-view' to display headlines with tags matching
  2539. a condition (the user is prompted for the condition).
  2540. M Like `m', but select only TODO entries, no ordinary headlines.
  2541. e Export views to associated files.
  2542. s Search entries for keywords.
  2543. S Search entries for keywords, only with TODO keywords.
  2544. / Multi occur across all agenda files and also files listed
  2545. in `org-agenda-text-search-extra-files'.
  2546. < Restrict agenda commands to buffer, subtree, or region.
  2547. Press several times to get the desired effect.
  2548. > Remove a previous restriction.
  2549. # List \"stuck\" projects.
  2550. ! Configure what \"stuck\" means.
  2551. C Configure custom agenda commands.
  2552. More commands can be added by configuring the variable
  2553. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2554. searches can be pre-defined in this way.
  2555. If the current buffer is in Org mode and visiting a file, you can also
  2556. first press `<' once to indicate that the agenda should be temporarily
  2557. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2558. Pressing `<' twice means to restrict to the current subtree or region
  2559. \(if active)."
  2560. (interactive "P")
  2561. (catch 'exit
  2562. (let* ((org-keys keys)
  2563. (prefix-descriptions nil)
  2564. (org-agenda-buffer-name org-agenda-buffer-name)
  2565. (org-agenda-window-setup (if (equal (buffer-name)
  2566. org-agenda-buffer-name)
  2567. 'current-window
  2568. org-agenda-window-setup))
  2569. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2570. (org-agenda-custom-commands
  2571. ;; normalize different versions
  2572. (delq nil
  2573. (mapcar
  2574. (lambda (x)
  2575. (cond ((stringp (cdr x))
  2576. (push x prefix-descriptions)
  2577. nil)
  2578. ((stringp (nth 1 x)) x)
  2579. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2580. (t (cons (car x) (cons "" (cdr x))))))
  2581. org-agenda-custom-commands)))
  2582. (org-agenda-custom-commands
  2583. (org-contextualize-keys
  2584. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2585. ;; (buf (current-buffer))
  2586. (bfn (buffer-file-name (buffer-base-buffer)))
  2587. entry type org-match lprops ans) ;; key
  2588. ;; Turn off restriction unless there is an overriding one,
  2589. (unless org-agenda-overriding-restriction
  2590. (unless org-agenda-keep-restricted-file-list
  2591. ;; There is a request to keep the file list in place
  2592. (put 'org-agenda-files 'org-restrict nil))
  2593. (setq org-agenda-restrict nil)
  2594. (move-marker org-agenda-restrict-begin nil)
  2595. (move-marker org-agenda-restrict-end nil))
  2596. ;; Delete old local properties
  2597. (put 'org-agenda-redo-command 'org-lprops nil)
  2598. ;; Delete previously set last-arguments
  2599. (put 'org-agenda-redo-command 'last-args nil)
  2600. ;; Remember where this call originated
  2601. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2602. (unless org-keys
  2603. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2604. org-keys (car ans)
  2605. restriction (cdr ans)))
  2606. ;; If we have sticky agenda buffers, set a name for the buffer,
  2607. ;; depending on the invoking keys. The user may still set this
  2608. ;; as a command option, which will overwrite what we do here.
  2609. (when org-agenda-sticky
  2610. (setq org-agenda-buffer-name
  2611. (format "*Org Agenda(%s)*" org-keys)))
  2612. ;; Establish the restriction, if any
  2613. (when (and (not org-agenda-overriding-restriction) restriction)
  2614. (put 'org-agenda-files 'org-restrict (list bfn))
  2615. (cond
  2616. ((eq restriction 'region)
  2617. (setq org-agenda-restrict (current-buffer))
  2618. (move-marker org-agenda-restrict-begin (region-beginning))
  2619. (move-marker org-agenda-restrict-end (region-end)))
  2620. ((eq restriction 'subtree)
  2621. (save-excursion
  2622. (setq org-agenda-restrict (current-buffer))
  2623. (org-back-to-heading t)
  2624. (move-marker org-agenda-restrict-begin (point))
  2625. (move-marker org-agenda-restrict-end
  2626. (progn (org-end-of-subtree t)))))
  2627. ((and (eq restriction 'buffer)
  2628. (or (< 1 (point-min))
  2629. (< (point-max) (1+ (buffer-size)))))
  2630. (setq org-agenda-restrict (current-buffer))
  2631. (move-marker org-agenda-restrict-begin (point-min))
  2632. (move-marker org-agenda-restrict-end (point-max)))))
  2633. ;; For example the todo list should not need it (but does...)
  2634. (cond
  2635. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2636. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2637. (progn
  2638. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2639. ;; to some of the local variables? There's no doc about
  2640. ;; that for `org-agenda-custom-commands'.
  2641. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2642. lprops (nth 4 entry))
  2643. (when org-agenda-sticky
  2644. (setq org-agenda-buffer-name
  2645. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2646. (format "*Org Agenda(%s)*" org-keys))))
  2647. (put 'org-agenda-redo-command 'org-lprops lprops)
  2648. (cl-progv
  2649. (mapcar #'car lprops)
  2650. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2651. (pcase type
  2652. (`agenda
  2653. (org-agenda-list current-prefix-arg))
  2654. (`agenda*
  2655. (org-agenda-list current-prefix-arg nil nil t))
  2656. (`alltodo
  2657. (org-todo-list current-prefix-arg))
  2658. (`search
  2659. (org-search-view current-prefix-arg org-match nil))
  2660. (`stuck
  2661. (org-agenda-list-stuck-projects current-prefix-arg))
  2662. (`tags
  2663. (org-tags-view current-prefix-arg org-match))
  2664. (`tags-todo
  2665. (org-tags-view '(4) org-match))
  2666. (`todo
  2667. (org-todo-list org-match))
  2668. (`tags-tree
  2669. (org-check-for-org-mode)
  2670. (org-match-sparse-tree current-prefix-arg org-match))
  2671. (`todo-tree
  2672. (org-check-for-org-mode)
  2673. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2674. (regexp-quote org-match) "\\>")))
  2675. (`occur-tree
  2676. (org-check-for-org-mode)
  2677. (org-occur org-match))
  2678. ((pred functionp)
  2679. (funcall type org-match))
  2680. ;; FIXME: Will signal an error since it's not `functionp'!
  2681. ((pred fboundp) (funcall type org-match))
  2682. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2683. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2684. ((equal org-keys "C")
  2685. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2686. (customize-variable 'org-agenda-custom-commands))
  2687. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2688. ((equal org-keys "s") (call-interactively 'org-search-view))
  2689. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2690. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2691. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2692. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2693. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2694. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2695. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2696. (add-hook
  2697. 'post-command-hook
  2698. (lambda ()
  2699. (unless (current-message)
  2700. (let* ((m (org-agenda-get-any-marker))
  2701. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2702. (when note
  2703. (message "FLAGGING-NOTE ([?] for more info): %s"
  2704. (org-add-props
  2705. (replace-regexp-in-string
  2706. "\\\\n" "//"
  2707. (copy-sequence note))
  2708. nil 'face 'org-warning))))))
  2709. t t))
  2710. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2711. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2712. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2713. (t (user-error "Invalid agenda key"))))))
  2714. (defvar org-agenda-multi)
  2715. (defun org-agenda-append-agenda ()
  2716. "Append another agenda view to the current one.
  2717. This function allows interactive building of block agendas.
  2718. Agenda views are separated by `org-agenda-block-separator'."
  2719. (interactive)
  2720. (unless (derived-mode-p 'org-agenda-mode)
  2721. (user-error "Can only append from within agenda buffer"))
  2722. (let ((org-agenda-multi t))
  2723. (org-agenda)
  2724. (widen)
  2725. (org-agenda-finalize)
  2726. (setq buffer-read-only t)
  2727. (org-agenda-fit-window-to-buffer)))
  2728. (defun org-agenda-normalize-custom-commands (cmds)
  2729. "Normalize custom commands CMDS."
  2730. (delq nil
  2731. (mapcar
  2732. (lambda (x)
  2733. (cond ((stringp (cdr x)) nil)
  2734. ((stringp (nth 1 x)) x)
  2735. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2736. (t (cons (car x) (cons "" (cdr x))))))
  2737. cmds)))
  2738. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2739. "The user interface for selecting an agenda command."
  2740. (catch 'exit
  2741. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2742. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2743. (region-p (org-region-active-p))
  2744. (custom org-agenda-custom-commands)
  2745. (selstring "")
  2746. restriction second-time
  2747. c entry key type match prefixes rmheader header-end custom1 desc
  2748. line lines left right n n1)
  2749. (save-window-excursion
  2750. (delete-other-windows)
  2751. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2752. (erase-buffer)
  2753. (insert (eval-when-compile
  2754. (let ((header
  2755. (copy-sequence
  2756. "Press key for an agenda command:
  2757. -------------------------------- < Buffer, subtree/region restriction
  2758. a Agenda for current week or day > Remove restriction
  2759. t List of all TODO entries e Export agenda views
  2760. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2761. s Search for keywords M Like m, but only TODO entries
  2762. / Multi-occur S Like s, but only TODO entries
  2763. ? Find :FLAGGED: entries C Configure custom agenda commands
  2764. * Toggle sticky agenda views # List stuck projects (!=configure)
  2765. "))
  2766. (start 0))
  2767. (while (string-match
  2768. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2769. header start)
  2770. (setq start (match-end 0))
  2771. (add-text-properties (match-beginning 2) (match-end 2)
  2772. '(face bold) header))
  2773. header)))
  2774. (setq header-end (point-marker))
  2775. (while t
  2776. (setq custom1 custom)
  2777. (when (eq rmheader t)
  2778. (org-goto-line 1)
  2779. (re-search-forward ":" nil t)
  2780. (delete-region (match-end 0) (point-at-eol))
  2781. (forward-char 1)
  2782. (looking-at "-+")
  2783. (delete-region (match-end 0) (point-at-eol))
  2784. (move-marker header-end (match-end 0)))
  2785. (goto-char header-end)
  2786. (delete-region (point) (point-max))
  2787. ;; Produce all the lines that describe custom commands and prefixes
  2788. (setq lines nil)
  2789. (while (setq entry (pop custom1))
  2790. (setq key (car entry) desc (nth 1 entry)
  2791. type (nth 2 entry)
  2792. match (nth 3 entry))
  2793. (if (> (length key) 1)
  2794. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2795. (setq line
  2796. (format
  2797. "%-4s%-14s"
  2798. (org-add-props (copy-sequence key)
  2799. '(face bold))
  2800. (cond
  2801. ((string-match "\\S-" desc) desc)
  2802. ((eq type 'agenda) "Agenda for current week or day")
  2803. ((eq type 'agenda*) "Appointments for current week or day")
  2804. ((eq type 'alltodo) "List of all TODO entries")
  2805. ((eq type 'search) "Word search")
  2806. ((eq type 'stuck) "List of stuck projects")
  2807. ((eq type 'todo) "TODO keyword")
  2808. ((eq type 'tags) "Tags query")
  2809. ((eq type 'tags-todo) "Tags (TODO)")
  2810. ((eq type 'tags-tree) "Tags tree")
  2811. ((eq type 'todo-tree) "TODO kwd tree")
  2812. ((eq type 'occur-tree) "Occur tree")
  2813. ((functionp type) (if (symbolp type)
  2814. (symbol-name type)
  2815. "Lambda expression"))
  2816. (t "???"))))
  2817. (cond
  2818. ((not (org-string-nw-p match)) nil)
  2819. (org-agenda-menu-show-matcher
  2820. (setq line
  2821. (concat line ": "
  2822. (cond
  2823. ((stringp match)
  2824. (propertize match 'face 'org-warning))
  2825. ((listp type)
  2826. (format "set of %d commands" (length type)))))))
  2827. (t
  2828. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2829. (push line lines)))
  2830. (setq lines (nreverse lines))
  2831. (when prefixes
  2832. (mapc (lambda (x)
  2833. (push
  2834. (format "%s %s"
  2835. (org-add-props (char-to-string x)
  2836. nil 'face 'bold)
  2837. (or (cdr (assoc (concat selstring
  2838. (char-to-string x))
  2839. prefix-descriptions))
  2840. "Prefix key"))
  2841. lines))
  2842. prefixes))
  2843. ;; Check if we should display in two columns
  2844. (if org-agenda-menu-two-columns
  2845. (progn
  2846. (setq n (length lines)
  2847. n1 (+ (/ n 2) (mod n 2))
  2848. right (nthcdr n1 lines)
  2849. left (copy-sequence lines))
  2850. (setcdr (nthcdr (1- n1) left) nil))
  2851. (setq left lines right nil))
  2852. (while left
  2853. (insert "\n" (pop left))
  2854. (when right
  2855. (if (< (current-column) 40)
  2856. (move-to-column 40 t)
  2857. (insert " "))
  2858. (insert (pop right))))
  2859. ;; Make the window the right size
  2860. (goto-char (point-min))
  2861. (if second-time
  2862. (when (not (pos-visible-in-window-p (point-max)))
  2863. (org-fit-window-to-buffer))
  2864. (setq second-time t)
  2865. (org-fit-window-to-buffer))
  2866. ;; Hint to navigation if window too small for all information
  2867. (setq header-line-format
  2868. (when (not (pos-visible-in-window-p (point-max)))
  2869. "Use C-v, M-v, C-n or C-p to navigate."))
  2870. ;; Ask for selection
  2871. (cl-loop
  2872. do (progn
  2873. (message "Press key for agenda command%s:"
  2874. (if (or restrict-ok org-agenda-overriding-restriction)
  2875. (if org-agenda-overriding-restriction
  2876. " (restriction lock active)"
  2877. (if restriction
  2878. (format " (restricted to %s)" restriction)
  2879. " (unrestricted)"))
  2880. ""))
  2881. (setq c (read-char-exclusive)))
  2882. until (not (memq c '(14 16 22 134217846)))
  2883. do (org-scroll c))
  2884. (message "")
  2885. (cond
  2886. ((assoc (char-to-string c) custom)
  2887. (setq selstring (concat selstring (char-to-string c)))
  2888. (throw 'exit (cons selstring restriction)))
  2889. ((memq c prefixes)
  2890. (setq selstring (concat selstring (char-to-string c))
  2891. prefixes nil
  2892. rmheader (or rmheader t)
  2893. custom (delq nil (mapcar
  2894. (lambda (x)
  2895. (if (or (= (length (car x)) 1)
  2896. (/= (string-to-char (car x)) c))
  2897. nil
  2898. (cons (substring (car x) 1) (cdr x))))
  2899. custom))))
  2900. ((eq c ?*)
  2901. (call-interactively 'org-toggle-sticky-agenda)
  2902. (sit-for 2))
  2903. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2904. (message "Restriction is only possible in Org buffers")
  2905. (ding) (sit-for 1))
  2906. ((eq c ?1)
  2907. (org-agenda-remove-restriction-lock 'noupdate)
  2908. (setq restriction 'buffer))
  2909. ((eq c ?0)
  2910. (org-agenda-remove-restriction-lock 'noupdate)
  2911. (setq restriction (if region-p 'region 'subtree)))
  2912. ((eq c ?<)
  2913. (org-agenda-remove-restriction-lock 'noupdate)
  2914. (setq restriction
  2915. (cond
  2916. ((eq restriction 'buffer)
  2917. (if region-p 'region 'subtree))
  2918. ((memq restriction '(subtree region))
  2919. nil)
  2920. (t 'buffer))))
  2921. ((eq c ?>)
  2922. (org-agenda-remove-restriction-lock 'noupdate)
  2923. (setq restriction nil))
  2924. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2925. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2926. ((and (> (length selstring) 0) (eq c ?\d))
  2927. (delete-window)
  2928. (org-agenda-get-restriction-and-command prefix-descriptions))
  2929. ((equal c ?q) (user-error "Abort"))
  2930. (t (user-error "Invalid key %c" c))))))))
  2931. (defun org-agenda-fit-window-to-buffer ()
  2932. "Fit the window to the buffer size."
  2933. (and (memq org-agenda-window-setup '(reorganize-frame))
  2934. (fboundp 'fit-window-to-buffer)
  2935. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2936. (= (car org-agenda-window-frame-fractions) 1.0))
  2937. (delete-other-windows)
  2938. (org-fit-window-to-buffer
  2939. nil
  2940. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2941. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2942. (defvar org-cmd nil)
  2943. (defvar org-agenda-overriding-cmd nil)
  2944. (defvar org-agenda-overriding-arguments nil)
  2945. (defvar org-agenda-overriding-cmd-arguments nil)
  2946. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2947. (declare (indent 1) (obsolete cl-progv "2021"))
  2948. (eval (cons 'let (cons list body))))
  2949. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2950. (declare (indent 2) (obsolete cl-progv "2021"))
  2951. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2952. (defun org-agenda-run-series (name series)
  2953. "Run agenda NAME as a SERIES of agenda commands."
  2954. (let* ((gprops (nth 1 series))
  2955. (gvars (mapcar #'car gprops))
  2956. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2957. (cl-progv gvars gvals (org-agenda-prepare name))
  2958. ;; We need to reset agenda markers here, because when constructing a
  2959. ;; block agenda, the individual blocks do not do that.
  2960. (org-agenda-reset-markers)
  2961. (with-no-warnings
  2962. (defvar match)) ;Used via the `eval' below.
  2963. (let* ((org-agenda-multi t)
  2964. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2965. ;; than expressions, so you don't need to `quote' the args
  2966. ;; and you just need to `apply' instead of `eval' when using it.
  2967. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2968. (cmds (car series))
  2969. match
  2970. org-cmd type lprops)
  2971. (while (setq org-cmd (pop cmds))
  2972. (setq type (car org-cmd))
  2973. (setq match (eval (nth 1 org-cmd) t))
  2974. (setq lprops (nth 2 org-cmd))
  2975. (let ((org-agenda-overriding-arguments
  2976. (if (eq org-agenda-overriding-cmd org-cmd)
  2977. (or org-agenda-overriding-arguments
  2978. org-agenda-overriding-cmd-arguments)))
  2979. (lvars (mapcar #'car lprops))
  2980. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2981. (cl-progv (append gvars lvars) (append gvals lvals)
  2982. (pcase type
  2983. (`agenda
  2984. (call-interactively 'org-agenda-list))
  2985. (`agenda*
  2986. (funcall 'org-agenda-list nil nil t))
  2987. (`alltodo
  2988. (call-interactively 'org-todo-list))
  2989. (`search
  2990. (org-search-view current-prefix-arg match nil))
  2991. (`stuck
  2992. (call-interactively 'org-agenda-list-stuck-projects))
  2993. (`tags
  2994. (org-tags-view current-prefix-arg match))
  2995. (`tags-todo
  2996. (org-tags-view '(4) match))
  2997. (`todo
  2998. (org-todo-list match))
  2999. ((pred fboundp)
  3000. (funcall type match))
  3001. (_ (error "Invalid type in command series"))))))
  3002. (widen)
  3003. (let ((inhibit-read-only t))
  3004. (add-text-properties (point-min) (point-max)
  3005. `(org-series t org-series-redo-cmd ,redo)))
  3006. (setq org-agenda-redo-command redo)
  3007. (goto-char (point-min)))
  3008. (org-agenda-fit-window-to-buffer)
  3009. (cl-progv gvars gvals (org-agenda-finalize))))
  3010. (defun org-agenda--split-plist (plist)
  3011. ;; We could/should arguably use `map-keys' and `map-values'.
  3012. (let (keys vals)
  3013. (while plist
  3014. (push (pop plist) keys)
  3015. (push (pop plist) vals))
  3016. (cons (nreverse keys) (nreverse vals))))
  3017. ;;;###autoload
  3018. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3019. "Run an agenda command in batch mode and send the result to STDOUT.
  3020. If CMD-KEY is a string of length 1, it is used as a key in
  3021. `org-agenda-custom-commands' and triggers this command. If it is a
  3022. longer string it is used as a tags/todo match string.
  3023. Parameters are alternating variable names and values that will be bound
  3024. before running the agenda command."
  3025. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3026. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3027. (defun org--batch-agenda (cmd-key vars vals)
  3028. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3029. ;; a variable name rather than an expression to evaluate. Yuck!
  3030. (cl-progv vars vals
  3031. (let (org-agenda-sticky)
  3032. (if (> (length cmd-key) 1)
  3033. (org-tags-view nil cmd-key)
  3034. (org-agenda nil cmd-key))))
  3035. (set-buffer org-agenda-buffer-name)
  3036. (princ (buffer-string)))
  3037. (defvar org-agenda-info nil)
  3038. ;;;###autoload
  3039. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3040. "Run an agenda command in batch mode and send the result to STDOUT.
  3041. If CMD-KEY is a string of length 1, it is used as a key in
  3042. `org-agenda-custom-commands' and triggers this command. If it is a
  3043. longer string it is used as a tags/todo match string.
  3044. Parameters are alternating variable names and values that will be bound
  3045. before running the agenda command.
  3046. The output gives a line for each selected agenda item. Each
  3047. item is a list of comma-separated values, like this:
  3048. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3049. category The category of the item
  3050. head The headline, without TODO kwd, TAGS and PRIORITY
  3051. type The type of the agenda entry, can be
  3052. todo selected in TODO match
  3053. tagsmatch selected in tags match
  3054. diary imported from diary
  3055. deadline a deadline on given date
  3056. scheduled scheduled on given date
  3057. timestamp entry has timestamp on given date
  3058. closed entry was closed on given date
  3059. upcoming-deadline warning about deadline
  3060. past-scheduled forwarded scheduled item
  3061. block entry has date block including g. date
  3062. todo The todo keyword, if any
  3063. tags All tags including inherited ones, separated by colons
  3064. date The relevant date, like 2007-2-14
  3065. time The time, like 15:00-16:50
  3066. extra String with extra planning info
  3067. priority-l The priority letter if any was given
  3068. priority-n The computed numerical priority
  3069. agenda-day The day in the agenda where this is listed"
  3070. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3071. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3072. (defun org--batch-agenda-csv (cmd-key vars vals)
  3073. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3074. ;; a variable name rather than an expression to evaluate. Yuck!
  3075. (let ((org-agenda-remove-tags t))
  3076. (cl-progv vars vals
  3077. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3078. (if (> (length cmd-key) 2)
  3079. (org-tags-view nil cmd-key)
  3080. (org-agenda nil cmd-key))))
  3081. (set-buffer org-agenda-buffer-name)
  3082. (let ((lines (org-split-string (buffer-string) "\n")))
  3083. (dolist (line lines)
  3084. (when (get-text-property 0 'org-category line)
  3085. (setq org-agenda-info
  3086. (org-fix-agenda-info (text-properties-at 0 line)))
  3087. (princ
  3088. (mapconcat #'org-agenda-export-csv-mapper
  3089. '(org-category txt type todo tags date time extra
  3090. priority-letter priority agenda-day)
  3091. ","))
  3092. (princ "\n")))))
  3093. (defun org-fix-agenda-info (props)
  3094. "Make sure all properties on an agenda item have a canonical form.
  3095. This ensures the export commands can easily use it."
  3096. (let (tmp re)
  3097. (when (setq tmp (plist-get props 'tags))
  3098. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3099. (when (setq tmp (plist-get props 'date))
  3100. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3101. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3102. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3103. (setq tmp (calendar-date-string tmp)))
  3104. (setq props (plist-put props 'date tmp)))
  3105. (when (setq tmp (plist-get props 'day))
  3106. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3107. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3108. (setq tmp (calendar-date-string tmp)))
  3109. (setq props (plist-put props 'day tmp))
  3110. (setq props (plist-put props 'agenda-day tmp)))
  3111. (when (setq tmp (plist-get props 'txt))
  3112. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3113. (plist-put props 'priority-letter (match-string 1 tmp))
  3114. (setq tmp (replace-match "" t t tmp)))
  3115. (when (and (setq re (plist-get props 'org-todo-regexp))
  3116. (setq re (concat "\\`\\.*" re " ?"))
  3117. (let ((case-fold-search nil)) (string-match re tmp)))
  3118. (plist-put props 'todo (match-string 1 tmp))
  3119. (setq tmp (replace-match "" t t tmp)))
  3120. (plist-put props 'txt tmp)))
  3121. props)
  3122. (defun org-agenda-export-csv-mapper (prop)
  3123. (let ((res (plist-get org-agenda-info prop)))
  3124. (setq res
  3125. (cond
  3126. ((not res) "")
  3127. ((stringp res) res)
  3128. (t (prin1-to-string res))))
  3129. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3130. ;;;###autoload
  3131. (defun org-store-agenda-views (&rest _parameters)
  3132. "Store agenda views."
  3133. (interactive)
  3134. (org--batch-store-agenda-views nil nil))
  3135. ;;;###autoload
  3136. (defmacro org-batch-store-agenda-views (&rest parameters)
  3137. "Run all custom agenda commands that have a file argument."
  3138. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3139. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3140. (defun org--batch-store-agenda-views (vars vals)
  3141. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3142. (pop-up-frames nil)
  3143. (dir default-directory)
  3144. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3145. (save-window-excursion
  3146. (while cmds
  3147. (setq cmd (pop cmds)
  3148. thiscmdkey (car cmd)
  3149. thiscmdcmd (cdr cmd)
  3150. match (nth 2 thiscmdcmd)
  3151. bufname (if org-agenda-sticky
  3152. (or (and (stringp match)
  3153. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3154. (format "*Org Agenda(%s)*" thiscmdkey))
  3155. org-agenda-buffer-name)
  3156. cmd-or-set (nth 2 cmd)
  3157. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3158. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3159. (if (stringp files) (setq files (list files)))
  3160. (when files
  3161. (let* ((opts (append org-agenda-exporter-settings opts))
  3162. (vars (append (mapcar #'car opts) vars))
  3163. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3164. opts)
  3165. vals)))
  3166. (cl-progv vars vals
  3167. (org-agenda nil thiscmdkey))
  3168. (set-buffer bufname)
  3169. (while files
  3170. (cl-progv vars vals
  3171. (org-agenda-write (expand-file-name (pop files) dir)
  3172. nil t bufname))))
  3173. (and (get-buffer bufname)
  3174. (kill-buffer bufname)))))))
  3175. (defvar org-agenda-current-span nil
  3176. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3177. (defun org-agenda-mark-header-line (pos)
  3178. "Mark the line at POS as an agenda structure header."
  3179. (save-excursion
  3180. (goto-char pos)
  3181. (put-text-property (point-at-bol) (point-at-eol)
  3182. 'org-agenda-structural-header t)
  3183. (when org-agenda-title-append
  3184. (put-text-property (point-at-bol) (point-at-eol)
  3185. 'org-agenda-title-append org-agenda-title-append))))
  3186. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3187. (defvar org-agenda-write-buffer-name "Agenda View")
  3188. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3189. "Write the current buffer (an agenda view) as a file.
  3190. Depending on the extension of the file name, plain text (.txt),
  3191. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3192. If the extension is .ics, translate visible agenda into iCalendar
  3193. format. If the extension is .org, collect all subtrees
  3194. corresponding to the agenda entries and add them in an .org file.
  3195. With prefix argument OPEN, open the new file immediately. If
  3196. NOSETTINGS is given, do not scope the settings of
  3197. `org-agenda-exporter-settings' into the export commands. This is
  3198. used when the settings have already been scoped and we do not
  3199. wish to overrule other, higher priority settings. If
  3200. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3201. the agenda to write."
  3202. (interactive "FWrite agenda to file: \nP")
  3203. (if (or (not (file-writable-p file))
  3204. (and (file-exists-p file)
  3205. (if (called-interactively-p 'any)
  3206. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3207. (user-error "Cannot write agenda to file %s" file))
  3208. (cl-progv
  3209. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3210. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3211. org-agenda-exporter-settings))
  3212. (save-excursion
  3213. (save-window-excursion
  3214. (let ((bs (copy-sequence (buffer-string)))
  3215. (extension (file-name-extension file))
  3216. (default-directory (file-name-directory file))
  3217. ) ;; beg content
  3218. (with-temp-buffer
  3219. (rename-buffer org-agenda-write-buffer-name t)
  3220. (set-buffer-modified-p nil)
  3221. (insert bs)
  3222. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3223. (run-hooks 'org-agenda-before-write-hook)
  3224. (cond
  3225. ((bound-and-true-p org-mobile-creating-agendas)
  3226. (org-mobile-write-agenda-for-mobile file))
  3227. ((string= "org" extension)
  3228. (let (content p m message-log-max)
  3229. (goto-char (point-min))
  3230. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3231. (goto-char p)
  3232. (setq m (get-text-property (point) 'org-hd-marker))
  3233. (when m
  3234. (push (with-current-buffer (marker-buffer m)
  3235. (goto-char m)
  3236. (org-copy-subtree 1 nil t t)
  3237. org-subtree-clip)
  3238. content)))
  3239. (find-file file)
  3240. (erase-buffer)
  3241. (dolist (s content) (org-paste-subtree 1 s))
  3242. (write-file file)
  3243. (kill-buffer (current-buffer))
  3244. (message "Org file written to %s" file)))
  3245. ((member extension '("html" "htm"))
  3246. (or (require 'htmlize nil t)
  3247. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3248. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3249. (set-buffer (htmlize-buffer (current-buffer)))
  3250. (when org-agenda-export-html-style
  3251. ;; replace <style> section with org-agenda-export-html-style
  3252. (goto-char (point-min))
  3253. (kill-region (- (search-forward "<style") 6)
  3254. (search-forward "</style>"))
  3255. (insert org-agenda-export-html-style))
  3256. (write-file file)
  3257. (kill-buffer (current-buffer))
  3258. (message "HTML written to %s" file))
  3259. ((string= "ps" extension)
  3260. (require 'ps-print)
  3261. (ps-print-buffer-with-faces file)
  3262. (message "Postscript written to %s" file))
  3263. ((string= "pdf" extension)
  3264. (require 'ps-print)
  3265. (ps-print-buffer-with-faces
  3266. (concat (file-name-sans-extension file) ".ps"))
  3267. (call-process "ps2pdf" nil nil nil
  3268. (expand-file-name
  3269. (concat (file-name-sans-extension file) ".ps"))
  3270. (expand-file-name file))
  3271. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3272. (message "PDF written to %s" file))
  3273. ((string= "ics" extension)
  3274. (require 'ox-icalendar)
  3275. (declare-function org-icalendar-export-current-agenda
  3276. "ox-icalendar" (file))
  3277. (org-icalendar-export-current-agenda (expand-file-name file)))
  3278. (t
  3279. (let ((bs (buffer-string)))
  3280. (find-file file)
  3281. (erase-buffer)
  3282. (insert bs)
  3283. (save-buffer 0)
  3284. (kill-buffer (current-buffer))
  3285. (message "Plain text written to %s" file))))))))
  3286. (set-buffer (or agenda-bufname
  3287. ;; FIXME: I'm pretty sure called-interactively-p
  3288. ;; doesn't do what we want here!
  3289. (and (called-interactively-p 'any) (buffer-name))
  3290. org-agenda-buffer-name)))
  3291. (when open (org-open-file file)))
  3292. (defun org-agenda-remove-marked-text (property &optional value)
  3293. "Delete all text marked with VALUE of PROPERTY.
  3294. VALUE defaults to t."
  3295. (let (beg)
  3296. (setq value (or value t))
  3297. (while (setq beg (text-property-any (point-min) (point-max)
  3298. property value))
  3299. (delete-region
  3300. beg (or (next-single-property-change beg property)
  3301. (point-max))))))
  3302. (defun org-agenda-add-entry-text ()
  3303. "Add entry text to agenda lines.
  3304. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3305. entry text following headings shown in the agenda.
  3306. Drawers will be excluded, also the line with scheduling/deadline info."
  3307. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3308. (not (bound-and-true-p org-mobile-creating-agendas)))
  3309. (let (m txt)
  3310. (goto-char (point-min))
  3311. (while (not (eobp))
  3312. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3313. (beginning-of-line 2)
  3314. (setq txt (org-agenda-get-some-entry-text
  3315. m org-agenda-add-entry-text-maxlines " > "))
  3316. (end-of-line 1)
  3317. (if (string-match "\\S-" txt)
  3318. (insert "\n" txt)
  3319. (or (eobp) (forward-char 1))))))))
  3320. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3321. &rest keep)
  3322. "Extract entry text from MARKER, at most N-LINES lines.
  3323. This will ignore drawers etc, just get the text.
  3324. If INDENT is given, prefix every line with this string. If KEEP is
  3325. given, it is a list of symbols, defining stuff that should not be
  3326. removed from the entry content. Currently only `planning' is allowed here."
  3327. (let (txt drawer-re kwd-time-re ind)
  3328. (save-excursion
  3329. (with-current-buffer (marker-buffer marker)
  3330. (if (not (derived-mode-p 'org-mode))
  3331. (setq txt "")
  3332. (org-with-wide-buffer
  3333. (goto-char marker)
  3334. (end-of-line 1)
  3335. (setq txt (buffer-substring
  3336. (min (1+ (point)) (point-max))
  3337. (progn (outline-next-heading) (point)))
  3338. drawer-re org-drawer-regexp
  3339. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3340. ".*\n?"))
  3341. (with-temp-buffer
  3342. (insert txt)
  3343. (when org-agenda-add-entry-text-descriptive-links
  3344. (goto-char (point-min))
  3345. (while (org-activate-links (point-max))
  3346. (goto-char (match-end 0))))
  3347. (goto-char (point-min))
  3348. (while (re-search-forward org-link-bracket-re (point-max) t)
  3349. (set-text-properties (match-beginning 0) (match-end 0)
  3350. nil))
  3351. (goto-char (point-min))
  3352. (while (re-search-forward drawer-re nil t)
  3353. (delete-region
  3354. (match-beginning 0)
  3355. (progn (re-search-forward
  3356. "^[ \t]*:END:.*\n?" nil 'move)
  3357. (point))))
  3358. (unless (member 'planning keep)
  3359. (goto-char (point-min))
  3360. (while (re-search-forward kwd-time-re nil t)
  3361. (replace-match "")))
  3362. (goto-char (point-min))
  3363. (when org-agenda-entry-text-exclude-regexps
  3364. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3365. (while (setq re (pop re-list))
  3366. (goto-char (point-min))
  3367. (while (re-search-forward re nil t)
  3368. (replace-match "")))))
  3369. (goto-char (point-max))
  3370. (skip-chars-backward " \t\n")
  3371. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3372. ;; find and remove min common indentation
  3373. (goto-char (point-min))
  3374. (untabify (point-min) (point-max))
  3375. (setq ind (current-indentation))
  3376. (while (not (eobp))
  3377. (unless (looking-at "[ \t]*$")
  3378. (setq ind (min ind (current-indentation))))
  3379. (beginning-of-line 2))
  3380. (goto-char (point-min))
  3381. (while (not (eobp))
  3382. (unless (looking-at "[ \t]*$")
  3383. (move-to-column ind)
  3384. (delete-region (point-at-bol) (point)))
  3385. (beginning-of-line 2))
  3386. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3387. (goto-char (point-min))
  3388. (when indent
  3389. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3390. (replace-match indent t t)))
  3391. (goto-char (point-min))
  3392. (while (looking-at "[ \t]*\n") (replace-match ""))
  3393. (goto-char (point-max))
  3394. (when (> (org-current-line)
  3395. n-lines)
  3396. (org-goto-line (1+ n-lines))
  3397. (backward-char 1))
  3398. (setq txt (buffer-substring (point-min) (point))))))))
  3399. txt))
  3400. (defun org-check-for-org-mode ()
  3401. "Make sure current buffer is in Org mode. Error if not."
  3402. (or (derived-mode-p 'org-mode)
  3403. (error "Cannot execute Org agenda command on buffer in %s"
  3404. major-mode)))
  3405. ;;; Agenda prepare and finalize
  3406. (defvar org-agenda-multi nil) ; dynamically scoped
  3407. (defvar org-agenda-pre-window-conf nil)
  3408. (defvar org-agenda-columns-active nil)
  3409. (defvar org-agenda-name nil)
  3410. (defvar org-agenda-tag-filter nil)
  3411. (defvar org-agenda-category-filter nil)
  3412. (defvar org-agenda-regexp-filter nil)
  3413. (defvar org-agenda-effort-filter nil)
  3414. (defvar org-agenda-top-headline-filter nil)
  3415. (defvar org-agenda-represented-categories nil
  3416. "Cache for the list of all categories in the agenda.")
  3417. (defvar org-agenda-represented-tags nil
  3418. "Cache for the list of all categories in the agenda.")
  3419. (defvar org-agenda-tag-filter-preset nil
  3420. "A preset of the tags filter used for secondary agenda filtering.
  3421. This must be a list of strings, each string must be a single tag preceded
  3422. by \"+\" or \"-\".
  3423. This variable should not be set directly, but agenda custom commands can
  3424. bind it in the options section. The preset filter is a global property of
  3425. the entire agenda view. In a block agenda, it will not work reliably to
  3426. define a filter for one of the individual blocks. You need to set it in
  3427. the global options and expect it to be applied to the entire view.")
  3428. (defconst org-agenda-filter-variables
  3429. '((category . org-agenda-category-filter)
  3430. (tag . org-agenda-tag-filter)
  3431. (effort . org-agenda-effort-filter)
  3432. (regexp . org-agenda-regexp-filter))
  3433. "Alist of filter types and associated variables.")
  3434. (defun org-agenda-filter-any ()
  3435. "Is any filter active?"
  3436. (cl-some (lambda (x)
  3437. (or (symbol-value (cdr x))
  3438. (get :preset-filter x)))
  3439. org-agenda-filter-variables))
  3440. (defvar org-agenda-category-filter-preset nil
  3441. "A preset of the category filter used for secondary agenda filtering.
  3442. This must be a list of strings, each string must be a single category
  3443. preceded by \"+\" or \"-\".
  3444. This variable should not be set directly, but agenda custom commands can
  3445. bind it in the options section. The preset filter is a global property of
  3446. the entire agenda view. In a block agenda, it will not work reliably to
  3447. define a filter for one of the individual blocks. You need to set it in
  3448. the global options and expect it to be applied to the entire view.")
  3449. (defvar org-agenda-regexp-filter-preset nil
  3450. "A preset of the regexp filter used for secondary agenda filtering.
  3451. This must be a list of strings, each string must be a single regexp
  3452. preceded by \"+\" or \"-\".
  3453. This variable should not be set directly, but agenda custom commands can
  3454. bind it in the options section. The preset filter is a global property of
  3455. the entire agenda view. In a block agenda, it will not work reliably to
  3456. define a filter for one of the individual blocks. You need to set it in
  3457. the global options and expect it to be applied to the entire view.")
  3458. (defvar org-agenda-effort-filter-preset nil
  3459. "A preset of the effort condition used for secondary agenda filtering.
  3460. This must be a list of strings, each string must be a single regexp
  3461. preceded by \"+\" or \"-\".
  3462. This variable should not be set directly, but agenda custom commands can
  3463. bind it in the options section. The preset filter is a global property of
  3464. the entire agenda view. In a block agenda, it will not work reliably to
  3465. define a filter for one of the individual blocks. You need to set it in
  3466. the global options and expect it to be applied to the entire view.")
  3467. (defun org-agenda-use-sticky-p ()
  3468. "Return non-nil if an agenda buffer named
  3469. `org-agenda-buffer-name' exists and should be shown instead of
  3470. generating a new one."
  3471. (and
  3472. ;; turned off by user
  3473. org-agenda-sticky
  3474. ;; For multi-agenda buffer already exists
  3475. (not org-agenda-multi)
  3476. ;; buffer found
  3477. (get-buffer org-agenda-buffer-name)
  3478. ;; C-u parameter is same as last call
  3479. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3480. (and
  3481. (equal current-prefix-arg
  3482. org-agenda-last-prefix-arg)
  3483. ;; In case user turned stickiness on, while having existing
  3484. ;; Agenda buffer active, don't reuse that buffer, because it
  3485. ;; does not have org variables local
  3486. org-agenda-this-buffer-is-sticky))))
  3487. (defvar org-agenda-buffer-tmp-name nil)
  3488. (defun org-agenda--get-buffer-name (sticky-name)
  3489. (or org-agenda-buffer-tmp-name
  3490. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3491. sticky-name
  3492. "*Org Agenda*"))
  3493. (defun org-agenda-prepare-window (abuf filter-alist)
  3494. "Setup agenda buffer in the window.
  3495. ABUF is the buffer for the agenda window.
  3496. FILTER-ALIST is an alist of filters we need to apply when
  3497. `org-agenda-persistent-filter' is non-nil."
  3498. (let* ((awin (get-buffer-window abuf)) wconf)
  3499. (cond
  3500. ((equal (current-buffer) abuf) nil)
  3501. (awin (select-window awin))
  3502. ((not (setq wconf (current-window-configuration))))
  3503. ((eq org-agenda-window-setup 'current-window)
  3504. (pop-to-buffer-same-window abuf))
  3505. ((eq org-agenda-window-setup 'other-window)
  3506. (org-switch-to-buffer-other-window abuf))
  3507. ((eq org-agenda-window-setup 'other-frame)
  3508. (switch-to-buffer-other-frame abuf))
  3509. ((eq org-agenda-window-setup 'other-tab)
  3510. (if (fboundp 'switch-to-buffer-other-tab)
  3511. (switch-to-buffer-other-tab abuf)
  3512. (user-error "Your version of Emacs does not have tab bar support")))
  3513. ((eq org-agenda-window-setup 'only-window)
  3514. (delete-other-windows)
  3515. (pop-to-buffer-same-window abuf))
  3516. ((eq org-agenda-window-setup 'reorganize-frame)
  3517. (delete-other-windows)
  3518. (org-switch-to-buffer-other-window abuf)))
  3519. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3520. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3521. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3522. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3523. ;; Additional test in case agenda is invoked from within agenda
  3524. ;; buffer via elisp link.
  3525. (unless (equal (current-buffer) abuf)
  3526. (pop-to-buffer-same-window abuf))
  3527. (setq org-agenda-pre-window-conf
  3528. (or wconf org-agenda-pre-window-conf))))
  3529. (defun org-agenda-prepare (&optional name)
  3530. (let ((filter-alist (when org-agenda-persistent-filter
  3531. (with-current-buffer
  3532. (get-buffer-create org-agenda-buffer-name)
  3533. `((tag . ,org-agenda-tag-filter)
  3534. (re . ,org-agenda-regexp-filter)
  3535. (effort . ,org-agenda-effort-filter)
  3536. (cat . ,org-agenda-category-filter))))))
  3537. (if (org-agenda-use-sticky-p)
  3538. (progn
  3539. (put 'org-agenda-tag-filter :preset-filter nil)
  3540. (put 'org-agenda-category-filter :preset-filter nil)
  3541. (put 'org-agenda-regexp-filter :preset-filter nil)
  3542. (put 'org-agenda-effort-filter :preset-filter nil)
  3543. ;; Popup existing buffer
  3544. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3545. filter-alist)
  3546. (message "Sticky Agenda buffer, use `r' to refresh")
  3547. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3548. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3549. (setq org-todo-keywords-for-agenda nil)
  3550. (put 'org-agenda-tag-filter :preset-filter
  3551. org-agenda-tag-filter-preset)
  3552. (put 'org-agenda-category-filter :preset-filter
  3553. org-agenda-category-filter-preset)
  3554. (put 'org-agenda-regexp-filter :preset-filter
  3555. org-agenda-regexp-filter-preset)
  3556. (put 'org-agenda-effort-filter :preset-filter
  3557. org-agenda-effort-filter-preset)
  3558. (if org-agenda-multi
  3559. (progn
  3560. (setq buffer-read-only nil)
  3561. (goto-char (point-max))
  3562. (unless (or (bobp) org-agenda-compact-blocks
  3563. (not org-agenda-block-separator))
  3564. (insert "\n"
  3565. (if (stringp org-agenda-block-separator)
  3566. org-agenda-block-separator
  3567. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3568. "\n"))
  3569. (narrow-to-region (point) (point-max)))
  3570. (setq org-done-keywords-for-agenda nil)
  3571. ;; Setting any org variables that are in org-agenda-local-vars
  3572. ;; list need to be done after the prepare call
  3573. (org-agenda-prepare-window
  3574. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3575. (setq buffer-read-only nil)
  3576. (org-agenda-reset-markers)
  3577. (let ((inhibit-read-only t)) (erase-buffer))
  3578. (org-agenda-mode)
  3579. (setq org-agenda-buffer (current-buffer))
  3580. (setq org-agenda-contributing-files nil)
  3581. (setq org-agenda-columns-active nil)
  3582. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3583. (setq org-todo-keywords-for-agenda
  3584. (org-uniquify org-todo-keywords-for-agenda))
  3585. (setq org-done-keywords-for-agenda
  3586. (org-uniquify org-done-keywords-for-agenda))
  3587. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3588. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3589. (and name (not org-agenda-name)
  3590. (setq-local org-agenda-name name)))
  3591. (setq buffer-read-only nil))))
  3592. (defvar org-overriding-columns-format)
  3593. (defvar org-local-columns-format)
  3594. (defun org-agenda-finalize ()
  3595. "Finishing touch for the agenda buffer.
  3596. This function is called just before displaying the agenda. If
  3597. you want to add your own functions to the finalization of the
  3598. agenda display, configure `org-agenda-finalize-hook'."
  3599. (unless org-agenda-multi
  3600. (let ((inhibit-read-only t))
  3601. (save-excursion
  3602. (goto-char (point-min))
  3603. (save-excursion
  3604. (while (org-activate-links (point-max))
  3605. (goto-char (match-end 0))))
  3606. (unless (eq org-agenda-remove-tags t)
  3607. (org-agenda-align-tags))
  3608. (unless org-agenda-with-colors
  3609. (remove-text-properties (point-min) (point-max) '(face nil)))
  3610. (when (bound-and-true-p org-overriding-columns-format)
  3611. (setq-local org-local-columns-format
  3612. org-overriding-columns-format))
  3613. (when org-agenda-view-columns-initially
  3614. (org-agenda-columns))
  3615. (when org-agenda-fontify-priorities
  3616. (org-agenda-fontify-priorities))
  3617. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3618. (org-agenda-dim-blocked-tasks))
  3619. (org-agenda-mark-clocking-task)
  3620. (when org-agenda-entry-text-mode
  3621. (org-agenda-entry-text-hide)
  3622. (org-agenda-entry-text-show))
  3623. (when (and (featurep 'org-habit)
  3624. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3625. (org-habit-insert-consistency-graphs))
  3626. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3627. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3628. (and (listp org-agenda-show-inherited-tags)
  3629. (memq org-agenda-type org-agenda-show-inherited-tags))
  3630. (and (eq org-agenda-show-inherited-tags t)
  3631. (or (eq org-agenda-use-tag-inheritance t)
  3632. (and (listp org-agenda-use-tag-inheritance)
  3633. (not (memq org-agenda-type
  3634. org-agenda-use-tag-inheritance))))))
  3635. (let (mrk)
  3636. (save-excursion
  3637. (goto-char (point-min))
  3638. (while (equal (forward-line) 0)
  3639. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3640. (put-text-property (point-at-bol) (point-at-eol)
  3641. 'tags
  3642. (org-with-point-at mrk
  3643. (org-get-tags))))))))
  3644. (setq org-agenda-represented-tags nil
  3645. org-agenda-represented-categories nil)
  3646. (when org-agenda-top-headline-filter
  3647. (org-agenda-filter-top-headline-apply
  3648. org-agenda-top-headline-filter))
  3649. (when org-agenda-tag-filter
  3650. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3651. (when (get 'org-agenda-tag-filter :preset-filter)
  3652. (org-agenda-filter-apply
  3653. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3654. (when org-agenda-category-filter
  3655. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3656. (when (get 'org-agenda-category-filter :preset-filter)
  3657. (org-agenda-filter-apply
  3658. (get 'org-agenda-category-filter :preset-filter) 'category))
  3659. (when org-agenda-regexp-filter
  3660. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3661. (when (get 'org-agenda-regexp-filter :preset-filter)
  3662. (org-agenda-filter-apply
  3663. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3664. (when org-agenda-effort-filter
  3665. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3666. (when (get 'org-agenda-effort-filter :preset-filter)
  3667. (org-agenda-filter-apply
  3668. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3669. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3670. (run-hooks 'org-agenda-finalize-hook))))
  3671. (defun org-agenda-mark-clocking-task ()
  3672. "Mark the current clock entry in the agenda if it is present."
  3673. ;; We need to widen when `org-agenda-finalize' is called from
  3674. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3675. (when (bound-and-true-p org-clock-current-task)
  3676. (save-restriction
  3677. (widen)
  3678. (org-agenda-unmark-clocking-task)
  3679. (when (marker-buffer org-clock-hd-marker)
  3680. (save-excursion
  3681. (goto-char (point-min))
  3682. (let (s ov)
  3683. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3684. (goto-char s)
  3685. (when (equal (org-get-at-bol 'org-hd-marker)
  3686. org-clock-hd-marker)
  3687. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3688. (overlay-put ov 'type 'org-agenda-clocking)
  3689. (overlay-put ov 'face 'org-agenda-clocking)
  3690. (overlay-put ov 'help-echo
  3691. "The clock is running in this item")))))))))
  3692. (defun org-agenda-unmark-clocking-task ()
  3693. "Unmark the current clocking task."
  3694. (mapc (lambda (o)
  3695. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3696. (delete-overlay o)))
  3697. (overlays-in (point-min) (point-max))))
  3698. (defun org-agenda-fontify-priorities ()
  3699. "Make highest priority lines bold, and lowest italic."
  3700. (interactive)
  3701. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3702. (delete-overlay o)))
  3703. (overlays-in (point-min) (point-max)))
  3704. (save-excursion
  3705. (let (b e p ov h l)
  3706. (goto-char (point-min))
  3707. (while (re-search-forward org-priority-regexp nil t)
  3708. (setq h (or (get-char-property (point) 'org-priority-highest)
  3709. org-priority-highest)
  3710. l (or (get-char-property (point) 'org-priority-lowest)
  3711. org-priority-lowest)
  3712. p (string-to-char (match-string 2))
  3713. b (match-beginning 1)
  3714. e (if (eq org-agenda-fontify-priorities 'cookies)
  3715. (1+ (match-end 2))
  3716. (point-at-eol))
  3717. ov (make-overlay b e))
  3718. (overlay-put
  3719. ov 'face
  3720. (let ((special-face
  3721. (cond ((org-face-from-face-or-color
  3722. 'priority 'org-priority
  3723. (cdr (assoc p org-priority-faces))))
  3724. ((and (listp org-agenda-fontify-priorities)
  3725. (org-face-from-face-or-color
  3726. 'priority 'org-priority
  3727. (cdr (assoc p org-agenda-fontify-priorities)))))
  3728. ((equal p l) 'italic)
  3729. ((equal p h) 'bold))))
  3730. (if special-face (list special-face 'org-priority) 'org-priority)))
  3731. (overlay-put ov 'org-type 'org-priority)))))
  3732. (defvar org-depend-tag-blocked)
  3733. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3734. "Dim currently blocked TODOs in the agenda display.
  3735. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3736. dimming them." ;FIXME: The arg isn't used, actually!
  3737. (interactive "P")
  3738. (when (called-interactively-p 'interactive)
  3739. (message "Dim or hide blocked tasks..."))
  3740. (dolist (o (overlays-in (point-min) (point-max)))
  3741. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3742. (delete-overlay o)))
  3743. (save-excursion
  3744. (let ((inhibit-read-only t))
  3745. (goto-char (point-min))
  3746. (while (let ((pos (text-property-not-all
  3747. (point) (point-max) 'org-todo-blocked nil)))
  3748. (when pos (goto-char pos)))
  3749. (let* ((invisible
  3750. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3751. (todo-blocked
  3752. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3753. (ov (make-overlay (if invisible
  3754. (line-end-position 0)
  3755. (line-beginning-position))
  3756. (line-end-position))))
  3757. (when todo-blocked
  3758. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3759. (when invisible
  3760. (org-agenda-filter-hide-line 'todo-blocked)))
  3761. (if (= (point-max) (line-end-position))
  3762. (goto-char (point-max))
  3763. (move-beginning-of-line 2)))))
  3764. (when (called-interactively-p 'interactive)
  3765. (message "Dim or hide blocked tasks...done")))
  3766. (defun org-agenda--mark-blocked-entry (entry)
  3767. "If ENTRY is blocked, mark it for fontification or invisibility.
  3768. If the header at `org-hd-marker' is blocked according to
  3769. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3770. \\='invisible and the header is not blocked by checkboxes, set the
  3771. text property `org-todo-blocked' to `invisible', otherwise set it
  3772. to t."
  3773. (when (get-text-property 0 'todo-state entry)
  3774. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3775. (org-blocked-by-checkboxes nil)
  3776. ;; Necessary so that `org-entry-blocked-p' does not change
  3777. ;; the buffer.
  3778. (org-depend-tag-blocked nil))
  3779. (when entry-marker
  3780. (let ((blocked
  3781. (with-current-buffer (marker-buffer entry-marker)
  3782. (save-excursion
  3783. (goto-char entry-marker)
  3784. (org-entry-blocked-p)))))
  3785. (when blocked
  3786. (let ((really-invisible
  3787. (and (not org-blocked-by-checkboxes)
  3788. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3789. (put-text-property
  3790. 0 (length entry) 'org-todo-blocked
  3791. (if really-invisible 'invisible t)
  3792. entry)
  3793. (put-text-property
  3794. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3795. entry)
  3796. (defvar org-agenda-skip-function nil
  3797. "Function to be called at each match during agenda construction.
  3798. If this function returns nil, the current match should not be skipped.
  3799. Otherwise, the function must return a position from where the search
  3800. should be continued.
  3801. This may also be a Lisp form, it will be evaluated.
  3802. Never set this variable using `setq' or so, because then it will apply
  3803. to all future agenda commands. If you do want a global skipping condition,
  3804. use the option `org-agenda-skip-function-global' instead.
  3805. The correct usage for `org-agenda-skip-function' is to bind it with
  3806. `let' to scope it dynamically into the agenda-constructing command.
  3807. A good way to set it is through options in `org-agenda-custom-commands'.")
  3808. (defun org-agenda-skip (&optional element)
  3809. "Throw to `:skip' in places that should be skipped.
  3810. Also moves point to the end of the skipped region, so that search can
  3811. continue from there.
  3812. Optional argument ELEMENT contains element at point."
  3813. (let ((p (point-at-bol)) to)
  3814. (when (or
  3815. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3816. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3817. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3818. (org-end-of-subtree t element))
  3819. (and (member org-archive-tag org-file-tags)
  3820. (goto-char (point-max)))))
  3821. (and org-agenda-skip-comment-trees
  3822. (org-in-commented-heading-p nil element)
  3823. (org-end-of-subtree t element))
  3824. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3825. (org-agenda-skip-eval org-agenda-skip-function)))
  3826. (goto-char to))
  3827. (org-in-src-block-p t))
  3828. (throw :skip t))))
  3829. (defun org-agenda-skip-eval (form)
  3830. "If FORM is a function or a list, call (or eval) it and return the result.
  3831. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3832. and match data are returned to the previous state no matter what these
  3833. functions do."
  3834. (let (fp)
  3835. (and form
  3836. (or (setq fp (functionp form))
  3837. (consp form))
  3838. (save-excursion
  3839. (save-match-data
  3840. (if fp
  3841. (funcall form)
  3842. (eval form t)))))))
  3843. (defvar org-agenda-markers nil
  3844. "List of all currently active markers created by `org-agenda'.")
  3845. (defvar org-agenda-last-marker-time (float-time)
  3846. "Creation time of the last agenda marker.")
  3847. (defun org-agenda-new-marker (&optional pos)
  3848. "Return a new agenda marker.
  3849. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3850. of these markers and resets them when they are no longer in use."
  3851. (let ((m (copy-marker (or pos (point)) t)))
  3852. (setq org-agenda-last-marker-time (float-time))
  3853. (if org-agenda-buffer
  3854. (with-current-buffer org-agenda-buffer
  3855. (push m org-agenda-markers))
  3856. (push m org-agenda-markers))
  3857. m))
  3858. (defun org-agenda-reset-markers ()
  3859. "Reset markers created by `org-agenda'."
  3860. (while org-agenda-markers
  3861. (move-marker (pop org-agenda-markers) nil)))
  3862. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3863. "Save relative positions of markers in region.
  3864. This check for agenda markers in all agenda buffers currently active."
  3865. (dolist (buf (buffer-list))
  3866. (with-current-buffer buf
  3867. (when (eq major-mode 'org-agenda-mode)
  3868. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3869. org-agenda-markers)))))
  3870. ;;; Entry text mode
  3871. (defun org-agenda-entry-text-show-here ()
  3872. "Add some text from the entry as context to the current line."
  3873. (let (m txt o)
  3874. (setq m (org-get-at-bol 'org-hd-marker))
  3875. (unless (marker-buffer m)
  3876. (error "No marker points to an entry here"))
  3877. (setq txt (concat "\n" (org-no-properties
  3878. (org-agenda-get-some-entry-text
  3879. m org-agenda-entry-text-maxlines
  3880. org-agenda-entry-text-leaders))))
  3881. (when (string-match "\\S-" txt)
  3882. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3883. (overlay-put o 'evaporate t)
  3884. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3885. (overlay-put o 'after-string txt))))
  3886. (defun org-agenda-entry-text-show ()
  3887. "Add entry context for all agenda lines."
  3888. (interactive)
  3889. (save-excursion
  3890. (goto-char (point-max))
  3891. (beginning-of-line 1)
  3892. (while (not (bobp))
  3893. (when (org-get-at-bol 'org-hd-marker)
  3894. (org-agenda-entry-text-show-here))
  3895. (beginning-of-line 0))))
  3896. (defun org-agenda-entry-text-hide ()
  3897. "Remove any shown entry context."
  3898. (mapc (lambda (o)
  3899. (when (eq (overlay-get o 'org-overlay-type)
  3900. 'agenda-entry-content)
  3901. (delete-overlay o)))
  3902. (overlays-in (point-min) (point-max))))
  3903. (defun org-agenda-get-day-face (date)
  3904. "Return the face DATE should be displayed with."
  3905. (cond ((and (functionp org-agenda-day-face-function)
  3906. (funcall org-agenda-day-face-function date)))
  3907. ((and (org-agenda-today-p date)
  3908. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3909. 'org-agenda-date-weekend-today)
  3910. ((org-agenda-today-p date) 'org-agenda-date-today)
  3911. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3912. 'org-agenda-date-weekend)
  3913. (t 'org-agenda-date)))
  3914. (defvar org-agenda-show-log-scoped)
  3915. ;;; Agenda Daily/Weekly
  3916. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3917. "Start day for the agenda view.
  3918. Custom commands can set this variable in the options section.
  3919. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3920. input allowed when reading a date through the Org calendar.
  3921. See the docstring of `org-read-date' for details.")
  3922. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3923. (defvar org-arg-loc nil) ; local variable
  3924. ;;;###autoload
  3925. (defun org-agenda-list (&optional arg start-day span with-hour)
  3926. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3927. The view will be for the current day or week, but from the overview buffer
  3928. you will be able to go to other days/weeks.
  3929. With a numeric prefix argument in an interactive call, the agenda will
  3930. span ARG days. Lisp programs should instead specify SPAN to change
  3931. the number of days. SPAN defaults to `org-agenda-span'.
  3932. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3933. given in `org-agenda-start-on-weekday'.
  3934. When WITH-HOUR is non-nil, only include scheduled and deadline
  3935. items if they have an hour specification like [h]h:mm."
  3936. (interactive "P")
  3937. (when org-agenda-overriding-arguments
  3938. (setq arg (car org-agenda-overriding-arguments)
  3939. start-day (nth 1 org-agenda-overriding-arguments)
  3940. span (nth 2 org-agenda-overriding-arguments)))
  3941. (when (and (integerp arg) (> arg 0))
  3942. (setq span arg arg nil))
  3943. (when (numberp span)
  3944. (unless (< 0 span)
  3945. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3946. (catch 'exit
  3947. (setq org-agenda-buffer-name
  3948. (org-agenda--get-buffer-name
  3949. (and org-agenda-sticky
  3950. (cond ((and org-keys (stringp org-match))
  3951. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3952. (org-keys
  3953. (format "*Org Agenda(%s)*" org-keys))
  3954. (t "*Org Agenda(a)*")))))
  3955. (org-agenda-prepare "Day/Week")
  3956. (setq start-day (or start-day org-agenda-start-day))
  3957. (when (stringp start-day)
  3958. ;; Convert to an absolute day number
  3959. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3960. (org-compile-prefix-format 'agenda)
  3961. (org-set-sorting-strategy 'agenda)
  3962. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3963. (today (org-today))
  3964. (sd (or start-day today))
  3965. (ndays (org-agenda-span-to-ndays span sd))
  3966. (org-agenda-start-on-weekday
  3967. (and (or (eq ndays 7) (eq ndays 14))
  3968. org-agenda-start-on-weekday))
  3969. (thefiles (org-agenda-files nil 'ifmode))
  3970. (files thefiles)
  3971. (start (if (or (null org-agenda-start-on-weekday)
  3972. (< ndays 7))
  3973. sd
  3974. (let* ((nt (calendar-day-of-week
  3975. (calendar-gregorian-from-absolute sd)))
  3976. (n1 org-agenda-start-on-weekday)
  3977. (d (- nt n1)))
  3978. (- sd (+ (if (< d 0) 7 0) d)))))
  3979. (day-numbers (list start))
  3980. (day-cnt 0)
  3981. (inhibit-redisplay (not debug-on-error))
  3982. (org-agenda-show-log-scoped org-agenda-show-log)
  3983. s rtn rtnall file date d start-pos end-pos todayp ;; e
  3984. clocktable-start clocktable-end) ;; filter
  3985. (setq org-agenda-redo-command
  3986. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3987. (dotimes (_ (1- ndays))
  3988. (push (1+ (car day-numbers)) day-numbers))
  3989. (setq day-numbers (nreverse day-numbers))
  3990. (setq clocktable-start (car day-numbers)
  3991. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3992. (setq-local org-starting-day (car day-numbers))
  3993. (setq-local org-arg-loc arg)
  3994. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3995. (unless org-agenda-compact-blocks
  3996. (let* ((d1 (car day-numbers))
  3997. (d2 (org-last day-numbers))
  3998. (w1 (org-days-to-iso-week d1))
  3999. (w2 (org-days-to-iso-week d2)))
  4000. (setq s (point))
  4001. (org-agenda--insert-overriding-header
  4002. (concat (org-agenda-span-name span)
  4003. "-agenda"
  4004. (cond ((<= 350 (- d2 d1)) "")
  4005. ((= w1 w2) (format " (W%02d)" w1))
  4006. (t (format " (W%02d-W%02d)" w1 w2)))
  4007. ":\n")))
  4008. ;; Add properties if we actually inserted a header.
  4009. (when (> (point) s)
  4010. (add-text-properties s (1- (point))
  4011. (list 'face 'org-agenda-structure
  4012. 'org-date-line t))
  4013. (org-agenda-mark-header-line s)))
  4014. (while (setq d (pop day-numbers))
  4015. (setq date (calendar-gregorian-from-absolute d)
  4016. s (point))
  4017. (if (or (setq todayp (= d today))
  4018. (and (not start-pos) (= d sd)))
  4019. (setq start-pos (point))
  4020. (when (and start-pos (not end-pos))
  4021. (setq end-pos (point))))
  4022. (setq files thefiles
  4023. rtnall nil)
  4024. (while (setq file (pop files))
  4025. (catch 'nextfile
  4026. (org-check-agenda-file file)
  4027. (let ((org-agenda-entry-types org-agenda-entry-types))
  4028. ;; Starred types override non-starred equivalents
  4029. (when (member :deadline* org-agenda-entry-types)
  4030. (setq org-agenda-entry-types
  4031. (delq :deadline org-agenda-entry-types)))
  4032. (when (member :scheduled* org-agenda-entry-types)
  4033. (setq org-agenda-entry-types
  4034. (delq :scheduled org-agenda-entry-types)))
  4035. ;; Honor with-hour
  4036. (when with-hour
  4037. (when (member :deadline org-agenda-entry-types)
  4038. (setq org-agenda-entry-types
  4039. (delq :deadline org-agenda-entry-types))
  4040. (push :deadline* org-agenda-entry-types))
  4041. (when (member :scheduled org-agenda-entry-types)
  4042. (setq org-agenda-entry-types
  4043. (delq :scheduled org-agenda-entry-types))
  4044. (push :scheduled* org-agenda-entry-types)))
  4045. (unless org-agenda-include-deadlines
  4046. (setq org-agenda-entry-types
  4047. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4048. (cond
  4049. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4050. (setq rtn (org-agenda-get-day-entries
  4051. file date :closed)))
  4052. (org-agenda-show-log-scoped
  4053. (setq rtn (apply #'org-agenda-get-day-entries
  4054. file date
  4055. (append '(:closed) org-agenda-entry-types))))
  4056. (t
  4057. (setq rtn (apply #'org-agenda-get-day-entries
  4058. file date
  4059. org-agenda-entry-types)))))
  4060. (setq rtnall (append rtnall rtn)))) ;; all entries
  4061. (when org-agenda-include-diary
  4062. (let ((org-agenda-search-headline-for-time t))
  4063. (require 'diary-lib)
  4064. (setq rtn (org-get-entries-from-diary date))
  4065. (setq rtnall (append rtnall rtn))))
  4066. (when (or rtnall org-agenda-show-all-dates)
  4067. (setq day-cnt (1+ day-cnt))
  4068. (insert
  4069. (if (stringp org-agenda-format-date)
  4070. (format-time-string org-agenda-format-date
  4071. (org-time-from-absolute date))
  4072. (funcall org-agenda-format-date date))
  4073. "\n")
  4074. (put-text-property s (1- (point)) 'face
  4075. (org-agenda-get-day-face date))
  4076. (put-text-property s (1- (point)) 'org-date-line t)
  4077. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4078. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4079. (when todayp
  4080. (put-text-property s (1- (point)) 'org-today t))
  4081. (setq rtnall
  4082. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4083. (when rtnall (insert ;; all entries
  4084. (org-agenda-finalize-entries rtnall 'agenda)
  4085. "\n"))
  4086. (put-text-property s (1- (point)) 'day d)
  4087. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4088. (when (and org-agenda-clockreport-mode clocktable-start)
  4089. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4090. ;; the above line is to ensure the restricted range!
  4091. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4092. tbl)
  4093. (setq p (org-plist-delete p :block))
  4094. (setq p (plist-put p :tstart clocktable-start))
  4095. (setq p (plist-put p :tend clocktable-end))
  4096. (setq p (plist-put p :scope 'agenda))
  4097. (setq tbl (apply #'org-clock-get-clocktable p))
  4098. (when org-agenda-clock-report-header
  4099. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure)))
  4100. (insert tbl)))
  4101. (goto-char (point-min))
  4102. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4103. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4104. (and (pos-visible-in-window-p (point-min))
  4105. (pos-visible-in-window-p (point-max))))
  4106. (goto-char (1- (point-max)))
  4107. (recenter -1)
  4108. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4109. (goto-char (or start-pos 1))
  4110. (recenter 1)))
  4111. (goto-char (or start-pos 1))
  4112. (add-text-properties (point-min) (point-max)
  4113. `(org-agenda-type agenda
  4114. org-last-args (,arg ,start-day ,span)
  4115. org-redo-cmd ,org-agenda-redo-command
  4116. org-series-cmd ,org-cmd))
  4117. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4118. (org-agenda-show-clocking-issues))
  4119. (org-agenda-finalize)
  4120. (setq buffer-read-only t)
  4121. (message ""))))
  4122. (defun org-agenda-ndays-to-span (n)
  4123. "Return a span symbol for a span of N days, or N if none matches."
  4124. (cond ((symbolp n) n)
  4125. ((= n 1) 'day)
  4126. ((= n 7) 'week)
  4127. ((= n 14) 'fortnight)
  4128. (t n)))
  4129. (defun org-agenda-span-to-ndays (span &optional start-day)
  4130. "Return ndays from SPAN, possibly starting at START-DAY.
  4131. START-DAY is an absolute time value."
  4132. (cond ((numberp span) span)
  4133. ((eq span 'day) 1)
  4134. ((eq span 'week) 7)
  4135. ((eq span 'fortnight) 14)
  4136. ((eq span 'month)
  4137. (let ((date (calendar-gregorian-from-absolute start-day)))
  4138. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4139. ((eq span 'year)
  4140. (let ((date (calendar-gregorian-from-absolute start-day)))
  4141. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4142. (defun org-agenda-span-name (span)
  4143. "Return a SPAN name."
  4144. (if (null span)
  4145. ""
  4146. (if (symbolp span)
  4147. (capitalize (symbol-name span))
  4148. (format "%d days" span))))
  4149. ;;; Agenda word search
  4150. (defvar org-agenda-search-history nil)
  4151. (defvar org-search-syntax-table nil
  4152. "Special syntax table for Org search.
  4153. In this table, we have single quotes not as word constituents, to
  4154. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4155. (defvar org-mode-syntax-table) ; From org.el
  4156. (defun org-search-syntax-table ()
  4157. (unless org-search-syntax-table
  4158. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4159. (modify-syntax-entry ?' "." org-search-syntax-table)
  4160. (modify-syntax-entry ?` "." org-search-syntax-table))
  4161. org-search-syntax-table)
  4162. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4163. ;;;###autoload
  4164. (defun org-search-view (&optional todo-only string edit-at)
  4165. "Show all entries that contain a phrase or words or regular expressions.
  4166. With optional prefix argument TODO-ONLY, only consider entries that are
  4167. TODO entries. The argument STRING can be used to pass a default search
  4168. string into this function. If EDIT-AT is non-nil, it means that the
  4169. user should get a chance to edit this string, with cursor at position
  4170. EDIT-AT.
  4171. The search string can be viewed either as a phrase that should be found as
  4172. is, or it can be broken into a number of snippets, each of which must match
  4173. in a Boolean way to select an entry. The default depends on the variable
  4174. `org-agenda-search-view-always-boolean'.
  4175. Even if this is turned off (the default) you can always switch to
  4176. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4177. The default is a direct search of the whole phrase, where each space in
  4178. the search string can expand to an arbitrary amount of whitespace,
  4179. including newlines.
  4180. If using a Boolean search, the search string is split on whitespace and
  4181. each snippet is searched separately, with logical AND to select an entry.
  4182. Words prefixed with a minus must *not* occur in the entry. Words without
  4183. a prefix or prefixed with a plus must occur in the entry. Matching is
  4184. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4185. match whole words, not parts of a word) if
  4186. `org-agenda-search-view-force-full-words' is set (default is nil).
  4187. Boolean search snippets enclosed by curly braces are interpreted as
  4188. regular expressions that must or (when preceded with \"-\") must not
  4189. match in the entry. Snippets enclosed into double quotes will be taken
  4190. as a whole, to include whitespace.
  4191. - If the search string starts with an asterisk, search only in headlines.
  4192. - If (possibly after the leading star) the search string starts with an
  4193. exclamation mark, this also means to look at TODO entries only, an effect
  4194. that can also be achieved with a prefix argument.
  4195. - If (possibly after star and exclamation mark) the search string starts
  4196. with a colon, this will mean that the (non-regexp) snippets of the
  4197. Boolean search must match as full words.
  4198. This command searches the agenda files, and in addition the files
  4199. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4200. is active."
  4201. (interactive "P")
  4202. (when org-agenda-overriding-arguments
  4203. (setq todo-only (car org-agenda-overriding-arguments)
  4204. string (nth 1 org-agenda-overriding-arguments)
  4205. edit-at (nth 2 org-agenda-overriding-arguments)))
  4206. (let* ((props (list 'face nil
  4207. 'done-face 'org-agenda-done
  4208. 'org-not-done-regexp org-not-done-regexp
  4209. 'org-todo-regexp org-todo-regexp
  4210. 'org-complex-heading-regexp org-complex-heading-regexp
  4211. 'mouse-face 'highlight
  4212. 'help-echo "mouse-2 or RET jump to location"))
  4213. (full-words org-agenda-search-view-force-full-words)
  4214. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4215. regexp rtn rtnall files file pos inherited-tags
  4216. marker category level tags c neg re boolean
  4217. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4218. (unless (and (not edit-at)
  4219. (stringp string)
  4220. (string-match "\\S-" string))
  4221. (setq string (read-string
  4222. (if org-agenda-search-view-always-boolean
  4223. "[+-]Word/{Regexp} ...: "
  4224. "Phrase or [+-]Word/{Regexp} ...: ")
  4225. (cond
  4226. ((integerp edit-at) (cons string edit-at))
  4227. (edit-at string))
  4228. 'org-agenda-search-history)))
  4229. (catch 'exit
  4230. (setq org-agenda-buffer-name
  4231. (org-agenda--get-buffer-name
  4232. (and org-agenda-sticky
  4233. (if (stringp string)
  4234. (format "*Org Agenda(%s:%s)*"
  4235. (or org-keys (or (and todo-only "S") "s"))
  4236. string)
  4237. (format "*Org Agenda(%s)*"
  4238. (or (and todo-only "S") "s"))))))
  4239. (org-agenda-prepare "SEARCH")
  4240. (org-compile-prefix-format 'search)
  4241. (org-set-sorting-strategy 'search)
  4242. (setq org-agenda-redo-command
  4243. (list 'org-search-view (if todo-only t nil)
  4244. (list 'if 'current-prefix-arg nil string)))
  4245. (setq org-agenda-query-string string)
  4246. (if (equal (string-to-char string) ?*)
  4247. (setq hdl-only t
  4248. words (substring string 1))
  4249. (setq words string))
  4250. (when (equal (string-to-char words) ?!)
  4251. (setq todo-only t
  4252. words (substring words 1)))
  4253. (when (equal (string-to-char words) ?:)
  4254. (setq full-words t
  4255. words (substring words 1)))
  4256. (when (or org-agenda-search-view-always-boolean
  4257. (member (string-to-char words) '(?- ?+ ?\{)))
  4258. (setq boolean t))
  4259. (setq words (split-string words))
  4260. (let (www w)
  4261. (while (setq w (pop words))
  4262. (while (and (string-match "\\\\\\'" w) words)
  4263. (setq w (concat (substring w 0 -1) " " (pop words))))
  4264. (push w www))
  4265. (setq words (nreverse www) www nil)
  4266. (while (setq w (pop words))
  4267. (when (and (string-match "\\`[-+]?{" w)
  4268. (not (string-match "}\\'" w)))
  4269. (while (and words (not (string-match "}\\'" (car words))))
  4270. (setq w (concat w " " (pop words))))
  4271. (setq w (concat w " " (pop words))))
  4272. (push w www))
  4273. (setq words (nreverse www)))
  4274. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4275. (when boolean
  4276. (let (wds w)
  4277. (while (setq w (pop words))
  4278. (when (or (equal (substring w 0 1) "\"")
  4279. (and (> (length w) 1)
  4280. (member (substring w 0 1) '("+" "-"))
  4281. (equal (substring w 1 2) "\"")))
  4282. (while (and words (not (equal (substring w -1) "\"")))
  4283. (setq w (concat w " " (pop words)))))
  4284. (and (string-match "\\`\\([-+]?\\)\"" w)
  4285. (setq w (replace-match "\\1" nil nil w)))
  4286. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4287. (push w wds))
  4288. (setq words (nreverse wds))))
  4289. (if boolean
  4290. (mapc (lambda (w)
  4291. (setq c (string-to-char w))
  4292. (if (equal c ?-)
  4293. (setq neg t w (substring w 1))
  4294. (if (equal c ?+)
  4295. (setq neg nil w (substring w 1))
  4296. (setq neg nil)))
  4297. (if (string-match "\\`{.*}\\'" w)
  4298. (setq re (substring w 1 -1))
  4299. (if full-words
  4300. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4301. (setq re (regexp-quote (downcase w)))))
  4302. (if neg (push re regexps-) (push re regexps+)))
  4303. words)
  4304. (push (mapconcat #'regexp-quote words "\\s-+")
  4305. regexps+))
  4306. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4307. (if (not regexps+)
  4308. (setq regexp org-outline-regexp-bol)
  4309. (setq regexp (pop regexps+))
  4310. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4311. regexp))))
  4312. (setq files (org-agenda-files nil 'ifmode))
  4313. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4314. ;; restriction.
  4315. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4316. (pop org-agenda-text-search-extra-files)
  4317. (unless (get 'org-agenda-files 'org-restrict)
  4318. (setq files (org-add-archive-files files))))
  4319. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4320. ;; non-existent ones.
  4321. (setq files (cl-remove-duplicates
  4322. (append files org-agenda-text-search-extra-files)
  4323. :test (lambda (a b)
  4324. (and (file-exists-p a)
  4325. (file-exists-p b)
  4326. (file-equal-p a b))))
  4327. rtnall nil)
  4328. (while (setq file (pop files))
  4329. (setq ee nil)
  4330. (catch 'nextfile
  4331. (org-check-agenda-file file)
  4332. (setq buffer (if (file-exists-p file)
  4333. (org-get-agenda-file-buffer file)
  4334. (error "No such file %s" file)))
  4335. (unless buffer
  4336. ;; If file does not exist, make sure an error message is sent
  4337. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4338. file))))
  4339. (with-current-buffer buffer
  4340. (with-syntax-table (org-search-syntax-table)
  4341. (unless (derived-mode-p 'org-mode)
  4342. (error "Agenda file %s is not in Org mode" file))
  4343. (let ((case-fold-search t))
  4344. (save-excursion
  4345. (save-restriction
  4346. (if (eq buffer org-agenda-restrict)
  4347. (narrow-to-region org-agenda-restrict-begin
  4348. org-agenda-restrict-end)
  4349. (widen))
  4350. (goto-char (point-min))
  4351. (unless (or (org-at-heading-p)
  4352. (outline-next-heading))
  4353. (throw 'nextfile t))
  4354. (goto-char (max (point-min) (1- (point))))
  4355. (while (re-search-forward regexp nil t)
  4356. (org-back-to-heading t)
  4357. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4358. (> (org-reduced-level (org-outline-level))
  4359. org-agenda-search-view-max-outline-level)
  4360. (forward-line -1)
  4361. (org-back-to-heading t)))
  4362. (skip-chars-forward "* ")
  4363. (setq beg (point-at-bol)
  4364. beg1 (point)
  4365. end (progn
  4366. (outline-next-heading)
  4367. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4368. (> (org-reduced-level (org-outline-level))
  4369. org-agenda-search-view-max-outline-level)
  4370. (forward-line 1)
  4371. (outline-next-heading)))
  4372. (point)))
  4373. (catch :skip
  4374. (goto-char beg)
  4375. (org-agenda-skip)
  4376. (setq str (buffer-substring-no-properties
  4377. (point-at-bol)
  4378. (if hdl-only (point-at-eol) end)))
  4379. (mapc (lambda (wr) (when (string-match wr str)
  4380. (goto-char (1- end))
  4381. (throw :skip t)))
  4382. regexps-)
  4383. (mapc (lambda (wr) (unless (string-match wr str)
  4384. (goto-char (1- end))
  4385. (throw :skip t)))
  4386. (if todo-only
  4387. (cons (concat "^\\*+[ \t]+"
  4388. org-not-done-regexp)
  4389. regexps+)
  4390. regexps+))
  4391. (goto-char beg)
  4392. (setq marker (org-agenda-new-marker (point))
  4393. category (org-get-category)
  4394. level (make-string (org-reduced-level (org-outline-level)) ? )
  4395. inherited-tags
  4396. (or (eq org-agenda-show-inherited-tags 'always)
  4397. (and (listp org-agenda-show-inherited-tags)
  4398. (memq 'todo org-agenda-show-inherited-tags))
  4399. (and (eq org-agenda-show-inherited-tags t)
  4400. (or (eq org-agenda-use-tag-inheritance t)
  4401. (memq 'todo org-agenda-use-tag-inheritance))))
  4402. tags (org-get-tags nil (not inherited-tags))
  4403. txt (org-agenda-format-item
  4404. ""
  4405. (buffer-substring-no-properties
  4406. beg1 (point-at-eol))
  4407. level category tags t))
  4408. (org-add-props txt props
  4409. 'org-marker marker 'org-hd-marker marker
  4410. 'org-todo-regexp org-todo-regexp
  4411. 'level level
  4412. 'org-complex-heading-regexp org-complex-heading-regexp
  4413. 'priority 1000
  4414. 'type "search")
  4415. (push txt ee)
  4416. (goto-char (1- end))))))))))
  4417. (setq rtn (nreverse ee))
  4418. (setq rtnall (append rtnall rtn)))
  4419. (org-agenda--insert-overriding-header
  4420. (with-temp-buffer
  4421. (insert "Search words: ")
  4422. (add-text-properties (point-min) (1- (point))
  4423. (list 'face 'org-agenda-structure))
  4424. (setq pos (point))
  4425. (insert string "\n")
  4426. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4427. (setq pos (point))
  4428. (unless org-agenda-multi
  4429. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4430. Press `\\[org-agenda-manipulate-query-add]', \
  4431. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4432. `\\[org-agenda-manipulate-query-add-re]', \
  4433. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4434. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4435. (add-text-properties pos (1- (point))
  4436. (list 'face 'org-agenda-structure-secondary)))
  4437. (buffer-string)))
  4438. (org-agenda-mark-header-line (point-min))
  4439. (when rtnall
  4440. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4441. (goto-char (point-min))
  4442. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4443. (add-text-properties (point-min) (point-max)
  4444. `(org-agenda-type search
  4445. org-last-args (,todo-only ,string ,edit-at)
  4446. org-redo-cmd ,org-agenda-redo-command
  4447. org-series-cmd ,org-cmd))
  4448. (org-agenda-finalize)
  4449. (setq buffer-read-only t))))
  4450. ;;; Agenda TODO list
  4451. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4452. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4453. (concat
  4454. (if (or (equal keywords "ALL") (not keywords))
  4455. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4456. (mapconcat
  4457. (lambda (kw)
  4458. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4459. (org-split-string keywords "|")
  4460. "|"))
  4461. "\n"))
  4462. (defvar org-select-this-todo-keyword nil)
  4463. (defvar org-last-arg nil)
  4464. (defvar crm-separator)
  4465. ;;;###autoload
  4466. (defun org-todo-list (&optional arg)
  4467. "Show all (not done) TODO entries from all agenda files in a single list.
  4468. The prefix arg can be used to select a specific TODO keyword and limit
  4469. the list to these. When using `\\[universal-argument]', you will be prompted
  4470. for a keyword. A numeric prefix directly selects the Nth keyword in
  4471. `org-todo-keywords-1'."
  4472. (interactive "P")
  4473. (when org-agenda-overriding-arguments
  4474. (setq arg org-agenda-overriding-arguments))
  4475. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4476. (let* ((today (org-today))
  4477. (date (calendar-gregorian-from-absolute today))
  4478. (completion-ignore-case t)
  4479. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4480. (catch 'exit
  4481. (setq org-agenda-buffer-name
  4482. (org-agenda--get-buffer-name
  4483. (and org-agenda-sticky
  4484. (if (stringp org-select-this-todo-keyword)
  4485. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4486. org-select-this-todo-keyword)
  4487. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4488. (org-agenda-prepare "TODO")
  4489. (setq kwds org-todo-keywords-for-agenda
  4490. org-select-this-todo-keyword (if (stringp arg) arg
  4491. (and (integerp arg)
  4492. (> arg 0)
  4493. (nth (1- arg) kwds))))
  4494. (when (equal arg '(4))
  4495. (setq org-select-this-todo-keyword
  4496. (mapconcat #'identity
  4497. (let ((crm-separator "|"))
  4498. (completing-read-multiple
  4499. "Keyword (or KWD1|KWD2|...): "
  4500. (mapcar #'list kwds) nil nil))
  4501. "|")))
  4502. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4503. (org-compile-prefix-format 'todo)
  4504. (org-set-sorting-strategy 'todo)
  4505. (setq org-agenda-redo-command
  4506. `(org-todo-list (or (and (numberp current-prefix-arg)
  4507. current-prefix-arg)
  4508. ,org-select-this-todo-keyword
  4509. current-prefix-arg ,arg)))
  4510. (setq files (org-agenda-files nil 'ifmode)
  4511. rtnall nil)
  4512. (while (setq file (pop files))
  4513. (catch 'nextfile
  4514. (org-check-agenda-file file)
  4515. (setq rtn (org-agenda-get-day-entries file date :todo))
  4516. (setq rtnall (append rtnall rtn))))
  4517. (org-agenda--insert-overriding-header
  4518. (with-temp-buffer
  4519. (insert "Global list of TODO items of type: ")
  4520. (add-text-properties (point-min) (1- (point))
  4521. (list 'face 'org-agenda-structure
  4522. 'short-heading
  4523. (concat "ToDo: "
  4524. (or org-select-this-todo-keyword "ALL"))))
  4525. (org-agenda-mark-header-line (point-min))
  4526. (insert (org-agenda-propertize-selected-todo-keywords
  4527. org-select-this-todo-keyword))
  4528. (setq pos (point))
  4529. (unless org-agenda-multi
  4530. (insert (substitute-command-keys "Press \
  4531. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4532. to search again: (0)[ALL]"))
  4533. (let ((n 0))
  4534. (dolist (k kwds)
  4535. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4536. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4537. (insert "\n "))
  4538. (insert " " s))))
  4539. (insert "\n"))
  4540. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4541. (buffer-string)))
  4542. (org-agenda-mark-header-line (point-min))
  4543. (when rtnall
  4544. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4545. (goto-char (point-min))
  4546. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4547. (add-text-properties (point-min) (point-max)
  4548. `(org-agenda-type todo
  4549. org-last-args ,arg
  4550. org-redo-cmd ,org-agenda-redo-command
  4551. org-series-cmd ,org-cmd))
  4552. (org-agenda-finalize)
  4553. (setq buffer-read-only t))))
  4554. ;;; Agenda tags match
  4555. ;;;###autoload
  4556. (defun org-tags-view (&optional todo-only match)
  4557. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4558. The prefix arg TODO-ONLY limits the search to TODO entries."
  4559. (interactive "P")
  4560. (when org-agenda-overriding-arguments
  4561. (setq todo-only (car org-agenda-overriding-arguments)
  4562. match (nth 1 org-agenda-overriding-arguments)))
  4563. (let* ((org-tags-match-list-sublevels
  4564. org-tags-match-list-sublevels)
  4565. (completion-ignore-case t)
  4566. (org--matcher-tags-todo-only todo-only)
  4567. rtn rtnall files file pos matcher
  4568. buffer)
  4569. (when (and (stringp match) (not (string-match "\\S-" match)))
  4570. (setq match nil))
  4571. (catch 'exit
  4572. (setq org-agenda-buffer-name
  4573. (org-agenda--get-buffer-name
  4574. (and org-agenda-sticky
  4575. (if (stringp match)
  4576. (format "*Org Agenda(%s:%s)*"
  4577. (or org-keys (or (and todo-only "M") "m"))
  4578. match)
  4579. (format "*Org Agenda(%s)*"
  4580. (or (and todo-only "M") "m"))))))
  4581. (setq matcher (org-make-tags-matcher match))
  4582. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4583. ;; expanding tags within `org-make-tags-matcher'
  4584. (org-agenda-prepare (concat "TAGS " match))
  4585. (setq match (car matcher)
  4586. matcher (cdr matcher))
  4587. (org-compile-prefix-format 'tags)
  4588. (org-set-sorting-strategy 'tags)
  4589. (setq org-agenda-query-string match)
  4590. (setq org-agenda-redo-command
  4591. (list 'org-tags-view
  4592. `(quote ,org--matcher-tags-todo-only)
  4593. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4594. (setq files (org-agenda-files nil 'ifmode)
  4595. rtnall nil)
  4596. (while (setq file (pop files))
  4597. (catch 'nextfile
  4598. (org-check-agenda-file file)
  4599. (setq buffer (if (file-exists-p file)
  4600. (org-get-agenda-file-buffer file)
  4601. (error "No such file %s" file)))
  4602. (if (not buffer)
  4603. ;; If file does not exist, error message to agenda
  4604. (setq rtn (list
  4605. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4606. rtnall (append rtnall rtn))
  4607. (with-current-buffer buffer
  4608. (unless (derived-mode-p 'org-mode)
  4609. (error "Agenda file %s is not in Org mode" file))
  4610. (save-excursion
  4611. (save-restriction
  4612. (if (eq buffer org-agenda-restrict)
  4613. (narrow-to-region org-agenda-restrict-begin
  4614. org-agenda-restrict-end)
  4615. (widen))
  4616. (setq rtn (org-scan-tags 'agenda
  4617. matcher
  4618. org--matcher-tags-todo-only))
  4619. (setq rtnall (append rtnall rtn))))))))
  4620. (org-agenda--insert-overriding-header
  4621. (with-temp-buffer
  4622. (insert "Headlines with TAGS match: ")
  4623. (add-text-properties (point-min) (1- (point))
  4624. (list 'face 'org-agenda-structure
  4625. 'short-heading
  4626. (concat "Match: " match)))
  4627. (setq pos (point))
  4628. (insert match "\n")
  4629. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4630. (setq pos (point))
  4631. (unless org-agenda-multi
  4632. (insert (substitute-command-keys
  4633. "Press \
  4634. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4635. to search again\n")))
  4636. (add-text-properties pos (1- (point))
  4637. (list 'face 'org-agenda-structure-secondary))
  4638. (buffer-string)))
  4639. (org-agenda-mark-header-line (point-min))
  4640. (when rtnall
  4641. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4642. (goto-char (point-min))
  4643. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4644. (add-text-properties
  4645. (point-min) (point-max)
  4646. `(org-agenda-type tags
  4647. org-last-args (,org--matcher-tags-todo-only ,match)
  4648. org-redo-cmd ,org-agenda-redo-command
  4649. org-series-cmd ,org-cmd))
  4650. (org-agenda-finalize)
  4651. (setq buffer-read-only t))))
  4652. ;;; Agenda Finding stuck projects
  4653. (defvar org-agenda-skip-regexp nil
  4654. "Regular expression used in skipping subtrees for the agenda.
  4655. This is basically a temporary global variable that can be set and then
  4656. used by user-defined selections using `org-agenda-skip-function'.")
  4657. (defvar org-agenda-overriding-header nil
  4658. "When set during agenda, todo and tags searches it replaces the header.
  4659. If an empty string, no header will be inserted. If any other
  4660. string, it will be inserted as a header. If a function, insert
  4661. the string returned by the function as a header. If nil, a
  4662. header will be generated automatically according to the command.
  4663. This variable should not be set directly, but custom commands can
  4664. bind it in the options section.")
  4665. (defun org-agenda-skip-entry-if (&rest conditions)
  4666. "Skip entry if any of CONDITIONS is true.
  4667. See `org-agenda-skip-if' for details."
  4668. (org-agenda-skip-if nil conditions))
  4669. (defun org-agenda-skip-subtree-if (&rest conditions)
  4670. "Skip subtree if any of CONDITIONS is true.
  4671. See `org-agenda-skip-if' for details."
  4672. (org-agenda-skip-if t conditions))
  4673. (defun org-agenda-skip-if (subtree conditions)
  4674. "Check current entity for CONDITIONS.
  4675. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4676. the entry (i.e. the text before the next heading) is checked.
  4677. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4678. from different tests. Valid conditions are:
  4679. scheduled Check if there is a scheduled cookie
  4680. notscheduled Check if there is no scheduled cookie
  4681. deadline Check if there is a deadline
  4682. notdeadline Check if there is no deadline
  4683. timestamp Check if there is a timestamp (also deadline or scheduled)
  4684. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4685. regexp Check if regexp matches
  4686. notregexp Check if regexp does not match.
  4687. todo Check if TODO keyword matches
  4688. nottodo Check if TODO keyword does not match
  4689. The regexp is taken from the conditions list, it must come right after
  4690. the `regexp' or `notregexp' element.
  4691. `todo' and `nottodo' accept as an argument a list of todo
  4692. keywords, which may include \"*\" to match any todo keyword.
  4693. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4694. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4695. Instead of a list, a keyword class may be given. For example:
  4696. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4697. would skip entries that haven't been marked with any of \"DONE\"
  4698. keywords. Possible classes are: `todo', `done', `any'.
  4699. If any of these conditions is met, this function returns the end point of
  4700. the entity, causing the search to continue from there. This is a function
  4701. that can be put into `org-agenda-skip-function' for the duration of a command."
  4702. (org-back-to-heading t)
  4703. (let* (;; (beg (point))
  4704. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4705. (org-entry-end-position)))
  4706. (planning-end (if subtree end (line-end-position 2)))
  4707. m)
  4708. (and
  4709. (or (and (memq 'scheduled conditions)
  4710. (re-search-forward org-scheduled-time-regexp planning-end t))
  4711. (and (memq 'notscheduled conditions)
  4712. (not
  4713. (save-excursion
  4714. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4715. (and (memq 'deadline conditions)
  4716. (re-search-forward org-deadline-time-regexp planning-end t))
  4717. (and (memq 'notdeadline conditions)
  4718. (not
  4719. (save-excursion
  4720. (re-search-forward org-deadline-time-regexp planning-end t))))
  4721. (and (memq 'timestamp conditions)
  4722. (re-search-forward org-ts-regexp end t))
  4723. (and (memq 'nottimestamp conditions)
  4724. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4725. (and (setq m (memq 'regexp conditions))
  4726. (stringp (nth 1 m))
  4727. (re-search-forward (nth 1 m) end t))
  4728. (and (setq m (memq 'notregexp conditions))
  4729. (stringp (nth 1 m))
  4730. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4731. (and (or
  4732. (setq m (memq 'nottodo conditions))
  4733. (setq m (memq 'todo-unblocked conditions))
  4734. (setq m (memq 'nottodo-unblocked conditions))
  4735. (setq m (memq 'todo conditions)))
  4736. (org-agenda-skip-if-todo m end)))
  4737. end)))
  4738. (defun org-agenda-skip-if-todo (args end)
  4739. "Helper function for `org-agenda-skip-if', do not use it directly.
  4740. ARGS is a list with first element either `todo', `nottodo',
  4741. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4742. a list of TODO keywords, or a state symbol `todo' or `done' or
  4743. `any'."
  4744. (let ((todo-re
  4745. (concat "^\\*+[ \t]+"
  4746. (regexp-opt
  4747. (pcase args
  4748. (`(,_ todo)
  4749. (org-delete-all org-done-keywords
  4750. (copy-sequence org-todo-keywords-1)))
  4751. (`(,_ done) org-done-keywords)
  4752. (`(,_ any) org-todo-keywords-1)
  4753. (`(,_ ,(pred atom))
  4754. (error "Invalid TODO class or type: %S" args))
  4755. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4756. (`(,_ ,todo-list) todo-list))
  4757. 'words))))
  4758. (pcase args
  4759. (`(todo . ,_)
  4760. (let (case-fold-search) (re-search-forward todo-re end t)))
  4761. (`(nottodo . ,_)
  4762. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4763. (`(todo-unblocked . ,_)
  4764. (catch :unblocked
  4765. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4766. (when (org-entry-blocked-p) (throw :unblocked t)))
  4767. nil))
  4768. (`(nottodo-unblocked . ,_)
  4769. (catch :unblocked
  4770. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4771. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4772. t))
  4773. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4774. ;;;###autoload
  4775. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4776. "Create agenda view for projects that are stuck.
  4777. Stuck projects are project that have no next actions. For the definitions
  4778. of what a project is and how to check if it stuck, customize the variable
  4779. `org-stuck-projects'."
  4780. (interactive)
  4781. (let* ((org-agenda-overriding-header
  4782. (or org-agenda-overriding-header "List of stuck projects: "))
  4783. (matcher (nth 0 org-stuck-projects))
  4784. (todo (nth 1 org-stuck-projects))
  4785. (tags (nth 2 org-stuck-projects))
  4786. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4787. (todo-wds
  4788. (if (not (member "*" todo)) todo
  4789. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4790. (org-delete-all org-done-keywords-for-agenda
  4791. (copy-sequence org-todo-keywords-for-agenda))))
  4792. (todo-re (and todo
  4793. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4794. (mapconcat #'identity todo-wds "\\|"))))
  4795. (tags-re (cond ((null tags) nil)
  4796. ((member "*" tags) org-tag-line-re)
  4797. (tags
  4798. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4799. (concat org-outline-regexp-bol
  4800. ".*?[ \t]:"
  4801. other-tags
  4802. (regexp-opt tags t)
  4803. ":" other-tags "[ \t]*$")))
  4804. (t nil)))
  4805. (re-list (delq nil (list todo-re tags-re gen-re)))
  4806. (skip-re
  4807. (if (null re-list)
  4808. (error "Missing information to identify unstuck projects")
  4809. (mapconcat #'identity re-list "\\|")))
  4810. (org-agenda-skip-function
  4811. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4812. ;; in the subtree.
  4813. (lambda ()
  4814. (and (save-excursion
  4815. (let ((case-fold-search nil))
  4816. (re-search-forward
  4817. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4818. (progn (outline-next-heading) (point))))))
  4819. (org-tags-view nil matcher)
  4820. (setq org-agenda-buffer-name (buffer-name))
  4821. (with-current-buffer org-agenda-buffer-name
  4822. (setq org-agenda-redo-command
  4823. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4824. (let ((inhibit-read-only t))
  4825. (add-text-properties
  4826. (point-min) (point-max)
  4827. `(org-redo-cmd ,org-agenda-redo-command))))))
  4828. ;;; Diary integration
  4829. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4830. (defvar diary-list-entries-hook)
  4831. (defvar diary-time-regexp)
  4832. (defvar diary-modify-entry-list-string-function)
  4833. (defvar diary-file-name-prefix)
  4834. (defvar diary-display-function)
  4835. (defun org-get-entries-from-diary (date)
  4836. "Get the (Emacs Calendar) diary entries for DATE."
  4837. (require 'diary-lib)
  4838. (declare-function diary-fancy-display "diary-lib" ())
  4839. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4840. (diary-display-function #'diary-fancy-display)
  4841. (pop-up-frames nil)
  4842. (diary-list-entries-hook
  4843. (cons 'org-diary-default-entry diary-list-entries-hook))
  4844. (diary-file-name-prefix nil) ; turn this feature off
  4845. (diary-modify-entry-list-string-function
  4846. #'org-modify-diary-entry-string)
  4847. (diary-time-regexp (concat "^" diary-time-regexp))
  4848. entries
  4849. (org-disable-agenda-to-diary t))
  4850. (save-excursion
  4851. (save-window-excursion
  4852. (diary-list-entries date 1)))
  4853. (if (not (get-buffer diary-fancy-buffer))
  4854. (setq entries nil)
  4855. (with-current-buffer diary-fancy-buffer
  4856. (setq buffer-read-only nil)
  4857. (if (zerop (buffer-size))
  4858. ;; No entries
  4859. (setq entries nil)
  4860. ;; Omit the date and other unnecessary stuff
  4861. (org-agenda-cleanup-fancy-diary)
  4862. ;; Add prefix to each line and extend the text properties
  4863. (if (zerop (buffer-size))
  4864. (setq entries nil)
  4865. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4866. (setq entries
  4867. (with-temp-buffer
  4868. (insert entries) (goto-char (point-min))
  4869. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4870. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4871. (replace-match (concat "; " (match-string 1)))))
  4872. (buffer-string)))))
  4873. (set-buffer-modified-p nil)
  4874. (kill-buffer diary-fancy-buffer)))
  4875. (when entries
  4876. (setq entries (org-split-string entries "\n"))
  4877. (setq entries
  4878. (mapcar
  4879. (lambda (x)
  4880. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4881. ;; Extend the text properties to the beginning of the line
  4882. (org-add-props x (text-properties-at (1- (length x)) x)
  4883. 'type "diary" 'date date 'face 'org-agenda-diary))
  4884. entries)))))
  4885. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4886. "Hook run when the fancy diary buffer is cleaned up.")
  4887. (defun org-agenda-cleanup-fancy-diary ()
  4888. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4889. This gets rid of the date, the underline under the date, and the
  4890. dummy entry installed by Org mode to ensure non-empty diary for
  4891. each date. It also removes lines that contain only whitespace."
  4892. (goto-char (point-min))
  4893. (if (looking-at ".*?:[ \t]*")
  4894. (progn
  4895. (replace-match "")
  4896. (re-search-forward "\n=+$" nil t)
  4897. (replace-match "")
  4898. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4899. (re-search-forward "\n=+$" nil t)
  4900. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4901. (goto-char (point-min))
  4902. (while (re-search-forward "^ +\n" nil t)
  4903. (replace-match ""))
  4904. (goto-char (point-min))
  4905. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4906. (replace-match ""))
  4907. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4908. (defun org-modify-diary-entry-string (string)
  4909. "Add text properties to string, allowing Org to act on it."
  4910. (org-add-props string nil
  4911. 'mouse-face 'highlight
  4912. 'help-echo (if buffer-file-name
  4913. (format "mouse-2 or RET jump to diary file %s"
  4914. (abbreviate-file-name buffer-file-name))
  4915. "")
  4916. 'org-agenda-diary-link t
  4917. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4918. (defun org-diary-default-entry ()
  4919. "Add a dummy entry to the diary.
  4920. Needed to avoid empty dates which mess up holiday display."
  4921. ;; Catch the error if dealing with the new add-to-diary-alist
  4922. (when org-disable-agenda-to-diary
  4923. (diary-add-to-list original-date "Org mode dummy" "")))
  4924. (defvar org-diary-last-run-time nil)
  4925. ;;;###autoload
  4926. (defun org-diary (&rest args)
  4927. "Return diary information from org files.
  4928. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4929. It accesses org files and extracts information from those files to be
  4930. listed in the diary. The function accepts arguments specifying what
  4931. items should be listed. For a list of arguments allowed here, see the
  4932. variable `org-agenda-entry-types'.
  4933. The call in the diary file should look like this:
  4934. &%%(org-diary) ~/path/to/some/orgfile.org
  4935. Use a separate line for each org file to check. Or, if you omit the file name,
  4936. all files listed in `org-agenda-files' will be checked automatically:
  4937. &%%(org-diary)
  4938. If you don't give any arguments (as in the example above), the default value
  4939. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4940. So the example above may also be written as
  4941. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4942. The function expects the lisp variables `entry' and `date' to be provided
  4943. by the caller, because this is how the calendar works. Don't use this
  4944. function from a program - use `org-agenda-get-day-entries' instead."
  4945. (with-no-warnings (defvar date) (defvar entry))
  4946. (when (> (- (float-time)
  4947. org-agenda-last-marker-time)
  4948. 5)
  4949. ;; I am not sure if this works with sticky agendas, because the marker
  4950. ;; list is then no longer a global variable.
  4951. (org-agenda-reset-markers))
  4952. (org-compile-prefix-format 'agenda)
  4953. (org-set-sorting-strategy 'agenda)
  4954. (setq args (or args org-agenda-entry-types))
  4955. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4956. (list entry)
  4957. (org-agenda-files t)))
  4958. (time (float-time))
  4959. file rtn results)
  4960. (when (or (not org-diary-last-run-time)
  4961. (> (- time
  4962. org-diary-last-run-time)
  4963. 3))
  4964. (org-agenda-prepare-buffers files))
  4965. (setq org-diary-last-run-time time)
  4966. ;; If this is called during org-agenda, don't return any entries to
  4967. ;; the calendar. Org Agenda will list these entries itself.
  4968. (when org-disable-agenda-to-diary (setq files nil))
  4969. (while (setq file (pop files))
  4970. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4971. (setq results (append results rtn)))
  4972. (when results
  4973. (setq results
  4974. (mapcar (lambda (i) (replace-regexp-in-string
  4975. org-link-bracket-re "\\2" i))
  4976. results))
  4977. (concat (org-agenda-finalize-entries results) "\n"))))
  4978. ;;; Agenda entry finders
  4979. (defun org-agenda--timestamp-to-absolute (&rest args)
  4980. "Call `org-time-string-to-absolute' with ARGS.
  4981. However, throw `:skip' whenever an error is raised."
  4982. (condition-case e
  4983. (apply #'org-time-string-to-absolute args)
  4984. (org-diary-sexp-no-match (throw :skip nil))
  4985. (error
  4986. (message "%s; Skipping entry" (error-message-string e))
  4987. (throw :skip nil))))
  4988. (defun org-agenda-get-day-entries (file date &rest args)
  4989. "Does the work for `org-diary' and `org-agenda'.
  4990. FILE is the path to a file to be checked for entries. DATE is date like
  4991. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4992. which kind of entries should be extracted. For details about these, see
  4993. the documentation of `org-diary'."
  4994. (let* ((org-startup-folded nil)
  4995. (org-startup-align-all-tables nil)
  4996. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4997. (error "No such file %s" file))))
  4998. (if (not buffer)
  4999. ;; If file does not exist, signal it in diary nonetheless.
  5000. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5001. (with-current-buffer buffer
  5002. (unless (derived-mode-p 'org-mode)
  5003. (error "Agenda file %s is not in Org mode" file))
  5004. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5005. (setf org-agenda-current-date date)
  5006. (save-excursion
  5007. (save-restriction
  5008. (if (eq buffer org-agenda-restrict)
  5009. (narrow-to-region org-agenda-restrict-begin
  5010. org-agenda-restrict-end)
  5011. (widen))
  5012. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5013. ;; first in order to populate DEADLINES before passing it.
  5014. ;;
  5015. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5016. ;; guarding us from modifying `org-agenda-entry-types'.
  5017. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5018. (when (and (memq :scheduled args) (memq :scheduled* args))
  5019. (setf args (delq :scheduled* args)))
  5020. (cond
  5021. ((memq :deadline args)
  5022. (setf args (cons :deadline
  5023. (delq :deadline (delq :deadline* args)))))
  5024. ((memq :deadline* args)
  5025. (setf args (cons :deadline* (delq :deadline* args)))))
  5026. ;; Collect list of headlines. Return them flattened.
  5027. (let ((case-fold-search nil) results deadlines)
  5028. (org-dlet
  5029. ((date date))
  5030. (dolist (arg args (apply #'nconc (nreverse results)))
  5031. (pcase arg
  5032. ((and :todo (guard (org-agenda-today-p date)))
  5033. (push (org-agenda-get-todos) results))
  5034. (:timestamp
  5035. (push (org-agenda-get-blocks) results)
  5036. (push (org-agenda-get-timestamps deadlines) results))
  5037. (:sexp
  5038. (push (org-agenda-get-sexps) results))
  5039. (:scheduled
  5040. (push (org-agenda-get-scheduled deadlines) results))
  5041. (:scheduled*
  5042. (push (org-agenda-get-scheduled deadlines t) results))
  5043. (:closed
  5044. (push (org-agenda-get-progress) results))
  5045. (:deadline
  5046. (setf deadlines (org-agenda-get-deadlines))
  5047. (push deadlines results))
  5048. (:deadline*
  5049. (setf deadlines (org-agenda-get-deadlines t))
  5050. (push deadlines results))))))))))))
  5051. (defsubst org-em (x y list)
  5052. "Is X or Y a member of LIST?"
  5053. (or (memq x list) (memq y list)))
  5054. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5055. (defvar org-agenda-sorting-strategy-selected nil)
  5056. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5057. "Retrieve timestamp information for sorting agenda views.
  5058. Given a point or marker POM, returns a cons cell of the timestamp
  5059. and the timestamp type relevant for the sorting strategy in
  5060. `org-agenda-sorting-strategy-selected'."
  5061. (let (ts ts-date-type)
  5062. (save-match-data
  5063. (cond ((org-em 'scheduled-up 'scheduled-down
  5064. org-agenda-sorting-strategy-selected)
  5065. (setq ts (org-entry-get pom "SCHEDULED")
  5066. ts-date-type " scheduled"))
  5067. ((org-em 'deadline-up 'deadline-down
  5068. org-agenda-sorting-strategy-selected)
  5069. (setq ts (org-entry-get pom "DEADLINE")
  5070. ts-date-type " deadline"))
  5071. ((org-em 'ts-up 'ts-down
  5072. org-agenda-sorting-strategy-selected)
  5073. (setq ts (org-entry-get pom "TIMESTAMP")
  5074. ts-date-type " timestamp"))
  5075. ((org-em 'tsia-up 'tsia-down
  5076. org-agenda-sorting-strategy-selected)
  5077. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5078. ts-date-type " timestamp_ia"))
  5079. ((org-em 'timestamp-up 'timestamp-down
  5080. org-agenda-sorting-strategy-selected)
  5081. (setq ts (or (org-entry-get pom "SCHEDULED")
  5082. (org-entry-get pom "DEADLINE")
  5083. (org-entry-get pom "TIMESTAMP")
  5084. (org-entry-get pom "TIMESTAMP_IA"))
  5085. ts-date-type ""))
  5086. (t (setq ts-date-type "")))
  5087. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5088. ts-date-type))))
  5089. (defun org-agenda-get-todos ()
  5090. "Return the TODO information for agenda display."
  5091. (let* ((props (list 'face nil
  5092. 'done-face 'org-agenda-done
  5093. 'org-not-done-regexp org-not-done-regexp
  5094. 'org-todo-regexp org-todo-regexp
  5095. 'org-complex-heading-regexp org-complex-heading-regexp
  5096. 'mouse-face 'highlight
  5097. 'help-echo
  5098. (format "mouse-2 or RET jump to org file %s"
  5099. (abbreviate-file-name buffer-file-name))))
  5100. (case-fold-search nil)
  5101. (regexp (format org-heading-keyword-regexp-format
  5102. (cond
  5103. ((and org-select-this-todo-keyword
  5104. (equal org-select-this-todo-keyword "*"))
  5105. org-todo-regexp)
  5106. (org-select-this-todo-keyword
  5107. (concat "\\("
  5108. (mapconcat #'identity
  5109. (org-split-string
  5110. org-select-this-todo-keyword
  5111. "|")
  5112. "\\|")
  5113. "\\)"))
  5114. (t org-not-done-regexp))))
  5115. marker priority category level tags todo-state
  5116. ts-date ts-date-type ts-date-pair
  5117. ee txt beg end inherited-tags todo-state-end-pos
  5118. effort effort-minutes)
  5119. (goto-char (point-min))
  5120. (while (re-search-forward regexp nil t)
  5121. (catch :skip
  5122. (save-match-data
  5123. (beginning-of-line)
  5124. (org-agenda-skip)
  5125. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5126. (unless (and (setq todo-state (org-get-todo-state))
  5127. (setq todo-state-end-pos (match-end 2)))
  5128. (goto-char end)
  5129. (throw :skip nil))
  5130. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5131. (goto-char (1+ beg))
  5132. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5133. (throw :skip nil)))
  5134. (goto-char (match-beginning 2))
  5135. (setq marker (org-agenda-new-marker (match-beginning 0))
  5136. category (org-get-category)
  5137. effort (save-match-data (or (get-text-property (point) 'effort)
  5138. (org-entry-get (point) org-effort-property)))
  5139. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5140. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5141. ts-date (car ts-date-pair)
  5142. ts-date-type (cdr ts-date-pair)
  5143. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5144. inherited-tags
  5145. (or (eq org-agenda-show-inherited-tags 'always)
  5146. (and (listp org-agenda-show-inherited-tags)
  5147. (memq 'todo org-agenda-show-inherited-tags))
  5148. (and (eq org-agenda-show-inherited-tags t)
  5149. (or (eq org-agenda-use-tag-inheritance t)
  5150. (memq 'todo org-agenda-use-tag-inheritance))))
  5151. tags (org-get-tags nil (not inherited-tags))
  5152. level (make-string (org-reduced-level (org-outline-level)) ? )
  5153. txt (org-agenda-format-item ""
  5154. (org-add-props txt nil
  5155. 'effort effort
  5156. 'effort-minutes effort-minutes)
  5157. level category tags t)
  5158. priority (1+ (org-get-priority txt)))
  5159. (org-add-props txt props
  5160. 'org-marker marker 'org-hd-marker marker
  5161. 'priority priority
  5162. 'effort effort 'effort-minutes effort-minutes
  5163. 'level level
  5164. 'ts-date ts-date
  5165. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5166. (push txt ee)
  5167. (if org-agenda-todo-list-sublevels
  5168. (goto-char todo-state-end-pos)
  5169. (org-end-of-subtree 'invisible))))
  5170. (nreverse ee)))
  5171. (defun org-agenda-todo-custom-ignore-p (time n)
  5172. "Check whether timestamp is farther away than n number of days.
  5173. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5174. `org-agenda-todo-ignore-scheduled' or
  5175. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5176. (let ((days (org-time-stamp-to-now
  5177. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5178. (if (>= n 0)
  5179. (>= days n)
  5180. (<= days n))))
  5181. ;;;###autoload
  5182. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5183. (&optional end)
  5184. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5185. (when (or org-agenda-todo-ignore-with-date
  5186. org-agenda-todo-ignore-scheduled
  5187. org-agenda-todo-ignore-deadlines
  5188. org-agenda-todo-ignore-timestamp)
  5189. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5190. (save-excursion
  5191. (or (and org-agenda-todo-ignore-with-date
  5192. (re-search-forward org-ts-regexp end t))
  5193. (and org-agenda-todo-ignore-scheduled
  5194. (re-search-forward org-scheduled-time-regexp end t)
  5195. (cond
  5196. ((eq org-agenda-todo-ignore-scheduled 'future)
  5197. (> (org-time-stamp-to-now
  5198. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5199. 0))
  5200. ((eq org-agenda-todo-ignore-scheduled 'past)
  5201. (<= (org-time-stamp-to-now
  5202. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5203. 0))
  5204. ((numberp org-agenda-todo-ignore-scheduled)
  5205. (org-agenda-todo-custom-ignore-p
  5206. (match-string 1) org-agenda-todo-ignore-scheduled))
  5207. (t)))
  5208. (and org-agenda-todo-ignore-deadlines
  5209. (re-search-forward org-deadline-time-regexp end t)
  5210. (cond
  5211. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5212. ((eq org-agenda-todo-ignore-deadlines 'far)
  5213. (not (org-deadline-close-p (match-string 1))))
  5214. ((eq org-agenda-todo-ignore-deadlines 'future)
  5215. (> (org-time-stamp-to-now
  5216. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5217. 0))
  5218. ((eq org-agenda-todo-ignore-deadlines 'past)
  5219. (<= (org-time-stamp-to-now
  5220. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5221. 0))
  5222. ((numberp org-agenda-todo-ignore-deadlines)
  5223. (org-agenda-todo-custom-ignore-p
  5224. (match-string 1) org-agenda-todo-ignore-deadlines))
  5225. (t (org-deadline-close-p (match-string 1)))))
  5226. (and org-agenda-todo-ignore-timestamp
  5227. (let ((buffer (current-buffer))
  5228. (regexp
  5229. (concat
  5230. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5231. (start (point)))
  5232. ;; Copy current buffer into a temporary one
  5233. (with-temp-buffer
  5234. (insert-buffer-substring buffer start end)
  5235. (goto-char (point-min))
  5236. ;; Delete SCHEDULED and DEADLINE items
  5237. (while (re-search-forward regexp end t)
  5238. (delete-region (match-beginning 0) (match-end 0)))
  5239. (goto-char (point-min))
  5240. ;; No search for timestamp left
  5241. (when (re-search-forward org-ts-regexp nil t)
  5242. (cond
  5243. ((eq org-agenda-todo-ignore-timestamp 'future)
  5244. (> (org-time-stamp-to-now
  5245. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5246. 0))
  5247. ((eq org-agenda-todo-ignore-timestamp 'past)
  5248. (<= (org-time-stamp-to-now
  5249. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5250. 0))
  5251. ((numberp org-agenda-todo-ignore-timestamp)
  5252. (org-agenda-todo-custom-ignore-p
  5253. (match-string 1) org-agenda-todo-ignore-timestamp))
  5254. (t))))))))))
  5255. (defun org-agenda-get-timestamps (&optional deadlines)
  5256. "Return the date stamp information for agenda display.
  5257. Optional argument DEADLINES is a list of deadline items to be
  5258. displayed in agenda view."
  5259. (with-no-warnings (defvar date))
  5260. (let* ((props (list 'face 'org-agenda-calendar-event
  5261. 'org-not-done-regexp org-not-done-regexp
  5262. 'org-todo-regexp org-todo-regexp
  5263. 'org-complex-heading-regexp org-complex-heading-regexp
  5264. 'mouse-face 'highlight
  5265. 'help-echo
  5266. (format "mouse-2 or RET jump to Org file %s"
  5267. (abbreviate-file-name buffer-file-name))))
  5268. (current (calendar-absolute-from-gregorian date))
  5269. (today (org-today))
  5270. (deadline-position-alist
  5271. (mapcar (lambda (d)
  5272. (let ((m (get-text-property 0 'org-hd-marker d)))
  5273. (and m (marker-position m))))
  5274. deadlines))
  5275. ;; Match time-stamps set to current date, time-stamps with
  5276. ;; a repeater, and S-exp time-stamps.
  5277. (regexp
  5278. (concat
  5279. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5280. (regexp-quote
  5281. (substring
  5282. (format-time-string
  5283. (car org-time-stamp-formats)
  5284. (encode-time ; DATE bound by calendar
  5285. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5286. 1 11))
  5287. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5288. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5289. timestamp-items)
  5290. (goto-char (point-min))
  5291. (while (re-search-forward regexp nil t)
  5292. ;; Skip date ranges, scheduled and deadlines, which are handled
  5293. ;; specially. Also skip time-stamps before first headline as
  5294. ;; there would be no entry to add to the agenda. Eventually,
  5295. ;; ignore clock entries.
  5296. (catch :skip
  5297. (save-match-data
  5298. (when (or (org-at-date-range-p)
  5299. (org-at-planning-p)
  5300. (org-before-first-heading-p)
  5301. (and org-agenda-include-inactive-timestamps
  5302. (org-at-clock-log-p))
  5303. (not (org-at-timestamp-p 'agenda)))
  5304. (throw :skip nil))
  5305. (org-agenda-skip))
  5306. (let* ((pos (match-beginning 0))
  5307. (repeat (match-string 1))
  5308. (sexp-entry (match-string 3))
  5309. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5310. (save-excursion
  5311. (goto-char pos)
  5312. (looking-at org-ts-regexp-both)
  5313. (match-string 0))))
  5314. (todo-state (org-get-todo-state))
  5315. (warntime (get-text-property (point) 'org-appt-warntime))
  5316. (done? (member todo-state org-done-keywords)))
  5317. ;; Possibly skip done tasks.
  5318. (when (and done? org-agenda-skip-timestamp-if-done)
  5319. (throw :skip t))
  5320. ;; S-exp entry doesn't match current day: skip it.
  5321. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5322. (throw :skip nil))
  5323. (when repeat
  5324. (let* ((past
  5325. ;; A repeating time stamp is shown at its base
  5326. ;; date and every repeated date up to TODAY. If
  5327. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5328. ;; however, only the last repeat before today
  5329. ;; (inclusive) is shown.
  5330. (org-agenda--timestamp-to-absolute
  5331. repeat
  5332. (if (or (> current today)
  5333. (eq org-agenda-prefer-last-repeat t)
  5334. (member todo-state org-agenda-prefer-last-repeat))
  5335. today
  5336. current)
  5337. 'past (current-buffer) pos))
  5338. (future
  5339. ;; Display every repeated date past TODAY
  5340. ;; (exclusive) unless
  5341. ;; `org-agenda-show-future-repeats' is nil. If
  5342. ;; this variable is set to `next', only display
  5343. ;; the first repeated date after TODAY
  5344. ;; (exclusive).
  5345. (cond
  5346. ((<= current today) past)
  5347. ((not org-agenda-show-future-repeats) past)
  5348. (t
  5349. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5350. (1+ today)
  5351. current)))
  5352. (org-agenda--timestamp-to-absolute
  5353. repeat base 'future (current-buffer) pos))))))
  5354. (when (and (/= current past) (/= current future))
  5355. (throw :skip nil))))
  5356. (save-excursion
  5357. (re-search-backward org-outline-regexp-bol nil t)
  5358. ;; Possibly skip time-stamp when a deadline is set.
  5359. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5360. (assq (point) deadline-position-alist))
  5361. (throw :skip nil))
  5362. (let* ((category (org-get-category pos))
  5363. (effort (org-entry-get pos org-effort-property))
  5364. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5365. (inherited-tags
  5366. (or (eq org-agenda-show-inherited-tags 'always)
  5367. (and (consp org-agenda-show-inherited-tags)
  5368. (memq 'agenda org-agenda-show-inherited-tags))
  5369. (and (eq org-agenda-show-inherited-tags t)
  5370. (or (eq org-agenda-use-tag-inheritance t)
  5371. (memq 'agenda
  5372. org-agenda-use-tag-inheritance)))))
  5373. (tags (org-get-tags nil (not inherited-tags)))
  5374. (level (make-string (org-reduced-level (org-outline-level))
  5375. ?\s))
  5376. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5377. (match-string 1)))
  5378. (inactive? (= (char-after pos) ?\[))
  5379. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5380. (item
  5381. (org-agenda-format-item
  5382. (and inactive? org-agenda-inactive-leader)
  5383. (org-add-props head nil
  5384. 'effort effort
  5385. 'effort-minutes effort-minutes)
  5386. level category tags time-stamp org-ts-regexp habit?)))
  5387. (org-add-props item props
  5388. 'priority (if habit?
  5389. (org-habit-get-priority (org-habit-parse-todo))
  5390. (org-get-priority item))
  5391. 'org-marker (org-agenda-new-marker pos)
  5392. 'org-hd-marker (org-agenda-new-marker)
  5393. 'date date
  5394. 'level level
  5395. 'effort effort 'effort-minutes effort-minutes
  5396. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5397. current)
  5398. 'todo-state todo-state
  5399. 'warntime warntime
  5400. 'type "timestamp")
  5401. (push item timestamp-items))))
  5402. (when org-agenda-skip-additional-timestamps-same-entry
  5403. (outline-next-heading))))
  5404. (nreverse timestamp-items)))
  5405. (defun org-agenda-get-sexps ()
  5406. "Return the sexp information for agenda display."
  5407. (require 'diary-lib)
  5408. (with-no-warnings (defvar date) (defvar entry))
  5409. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5410. 'mouse-face 'highlight
  5411. 'help-echo
  5412. (format "mouse-2 or RET jump to org file %s"
  5413. (abbreviate-file-name buffer-file-name))))
  5414. (regexp "^&?%%(")
  5415. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5416. ;; so as to "hide" any current binding for it?
  5417. marker category extra level ee txt tags entry
  5418. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5419. effort effort-minutes)
  5420. (goto-char (point-min))
  5421. (while (re-search-forward regexp nil t)
  5422. (catch :skip
  5423. (org-agenda-skip)
  5424. (setq beg (match-beginning 0))
  5425. (goto-char (1- (match-end 0)))
  5426. (setq b (point))
  5427. (forward-sexp 1)
  5428. (setq sexp (buffer-substring b (point)))
  5429. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5430. (org-trim (match-string 1))
  5431. ""))
  5432. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5433. (when result
  5434. (setq marker (org-agenda-new-marker beg)
  5435. level (make-string (org-reduced-level (org-outline-level)) ? )
  5436. category (org-get-category beg)
  5437. effort (save-match-data (or (get-text-property (point) 'effort)
  5438. (org-entry-get (point) org-effort-property)))
  5439. inherited-tags
  5440. (or (eq org-agenda-show-inherited-tags 'always)
  5441. (and (listp org-agenda-show-inherited-tags)
  5442. (memq 'agenda org-agenda-show-inherited-tags))
  5443. (and (eq org-agenda-show-inherited-tags t)
  5444. (or (eq org-agenda-use-tag-inheritance t)
  5445. (memq 'agenda org-agenda-use-tag-inheritance))))
  5446. tags (org-get-tags nil (not inherited-tags))
  5447. todo-state (org-get-todo-state)
  5448. warntime (get-text-property (point) 'org-appt-warntime)
  5449. extra nil)
  5450. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5451. (dolist (r (if (stringp result)
  5452. (list result)
  5453. result)) ;; we expect a list here
  5454. (when (and org-agenda-diary-sexp-prefix
  5455. (string-match org-agenda-diary-sexp-prefix r))
  5456. (setq extra (match-string 0 r)
  5457. r (replace-match "" nil nil r)))
  5458. (if (string-match "\\S-" r)
  5459. (setq txt r)
  5460. (setq txt "SEXP entry returned empty string"))
  5461. (setq txt (org-agenda-format-item extra
  5462. (org-add-props txt nil
  5463. 'effort effort
  5464. 'effort-minutes effort-minutes)
  5465. level category tags 'time))
  5466. (org-add-props txt props 'org-marker marker
  5467. 'date date 'todo-state todo-state
  5468. 'effort effort 'effort-minutes effort-minutes
  5469. 'level level 'type "sexp" 'warntime warntime)
  5470. (push txt ee)))))
  5471. (nreverse ee)))
  5472. ;; Calendar sanity: define some functions that are independent of
  5473. ;; `calendar-date-style'.
  5474. (defun org-anniversary (year month day &optional mark)
  5475. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5476. (with-no-warnings
  5477. (let ((calendar-date-style 'iso))
  5478. (diary-anniversary year month day mark))))
  5479. (defun org-cyclic (N year month day &optional mark)
  5480. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5481. (with-no-warnings
  5482. (let ((calendar-date-style 'iso))
  5483. (diary-cyclic N year month day mark))))
  5484. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5485. "Like `diary-block', but with fixed (ISO) order of arguments."
  5486. (with-no-warnings
  5487. (let ((calendar-date-style 'iso))
  5488. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5489. (defun org-date (year month day &optional mark)
  5490. "Like `diary-date', but with fixed (ISO) order of arguments."
  5491. (with-no-warnings
  5492. (let ((calendar-date-style 'iso))
  5493. (diary-date year month day mark))))
  5494. ;; Define the `org-class' function
  5495. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5496. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5497. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5498. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5499. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5500. `holidays', then any date that is known by the Emacs calendar to be a
  5501. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5502. then those holidays will be skipped."
  5503. (with-no-warnings (defvar date) (defvar entry))
  5504. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5505. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5506. (d (calendar-absolute-from-gregorian date))
  5507. (h (when skip-weeks (calendar-check-holidays date))))
  5508. (and
  5509. (<= date1 d)
  5510. (<= d date2)
  5511. (= (calendar-day-of-week date) dayname)
  5512. (or (not skip-weeks)
  5513. (progn
  5514. (require 'cal-iso)
  5515. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5516. (not (or (and h (memq 'holidays skip-weeks))
  5517. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5518. entry)))
  5519. (defalias 'org-get-closed #'org-agenda-get-progress)
  5520. (defun org-agenda-get-progress ()
  5521. "Return the logged TODO entries for agenda display."
  5522. (with-no-warnings (defvar date))
  5523. (let* ((props (list 'mouse-face 'highlight
  5524. 'org-not-done-regexp org-not-done-regexp
  5525. 'org-todo-regexp org-todo-regexp
  5526. 'org-complex-heading-regexp org-complex-heading-regexp
  5527. 'help-echo
  5528. (format "mouse-2 or RET jump to org file %s"
  5529. (abbreviate-file-name buffer-file-name))))
  5530. (items (if (consp org-agenda-show-log-scoped)
  5531. org-agenda-show-log-scoped
  5532. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5533. '(clock)
  5534. org-agenda-log-mode-items)))
  5535. (parts
  5536. (delq nil
  5537. (list
  5538. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5539. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5540. (when (memq 'state items)
  5541. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5542. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5543. (error "`org-agenda-log-mode-items' is empty")))
  5544. (regexp (concat
  5545. "\\(" parts-re "\\)"
  5546. " *\\["
  5547. (regexp-quote
  5548. (substring
  5549. (format-time-string
  5550. (car org-time-stamp-formats)
  5551. (encode-time ; DATE bound by calendar
  5552. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5553. 1 11))))
  5554. (org-agenda-search-headline-for-time nil)
  5555. marker hdmarker priority category level tags closedp type
  5556. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5557. effort effort-minutes)
  5558. (goto-char (point-min))
  5559. (while (re-search-forward regexp nil t)
  5560. (catch :skip
  5561. (org-agenda-skip)
  5562. (setq marker (org-agenda-new-marker (match-beginning 0))
  5563. closedp (equal (match-string 1) org-closed-string)
  5564. statep (equal (string-to-char (match-string 1)) ?-)
  5565. clockp (not (or closedp statep))
  5566. state (and statep (match-string 2))
  5567. category (org-get-category (match-beginning 0))
  5568. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5569. effort (save-match-data (or (get-text-property (point) 'effort)
  5570. (org-entry-get (point) org-effort-property))))
  5571. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5572. (when (string-match "\\]" timestr)
  5573. ;; substring should only run to end of time stamp
  5574. (setq rest (substring timestr (match-end 0))
  5575. timestr (substring timestr 0 (match-end 0)))
  5576. (if (and (not closedp) (not statep)
  5577. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5578. rest))
  5579. (progn (setq timestr (concat (substring timestr 0 -1)
  5580. "-" (match-string 1 rest) "]"))
  5581. (setq clocked (match-string 2 rest)))
  5582. (setq clocked "-")))
  5583. (save-excursion
  5584. (setq extra
  5585. (cond
  5586. ((not org-agenda-log-mode-add-notes) nil)
  5587. (statep
  5588. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5589. (match-string 1)))
  5590. (clockp
  5591. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5592. (match-string 1)))))
  5593. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5594. (throw :skip nil)
  5595. (goto-char (match-beginning 0))
  5596. (setq hdmarker (org-agenda-new-marker)
  5597. inherited-tags
  5598. (or (eq org-agenda-show-inherited-tags 'always)
  5599. (and (listp org-agenda-show-inherited-tags)
  5600. (memq 'todo org-agenda-show-inherited-tags))
  5601. (and (eq org-agenda-show-inherited-tags t)
  5602. (or (eq org-agenda-use-tag-inheritance t)
  5603. (memq 'todo org-agenda-use-tag-inheritance))))
  5604. tags (org-get-tags nil (not inherited-tags))
  5605. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5606. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5607. (setq txt (match-string 1))
  5608. (when extra
  5609. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5610. (setq txt (concat (substring txt 0 (match-beginning 1))
  5611. " - " extra " " (match-string 2 txt)))
  5612. (setq txt (concat txt " - " extra))))
  5613. (setq txt (org-agenda-format-item
  5614. (cond
  5615. (closedp "Closed: ")
  5616. (statep (concat "State: (" state ")"))
  5617. (t (concat "Clocked: (" clocked ")")))
  5618. (org-add-props txt nil
  5619. 'effort effort
  5620. 'effort-minutes effort-minutes)
  5621. level category tags timestr)))
  5622. (setq type (cond (closedp "closed")
  5623. (statep "state")
  5624. (t "clock")))
  5625. (setq priority 100000)
  5626. (org-add-props txt props
  5627. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5628. 'priority priority 'level level
  5629. 'effort effort 'effort-minutes effort-minutes
  5630. 'type type 'date date
  5631. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5632. (push txt ee))
  5633. (goto-char (point-at-eol))))
  5634. (nreverse ee)))
  5635. (defun org-agenda-show-clocking-issues ()
  5636. "Add overlays, showing issues with clocking.
  5637. See also the user option `org-agenda-clock-consistency-checks'."
  5638. (interactive)
  5639. (let* ((pl org-agenda-clock-consistency-checks)
  5640. (re (concat "^[ \t]*"
  5641. org-clock-string
  5642. "[ \t]+"
  5643. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5644. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5645. (tlstart 0.)
  5646. (tlend 0.)
  5647. (maxtime (org-duration-to-minutes
  5648. (or (plist-get pl :max-duration) "24:00")))
  5649. (mintime (org-duration-to-minutes
  5650. (or (plist-get pl :min-duration) 0)))
  5651. (maxgap (org-duration-to-minutes
  5652. ;; default 30:00 means never complain
  5653. (or (plist-get pl :max-gap) "30:00")))
  5654. (gapok (mapcar #'org-duration-to-minutes
  5655. (plist-get pl :gap-ok-around)))
  5656. (def-face (or (plist-get pl :default-face)
  5657. '((:background "DarkRed") (:foreground "white"))))
  5658. issue face m te ts dt ov)
  5659. (goto-char (point-min))
  5660. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5661. (setq issue nil face def-face)
  5662. (catch 'next
  5663. (setq m (org-get-at-bol 'org-marker)
  5664. te nil ts nil)
  5665. (unless (and m (markerp m))
  5666. (setq issue "No valid clock line") (throw 'next t))
  5667. (org-with-point-at m
  5668. (save-excursion
  5669. (goto-char (point-at-bol))
  5670. (unless (looking-at re)
  5671. (error "No valid Clock line")
  5672. (throw 'next t))
  5673. (unless (match-end 3)
  5674. (setq issue
  5675. (format
  5676. "No end time: (%s)"
  5677. (org-duration-from-minutes
  5678. (floor
  5679. (- (float-time (org-current-time))
  5680. (float-time (org-time-string-to-time (match-string 1))))
  5681. 60)))
  5682. face (or (plist-get pl :no-end-time-face) face))
  5683. (throw 'next t))
  5684. (setq ts (match-string 1)
  5685. te (match-string 3)
  5686. ts (float-time (org-time-string-to-time ts))
  5687. te (float-time (org-time-string-to-time te))
  5688. dt (- te ts))))
  5689. (cond
  5690. ((> dt (* 60 maxtime))
  5691. ;; a very long clocking chunk
  5692. (setq issue (format "Clocking interval is very long: %s"
  5693. (org-duration-from-minutes (floor dt 60)))
  5694. face (or (plist-get pl :long-face) face)))
  5695. ((< dt (* 60 mintime))
  5696. ;; a very short clocking chunk
  5697. (setq issue (format "Clocking interval is very short: %s"
  5698. (org-duration-from-minutes (floor dt 60)))
  5699. face (or (plist-get pl :short-face) face)))
  5700. ((and (> tlend 0) (< ts tlend))
  5701. ;; Two clock entries are overlapping
  5702. (setq issue (format "Clocking overlap: %d minutes"
  5703. (/ (- tlend ts) 60))
  5704. face (or (plist-get pl :overlap-face) face)))
  5705. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5706. ;; There is a gap, lets see if we need to report it
  5707. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5708. (setq issue (format "Clocking gap: %d minutes"
  5709. (/ (- ts tlend) 60))
  5710. face (or (plist-get pl :gap-face) face))))
  5711. (t nil)))
  5712. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5713. (when issue
  5714. ;; OK, there was some issue, add an overlay to show the issue
  5715. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5716. (overlay-put ov 'before-string
  5717. (concat
  5718. (org-add-props
  5719. (format "%-43s" (concat " " issue))
  5720. nil
  5721. 'face face)
  5722. "\n"))
  5723. (overlay-put ov 'evaporate t)))))
  5724. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5725. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5726. (catch 'exit
  5727. (unless ok-list
  5728. ;; there are no OK times for gaps...
  5729. (throw 'exit nil))
  5730. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5731. ;; This is more than 24 hours, so it is OK.
  5732. ;; because we have at least one OK time, that must be in the
  5733. ;; 24 hour interval.
  5734. (throw 'exit t))
  5735. ;; We have a shorter gap.
  5736. ;; Now we have to get the minute of the day when these times are
  5737. (let* ((t1dec (decode-time t1))
  5738. (t2dec (decode-time t2))
  5739. ;; compute the minute on the day
  5740. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5741. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5742. (when (< min2 min1)
  5743. ;; if min2 is smaller than min1, this means it is on the next day.
  5744. ;; Wrap it to after midnight.
  5745. (setq min2 (+ min2 1440)))
  5746. ;; Now check if any of the OK times is in the gap
  5747. (mapc (lambda (x)
  5748. ;; Wrap the time to after midnight if necessary
  5749. (when (< x min1) (setq x (+ x 1440)))
  5750. ;; Check if in interval
  5751. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5752. ok-list)
  5753. ;; Nope, this gap is not OK
  5754. nil)))
  5755. (defun org-agenda-get-deadlines (&optional with-hour)
  5756. "Return the deadline information for agenda display.
  5757. When WITH-HOUR is non-nil, only return deadlines with an hour
  5758. specification like [h]h:mm."
  5759. (with-no-warnings (defvar date))
  5760. (let* ((props (list 'mouse-face 'highlight
  5761. 'org-not-done-regexp org-not-done-regexp
  5762. 'org-todo-regexp org-todo-regexp
  5763. 'org-complex-heading-regexp org-complex-heading-regexp
  5764. 'help-echo
  5765. (format "mouse-2 or RET jump to org file %s"
  5766. (abbreviate-file-name buffer-file-name))))
  5767. (regexp (if with-hour
  5768. org-deadline-time-hour-regexp
  5769. org-deadline-time-regexp))
  5770. (today (org-today))
  5771. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5772. (current (calendar-absolute-from-gregorian date))
  5773. deadline-items)
  5774. (goto-char (point-min))
  5775. (if (org-element--cache-active-p)
  5776. (org-element-cache-map
  5777. (lambda (el)
  5778. (when (and (org-element-property :deadline el)
  5779. (or (not with-hour)
  5780. (org-element-property
  5781. :hour-start
  5782. (org-element-property :deadline el))
  5783. (org-element-property
  5784. :hour-end
  5785. (org-element-property :deadline el))))
  5786. (goto-char (org-element-property :contents-begin el))
  5787. (catch :skip
  5788. (org-agenda-skip el)
  5789. (let* ((s (substring (org-element-property
  5790. :raw-value
  5791. (org-element-property :deadline el))
  5792. 1 -1))
  5793. (pos (save-excursion
  5794. (goto-char (org-element-property :contents-begin el))
  5795. ;; We intentionally leave NOERROR
  5796. ;; argument in `re-search-forward' nil. If
  5797. ;; the search fails here, something went
  5798. ;; wrong and we are looking at
  5799. ;; non-matching headline.
  5800. (re-search-forward regexp (line-end-position))
  5801. (1- (match-beginning 1))))
  5802. (todo-state (org-element-property :todo-keyword el))
  5803. (done? (eq 'done (org-element-property :todo-type el)))
  5804. (sexp? (eq 'diary
  5805. (org-element-property
  5806. :type (org-element-property :deadline el))))
  5807. ;; DEADLINE is the deadline date for the entry. It is
  5808. ;; either the base date or the last repeat, according
  5809. ;; to `org-agenda-prefer-last-repeat'.
  5810. (deadline
  5811. (cond
  5812. (sexp? (org-agenda--timestamp-to-absolute s current))
  5813. ((or (eq org-agenda-prefer-last-repeat t)
  5814. (member todo-state org-agenda-prefer-last-repeat))
  5815. (org-agenda--timestamp-to-absolute
  5816. s today 'past (current-buffer) pos))
  5817. (t (org-agenda--timestamp-to-absolute s))))
  5818. ;; REPEAT is the future repeat closest from CURRENT,
  5819. ;; according to `org-agenda-show-future-repeats'. If
  5820. ;; the latter is nil, or if the time stamp has no
  5821. ;; repeat part, default to DEADLINE.
  5822. (repeat
  5823. (cond
  5824. (sexp? deadline)
  5825. ((<= current today) deadline)
  5826. ((not org-agenda-show-future-repeats) deadline)
  5827. (t
  5828. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5829. (1+ today)
  5830. current)))
  5831. (org-agenda--timestamp-to-absolute
  5832. s base 'future (current-buffer) pos)))))
  5833. (diff (- deadline current))
  5834. (suppress-prewarning
  5835. (let ((scheduled
  5836. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5837. (org-element-property
  5838. :raw-value
  5839. (org-element-property :scheduled el)))))
  5840. (cond
  5841. ((not scheduled) nil)
  5842. ;; The current item has a scheduled date, so
  5843. ;; evaluate its prewarning lead time.
  5844. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5845. ;; Use global prewarning-restart lead time.
  5846. org-agenda-skip-deadline-prewarning-if-scheduled)
  5847. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5848. 'pre-scheduled)
  5849. ;; Set pre-warning to no earlier than SCHEDULED.
  5850. (min (- deadline
  5851. (org-agenda--timestamp-to-absolute scheduled))
  5852. org-deadline-warning-days))
  5853. ;; Set pre-warning to deadline.
  5854. (t 0))))
  5855. (wdays (or suppress-prewarning (org-get-wdays s))))
  5856. (cond
  5857. ;; Only display deadlines at their base date, at future
  5858. ;; repeat occurrences or in today agenda.
  5859. ((= current deadline) nil)
  5860. ((= current repeat) nil)
  5861. ((not today?) (throw :skip nil))
  5862. ;; Upcoming deadline: display within warning period WDAYS.
  5863. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5864. ;; Overdue deadline: warn about it for
  5865. ;; `org-deadline-past-days' duration.
  5866. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5867. ;; Possibly skip done tasks.
  5868. (when (and done?
  5869. (or org-agenda-skip-deadline-if-done
  5870. (/= deadline current)))
  5871. (throw :skip nil))
  5872. (save-excursion
  5873. (goto-char (org-element-property :begin el))
  5874. (let* ((category (org-get-category))
  5875. (effort (save-match-data (or (get-text-property (point) 'effort)
  5876. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5877. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5878. (level (make-string (org-element-property :level el)
  5879. ?\s))
  5880. (head (save-excursion
  5881. (goto-char (org-element-property :begin el))
  5882. (re-search-forward org-outline-regexp-bol)
  5883. (buffer-substring-no-properties (point) (line-end-position))))
  5884. (inherited-tags
  5885. (or (eq org-agenda-show-inherited-tags 'always)
  5886. (and (listp org-agenda-show-inherited-tags)
  5887. (memq 'agenda org-agenda-show-inherited-tags))
  5888. (and (eq org-agenda-show-inherited-tags t)
  5889. (or (eq org-agenda-use-tag-inheritance t)
  5890. (memq 'agenda
  5891. org-agenda-use-tag-inheritance)))))
  5892. (tags (org-get-tags el (not inherited-tags)))
  5893. (time
  5894. (cond
  5895. ;; No time of day designation if it is only
  5896. ;; a reminder.
  5897. ((and (/= current deadline) (/= current repeat)) nil)
  5898. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5899. (concat (substring s (match-beginning 1)) " "))
  5900. (t 'time)))
  5901. (item
  5902. (org-agenda-format-item
  5903. ;; Insert appropriate suffixes before deadlines.
  5904. ;; Those only apply to today agenda.
  5905. (pcase-let ((`(,now ,future ,past)
  5906. org-agenda-deadline-leaders))
  5907. (cond
  5908. ((and today? (< deadline today)) (format past (- diff)))
  5909. ((and today? (> deadline today)) (format future diff))
  5910. (t now)))
  5911. (org-add-props head nil
  5912. 'effort effort
  5913. 'effort-minutes effort-minutes)
  5914. level category tags time))
  5915. (face (org-agenda-deadline-face
  5916. (- 1 (/ (float diff) (max wdays 1)))))
  5917. (upcoming? (and today? (> deadline today)))
  5918. (warntime (get-text-property (point) 'org-appt-warntime)))
  5919. (org-add-props item props
  5920. 'org-marker (org-agenda-new-marker pos)
  5921. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5922. 'warntime warntime
  5923. 'level level
  5924. 'effort effort 'effort-minutes effort-minutes
  5925. 'ts-date deadline
  5926. 'priority
  5927. ;; Adjust priority to today reminders about deadlines.
  5928. ;; Overdue deadlines get the highest priority
  5929. ;; increase, then imminent deadlines and eventually
  5930. ;; more distant deadlines.
  5931. (let ((adjust (if today? (- diff) 0)))
  5932. (+ adjust (org-get-priority item)))
  5933. 'todo-state todo-state
  5934. 'type (if upcoming? "upcoming-deadline" "deadline")
  5935. 'date (if upcoming? date deadline)
  5936. 'face (if done? 'org-agenda-done face)
  5937. 'undone-face face
  5938. 'done-face 'org-agenda-done)
  5939. (push item deadline-items)))))))
  5940. :next-re regexp
  5941. :fail-re regexp
  5942. :narrow t)
  5943. (while (re-search-forward regexp nil t)
  5944. (catch :skip
  5945. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5946. (org-agenda-skip)
  5947. (let* ((s (match-string 1))
  5948. (pos (1- (match-beginning 1)))
  5949. (todo-state (save-match-data (org-get-todo-state)))
  5950. (done? (member todo-state org-done-keywords))
  5951. (sexp? (string-prefix-p "%%" s))
  5952. ;; DEADLINE is the deadline date for the entry. It is
  5953. ;; either the base date or the last repeat, according
  5954. ;; to `org-agenda-prefer-last-repeat'.
  5955. (deadline
  5956. (cond
  5957. (sexp? (org-agenda--timestamp-to-absolute s current))
  5958. ((or (eq org-agenda-prefer-last-repeat t)
  5959. (member todo-state org-agenda-prefer-last-repeat))
  5960. (org-agenda--timestamp-to-absolute
  5961. s today 'past (current-buffer) pos))
  5962. (t (org-agenda--timestamp-to-absolute s))))
  5963. ;; REPEAT is the future repeat closest from CURRENT,
  5964. ;; according to `org-agenda-show-future-repeats'. If
  5965. ;; the latter is nil, or if the time stamp has no
  5966. ;; repeat part, default to DEADLINE.
  5967. (repeat
  5968. (cond
  5969. (sexp? deadline)
  5970. ((<= current today) deadline)
  5971. ((not org-agenda-show-future-repeats) deadline)
  5972. (t
  5973. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5974. (1+ today)
  5975. current)))
  5976. (org-agenda--timestamp-to-absolute
  5977. s base 'future (current-buffer) pos)))))
  5978. (diff (- deadline current))
  5979. (suppress-prewarning
  5980. (let ((scheduled
  5981. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5982. (org-entry-get nil "SCHEDULED"))))
  5983. (cond
  5984. ((not scheduled) nil)
  5985. ;; The current item has a scheduled date, so
  5986. ;; evaluate its prewarning lead time.
  5987. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5988. ;; Use global prewarning-restart lead time.
  5989. org-agenda-skip-deadline-prewarning-if-scheduled)
  5990. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5991. 'pre-scheduled)
  5992. ;; Set pre-warning to no earlier than SCHEDULED.
  5993. (min (- deadline
  5994. (org-agenda--timestamp-to-absolute scheduled))
  5995. org-deadline-warning-days))
  5996. ;; Set pre-warning to deadline.
  5997. (t 0))))
  5998. (wdays (or suppress-prewarning (org-get-wdays s))))
  5999. (cond
  6000. ;; Only display deadlines at their base date, at future
  6001. ;; repeat occurrences or in today agenda.
  6002. ((= current deadline) nil)
  6003. ((= current repeat) nil)
  6004. ((not today?) (throw :skip nil))
  6005. ;; Upcoming deadline: display within warning period WDAYS.
  6006. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6007. ;; Overdue deadline: warn about it for
  6008. ;; `org-deadline-past-days' duration.
  6009. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6010. ;; Possibly skip done tasks.
  6011. (when (and done?
  6012. (or org-agenda-skip-deadline-if-done
  6013. (/= deadline current)))
  6014. (throw :skip nil))
  6015. (save-excursion
  6016. (re-search-backward "^\\*+[ \t]+" nil t)
  6017. (goto-char (match-end 0))
  6018. (let* ((category (org-get-category))
  6019. (effort (save-match-data (or (get-text-property (point) 'effort)
  6020. (org-entry-get (point) org-effort-property))))
  6021. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6022. (level (make-string (org-reduced-level (org-outline-level))
  6023. ?\s))
  6024. (head (buffer-substring-no-properties
  6025. (point) (line-end-position)))
  6026. (inherited-tags
  6027. (or (eq org-agenda-show-inherited-tags 'always)
  6028. (and (listp org-agenda-show-inherited-tags)
  6029. (memq 'agenda org-agenda-show-inherited-tags))
  6030. (and (eq org-agenda-show-inherited-tags t)
  6031. (or (eq org-agenda-use-tag-inheritance t)
  6032. (memq 'agenda
  6033. org-agenda-use-tag-inheritance)))))
  6034. (tags (org-get-tags nil (not inherited-tags)))
  6035. (time
  6036. (cond
  6037. ;; No time of day designation if it is only
  6038. ;; a reminder.
  6039. ((and (/= current deadline) (/= current repeat)) nil)
  6040. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6041. (concat (substring s (match-beginning 1)) " "))
  6042. (t 'time)))
  6043. (item
  6044. (org-agenda-format-item
  6045. ;; Insert appropriate suffixes before deadlines.
  6046. ;; Those only apply to today agenda.
  6047. (pcase-let ((`(,now ,future ,past)
  6048. org-agenda-deadline-leaders))
  6049. (cond
  6050. ((and today? (< deadline today)) (format past (- diff)))
  6051. ((and today? (> deadline today)) (format future diff))
  6052. (t now)))
  6053. (org-add-props head nil
  6054. 'effort effort
  6055. 'effort-minutes effort-minutes)
  6056. level category tags time))
  6057. (face (org-agenda-deadline-face
  6058. (- 1 (/ (float diff) (max wdays 1)))))
  6059. (upcoming? (and today? (> deadline today)))
  6060. (warntime (get-text-property (point) 'org-appt-warntime)))
  6061. (org-add-props item props
  6062. 'org-marker (org-agenda-new-marker pos)
  6063. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6064. 'warntime warntime
  6065. 'level level
  6066. 'effort effort 'effort-minutes effort-minutes
  6067. 'ts-date deadline
  6068. 'priority
  6069. ;; Adjust priority to today reminders about deadlines.
  6070. ;; Overdue deadlines get the highest priority
  6071. ;; increase, then imminent deadlines and eventually
  6072. ;; more distant deadlines.
  6073. (let ((adjust (if today? (- diff) 0)))
  6074. (+ adjust (org-get-priority item)))
  6075. 'todo-state todo-state
  6076. 'type (if upcoming? "upcoming-deadline" "deadline")
  6077. 'date (if upcoming? date deadline)
  6078. 'face (if done? 'org-agenda-done face)
  6079. 'undone-face face
  6080. 'done-face 'org-agenda-done)
  6081. (push item deadline-items)))))))
  6082. (nreverse deadline-items)))
  6083. (defun org-agenda-deadline-face (fraction)
  6084. "Return the face to displaying a deadline item.
  6085. FRACTION is what fraction of the head-warning time has passed."
  6086. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6087. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6088. "Return the scheduled information for agenda display.
  6089. Optional argument DEADLINES is a list of deadline items to be
  6090. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6091. scheduled items with an hour specification like [h]h:mm."
  6092. (with-no-warnings (defvar date))
  6093. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6094. 'org-todo-regexp org-todo-regexp
  6095. 'org-complex-heading-regexp org-complex-heading-regexp
  6096. 'done-face 'org-agenda-done
  6097. 'mouse-face 'highlight
  6098. 'help-echo
  6099. (format "mouse-2 or RET jump to Org file %s"
  6100. (abbreviate-file-name buffer-file-name))))
  6101. (regexp (if with-hour
  6102. org-scheduled-time-hour-regexp
  6103. org-scheduled-time-regexp))
  6104. (today (org-today))
  6105. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6106. (current (calendar-absolute-from-gregorian date))
  6107. (deadline-pos
  6108. (mapcar (lambda (d)
  6109. (let ((m (get-text-property 0 'org-hd-marker d)))
  6110. (and m (marker-position m))))
  6111. deadlines))
  6112. scheduled-items)
  6113. (goto-char (point-min))
  6114. (if (org-element--cache-active-p)
  6115. (org-element-cache-map
  6116. (lambda (el)
  6117. (when (and (org-element-property :scheduled el)
  6118. (or (not with-hour)
  6119. (org-element-property
  6120. :hour-start
  6121. (org-element-property :scheduled el))
  6122. (org-element-property
  6123. :hour-end
  6124. (org-element-property :scheduled el))))
  6125. (goto-char (org-element-property :contents-begin el))
  6126. (catch :skip
  6127. (org-agenda-skip el)
  6128. (let* ((s (substring (org-element-property
  6129. :raw-value
  6130. (org-element-property :scheduled el))
  6131. 1 -1))
  6132. (pos (save-excursion
  6133. (goto-char (org-element-property :contents-begin el))
  6134. ;; We intentionally leave NOERROR
  6135. ;; argument in `re-search-forward' nil. If
  6136. ;; the search fails here, something went
  6137. ;; wrong and we are looking at
  6138. ;; non-matching headline.
  6139. (re-search-forward regexp (line-end-position))
  6140. (1- (match-beginning 1))))
  6141. (todo-state (org-element-property :todo-keyword el))
  6142. (donep (eq 'done (org-element-property :todo-type el)))
  6143. (sexp? (eq 'diary
  6144. (org-element-property
  6145. :type (org-element-property :scheduled el))))
  6146. ;; SCHEDULE is the scheduled date for the entry. It is
  6147. ;; either the bare date or the last repeat, according
  6148. ;; to `org-agenda-prefer-last-repeat'.
  6149. (schedule
  6150. (cond
  6151. (sexp? (org-agenda--timestamp-to-absolute s current))
  6152. ((or (eq org-agenda-prefer-last-repeat t)
  6153. (member todo-state org-agenda-prefer-last-repeat))
  6154. (org-agenda--timestamp-to-absolute
  6155. s today 'past (current-buffer) pos))
  6156. (t (org-agenda--timestamp-to-absolute s))))
  6157. ;; REPEAT is the future repeat closest from CURRENT,
  6158. ;; according to `org-agenda-show-future-repeats'. If
  6159. ;; the latter is nil, or if the time stamp has no
  6160. ;; repeat part, default to SCHEDULE.
  6161. (repeat
  6162. (cond
  6163. (sexp? schedule)
  6164. ((<= current today) schedule)
  6165. ((not org-agenda-show-future-repeats) schedule)
  6166. (t
  6167. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6168. (1+ today)
  6169. current)))
  6170. (org-agenda--timestamp-to-absolute
  6171. s base 'future (current-buffer) pos)))))
  6172. (diff (- current schedule))
  6173. (warntime (get-text-property (point) 'org-appt-warntime))
  6174. (pastschedp (< schedule today))
  6175. (futureschedp (> schedule today))
  6176. (habitp (and (fboundp 'org-is-habit-p)
  6177. (string= "habit" (org-element-property :STYLE el))))
  6178. (suppress-delay
  6179. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6180. (org-element-property
  6181. :raw-value
  6182. (org-element-property :deadline el)))))
  6183. (cond
  6184. ((not deadline) nil)
  6185. ;; The current item has a deadline date, so
  6186. ;; evaluate its delay time.
  6187. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6188. ;; Use global delay time.
  6189. (- org-agenda-skip-scheduled-delay-if-deadline))
  6190. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6191. 'post-deadline)
  6192. ;; Set delay to no later than DEADLINE.
  6193. (min (- schedule
  6194. (org-agenda--timestamp-to-absolute deadline))
  6195. org-scheduled-delay-days))
  6196. (t 0))))
  6197. (ddays
  6198. (cond
  6199. ;; Nullify delay when a repeater triggered already
  6200. ;; and the delay is of the form --Xd.
  6201. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6202. (> schedule (org-agenda--timestamp-to-absolute s)))
  6203. 0)
  6204. (suppress-delay
  6205. (let ((org-scheduled-delay-days suppress-delay))
  6206. (org-get-wdays s t t)))
  6207. (t (org-get-wdays s t)))))
  6208. ;; Display scheduled items at base date (SCHEDULE), today if
  6209. ;; scheduled before the current date, and at any repeat past
  6210. ;; today. However, skip delayed items and items that have
  6211. ;; been displayed for more than `org-scheduled-past-days'.
  6212. (unless (and todayp
  6213. habitp
  6214. (bound-and-true-p org-habit-show-all-today))
  6215. (when (or (and (> ddays 0) (< diff ddays))
  6216. (> diff (or (and habitp org-habit-scheduled-past-days)
  6217. org-scheduled-past-days))
  6218. (> schedule current)
  6219. (and (/= current schedule)
  6220. (/= current today)
  6221. (/= current repeat)))
  6222. (throw :skip nil)))
  6223. ;; Possibly skip done tasks.
  6224. (when (and donep
  6225. (or org-agenda-skip-scheduled-if-done
  6226. (/= schedule current)))
  6227. (throw :skip nil))
  6228. ;; Skip entry if it already appears as a deadline, per
  6229. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6230. ;; doesn't apply to habits.
  6231. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6232. ((guard
  6233. (or (not (memq (line-beginning-position 0) deadline-pos))
  6234. habitp))
  6235. nil)
  6236. (`repeated-after-deadline
  6237. (let ((deadline (time-to-days
  6238. (when (org-element-property :deadline el)
  6239. (org-time-string-to-time
  6240. (org-element-property :deadline el))))))
  6241. (and (<= schedule deadline) (> current deadline))))
  6242. (`not-today pastschedp)
  6243. (`t t)
  6244. (_ nil))
  6245. (throw :skip nil))
  6246. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6247. ;; only show them for today. Also skip done habits.
  6248. (when (and habitp
  6249. (or donep
  6250. (not (bound-and-true-p org-habit-show-habits))
  6251. (and (not todayp)
  6252. (bound-and-true-p
  6253. org-habit-show-habits-only-for-today))))
  6254. (throw :skip nil))
  6255. (save-excursion
  6256. (goto-char (org-element-property :begin el))
  6257. (let* ((category (org-get-category))
  6258. (effort (save-match-data
  6259. (or (get-text-property (point) 'effort)
  6260. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6261. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6262. (inherited-tags
  6263. (or (eq org-agenda-show-inherited-tags 'always)
  6264. (and (listp org-agenda-show-inherited-tags)
  6265. (memq 'agenda org-agenda-show-inherited-tags))
  6266. (and (eq org-agenda-show-inherited-tags t)
  6267. (or (eq org-agenda-use-tag-inheritance t)
  6268. (memq 'agenda
  6269. org-agenda-use-tag-inheritance)))))
  6270. (tags (org-get-tags el (not inherited-tags)))
  6271. (level (make-string (org-element-property :level el)
  6272. ?\s))
  6273. (head (save-excursion
  6274. (goto-char (org-element-property :begin el))
  6275. (re-search-forward org-outline-regexp-bol)
  6276. (buffer-substring (point) (line-end-position))))
  6277. (time
  6278. (cond
  6279. ;; No time of day designation if it is only a
  6280. ;; reminder, except for habits, which always show
  6281. ;; the time of day. Habits are an exception
  6282. ;; because if there is a time of day, that is
  6283. ;; interpreted to mean they should usually happen
  6284. ;; then, even if doing the habit was missed.
  6285. ((and
  6286. (not habitp)
  6287. (/= current schedule)
  6288. (/= current repeat))
  6289. nil)
  6290. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6291. (concat (substring s (match-beginning 1)) " "))
  6292. (t 'time)))
  6293. (item
  6294. (org-agenda-format-item
  6295. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6296. ;; Show a reminder of a past scheduled today.
  6297. (if (and todayp pastschedp)
  6298. (format past diff)
  6299. first))
  6300. (org-add-props head nil
  6301. 'effort effort
  6302. 'effort-minutes effort-minutes)
  6303. level category tags time nil habitp))
  6304. (face (cond ((and (not habitp) pastschedp)
  6305. 'org-scheduled-previously)
  6306. ((and habitp futureschedp)
  6307. 'org-agenda-done)
  6308. (todayp 'org-scheduled-today)
  6309. (t 'org-scheduled)))
  6310. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6311. (org-add-props item props
  6312. 'undone-face face
  6313. 'face (if donep 'org-agenda-done face)
  6314. 'org-marker (org-agenda-new-marker pos)
  6315. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6316. 'type (if pastschedp "past-scheduled" "scheduled")
  6317. 'date (if pastschedp schedule date)
  6318. 'ts-date schedule
  6319. 'warntime warntime
  6320. 'level level
  6321. 'effort effort 'effort-minutes effort-minutes
  6322. 'priority (if habitp (org-habit-get-priority habitp)
  6323. (+ 99 diff (org-get-priority item)))
  6324. 'org-habit-p habitp
  6325. 'todo-state todo-state)
  6326. (push item scheduled-items)))))))
  6327. :next-re regexp
  6328. :fail-re regexp
  6329. :narrow t)
  6330. (while (re-search-forward regexp nil t)
  6331. (catch :skip
  6332. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6333. (org-agenda-skip)
  6334. (let* ((s (match-string 1))
  6335. (pos (1- (match-beginning 1)))
  6336. (todo-state (save-match-data (org-get-todo-state)))
  6337. (donep (member todo-state org-done-keywords))
  6338. (sexp? (string-prefix-p "%%" s))
  6339. ;; SCHEDULE is the scheduled date for the entry. It is
  6340. ;; either the bare date or the last repeat, according
  6341. ;; to `org-agenda-prefer-last-repeat'.
  6342. (schedule
  6343. (cond
  6344. (sexp? (org-agenda--timestamp-to-absolute s current))
  6345. ((or (eq org-agenda-prefer-last-repeat t)
  6346. (member todo-state org-agenda-prefer-last-repeat))
  6347. (org-agenda--timestamp-to-absolute
  6348. s today 'past (current-buffer) pos))
  6349. (t (org-agenda--timestamp-to-absolute s))))
  6350. ;; REPEAT is the future repeat closest from CURRENT,
  6351. ;; according to `org-agenda-show-future-repeats'. If
  6352. ;; the latter is nil, or if the time stamp has no
  6353. ;; repeat part, default to SCHEDULE.
  6354. (repeat
  6355. (cond
  6356. (sexp? schedule)
  6357. ((<= current today) schedule)
  6358. ((not org-agenda-show-future-repeats) schedule)
  6359. (t
  6360. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6361. (1+ today)
  6362. current)))
  6363. (org-agenda--timestamp-to-absolute
  6364. s base 'future (current-buffer) pos)))))
  6365. (diff (- current schedule))
  6366. (warntime (get-text-property (point) 'org-appt-warntime))
  6367. (pastschedp (< schedule today))
  6368. (futureschedp (> schedule today))
  6369. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6370. (suppress-delay
  6371. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6372. (org-entry-get nil "DEADLINE"))))
  6373. (cond
  6374. ((not deadline) nil)
  6375. ;; The current item has a deadline date, so
  6376. ;; evaluate its delay time.
  6377. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6378. ;; Use global delay time.
  6379. (- org-agenda-skip-scheduled-delay-if-deadline))
  6380. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6381. 'post-deadline)
  6382. ;; Set delay to no later than DEADLINE.
  6383. (min (- schedule
  6384. (org-agenda--timestamp-to-absolute deadline))
  6385. org-scheduled-delay-days))
  6386. (t 0))))
  6387. (ddays
  6388. (cond
  6389. ;; Nullify delay when a repeater triggered already
  6390. ;; and the delay is of the form --Xd.
  6391. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6392. (> schedule (org-agenda--timestamp-to-absolute s)))
  6393. 0)
  6394. (suppress-delay
  6395. (let ((org-scheduled-delay-days suppress-delay))
  6396. (org-get-wdays s t t)))
  6397. (t (org-get-wdays s t)))))
  6398. ;; Display scheduled items at base date (SCHEDULE), today if
  6399. ;; scheduled before the current date, and at any repeat past
  6400. ;; today. However, skip delayed items and items that have
  6401. ;; been displayed for more than `org-scheduled-past-days'.
  6402. (unless (and todayp
  6403. habitp
  6404. (bound-and-true-p org-habit-show-all-today))
  6405. (when (or (and (> ddays 0) (< diff ddays))
  6406. (> diff (or (and habitp org-habit-scheduled-past-days)
  6407. org-scheduled-past-days))
  6408. (> schedule current)
  6409. (and (/= current schedule)
  6410. (/= current today)
  6411. (/= current repeat)))
  6412. (throw :skip nil)))
  6413. ;; Possibly skip done tasks.
  6414. (when (and donep
  6415. (or org-agenda-skip-scheduled-if-done
  6416. (/= schedule current)))
  6417. (throw :skip nil))
  6418. ;; Skip entry if it already appears as a deadline, per
  6419. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6420. ;; doesn't apply to habits.
  6421. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6422. ((guard
  6423. (or (not (memq (line-beginning-position 0) deadline-pos))
  6424. habitp))
  6425. nil)
  6426. (`repeated-after-deadline
  6427. (let ((deadline (time-to-days
  6428. (org-get-deadline-time (point)))))
  6429. (and (<= schedule deadline) (> current deadline))))
  6430. (`not-today pastschedp)
  6431. (`t t)
  6432. (_ nil))
  6433. (throw :skip nil))
  6434. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6435. ;; only show them for today. Also skip done habits.
  6436. (when (and habitp
  6437. (or donep
  6438. (not (bound-and-true-p org-habit-show-habits))
  6439. (and (not todayp)
  6440. (bound-and-true-p
  6441. org-habit-show-habits-only-for-today))))
  6442. (throw :skip nil))
  6443. (save-excursion
  6444. (re-search-backward "^\\*+[ \t]+" nil t)
  6445. (goto-char (match-end 0))
  6446. (let* ((category (org-get-category))
  6447. (effort (save-match-data (or (get-text-property (point) 'effort)
  6448. (org-entry-get (point) org-effort-property))))
  6449. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6450. (inherited-tags
  6451. (or (eq org-agenda-show-inherited-tags 'always)
  6452. (and (listp org-agenda-show-inherited-tags)
  6453. (memq 'agenda org-agenda-show-inherited-tags))
  6454. (and (eq org-agenda-show-inherited-tags t)
  6455. (or (eq org-agenda-use-tag-inheritance t)
  6456. (memq 'agenda
  6457. org-agenda-use-tag-inheritance)))))
  6458. (tags (org-get-tags nil (not inherited-tags)))
  6459. (level (make-string (org-reduced-level (org-outline-level))
  6460. ?\s))
  6461. (head (buffer-substring (point) (line-end-position)))
  6462. (time
  6463. (cond
  6464. ;; No time of day designation if it is only a
  6465. ;; reminder, except for habits, which always show
  6466. ;; the time of day. Habits are an exception
  6467. ;; because if there is a time of day, that is
  6468. ;; interpreted to mean they should usually happen
  6469. ;; then, even if doing the habit was missed.
  6470. ((and
  6471. (not habitp)
  6472. (/= current schedule)
  6473. (/= current repeat))
  6474. nil)
  6475. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6476. (concat (substring s (match-beginning 1)) " "))
  6477. (t 'time)))
  6478. (item
  6479. (org-agenda-format-item
  6480. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6481. ;; Show a reminder of a past scheduled today.
  6482. (if (and todayp pastschedp)
  6483. (format past diff)
  6484. first))
  6485. (org-add-props head nil
  6486. 'effort effort
  6487. 'effort-minutes effort-minutes)
  6488. level category tags time nil habitp))
  6489. (face (cond ((and (not habitp) pastschedp)
  6490. 'org-scheduled-previously)
  6491. ((and habitp futureschedp)
  6492. 'org-agenda-done)
  6493. (todayp 'org-scheduled-today)
  6494. (t 'org-scheduled)))
  6495. (habitp (and habitp (org-habit-parse-todo))))
  6496. (org-add-props item props
  6497. 'undone-face face
  6498. 'face (if donep 'org-agenda-done face)
  6499. 'org-marker (org-agenda-new-marker pos)
  6500. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6501. 'type (if pastschedp "past-scheduled" "scheduled")
  6502. 'date (if pastschedp schedule date)
  6503. 'ts-date schedule
  6504. 'warntime warntime
  6505. 'level level
  6506. 'effort effort 'effort-minutes effort-minutes
  6507. 'priority (if habitp (org-habit-get-priority habitp)
  6508. (+ 99 diff (org-get-priority item)))
  6509. 'org-habit-p habitp
  6510. 'todo-state todo-state)
  6511. (push item scheduled-items)))))))
  6512. (nreverse scheduled-items)))
  6513. (defun org-agenda-get-blocks ()
  6514. "Return the date-range information for agenda display."
  6515. (with-no-warnings (defvar date))
  6516. (let* ((props (list 'face nil
  6517. 'org-not-done-regexp org-not-done-regexp
  6518. 'org-todo-regexp org-todo-regexp
  6519. 'org-complex-heading-regexp org-complex-heading-regexp
  6520. 'mouse-face 'highlight
  6521. 'help-echo
  6522. (format "mouse-2 or RET jump to org file %s"
  6523. (abbreviate-file-name buffer-file-name))))
  6524. (regexp org-tr-regexp)
  6525. (d0 (calendar-absolute-from-gregorian date))
  6526. marker hdmarker ee txt d1 d2 s1 s2 category
  6527. level todo-state tags pos head donep inherited-tags
  6528. effort effort-minutes)
  6529. (goto-char (point-min))
  6530. (while (re-search-forward regexp nil t)
  6531. (catch :skip
  6532. (org-agenda-skip)
  6533. (setq pos (point))
  6534. (let ((start-time (match-string 1))
  6535. (end-time (match-string 2)))
  6536. (setq s1 (match-string 1)
  6537. s2 (match-string 2)
  6538. d1 (time-to-days
  6539. (condition-case err
  6540. (org-time-string-to-time s1)
  6541. (error
  6542. (error
  6543. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6544. s1
  6545. pos
  6546. (current-buffer)
  6547. (error-message-string err)))))
  6548. d2 (time-to-days
  6549. (condition-case err
  6550. (org-time-string-to-time s2)
  6551. (error
  6552. (error
  6553. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6554. s2
  6555. pos
  6556. (current-buffer)
  6557. (error-message-string err))))))
  6558. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6559. ;; Only allow days between the limits, because the normal
  6560. ;; date stamps will catch the limits.
  6561. (save-excursion
  6562. (setq todo-state (org-get-todo-state))
  6563. (setq donep (member todo-state org-done-keywords))
  6564. (when (and donep org-agenda-skip-timestamp-if-done)
  6565. (throw :skip t))
  6566. (setq marker (org-agenda-new-marker (point))
  6567. category (org-get-category))
  6568. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6569. (org-entry-get (point) org-effort-property))))
  6570. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6571. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6572. (throw :skip nil)
  6573. (goto-char (match-beginning 0))
  6574. (setq hdmarker (org-agenda-new-marker (point))
  6575. inherited-tags
  6576. (or (eq org-agenda-show-inherited-tags 'always)
  6577. (and (listp org-agenda-show-inherited-tags)
  6578. (memq 'agenda org-agenda-show-inherited-tags))
  6579. (and (eq org-agenda-show-inherited-tags t)
  6580. (or (eq org-agenda-use-tag-inheritance t)
  6581. (memq 'agenda org-agenda-use-tag-inheritance))))
  6582. tags (org-get-tags nil (not inherited-tags)))
  6583. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6584. (looking-at "\\*+[ \t]+\\(.*\\)")
  6585. (setq head (match-string 1))
  6586. (let ((remove-re
  6587. (if org-agenda-remove-timeranges-from-blocks
  6588. (concat
  6589. "<" (regexp-quote s1) ".*?>"
  6590. "--"
  6591. "<" (regexp-quote s2) ".*?>")
  6592. nil)))
  6593. (setq txt (org-agenda-format-item
  6594. (format
  6595. (nth (if (= d1 d2) 0 1)
  6596. org-agenda-timerange-leaders)
  6597. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6598. (org-add-props head nil
  6599. 'effort effort
  6600. 'effort-minutes effort-minutes)
  6601. level category tags
  6602. (save-match-data
  6603. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6604. (match-string 6 s1)))
  6605. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6606. (match-string 6 s2))))
  6607. (cond ((string= hhmm1 hhmm2)
  6608. (concat "<" start-time ">--<" end-time ">"))
  6609. ((and (= d1 d0) (= d2 d0))
  6610. (concat "<" start-time ">--<" end-time ">"))
  6611. ((= d1 d0)
  6612. (concat "<" start-time ">"))
  6613. ((= d2 d0)
  6614. (concat "<" end-time ">")))))
  6615. remove-re))))
  6616. (org-add-props txt props
  6617. 'org-marker marker 'org-hd-marker hdmarker
  6618. 'type "block" 'date date
  6619. 'level level
  6620. 'effort effort 'effort-minutes effort-minutes
  6621. 'todo-state todo-state
  6622. 'priority (org-get-priority txt))
  6623. (push txt ee))))
  6624. (goto-char pos)))
  6625. ;; Sort the entries by expiration date.
  6626. (nreverse ee)))
  6627. ;;; Agenda presentation and sorting
  6628. (defvar org-prefix-has-time nil
  6629. "A flag, set by `org-compile-prefix-format'.
  6630. The flag is set if the currently compiled format contains a `%t'.")
  6631. (defvar org-prefix-has-tag nil
  6632. "A flag, set by `org-compile-prefix-format'.
  6633. The flag is set if the currently compiled format contains a `%T'.")
  6634. (defvar org-prefix-has-effort nil
  6635. "A flag, set by `org-compile-prefix-format'.
  6636. The flag is set if the currently compiled format contains a `%e'.")
  6637. (defvar org-prefix-has-breadcrumbs nil
  6638. "A flag, set by `org-compile-prefix-format'.
  6639. The flag is set if the currently compiled format contains a `%b'.")
  6640. (defvar org-prefix-category-length nil
  6641. "Used by `org-compile-prefix-format' to remember the category field width.")
  6642. (defvar org-prefix-category-max-length nil
  6643. "Used by `org-compile-prefix-format' to remember the category field width.")
  6644. (defun org-agenda-get-category-icon (category)
  6645. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6646. (cl-dolist (entry org-agenda-category-icon-alist)
  6647. (when (string-match-p (car entry) category)
  6648. (if (listp (cadr entry))
  6649. (cl-return (cadr entry))
  6650. (cl-return (apply #'create-image (cdr entry)))))))
  6651. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6652. remove-re habitp)
  6653. "Format TXT to be inserted into the agenda buffer.
  6654. In particular, add the prefix and corresponding text properties.
  6655. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6656. WITH-LEVEL may be a string to replace the `%l' specifier.
  6657. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6658. category taken from local variable or file name. It will replace the `%c'
  6659. specifier in the format.
  6660. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6661. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6662. When DOTIME is a string, this string is searched for a time before TXT is.
  6663. TAGS can be the tags of the headline.
  6664. Any match of REMOVE-RE will be removed from TXT."
  6665. ;; We keep the org-prefix-* variable values along with a compiled
  6666. ;; formatter, so that multiple agendas existing at the same time do
  6667. ;; not step on each other toes.
  6668. ;;
  6669. ;; It was inconvenient to make these variables buffer local in
  6670. ;; Agenda buffers, because this function expects to be called with
  6671. ;; the buffer where item comes from being current, and not agenda
  6672. ;; buffer
  6673. (let* ((bindings (car org-prefix-format-compiled))
  6674. (formatter (cadr org-prefix-format-compiled)))
  6675. (cl-loop for (var value) in bindings
  6676. do (set var value))
  6677. (save-match-data
  6678. ;; Diary entries sometimes have extra whitespace at the beginning
  6679. (setq txt (org-trim txt))
  6680. ;; Fix the tags part in txt
  6681. (setq txt (org-agenda-fix-displayed-tags
  6682. txt tags
  6683. org-agenda-show-inherited-tags
  6684. org-agenda-hide-tags-regexp))
  6685. (with-no-warnings
  6686. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6687. ;; Based on what I see in `org-compile-prefix-format', I added
  6688. ;; a few more.
  6689. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6690. (defvar effort) (defvar extra)
  6691. (defvar level) (defvar tag) (defvar time))
  6692. (let* ((category (or with-category
  6693. (if buffer-file-name
  6694. (file-name-sans-extension
  6695. (file-name-nondirectory buffer-file-name))
  6696. "")))
  6697. (category-icon (org-agenda-get-category-icon category))
  6698. (category-icon (if category-icon
  6699. (propertize " " 'display category-icon)
  6700. ""))
  6701. (effort (and (not (string= txt ""))
  6702. (get-text-property 1 'effort txt)))
  6703. (tag (if tags (nth (1- (length tags)) tags) ""))
  6704. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6705. (extra (or (and (not habitp) extra) ""))
  6706. time
  6707. (ts (when dotime (concat
  6708. (if (stringp dotime) dotime "")
  6709. (and org-agenda-search-headline-for-time txt))))
  6710. (time-of-day (and dotime (org-get-time-of-day ts)))
  6711. stamp plain s0 s1 s2 rtn srp l
  6712. duration breadcrumbs)
  6713. (and (derived-mode-p 'org-mode) buffer-file-name
  6714. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6715. (when (and dotime time-of-day)
  6716. ;; Extract starting and ending time and move them to prefix
  6717. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6718. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6719. (setq s0 (match-string 0 ts)
  6720. srp (and stamp (match-end 3))
  6721. s1 (match-string (if plain 1 2) ts)
  6722. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6723. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6724. ;; them, we might want to remove them there to avoid duplication.
  6725. ;; The user can turn this off with a variable.
  6726. (when (and org-prefix-has-time
  6727. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6728. (string-match (concat (regexp-quote s0) " *") txt)
  6729. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6730. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6731. (= (match-beginning 0) 0)
  6732. t))
  6733. (setq txt (replace-match "" nil nil txt))))
  6734. ;; Normalize the time(s) to 24 hour.
  6735. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6736. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6737. ;; Try to set s2 if s1 and
  6738. ;; `org-agenda-default-appointment-duration' are set
  6739. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6740. (setq s2
  6741. (org-duration-from-minutes
  6742. (+ (org-duration-to-minutes s1 t)
  6743. org-agenda-default-appointment-duration)
  6744. nil t)))
  6745. ;; Compute the duration
  6746. (when s2
  6747. (setq duration (- (org-duration-to-minutes s2)
  6748. (org-duration-to-minutes s1))))
  6749. ;; Format S1 and S2 for display.
  6750. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6751. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6752. (when (string-match org-tag-group-re txt)
  6753. ;; Tags are in the string
  6754. (if (or (eq org-agenda-remove-tags t)
  6755. (and org-agenda-remove-tags
  6756. org-prefix-has-tag))
  6757. (setq txt (replace-match "" t t txt))
  6758. (setq txt (replace-match
  6759. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6760. (match-string 1 txt))
  6761. t t txt))))
  6762. (when remove-re
  6763. (while (string-match remove-re txt)
  6764. (setq txt (replace-match "" t t txt))))
  6765. ;; Set org-heading property on `txt' to mark the start of the
  6766. ;; heading.
  6767. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6768. ;; Prepare the variables needed in the eval of the compiled format
  6769. (when org-prefix-has-breadcrumbs
  6770. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6771. (let ((s (org-format-outline-path (org-get-outline-path)
  6772. (1- (frame-width))
  6773. nil org-agenda-breadcrumbs-separator)))
  6774. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6775. (setq time (cond (s2 (concat
  6776. (org-agenda-time-of-day-to-ampm-maybe s1)
  6777. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6778. (when org-agenda-timegrid-use-ampm " ")))
  6779. (s1 (concat
  6780. (org-agenda-time-of-day-to-ampm-maybe s1)
  6781. (if org-agenda-timegrid-use-ampm
  6782. (concat time-grid-trailing-characters " ")
  6783. time-grid-trailing-characters)))
  6784. (t ""))
  6785. category (if (symbolp category) (symbol-name category) category)
  6786. level (or with-level ""))
  6787. (if (string-match org-link-bracket-re category)
  6788. (progn
  6789. (setq l (string-width (or (match-string 2) (match-string 1))))
  6790. (when (< l (or org-prefix-category-length 0))
  6791. (setq category (copy-sequence category))
  6792. (org-add-props category nil
  6793. 'extra-space (make-string
  6794. (- org-prefix-category-length l 1) ?\ ))))
  6795. (when (and org-prefix-category-max-length
  6796. (>= (length category) org-prefix-category-max-length))
  6797. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6798. ;; Evaluate the compiled format
  6799. (setq rtn (concat (eval formatter t) txt))
  6800. ;; And finally add the text properties
  6801. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6802. (org-add-props rtn nil
  6803. 'org-category category
  6804. 'tags tags
  6805. 'org-priority-highest org-priority-highest
  6806. 'org-priority-lowest org-priority-lowest
  6807. 'time-of-day time-of-day
  6808. 'duration duration
  6809. 'breadcrumbs breadcrumbs
  6810. 'txt txt
  6811. 'level level
  6812. 'time time
  6813. 'extra extra
  6814. 'format org-prefix-format-compiled
  6815. 'dotime dotime)))))
  6816. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6817. "Remove tags string from TXT, and add a modified list of tags.
  6818. The modified list may contain inherited tags, and tags matched by
  6819. `org-agenda-hide-tags-regexp' will be removed."
  6820. (when (or add-inherited hide-re)
  6821. (when (string-match org-tag-group-re txt)
  6822. (setq txt (substring txt 0 (match-beginning 0))))
  6823. (setq tags
  6824. (delq nil
  6825. (mapcar (lambda (tg)
  6826. (if (or (and hide-re (string-match hide-re tg))
  6827. (and (not add-inherited)
  6828. (get-text-property 0 'inherited tg)))
  6829. nil
  6830. tg))
  6831. tags)))
  6832. (when tags
  6833. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6834. i)
  6835. (setq txt (concat txt " :"
  6836. (mapconcat
  6837. (lambda (x)
  6838. (setq i (get-text-property 0 'inherited x))
  6839. (if (and have-i (not i))
  6840. (progn
  6841. (setq have-i nil)
  6842. (concat ":" x))
  6843. x))
  6844. tags ":")
  6845. (if have-i "::" ":"))))))
  6846. txt)
  6847. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6848. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6849. "Add a time-grid for agenda items which need it.
  6850. LIST is the list of agenda items formatted by `org-agenda-list'.
  6851. NDAYS is the span of the current agenda view.
  6852. TODAYP is t when the current agenda view is on today."
  6853. (catch 'exit
  6854. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6855. ((and todayp (member 'today (car org-agenda-time-grid))))
  6856. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6857. ((member 'weekly (car org-agenda-time-grid)))
  6858. (t (throw 'exit list)))
  6859. (let* ((have (delq nil (mapcar
  6860. (lambda (x) (get-text-property 1 'time-of-day x))
  6861. list)))
  6862. (string (nth 3 org-agenda-time-grid))
  6863. (gridtimes (nth 1 org-agenda-time-grid))
  6864. (req (car org-agenda-time-grid))
  6865. (remove (member 'remove-match req))
  6866. new time)
  6867. (when (and (member 'require-timed req) (not have))
  6868. ;; don't show empty grid
  6869. (throw 'exit list))
  6870. (while (setq time (pop gridtimes))
  6871. (unless (and remove (member time have))
  6872. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6873. (push (org-agenda-format-item
  6874. nil string nil "" nil
  6875. (concat (substring time 0 -2) ":" (substring time -2)))
  6876. new)
  6877. (put-text-property
  6878. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6879. (when (and todayp org-agenda-show-current-time-in-grid)
  6880. (push (org-agenda-format-item
  6881. nil org-agenda-current-time-string nil "" nil
  6882. (format-time-string "%H:%M "))
  6883. new)
  6884. (put-text-property
  6885. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6886. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6887. (append new list)
  6888. (append list new)))))
  6889. (defun org-compile-prefix-format (key)
  6890. "Compile the prefix format into a Lisp form that can be evaluated.
  6891. KEY is the agenda type (see `org-agenda-prefix-format').
  6892. The resulting form and associated variable bindings is returned
  6893. and stored in the variable `org-prefix-format-compiled'."
  6894. (setq org-prefix-has-time nil
  6895. org-prefix-has-tag nil
  6896. org-prefix-category-length nil
  6897. org-prefix-has-effort nil
  6898. org-prefix-has-breadcrumbs nil)
  6899. (let ((s (cond
  6900. ((stringp org-agenda-prefix-format)
  6901. org-agenda-prefix-format)
  6902. ((assq key org-agenda-prefix-format)
  6903. (cdr (assq key org-agenda-prefix-format)))
  6904. (t " %-12:c%?-12t% s")))
  6905. (start 0)
  6906. varform vars var c f opt) ;; e
  6907. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6908. s start)
  6909. (setq var (or (cdr (assoc (match-string 4 s)
  6910. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6911. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6912. 'eval)
  6913. c (or (match-string 3 s) "")
  6914. opt (match-beginning 1)
  6915. start (1+ (match-beginning 0)))
  6916. (cl-case var
  6917. (time (setq org-prefix-has-time t))
  6918. (tag (setq org-prefix-has-tag t))
  6919. (effort (setq org-prefix-has-effort t))
  6920. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6921. (setq f (concat "%" (match-string 2 s) "s"))
  6922. (when (eq var 'category)
  6923. (setq org-prefix-category-length
  6924. (floor (abs (string-to-number (match-string 2 s)))))
  6925. (setq org-prefix-category-max-length
  6926. (let ((x (match-string 2 s)))
  6927. (save-match-data
  6928. (and (string-match "\\.[0-9]+" x)
  6929. (string-to-number (substring (match-string 0 x) 1)))))))
  6930. (if (eq var 'eval)
  6931. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6932. (if opt
  6933. (setq varform
  6934. `(if (member ,var '("" nil))
  6935. ""
  6936. (format ,f (concat ,var ,c))))
  6937. (setq varform
  6938. `(format ,f (if (member ,var '("" nil)) ""
  6939. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6940. (if (eq var 'eval)
  6941. (setf (substring s (match-beginning 0)
  6942. (+ (match-beginning 4)
  6943. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6944. "%s")
  6945. (setq s (replace-match "%s" t nil s)))
  6946. (push varform vars))
  6947. (setq vars (nreverse vars))
  6948. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6949. (setq org-prefix-format-compiled
  6950. (list
  6951. `((org-prefix-has-time ,org-prefix-has-time)
  6952. (org-prefix-has-tag ,org-prefix-has-tag)
  6953. (org-prefix-category-length ,org-prefix-category-length)
  6954. (org-prefix-has-effort ,org-prefix-has-effort)
  6955. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6956. `(format ,s ,@vars))))))
  6957. (defun org-set-sorting-strategy (key)
  6958. (setq org-agenda-sorting-strategy-selected
  6959. (if (symbolp (car org-agenda-sorting-strategy))
  6960. ;; the old format
  6961. org-agenda-sorting-strategy
  6962. (or (cdr (assq key org-agenda-sorting-strategy))
  6963. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6964. '(time-up category-keep priority-down)))))
  6965. (defun org-get-time-of-day (s &optional string)
  6966. "Check string S for a time of day.
  6967. If found, return it as a military time number between 0 and 2400.
  6968. If not found, return nil.
  6969. The optional STRING argument forces conversion into a 5 character wide string
  6970. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6971. where H:MM is the duration above midnight."
  6972. (let ((case-fold-search t)
  6973. (time-regexp
  6974. (rx word-start
  6975. (group (opt (any "012")) digit) ;group 1: hours
  6976. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6977. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6978. ;; Special "HHam/pm" case.
  6979. (group-n 3 (or "am" "pm")))
  6980. word-end)))
  6981. (save-match-data
  6982. (when (and (string-match time-regexp s)
  6983. (not (eq 'org-link (get-text-property 1 'face s))))
  6984. (let ((hours
  6985. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  6986. (am-p (equal ampm "am")))
  6987. (pcase (string-to-number (match-string 1 s))
  6988. ((and (guard (not ampm)) h) h)
  6989. (12 (if am-p 0 12))
  6990. (h (+ h (if am-p 0 12))))))
  6991. (minutes
  6992. (if (match-end 2)
  6993. (string-to-number (match-string 2 s))
  6994. 0)))
  6995. (pcase string
  6996. (`nil (+ minutes (* hours 100)))
  6997. ((and `overtime
  6998. (guard (or (> hours 24)
  6999. (and (= hours 24)
  7000. (> minutes 0)))))
  7001. (format "+%d:%02d" (- hours 24) minutes))
  7002. ((guard org-agenda-time-leading-zero)
  7003. (format "%02d:%02d" hours minutes))
  7004. (_
  7005. (format "%d:%02d" hours minutes))))))))
  7006. (defvar org-agenda-before-sorting-filter-function nil
  7007. "Function to be applied to agenda items prior to sorting.
  7008. Prior to sorting also means just before they are inserted into the agenda.
  7009. To aid sorting, you may revisit the original entries and add more text
  7010. properties which will later be used by the sorting functions.
  7011. The function should take a string argument, an agenda line.
  7012. It has access to the text properties in that line, which contain among
  7013. other things, the property `org-hd-marker' that points to the entry
  7014. where the line comes from. Note that not all lines going into the agenda
  7015. have this property, only most.
  7016. The function should return the modified string. It is probably best
  7017. to ONLY change text properties.
  7018. You can also use this function as a filter, by returning nil for lines
  7019. you don't want to have in the agenda at all. For this application, you
  7020. could bind the variable in the options section of a custom command.")
  7021. (defun org-agenda-finalize-entries (list &optional type)
  7022. "Sort, limit and concatenate the LIST of agenda items.
  7023. The optional argument TYPE tells the agenda type."
  7024. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7025. (cdr (assoc type org-agenda-max-effort)))
  7026. (t org-agenda-max-effort)))
  7027. (max-todo (cond ((listp org-agenda-max-todos)
  7028. (cdr (assoc type org-agenda-max-todos)))
  7029. (t org-agenda-max-todos)))
  7030. (max-tags (cond ((listp org-agenda-max-tags)
  7031. (cdr (assoc type org-agenda-max-tags)))
  7032. (t org-agenda-max-tags)))
  7033. (max-entries (cond ((listp org-agenda-max-entries)
  7034. (cdr (assoc type org-agenda-max-entries)))
  7035. (t org-agenda-max-entries))))
  7036. (when org-agenda-before-sorting-filter-function
  7037. (setq list
  7038. (delq nil
  7039. (mapcar
  7040. org-agenda-before-sorting-filter-function list))))
  7041. (setq list (mapcar #'org-agenda-highlight-todo list)
  7042. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7043. (when max-effort
  7044. (setq list (org-agenda-limit-entries
  7045. list 'effort-minutes max-effort
  7046. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7047. 32767 -1))))))
  7048. (when max-todo
  7049. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7050. (when max-tags
  7051. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7052. (when max-entries
  7053. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7054. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7055. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7056. (mapconcat #'identity list "\n")))
  7057. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7058. "Limit the number of agenda entries."
  7059. (let ((include (and limit (< limit 0))))
  7060. (if limit
  7061. (let ((fun (or fn (lambda (p) (when p 1))))
  7062. (lim 0))
  7063. (delq nil
  7064. (mapcar
  7065. (lambda (e)
  7066. (let ((pval (funcall
  7067. fun (get-text-property (1- (length e))
  7068. prop e))))
  7069. (when pval (setq lim (+ lim pval)))
  7070. (cond ((and pval (<= lim (abs limit))) e)
  7071. ((and include (not pval)) e))))
  7072. list)))
  7073. list)))
  7074. (defun org-agenda-limit-interactively (remove)
  7075. "In agenda, interactively limit entries to various maximums."
  7076. (interactive "P")
  7077. (if remove
  7078. (progn (setq org-agenda-max-entries nil
  7079. org-agenda-max-todos nil
  7080. org-agenda-max-tags nil
  7081. org-agenda-max-effort nil)
  7082. (org-agenda-redo))
  7083. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7084. (msg (cond ((= max ?E) "How many minutes? ")
  7085. ((= max ?e) "How many entries? ")
  7086. ((= max ?t) "How many TODO entries? ")
  7087. ((= max ?T) "How many tagged entries? ")
  7088. (t (user-error "Wrong input"))))
  7089. (num (string-to-number (read-from-minibuffer msg))))
  7090. (cond ((equal max ?e)
  7091. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7092. ((equal max ?t)
  7093. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7094. ((equal max ?T)
  7095. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7096. ((equal max ?E)
  7097. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7098. (org-agenda-fit-window-to-buffer))
  7099. (defun org-agenda-highlight-todo (x)
  7100. (let ((org-done-keywords org-done-keywords-for-agenda)
  7101. (case-fold-search nil)
  7102. re)
  7103. (if (eq x 'line)
  7104. (save-excursion
  7105. (beginning-of-line 1)
  7106. (setq re (org-get-at-bol 'org-todo-regexp))
  7107. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7108. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7109. (add-text-properties (match-beginning 0) (match-end 1)
  7110. (list 'face (org-get-todo-face 1)))
  7111. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7112. (delete-region (match-beginning 1) (1- (match-end 0)))
  7113. (goto-char (match-beginning 1))
  7114. (insert (format org-agenda-todo-keyword-format s)))))
  7115. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7116. (setq re (get-text-property 0 'org-todo-regexp x))
  7117. (when (and re
  7118. ;; Test `pl' because if there's no heading content,
  7119. ;; there's no point matching to highlight. Note
  7120. ;; that if we didn't test `pl' first, and there
  7121. ;; happened to be no keyword from `org-todo-regexp'
  7122. ;; on this heading line, then the `equal' comparison
  7123. ;; afterwards would spuriously succeed in the case
  7124. ;; where `pl' is nil -- causing an args-out-of-range
  7125. ;; error when we try to add text properties to text
  7126. ;; that isn't there.
  7127. pl
  7128. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7129. x pl)
  7130. pl))
  7131. (add-text-properties
  7132. (or (match-end 1) (match-end 0)) (match-end 0)
  7133. (list 'face (org-get-todo-face (match-string 2 x)))
  7134. x)
  7135. (when (match-end 1)
  7136. (setq x
  7137. (concat
  7138. (substring x 0 (match-end 1))
  7139. (unless (string= org-agenda-todo-keyword-format "")
  7140. (format org-agenda-todo-keyword-format
  7141. (match-string 2 x)))
  7142. (unless (string= org-agenda-todo-keyword-format "")
  7143. ;; Remove `display' property as the icon could leak
  7144. ;; on the white space.
  7145. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7146. 'display)))
  7147. (substring x (match-end 3)))))))
  7148. x)))
  7149. (defsubst org-cmp-values (a b property)
  7150. "Compare the numeric value of text PROPERTY for string A and B."
  7151. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7152. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7153. (cond ((> pa pb) +1)
  7154. ((< pa pb) -1))))
  7155. (defsubst org-cmp-effort (a b)
  7156. "Compare the effort values of string A and B."
  7157. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7158. ;; `effort-minutes' property is not directly accessible from
  7159. ;; the strings, but is stored as a property in `txt'.
  7160. (ea (or (get-text-property
  7161. 0 'effort-minutes (get-text-property 0 'txt a))
  7162. def))
  7163. (eb (or (get-text-property
  7164. 0 'effort-minutes (get-text-property 0 'txt b))
  7165. def)))
  7166. (cond ((> ea eb) +1)
  7167. ((< ea eb) -1))))
  7168. (defsubst org-cmp-category (a b)
  7169. "Compare the string values of categories of strings A and B."
  7170. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7171. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7172. (cond ((string-lessp ca cb) -1)
  7173. ((string-lessp cb ca) +1))))
  7174. (defsubst org-cmp-todo-state (a b)
  7175. "Compare the todo states of strings A and B."
  7176. (let* ((ma (or (get-text-property 1 'org-marker a)
  7177. (get-text-property 1 'org-hd-marker a)))
  7178. (mb (or (get-text-property 1 'org-marker b)
  7179. (get-text-property 1 'org-hd-marker b)))
  7180. (fa (and ma (marker-buffer ma)))
  7181. (fb (and mb (marker-buffer mb)))
  7182. (todo-kwds
  7183. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7184. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7185. (ta (or (get-text-property 1 'todo-state a) ""))
  7186. (tb (or (get-text-property 1 'todo-state b) ""))
  7187. (la (- (length (member ta todo-kwds))))
  7188. (lb (- (length (member tb todo-kwds))))
  7189. (donepa (member ta org-done-keywords-for-agenda))
  7190. (donepb (member tb org-done-keywords-for-agenda)))
  7191. (cond ((and donepa (not donepb)) -1)
  7192. ((and (not donepa) donepb) +1)
  7193. ((< la lb) -1)
  7194. ((< lb la) +1))))
  7195. (defsubst org-cmp-alpha (a b)
  7196. "Compare the headlines, alphabetically."
  7197. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7198. (plb (text-property-any 0 (length b) 'org-heading t b))
  7199. (ta (and pla (substring a pla)))
  7200. (tb (and plb (substring b plb)))
  7201. (case-fold-search nil))
  7202. (when pla
  7203. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7204. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7205. ta)
  7206. (setq ta (substring ta (match-end 0))))
  7207. (setq ta (downcase ta)))
  7208. (when plb
  7209. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7210. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7211. tb)
  7212. (setq tb (substring tb (match-end 0))))
  7213. (setq tb (downcase tb)))
  7214. (cond ((not (or ta tb)) nil)
  7215. ((not ta) +1)
  7216. ((not tb) -1)
  7217. ((string-lessp ta tb) -1)
  7218. ((string-lessp tb ta) +1))))
  7219. (defsubst org-cmp-tag (a b)
  7220. "Compare the string values of the first tags of A and B."
  7221. (let ((ta (car (last (get-text-property 1 'tags a))))
  7222. (tb (car (last (get-text-property 1 'tags b)))))
  7223. (cond ((not (or ta tb)) nil)
  7224. ((not ta) +1)
  7225. ((not tb) -1)
  7226. ((string-lessp ta tb) -1)
  7227. ((string-lessp tb ta) +1))))
  7228. (defsubst org-cmp-time (a b)
  7229. "Compare the time-of-day values of strings A and B."
  7230. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7231. (ta (or (get-text-property 1 'time-of-day a) def))
  7232. (tb (or (get-text-property 1 'time-of-day b) def)))
  7233. (cond ((< ta tb) -1)
  7234. ((< tb ta) +1))))
  7235. (defsubst org-cmp-ts (a b type)
  7236. "Compare the timestamps values of entries A and B.
  7237. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7238. \"timestamp_ia\", compare within each of these type. When TYPE
  7239. is the empty string, compare all timestamps without respect of
  7240. their type."
  7241. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7242. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7243. (get-text-property 1 'ts-date a))
  7244. def))
  7245. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7246. (get-text-property 1 'ts-date b))
  7247. def)))
  7248. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7249. ((if tb (and ta (< tb ta)) ta) +1))))
  7250. (defsubst org-cmp-habit-p (a b)
  7251. "Compare the todo states of strings A and B."
  7252. (let ((ha (get-text-property 1 'org-habit-p a))
  7253. (hb (get-text-property 1 'org-habit-p b)))
  7254. (cond ((and ha (not hb)) -1)
  7255. ((and (not ha) hb) +1))))
  7256. (defun org-entries-lessp (a b)
  7257. "Predicate for sorting agenda entries."
  7258. ;; The following variables will be used when the form is evaluated.
  7259. ;; So even though the compiler complains, keep them.
  7260. (let ((ss org-agenda-sorting-strategy-selected))
  7261. (org-dlet
  7262. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7263. (org-cmp-ts a b "")))
  7264. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7265. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7266. (org-cmp-ts a b "scheduled")))
  7267. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7268. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7269. (org-cmp-ts a b "deadline")))
  7270. (deadline-down (if deadline-up (- deadline-up) nil))
  7271. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7272. (org-cmp-ts a b "timestamp_ia")))
  7273. (tsia-down (if tsia-up (- tsia-up) nil))
  7274. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7275. (org-cmp-ts a b "timestamp")))
  7276. (ts-down (if ts-up (- ts-up) nil))
  7277. (time-up (and (org-em 'time-up 'time-down ss)
  7278. (org-cmp-time a b)))
  7279. (time-down (if time-up (- time-up) nil))
  7280. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7281. (org-cmp-values a b 'org-stats)))
  7282. (stats-down (if stats-up (- stats-up) nil))
  7283. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7284. (org-cmp-values a b 'priority)))
  7285. (priority-down (if priority-up (- priority-up) nil))
  7286. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7287. (org-cmp-effort a b)))
  7288. (effort-down (if effort-up (- effort-up) nil))
  7289. (category-up (and (or (org-em 'category-up 'category-down ss)
  7290. (memq 'category-keep ss))
  7291. (org-cmp-category a b)))
  7292. (category-down (if category-up (- category-up) nil))
  7293. (category-keep (if category-up +1 nil))
  7294. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7295. (org-cmp-tag a b)))
  7296. (tag-down (if tag-up (- tag-up) nil))
  7297. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7298. (org-cmp-todo-state a b)))
  7299. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7300. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7301. (org-cmp-habit-p a b)))
  7302. (habit-down (if habit-up (- habit-up) nil))
  7303. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7304. (org-cmp-alpha a b)))
  7305. (alpha-down (if alpha-up (- alpha-up) nil))
  7306. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7307. user-defined-up user-defined-down)
  7308. (when (and need-user-cmp org-agenda-cmp-user-defined
  7309. (functionp org-agenda-cmp-user-defined))
  7310. (setq user-defined-up
  7311. (funcall org-agenda-cmp-user-defined a b)
  7312. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7313. (cdr (assoc
  7314. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7315. '((-1 . t) (1 . nil) (nil . nil)))))))
  7316. ;;; Agenda restriction lock
  7317. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7318. "Overlay to mark the headline to which agenda commands are restricted.")
  7319. (overlay-put org-agenda-restriction-lock-overlay
  7320. 'face 'org-agenda-restriction-lock)
  7321. (overlay-put org-agenda-restriction-lock-overlay
  7322. 'help-echo "Agendas are currently limited to this subtree.")
  7323. (delete-overlay org-agenda-restriction-lock-overlay)
  7324. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7325. "Set the restriction lock to the agenda item at point from within the agenda.
  7326. When called with a `\\[universal-argument]' prefix, restrict to
  7327. the file which contains the item.
  7328. Argument ARG is the prefix argument."
  7329. (interactive "P")
  7330. (unless (derived-mode-p 'org-agenda-mode)
  7331. (user-error "Not in an Org agenda buffer"))
  7332. (let* ((marker (or (org-get-at-bol 'org-marker)
  7333. (org-agenda-error)))
  7334. (buffer (marker-buffer marker))
  7335. (pos (marker-position marker)))
  7336. (with-current-buffer buffer
  7337. (goto-char pos)
  7338. (org-agenda-set-restriction-lock arg))))
  7339. ;;;###autoload
  7340. (defun org-agenda-set-restriction-lock (&optional type)
  7341. "Set restriction lock for agenda to current subtree or file.
  7342. When in a restricted subtree, remove it.
  7343. The restriction will span over the entire file if TYPE is `file',
  7344. or if type is \\='(4), or if the cursor is before the first headline
  7345. in the file. Otherwise, only apply the restriction to the current
  7346. subtree."
  7347. (interactive "P")
  7348. (if (and org-agenda-overriding-restriction
  7349. (member org-agenda-restriction-lock-overlay
  7350. (overlays-at (point)))
  7351. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7352. (point)))
  7353. (org-agenda-remove-restriction-lock 'noupdate)
  7354. (org-agenda-remove-restriction-lock 'noupdate)
  7355. (and (equal type '(4)) (setq type 'file))
  7356. (setq type (cond
  7357. (type type)
  7358. ((org-at-heading-p) 'subtree)
  7359. ((condition-case nil (org-back-to-heading t) (error nil))
  7360. 'subtree)
  7361. (t 'file)))
  7362. (if (eq type 'subtree)
  7363. (progn
  7364. (setq org-agenda-restrict (current-buffer))
  7365. (setq org-agenda-overriding-restriction 'subtree)
  7366. (put 'org-agenda-files 'org-restrict
  7367. (list (buffer-file-name (buffer-base-buffer))))
  7368. (org-back-to-heading t)
  7369. (move-overlay org-agenda-restriction-lock-overlay
  7370. (point)
  7371. (if org-agenda-restriction-lock-highlight-subtree
  7372. (save-excursion (org-end-of-subtree t t) (point))
  7373. (point-at-eol)))
  7374. (move-marker org-agenda-restrict-begin (point))
  7375. (move-marker org-agenda-restrict-end
  7376. (save-excursion (org-end-of-subtree t t)))
  7377. (message "Locking agenda restriction to subtree"))
  7378. (put 'org-agenda-files 'org-restrict
  7379. (list (buffer-file-name (buffer-base-buffer))))
  7380. (setq org-agenda-restrict nil)
  7381. (setq org-agenda-overriding-restriction 'file)
  7382. (move-marker org-agenda-restrict-begin nil)
  7383. (move-marker org-agenda-restrict-end nil)
  7384. (message "Locking agenda restriction to file"))
  7385. (setq current-prefix-arg nil))
  7386. (org-agenda-maybe-redo))
  7387. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7388. "Remove agenda restriction lock."
  7389. (interactive "P")
  7390. (if (not org-agenda-restrict)
  7391. (message "No agenda restriction to remove.")
  7392. (delete-overlay org-agenda-restriction-lock-overlay)
  7393. (delete-overlay org-speedbar-restriction-lock-overlay)
  7394. (setq org-agenda-overriding-restriction nil)
  7395. (setq org-agenda-restrict nil)
  7396. (put 'org-agenda-files 'org-restrict nil)
  7397. (move-marker org-agenda-restrict-begin nil)
  7398. (move-marker org-agenda-restrict-end nil)
  7399. (setq current-prefix-arg nil)
  7400. (message "Agenda restriction lock removed")
  7401. (or noupdate (org-agenda-maybe-redo))))
  7402. (defun org-agenda-maybe-redo ()
  7403. "If there is any window showing the agenda view, update it."
  7404. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7405. org-agenda-buffer-name)
  7406. t))
  7407. (w0 (selected-window)))
  7408. (when w
  7409. (select-window w)
  7410. (org-agenda-redo)
  7411. (select-window w0)
  7412. (if org-agenda-overriding-restriction
  7413. (message "Agenda view shifted to new %s restriction"
  7414. org-agenda-overriding-restriction)
  7415. (message "Agenda restriction lock removed")))))
  7416. ;;; Agenda commands
  7417. (defun org-agenda-check-type (error &rest types)
  7418. "Check if agenda buffer or component is of allowed type.
  7419. If ERROR is non-nil, throw an error, otherwise just return nil.
  7420. Allowed types are `agenda' `todo' `tags' `search'."
  7421. (cond ((not org-agenda-type)
  7422. (error "No Org agenda currently displayed"))
  7423. ((memq org-agenda-type types) t)
  7424. (error
  7425. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7426. (t nil)))
  7427. (defun org-agenda-Quit ()
  7428. "Exit the agenda, killing the agenda buffer.
  7429. Like `org-agenda-quit', but kill the buffer even when
  7430. `org-agenda-sticky' is non-nil."
  7431. (interactive)
  7432. (org-agenda--quit))
  7433. (defun org-agenda-quit ()
  7434. "Exit the agenda.
  7435. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7436. instead of killing it.
  7437. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7438. the pre-agenda window configuration.
  7439. When column view is active, exit column view instead of the
  7440. agenda."
  7441. (interactive)
  7442. (org-agenda--quit org-agenda-sticky))
  7443. (defun org-agenda--quit (&optional bury)
  7444. (if org-agenda-columns-active
  7445. (org-columns-quit)
  7446. (let ((wconf org-agenda-pre-window-conf)
  7447. (buf (current-buffer))
  7448. (org-agenda-last-indirect-window
  7449. (and (eq org-indirect-buffer-display 'other-window)
  7450. org-agenda-last-indirect-buffer
  7451. (get-buffer-window org-agenda-last-indirect-buffer))))
  7452. (cond
  7453. ((eq org-agenda-window-setup 'other-frame)
  7454. (delete-frame))
  7455. ((eq org-agenda-window-setup 'other-tab)
  7456. (if (fboundp 'tab-bar-close-tab)
  7457. (tab-bar-close-tab)
  7458. (user-error "Your version of Emacs does not have tab bar mode support")))
  7459. ((and org-agenda-restore-windows-after-quit
  7460. wconf)
  7461. ;; Maybe restore the pre-agenda window configuration. Reset
  7462. ;; `org-agenda-pre-window-conf' before running
  7463. ;; `set-window-configuration', which loses the current buffer.
  7464. (setq org-agenda-pre-window-conf nil)
  7465. (set-window-configuration wconf))
  7466. (t
  7467. (when org-agenda-last-indirect-window
  7468. (delete-window org-agenda-last-indirect-window))
  7469. (and (not (eq org-agenda-window-setup 'current-window))
  7470. (not (one-window-p))
  7471. (delete-window))))
  7472. (if bury
  7473. ;; Set the agenda buffer as the current buffer instead of
  7474. ;; passing it as an argument to `bury-buffer' so that
  7475. ;; `bury-buffer' removes it from the window.
  7476. (with-current-buffer buf
  7477. (bury-buffer))
  7478. (kill-buffer buf)
  7479. (setq org-agenda-archives-mode nil
  7480. org-agenda-buffer nil)))))
  7481. (defun org-agenda-exit ()
  7482. "Exit the agenda, killing Org buffers loaded by the agenda.
  7483. Like `org-agenda-Quit', but kill any buffers that were created by
  7484. the agenda. Org buffers visited directly by the user will not be
  7485. touched. Also, exit the agenda even if it is in column view."
  7486. (interactive)
  7487. (when org-agenda-columns-active
  7488. (org-columns-quit))
  7489. (org-release-buffers org-agenda-new-buffers)
  7490. (setq org-agenda-new-buffers nil)
  7491. (org-agenda-Quit))
  7492. (defun org-agenda-kill-all-agenda-buffers ()
  7493. "Kill all buffers in `org-agenda-mode'.
  7494. This is used when toggling sticky agendas."
  7495. (interactive)
  7496. (let (blist)
  7497. (dolist (buf (buffer-list))
  7498. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7499. (push buf blist)))
  7500. (mapc #'kill-buffer blist)))
  7501. (defun org-agenda-execute (arg)
  7502. "Execute another agenda command, keeping same window.
  7503. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7504. in the agenda."
  7505. (interactive "P")
  7506. (let ((org-agenda-window-setup 'current-window))
  7507. (org-agenda arg)))
  7508. (defun org-agenda-redo (&optional all)
  7509. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7510. (interactive "P")
  7511. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7512. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7513. (cpa (unless (eq all t) current-prefix-arg))
  7514. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7515. (org-agenda-sticky nil)
  7516. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7517. org-agenda-buffer-name))
  7518. (org-agenda-keep-modes t)
  7519. (tag-filter org-agenda-tag-filter)
  7520. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7521. (top-hl-filter org-agenda-top-headline-filter)
  7522. (cat-filter org-agenda-category-filter)
  7523. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7524. (re-filter org-agenda-regexp-filter)
  7525. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7526. (effort-filter org-agenda-effort-filter)
  7527. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7528. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7529. (cols org-agenda-columns-active)
  7530. (line (org-current-line))
  7531. (window-line (- line (org-current-line (window-start))))
  7532. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7533. (redo-cmd (get-text-property p 'org-redo-cmd))
  7534. (last-args (get-text-property p 'org-last-args))
  7535. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7536. (org-agenda-overriding-cmd-arguments
  7537. (unless (eq all t)
  7538. (cond ((listp last-args)
  7539. (cons (or cpa (car last-args)) (cdr last-args)))
  7540. ((stringp last-args)
  7541. last-args))))
  7542. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7543. (put 'org-agenda-tag-filter :preset-filter nil)
  7544. (put 'org-agenda-category-filter :preset-filter nil)
  7545. (put 'org-agenda-regexp-filter :preset-filter nil)
  7546. (put 'org-agenda-effort-filter :preset-filter nil)
  7547. (and cols (org-columns-quit))
  7548. (message "Rebuilding agenda buffer...")
  7549. (if series-redo-cmd
  7550. (eval series-redo-cmd t)
  7551. (cl-progv
  7552. (mapcar #'car lprops)
  7553. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7554. (eval redo-cmd t)))
  7555. (setq org-agenda-undo-list nil
  7556. org-agenda-pending-undo-list nil
  7557. org-agenda-tag-filter tag-filter
  7558. org-agenda-category-filter cat-filter
  7559. org-agenda-regexp-filter re-filter
  7560. org-agenda-effort-filter effort-filter
  7561. org-agenda-top-headline-filter top-hl-filter)
  7562. (message "Rebuilding agenda buffer...done")
  7563. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7564. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7565. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7566. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7567. (let ((tag (or tag-filter tag-preset))
  7568. (cat (or cat-filter cat-preset))
  7569. (effort (or effort-filter effort-preset))
  7570. (re (or re-filter re-preset)))
  7571. (when tag (org-agenda-filter-apply tag 'tag t))
  7572. (when cat (org-agenda-filter-apply cat 'category))
  7573. (when effort (org-agenda-filter-apply effort 'effort))
  7574. (when re (org-agenda-filter-apply re 'regexp)))
  7575. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7576. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7577. (org-goto-line line)
  7578. (when (called-interactively-p 'any) (recenter window-line))))
  7579. (defun org-agenda-redo-all (&optional exhaustive)
  7580. "Rebuild all agenda views in the current buffer.
  7581. With a prefix argument, do so in all agenda buffers."
  7582. (interactive "P")
  7583. (if exhaustive
  7584. (dolist (buffer (buffer-list))
  7585. (with-current-buffer buffer
  7586. (when (derived-mode-p 'org-agenda-mode)
  7587. (org-agenda-redo t))))
  7588. (org-agenda-redo t)))
  7589. (defvar org-global-tags-completion-table nil)
  7590. (defvar org-agenda-filter-form nil)
  7591. (defvar org-agenda-filtered-by-category nil)
  7592. (defsubst org-agenda-get-category ()
  7593. "Return the category of the agenda line."
  7594. (org-get-at-bol 'org-category))
  7595. (defun org-agenda-filter-by-category (strip)
  7596. "Filter lines in the agenda buffer that have a specific category.
  7597. The category is that of the current line.
  7598. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7599. When there is already a category filter in place, this command removes the
  7600. filter."
  7601. (interactive "P")
  7602. (if (and org-agenda-filtered-by-category
  7603. org-agenda-category-filter)
  7604. (org-agenda-filter-show-all-cat)
  7605. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7606. (cond
  7607. ((and cat strip)
  7608. (org-agenda-filter-apply
  7609. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7610. (cat
  7611. (org-agenda-filter-apply
  7612. (setq org-agenda-category-filter
  7613. (list (concat "+" cat)))
  7614. 'category))
  7615. (t (error "No category at point"))))))
  7616. (defun org-find-top-headline (&optional pos)
  7617. "Find the topmost parent headline and return it.
  7618. POS when non-nil is the marker or buffer position to start the
  7619. search from."
  7620. (save-excursion
  7621. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7622. (when pos (goto-char pos))
  7623. ;; Skip up to the topmost parent.
  7624. (while (org-up-heading-safe))
  7625. (ignore-errors
  7626. (replace-regexp-in-string
  7627. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7628. (nth 4 (org-heading-components)))))))
  7629. (defvar org-agenda-filtered-by-top-headline nil)
  7630. (defun org-agenda-filter-by-top-headline (strip)
  7631. "Keep only those lines that are descendants from the same top headline.
  7632. The top headline is that of the current line. With prefix arg STRIP, hide
  7633. all lines of the category at point."
  7634. (interactive "P")
  7635. (if org-agenda-filtered-by-top-headline
  7636. (progn
  7637. (setq org-agenda-filtered-by-top-headline nil
  7638. org-agenda-top-headline-filter nil)
  7639. (org-agenda-filter-show-all-top-filter))
  7640. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7641. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7642. (error "No top-level headline at point")))))
  7643. (defvar org-agenda-regexp-filter nil)
  7644. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7645. "Filter agenda entries by a regular expressions.
  7646. You will be prompted for the regular expression, and the agenda
  7647. view will only show entries that are matched by that expression.
  7648. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7649. When there is already a regexp filter active, this command removed the
  7650. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7651. an already existing regexp filter."
  7652. (interactive "P")
  7653. (let* ((strip (equal strip-or-accumulate '(4)))
  7654. (accumulate (equal strip-or-accumulate '(16))))
  7655. (cond
  7656. ((and org-agenda-regexp-filter (not accumulate))
  7657. (org-agenda-filter-show-all-re)
  7658. (message "Regexp filter removed"))
  7659. (t (let ((flt (concat (if strip "-" "+")
  7660. (read-from-minibuffer
  7661. (if strip
  7662. "Hide entries matching regexp: "
  7663. "Narrow to entries matching regexp: ")))))
  7664. (push flt org-agenda-regexp-filter)
  7665. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7666. (defvar org-agenda-effort-filter nil)
  7667. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7668. "Filter agenda entries by effort.
  7669. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7670. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7671. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7672. This last option is in practice not very useful, but it is available for
  7673. consistency with the other filter commands."
  7674. (interactive "P")
  7675. (let* ((efforts (split-string
  7676. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7677. org-global-properties
  7678. t))
  7679. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7680. ;; XXX: the following handles only up to 10 different
  7681. ;; effort values.
  7682. (allowed-keys (if (null efforts) nil
  7683. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7684. (number-sequence 1 (length efforts)))))
  7685. (keep (equal strip-or-accumulate '(16)))
  7686. (negative (equal strip-or-accumulate '(4)))
  7687. (current org-agenda-effort-filter)
  7688. (op nil))
  7689. (while (not (memq op '(?< ?> ?= ?_)))
  7690. (setq op (read-char-exclusive
  7691. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7692. ;; Select appropriate duration. Ignore non-digit characters.
  7693. (if (eq op ?_)
  7694. (progn
  7695. (org-agenda-filter-show-all-effort)
  7696. (message "Effort filter removed"))
  7697. (let ((prompt
  7698. (apply #'format
  7699. (concat "Effort %c "
  7700. (mapconcat (lambda (s) (concat "[%d]" s))
  7701. efforts
  7702. " "))
  7703. op allowed-keys))
  7704. (eff -1))
  7705. (while (not (memq eff allowed-keys))
  7706. (message prompt)
  7707. (setq eff (- (read-char-exclusive) 48)))
  7708. (org-agenda-filter-show-all-effort)
  7709. (setq org-agenda-effort-filter
  7710. (append
  7711. (list (concat (if negative "-" "+")
  7712. (char-to-string op)
  7713. ;; Numbering is 1 2 3 ... 9 0, but we want
  7714. ;; 0 1 2 ... 8 9.
  7715. (nth (mod (1- eff) 10) efforts)))
  7716. (if keep current nil)))
  7717. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7718. (defun org-agenda-filter (&optional strip-or-accumulate)
  7719. "Prompt for a general filter string and apply it to the agenda.
  7720. The string may contain filter elements like
  7721. +category
  7722. +tag
  7723. +<effort > and = are also allowed as effort operators
  7724. +/regexp/
  7725. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7726. `+' is optional if it is not required to separate two string parts.
  7727. Multiple filter elements can be concatenated without spaces, for example
  7728. +work-John<0:10-/plot/
  7729. selects entries with category `work' and effort estimates below 10 minutes,
  7730. and deselects entries with tag `John' or matching the regexp `plot'.
  7731. During entry of the filter, completion for tags, categories and effort
  7732. values is offered. Since the syntax for categories and tags is identical
  7733. there should be no overlap between categories and tags. If there is, tags
  7734. get priority.
  7735. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7736. entire filter, which can be useful in connection with the prompt history.
  7737. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7738. existing ones. A shortcut for this is to add an additional `+' at the
  7739. beginning of the string, like `+-John'.
  7740. With a triple prefix argument, execute the computed filtering defined in
  7741. the variable `org-agenda-auto-exclude-function'."
  7742. (interactive "P")
  7743. (if (equal strip-or-accumulate '(64))
  7744. ;; Execute the auto-exclude action
  7745. (if (not org-agenda-auto-exclude-function)
  7746. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7747. (org-agenda-filter-show-all-tag)
  7748. (setq org-agenda-tag-filter nil)
  7749. (dolist (tag (org-agenda-get-represented-tags))
  7750. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7751. (when modifier
  7752. (push modifier org-agenda-tag-filter))))
  7753. (unless (null org-agenda-tag-filter)
  7754. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7755. ;; Prompt for a filter and act
  7756. (let* ((tag-list (org-agenda-get-represented-tags))
  7757. (category-list (org-agenda-get-represented-categories))
  7758. (negate (equal strip-or-accumulate '(4)))
  7759. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7760. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7761. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7762. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7763. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7764. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7765. (f-string (completing-read
  7766. (concat
  7767. (if negate "Negative filter" "Filter")
  7768. " [+cat-tag<0:10-/regexp/]: ")
  7769. #'org-agenda-filter-completion-function
  7770. nil nil ff))
  7771. (keep (or (if (string-match "^\\+[+-]" f-string)
  7772. (progn (setq f-string (substring f-string 1)) t))
  7773. (equal strip-or-accumulate '(16))))
  7774. (fc (if keep org-agenda-category-filter))
  7775. (ft (if keep org-agenda-tag-filter))
  7776. (fe (if keep org-agenda-effort-filter))
  7777. (fr (if keep org-agenda-regexp-filter))
  7778. pm s)
  7779. ;; If the filter contains a double-quoted string, replace a
  7780. ;; single hyphen by the arbitrary and temporary string "~~~"
  7781. ;; to disambiguate such hyphens from syntactic ones.
  7782. (setq f-string (replace-regexp-in-string
  7783. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7784. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7785. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7786. (when negate
  7787. (setq pm (if (equal pm "+") "-" "+")))
  7788. (cond
  7789. ((match-beginning 3)
  7790. ;; category or tag
  7791. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7792. "~~~" "-" (match-string 3 f-string)))
  7793. (cond
  7794. ((member s tag-list)
  7795. (org-pushnew-to-end (concat pm s) ft))
  7796. ((member s category-list)
  7797. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7798. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7799. fc))
  7800. (t (message
  7801. "`%s%s' filter ignored because tag/category is not represented"
  7802. pm s))))
  7803. ((match-beginning 4)
  7804. ;; effort
  7805. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7806. ((match-beginning 5)
  7807. ;; regexp
  7808. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7809. (setq f-string (substring f-string (match-end 0))))
  7810. (org-agenda-filter-remove-all)
  7811. (and fc (org-agenda-filter-apply
  7812. (setq org-agenda-category-filter fc) 'category))
  7813. (and ft (org-agenda-filter-apply
  7814. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7815. (and fe (org-agenda-filter-apply
  7816. (setq org-agenda-effort-filter fe) 'effort))
  7817. (and fr (org-agenda-filter-apply
  7818. (setq org-agenda-regexp-filter fr) 'regexp))
  7819. (run-hooks 'org-agenda-filter-hook))))
  7820. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7821. "Complete a complex filter string.
  7822. FLAG specifies the type of completion operation to perform. This
  7823. function is passed as a collection function to `completing-read',
  7824. which see."
  7825. (let ((completion-ignore-case t) ;tags are case-sensitive
  7826. (confirm (lambda (x) (stringp x)))
  7827. (prefix "")
  7828. (operator "")
  7829. table)
  7830. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7831. (setq prefix (match-string 1 string)
  7832. operator (match-string 2 string)
  7833. string (match-string 3 string)))
  7834. (cond
  7835. ((member operator '("+" "-" "" nil))
  7836. (setq table (append (org-agenda-get-represented-categories)
  7837. (org-agenda-get-represented-tags))))
  7838. ((member operator '("<" ">" "="))
  7839. (setq table (split-string
  7840. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7841. org-global-properties
  7842. t))
  7843. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7844. " +")))
  7845. (t (setq table nil)))
  7846. (pcase flag
  7847. (`t (all-completions string table confirm))
  7848. (`lambda (assoc string table)) ;exact match?
  7849. (`nil
  7850. (pcase (try-completion string table confirm)
  7851. ((and completion (pred stringp))
  7852. (concat prefix completion))
  7853. (completion completion)))
  7854. (_ nil))))
  7855. (defun org-agenda-filter-remove-all ()
  7856. "Remove all filters from the current agenda buffer."
  7857. (interactive)
  7858. (when org-agenda-tag-filter
  7859. (org-agenda-filter-show-all-tag))
  7860. (when org-agenda-category-filter
  7861. (org-agenda-filter-show-all-cat))
  7862. (when org-agenda-regexp-filter
  7863. (org-agenda-filter-show-all-re))
  7864. (when org-agenda-top-headline-filter
  7865. (org-agenda-filter-show-all-top-filter))
  7866. (when org-agenda-effort-filter
  7867. (org-agenda-filter-show-all-effort))
  7868. (org-agenda-finalize)
  7869. (when (called-interactively-p 'interactive)
  7870. (message "All agenda filters removed")))
  7871. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7872. "Keep only those lines in the agenda buffer that have a specific tag.
  7873. The tag is selected with its fast selection letter, as configured.
  7874. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7875. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7876. instead of replacing it.
  7877. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7878. i.e. don't
  7879. filter on all its group members.
  7880. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7881. should be used to exclude the search - the interactive user can
  7882. also press `-' or `+' to switch between filtering and excluding."
  7883. (interactive "P")
  7884. (let* ((alist org-tag-alist-for-agenda)
  7885. (seen-chars nil)
  7886. (tag-chars (mapconcat
  7887. (lambda (x) (if (and (not (symbolp (car x)))
  7888. (cdr x)
  7889. (not (member (cdr x) seen-chars)))
  7890. (progn
  7891. (push (cdr x) seen-chars)
  7892. (char-to-string (cdr x)))
  7893. ""))
  7894. org-tag-alist-for-agenda ""))
  7895. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7896. (string-to-list tag-chars)))
  7897. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7898. (accumulate (equal strip-or-accumulate '(16)))
  7899. (expand (not (equal strip-or-accumulate '(64))))
  7900. (inhibit-read-only t)
  7901. (current org-agenda-tag-filter)
  7902. a tag) ;; n
  7903. (unless char
  7904. (while (not (memq char valid-char-list))
  7905. (org-unlogged-message
  7906. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7907. (if exclude "Exclude[+]" "Filter[-]")
  7908. (if expand "" " (no grouptag expand)")
  7909. tag-chars
  7910. (if org-agenda-auto-exclude-function "[RET] " ""))
  7911. (setq char (read-char-exclusive))
  7912. ;; Excluding or filtering down
  7913. (cond ((eq char ?-) (setq exclude t))
  7914. ((eq char ?+) (setq exclude nil)))))
  7915. (when (eq char ?\t)
  7916. (unless (local-variable-p 'org-global-tags-completion-table)
  7917. (setq-local org-global-tags-completion-table
  7918. (org-global-tags-completion-table)))
  7919. (let ((completion-ignore-case t))
  7920. (setq tag (completing-read
  7921. "Tag: " org-global-tags-completion-table nil t))))
  7922. (cond
  7923. ((eq char ?\r)
  7924. (org-agenda-filter-show-all-tag)
  7925. (when org-agenda-auto-exclude-function
  7926. (setq org-agenda-tag-filter nil)
  7927. (dolist (tag (org-agenda-get-represented-tags))
  7928. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7929. (when modifier
  7930. (push modifier org-agenda-tag-filter))))
  7931. (unless (null org-agenda-tag-filter)
  7932. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7933. ((eq char ?\\)
  7934. (org-agenda-filter-show-all-tag)
  7935. (when (get 'org-agenda-tag-filter :preset-filter)
  7936. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7937. ((eq char ?.)
  7938. (setq org-agenda-tag-filter
  7939. (mapcar (lambda(tag) (concat "+" tag))
  7940. (org-get-at-bol 'tags)))
  7941. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7942. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7943. ((or (eq char ?\s)
  7944. (setq a (rassoc char alist))
  7945. (and tag (setq a (cons tag nil))))
  7946. (org-agenda-filter-show-all-tag)
  7947. (setq tag (car a))
  7948. (setq org-agenda-tag-filter
  7949. (cons (concat (if exclude "-" "+") tag)
  7950. (if accumulate current nil)))
  7951. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7952. (t (error "Invalid tag selection character %c" char)))))
  7953. (defun org-agenda-get-represented-categories ()
  7954. "Return a list of all categories used in this agenda buffer."
  7955. (or org-agenda-represented-categories
  7956. (when (derived-mode-p 'org-agenda-mode)
  7957. (let ((pos (point-min)) categories)
  7958. (while (and (< pos (point-max))
  7959. (setq pos (next-single-property-change
  7960. pos 'org-category nil (point-max))))
  7961. (push (get-text-property pos 'org-category) categories))
  7962. (setq org-agenda-represented-categories
  7963. ;; Enclose category names with a hyphen in double
  7964. ;; quotes to process them specially in `org-agenda-filter'.
  7965. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7966. (nreverse (org-uniquify (delq nil categories)))))))))
  7967. (defvar org-tag-groups-alist-for-agenda)
  7968. (defun org-agenda-get-represented-tags ()
  7969. "Return a list of all tags used in this agenda buffer.
  7970. These will be lower-case, for filtering."
  7971. (or org-agenda-represented-tags
  7972. (when (derived-mode-p 'org-agenda-mode)
  7973. (let ((pos (point-min)) tags-lists tt)
  7974. (while (and (< pos (point-max))
  7975. (setq pos (next-single-property-change
  7976. pos 'tags nil (point-max))))
  7977. (setq tt (get-text-property pos 'tags))
  7978. (if tt (push tt tags-lists)))
  7979. (setq tags-lists
  7980. (nreverse (org-uniquify
  7981. (delq nil (apply #'append tags-lists)))))
  7982. (dolist (tag tags-lists)
  7983. (mapc
  7984. (lambda (group)
  7985. (when (member tag group)
  7986. (push (car group) tags-lists)))
  7987. org-tag-groups-alist-for-agenda))
  7988. (setq org-agenda-represented-tags tags-lists)))))
  7989. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7990. "Create the form that tests a line for agenda filter.
  7991. Optional argument EXPAND can be used for the TYPE tag and will
  7992. expand the tags in the FILTER if any of the tags in FILTER are
  7993. grouptags."
  7994. (let ((multi-pos-cats
  7995. (and (eq type 'category)
  7996. (string-match-p "\\+.*\\+"
  7997. (mapconcat (lambda (cat) (substring cat 0 1))
  7998. filter ""))))
  7999. f f1)
  8000. (cond
  8001. ;; Tag filter
  8002. ((eq type 'tag)
  8003. (setq filter
  8004. (delete-dups
  8005. (append (get 'org-agenda-tag-filter :preset-filter)
  8006. filter)))
  8007. (dolist (x filter)
  8008. (let ((op (string-to-char x)))
  8009. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8010. (setq x (list x)))
  8011. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8012. (push f1 f))))
  8013. ;; Category filter
  8014. ((eq type 'category)
  8015. (setq filter
  8016. (delete-dups
  8017. (append (get 'org-agenda-category-filter :preset-filter)
  8018. filter)))
  8019. (dolist (x filter)
  8020. (if (equal "-" (substring x 0 1))
  8021. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8022. (setq f1 (list 'equal (substring x 1) 'cat)))
  8023. (push f1 f)))
  8024. ;; Regexp filter
  8025. ((eq type 'regexp)
  8026. (setq filter
  8027. (delete-dups
  8028. (append (get 'org-agenda-regexp-filter :preset-filter)
  8029. filter)))
  8030. (dolist (x filter)
  8031. (if (equal "-" (substring x 0 1))
  8032. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8033. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8034. (push f1 f)))
  8035. ;; Effort filter
  8036. ((eq type 'effort)
  8037. (setq filter
  8038. (delete-dups
  8039. (append (get 'org-agenda-effort-filter :preset-filter)
  8040. filter)))
  8041. (dolist (x filter)
  8042. (push (org-agenda-filter-effort-form x) f))))
  8043. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8044. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8045. "Return a form associated to tag-expression TAGS.
  8046. Build a form testing a line for agenda filter for
  8047. tag-expressions. OP is an operator of type CHAR that allows the
  8048. function to set the right switches in the returned form."
  8049. (let (form)
  8050. ;; Any of the expressions can match if OP is +, all must match if
  8051. ;; the operator is -.
  8052. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8053. (let* ((tag (substring x 1))
  8054. (f (cond
  8055. ((string= "" tag) 'tags)
  8056. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8057. ;; TAG is a regexp.
  8058. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8059. (t (list 'member tag 'tags)))))
  8060. (push (if (eq op ?-) (list 'not f) f) form)))))
  8061. (defun org-agenda-filter-effort-form (e)
  8062. "Return the form to compare the effort of the current line with what E says.
  8063. E looks like \"+<2:25\"."
  8064. (let (op)
  8065. (setq e (substring e 1))
  8066. (setq op (string-to-char e) e (substring e 1))
  8067. (setq op (cond ((equal op ?<) '<=)
  8068. ((equal op ?>) '>=)
  8069. ((equal op ??) op)
  8070. (t '=)))
  8071. (list 'org-agenda-compare-effort (list 'quote op)
  8072. (org-duration-to-minutes e))))
  8073. (defun org-agenda-compare-effort (op value)
  8074. "Compare the effort of the current line with VALUE, using OP.
  8075. If the line does not have an effort defined, return nil."
  8076. ;; `effort-minutes' property cannot be extracted directly from
  8077. ;; current line but is stored as a property in `txt'.
  8078. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8079. (funcall op
  8080. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8081. value)))
  8082. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8083. "Expand group tags in FILTER for the agenda.
  8084. When NO-OPERATOR is non-nil, do not add the + operator to
  8085. returned tags."
  8086. (if org-group-tags
  8087. (let (case-fold-search rtn)
  8088. (mapc
  8089. (lambda (f)
  8090. (let (f0 dir)
  8091. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8092. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8093. (setq dir (if no-operator "" "+") f0 f))
  8094. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8095. (org-tags-expand f0 t))
  8096. rtn))))
  8097. filter)
  8098. (reverse rtn))
  8099. filter))
  8100. (defun org-agenda-filter-apply (filter type &optional expand)
  8101. "Set FILTER as the new agenda filter and apply it.
  8102. Optional argument EXPAND can be used for the TYPE tag and will
  8103. expand the tags in the FILTER if any of the tags in FILTER are
  8104. grouptags."
  8105. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8106. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8107. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8108. filter type expand))
  8109. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8110. ;; category is used as the filter:
  8111. (setq org-agenda-filtered-by-category
  8112. (and (eq type 'category)
  8113. (not (equal (substring (car filter) 0 1) "-"))))
  8114. (org-agenda-set-mode-name)
  8115. (save-excursion
  8116. (goto-char (point-min))
  8117. (while (not (eobp))
  8118. (when (or (org-get-at-bol 'org-hd-marker)
  8119. (org-get-at-bol 'org-marker))
  8120. (org-dlet
  8121. ((tags (org-get-at-bol 'tags))
  8122. (cat (org-agenda-get-category))
  8123. (txt (or (org-get-at-bol 'txt) "")))
  8124. (unless (eval org-agenda-filter-form t)
  8125. (org-agenda-filter-hide-line type))))
  8126. (beginning-of-line 2)))
  8127. (when (get-char-property (point) 'invisible)
  8128. (ignore-errors (org-agenda-previous-line))))
  8129. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8130. "Filter by top headline HL."
  8131. (org-agenda-set-mode-name)
  8132. (save-excursion
  8133. (goto-char (point-min))
  8134. (while (not (eobp))
  8135. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8136. (tophl (and pos (org-find-top-headline pos))))
  8137. (when (and tophl (funcall (if negative 'identity 'not)
  8138. (string= hl tophl)))
  8139. (org-agenda-filter-hide-line 'top-headline)))
  8140. (beginning-of-line 2)))
  8141. (when (get-char-property (point) 'invisible)
  8142. (org-agenda-previous-line))
  8143. (setq org-agenda-top-headline-filter hl
  8144. org-agenda-filtered-by-top-headline t))
  8145. (defun org-agenda-filter-hide-line (type)
  8146. "If current line is TYPE, hide it in the agenda buffer."
  8147. (let* (buffer-invisibility-spec
  8148. (beg (max (point-min) (1- (point-at-bol))))
  8149. (end (point-at-eol)))
  8150. (let ((inhibit-read-only t))
  8151. (add-text-properties
  8152. beg end `(invisible org-filtered org-filter-type ,type)))))
  8153. (defun org-agenda-remove-filter (type)
  8154. "Remove filter of type TYPE from the agenda buffer."
  8155. (interactive)
  8156. (save-excursion
  8157. (goto-char (point-min))
  8158. (let ((inhibit-read-only t) pos)
  8159. (while (setq pos (text-property-any (point) (point-max)
  8160. 'org-filter-type type))
  8161. (goto-char pos)
  8162. (remove-text-properties
  8163. (point) (next-single-property-change (point) 'org-filter-type)
  8164. `(invisible org-filtered org-filter-type ,type))))
  8165. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8166. (setq org-agenda-filter-form nil)
  8167. (org-agenda-set-mode-name)
  8168. (org-agenda-finalize)))
  8169. (defun org-agenda-filter-show-all-tag nil
  8170. (org-agenda-remove-filter 'tag))
  8171. (defun org-agenda-filter-show-all-re nil
  8172. (org-agenda-remove-filter 'regexp))
  8173. (defun org-agenda-filter-show-all-effort nil
  8174. (org-agenda-remove-filter 'effort))
  8175. (defun org-agenda-filter-show-all-cat nil
  8176. (org-agenda-remove-filter 'category))
  8177. (defun org-agenda-filter-show-all-top-filter nil
  8178. (org-agenda-remove-filter 'top-headline))
  8179. (defun org-agenda-manipulate-query-add ()
  8180. "Manipulate the query by adding a search term with positive selection.
  8181. Positive selection means the term must be matched for selection of an entry."
  8182. (interactive)
  8183. (org-agenda-manipulate-query ?\[))
  8184. (defun org-agenda-manipulate-query-subtract ()
  8185. "Manipulate the query by adding a search term with negative selection.
  8186. Negative selection means term must not be matched for selection of an entry."
  8187. (interactive)
  8188. (org-agenda-manipulate-query ?\]))
  8189. (defun org-agenda-manipulate-query-add-re ()
  8190. "Manipulate the query by adding a search regexp with positive selection.
  8191. Positive selection means the regexp must match for selection of an entry."
  8192. (interactive)
  8193. (org-agenda-manipulate-query ?\{))
  8194. (defun org-agenda-manipulate-query-subtract-re ()
  8195. "Manipulate the query by adding a search regexp with negative selection.
  8196. Negative selection means regexp must not match for selection of an entry."
  8197. (interactive)
  8198. (org-agenda-manipulate-query ?\}))
  8199. (defun org-agenda-manipulate-query (char)
  8200. (cond
  8201. ((eq org-agenda-type 'agenda)
  8202. (let ((org-agenda-include-inactive-timestamps t))
  8203. (org-agenda-redo))
  8204. (message "Display now includes inactive timestamps as well"))
  8205. ((eq org-agenda-type 'search)
  8206. (org-add-to-string
  8207. 'org-agenda-query-string
  8208. (if org-agenda-last-search-view-search-was-boolean
  8209. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8210. (?\{ . " +{}") (?\} . " -{}"))))
  8211. " "))
  8212. (setq org-agenda-redo-command
  8213. (list 'org-search-view
  8214. (car (get-text-property (min (1- (point-max)) (point))
  8215. 'org-last-args))
  8216. org-agenda-query-string
  8217. (+ (length org-agenda-query-string)
  8218. (if (member char '(?\{ ?\})) 0 1))))
  8219. (set-register org-agenda-query-register org-agenda-query-string)
  8220. (let ((org-agenda-overriding-arguments
  8221. (cdr org-agenda-redo-command)))
  8222. (org-agenda-redo)))
  8223. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8224. org-agenda-type))))
  8225. (defun org-add-to-string (var string)
  8226. (set var (concat (symbol-value var) string)))
  8227. (defun org-agenda-goto-date (date)
  8228. "Jump to DATE in agenda."
  8229. (interactive
  8230. (list
  8231. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8232. (org-read-date))))
  8233. (let* ((day (time-to-days (org-time-string-to-time date)))
  8234. (org-agenda-sticky-orig org-agenda-sticky)
  8235. (org-agenda-buffer-tmp-name (buffer-name))
  8236. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8237. (0-arg (or current-prefix-arg (car args)))
  8238. (2-arg (nth 2 args))
  8239. (with-hour-p (nth 4 org-agenda-redo-command))
  8240. (newcmd (list 'org-agenda-list 0-arg date
  8241. (org-agenda-span-to-ndays
  8242. 2-arg (org-time-string-to-absolute date))
  8243. with-hour-p))
  8244. (newargs (cdr newcmd))
  8245. (inhibit-read-only t)
  8246. org-agenda-sticky)
  8247. (if (not (org-agenda-check-type t 'agenda))
  8248. (error "Not available in non-agenda views")
  8249. (add-text-properties (point-min) (point-max)
  8250. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8251. (org-agenda-redo)
  8252. (goto-char (point-min))
  8253. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8254. (save-excursion (move-beginning-of-line 2) (eobp))))
  8255. (move-beginning-of-line 2))
  8256. (setq org-agenda-sticky org-agenda-sticky-orig
  8257. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8258. (defun org-agenda-goto-today ()
  8259. "Go to today."
  8260. (interactive)
  8261. (org-agenda-check-type t 'agenda)
  8262. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8263. (curspan (nth 2 args))
  8264. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8265. (cond
  8266. (tdpos (goto-char tdpos))
  8267. ((eq org-agenda-type 'agenda)
  8268. (let* ((sd (org-agenda-compute-starting-span
  8269. (org-today) (or curspan org-agenda-span)))
  8270. (org-agenda-overriding-arguments args))
  8271. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8272. (org-agenda-redo)
  8273. (org-agenda-find-same-or-today-or-agenda)))
  8274. (t (error "Cannot find today")))))
  8275. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8276. (goto-char
  8277. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8278. (text-property-any (point-min) (point-max) 'org-today t)
  8279. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8280. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8281. (org-agenda-backward-block))
  8282. (point-min))))
  8283. (defun org-agenda-backward-block ()
  8284. "Move backward by one agenda block."
  8285. (interactive)
  8286. (org-agenda-forward-block 'backward))
  8287. (defun org-agenda-forward-block (&optional backward)
  8288. "Move forward by one agenda block.
  8289. When optional argument BACKWARD is set, go backward."
  8290. (interactive)
  8291. (cond ((not (derived-mode-p 'org-agenda-mode))
  8292. (user-error
  8293. "Cannot execute this command outside of org-agenda-mode buffers"))
  8294. ((looking-at (if backward "\\`" "\\'"))
  8295. (message "Already at the %s block" (if backward "first" "last")))
  8296. (t (let ((_pos (prog1 (point)
  8297. (ignore-errors (if backward (backward-char 1)
  8298. (move-end-of-line 1)))))
  8299. (f (if backward
  8300. #'previous-single-property-change
  8301. #'next-single-property-change))
  8302. moved dest)
  8303. (while (and (setq dest (funcall
  8304. f (point) 'org-agenda-structural-header))
  8305. (not (get-text-property
  8306. (point) 'org-agenda-structural-header)))
  8307. (setq moved t)
  8308. (goto-char dest))
  8309. (if moved (move-beginning-of-line 1)
  8310. (goto-char (if backward (point-min) (point-max)))
  8311. (move-beginning-of-line 1)
  8312. (message "No %s block" (if backward "previous" "further")))))))
  8313. (defun org-agenda-later (arg)
  8314. "Go forward in time by the current span.
  8315. With prefix ARG, go forward that many times the current span."
  8316. (interactive "p")
  8317. (org-agenda-check-type t 'agenda)
  8318. (let* ((wstart (window-start))
  8319. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8320. (span (or (nth 2 args) org-agenda-current-span))
  8321. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8322. (greg (calendar-gregorian-from-absolute sd))
  8323. (cnt (org-get-at-bol 'org-day-cnt))
  8324. greg2)
  8325. (cond
  8326. ((numberp span)
  8327. (setq sd (+ (* span arg) sd)))
  8328. ((eq span 'day)
  8329. (setq sd (+ arg sd)))
  8330. ((eq span 'week)
  8331. (setq sd (+ (* 7 arg) sd)))
  8332. ((eq span 'fortnight)
  8333. (setq sd (+ (* 14 arg) sd)))
  8334. ((eq span 'month)
  8335. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8336. sd (calendar-absolute-from-gregorian greg2))
  8337. (setcar greg2 (1+ (car greg2))))
  8338. ((eq span 'year)
  8339. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8340. sd (calendar-absolute-from-gregorian greg2))
  8341. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8342. (t
  8343. (setq sd (+ (* span arg) sd))))
  8344. (let ((org-agenda-overriding-cmd
  8345. ;; `cmd' may have been set by `org-agenda-run-series' which
  8346. ;; uses `org-agenda-overriding-cmd' to decide whether
  8347. ;; overriding is allowed for `cmd'
  8348. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8349. (org-agenda-overriding-arguments
  8350. (list (car args) sd span)))
  8351. (org-agenda-redo)
  8352. (org-agenda-find-same-or-today-or-agenda cnt))
  8353. (set-window-start nil wstart)))
  8354. (defun org-agenda-earlier (arg)
  8355. "Go backward in time by the current span.
  8356. With prefix ARG, go backward that many times the current span."
  8357. (interactive "p")
  8358. (org-agenda-later (- arg)))
  8359. (defun org-agenda-view-mode-dispatch ()
  8360. "Call one of the view mode commands."
  8361. (interactive)
  8362. (org-unlogged-message
  8363. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8364. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8365. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8366. (pcase (read-char-exclusive)
  8367. (?\ (call-interactively 'org-agenda-reset-view))
  8368. (?d (call-interactively 'org-agenda-day-view))
  8369. (?w (call-interactively 'org-agenda-week-view))
  8370. (?t (call-interactively 'org-agenda-fortnight-view))
  8371. (?m (call-interactively 'org-agenda-month-view))
  8372. (?y (call-interactively 'org-agenda-year-view))
  8373. (?l (call-interactively 'org-agenda-log-mode))
  8374. (?L (org-agenda-log-mode '(4)))
  8375. (?c (org-agenda-log-mode 'clockcheck))
  8376. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8377. (?a (call-interactively 'org-agenda-archives-mode))
  8378. (?A (org-agenda-archives-mode 'files))
  8379. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8380. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8381. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8382. (?D (call-interactively 'org-agenda-toggle-diary))
  8383. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8384. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8385. (org-agenda-check-type t 'agenda)
  8386. (org-agenda-redo))
  8387. (message "Display now includes inactive timestamps as well"))
  8388. (?q (message "Abort"))
  8389. (key (user-error "Invalid key: %s" key))))
  8390. (defun org-agenda-reset-view ()
  8391. "Switch to default view for agenda."
  8392. (interactive)
  8393. (org-agenda-change-time-span org-agenda-span))
  8394. (defun org-agenda-day-view (&optional day-of-month)
  8395. "Switch to daily view for agenda.
  8396. With argument DAY-OF-MONTH, switch to that day of the month."
  8397. (interactive "P")
  8398. (org-agenda-change-time-span 'day day-of-month))
  8399. (defun org-agenda-week-view (&optional iso-week)
  8400. "Switch to weekly view for agenda.
  8401. With argument ISO-WEEK, switch to the corresponding ISO week.
  8402. If ISO-WEEK has more then 2 digits, only the last two encode
  8403. the week. Any digits before this encode a year. So 200712
  8404. means week 12 of year 2007. Years ranging from 70 years ago
  8405. to 30 years in the future can also be written as 2-digit years."
  8406. (interactive "P")
  8407. (org-agenda-change-time-span 'week iso-week))
  8408. (defun org-agenda-fortnight-view (&optional iso-week)
  8409. "Switch to fortnightly view for agenda.
  8410. With argument ISO-WEEK, switch to the corresponding ISO week.
  8411. If ISO-WEEK has more then 2 digits, only the last two encode
  8412. the week. Any digits before this encode a year. So 200712
  8413. means week 12 of year 2007. Years ranging from 70 years ago
  8414. to 30 years in the future can also be written as 2-digit years."
  8415. (interactive "P")
  8416. (org-agenda-change-time-span 'fortnight iso-week))
  8417. (defun org-agenda-month-view (&optional month)
  8418. "Switch to monthly view for agenda.
  8419. With argument MONTH, switch to that month. If MONTH has more
  8420. then 2 digits, only the last two encode the month. Any digits
  8421. before this encode a year. So 200712 means December year 2007.
  8422. Years ranging from 70 years ago to 30 years in the future can
  8423. also be written as 2-digit years."
  8424. (interactive "P")
  8425. (org-agenda-change-time-span 'month month))
  8426. (defun org-agenda-year-view (&optional year)
  8427. "Switch to yearly view for agenda.
  8428. With argument YEAR, switch to that year. Years ranging from 70
  8429. years ago to 30 years in the future can also be written as
  8430. 2-digit years."
  8431. (interactive "P")
  8432. (when year
  8433. (setq year (org-small-year-to-year year)))
  8434. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8435. (org-agenda-change-time-span 'year year)
  8436. (error "Abort")))
  8437. (defun org-agenda-change-time-span (span &optional n)
  8438. "Change the agenda view to SPAN.
  8439. SPAN may be `day', `week', `fortnight', `month', `year'."
  8440. (org-agenda-check-type t 'agenda)
  8441. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8442. (curspan (nth 2 args)))
  8443. (when (and (not n) (equal curspan span))
  8444. (error "Viewing span is already \"%s\"" span))
  8445. (let* ((sd (or (org-get-at-bol 'day)
  8446. (nth 1 args)
  8447. org-starting-day))
  8448. (sd (org-agenda-compute-starting-span sd span n))
  8449. (org-agenda-overriding-cmd
  8450. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8451. (org-agenda-overriding-arguments
  8452. (list (car args) sd span)))
  8453. (org-agenda-redo)
  8454. (org-agenda-find-same-or-today-or-agenda))
  8455. (org-agenda-set-mode-name)
  8456. (message "Switched to %s view" span)))
  8457. (defun org-agenda-compute-starting-span (sd span &optional n)
  8458. "Compute starting date for agenda.
  8459. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8460. is a cons cell with the starting date and the number of days,
  8461. so that the date SD will be in that range."
  8462. (let* ((greg (calendar-gregorian-from-absolute sd))
  8463. ;; (dg (nth 1 greg))
  8464. (mg (car greg))
  8465. (yg (nth 2 greg)))
  8466. (cond
  8467. ((eq span 'day)
  8468. (when n
  8469. (setq sd (+ (calendar-absolute-from-gregorian
  8470. (list mg 1 yg))
  8471. n -1))))
  8472. ((or (eq span 'week) (eq span 'fortnight))
  8473. (let* ((nt (calendar-day-of-week
  8474. (calendar-gregorian-from-absolute sd)))
  8475. (d (if org-agenda-start-on-weekday
  8476. (- nt org-agenda-start-on-weekday)
  8477. 0))
  8478. y1)
  8479. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8480. (when n
  8481. (require 'cal-iso)
  8482. (when (> n 99)
  8483. (setq y1 (org-small-year-to-year (/ n 100))
  8484. n (mod n 100)))
  8485. (setq sd
  8486. (calendar-iso-to-absolute
  8487. (list n 1
  8488. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8489. ((eq span 'month)
  8490. (let (y1)
  8491. (when (and n (> n 99))
  8492. (setq y1 (org-small-year-to-year (/ n 100))
  8493. n (mod n 100)))
  8494. (setq sd (calendar-absolute-from-gregorian
  8495. (list (or n mg) 1 (or y1 yg))))))
  8496. ((eq span 'year)
  8497. (setq sd (calendar-absolute-from-gregorian
  8498. (list 1 1 (or n yg))))))
  8499. sd))
  8500. (defun org-agenda-next-date-line (&optional arg)
  8501. "Jump to the next line indicating a date in agenda buffer."
  8502. (interactive "p")
  8503. (org-agenda-check-type t 'agenda)
  8504. (beginning-of-line 1)
  8505. ;; This does not work if user makes date format that starts with a blank
  8506. (when (looking-at-p "^\\S-") (forward-char 1))
  8507. (unless (re-search-forward "^\\S-" nil t arg)
  8508. (backward-char 1)
  8509. (error "No next date after this line in this buffer"))
  8510. (goto-char (match-beginning 0)))
  8511. (defun org-agenda-previous-date-line (&optional arg)
  8512. "Jump to the previous line indicating a date in agenda buffer."
  8513. (interactive "p")
  8514. (org-agenda-check-type t 'agenda)
  8515. (beginning-of-line 1)
  8516. (unless (re-search-backward "^\\S-" nil t arg)
  8517. (error "No previous date before this line in this buffer")))
  8518. ;; Initialize the highlight
  8519. (defvar org-hl (make-overlay 1 1))
  8520. (overlay-put org-hl 'face 'highlight)
  8521. (defun org-highlight (begin end &optional buffer)
  8522. "Highlight a region with overlay."
  8523. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8524. (defun org-unhighlight ()
  8525. "Detach overlay INDEX."
  8526. (delete-overlay org-hl))
  8527. (defun org-unhighlight-once ()
  8528. "Remove the highlight from its position, and this function from the hook."
  8529. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8530. (org-unhighlight))
  8531. (defvar org-agenda-pre-follow-window-conf nil)
  8532. (defun org-agenda-follow-mode ()
  8533. "Toggle follow mode in an agenda buffer."
  8534. (interactive)
  8535. (unless org-agenda-follow-mode
  8536. (setq org-agenda-pre-follow-window-conf
  8537. (current-window-configuration)))
  8538. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8539. (unless org-agenda-follow-mode
  8540. (set-window-configuration org-agenda-pre-follow-window-conf))
  8541. (org-agenda-set-mode-name)
  8542. (org-agenda-do-context-action)
  8543. (message "Follow mode is %s"
  8544. (if org-agenda-follow-mode "on" "off")))
  8545. (defun org-agenda-entry-text-mode (&optional arg)
  8546. "Toggle entry text mode in an agenda buffer."
  8547. (interactive "P")
  8548. (if (or org-agenda-tag-filter
  8549. org-agenda-category-filter
  8550. org-agenda-regexp-filter
  8551. org-agenda-top-headline-filter)
  8552. (user-error "Can't show entry text in filtered views")
  8553. (setq org-agenda-entry-text-mode (or (integerp arg)
  8554. (not org-agenda-entry-text-mode)))
  8555. (org-agenda-entry-text-hide)
  8556. (and org-agenda-entry-text-mode
  8557. (let ((org-agenda-entry-text-maxlines
  8558. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8559. (org-agenda-entry-text-show)))
  8560. (org-agenda-set-mode-name)
  8561. (message "Entry text mode is %s%s"
  8562. (if org-agenda-entry-text-mode "on" "off")
  8563. (if (not org-agenda-entry-text-mode) ""
  8564. (format " (maximum number of lines is %d)"
  8565. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8566. (defun org-agenda-clockreport-mode ()
  8567. "Toggle clocktable mode in an agenda buffer."
  8568. (interactive)
  8569. (org-agenda-check-type t 'agenda)
  8570. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8571. (org-agenda-set-mode-name)
  8572. (org-agenda-redo)
  8573. (message "Clocktable mode is %s"
  8574. (if org-agenda-clockreport-mode "on" "off")))
  8575. (defun org-agenda-log-mode (&optional special)
  8576. "Toggle log mode in an agenda buffer.
  8577. With argument SPECIAL, show all possible log items, not only the ones
  8578. configured in `org-agenda-log-mode-items'.
  8579. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8580. log items, nothing else."
  8581. (interactive "P")
  8582. (org-agenda-check-type t 'agenda)
  8583. (setq org-agenda-show-log
  8584. (cond
  8585. ((equal special '(16)) 'only)
  8586. ((eq special 'clockcheck)
  8587. (if (eq org-agenda-show-log 'clockcheck)
  8588. nil 'clockcheck))
  8589. (special '(closed clock state))
  8590. (t (not org-agenda-show-log))))
  8591. (org-agenda-set-mode-name)
  8592. (org-agenda-redo)
  8593. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8594. (defun org-agenda-archives-mode (&optional with-files)
  8595. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8596. When called with a prefix argument, include all archive files as well."
  8597. (interactive "P")
  8598. (setq org-agenda-archives-mode
  8599. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8600. (with-files t)
  8601. (org-agenda-archives-mode nil)
  8602. (t 'trees)))
  8603. (org-agenda-set-mode-name)
  8604. (org-agenda-redo)
  8605. (message
  8606. "%s"
  8607. (cond
  8608. ((eq org-agenda-archives-mode nil)
  8609. "No archives are included")
  8610. ((eq org-agenda-archives-mode 'trees)
  8611. (format "Trees with :%s: tag are included" org-archive-tag))
  8612. ((eq org-agenda-archives-mode t)
  8613. (format "Trees with :%s: tag and all active archive files are included"
  8614. org-archive-tag)))))
  8615. (defun org-agenda-toggle-diary ()
  8616. "Toggle diary inclusion in an agenda buffer."
  8617. (interactive)
  8618. (org-agenda-check-type t 'agenda)
  8619. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8620. (org-agenda-redo)
  8621. (org-agenda-set-mode-name)
  8622. (message "Diary inclusion turned %s"
  8623. (if org-agenda-include-diary "on" "off")))
  8624. (defun org-agenda-toggle-deadlines ()
  8625. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8626. (interactive)
  8627. (org-agenda-check-type t 'agenda)
  8628. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8629. (org-agenda-redo)
  8630. (org-agenda-set-mode-name)
  8631. (message "Deadlines inclusion turned %s"
  8632. (if org-agenda-include-deadlines "on" "off")))
  8633. (defun org-agenda-toggle-time-grid ()
  8634. "Toggle time grid in an agenda buffer."
  8635. (interactive)
  8636. (org-agenda-check-type t 'agenda)
  8637. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8638. (org-agenda-redo)
  8639. (org-agenda-set-mode-name)
  8640. (message "Time-grid turned %s"
  8641. (if org-agenda-use-time-grid "on" "off")))
  8642. (defun org-agenda-set-mode-name ()
  8643. "Set the mode name to indicate all the small mode settings."
  8644. (setq mode-name
  8645. (list "Org-Agenda"
  8646. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8647. " "
  8648. '(:eval (org-agenda-span-name org-agenda-current-span))
  8649. (if org-agenda-follow-mode " Follow" "")
  8650. (if org-agenda-entry-text-mode " ETxt" "")
  8651. (if org-agenda-include-diary " Diary" "")
  8652. (if org-agenda-include-deadlines " Ddl" "")
  8653. (if org-agenda-use-time-grid " Grid" "")
  8654. (if (and (boundp 'org-habit-show-habits)
  8655. org-habit-show-habits)
  8656. " Habit" "")
  8657. (cond
  8658. ((consp org-agenda-show-log) " LogAll")
  8659. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8660. (org-agenda-show-log " Log")
  8661. (t ""))
  8662. (if (org-agenda-filter-any) " " "")
  8663. (if (or org-agenda-category-filter
  8664. (get 'org-agenda-category-filter :preset-filter))
  8665. '(:eval (propertize
  8666. (concat "["
  8667. (mapconcat
  8668. #'identity
  8669. (append
  8670. (get 'org-agenda-category-filter :preset-filter)
  8671. org-agenda-category-filter)
  8672. "")
  8673. "]")
  8674. 'face 'org-agenda-filter-category
  8675. 'help-echo "Category used in filtering"))
  8676. "")
  8677. (if (or org-agenda-tag-filter
  8678. (get 'org-agenda-tag-filter :preset-filter))
  8679. '(:eval (propertize
  8680. (concat (mapconcat
  8681. #'identity
  8682. (append
  8683. (get 'org-agenda-tag-filter :preset-filter)
  8684. org-agenda-tag-filter)
  8685. ""))
  8686. 'face 'org-agenda-filter-tags
  8687. 'help-echo "Tags used in filtering"))
  8688. "")
  8689. (if (or org-agenda-effort-filter
  8690. (get 'org-agenda-effort-filter :preset-filter))
  8691. '(:eval (propertize
  8692. (concat (mapconcat
  8693. #'identity
  8694. (append
  8695. (get 'org-agenda-effort-filter :preset-filter)
  8696. org-agenda-effort-filter)
  8697. ""))
  8698. 'face 'org-agenda-filter-effort
  8699. 'help-echo "Effort conditions used in filtering"))
  8700. "")
  8701. (if (or org-agenda-regexp-filter
  8702. (get 'org-agenda-regexp-filter :preset-filter))
  8703. '(:eval (propertize
  8704. (concat (mapconcat
  8705. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8706. (append
  8707. (get 'org-agenda-regexp-filter :preset-filter)
  8708. org-agenda-regexp-filter)
  8709. ""))
  8710. 'face 'org-agenda-filter-regexp
  8711. 'help-echo "Regexp used in filtering"))
  8712. "")
  8713. (if org-agenda-archives-mode
  8714. (if (eq org-agenda-archives-mode t)
  8715. " Archives"
  8716. (format " :%s:" org-archive-tag))
  8717. "")
  8718. (if org-agenda-clockreport-mode " Clock" "")))
  8719. (force-mode-line-update))
  8720. (defun org-agenda-update-agenda-type ()
  8721. "Update the agenda type after each command."
  8722. (setq org-agenda-type
  8723. (or (get-text-property (point) 'org-agenda-type)
  8724. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8725. (defun org-agenda-next-line ()
  8726. "Move cursor to the next line, and show if follow mode is active."
  8727. (interactive)
  8728. (call-interactively 'next-line)
  8729. (org-agenda-do-context-action))
  8730. (defun org-agenda-previous-line ()
  8731. "Move cursor to the previous line, and show if follow-mode is active."
  8732. (interactive)
  8733. (call-interactively 'previous-line)
  8734. (org-agenda-do-context-action))
  8735. (defun org-agenda-next-item (n)
  8736. "Move cursor to next agenda item."
  8737. (interactive "p")
  8738. (let ((col (current-column)))
  8739. (dotimes (_ n)
  8740. (when (next-single-property-change (point-at-eol) 'org-marker)
  8741. (move-end-of-line 1)
  8742. (goto-char (next-single-property-change (point) 'org-marker))))
  8743. (org-move-to-column col))
  8744. (org-agenda-do-context-action))
  8745. (defun org-agenda-previous-item (n)
  8746. "Move cursor to next agenda item."
  8747. (interactive "p")
  8748. (dotimes (_ n)
  8749. (let ((col (current-column))
  8750. (goto (save-excursion
  8751. (move-end-of-line 0)
  8752. (previous-single-property-change (point) 'org-marker))))
  8753. (when goto (goto-char goto))
  8754. (org-move-to-column col)))
  8755. (org-agenda-do-context-action))
  8756. (defun org-agenda-do-context-action ()
  8757. "Show outline path and, maybe, follow mode window."
  8758. (let ((m (org-get-at-bol 'org-marker)))
  8759. (when (and (markerp m) (marker-buffer m))
  8760. (and org-agenda-follow-mode
  8761. (if org-agenda-follow-indirect
  8762. (org-agenda-tree-to-indirect-buffer nil)
  8763. (org-agenda-show)))
  8764. (and org-agenda-show-outline-path
  8765. (org-with-point-at m (org-display-outline-path t))))))
  8766. (defun org-agenda-show-tags ()
  8767. "Show the tags applicable to the current item."
  8768. (interactive)
  8769. (let* ((tags (org-get-at-bol 'tags)))
  8770. (if tags
  8771. (message "Tags are :%s:"
  8772. (org-no-properties (mapconcat #'identity tags ":")))
  8773. (message "No tags associated with this line"))))
  8774. (defun org-agenda-goto (&optional highlight)
  8775. "Go to the entry at point in the corresponding Org file."
  8776. (interactive)
  8777. (let* ((marker (or (org-get-at-bol 'org-marker)
  8778. (org-agenda-error)))
  8779. (buffer (marker-buffer marker))
  8780. (pos (marker-position marker)))
  8781. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8782. (switch-to-buffer-other-window buffer)
  8783. (widen)
  8784. (push-mark)
  8785. (goto-char pos)
  8786. (when (derived-mode-p 'org-mode)
  8787. (org-fold-show-context 'agenda)
  8788. (recenter (/ (window-height) 2))
  8789. (org-back-to-heading t)
  8790. (let ((case-fold-search nil))
  8791. (when (re-search-forward org-complex-heading-regexp nil t)
  8792. (goto-char (match-beginning 4)))))
  8793. (run-hooks 'org-agenda-after-show-hook)
  8794. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8795. (defvar org-agenda-after-show-hook nil
  8796. "Normal hook run after an item has been shown from the agenda.
  8797. Point is in the buffer where the item originated.")
  8798. ;; Defined later in org-agenda.el
  8799. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8800. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8801. "Between region BEG and END, call agenda command CMD.
  8802. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8803. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8804. deletes the agenda entry and don't move to the next entry."
  8805. (save-excursion
  8806. (goto-char beg)
  8807. (let ((mend (move-marker (make-marker) end))
  8808. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8809. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8810. org-agenda-loop-over-headlines-in-active-region))
  8811. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8812. (org-get-at-bol 'level))))
  8813. (while (< (point) mend)
  8814. (let ((ov (make-overlay (point) (point-at-eol))))
  8815. (if (not (or all
  8816. (and match (looking-at-p match))
  8817. (eq level (org-get-at-bol 'level))))
  8818. (org-agenda-next-item 1)
  8819. (overlay-put ov 'face 'region)
  8820. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8821. (when (not delete) (org-agenda-next-item 1))
  8822. (delete-overlay ov)))))))
  8823. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8824. ;; kill,set-property,set-effort] commands may loop over agenda
  8825. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8826. ;; use their own mechanisms on active regions.
  8827. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8828. "Maybe loop over agenda entries and perform CMD.
  8829. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8830. (declare (debug t))
  8831. `(if (and (called-interactively-p 'any)
  8832. org-agenda-loop-over-headlines-in-active-region
  8833. (org-region-active-p))
  8834. (org-agenda-do-in-region
  8835. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8836. ,@body))
  8837. (defun org-agenda-kill ()
  8838. "Kill the entry or subtree belonging to the current agenda entry."
  8839. (interactive)
  8840. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8841. (org-agenda-maybe-loop
  8842. #'org-agenda-kill nil nil t
  8843. (let* ((bufname-orig (buffer-name))
  8844. (marker (or (org-get-at-bol 'org-marker)
  8845. (org-agenda-error)))
  8846. (buffer (marker-buffer marker))
  8847. (pos (marker-position marker))
  8848. (type (org-get-at-bol 'type))
  8849. dbeg dend (n 0))
  8850. (org-with-remote-undo buffer
  8851. (with-current-buffer buffer
  8852. (save-excursion
  8853. (goto-char pos)
  8854. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8855. (setq dbeg (progn (org-back-to-heading t) (point))
  8856. dend (org-end-of-subtree t t))
  8857. (setq dbeg (point-at-bol)
  8858. dend (min (point-max) (1+ (point-at-eol)))))
  8859. (goto-char dbeg)
  8860. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8861. (when (or (eq t org-agenda-confirm-kill)
  8862. (and (numberp org-agenda-confirm-kill)
  8863. (> n org-agenda-confirm-kill)))
  8864. (let ((win-conf (current-window-configuration)))
  8865. (unwind-protect
  8866. (and
  8867. (prog2
  8868. (org-agenda-tree-to-indirect-buffer nil)
  8869. (not (y-or-n-p
  8870. (format "Delete entry with %d lines in buffer \"%s\"? "
  8871. n (buffer-name buffer))))
  8872. (kill-buffer org-last-indirect-buffer))
  8873. (error "Abort"))
  8874. (set-window-configuration win-conf))))
  8875. (let ((org-agenda-buffer-name bufname-orig))
  8876. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8877. (with-current-buffer buffer (delete-region dbeg dend))
  8878. (message "Agenda item and source killed")))))
  8879. (defvar org-archive-default-command) ; defined in org-archive.el
  8880. (defun org-agenda-archive-default ()
  8881. "Archive the entry or subtree belonging to the current agenda entry."
  8882. (interactive)
  8883. (require 'org-archive)
  8884. (funcall-interactively
  8885. #'org-agenda-archive-with org-archive-default-command))
  8886. (defun org-agenda-archive-default-with-confirmation ()
  8887. "Archive the entry or subtree belonging to the current agenda entry."
  8888. (interactive)
  8889. (require 'org-archive)
  8890. (funcall-interactively
  8891. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8892. (defun org-agenda-archive ()
  8893. "Archive the entry or subtree belonging to the current agenda entry."
  8894. (interactive)
  8895. (funcall-interactively
  8896. #'org-agenda-archive-with 'org-archive-subtree))
  8897. (defun org-agenda-archive-to-archive-sibling ()
  8898. "Move the entry to the archive sibling."
  8899. (interactive)
  8900. (funcall-interactively
  8901. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8902. (defvar org-archive-from-agenda)
  8903. (defun org-agenda-archive-with (cmd &optional confirm)
  8904. "Move the entry to the archive sibling."
  8905. (interactive)
  8906. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8907. (org-agenda-maybe-loop
  8908. #'org-agenda-archive-with cmd nil t
  8909. (let* ((bufname-orig (buffer-name))
  8910. (marker (or (org-get-at-bol 'org-marker)
  8911. (org-agenda-error)))
  8912. (buffer (marker-buffer marker))
  8913. (pos (marker-position marker)))
  8914. (org-with-remote-undo buffer
  8915. (with-current-buffer buffer
  8916. (if (derived-mode-p 'org-mode)
  8917. (if (and confirm
  8918. (not (y-or-n-p "Archive this subtree or entry? ")))
  8919. (error "Abort")
  8920. (save-window-excursion
  8921. (goto-char pos)
  8922. (let ((org-agenda-buffer-name bufname-orig))
  8923. (org-remove-subtree-entries-from-agenda))
  8924. (org-back-to-heading t)
  8925. (let ((org-archive-from-agenda t))
  8926. (funcall cmd))))
  8927. (error "Archiving works only in Org files")))))))
  8928. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8929. "Remove all lines in the agenda that correspond to a given subtree.
  8930. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8931. If this information is not given, the function uses the tree at point."
  8932. (let ((buf (or buf (current-buffer))) m p)
  8933. (save-excursion
  8934. (unless (and beg end)
  8935. (org-back-to-heading t)
  8936. (setq beg (point))
  8937. (org-end-of-subtree t)
  8938. (setq end (point)))
  8939. (set-buffer (get-buffer org-agenda-buffer-name))
  8940. (save-excursion
  8941. (goto-char (point-max))
  8942. (beginning-of-line 1)
  8943. (while (not (bobp))
  8944. (when (and (setq m (org-get-at-bol 'org-marker))
  8945. (equal buf (marker-buffer m))
  8946. (setq p (marker-position m))
  8947. (>= p beg)
  8948. (< p end))
  8949. (let ((inhibit-read-only t))
  8950. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8951. (beginning-of-line 0))))))
  8952. (defun org-agenda-refile (&optional goto rfloc no-update)
  8953. "Refile the item at point.
  8954. When called with `\\[universal-argument] \\[universal-argument]', \
  8955. go to the location of the last
  8956. refiled item.
  8957. When called with `\\[universal-argument] \\[universal-argument] \
  8958. \\[universal-argument]' prefix or when GOTO is 0, clear
  8959. the refile cache.
  8960. RFLOC can be a refile location obtained in a different way.
  8961. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8962. (interactive "P")
  8963. (cond
  8964. ((member goto '(0 (64)))
  8965. (org-refile-cache-clear))
  8966. ((equal goto '(16))
  8967. (org-refile-goto-last-stored))
  8968. (t
  8969. (let* ((buffer-orig (buffer-name))
  8970. (marker (or (org-get-at-bol 'org-hd-marker)
  8971. (org-agenda-error)))
  8972. (buffer (marker-buffer marker))
  8973. ;; (pos (marker-position marker))
  8974. (rfloc (or rfloc
  8975. (org-refile-get-location
  8976. (if goto "Goto" "Refile to") buffer
  8977. org-refile-allow-creating-parent-nodes))))
  8978. (with-current-buffer buffer
  8979. (org-with-wide-buffer
  8980. (goto-char marker)
  8981. (let ((org-agenda-buffer-name buffer-orig))
  8982. (org-remove-subtree-entries-from-agenda))
  8983. (org-refile goto buffer rfloc))))
  8984. (unless no-update (org-agenda-redo)))))
  8985. (defun org-agenda-open-link (&optional arg)
  8986. "Open the link(s) in the current entry, if any.
  8987. This looks for a link in the displayed line in the agenda.
  8988. It also looks at the text of the entry itself."
  8989. (interactive "P")
  8990. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8991. (org-get-at-bol 'org-marker)))
  8992. (buffer (and marker (marker-buffer marker)))
  8993. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8994. (lkall (and buffer (org-offer-links-in-entry
  8995. buffer marker arg prefix)))
  8996. (lk0 (car lkall))
  8997. (lk (if (stringp lk0) (list lk0) lk0))
  8998. (lkend (cdr lkall))
  8999. trg)
  9000. (cond
  9001. ((and buffer lk)
  9002. (mapcar (lambda(l)
  9003. (with-current-buffer buffer
  9004. (setq trg (and (string-match org-link-bracket-re l)
  9005. (match-string 1 l)))
  9006. (if (or (not trg) (string-match org-link-any-re trg))
  9007. ;; Don't use `org-with-wide-buffer' here as
  9008. ;; opening the link may result in moving the point
  9009. (save-restriction
  9010. (widen)
  9011. (goto-char marker)
  9012. (when (search-forward l nil lkend)
  9013. (goto-char (match-beginning 0))
  9014. (org-open-at-point)))
  9015. ;; This is an internal link, widen the buffer
  9016. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9017. (switch-to-buffer-other-window buffer)
  9018. (widen)
  9019. (goto-char marker)
  9020. (when (search-forward l nil lkend)
  9021. (goto-char (match-beginning 0))
  9022. (org-open-at-point)))))
  9023. lk))
  9024. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9025. (save-excursion
  9026. (beginning-of-line 1)
  9027. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9028. (org-link-open-from-string (match-string 1)))
  9029. (t (message "No link to open here")))))
  9030. (defun org-agenda-copy-local-variable (var)
  9031. "Get a variable from a referenced buffer and install it here."
  9032. (let ((m (org-get-at-bol 'org-marker)))
  9033. (when (and m (buffer-live-p (marker-buffer m)))
  9034. (set (make-local-variable var)
  9035. (with-current-buffer (marker-buffer m)
  9036. (symbol-value var))))))
  9037. (defun org-agenda-switch-to (&optional delete-other-windows)
  9038. "Go to the Org mode file which contains the item at point.
  9039. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9040. displayed Org file fills the frame."
  9041. (interactive)
  9042. (if (and org-return-follows-link
  9043. (not (org-get-at-bol 'org-marker))
  9044. (org-in-regexp org-link-bracket-re))
  9045. (org-link-open-from-string (match-string 0))
  9046. (let* ((marker (or (org-get-at-bol 'org-marker)
  9047. (org-agenda-error)))
  9048. (buffer (marker-buffer marker))
  9049. (pos (marker-position marker)))
  9050. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9051. (pop-to-buffer-same-window buffer)
  9052. (when delete-other-windows (delete-other-windows))
  9053. (widen)
  9054. (goto-char pos)
  9055. (when (derived-mode-p 'org-mode)
  9056. (org-fold-show-context 'agenda)
  9057. (run-hooks 'org-agenda-after-show-hook)))))
  9058. (defun org-agenda-goto-mouse (ev)
  9059. "Go to the Org file which contains the item at the mouse click."
  9060. (interactive "e")
  9061. (mouse-set-point ev)
  9062. (org-agenda-goto))
  9063. (defun org-agenda-show (&optional full-entry)
  9064. "Display the Org file which contains the item at point.
  9065. With prefix argument FULL-ENTRY, make the entire entry visible
  9066. if it was hidden in the outline."
  9067. (interactive "P")
  9068. (let ((win (selected-window)))
  9069. (org-agenda-goto t)
  9070. (when full-entry (org-fold-show-entry))
  9071. (select-window win)))
  9072. (defvar org-agenda-show-window nil)
  9073. (defun org-agenda-show-and-scroll-up (&optional arg)
  9074. "Display the Org file which contains the item at point.
  9075. When called repeatedly, scroll the window that is displaying the buffer.
  9076. With a `\\[universal-argument]' prefix argument, display the item, but \
  9077. fold drawers."
  9078. (interactive "P")
  9079. (let ((win (selected-window)))
  9080. (if (and (window-live-p org-agenda-show-window)
  9081. (eq this-command last-command))
  9082. (progn
  9083. (select-window org-agenda-show-window)
  9084. (ignore-errors (scroll-up)))
  9085. (org-agenda-goto t)
  9086. (org-fold-show-entry)
  9087. (if arg (org-cycle-hide-drawers 'children)
  9088. (org-with-wide-buffer
  9089. (narrow-to-region (org-entry-beginning-position)
  9090. (org-entry-end-position))
  9091. (org-fold-show-all '(drawers))))
  9092. (setq org-agenda-show-window (selected-window)))
  9093. (select-window win)))
  9094. (defun org-agenda-show-scroll-down ()
  9095. "Scroll down the window showing the agenda."
  9096. (interactive)
  9097. (let ((win (selected-window)))
  9098. (when (window-live-p org-agenda-show-window)
  9099. (select-window org-agenda-show-window)
  9100. (ignore-errors (scroll-down))
  9101. (select-window win))))
  9102. (defun org-agenda-show-1 (&optional more)
  9103. "Display the Org file which contains the item at point.
  9104. The prefix arg selects the amount of information to display:
  9105. 0 hide the subtree
  9106. 1 just show the entry according to defaults.
  9107. 2 show the children view
  9108. 3 show the subtree view
  9109. 4 show the entire subtree and any drawers
  9110. With prefix argument FULL-ENTRY, make the entire entry visible
  9111. if it was hidden in the outline."
  9112. (interactive "p")
  9113. (let ((win (selected-window)))
  9114. (org-agenda-goto t)
  9115. (org-back-to-heading)
  9116. (set-window-start (selected-window) (point-at-bol))
  9117. (cond
  9118. ((= more 0)
  9119. (org-fold-subtree t)
  9120. (save-excursion
  9121. (org-back-to-heading)
  9122. (run-hook-with-args 'org-cycle-hook 'folded))
  9123. (message "Remote: FOLDED"))
  9124. ((and (called-interactively-p 'any) (= more 1))
  9125. (message "Remote: show with default settings"))
  9126. ((= more 2)
  9127. (org-fold-show-entry)
  9128. (org-fold-show-children)
  9129. (save-excursion
  9130. (org-back-to-heading)
  9131. (run-hook-with-args 'org-cycle-hook 'children))
  9132. (message "Remote: CHILDREN"))
  9133. ((= more 3)
  9134. (org-fold-show-subtree)
  9135. (save-excursion
  9136. (org-back-to-heading)
  9137. (run-hook-with-args 'org-cycle-hook 'subtree))
  9138. (message "Remote: SUBTREE"))
  9139. ((> more 3)
  9140. (org-fold-show-subtree)
  9141. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9142. (select-window win)))
  9143. (defvar org-agenda-cycle-counter nil)
  9144. (defun org-agenda-cycle-show (&optional n)
  9145. "Show the current entry in another window, with default settings.
  9146. Default settings are taken from `org-show-context-detail'. When
  9147. use repeatedly in immediate succession, the remote entry will
  9148. cycle through visibility
  9149. children -> subtree -> folded
  9150. When called with a numeric prefix arg, that arg will be passed through to
  9151. `org-agenda-show-1'. For the interpretation of that argument, see the
  9152. docstring of `org-agenda-show-1'."
  9153. (interactive "P")
  9154. (if (integerp n)
  9155. (setq org-agenda-cycle-counter n)
  9156. (if (not (eq last-command this-command))
  9157. (setq org-agenda-cycle-counter 1)
  9158. (if (equal org-agenda-cycle-counter 0)
  9159. (setq org-agenda-cycle-counter 2)
  9160. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9161. (when (> org-agenda-cycle-counter 3)
  9162. (setq org-agenda-cycle-counter 0)))))
  9163. (org-agenda-show-1 org-agenda-cycle-counter))
  9164. (defun org-agenda-recenter (arg)
  9165. "Display the Org file which contains the item at point and recenter."
  9166. (interactive "P")
  9167. (let ((win (selected-window)))
  9168. (org-agenda-goto t)
  9169. (recenter arg)
  9170. (select-window win)))
  9171. (defun org-agenda-show-mouse (ev)
  9172. "Display the Org file which contains the item at the mouse click."
  9173. (interactive "e")
  9174. (mouse-set-point ev)
  9175. (org-agenda-show))
  9176. (defun org-agenda-check-no-diary ()
  9177. "Check if the entry is a diary link and abort if yes."
  9178. (when (org-get-at-bol 'org-agenda-diary-link)
  9179. (org-agenda-error)))
  9180. (defun org-agenda-error ()
  9181. "Throw an error when a command is not allowed in the agenda."
  9182. (user-error "Command not allowed in this line"))
  9183. (defun org-agenda-tree-to-indirect-buffer (arg)
  9184. "Show the subtree corresponding to the current entry in an indirect buffer.
  9185. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9186. With a numerical prefix ARG, go up to this level and then take that tree.
  9187. With a negative numeric ARG, go up by this number of levels.
  9188. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9189. i.e. don't use
  9190. the dedicated frame."
  9191. (interactive "P")
  9192. (if current-prefix-arg
  9193. (org-agenda-do-tree-to-indirect-buffer arg)
  9194. (let ((agenda-buffer (buffer-name))
  9195. (agenda-window (selected-window))
  9196. (indirect-window
  9197. (and org-last-indirect-buffer
  9198. (get-buffer-window org-last-indirect-buffer))))
  9199. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9200. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9201. (eq org-indirect-buffer-display 'dedicated-frame))
  9202. (unwind-protect
  9203. (unless (and indirect-window (window-live-p indirect-window))
  9204. (setq indirect-window (split-window agenda-window)))
  9205. (and indirect-window (select-window indirect-window))
  9206. (switch-to-buffer org-last-indirect-buffer :norecord)
  9207. (fit-window-to-buffer indirect-window)))
  9208. (select-window (get-buffer-window agenda-buffer))
  9209. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9210. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9211. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9212. (org-agenda-check-no-diary)
  9213. (let* ((marker (or (org-get-at-bol 'org-marker)
  9214. (org-agenda-error)))
  9215. (buffer (marker-buffer marker))
  9216. (pos (marker-position marker)))
  9217. (with-current-buffer buffer
  9218. (save-excursion
  9219. (goto-char pos)
  9220. (org-tree-to-indirect-buffer arg)))))
  9221. (defvar org-last-heading-marker (make-marker)
  9222. "Marker pointing to the headline that last changed its TODO state
  9223. by a remote command from the agenda.")
  9224. (defun org-agenda-todo-nextset ()
  9225. "Switch TODO entry to next sequence."
  9226. (interactive)
  9227. (org-agenda-todo 'nextset))
  9228. (defun org-agenda-todo-previousset ()
  9229. "Switch TODO entry to previous sequence."
  9230. (interactive)
  9231. (org-agenda-todo 'previousset))
  9232. (defvar org-agenda-headline-snapshot-before-repeat)
  9233. (defun org-agenda-todo (&optional arg)
  9234. "Cycle TODO state of line at point, also in Org file.
  9235. This changes the line at point, all other lines in the agenda referring to
  9236. the same tree node, and the headline of the tree node in the Org file."
  9237. (interactive "P")
  9238. (org-agenda-check-no-diary)
  9239. (org-agenda-maybe-loop
  9240. #'org-agenda-todo arg nil nil
  9241. (let* ((col (current-column))
  9242. (marker (or (org-get-at-bol 'org-marker)
  9243. (org-agenda-error)))
  9244. (buffer (marker-buffer marker))
  9245. (pos (marker-position marker))
  9246. (hdmarker (org-get-at-bol 'org-hd-marker))
  9247. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9248. (inhibit-read-only t)
  9249. org-loop-over-headlines-in-active-region
  9250. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9251. (org-with-remote-undo buffer
  9252. (with-current-buffer buffer
  9253. (widen)
  9254. (goto-char pos)
  9255. (org-fold-show-context 'agenda)
  9256. (let ((current-prefix-arg arg))
  9257. (call-interactively 'org-todo)
  9258. ;; Make sure that log is recorded in current undo.
  9259. (when (and org-log-setup
  9260. (not (eq org-log-note-how 'note)))
  9261. (org-add-log-note)))
  9262. (and (bolp) (forward-char 1))
  9263. (setq newhead (org-get-heading))
  9264. (when (and org-agenda-headline-snapshot-before-repeat
  9265. (not (equal org-agenda-headline-snapshot-before-repeat
  9266. newhead))
  9267. todayp)
  9268. (setq newhead org-agenda-headline-snapshot-before-repeat
  9269. just-one t))
  9270. (save-excursion
  9271. (org-back-to-heading)
  9272. (move-marker org-last-heading-marker (point))))
  9273. (beginning-of-line 1)
  9274. (save-window-excursion
  9275. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9276. (when (bound-and-true-p org-clock-out-when-done)
  9277. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9278. newhead)
  9279. (org-agenda-unmark-clocking-task))
  9280. (org-move-to-column col)
  9281. (org-agenda-mark-clocking-task)))))
  9282. (defun org-agenda-add-note (&optional _arg)
  9283. "Add a time-stamped note to the entry at point."
  9284. (interactive) ;; "P"
  9285. (org-agenda-check-no-diary)
  9286. (let* ((marker (or (org-get-at-bol 'org-marker)
  9287. (org-agenda-error)))
  9288. (buffer (marker-buffer marker))
  9289. (pos (marker-position marker))
  9290. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9291. (inhibit-read-only t))
  9292. (with-current-buffer buffer
  9293. (widen)
  9294. (goto-char pos)
  9295. (org-fold-show-context 'agenda)
  9296. (org-add-note))))
  9297. (defun org-agenda-change-all-lines (newhead hdmarker
  9298. &optional fixface just-this)
  9299. "Change all lines in the agenda buffer which match HDMARKER.
  9300. The new content of the line will be NEWHEAD (as modified by
  9301. `org-agenda-format-item'). HDMARKER is checked with
  9302. `equal' against all `org-hd-marker' text properties in the file.
  9303. If FIXFACE is non-nil, the face of each item is modified according to
  9304. the new TODO state.
  9305. If JUST-THIS is non-nil, change just the current line, not all.
  9306. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9307. (let* ((inhibit-read-only t)
  9308. (line (org-current-line))
  9309. (org-agenda-buffer (current-buffer))
  9310. (thetags (with-current-buffer (marker-buffer hdmarker)
  9311. (org-get-tags hdmarker)))
  9312. props m undone-face done-face finish new dotime level cat tags
  9313. effort effort-minutes) ;; pl
  9314. (save-excursion
  9315. (goto-char (point-max))
  9316. (beginning-of-line 1)
  9317. (while (not finish)
  9318. (setq finish (bobp))
  9319. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9320. (or (not just-this) (= (org-current-line) line))
  9321. (equal m hdmarker))
  9322. (setq props (text-properties-at (point))
  9323. dotime (org-get-at-bol 'dotime)
  9324. cat (org-agenda-get-category)
  9325. level (org-get-at-bol 'level)
  9326. tags thetags
  9327. effort (org-get-at-bol 'effort)
  9328. effort-minutes (org-get-at-bol 'effort-minutes)
  9329. new
  9330. (let ((org-prefix-format-compiled
  9331. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9332. org-prefix-format-compiled))
  9333. (extra (org-get-at-bol 'extra)))
  9334. (with-current-buffer (marker-buffer hdmarker)
  9335. (org-with-wide-buffer
  9336. (org-agenda-format-item extra
  9337. (org-add-props newhead nil
  9338. 'effort effort
  9339. 'effort-minutes effort-minutes)
  9340. level cat tags dotime))))
  9341. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9342. undone-face (org-get-at-bol 'undone-face)
  9343. done-face (org-get-at-bol 'done-face))
  9344. (beginning-of-line 1)
  9345. (cond
  9346. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9347. ((looking-at ".*")
  9348. ;; When replacing the whole line, preserve bulk mark
  9349. ;; overlay, if any.
  9350. (let ((mark (catch :overlay
  9351. (dolist (o (overlays-in (point) (+ 2 (point))))
  9352. (when (eq (overlay-get o 'type)
  9353. 'org-marked-entry-overlay)
  9354. (throw :overlay o))))))
  9355. (replace-match new t t)
  9356. (beginning-of-line)
  9357. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9358. (add-text-properties (point-at-bol) (point-at-eol) props)
  9359. (when fixface
  9360. (add-text-properties
  9361. (point-at-bol) (point-at-eol)
  9362. (list 'face
  9363. (if org-last-todo-state-is-todo
  9364. undone-face done-face))))
  9365. (org-agenda-highlight-todo 'line)
  9366. (beginning-of-line 1))
  9367. (t (error "Line update did not work")))
  9368. (save-restriction
  9369. (narrow-to-region (point-at-bol) (point-at-eol))
  9370. (org-agenda-finalize)))
  9371. (beginning-of-line 0)))))
  9372. (defun org-agenda-align-tags (&optional line)
  9373. "Align all tags in agenda items to `org-agenda-tags-column'.
  9374. When optional argument LINE is non-nil, align tags only on the
  9375. current line."
  9376. (let ((inhibit-read-only t)
  9377. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9378. (- (window-max-chars-per-line))
  9379. org-agenda-tags-column))
  9380. (end (and line (line-end-position)))
  9381. l c)
  9382. (save-excursion
  9383. (goto-char (if line (line-beginning-position) (point-min)))
  9384. (while (re-search-forward org-tag-group-re end t)
  9385. (add-text-properties
  9386. (match-beginning 1) (match-end 1)
  9387. (list 'face (delq nil (let ((prop (get-text-property
  9388. (match-beginning 1) 'face)))
  9389. (or (listp prop) (setq prop (list prop)))
  9390. (if (memq 'org-tag prop)
  9391. prop
  9392. (cons 'org-tag prop))))))
  9393. (setq l (string-width (match-string 1))
  9394. c (if (< org-agenda-tags-column 0)
  9395. (- (abs org-agenda-tags-column) l)
  9396. org-agenda-tags-column))
  9397. (goto-char (match-beginning 1))
  9398. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9399. (point))
  9400. (insert (org-add-props
  9401. (make-string (max 1 (- c (current-column))) ?\s)
  9402. (plist-put (copy-sequence (text-properties-at (point)))
  9403. 'face nil))))
  9404. (goto-char (point-min))
  9405. (org-font-lock-add-tag-faces (point-max)))))
  9406. (defun org-agenda-priority-up ()
  9407. "Increase the priority of line at point, also in Org file."
  9408. (interactive)
  9409. (org-agenda-priority 'up))
  9410. (defun org-agenda-priority-down ()
  9411. "Decrease the priority of line at point, also in Org file."
  9412. (interactive)
  9413. (org-agenda-priority 'down))
  9414. (defun org-agenda-priority (&optional force-direction)
  9415. "Set the priority of line at point, also in Org file.
  9416. This changes the line at point, all other lines in the agenda
  9417. referring to the same tree node, and the headline of the tree
  9418. node in the Org file.
  9419. Called with one universal prefix arg, show the priority instead
  9420. of setting it.
  9421. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9422. `down', or a character."
  9423. (interactive "P")
  9424. (unless org-priority-enable-commands
  9425. (user-error "Priority commands are disabled"))
  9426. (org-agenda-check-no-diary)
  9427. (let* ((col (current-column))
  9428. (hdmarker (org-get-at-bol 'org-hd-marker))
  9429. (buffer (marker-buffer hdmarker))
  9430. (pos (marker-position hdmarker))
  9431. (inhibit-read-only t)
  9432. newhead)
  9433. (org-with-remote-undo buffer
  9434. (with-current-buffer buffer
  9435. (widen)
  9436. (goto-char pos)
  9437. (org-fold-show-context 'agenda)
  9438. (org-priority force-direction)
  9439. (end-of-line 1)
  9440. (setq newhead (org-get-heading)))
  9441. (org-agenda-change-all-lines newhead hdmarker)
  9442. (org-move-to-column col))))
  9443. ;; FIXME: should fix the tags property of the agenda line.
  9444. (defun org-agenda-set-tags (&optional tag onoff)
  9445. "Set tags for the current headline."
  9446. (interactive)
  9447. (org-agenda-check-no-diary)
  9448. (if (and (org-region-active-p) (called-interactively-p 'any))
  9449. (call-interactively 'org-change-tag-in-region)
  9450. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9451. (org-agenda-error)))
  9452. (buffer (marker-buffer hdmarker))
  9453. (pos (marker-position hdmarker))
  9454. (inhibit-read-only t)
  9455. newhead)
  9456. (org-with-remote-undo buffer
  9457. (with-current-buffer buffer
  9458. (widen)
  9459. (goto-char pos)
  9460. (org-fold-show-context 'agenda)
  9461. (if tag
  9462. (org-toggle-tag tag onoff)
  9463. (call-interactively #'org-set-tags-command))
  9464. (end-of-line 1)
  9465. (setq newhead (org-get-heading)))
  9466. (org-agenda-change-all-lines newhead hdmarker)
  9467. (beginning-of-line 1)))))
  9468. (defun org-agenda-set-property ()
  9469. "Set a property for the current headline."
  9470. (interactive)
  9471. (org-agenda-check-no-diary)
  9472. (org-agenda-maybe-loop
  9473. #'org-agenda-set-property nil nil nil
  9474. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9475. (org-agenda-error)))
  9476. (buffer (marker-buffer hdmarker))
  9477. (pos (marker-position hdmarker))
  9478. (inhibit-read-only t)
  9479. ) ;; newhead
  9480. (org-with-remote-undo buffer
  9481. (with-current-buffer buffer
  9482. (widen)
  9483. (goto-char pos)
  9484. (org-fold-show-context 'agenda)
  9485. (call-interactively 'org-set-property))))))
  9486. (defun org-agenda-set-effort ()
  9487. "Set the effort property for the current headline."
  9488. (interactive)
  9489. (org-agenda-check-no-diary)
  9490. (org-agenda-maybe-loop
  9491. #'org-agenda-set-effort nil nil nil
  9492. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9493. (org-agenda-error)))
  9494. (buffer (marker-buffer hdmarker))
  9495. (pos (marker-position hdmarker))
  9496. (inhibit-read-only t)
  9497. newhead)
  9498. (org-with-remote-undo buffer
  9499. (with-current-buffer buffer
  9500. (widen)
  9501. (goto-char pos)
  9502. (org-fold-show-context 'agenda)
  9503. (call-interactively 'org-set-effort)
  9504. (end-of-line 1)
  9505. (setq newhead (org-get-heading)))
  9506. (org-agenda-change-all-lines newhead hdmarker)))))
  9507. (defun org-agenda-toggle-archive-tag ()
  9508. "Toggle the archive tag for the current entry."
  9509. (interactive)
  9510. (org-agenda-check-no-diary)
  9511. (org-agenda-maybe-loop
  9512. #'org-agenda-toggle-archive-tag nil nil nil
  9513. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9514. (org-agenda-error)))
  9515. (buffer (marker-buffer hdmarker))
  9516. (pos (marker-position hdmarker))
  9517. (inhibit-read-only t)
  9518. newhead)
  9519. (org-with-remote-undo buffer
  9520. (with-current-buffer buffer
  9521. (widen)
  9522. (goto-char pos)
  9523. (org-fold-show-context 'agenda)
  9524. (call-interactively 'org-toggle-archive-tag)
  9525. (end-of-line 1)
  9526. (setq newhead (org-get-heading)))
  9527. (org-agenda-change-all-lines newhead hdmarker)
  9528. (beginning-of-line 1)))))
  9529. (defun org-agenda-do-date-later (arg)
  9530. (interactive "P")
  9531. (cond
  9532. ((or (equal arg '(16))
  9533. (memq last-command
  9534. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9535. (setq this-command 'org-agenda-date-later-minutes)
  9536. (org-agenda-date-later-minutes 1))
  9537. ((or (equal arg '(4))
  9538. (memq last-command
  9539. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9540. (setq this-command 'org-agenda-date-later-hours)
  9541. (org-agenda-date-later-hours 1))
  9542. (t
  9543. (org-agenda-date-later (prefix-numeric-value arg)))))
  9544. (defun org-agenda-do-date-earlier (arg)
  9545. (interactive "P")
  9546. (cond
  9547. ((or (equal arg '(16))
  9548. (memq last-command
  9549. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9550. (setq this-command 'org-agenda-date-earlier-minutes)
  9551. (org-agenda-date-earlier-minutes 1))
  9552. ((or (equal arg '(4))
  9553. (memq last-command
  9554. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9555. (setq this-command 'org-agenda-date-earlier-hours)
  9556. (org-agenda-date-earlier-hours 1))
  9557. (t
  9558. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9559. (defun org-agenda-date-later (arg &optional what)
  9560. "Change the date of this item to ARG day(s) later."
  9561. (interactive "p")
  9562. (org-agenda-check-type t 'agenda)
  9563. (org-agenda-check-no-diary)
  9564. (let* ((marker (or (org-get-at-bol 'org-marker)
  9565. (org-agenda-error)))
  9566. (buffer (marker-buffer marker))
  9567. (pos (marker-position marker))
  9568. cdate today)
  9569. (org-with-remote-undo buffer
  9570. (with-current-buffer buffer
  9571. (widen)
  9572. (goto-char pos)
  9573. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9574. (when (and org-agenda-move-date-from-past-immediately-to-today
  9575. (equal arg 1)
  9576. (or (not what) (eq what 'day))
  9577. (not (save-match-data (org-at-date-range-p))))
  9578. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9579. cdate (calendar-absolute-from-gregorian
  9580. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9581. today (org-today))
  9582. (when (> today cdate)
  9583. ;; immediately shift to today
  9584. (setq arg (- today cdate))))
  9585. (org-timestamp-change arg (or what 'day))
  9586. (when (and (org-at-date-range-p)
  9587. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9588. (let ((end org-last-changed-timestamp))
  9589. (org-timestamp-change arg (or what 'day))
  9590. (setq org-last-changed-timestamp
  9591. (concat org-last-changed-timestamp "--" end)))))
  9592. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9593. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9594. (defun org-agenda-date-earlier (arg &optional what)
  9595. "Change the date of this item to ARG day(s) earlier."
  9596. (interactive "p")
  9597. (org-agenda-date-later (- arg) what))
  9598. (defun org-agenda-date-later-minutes (arg)
  9599. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9600. (interactive "p")
  9601. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9602. (org-agenda-date-later arg 'minute))
  9603. (defun org-agenda-date-earlier-minutes (arg)
  9604. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9605. (interactive "p")
  9606. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9607. (org-agenda-date-earlier arg 'minute))
  9608. (defun org-agenda-date-later-hours (arg)
  9609. "Change the time of this item, in hour steps."
  9610. (interactive "p")
  9611. (org-agenda-date-later arg 'hour))
  9612. (defun org-agenda-date-earlier-hours (arg)
  9613. "Change the time of this item, in hour steps."
  9614. (interactive "p")
  9615. (org-agenda-date-earlier arg 'hour))
  9616. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9617. "Show new date stamp via text properties."
  9618. ;; We use text properties to make this undoable
  9619. (let ((inhibit-read-only t))
  9620. (setq stamp (concat prefix " => " stamp " "))
  9621. (save-excursion
  9622. (goto-char (point-max))
  9623. (while (not (bobp))
  9624. (when (equal marker (org-get-at-bol 'org-marker))
  9625. (remove-text-properties (line-beginning-position)
  9626. (line-end-position)
  9627. '(display nil))
  9628. (org-move-to-column
  9629. (- (window-max-chars-per-line)
  9630. (length stamp))
  9631. t)
  9632. (add-text-properties
  9633. (1- (point)) (point-at-eol)
  9634. (list 'display (org-add-props stamp nil
  9635. 'face '(secondary-selection default))))
  9636. (beginning-of-line 1))
  9637. (beginning-of-line 0)))))
  9638. (defun org-agenda-date-prompt (arg)
  9639. "Change the date of this item. Date is prompted for, with default today.
  9640. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9641. be used to request time specification in the time stamp."
  9642. (interactive "P")
  9643. (org-agenda-check-type t 'agenda)
  9644. (org-agenda-check-no-diary)
  9645. (org-agenda-maybe-loop
  9646. #'org-agenda-date-prompt arg t nil
  9647. (let* ((marker (or (org-get-at-bol 'org-marker)
  9648. (org-agenda-error)))
  9649. (buffer (marker-buffer marker))
  9650. (pos (marker-position marker)))
  9651. (org-with-remote-undo buffer
  9652. (with-current-buffer buffer
  9653. (widen)
  9654. (goto-char pos)
  9655. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9656. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9657. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9658. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9659. (defun org-agenda-schedule (arg &optional time)
  9660. "Schedule the item at point.
  9661. ARG is passed through to `org-schedule'."
  9662. (interactive "P")
  9663. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9664. (org-agenda-check-no-diary)
  9665. (org-agenda-maybe-loop
  9666. #'org-agenda-schedule arg t nil
  9667. (let* ((marker (or (org-get-at-bol 'org-marker)
  9668. (org-agenda-error)))
  9669. ;; (type (marker-insertion-type marker))
  9670. (buffer (marker-buffer marker))
  9671. (pos (marker-position marker))
  9672. ts)
  9673. (set-marker-insertion-type marker t)
  9674. (org-with-remote-undo buffer
  9675. (with-current-buffer buffer
  9676. (widen)
  9677. (goto-char pos)
  9678. (setq ts (org-schedule arg time)))
  9679. (org-agenda-show-new-time marker ts " S"))
  9680. (message "%s" ts))))
  9681. (defun org-agenda-deadline (arg &optional time)
  9682. "Schedule the item at point.
  9683. ARG is passed through to `org-deadline'."
  9684. (interactive "P")
  9685. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9686. (org-agenda-check-no-diary)
  9687. (org-agenda-maybe-loop
  9688. #'org-agenda-deadline arg t nil
  9689. (let* ((marker (or (org-get-at-bol 'org-marker)
  9690. (org-agenda-error)))
  9691. (buffer (marker-buffer marker))
  9692. (pos (marker-position marker))
  9693. ts)
  9694. (org-with-remote-undo buffer
  9695. (with-current-buffer buffer
  9696. (widen)
  9697. (goto-char pos)
  9698. (setq ts (org-deadline arg time)))
  9699. (org-agenda-show-new-time marker ts " D"))
  9700. (message "%s" ts))))
  9701. (defun org-agenda-clock-in (&optional arg)
  9702. "Start the clock on the currently selected item."
  9703. (interactive "P")
  9704. (org-agenda-check-no-diary)
  9705. (if (equal arg '(4))
  9706. (org-clock-in arg)
  9707. (let* ((marker (or (org-get-at-bol 'org-marker)
  9708. (org-agenda-error)))
  9709. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9710. (pos (marker-position marker))
  9711. (col (current-column))
  9712. newhead)
  9713. (org-with-remote-undo (marker-buffer marker)
  9714. (with-current-buffer (marker-buffer marker)
  9715. (widen)
  9716. (goto-char pos)
  9717. (org-fold-show-context 'agenda)
  9718. (org-clock-in arg)
  9719. (setq newhead (org-get-heading)))
  9720. (org-agenda-change-all-lines newhead hdmarker))
  9721. (org-move-to-column col))))
  9722. (defun org-agenda-clock-out ()
  9723. "Stop the currently running clock."
  9724. (interactive)
  9725. (unless (marker-buffer org-clock-marker)
  9726. (user-error "No running clock"))
  9727. (let ((marker (make-marker)) (col (current-column)) newhead)
  9728. (org-with-remote-undo (marker-buffer org-clock-marker)
  9729. (with-current-buffer (marker-buffer org-clock-marker)
  9730. (org-with-wide-buffer
  9731. (goto-char org-clock-marker)
  9732. (org-back-to-heading t)
  9733. (move-marker marker (point))
  9734. (org-clock-out)
  9735. (setq newhead (org-get-heading)))))
  9736. (org-agenda-change-all-lines newhead marker)
  9737. (move-marker marker nil)
  9738. (org-move-to-column col)
  9739. (org-agenda-unmark-clocking-task)))
  9740. (defun org-agenda-clock-cancel (&optional _arg)
  9741. "Cancel the currently running clock."
  9742. (interactive) ;; "P"
  9743. (unless (marker-buffer org-clock-marker)
  9744. (user-error "No running clock"))
  9745. (org-with-remote-undo (marker-buffer org-clock-marker)
  9746. (org-clock-cancel)))
  9747. (defun org-agenda-clock-goto ()
  9748. "Jump to the currently clocked in task within the agenda.
  9749. If the currently clocked in task is not listed in the agenda
  9750. buffer, display it in another window."
  9751. (interactive)
  9752. (let (pos)
  9753. (mapc (lambda (o)
  9754. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9755. (setq pos (overlay-start o))))
  9756. (overlays-in (point-min) (point-max)))
  9757. (cond (pos (goto-char pos))
  9758. ;; If the currently clocked entry is not in the agenda
  9759. ;; buffer, we visit it in another window:
  9760. ((bound-and-true-p org-clock-current-task)
  9761. (org-switch-to-buffer-other-window (org-clock-goto)))
  9762. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9763. (defun org-agenda-diary-entry-in-org-file ()
  9764. "Make a diary entry in the file `org-agenda-diary-file'."
  9765. (let (d1 d2 char (text "") dp1 dp2)
  9766. (if (equal (buffer-name) "*Calendar*")
  9767. (setq d1 (calendar-cursor-to-date t)
  9768. d2 (car calendar-mark-ring))
  9769. (setq dp1 (get-text-property (point-at-bol) 'day))
  9770. (unless dp1 (user-error "No date defined in current line"))
  9771. (setq d1 (calendar-gregorian-from-absolute dp1)
  9772. d2 (and (ignore-errors (mark))
  9773. (save-excursion
  9774. (goto-char (mark))
  9775. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9776. (calendar-gregorian-from-absolute dp2))))
  9777. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9778. (setq char (read-char-exclusive))
  9779. (cond
  9780. ((equal char ?d)
  9781. (setq text (read-string "Day entry: "))
  9782. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9783. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9784. ((equal char ?a)
  9785. (setq d1 (list (car d1) (nth 1 d1)
  9786. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9787. (nth 2 d1))))
  9788. (setq text (read-string "Anniversary (use %d to show years): "))
  9789. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9790. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9791. ((equal char ?b)
  9792. (setq text (read-string "Block entry: "))
  9793. (unless (and d1 d2 (not (equal d1 d2)))
  9794. (user-error "No block of days selected"))
  9795. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9796. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9797. ((equal char ?j)
  9798. (org-switch-to-buffer-other-window
  9799. (find-file-noselect org-agenda-diary-file))
  9800. (require 'org-datetree)
  9801. (org-datetree-find-date-create d1)
  9802. (org-fold-reveal t))
  9803. (t (user-error "Invalid selection character `%c'" char)))))
  9804. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9805. "Where in `org-agenda-diary-file' should new entries be added?
  9806. Valid values:
  9807. date-tree in the date tree, as first child of the date
  9808. date-tree-last in the date tree, as last child of the date
  9809. top-level as top-level entries at the end of the file."
  9810. :group 'org-agenda
  9811. :type '(choice
  9812. (const :tag "first in a date tree" date-tree)
  9813. (const :tag "last in a date tree" date-tree-last)
  9814. (const :tag "as top level at end of file" top-level)))
  9815. (defcustom org-agenda-insert-diary-extract-time nil
  9816. "Non-nil means extract any time specification from the diary entry."
  9817. :group 'org-agenda
  9818. :version "24.1"
  9819. :type 'boolean)
  9820. (defcustom org-agenda-bulk-mark-char ">"
  9821. "A single-character string to be used as the bulk mark."
  9822. :group 'org-agenda
  9823. :version "24.1"
  9824. :type 'string)
  9825. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9826. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9827. If TEXT is not empty, it will become the headline of the new entry, and
  9828. the resulting entry will not be shown. When TEXT is empty, switch to
  9829. `org-agenda-diary-file' and let the user finish the entry there."
  9830. (let ((cw (current-window-configuration)))
  9831. (org-switch-to-buffer-other-window
  9832. (find-file-noselect org-agenda-diary-file))
  9833. (widen)
  9834. (goto-char (point-min))
  9835. (cl-case type
  9836. (anniversary
  9837. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9838. (progn
  9839. (or (org-at-heading-p)
  9840. (progn
  9841. (outline-next-heading)
  9842. (insert "* Anniversaries\n\n")
  9843. (beginning-of-line -1)))))
  9844. (outline-next-heading)
  9845. (org-back-over-empty-lines)
  9846. (backward-char 1)
  9847. (insert "\n")
  9848. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9849. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9850. (day
  9851. (let ((org-prefix-has-time t)
  9852. (org-agenda-time-leading-zero t)
  9853. fmt time time2)
  9854. (when org-agenda-insert-diary-extract-time
  9855. ;; Use org-agenda-format-item to parse text for a time-range and
  9856. ;; remove it. FIXME: This is a hack, we should refactor
  9857. ;; that function to make time extraction available separately
  9858. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9859. time (get-text-property 0 'time fmt)
  9860. time2 (if (> (length time) 0)
  9861. ;; split-string removes trailing ...... if
  9862. ;; no end time given. First space
  9863. ;; separates time from date.
  9864. (concat " " (car (split-string time "\\.")))
  9865. nil)
  9866. text (get-text-property 0 'txt fmt)))
  9867. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9868. (org-agenda-insert-diary-as-top-level text)
  9869. (require 'org-datetree)
  9870. (org-datetree-find-date-create d1)
  9871. (org-agenda-insert-diary-make-new-entry text))
  9872. (org-insert-time-stamp (org-time-from-absolute
  9873. (calendar-absolute-from-gregorian d1))
  9874. nil nil nil nil time2))
  9875. (end-of-line 0))
  9876. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9877. ;; otherwise the indentation gets confused by the
  9878. ;; special meaning of 'block
  9879. (when (> (calendar-absolute-from-gregorian d1)
  9880. (calendar-absolute-from-gregorian d2))
  9881. (setq d1 (prog1 d2 (setq d2 d1))))
  9882. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9883. (org-agenda-insert-diary-as-top-level text)
  9884. (require 'org-datetree)
  9885. (org-datetree-find-date-create d1)
  9886. (org-agenda-insert-diary-make-new-entry text))
  9887. (org-insert-time-stamp (org-time-from-absolute
  9888. (calendar-absolute-from-gregorian d1)))
  9889. (insert "--")
  9890. (org-insert-time-stamp (org-time-from-absolute
  9891. (calendar-absolute-from-gregorian d2)))
  9892. (end-of-line 0)))
  9893. (if (string-match "\\S-" text)
  9894. (progn
  9895. (set-window-configuration cw)
  9896. (message "%s entry added to %s"
  9897. (capitalize (symbol-name type))
  9898. (abbreviate-file-name org-agenda-diary-file)))
  9899. (org-fold-reveal t)
  9900. (message "Please finish entry here"))))
  9901. (defun org-agenda-insert-diary-as-top-level (text)
  9902. "Make new entry as a top-level entry at the end of the file.
  9903. Add TEXT as headline, and position the cursor in the second line so that
  9904. a timestamp can be added there."
  9905. (widen)
  9906. (goto-char (point-max))
  9907. (unless (bolp) (insert "\n"))
  9908. (org-insert-heading nil t t)
  9909. (insert text)
  9910. (org-end-of-meta-data)
  9911. (unless (bolp) (insert "\n"))
  9912. (when org-adapt-indentation (indent-to-column 2)))
  9913. (defun org-agenda-insert-diary-make-new-entry (text)
  9914. "Make a new entry with TEXT as a child of the current subtree.
  9915. Position the point in the heading's first body line so that
  9916. a timestamp can be added there."
  9917. (cond
  9918. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9919. (end-of-line)
  9920. (org-insert-heading '(4) t)
  9921. (org-do-demote))
  9922. (t
  9923. (outline-next-heading)
  9924. (org-back-over-empty-lines)
  9925. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9926. (org-insert-heading nil t)
  9927. (org-do-demote)))
  9928. (let ((col (current-column)))
  9929. (insert text)
  9930. (org-end-of-meta-data)
  9931. ;; Ensure point is left on a blank line, at proper indentation.
  9932. (unless (bolp) (insert "\n"))
  9933. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9934. (when org-adapt-indentation (indent-to-column col)))
  9935. (org-fold-show-set-visibility 'lineage))
  9936. (defun org-agenda-diary-entry ()
  9937. "Make a diary entry, like the `i' command from the calendar.
  9938. All the standard commands work: block, weekly etc.
  9939. When `org-agenda-diary-file' points to a file,
  9940. `org-agenda-diary-entry-in-org-file' is called instead to create
  9941. entries in that Org file."
  9942. (interactive)
  9943. (if (not (eq org-agenda-diary-file 'diary-file))
  9944. (org-agenda-diary-entry-in-org-file)
  9945. (require 'diary-lib)
  9946. (let* ((char (read-char-exclusive
  9947. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9948. [a]nniversary [b]lock [c]yclic"))
  9949. (cmd (cdr (assoc char
  9950. '((?d . diary-insert-entry)
  9951. (?w . diary-insert-weekly-entry)
  9952. (?m . diary-insert-monthly-entry)
  9953. (?y . diary-insert-yearly-entry)
  9954. (?a . diary-insert-anniversary-entry)
  9955. (?b . diary-insert-block-entry)
  9956. (?c . diary-insert-cyclic-entry)))))
  9957. (oldf (symbol-function 'calendar-cursor-to-date))
  9958. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9959. (point (point))
  9960. (mark (or (mark t) (point))))
  9961. (unless cmd
  9962. (user-error "No command associated with <%c>" char))
  9963. (unless (and (get-text-property point 'day)
  9964. (or (not (equal ?b char))
  9965. (get-text-property mark 'day)))
  9966. (user-error "Don't know which date to use for diary entry"))
  9967. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9968. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9969. (let ((calendar-mark-ring
  9970. (list (calendar-gregorian-from-absolute
  9971. (or (get-text-property mark 'day)
  9972. (get-text-property point 'day))))))
  9973. (unwind-protect
  9974. (progn
  9975. (fset 'calendar-cursor-to-date
  9976. (lambda (&optional _error _dummy)
  9977. (calendar-gregorian-from-absolute
  9978. (get-text-property point 'day))))
  9979. (call-interactively cmd))
  9980. (fset 'calendar-cursor-to-date oldf))))))
  9981. (defun org-agenda-execute-calendar-command (cmd)
  9982. "Execute a calendar command from the agenda with date from cursor."
  9983. (org-agenda-check-type t 'agenda)
  9984. (require 'diary-lib)
  9985. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9986. (user-error "Don't know which date to use for the calendar command"))
  9987. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9988. (point (point))
  9989. (date (calendar-gregorian-from-absolute
  9990. (get-text-property point 'day))))
  9991. ;; the following 2 vars are needed in the calendar
  9992. (org-dlet
  9993. ((displayed-month (car date))
  9994. (displayed-year (nth 2 date)))
  9995. (unwind-protect
  9996. (progn
  9997. (fset 'calendar-cursor-to-date
  9998. (lambda (&optional _error _dummy)
  9999. (calendar-gregorian-from-absolute
  10000. (get-text-property point 'day))))
  10001. (call-interactively cmd))
  10002. (fset 'calendar-cursor-to-date oldf)))))
  10003. (defun org-agenda-phases-of-moon ()
  10004. "Display the phases of the moon for the 3 months around the cursor date."
  10005. (interactive)
  10006. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10007. (defun org-agenda-holidays ()
  10008. "Display the holidays for the 3 months around the cursor date."
  10009. (interactive)
  10010. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10011. (defvar calendar-longitude) ; defined in calendar.el
  10012. (defvar calendar-latitude) ; defined in calendar.el
  10013. (defvar calendar-location-name) ; defined in calendar.el
  10014. (defun org-agenda-sunrise-sunset (arg)
  10015. "Display sunrise and sunset for the cursor date.
  10016. Latitude and longitude can be specified with the variables
  10017. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10018. argument, latitude and longitude will be prompted for."
  10019. (interactive "P")
  10020. (require 'solar)
  10021. (let ((calendar-longitude (if arg nil calendar-longitude))
  10022. (calendar-latitude (if arg nil calendar-latitude))
  10023. (calendar-location-name
  10024. (if arg "the given coordinates" calendar-location-name)))
  10025. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10026. (defun org-agenda-goto-calendar ()
  10027. "Open the Emacs calendar with the date at the cursor."
  10028. (interactive)
  10029. (org-agenda-check-type t 'agenda)
  10030. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10031. (user-error "Don't know which date to open in calendar")))
  10032. (date (calendar-gregorian-from-absolute day))
  10033. (calendar-move-hook nil)
  10034. (calendar-view-holidays-initially-flag nil)
  10035. (calendar-view-diary-initially-flag nil))
  10036. (calendar)
  10037. (calendar-goto-date date)))
  10038. ;;;###autoload
  10039. (defun org-calendar-goto-agenda ()
  10040. "Compute the Org agenda for the calendar date displayed at the cursor.
  10041. This is a command that has to be installed in `calendar-mode-map'."
  10042. (interactive)
  10043. ;; Temporarily disable sticky agenda since user clearly wants to
  10044. ;; refresh view anyway.
  10045. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10046. (org-agenda-sticky nil))
  10047. (org-agenda-list nil (calendar-absolute-from-gregorian
  10048. (calendar-cursor-to-date))
  10049. nil)))
  10050. (defun org-agenda-convert-date ()
  10051. (interactive)
  10052. (org-agenda-check-type t 'agenda)
  10053. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10054. date s)
  10055. (unless day
  10056. (user-error "Don't know which date to convert"))
  10057. (setq date (calendar-gregorian-from-absolute day))
  10058. (setq s (concat
  10059. "Gregorian: " (calendar-date-string date) "\n"
  10060. "ISO: " (calendar-iso-date-string date) "\n"
  10061. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10062. "Julian: " (calendar-julian-date-string date) "\n"
  10063. "Astron. JD: " (calendar-astro-date-string date)
  10064. " (Julian date number at noon UTC)\n"
  10065. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10066. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10067. "French: " (calendar-french-date-string date) "\n"
  10068. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10069. "Mayan: " (calendar-mayan-date-string date) "\n"
  10070. "Coptic: " (calendar-coptic-date-string date) "\n"
  10071. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10072. "Persian: " (calendar-persian-date-string date) "\n"
  10073. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10074. (with-output-to-temp-buffer "*Dates*"
  10075. (princ s))
  10076. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10077. ;;; Bulk commands
  10078. (defun org-agenda-bulk-marked-p ()
  10079. "Non-nil when current entry is marked for bulk action."
  10080. (eq (get-char-property (point-at-bol) 'type)
  10081. 'org-marked-entry-overlay))
  10082. (defun org-agenda-bulk-mark (&optional arg)
  10083. "Mark entries for future bulk action.
  10084. When ARG is nil or one and region is not active then mark the
  10085. entry at point.
  10086. When ARG is nil or one and region is active then mark the entries
  10087. in the region.
  10088. When ARG is greater than one mark ARG lines."
  10089. (interactive "p")
  10090. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10091. (setq arg (count-lines (region-beginning) (region-end)))
  10092. (goto-char (region-beginning))
  10093. (deactivate-mark))
  10094. (dotimes (_ (or arg 1))
  10095. (unless (org-get-at-bol 'org-agenda-diary-link)
  10096. (let* ((m (org-get-at-bol 'org-hd-marker))
  10097. ov)
  10098. (unless (org-agenda-bulk-marked-p)
  10099. (unless m (user-error "Nothing to mark at point"))
  10100. (push m org-agenda-bulk-marked-entries)
  10101. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10102. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10103. (org-get-todo-face "TODO")
  10104. 'evaporate)
  10105. (overlay-put ov 'type 'org-marked-entry-overlay))
  10106. (end-of-line 1)
  10107. (or (ignore-errors
  10108. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10109. (beginning-of-line 2))
  10110. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10111. (beginning-of-line 2)))))
  10112. (message "%d entries marked for bulk action"
  10113. (length org-agenda-bulk-marked-entries)))
  10114. (defun org-agenda-bulk-mark-all ()
  10115. "Mark all entries for future agenda bulk action."
  10116. (interactive)
  10117. (org-agenda-bulk-mark-regexp "."))
  10118. (defun org-agenda-bulk-mark-regexp (regexp)
  10119. "Mark entries matching REGEXP for future agenda bulk action."
  10120. (interactive "sMark entries matching regexp: ")
  10121. (let ((entries-marked 0) txt-at-point)
  10122. (save-excursion
  10123. (goto-char (point-min))
  10124. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10125. (while (and (re-search-forward regexp nil t)
  10126. (setq txt-at-point
  10127. (get-text-property (match-beginning 0) 'txt)))
  10128. (if (get-char-property (point) 'invisible)
  10129. (beginning-of-line 2)
  10130. (when (string-match-p regexp txt-at-point)
  10131. (setq entries-marked (1+ entries-marked))
  10132. (call-interactively 'org-agenda-bulk-mark)))))
  10133. (unless entries-marked
  10134. (message "No entry matching this regexp."))))
  10135. (defun org-agenda-bulk-unmark (&optional arg)
  10136. "Unmark the entry at point for future bulk action."
  10137. (interactive "P")
  10138. (if arg
  10139. (org-agenda-bulk-unmark-all)
  10140. (cond ((org-agenda-bulk-marked-p)
  10141. (org-agenda-bulk-remove-overlays
  10142. (point-at-bol) (+ 2 (point-at-bol)))
  10143. (setq org-agenda-bulk-marked-entries
  10144. (delete (org-get-at-bol 'org-hd-marker)
  10145. org-agenda-bulk-marked-entries))
  10146. (end-of-line 1)
  10147. (or (ignore-errors
  10148. (goto-char (next-single-property-change (point) 'txt)))
  10149. (beginning-of-line 2))
  10150. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10151. (beginning-of-line 2))
  10152. (message "%d entries left marked for bulk action"
  10153. (length org-agenda-bulk-marked-entries)))
  10154. (t (message "No entry to unmark here")))))
  10155. (defun org-agenda-bulk-toggle-all ()
  10156. "Toggle all marks for bulk action."
  10157. (interactive)
  10158. (save-excursion
  10159. (goto-char (point-min))
  10160. (while (ignore-errors
  10161. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10162. (org-agenda-bulk-toggle))))
  10163. (defun org-agenda-bulk-toggle ()
  10164. "Toggle the mark at point for bulk action."
  10165. (interactive)
  10166. (if (org-agenda-bulk-marked-p)
  10167. (org-agenda-bulk-unmark)
  10168. (org-agenda-bulk-mark)))
  10169. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10170. "Remove the mark overlays between BEG and END in the agenda buffer.
  10171. BEG and END default to the buffer limits.
  10172. This only removes the overlays, it does not remove the markers
  10173. from the list in `org-agenda-bulk-marked-entries'."
  10174. (interactive)
  10175. (mapc (lambda (ov)
  10176. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10177. (delete-overlay ov)))
  10178. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10179. (defun org-agenda-bulk-unmark-all ()
  10180. "Remove all marks in the agenda buffer.
  10181. This will remove the markers and the overlays."
  10182. (interactive)
  10183. (if (null org-agenda-bulk-marked-entries)
  10184. (message "No entry to unmark")
  10185. (setq org-agenda-bulk-marked-entries nil)
  10186. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10187. (defcustom org-agenda-persistent-marks nil
  10188. "Non-nil means marked items will stay marked after a bulk action.
  10189. You can toggle this interactively by typing `p' when prompted for a
  10190. bulk action."
  10191. :group 'org-agenda
  10192. :version "24.1"
  10193. :type 'boolean)
  10194. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10195. "Shall some commands act upon headlines in the active region?
  10196. When set to t, some commands will be performed in all headlines
  10197. within the active region.
  10198. When set to `start-level', some commands will be performed in all
  10199. headlines within the active region, provided that these headlines
  10200. are of the same level than the first one.
  10201. When set to a regular expression, those commands will be
  10202. performed on the matching headlines within the active region.
  10203. The list of commands is: `org-agenda-schedule',
  10204. `org-agenda-deadline', `org-agenda-date-prompt',
  10205. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10206. See `org-loop-over-headlines-in-active-region' for the equivalent
  10207. option for Org buffers."
  10208. :type '(choice (const :tag "Don't loop" nil)
  10209. (const :tag "All headlines in active region" t)
  10210. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10211. (regexp :tag "Regular expression matcher"))
  10212. :version "27.1"
  10213. :package-version '(Org . "9.4")
  10214. :group 'org-agenda)
  10215. (defun org-agenda-bulk-action (&optional arg)
  10216. "Execute an remote-editing action on all marked entries.
  10217. The prefix arg is passed through to the command if possible."
  10218. (interactive "P")
  10219. ;; When there is no mark, act on the agenda entry at point.
  10220. (if (not org-agenda-bulk-marked-entries)
  10221. (save-excursion (org-agenda-bulk-mark)))
  10222. (dolist (m org-agenda-bulk-marked-entries)
  10223. (unless (and (markerp m)
  10224. (marker-buffer m)
  10225. (buffer-live-p (marker-buffer m))
  10226. (marker-position m))
  10227. (user-error "Marker %s for bulk command is invalid" m)))
  10228. ;; Prompt for the bulk command.
  10229. (org-unlogged-message
  10230. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10231. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10232. "[S]catter [f]unction "
  10233. (and org-agenda-bulk-custom-functions
  10234. (format " Custom: [%s]"
  10235. (mapconcat (lambda (f) (char-to-string (car f)))
  10236. org-agenda-bulk-custom-functions
  10237. "")))))
  10238. (catch 'exit
  10239. (let* ((org-log-refile (if org-log-refile 'time nil))
  10240. (entries (reverse org-agenda-bulk-marked-entries))
  10241. (org-overriding-default-time
  10242. (and (get-text-property (point) 'org-agenda-date-header)
  10243. (org-get-cursor-date)))
  10244. redo-at-end
  10245. cmd)
  10246. (pcase (read-char-exclusive)
  10247. (?p
  10248. (let ((org-agenda-persistent-marks
  10249. (not org-agenda-persistent-marks)))
  10250. (org-agenda-bulk-action)
  10251. (throw 'exit nil)))
  10252. (?$
  10253. (setq cmd #'org-agenda-archive))
  10254. (?A
  10255. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10256. ((or ?r ?w)
  10257. (let ((refile-location
  10258. (org-refile-get-location
  10259. "Refile to"
  10260. (marker-buffer (car entries))
  10261. org-refile-allow-creating-parent-nodes)))
  10262. (when (nth 3 refile-location)
  10263. (setcar (nthcdr 3 refile-location)
  10264. (move-marker
  10265. (make-marker)
  10266. (nth 3 refile-location)
  10267. (or (get-file-buffer (nth 1 refile-location))
  10268. (find-buffer-visiting (nth 1 refile-location))
  10269. (error "This should not happen")))))
  10270. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10271. (setq redo-at-end t)))
  10272. (?t
  10273. (let ((state (completing-read
  10274. "Todo state: "
  10275. (with-current-buffer (marker-buffer (car entries))
  10276. (mapcar #'list org-todo-keywords-1)))))
  10277. (setq cmd (lambda ()
  10278. (let ((org-inhibit-blocking t)
  10279. (org-inhibit-logging 'note))
  10280. (org-agenda-todo state))))))
  10281. ((and (or ?- ?+) action)
  10282. (let ((tag (completing-read
  10283. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10284. (with-current-buffer (marker-buffer (car entries))
  10285. (delq nil
  10286. (mapcar (lambda (x) (and (stringp (car x)) x))
  10287. org-current-tag-alist))))))
  10288. (setq cmd
  10289. (lambda ()
  10290. (org-agenda-set-tags tag
  10291. (if (eq action ?+) 'on 'off))))))
  10292. ((and (or ?s ?d) c)
  10293. (let* ((schedule? (eq c ?s))
  10294. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10295. (time
  10296. (and (not arg)
  10297. (let ((new (org-read-date
  10298. nil nil nil prompt org-overriding-default-time)))
  10299. ;; A "double plus" answer applies to every
  10300. ;; scheduled time. Do not turn it into
  10301. ;; a fixed date yet.
  10302. (if (string-match-p "\\`[ \t]*\\+\\+"
  10303. org-read-date-final-answer)
  10304. org-read-date-final-answer
  10305. new)))))
  10306. ;; Make sure to not prompt for a note when bulk
  10307. ;; rescheduling/resetting deadline as Org cannot cope with
  10308. ;; simultaneous notes. Besides, it could be annoying
  10309. ;; depending on the number of marked items.
  10310. (setq cmd
  10311. (if schedule?
  10312. (lambda ()
  10313. (let ((org-log-reschedule
  10314. (and org-log-reschedule 'time)))
  10315. (org-agenda-schedule arg time)))
  10316. (lambda ()
  10317. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10318. (org-agenda-deadline arg time)))))))
  10319. (?S
  10320. (unless (org-agenda-check-type nil 'agenda 'todo)
  10321. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10322. (let ((days (read-number
  10323. (format "Scatter tasks across how many %sdays: "
  10324. (if arg "week" ""))
  10325. 7)))
  10326. (setq cmd
  10327. (lambda ()
  10328. (let ((distance (1+ (random days))))
  10329. (when arg
  10330. (let ((dist distance)
  10331. (day-of-week
  10332. (calendar-day-of-week
  10333. (calendar-gregorian-from-absolute (org-today)))))
  10334. (dotimes (_ (1+ dist))
  10335. (while (member day-of-week org-agenda-weekend-days)
  10336. (cl-incf distance)
  10337. (cl-incf day-of-week)
  10338. (when (= day-of-week 7)
  10339. (setq day-of-week 0)))
  10340. (cl-incf day-of-week)
  10341. (when (= day-of-week 7)
  10342. (setq day-of-week 0)))))
  10343. ;; Silently fail when try to replan a sexp entry.
  10344. (ignore-errors
  10345. (let* ((date (calendar-gregorian-from-absolute
  10346. (+ (org-today) distance)))
  10347. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  10348. (nth 2 date))))
  10349. (org-agenda-schedule nil time))))))))
  10350. (?f
  10351. (setq cmd
  10352. (intern
  10353. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10354. (action
  10355. (setq cmd
  10356. (pcase (assoc action org-agenda-bulk-custom-functions)
  10357. (`(,_ ,fn)
  10358. fn)
  10359. (`(,_ ,fn ,arg-fn)
  10360. (apply #'apply-partially fn (funcall arg-fn)))
  10361. (_
  10362. (user-error "Invalid bulk action: %c" action))))
  10363. (setq redo-at-end t)))
  10364. ;; Sort the markers, to make sure that parents are handled
  10365. ;; before children.
  10366. (setq entries (sort entries
  10367. (lambda (a b)
  10368. (cond
  10369. ((eq (marker-buffer a) (marker-buffer b))
  10370. (< (marker-position a) (marker-position b)))
  10371. (t
  10372. (string< (buffer-name (marker-buffer a))
  10373. (buffer-name (marker-buffer b))))))))
  10374. ;; Now loop over all markers and apply CMD.
  10375. (let ((processed 0)
  10376. (skipped 0))
  10377. (dolist (e entries)
  10378. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10379. (if (not pos)
  10380. (progn (message "Skipping removed entry at %s" e)
  10381. (cl-incf skipped))
  10382. (goto-char pos)
  10383. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10384. ;; `post-command-hook' is not run yet. We make sure any
  10385. ;; pending log note is processed.
  10386. (when org-log-setup (org-add-log-note))
  10387. (cl-incf processed))))
  10388. (when redo-at-end (org-agenda-redo))
  10389. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10390. (message "Acted on %d entries%s%s"
  10391. processed
  10392. (if (= skipped 0)
  10393. ""
  10394. (format ", skipped %d (disappeared before their turn)"
  10395. skipped))
  10396. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10397. (defun org-agenda-capture (&optional with-time)
  10398. "Call `org-capture' with the date at point.
  10399. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10400. current HH:MM time."
  10401. (interactive "P")
  10402. (if (not (eq major-mode 'org-agenda-mode))
  10403. (user-error "You cannot do this outside of agenda buffers")
  10404. (let ((org-overriding-default-time
  10405. (org-get-cursor-date (equal with-time 1))))
  10406. (call-interactively 'org-capture))))
  10407. ;;; Dragging agenda lines forward/backward
  10408. (defun org-agenda-reapply-filters ()
  10409. "Re-apply all agenda filters."
  10410. (mapcar
  10411. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10412. `((,org-agenda-tag-filter tag)
  10413. (,org-agenda-category-filter category)
  10414. (,org-agenda-regexp-filter regexp)
  10415. (,org-agenda-effort-filter effort)
  10416. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10417. (,(get 'org-agenda-category-filter :preset-filter) category)
  10418. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10419. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10420. (defun org-agenda-drag-line-forward (arg &optional backward)
  10421. "Drag an agenda line forward by ARG lines.
  10422. When the optional argument `backward' is non-nil, move backward."
  10423. (interactive "p")
  10424. (let ((inhibit-read-only t) lst line)
  10425. (if (or (not (get-text-property (point) 'txt))
  10426. (save-excursion
  10427. (dotimes (_ arg)
  10428. (move-beginning-of-line (if backward 0 2))
  10429. (push (not (get-text-property (point) 'txt)) lst))
  10430. (delq nil lst)))
  10431. (message "Cannot move line forward")
  10432. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10433. (move-beginning-of-line 1)
  10434. (setq line (buffer-substring (point) end))
  10435. (delete-region (point) end)
  10436. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10437. (insert line)
  10438. (org-agenda-reapply-filters)
  10439. (org-agenda-mark-clocking-task)
  10440. (move-beginning-of-line 0)))))
  10441. (defun org-agenda-drag-line-backward (arg)
  10442. "Drag an agenda line backward by ARG lines."
  10443. (interactive "p")
  10444. (org-agenda-drag-line-forward arg t))
  10445. ;;; Flagging notes
  10446. (defun org-agenda-show-the-flagging-note ()
  10447. "Display the flagging note in the other window.
  10448. When called a second time in direct sequence, offer to remove the FLAGGING
  10449. tag and (if present) the flagging note."
  10450. (interactive)
  10451. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10452. (win (selected-window))
  10453. note) ;; heading newhead
  10454. (unless hdmarker
  10455. (user-error "No linked entry at point"))
  10456. (if (and (eq this-command last-command)
  10457. (y-or-n-p "Unflag and remove any flagging note? "))
  10458. (progn
  10459. (org-agenda-remove-flag hdmarker)
  10460. (let ((win (get-buffer-window "*Flagging Note*")))
  10461. (and win (delete-window win)))
  10462. (message "Entry unflagged"))
  10463. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10464. (unless note
  10465. (user-error "No flagging note"))
  10466. (org-kill-new note)
  10467. (org-switch-to-buffer-other-window "*Flagging Note*")
  10468. (erase-buffer)
  10469. (insert note)
  10470. (goto-char (point-min))
  10471. (while (re-search-forward "\\\\n" nil t)
  10472. (replace-match "\n" t t))
  10473. (goto-char (point-min))
  10474. (select-window win)
  10475. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10476. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10477. tag and note")))))
  10478. (defun org-agenda-remove-flag (marker)
  10479. "Remove the FLAGGED tag and any flagging note in the entry."
  10480. (let ((newhead
  10481. (org-with-point-at marker
  10482. (org-toggle-tag "FLAGGED" 'off)
  10483. (org-entry-delete nil "THEFLAGGINGNOTE")
  10484. (org-get-heading))))
  10485. (org-agenda-change-all-lines newhead marker)
  10486. (message "Entry unflagged")))
  10487. (defun org-agenda-get-any-marker (&optional pos)
  10488. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10489. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10490. ;;; Appointment reminders
  10491. (defvar appt-time-msg-list) ; defined in appt.el
  10492. ;;;###autoload
  10493. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10494. "Activate appointments found in `org-agenda-files'.
  10495. With a `\\[universal-argument]' prefix, refresh the list of \
  10496. appointments.
  10497. If FILTER is t, interactively prompt the user for a regular
  10498. expression, and filter out entries that don't match it.
  10499. If FILTER is a string, use this string as a regular expression
  10500. for filtering entries out.
  10501. If FILTER is a function, filter out entries against which
  10502. calling the function returns nil. This function takes one
  10503. argument: an entry from `org-agenda-get-day-entries'.
  10504. FILTER can also be an alist with the car of each cell being
  10505. either `headline' or `category'. For example:
  10506. \\='((headline \"IMPORTANT\")
  10507. (category \"Work\"))
  10508. will only add headlines containing IMPORTANT or headlines
  10509. belonging to the \"Work\" category.
  10510. ARGS are symbols indicating what kind of entries to consider.
  10511. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10512. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10513. and :timestamp entries. See the docstring of `org-diary' for
  10514. details and examples.
  10515. If an entry has a APPT_WARNTIME property, its value will be used
  10516. to override `appt-message-warning-time'."
  10517. (interactive "P")
  10518. (when refresh (setq appt-time-msg-list nil))
  10519. (when (eq filter t)
  10520. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10521. (let* ((cnt 0) ; count added events
  10522. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10523. (org-agenda-new-buffers nil)
  10524. (org-deadline-warning-days 0)
  10525. ;; Do not use `org-today' here because appt only takes
  10526. ;; time and without date as argument, so it may pass wrong
  10527. ;; information otherwise
  10528. (today (org-date-to-gregorian
  10529. (time-to-days nil)))
  10530. (org-agenda-restrict nil)
  10531. (files (org-agenda-files 'unrestricted)) entries file
  10532. (org-agenda-buffer nil))
  10533. ;; Get all entries which may contain an appt
  10534. (org-agenda-prepare-buffers files)
  10535. (while (setq file (pop files))
  10536. (setq entries
  10537. (delq nil
  10538. (append entries
  10539. (apply #'org-agenda-get-day-entries
  10540. file today scope)))))
  10541. ;; Map through entries and find if we should filter them out
  10542. (mapc
  10543. (lambda (x)
  10544. (let* ((evt (org-trim
  10545. (replace-regexp-in-string
  10546. org-link-bracket-re "\\2"
  10547. (or (get-text-property 1 'txt x) ""))))
  10548. (cat (get-text-property (1- (length x)) 'org-category x))
  10549. (tod (get-text-property 1 'time-of-day x))
  10550. (ok (or (null filter)
  10551. (and (stringp filter) (string-match filter evt))
  10552. (and (functionp filter) (funcall filter x))
  10553. (and (listp filter)
  10554. (let ((cat-filter (cadr (assq 'category filter)))
  10555. (evt-filter (cadr (assq 'headline filter))))
  10556. (or (and (stringp cat-filter)
  10557. (string-match cat-filter cat))
  10558. (and (stringp evt-filter)
  10559. (string-match evt-filter evt)))))))
  10560. (wrn (get-text-property 1 'warntime x)))
  10561. ;; FIXME: Shall we remove text-properties for the appt text?
  10562. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10563. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10564. (setq tod (concat "00" (number-to-string tod)))
  10565. (setq tod (when (string-match
  10566. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10567. (concat (match-string 1 tod) ":"
  10568. (match-string 2 tod))))
  10569. (when (appt-add tod evt wrn)
  10570. (setq cnt (1+ cnt))))))
  10571. entries)
  10572. (org-release-buffers org-agenda-new-buffers)
  10573. (if (eq cnt 0)
  10574. (message "No event to add")
  10575. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10576. (defun org-agenda-today-p (date)
  10577. "Non-nil when DATE means today.
  10578. DATE is either a list of the form (month day year) or a number of
  10579. days as returned by `calendar-absolute-from-gregorian' or
  10580. `org-today'. This function considers `org-extend-today-until'
  10581. when defining today."
  10582. (eq (org-today)
  10583. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10584. (defun org-agenda-todo-yesterday (&optional arg)
  10585. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10586. (interactive "P")
  10587. (let* ((org-use-effective-time t)
  10588. (hour (nth 2 (decode-time (org-current-time))))
  10589. (org-extend-today-until (1+ hour)))
  10590. (org-agenda-todo arg)))
  10591. (defun org-agenda-ctrl-c-ctrl-c ()
  10592. "Set tags in agenda buffer."
  10593. (interactive)
  10594. (org-agenda-set-tags))
  10595. (provide 'org-agenda)
  10596. ;;; org-agenda.el ends here