org-agenda.el 446 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400
  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. ;; URL: 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. (if (and (display-graphic-p)
  120. (char-displayable-p ?─))
  121. ?─
  122. ?=)
  123. "The separator between blocks in the agenda.
  124. If this is a string, it will be used as the separator, with a newline added.
  125. If it is a character, it will be repeated to fill the window width.
  126. If nil the separator is disabled. In `org-agenda-custom-commands' this
  127. addresses the separator between the current and the previous block."
  128. :group 'org-agenda
  129. :version "29.1"
  130. :type '(choice
  131. (const :tag "Disabled" nil)
  132. (character)
  133. (string)))
  134. (defgroup org-agenda-export nil
  135. "Options concerning exporting agenda views in Org mode."
  136. :tag "Org Agenda Export"
  137. :group 'org-agenda)
  138. (defcustom org-agenda-with-colors t
  139. "Non-nil means use colors in agenda views."
  140. :group 'org-agenda-export
  141. :type 'boolean)
  142. (defcustom org-agenda-exporter-settings nil
  143. ;; FIXME: Do we really want to evaluate those settings and thus force
  144. ;; the user to use `quote' all the time?
  145. "Alist of variable/value pairs that should be active during agenda export.
  146. This is a good place to set options for ps-print and for htmlize.
  147. Note that the way this is implemented, the values will be evaluated
  148. before assigned to the variables. So make sure to quote values you do
  149. *not* want evaluated, for example
  150. (setq org-agenda-exporter-settings
  151. \\='((ps-print-color-p \\='black-white)))"
  152. :group 'org-agenda-export
  153. :type '(repeat
  154. (list
  155. (variable)
  156. (sexp :tag "Value"))))
  157. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  158. "Hook run in a temporary buffer before writing the agenda to an export file.
  159. A useful function for this hook is `org-agenda-add-entry-text'."
  160. :group 'org-agenda-export
  161. :type 'hook
  162. :options '(org-agenda-add-entry-text))
  163. (defcustom org-agenda-add-entry-text-maxlines 0
  164. "Maximum number of entry text lines to be added to agenda.
  165. This is only relevant when `org-agenda-add-entry-text' is part of
  166. `org-agenda-before-write-hook', which is the default.
  167. When this is 0, nothing will happen. When it is greater than 0, it
  168. specifies the maximum number of lines that will be added for each entry
  169. that is listed in the agenda view.
  170. Note that this variable is not used during display, only when exporting
  171. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  172. and `org-agenda-entry-text-maxlines'."
  173. :group 'org-agenda
  174. :type 'integer)
  175. (defcustom org-agenda-add-entry-text-descriptive-links t
  176. "Non-nil means export org-links as descriptive links in agenda added text.
  177. This variable applies to the text added to the agenda when
  178. `org-agenda-add-entry-text-maxlines' is larger than 0.
  179. When this variable is nil, the URL will (also) be shown."
  180. :group 'org-agenda
  181. :type 'boolean)
  182. (defcustom org-agenda-export-html-style nil
  183. "The style specification for exported HTML Agenda files.
  184. If this variable contains a string, it will replace the default <style>
  185. section as produced by `htmlize'.
  186. Since there are different ways of setting style information, this variable
  187. needs to contain the full HTML structure to provide a style, including the
  188. surrounding HTML tags. The style specifications should include definitions
  189. the fonts used by the agenda, here is an example:
  190. <style type=\"text/css\">
  191. p { font-weight: normal; color: gray; }
  192. .org-agenda-structure {
  193. font-size: 110%;
  194. color: #003399;
  195. font-weight: 600;
  196. }
  197. .org-todo {
  198. color: #cc6666;
  199. font-weight: bold;
  200. }
  201. .org-agenda-done {
  202. color: #339933;
  203. }
  204. .org-done {
  205. color: #339933;
  206. }
  207. .title { text-align: center; }
  208. .todo, .deadline { color: red; }
  209. .done { color: green; }
  210. </style>
  211. or, if you want to keep the style in a file,
  212. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  213. As the value of this option simply gets inserted into the HTML <head> header,
  214. you can \"misuse\" it to also add other text to the header."
  215. :group 'org-agenda-export
  216. :group 'org-export-html
  217. :type '(choice
  218. (const nil)
  219. (string)))
  220. (defcustom org-agenda-persistent-filter nil
  221. "When set, keep filters from one agenda view to the next."
  222. :group 'org-agenda
  223. :type 'boolean)
  224. (defgroup org-agenda-custom-commands nil
  225. "Options concerning agenda views in Org mode."
  226. :tag "Org Agenda Custom Commands"
  227. :group 'org-agenda)
  228. (defconst org-sorting-choice
  229. '(choice
  230. (const time-up) (const time-down)
  231. (const timestamp-up) (const timestamp-down)
  232. (const scheduled-up) (const scheduled-down)
  233. (const deadline-up) (const deadline-down)
  234. (const ts-up) (const ts-down)
  235. (const tsia-up) (const tsia-down)
  236. (const category-keep) (const category-up) (const category-down)
  237. (const tag-down) (const tag-up)
  238. (const priority-up) (const priority-down)
  239. (const todo-state-up) (const todo-state-down)
  240. (const effort-up) (const effort-down)
  241. (const habit-up) (const habit-down)
  242. (const alpha-up) (const alpha-down)
  243. (const user-defined-up) (const user-defined-down))
  244. "Sorting choices.")
  245. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  246. ;; the new variable `org-agenda-tag-filter-preset'.
  247. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  248. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  249. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  250. "List of types searched for when creating the daily/weekly agenda.
  251. This variable is a list of symbols that controls the types of
  252. items that appear in the daily/weekly agenda. Allowed symbols in this
  253. list are
  254. :timestamp List items containing a date stamp or date range matching
  255. the selected date. This includes sexp entries in angular
  256. brackets.
  257. :sexp List entries resulting from plain diary-like sexps.
  258. :deadline List deadline due on that date. When the date is today,
  259. also list any deadlines past due, or due within
  260. `org-deadline-warning-days'.
  261. :deadline* Same as above, but only include the deadline if it has an
  262. hour specification as [h]h:mm.
  263. :scheduled List all items which are scheduled for the given date.
  264. The diary for *today* also contains items which were
  265. scheduled earlier and are not yet marked DONE.
  266. :scheduled* Same as above, but only include the scheduled item if it
  267. has an hour specification as [h]h:mm.
  268. By default, all four non-starred types are turned on.
  269. When :scheduled* or :deadline* are included, :schedule or :deadline
  270. will be ignored.
  271. Never set this variable globally using `setq', because then it
  272. will apply to all future agenda commands. Instead, bind it with
  273. `let' to scope it dynamically into the agenda-constructing
  274. command. A good way to set it is through options in
  275. `org-agenda-custom-commands'. For a more flexible (though
  276. somewhat less efficient) way of determining what is included in
  277. the daily/weekly agenda, see `org-agenda-skip-function'.")
  278. (defconst org-agenda-custom-commands-local-options
  279. `(repeat :tag "Local settings for this command. Remember to quote values"
  280. (choice :tag "Setting"
  281. (list :tag "Heading for this block"
  282. (const org-agenda-overriding-header)
  283. (string :tag "Headline"))
  284. (list :tag "Files to be searched"
  285. (const org-agenda-files)
  286. (list
  287. (const :format "" quote)
  288. (repeat (file))))
  289. (list :tag "Sorting strategy"
  290. (const org-agenda-sorting-strategy)
  291. (list
  292. (const :format "" quote)
  293. (repeat
  294. ,org-sorting-choice)))
  295. (list :tag "Prefix format"
  296. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  297. (string))
  298. (list :tag "Number of days in agenda"
  299. (const org-agenda-span)
  300. (list
  301. (const :format "" quote)
  302. (choice (const :tag "Day" day)
  303. (const :tag "Week" week)
  304. (const :tag "Fortnight" fortnight)
  305. (const :tag "Month" month)
  306. (const :tag "Year" year)
  307. (integer :tag "Custom"))))
  308. (list :tag "Fixed starting date"
  309. (const org-agenda-start-day)
  310. (string :value "2007-11-01"))
  311. (list :tag "Start on day of week"
  312. (const org-agenda-start-on-weekday)
  313. (choice :value 1
  314. (const :tag "Today" nil)
  315. (integer :tag "Weekday No.")))
  316. (list :tag "Include data from diary"
  317. (const org-agenda-include-diary)
  318. (boolean))
  319. (list :tag "Deadline Warning days"
  320. (const org-deadline-warning-days)
  321. (integer :value 1))
  322. (list :tag "Category filter preset"
  323. (const org-agenda-category-filter-preset)
  324. (list
  325. (const :format "" quote)
  326. (repeat
  327. (string :tag "+category or -category"))))
  328. (list :tag "Tags filter preset"
  329. (const org-agenda-tag-filter-preset)
  330. (list
  331. (const :format "" quote)
  332. (repeat
  333. (string :tag "+tag or -tag"))))
  334. (list :tag "Effort filter preset"
  335. (const org-agenda-effort-filter-preset)
  336. (list
  337. (const :format "" quote)
  338. (repeat
  339. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  340. (list :tag "Regexp filter preset"
  341. (const org-agenda-regexp-filter-preset)
  342. (list
  343. (const :format "" quote)
  344. (repeat
  345. (string :tag "+regexp or -regexp"))))
  346. (list :tag "Set daily/weekly entry types"
  347. (const org-agenda-entry-types)
  348. (list
  349. (const :format "" quote)
  350. (set :greedy t :value ,org-agenda-entry-types
  351. (const :deadline)
  352. (const :scheduled)
  353. (const :deadline*)
  354. (const :scheduled*)
  355. (const :timestamp)
  356. (const :sexp))))
  357. (list :tag "Columns format"
  358. (const org-overriding-columns-format)
  359. (string :tag "Format"))
  360. (list :tag "Standard skipping condition"
  361. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  362. (const org-agenda-skip-function)
  363. (list
  364. (const :format "" quote)
  365. (list
  366. (choice
  367. :tag "Skipping range"
  368. (const :tag "Skip entry" org-agenda-skip-entry-if)
  369. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  370. (repeat :inline t :tag "Conditions for skipping"
  371. (choice
  372. :tag "Condition type"
  373. (list :tag "Regexp matches" :inline t
  374. (const :format "" regexp)
  375. (regexp))
  376. (list :tag "Regexp does not match" :inline t
  377. (const :format "" notregexp)
  378. (regexp))
  379. (list :tag "TODO state is" :inline t
  380. (const todo)
  381. (choice
  382. (const :tag "Any not-done state" todo)
  383. (const :tag "Any done state" done)
  384. (const :tag "Any state" any)
  385. (list :tag "Keyword list"
  386. (const :format "" quote)
  387. (repeat (string :tag "Keyword")))))
  388. (list :tag "TODO state is not" :inline t
  389. (const nottodo)
  390. (choice
  391. (const :tag "Any not-done state" todo)
  392. (const :tag "Any done state" done)
  393. (const :tag "Any state" any)
  394. (list :tag "Keyword list"
  395. (const :format "" quote)
  396. (repeat (string :tag "Keyword")))))
  397. (const :tag "scheduled" scheduled)
  398. (const :tag "not scheduled" notscheduled)
  399. (const :tag "deadline" deadline)
  400. (const :tag "no deadline" notdeadline)
  401. (const :tag "timestamp" timestamp)
  402. (const :tag "no timestamp" nottimestamp))))))
  403. (list :tag "Non-standard skipping condition"
  404. :value (org-agenda-skip-function)
  405. (const org-agenda-skip-function)
  406. (sexp :tag "Function or form (quoted!)"))
  407. (list :tag "Any variable"
  408. (variable :tag "Variable")
  409. (sexp :tag "Value (sexp)"))))
  410. "Selection of examples for agenda command settings.
  411. This will be spliced into the custom type of
  412. `org-agenda-custom-commands'.")
  413. (defcustom org-agenda-custom-commands
  414. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  415. "Custom commands for the agenda.
  416. \\<org-mode-map>
  417. These commands will be offered on the splash screen displayed by the
  418. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  419. (key desc type match settings files)
  420. key The key (one or more characters as a string) to be associated
  421. with the command.
  422. desc A description of the command. When omitted or nil, a default
  423. description is built using MATCH.
  424. type The command type, any of the following symbols:
  425. agenda The daily/weekly agenda.
  426. agenda* Appointments for current week/day.
  427. todo Entries with a specific TODO keyword, in all agenda files.
  428. search Entries containing search words entry or headline.
  429. tags Tags/Property/TODO match in all agenda files.
  430. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  431. todo-tree Sparse tree of specific TODO keyword in *current* file.
  432. tags-tree Sparse tree with all tags matches in *current* file.
  433. occur-tree Occur sparse tree for *current* file.
  434. alltodo The global TODO list.
  435. stuck Stuck projects.
  436. ... A user-defined function.
  437. match What to search for:
  438. - a single keyword for TODO keyword searches
  439. - a tags/property/todo match expression for searches
  440. - a word search expression for text searches.
  441. - a regular expression for occur searches
  442. For all other commands, this should be the empty string.
  443. settings A list of option settings, similar to that in a let form, so like
  444. this: ((opt1 val1) (opt2 val2) ...). The values will be
  445. evaluated at the moment of execution, so quote them when needed.
  446. files A list of files to write the produced agenda buffer to with
  447. the command `org-store-agenda-views'.
  448. If a file name ends in \".html\", an HTML version of the buffer
  449. is written out. If it ends in \".ps\", a PostScript version is
  450. produced. Otherwise, only the plain text is written to the file.
  451. You can also define a set of commands, to create a composite agenda buffer.
  452. In this case, an entry looks like this:
  453. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  454. where
  455. desc A description string to be displayed in the dispatcher menu.
  456. cmd An agenda command, similar to the above. However, tree commands
  457. are not allowed. Valid commands for a set are:
  458. (agenda \"\" settings)
  459. (agenda* \"\" settings)
  460. (alltodo \"\" settings)
  461. (stuck \"\" settings)
  462. (todo \"match\" settings files)
  463. (search \"match\" settings files)
  464. (tags \"match\" settings files)
  465. (tags-todo \"match\" settings files)
  466. Each command can carry a list of options, and another set of options can be
  467. given for the whole set of commands. Individual command options take
  468. precedence over the general options.
  469. When using several characters as key to a command, the first characters
  470. are prefix commands. For the dispatcher to display useful information, you
  471. should provide a description for the prefix, like
  472. (setq org-agenda-custom-commands
  473. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  474. (\"hl\" tags \"+HOME+Lisa\")
  475. (\"hp\" tags \"+HOME+Peter\")
  476. (\"hk\" tags \"+HOME+Kim\")))
  477. See also Info node `(org) Custom Agenda Views'."
  478. :group 'org-agenda-custom-commands
  479. :type `(repeat
  480. (choice :value ("x" "Describe command here" tags "" nil)
  481. (list :tag "Single command"
  482. (string :tag "Access Key(s) ")
  483. (option (string :tag "Description"))
  484. (choice
  485. (const :tag "Agenda" agenda)
  486. (const :tag "TODO list" alltodo)
  487. (const :tag "Search words" search)
  488. (const :tag "Stuck projects" stuck)
  489. (const :tag "Tags/Property match (all agenda files)" tags)
  490. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  491. (const :tag "TODO keyword search (all agenda files)" todo)
  492. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  493. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  494. (const :tag "Occur tree (current buffer)" occur-tree)
  495. (sexp :tag "Other, user-defined function"))
  496. (string :tag "Match (only for some commands)")
  497. ,org-agenda-custom-commands-local-options
  498. (option (repeat :tag "Export" (file :tag "Export to"))))
  499. (list :tag "Command series, all agenda files"
  500. (string :tag "Access Key(s)")
  501. (string :tag "Description ")
  502. (repeat :tag "Component"
  503. (choice
  504. (list :tag "Agenda"
  505. (const :format "" agenda)
  506. (const :tag "" :format "" "")
  507. ,org-agenda-custom-commands-local-options)
  508. (list :tag "TODO list (all keywords)"
  509. (const :format "" alltodo)
  510. (const :tag "" :format "" "")
  511. ,org-agenda-custom-commands-local-options)
  512. (list :tag "Search words"
  513. (const :format "" search)
  514. (string :tag "Match")
  515. ,org-agenda-custom-commands-local-options)
  516. (list :tag "Stuck projects"
  517. (const :format "" stuck)
  518. (const :tag "" :format "" "")
  519. ,org-agenda-custom-commands-local-options)
  520. (list :tag "Tags/Property match (all agenda files)"
  521. (const :format "" tags)
  522. (string :tag "Match")
  523. ,org-agenda-custom-commands-local-options)
  524. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  525. (const :format "" tags-todo)
  526. (string :tag "Match")
  527. ,org-agenda-custom-commands-local-options)
  528. (list :tag "TODO keyword search"
  529. (const :format "" todo)
  530. (string :tag "Match")
  531. ,org-agenda-custom-commands-local-options)
  532. (list :tag "Other, user-defined function"
  533. (symbol :tag "function")
  534. (string :tag "Match")
  535. ,org-agenda-custom-commands-local-options)))
  536. (repeat :tag "Settings for entire command set"
  537. (list (variable :tag "Any variable")
  538. (sexp :tag "Value")))
  539. (option (repeat :tag "Export" (file :tag "Export to"))))
  540. (cons :tag "Prefix key documentation"
  541. (string :tag "Access Key(s)")
  542. (string :tag "Description ")))))
  543. (defcustom org-agenda-query-register ?o
  544. "The register holding the current query string.
  545. The purpose of this is that if you construct a query string interactively,
  546. you can then use it to define a custom command."
  547. :group 'org-agenda-custom-commands
  548. :type 'character)
  549. (defcustom org-stuck-projects
  550. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  551. "How to identify stuck projects.
  552. This is a list of four items:
  553. 1. A tags/todo/property matcher string that is used to identify a project.
  554. See the manual for a description of tag and property searches.
  555. The entire tree below a headline matched by this is considered one project.
  556. 2. A list of TODO keywords identifying non-stuck projects.
  557. If the project subtree contains any headline with one of these todo
  558. keywords, the project is considered to be not stuck. If you specify
  559. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  560. 3. A list of tags identifying non-stuck projects.
  561. If the project subtree contains any headline with one of these tags,
  562. the project is considered to be not stuck. If you specify \"*\" as
  563. a tag, any tag will mark the project unstuck. Note that this is about
  564. the explicit presence of a tag somewhere in the subtree, inherited
  565. tags do not count here. If inherited tags make a project not stuck,
  566. use \"-TAG\" in the tags part of the matcher under (1.) above.
  567. 4. An arbitrary regular expression matching non-stuck projects.
  568. If the project turns out to be not stuck, search continues also in the
  569. subtree to see if any of the subtasks have project status.
  570. See also the variable `org-tags-match-list-sublevels' which applies
  571. to projects matched by this search as well.
  572. After defining this variable, you may use `org-agenda-list-stuck-projects'
  573. \(bound to `\\[org-agenda] #') to produce the list."
  574. :group 'org-agenda-custom-commands
  575. :type '(list
  576. (string :tag "Tags/TODO match to identify a project")
  577. (repeat :tag "Projects are *not* stuck if they have an entry with \
  578. TODO keyword any of" (string))
  579. (repeat :tag "Projects are *not* stuck if they have an entry with \
  580. TAG being any of" (string))
  581. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  582. the subtree")))
  583. (defgroup org-agenda-skip nil
  584. "Options concerning skipping parts of agenda files."
  585. :tag "Org Agenda Skip"
  586. :group 'org-agenda)
  587. (defcustom org-agenda-skip-function-global nil
  588. "Function to be called at each match during agenda construction.
  589. If this function returns nil, the current match should not be skipped.
  590. If the function decided to skip an agenda match, is must return the
  591. buffer position from which the search should be continued.
  592. This may also be a Lisp form, which will be evaluated.
  593. This variable will be applied to every agenda match, including
  594. tags/property searches and TODO lists. So try to make the test function
  595. do its checking as efficiently as possible. To implement a skipping
  596. condition just for specific agenda commands, use the variable
  597. `org-agenda-skip-function' which can be set in the options section
  598. of custom agenda commands."
  599. :group 'org-agenda-skip
  600. :type 'sexp)
  601. (defgroup org-agenda-daily/weekly nil
  602. "Options concerning the daily/weekly agenda."
  603. :tag "Org Agenda Daily/Weekly"
  604. :group 'org-agenda)
  605. (defgroup org-agenda-todo-list nil
  606. "Options concerning the global todo list agenda view."
  607. :tag "Org Agenda Todo List"
  608. :group 'org-agenda)
  609. (defgroup org-agenda-match-view nil
  610. "Options concerning the general tags/property/todo match agenda view."
  611. :tag "Org Agenda Match View"
  612. :group 'org-agenda)
  613. (defgroup org-agenda-search-view nil
  614. "Options concerning the search agenda view."
  615. :tag "Org Agenda Search View"
  616. :group 'org-agenda)
  617. (defvar org-agenda-archives-mode nil
  618. "Non-nil means the agenda will include archived items.
  619. If this is the symbol `trees', trees in the selected agenda scope
  620. that are marked with the ARCHIVE tag will be included anyway. When this is
  621. t, also all archive files associated with the current selection of agenda
  622. files will be included.")
  623. (defcustom org-agenda-restriction-lock-highlight-subtree t
  624. "Non-nil means highlight the whole subtree when restriction is active.
  625. Otherwise only highlight the headline. Highlighting the whole subtree is
  626. useful to ensure no edits happen beyond the restricted region."
  627. :group 'org-agenda
  628. :type 'boolean)
  629. (defcustom org-agenda-skip-comment-trees t
  630. "Non-nil means skip trees that start with the COMMENT keyword.
  631. When nil, these trees are also scanned by agenda commands."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-todo-list-sublevels t
  635. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  636. When nil, the sublevels of a TODO entry are not checked, resulting in
  637. potentially much shorter TODO lists."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-todo-list
  640. :type 'boolean)
  641. (defcustom org-agenda-todo-ignore-with-date nil
  642. "Non-nil means don't show entries with a date in the global todo list.
  643. You can use this if you prefer to mark mere appointments with a TODO keyword,
  644. but don't want them to show up in the TODO list.
  645. When this is set, it also covers deadlines and scheduled items, the settings
  646. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  647. will be ignored.
  648. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  649. :group 'org-agenda-skip
  650. :group 'org-agenda-todo-list
  651. :type 'boolean)
  652. (defcustom org-agenda-todo-ignore-timestamp nil
  653. "Non-nil means don't show entries with a timestamp.
  654. This applies when creating the global todo list.
  655. Valid values are:
  656. past Don't show entries for today or in the past.
  657. future Don't show entries with a timestamp in the future.
  658. The idea behind this is that if it has a future
  659. timestamp, you don't want to think about it until the
  660. date.
  661. all Don't show any entries with a timestamp in the global todo list.
  662. The idea behind this is that by setting a timestamp, you
  663. have already \"taken care\" of this item.
  664. This variable can also have an integer as a value. If positive (N),
  665. todos with a timestamp N or more days in the future will be ignored. If
  666. negative (-N), todos with a timestamp N or more days in the past will be
  667. ignored. If 0, todos with a timestamp either today or in the future will
  668. be ignored. For example, a value of -1 will exclude todos with a
  669. timestamp in the past (yesterday or earlier), while a value of 7 will
  670. exclude todos with a timestamp a week or more in the future.
  671. See also `org-agenda-todo-ignore-with-date'.
  672. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  673. to make his option also apply to the tags-todo list."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-todo-list
  676. :version "24.1"
  677. :type '(choice
  678. (const :tag "Ignore future timestamp todos" future)
  679. (const :tag "Ignore past or present timestamp todos" past)
  680. (const :tag "Ignore all timestamp todos" all)
  681. (const :tag "Show timestamp todos" nil)
  682. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  683. (defcustom org-agenda-todo-ignore-scheduled nil
  684. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  685. This applies when creating the global todo list.
  686. Valid values are:
  687. past Don't show entries scheduled today or in the past.
  688. future Don't show entries scheduled in the future.
  689. The idea behind this is that by scheduling it, you don't want to
  690. think about it until the scheduled date.
  691. all Don't show any scheduled entries in the global todo list.
  692. The idea behind this is that by scheduling it, you have already
  693. \"taken care\" of this item.
  694. t Same as `all', for backward compatibility.
  695. This variable can also have an integer as a value. See
  696. `org-agenda-todo-ignore-timestamp' for more details.
  697. See also `org-agenda-todo-ignore-with-date'.
  698. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  699. to make his option also apply to the tags-todo list."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-todo-list
  702. :type '(choice
  703. (const :tag "Ignore future-scheduled todos" future)
  704. (const :tag "Ignore past- or present-scheduled todos" past)
  705. (const :tag "Ignore all scheduled todos" all)
  706. (const :tag "Ignore all scheduled todos (compatibility)" t)
  707. (const :tag "Show scheduled todos" nil)
  708. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  709. (defcustom org-agenda-todo-ignore-deadlines nil
  710. "Non-nil means ignore some deadline TODO items when making TODO list.
  711. There are different motivations for using different values, please think
  712. carefully when configuring this variable.
  713. This applies when creating the global TODO list.
  714. Valid values are:
  715. near Don't show near deadline entries. A deadline is near when it is
  716. closer than `org-deadline-warning-days' days. The idea behind this
  717. is that such items will appear in the agenda anyway.
  718. far Don't show TODO entries where a deadline has been defined, but
  719. is not going to happen anytime soon. This is useful if you want to use
  720. the TODO list to figure out what to do now.
  721. past Don't show entries with a deadline timestamp for today or in the past.
  722. future Don't show entries with a deadline timestamp in the future, not even
  723. when they become `near' ones. Use it with caution.
  724. all Ignore all TODO entries that do have a deadline.
  725. t Same as `near', for backward compatibility.
  726. This variable can also have an integer as a value. See
  727. `org-agenda-todo-ignore-timestamp' for more details.
  728. See also `org-agenda-todo-ignore-with-date'.
  729. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  730. to make his option also apply to the tags-todo list."
  731. :group 'org-agenda-skip
  732. :group 'org-agenda-todo-list
  733. :type '(choice
  734. (const :tag "Ignore near deadlines" near)
  735. (const :tag "Ignore near deadlines (compatibility)" t)
  736. (const :tag "Ignore far deadlines" far)
  737. (const :tag "Ignore all TODOs with a deadlines" all)
  738. (const :tag "Show all TODOs, even if they have a deadline" nil)
  739. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  740. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  741. "Time unit to use when possibly ignoring an agenda item.
  742. See the docstring of various `org-agenda-todo-ignore-*' options.
  743. The default is to compare time stamps using days. An item is thus
  744. considered to be in the future if it is at least one day after today.
  745. Non-nil means to compare time stamps using seconds. An item is then
  746. considered future if it has a time value later than current time."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-todo-list
  749. :version "24.4"
  750. :package-version '(Org . "8.0")
  751. :type '(choice
  752. (const :tag "Compare time with days" nil)
  753. (const :tag "Compare time with seconds" t)))
  754. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  755. "Non-nil means honor todo-list ignores options also in tags-todo search.
  756. The variables
  757. `org-agenda-todo-ignore-with-date',
  758. `org-agenda-todo-ignore-timestamp',
  759. `org-agenda-todo-ignore-scheduled',
  760. `org-agenda-todo-ignore-deadlines'
  761. make the global TODO list skip entries that have time stamps of certain
  762. kinds. If this option is set, the same options will also apply for the
  763. tags-todo search, which is the general tags/property matcher
  764. restricted to unfinished TODO entries only."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-todo-list
  767. :group 'org-agenda-match-view
  768. :type 'boolean)
  769. (defcustom org-agenda-skip-scheduled-if-done nil
  770. "Non-nil means don't show scheduled items in agenda when they are done.
  771. This is relevant for the daily/weekly agenda, not for the TODO list. It
  772. applies only to the actual date of the scheduling. Warnings about an item
  773. with a past scheduling dates are always turned off when the item is DONE."
  774. :group 'org-agenda-skip
  775. :group 'org-agenda-daily/weekly
  776. :type 'boolean)
  777. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  778. "Non-nil means skip scheduling line if same entry shows because of deadline.
  779. In the agenda of today, an entry can show up multiple times
  780. because it is both scheduled and has a nearby deadline, and maybe
  781. a plain time stamp as well.
  782. When this variable is nil, the entry will be shown several times.
  783. When set to t, then only the deadline is shown and the fact that
  784. the entry is scheduled today or was scheduled previously is not
  785. shown.
  786. When set to the symbol `not-today', skip scheduled previously,
  787. but not scheduled today.
  788. When set to the symbol `repeated-after-deadline', skip scheduled
  789. items if they are repeated beyond the current deadline."
  790. :group 'org-agenda-skip
  791. :group 'org-agenda-daily/weekly
  792. :type '(choice
  793. (const :tag "Never" nil)
  794. (const :tag "Always" t)
  795. (const :tag "Not when scheduled today" not-today)
  796. (const :tag "When repeated past deadline" repeated-after-deadline)))
  797. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  798. "Non-nil means skip timestamp line if same entry shows because of deadline.
  799. In the agenda of today, an entry can show up multiple times
  800. because it has both a plain timestamp and has a nearby deadline.
  801. When this variable is t, then only the deadline is shown and the
  802. fact that the entry has a timestamp for or including today is not
  803. shown. When this variable is nil, the entry will be shown
  804. several times."
  805. :group 'org-agenda-skip
  806. :group 'org-agenda-daily/weekly
  807. :version "24.1"
  808. :type '(choice
  809. (const :tag "Never" nil)
  810. (const :tag "Always" t)))
  811. (defcustom org-agenda-skip-deadline-if-done nil
  812. "Non-nil means don't show deadlines when the corresponding item is done.
  813. When nil, the deadline is still shown and should give you a happy feeling.
  814. This is relevant for the daily/weekly agenda. It applies only to the
  815. actual date of the deadline. Warnings about approaching and past-due
  816. deadlines are always turned off when the item is DONE."
  817. :group 'org-agenda-skip
  818. :group 'org-agenda-daily/weekly
  819. :type 'boolean)
  820. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  821. "Non-nil means skip deadline prewarning when entry is also scheduled.
  822. This will apply on all days where a prewarning for the deadline would
  823. be shown, but not at the day when the entry is actually due. On that day,
  824. the deadline will be shown anyway.
  825. This variable may be set to nil, t, the symbol `pre-scheduled',
  826. or a number which will then give the number of days before the actual
  827. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  828. eliminates the deadline prewarning only prior to the scheduled date.
  829. This can be used in a workflow where the first showing of the deadline will
  830. trigger you to schedule it, and then you don't want to be reminded of it
  831. because you will take care of it on the day when scheduled."
  832. :group 'org-agenda-skip
  833. :group 'org-agenda-daily/weekly
  834. :version "24.1"
  835. :type '(choice
  836. (const :tag "Always show prewarning" nil)
  837. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  838. (const :tag "Remove prewarning if entry is scheduled" t)
  839. (integer :tag "Restart prewarning N days before deadline")))
  840. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  841. "Non-nil means skip scheduled delay when entry also has a deadline.
  842. This variable may be set to nil, t, the symbol `post-deadline',
  843. or a number which will then give the number of days after the actual
  844. scheduled date when the delay should expire. The symbol `post-deadline'
  845. eliminates the schedule delay when the date is posterior to the deadline."
  846. :group 'org-agenda-skip
  847. :group 'org-agenda-daily/weekly
  848. :version "24.4"
  849. :package-version '(Org . "8.0")
  850. :type '(choice
  851. (const :tag "Always honor delay" nil)
  852. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  853. (const :tag "Ignore delay if entry has a deadline" t)
  854. (integer :tag "Honor delay up until N days after the scheduled date")))
  855. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  856. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  857. When non-nil, after the search for timestamps has matched once in an
  858. entry, the rest of the entry will not be searched."
  859. :group 'org-agenda-skip
  860. :type 'boolean)
  861. (defcustom org-agenda-skip-timestamp-if-done nil
  862. "Non-nil means don't select item by timestamp or -range if it is DONE."
  863. :group 'org-agenda-skip
  864. :group 'org-agenda-daily/weekly
  865. :type 'boolean)
  866. (defcustom org-agenda-dim-blocked-tasks t
  867. "Non-nil means dim blocked tasks in the agenda display.
  868. This causes some overhead during agenda construction, but if you
  869. have turned on `org-enforce-todo-dependencies',
  870. `org-enforce-todo-checkbox-dependencies', or any other blocking
  871. mechanism, this will create useful feedback in the agenda.
  872. Instead of t, this variable can also have the value `invisible'.
  873. Then blocked tasks will be invisible and only become visible when
  874. they become unblocked. An exemption to this behavior is when a task is
  875. blocked because of unchecked checkboxes below it. Since checkboxes do
  876. not show up in the agenda views, making this task invisible you remove any
  877. trace from agenda views that there is something to do. Therefore, a task
  878. that is blocked because of checkboxes will never be made invisible, it
  879. will only be dimmed."
  880. :group 'org-agenda-daily/weekly
  881. :group 'org-agenda-todo-list
  882. :version "24.3"
  883. :type '(choice
  884. (const :tag "Do not dim" nil)
  885. (const :tag "Dim to a gray face" t)
  886. (const :tag "Make invisible" invisible)))
  887. (defgroup org-agenda-startup nil
  888. "Options concerning initial settings in the Agenda in Org Mode."
  889. :tag "Org Agenda Startup"
  890. :group 'org-agenda)
  891. (defcustom org-agenda-menu-show-matcher t
  892. "Non-nil means show the match string in the agenda dispatcher menu.
  893. When nil, the matcher string is not shown, but is put into the help-echo
  894. property so than moving the mouse over the command shows it.
  895. Setting it to nil is good if matcher strings are very long and/or if
  896. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  897. :group 'org-agenda
  898. :version "24.1"
  899. :type 'boolean)
  900. (defcustom org-agenda-menu-two-columns nil
  901. "Non-nil means, use two columns to show custom commands in the dispatcher.
  902. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  903. to nil."
  904. :group 'org-agenda
  905. :version "24.1"
  906. :type 'boolean)
  907. (defcustom org-agenda-finalize-hook nil
  908. "Hook run just before displaying an agenda buffer.
  909. The buffer is still writable when the hook is called.
  910. You can modify some of the buffer substrings but you should be
  911. extra careful not to modify the text properties of the agenda
  912. headlines as the agenda display heavily relies on them."
  913. :group 'org-agenda-startup
  914. :type 'hook)
  915. (defcustom org-agenda-filter-hook nil
  916. "Hook run just after filtering with `org-agenda-filter'."
  917. :group 'org-agenda-startup
  918. :package-version '(Org . "9.4")
  919. :type 'hook)
  920. (defcustom org-agenda-mouse-1-follows-link nil
  921. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  922. A longer mouse click will still set point. Needs to be set
  923. before org.el is loaded."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-start-with-follow-mode nil
  927. "The initial value of follow mode in a newly created agenda window."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-follow-indirect nil
  931. "Non-nil means `org-agenda-follow-mode' displays only the
  932. current item's tree, in an indirect buffer."
  933. :group 'org-agenda
  934. :version "24.1"
  935. :type 'boolean)
  936. (defcustom org-agenda-show-outline-path t
  937. "Non-nil means show outline path in echo area after line motion."
  938. :group 'org-agenda-startup
  939. :type 'boolean)
  940. (defcustom org-agenda-start-with-entry-text-mode nil
  941. "The initial value of entry-text-mode in a newly created agenda window."
  942. :group 'org-agenda-startup
  943. :type 'boolean)
  944. (defcustom org-agenda-entry-text-maxlines 5
  945. "Number of text lines to be added when `E' is pressed in the agenda.
  946. Note that this variable only used during agenda display. To add entry text
  947. when exporting the agenda, configure the variable
  948. `org-agenda-add-entry-text-maxlines'."
  949. :group 'org-agenda
  950. :type 'integer)
  951. (defcustom org-agenda-entry-text-exclude-regexps nil
  952. "List of regular expressions to clean up entry text.
  953. The complete matches of all regular expressions in this list will be
  954. removed from entry text before it is shown in the agenda."
  955. :group 'org-agenda
  956. :type '(repeat (regexp)))
  957. (defcustom org-agenda-entry-text-leaders " > "
  958. "Text prepended to the entry text in agenda buffers."
  959. :version "24.4"
  960. :package-version '(Org . "8.0")
  961. :group 'org-agenda
  962. :type 'string)
  963. (defvar org-agenda-entry-text-cleanup-hook nil
  964. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  965. This cleanup is done in a temporary buffer, so the function may inspect and
  966. change the entire buffer.
  967. Some default stuff like drawers and scheduling/deadline dates will already
  968. have been removed when this is called, as will any matches for regular
  969. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  970. (defvar org-agenda-include-inactive-timestamps nil
  971. "Non-nil means include inactive time stamps in agenda.
  972. Dynamically scoped.")
  973. (defgroup org-agenda-windows nil
  974. "Options concerning the windows used by the Agenda in Org Mode."
  975. :tag "Org Agenda Windows"
  976. :group 'org-agenda)
  977. (defcustom org-agenda-window-setup 'reorganize-frame
  978. "How the agenda buffer should be displayed.
  979. Possible values for this option are:
  980. current-window Show agenda in the current window, keeping all other windows.
  981. other-window Use `switch-to-buffer-other-window' to display agenda.
  982. only-window Show agenda, deleting all other windows.
  983. reorganize-frame Show only two windows on the current frame, the current
  984. window and the agenda.
  985. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  986. Also, when exiting the agenda, kill that frame.
  987. other-tab Use `switch-to-buffer-other-tab' to display the
  988. agenda, making use of the `tab-bar-mode' introduced
  989. in Emacs version 27.1. Also, kill that tab when
  990. exiting the agenda view.
  991. See also the variable `org-agenda-restore-windows-after-quit'."
  992. :group 'org-agenda-windows
  993. :type '(choice
  994. (const current-window)
  995. (const other-frame)
  996. (const other-tab)
  997. (const other-window)
  998. (const only-window)
  999. (const reorganize-frame))
  1000. :package-version '(Org . "9.4"))
  1001. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1002. "The min and max height of the agenda window as a fraction of frame height.
  1003. The value of the variable is a cons cell with two numbers between 0 and 1.
  1004. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1005. :group 'org-agenda-windows
  1006. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1007. (defcustom org-agenda-restore-windows-after-quit nil
  1008. "Non-nil means restore window configuration upon exiting agenda.
  1009. Before the window configuration is changed for displaying the
  1010. agenda, the current status is recorded. When the agenda is
  1011. exited with `q' or `x' and this option is set, the old state is
  1012. restored. If `org-agenda-window-setup' is `other-frame' or
  1013. `other-tab', the value of this option will be ignored."
  1014. :group 'org-agenda-windows
  1015. :type 'boolean)
  1016. (defcustom org-agenda-span 'week
  1017. "Number of days to include in overview display.
  1018. Can be day, week, month, year, or any number of days.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :type '(choice (const :tag "Day" day)
  1022. (const :tag "Week" week)
  1023. (const :tag "Fortnight" fortnight)
  1024. (const :tag "Month" month)
  1025. (const :tag "Year" year)
  1026. (integer :tag "Custom")))
  1027. (defcustom org-agenda-start-on-weekday 1
  1028. "Non-nil means start the overview always on the specified weekday.
  1029. 0 denotes Sunday, 1 denotes Monday, etc.
  1030. When nil, always start on the current day.
  1031. Custom commands can set this variable in the options section."
  1032. :group 'org-agenda-daily/weekly
  1033. :type '(choice (const :tag "Today" nil)
  1034. (integer :tag "Weekday No.")))
  1035. (defcustom org-agenda-show-all-dates t
  1036. "Non-nil means `org-agenda' shows every day in the selected range.
  1037. When nil, only the days which actually have entries are shown."
  1038. :group 'org-agenda-daily/weekly
  1039. :type 'boolean)
  1040. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1041. "Format string for displaying dates in the agenda.
  1042. Used by the daily/weekly agenda. This should be a format string
  1043. understood by `format-time-string', or a function returning the
  1044. formatted date as a string. The function must take a single
  1045. argument, a calendar-style date list like (month day year)."
  1046. :group 'org-agenda-daily/weekly
  1047. :type '(choice
  1048. (string :tag "Format string")
  1049. (function :tag "Function")))
  1050. (defun org-agenda-end-of-line ()
  1051. "Go to the end of visible line."
  1052. (interactive)
  1053. (goto-char (line-end-position)))
  1054. (defun org-agenda-format-date-aligned (date)
  1055. "Format a DATE string for display in the daily/weekly agenda.
  1056. This function makes sure that dates are aligned for easy reading."
  1057. (require 'cal-iso)
  1058. (let* ((dayname (calendar-day-name date))
  1059. (day (cadr date))
  1060. (day-of-week (calendar-day-of-week date))
  1061. (month (car date))
  1062. (monthname (calendar-month-name month))
  1063. (year (nth 2 date))
  1064. (iso-week (org-days-to-iso-week
  1065. (calendar-absolute-from-gregorian date)))
  1066. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1067. ;; (1- year))
  1068. ;; ((and (= month 12) (<= iso-week 1))
  1069. ;; (1+ year))
  1070. ;; (t year)))
  1071. (weekstring (if (= day-of-week 1)
  1072. (format " W%02d" iso-week)
  1073. "")))
  1074. (format "%-10s %2d %s %4d%s"
  1075. dayname day monthname year weekstring)))
  1076. (defcustom org-agenda-time-leading-zero nil
  1077. "Non-nil means use leading zero for military times in agenda.
  1078. For example, 9:30am would become 09:30 rather than 9:30."
  1079. :group 'org-agenda-daily/weekly
  1080. :version "24.1"
  1081. :type 'boolean)
  1082. (defcustom org-agenda-timegrid-use-ampm nil
  1083. "When set, show AM/PM style timestamps on the timegrid."
  1084. :group 'org-agenda
  1085. :version "24.1"
  1086. :type 'boolean)
  1087. (defcustom org-agenda-clock-report-header nil
  1088. "Header for org agenda clock report mode"
  1089. :group 'org-agenda
  1090. :type '(choice
  1091. (string :tag "Header")
  1092. (const :tag "No header" nil))
  1093. :safe #'stringp
  1094. :package-version '(Org . "9.6"))
  1095. (defun org-agenda-time-of-day-to-ampm (time)
  1096. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1097. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1098. (minute (substring time -2))
  1099. (ampm "am"))
  1100. (cond
  1101. ((equal hour-number 12)
  1102. (setq ampm "pm"))
  1103. ((> hour-number 12)
  1104. (setq ampm "pm")
  1105. (setq hour-number (- hour-number 12))))
  1106. (concat
  1107. (if org-agenda-time-leading-zero
  1108. (format "%02d" hour-number)
  1109. (format "%02s" (number-to-string hour-number)))
  1110. ":" minute ampm)))
  1111. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1112. "Conditionally convert TIME to AM/PM format.
  1113. This is based on `org-agenda-timegrid-use-ampm'."
  1114. (if org-agenda-timegrid-use-ampm
  1115. (org-agenda-time-of-day-to-ampm time)
  1116. time))
  1117. (defcustom org-agenda-weekend-days '(6 0)
  1118. "Which days are weekend?
  1119. These days get the special face `org-agenda-date-weekend' in the agenda."
  1120. :group 'org-agenda-daily/weekly
  1121. :type '(set :greedy t
  1122. (const :tag "Monday" 1)
  1123. (const :tag "Tuesday" 2)
  1124. (const :tag "Wednesday" 3)
  1125. (const :tag "Thursday" 4)
  1126. (const :tag "Friday" 5)
  1127. (const :tag "Saturday" 6)
  1128. (const :tag "Sunday" 0)))
  1129. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1130. "Non-nil means jump to today when moving a past date forward in time.
  1131. When using S-right in the agenda to move a date forward, and the date
  1132. stamp currently points to the past, the first key press will move it
  1133. to today. When nil, just move one day forward even if the date stays
  1134. in the past."
  1135. :group 'org-agenda-daily/weekly
  1136. :version "24.1"
  1137. :type 'boolean)
  1138. (defcustom org-agenda-diary-file 'diary-file
  1139. "File to which to add new entries with the `i' key in agenda and calendar.
  1140. When this is the symbol `diary-file', the functionality in the Emacs
  1141. calendar will be used to add entries to the `diary-file'. But when this
  1142. points to a file, `org-agenda-diary-entry' will be used instead."
  1143. :group 'org-agenda
  1144. :type '(choice
  1145. (const :tag "The standard Emacs diary file" diary-file)
  1146. (file :tag "Special Org file diary entries")))
  1147. (defcustom org-agenda-include-diary nil
  1148. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1149. Custom commands can set this variable in the options section."
  1150. :group 'org-agenda-daily/weekly
  1151. :type 'boolean)
  1152. (defcustom org-agenda-include-deadlines t
  1153. "If non-nil, include entries within their deadline warning period.
  1154. Custom commands can set this variable in the options section."
  1155. :group 'org-agenda-daily/weekly
  1156. :version "24.1"
  1157. :type 'boolean)
  1158. (defcustom org-agenda-show-future-repeats t
  1159. "Non-nil shows repeated entries in the future part of the agenda.
  1160. When set to the symbol `next' only the first future repeat is shown."
  1161. :group 'org-agenda-daily/weekly
  1162. :type '(choice
  1163. (const :tag "Show all repeated entries" t)
  1164. (const :tag "Show next repeated entry" next)
  1165. (const :tag "Do not show repeated entries" nil))
  1166. :version "26.1"
  1167. :package-version '(Org . "9.1")
  1168. :safe #'symbolp)
  1169. (defcustom org-agenda-prefer-last-repeat nil
  1170. "Non-nil sets date for repeated entries to their last repeat.
  1171. When nil, display SCHEDULED and DEADLINE dates at their base
  1172. date, and in today's agenda, as a reminder. Display plain
  1173. time-stamps, on the other hand, at every repeat date in the past
  1174. in addition to the base date.
  1175. When non-nil, show a repeated entry at its latest repeat date,
  1176. possibly being today even if it wasn't marked as done. This
  1177. setting is useful if you do not always mark repeated entries as
  1178. done and, yet, consider that reaching repeat date starts the task
  1179. anew.
  1180. When set to a list of strings, prefer last repeats only for
  1181. entries with these TODO keywords."
  1182. :group 'org-agenda-daily/weekly
  1183. :type '(choice
  1184. (const :tag "Prefer last repeat" t)
  1185. (const :tag "Prefer base date" nil)
  1186. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1187. (string :tag "TODO keyword")))
  1188. :version "26.1"
  1189. :package-version '(Org . "9.1")
  1190. :safe (lambda (x) (or (booleanp x) (consp x))))
  1191. (defcustom org-scheduled-past-days 10000
  1192. "Number of days to continue listing scheduled items not marked DONE.
  1193. When an item is scheduled on a date, it shows up in the agenda on
  1194. this day and will be listed until it is marked done or for the
  1195. number of days given here."
  1196. :group 'org-agenda-daily/weekly
  1197. :type 'integer
  1198. :safe 'integerp)
  1199. (defcustom org-deadline-past-days 10000
  1200. "Number of days to warn about missed deadlines.
  1201. When an item has deadline on a date, it shows up in the agenda on
  1202. this day and will appear as a reminder until it is marked DONE or
  1203. for the number of days given here."
  1204. :group 'org-agenda-daily/weekly
  1205. :type 'integer
  1206. :version "26.1"
  1207. :package-version '(Org . "9.1")
  1208. :safe 'integerp)
  1209. (defcustom org-agenda-log-mode-items '(closed clock)
  1210. "List of items that should be shown in agenda log mode.
  1211. \\<org-agenda-mode-map>\
  1212. This list may contain the following symbols:
  1213. closed Show entries that have been closed on that day.
  1214. clock Show entries that have received clocked time on that day.
  1215. state Show all logged state changes.
  1216. Note that instead of changing this variable, you can also press \
  1217. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1218. the agenda to display all available LOG items temporarily."
  1219. :group 'org-agenda-daily/weekly
  1220. :type '(set :greedy t (const closed) (const clock) (const state)))
  1221. (defcustom org-agenda-clock-consistency-checks
  1222. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1223. :gap-ok-around ("4:00")
  1224. :default-face ((:background "DarkRed") (:foreground "white"))
  1225. :overlap-face nil :gap-face nil :no-end-time-face nil
  1226. :long-face nil :short-face nil)
  1227. "This is a property list, with the following keys:
  1228. :max-duration Mark clocking chunks that are longer than this time.
  1229. This is a time string like \"HH:MM\", or the number
  1230. of minutes as an integer.
  1231. :min-duration Mark clocking chunks that are shorter that this.
  1232. This is a time string like \"HH:MM\", or the number
  1233. of minutes as an integer.
  1234. :max-gap Mark gaps between clocking chunks that are longer than
  1235. this duration. A number of minutes, or a string
  1236. like \"HH:MM\".
  1237. :gap-ok-around List of times during the day which are usually not working
  1238. times. When a gap is detected, but the gap contains any
  1239. of these times, the gap is *not* reported. For example,
  1240. if this is (\"4:00\" \"13:00\") then gaps that contain
  1241. 4:00 in the morning (i.e. the night) and 13:00
  1242. (i.e. a typical lunch time) do not cause a warning.
  1243. You should have at least one time during the night in this
  1244. list, or otherwise the first task each morning will trigger
  1245. a warning because it follows a long gap.
  1246. Furthermore, the following properties can be used to define faces for
  1247. issue display.
  1248. :default-face the default face, if the specific face is undefined
  1249. :overlap-face face for overlapping clocks
  1250. :gap-face face for gaps between clocks
  1251. :no-end-time-face face for incomplete clocks
  1252. :long-face face for clock intervals that are too long
  1253. :short-face face for clock intervals that are too short"
  1254. :group 'org-agenda-daily/weekly
  1255. :group 'org-clock
  1256. :version "24.1"
  1257. :type 'plist)
  1258. (defcustom org-agenda-log-mode-add-notes t
  1259. "Non-nil means add first line of notes to log entries in agenda views.
  1260. If a log item like a state change or a clock entry is associated with
  1261. notes, the first line of these notes will be added to the entry in the
  1262. agenda display."
  1263. :group 'org-agenda-daily/weekly
  1264. :type 'boolean)
  1265. (defcustom org-agenda-start-with-log-mode nil
  1266. "The initial value of log-mode in a newly created agenda window.
  1267. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1268. explanations on the possible values."
  1269. :group 'org-agenda-startup
  1270. :group 'org-agenda-daily/weekly
  1271. :type '(choice (const :tag "Don't show log items" nil)
  1272. (const :tag "Show only log items" only)
  1273. (const :tag "Show all possible log items" clockcheck)
  1274. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1275. (choice (const :tag "Show closed log items" closed)
  1276. (const :tag "Show clocked log items" clock)
  1277. (const :tag "Show all logged state changes" state)))))
  1278. (defcustom org-agenda-start-with-clockreport-mode nil
  1279. "The initial value of clockreport-mode in a newly created agenda window."
  1280. :group 'org-agenda-startup
  1281. :group 'org-agenda-daily/weekly
  1282. :type 'boolean)
  1283. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1284. "Property list with parameters for the clocktable in clockreport mode.
  1285. This is the display mode that shows a clock table in the daily/weekly
  1286. agenda, the properties for this dynamic block can be set here.
  1287. The usual clocktable parameters are allowed here, but you cannot set
  1288. the properties :name, :tstart, :tend, :block, and :scope - these will
  1289. be overwritten to make sure the content accurately reflects the
  1290. current display in the agenda."
  1291. :group 'org-agenda-daily/weekly
  1292. :type 'plist)
  1293. (defvaralias 'org-agenda-search-view-search-words-only
  1294. 'org-agenda-search-view-always-boolean)
  1295. (defcustom org-agenda-search-view-always-boolean nil
  1296. "Non-nil means the search string is interpreted as individual parts.
  1297. The search string for search view can either be interpreted as a phrase,
  1298. or as a list of snippets that define a boolean search for a number of
  1299. strings.
  1300. When this is non-nil, the string will be split on whitespace, and each
  1301. snippet will be searched individually, and all must match in order to
  1302. select an entry. A snippet is then a single string of non-white
  1303. characters, or a string in double quotes, or a regexp in {} braces.
  1304. If a snippet is preceded by \"-\", the snippet must *not* match.
  1305. \"+\" is syntactic sugar for positive selection. Each snippet may
  1306. be found as a full word or a partial word, but see the variable
  1307. `org-agenda-search-view-force-full-words'.
  1308. When this is nil, search will look for the entire search phrase as one,
  1309. with each space character matching any amount of whitespace, including
  1310. line breaks.
  1311. Even when this is nil, you can still switch to Boolean search dynamically
  1312. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1313. is a regexp marked with braces like \"{abc}\", this will also switch to
  1314. boolean search."
  1315. :group 'org-agenda-search-view
  1316. :version "24.1"
  1317. :type 'boolean)
  1318. (defcustom org-agenda-search-view-force-full-words nil
  1319. "Non-nil means, search words must be matches as complete words.
  1320. When nil, they may also match part of a word."
  1321. :group 'org-agenda-search-view
  1322. :version "24.1"
  1323. :type 'boolean)
  1324. (defcustom org-agenda-search-view-max-outline-level 0
  1325. "Maximum outline level to display in search view.
  1326. E.g. when this is set to 1, the search view will only
  1327. show headlines of level 1. When set to 0, the default
  1328. value, don't limit agenda view by outline level."
  1329. :group 'org-agenda-search-view
  1330. :version "26.1"
  1331. :package-version '(Org . "8.3")
  1332. :type 'integer)
  1333. (defgroup org-agenda-time-grid nil
  1334. "Options concerning the time grid in the Org Agenda."
  1335. :tag "Org Agenda Time Grid"
  1336. :group 'org-agenda)
  1337. (defcustom org-agenda-search-headline-for-time t
  1338. "Non-nil means search headline for a time-of-day.
  1339. If the headline contains a time-of-day in one format or another, it will
  1340. be used to sort the entry into the time sequence of items for a day.
  1341. Some people have time stamps in the headline that refer to the creation
  1342. time or so, and then this produces an unwanted side effect. If this is
  1343. the case for your, use this variable to turn off searching the headline
  1344. for a time."
  1345. :group 'org-agenda-time-grid
  1346. :type 'boolean)
  1347. (defcustom org-agenda-use-time-grid t
  1348. "Non-nil means show a time grid in the agenda schedule.
  1349. A time grid is a set of lines for specific times (like every two hours between
  1350. 8:00 and 20:00). The items scheduled for a day at specific times are
  1351. sorted in between these lines.
  1352. For details about when the grid will be shown, and what it will look like, see
  1353. the variable `org-agenda-time-grid'."
  1354. :group 'org-agenda-time-grid
  1355. :type 'boolean)
  1356. (defcustom org-agenda-time-grid
  1357. (let ((graphical (and (display-graphic-p)
  1358. (char-displayable-p ?┄))))
  1359. `((daily today require-timed)
  1360. (800 1000 1200 1400 1600 1800 2000)
  1361. ,(if graphical " ┄┄┄┄┄ " "......")
  1362. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1363. "The settings for time grid for agenda display.
  1364. This is a list of four items. The first item is again a list. It contains
  1365. symbols specifying conditions when the grid should be displayed:
  1366. daily if the agenda shows a single day
  1367. weekly if the agenda shows an entire week
  1368. today show grid on current date, independent of daily/weekly display
  1369. require-timed show grid only if at least one item has a time specification
  1370. remove-match skip grid times already present in an entry
  1371. The second item is a list of integers, indicating the times that
  1372. should have a grid line.
  1373. The third item is a string which will be placed right after the
  1374. times that have a grid line.
  1375. The fourth item is a string placed after the grid times. This
  1376. will align with agenda items."
  1377. :group 'org-agenda-time-grid
  1378. :version "29.1"
  1379. :type
  1380. '(list
  1381. (set :greedy t :tag "Grid Display Options"
  1382. (const :tag "Show grid in single day agenda display" daily)
  1383. (const :tag "Show grid in weekly agenda display" weekly)
  1384. (const :tag "Always show grid for today" today)
  1385. (const :tag "Show grid only if any timed entries are present"
  1386. require-timed)
  1387. (const :tag "Skip grid times already present in an entry"
  1388. remove-match))
  1389. (repeat :tag "Grid Times" (integer :tag "Time"))
  1390. (string :tag "Grid String (after agenda times)")
  1391. (string :tag "Grid String (aligns with agenda items)")))
  1392. (defcustom org-agenda-show-current-time-in-grid t
  1393. "Non-nil means show the current time in the time grid."
  1394. :group 'org-agenda-time-grid
  1395. :version "24.1"
  1396. :type 'boolean)
  1397. (defcustom org-agenda-current-time-string
  1398. (if (and (display-graphic-p)
  1399. (char-displayable-p ?⭠)
  1400. (char-displayable-p ?─))
  1401. "⭠ now ───────────────────────────────────────────────"
  1402. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1403. "The string for the current time marker in the agenda."
  1404. :group 'org-agenda-time-grid
  1405. :version "29.1"
  1406. :type 'string)
  1407. (defgroup org-agenda-sorting nil
  1408. "Options concerning sorting in the Org Agenda."
  1409. :tag "Org Agenda Sorting"
  1410. :group 'org-agenda)
  1411. (defcustom org-agenda-sorting-strategy
  1412. '((agenda habit-down time-up priority-down category-keep)
  1413. (todo priority-down category-keep)
  1414. (tags priority-down category-keep)
  1415. (search category-keep))
  1416. "Sorting structure for the agenda items of a single day.
  1417. This is a list of symbols which will be used in sequence to determine
  1418. if an entry should be listed before another entry. The following
  1419. symbols are recognized:
  1420. time-up Put entries with time-of-day indications first, early first.
  1421. time-down Put entries with time-of-day indications first, late first.
  1422. timestamp-up Sort by any timestamp, early first.
  1423. timestamp-down Sort by any timestamp, late first.
  1424. scheduled-up Sort by scheduled timestamp, early first.
  1425. scheduled-down Sort by scheduled timestamp, late first.
  1426. deadline-up Sort by deadline timestamp, early first.
  1427. deadline-down Sort by deadline timestamp, late first.
  1428. ts-up Sort by active timestamp, early first.
  1429. ts-down Sort by active timestamp, late first.
  1430. tsia-up Sort by inactive timestamp, early first.
  1431. tsia-down Sort by inactive timestamp, late first.
  1432. category-keep Keep the default order of categories, corresponding to the
  1433. sequence in `org-agenda-files'.
  1434. category-up Sort alphabetically by category, A-Z.
  1435. category-down Sort alphabetically by category, Z-A.
  1436. tag-up Sort alphabetically by last tag, A-Z.
  1437. tag-down Sort alphabetically by last tag, Z-A.
  1438. priority-up Sort numerically by priority, high priority last.
  1439. priority-down Sort numerically by priority, high priority first.
  1440. todo-state-up Sort by todo state, tasks that are done last.
  1441. todo-state-down Sort by todo state, tasks that are done first.
  1442. effort-up Sort numerically by estimated effort, high effort last.
  1443. effort-down Sort numerically by estimated effort, high effort first.
  1444. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1445. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1446. habit-up Put entries that are habits first.
  1447. habit-down Put entries that are habits last.
  1448. alpha-up Sort headlines alphabetically.
  1449. alpha-down Sort headlines alphabetically, reversed.
  1450. The different possibilities will be tried in sequence, and testing stops
  1451. if one comparison returns a \"not-equal\". For example, the default
  1452. \\='(time-up category-keep priority-down)
  1453. means: Pull out all entries having a specified time of day and sort them,
  1454. in order to make a time schedule for the current day the first thing in the
  1455. agenda listing for the day. Of the entries without a time indication, keep
  1456. the grouped in categories, don't sort the categories, but keep them in
  1457. the sequence given in `org-agenda-files'. Within each category sort by
  1458. priority.
  1459. Leaving out `category-keep' would mean that items will be sorted across
  1460. categories by priority.
  1461. Instead of a single list, this can also be a set of list for specific
  1462. contents, with a context symbol in the car of the list, any of
  1463. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1464. Custom commands can bind this variable in the options section."
  1465. :group 'org-agenda-sorting
  1466. :type `(choice
  1467. (repeat :tag "General" ,org-sorting-choice)
  1468. (list :tag "Individually"
  1469. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1470. (repeat ,org-sorting-choice))
  1471. (cons (const :tag "Strategy for TODO lists" todo)
  1472. (repeat ,org-sorting-choice))
  1473. (cons (const :tag "Strategy for Tags matches" tags)
  1474. (repeat ,org-sorting-choice))
  1475. (cons (const :tag "Strategy for search matches" search)
  1476. (repeat ,org-sorting-choice)))))
  1477. (defcustom org-agenda-cmp-user-defined nil
  1478. "A function to define the comparison `user-defined'.
  1479. This function must receive two arguments, agenda entry a and b.
  1480. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1481. the user comparison, return nil.
  1482. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1483. part of an agenda sorting strategy."
  1484. :group 'org-agenda-sorting
  1485. :type 'symbol)
  1486. (defcustom org-agenda-sort-notime-is-late t
  1487. "Non-nil means items without time are considered late.
  1488. This is only relevant for sorting. When t, items which have no explicit
  1489. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1490. do have a time. When nil, the default time is before 0:00. You can use this
  1491. option to decide if the schedule for today should come before or after timeless
  1492. agenda entries."
  1493. :group 'org-agenda-sorting
  1494. :type 'boolean)
  1495. (defcustom org-agenda-sort-noeffort-is-high t
  1496. "Non-nil means items without effort estimate are sorted as high effort.
  1497. This also applies when filtering an agenda view with respect to the
  1498. < or > effort operator. Then, tasks with no effort defined will be treated
  1499. as tasks with high effort.
  1500. When nil, such items are sorted as 0 minutes effort."
  1501. :group 'org-agenda-sorting
  1502. :type 'boolean)
  1503. (defgroup org-agenda-line-format nil
  1504. "Options concerning the entry prefix in the Org agenda display."
  1505. :tag "Org Agenda Line Format"
  1506. :group 'org-agenda)
  1507. (defcustom org-agenda-prefix-format
  1508. '((agenda . " %i %-12:c%?-12t% s")
  1509. (todo . " %i %-12:c")
  1510. (tags . " %i %-12:c")
  1511. (search . " %i %-12:c"))
  1512. "Format specifications for the prefix of items in the agenda views.
  1513. An alist with one entry per agenda type. The keys of the
  1514. sublists are `agenda', `todo', `search' and `tags'. The values
  1515. are format strings.
  1516. This format works similar to a printf format, with the following meaning:
  1517. %c the category of the item, \"Diary\" for entries from the diary,
  1518. or as given by the CATEGORY keyword or derived from the file name
  1519. %e the effort required by the item
  1520. %l the level of the item (insert X space(s) if item is of level X)
  1521. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1522. %T the last tag of the item (ignore inherited tags, which come first)
  1523. %t the HH:MM time-of-day specification if one applies to the entry
  1524. %s Scheduling/Deadline information, a short string
  1525. %b show breadcrumbs, i.e., the names of the higher levels
  1526. %(expression) Eval EXPRESSION and replace the control string
  1527. by the result
  1528. All specifiers work basically like the standard `%s' of printf, but may
  1529. contain two additional characters: a question mark just after the `%'
  1530. and a whitespace/punctuation character just before the final letter.
  1531. If the first character after `%' is a question mark, the entire field
  1532. will only be included if the corresponding value applies to the current
  1533. entry. This is useful for fields which should have fixed width when
  1534. present, but zero width when absent. For example, \"%?-12t\" will
  1535. result in a 12 character time field if a time of the day is specified,
  1536. but will completely disappear in entries which do not contain a time.
  1537. If there is punctuation or whitespace character just before the
  1538. final format letter, this character will be appended to the field
  1539. value if the value is not empty. For example, the format
  1540. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1541. the category is empty, no additional colon is inserted.
  1542. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1543. which means:
  1544. - Indent the line with two space characters
  1545. - Give the category a 12 chars wide field, padded with whitespace on
  1546. the right (because of `-'). Append a colon if there is a category
  1547. (because of `:').
  1548. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1549. time, don't put in an empty field, just skip it (because of '?').
  1550. - Finally, put the scheduling information.
  1551. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1552. `org-agenda-remove-tags'.
  1553. Custom commands can set this variable in the options section."
  1554. :type '(choice
  1555. (string :tag "General format")
  1556. (list :greedy t :tag "View dependent"
  1557. (cons (const agenda) (string :tag "Format"))
  1558. (cons (const todo) (string :tag "Format"))
  1559. (cons (const tags) (string :tag "Format"))
  1560. (cons (const search) (string :tag "Format"))))
  1561. :group 'org-agenda-line-format
  1562. :version "26.1"
  1563. :package-version '(Org . "9.1"))
  1564. (defcustom org-agenda-breadcrumbs-separator "->"
  1565. "The separator of breadcrumbs in agenda lines."
  1566. :group 'org-agenda-line-format
  1567. :package-version '(Org . "9.3")
  1568. :type 'string
  1569. :safe #'stringp)
  1570. (defvar org-prefix-format-compiled nil
  1571. "The compiled prefix format and associated variables.
  1572. This is a list where first element is a list of variable bindings, and second
  1573. element is the compiled format expression. See the variable
  1574. `org-agenda-prefix-format'.")
  1575. (defcustom org-agenda-todo-keyword-format "%-1s"
  1576. "Format for the TODO keyword in agenda lines.
  1577. Set this to something like \"%-12s\" if you want all TODO keywords
  1578. to occupy a fixed space in the agenda display."
  1579. :group 'org-agenda-line-format
  1580. :type 'string)
  1581. (defcustom org-agenda-diary-sexp-prefix nil
  1582. "A regexp that matches part of a diary sexp entry
  1583. which should be treated as scheduling/deadline information in
  1584. `org-agenda'.
  1585. For example, you can use this to extract the `diary-remind-message' from
  1586. `diary-remind' entries."
  1587. :group 'org-agenda-line-format
  1588. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1589. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1590. "Text preceding timerange entries in the agenda view.
  1591. This is a list with two strings. The first applies when the range
  1592. is entirely on one day. The second applies if the range spans several days.
  1593. The strings may have two \"%d\" format specifiers which will be filled
  1594. with the sequence number of the days, and the total number of days in the
  1595. range, respectively."
  1596. :group 'org-agenda-line-format
  1597. :type '(list
  1598. (string :tag "Deadline today ")
  1599. (choice :tag "Deadline relative"
  1600. (string :tag "Format string")
  1601. (function))))
  1602. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1603. "Text preceding scheduled items in the agenda view.
  1604. This is a list with two strings. The first applies when the item is
  1605. scheduled on the current day. The second applies when it has been scheduled
  1606. previously, it may contain a %d indicating that this is the nth time that
  1607. this item is scheduled, due to automatic rescheduling of unfinished items
  1608. for the following day. So this number is one larger than the number of days
  1609. that passed since this item was scheduled first."
  1610. :group 'org-agenda-line-format
  1611. :version "24.4"
  1612. :package-version '(Org . "8.0")
  1613. :type '(list
  1614. (string :tag "Scheduled today ")
  1615. (string :tag "Scheduled previously")))
  1616. (defcustom org-agenda-inactive-leader "["
  1617. "Text preceding item pulled into the agenda by inactive time stamps.
  1618. These entries are added to the agenda when pressing \"[\"."
  1619. :group 'org-agenda-line-format
  1620. :version "24.1"
  1621. :type 'string)
  1622. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1623. "Text preceding deadline items in the agenda view.
  1624. This is a list with three strings. The first applies when the item has its
  1625. deadline on the current day. The second applies when the deadline is in the
  1626. future, the third one when it is in the past. The strings may contain %d
  1627. to capture the number of days."
  1628. :group 'org-agenda-line-format
  1629. :version "24.4"
  1630. :package-version '(Org . "8.0")
  1631. :type '(list
  1632. (string :tag "Deadline today ")
  1633. (string :tag "Deadline in the future ")
  1634. (string :tag "Deadline in the past ")))
  1635. (defcustom org-agenda-remove-times-when-in-prefix t
  1636. "Non-nil means remove duplicate time specifications in agenda items.
  1637. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1638. time-of-day specification in a headline or diary entry is extracted and
  1639. placed into the prefix. If this option is non-nil, the original specification
  1640. \(a timestamp or -range, or just a plain time(range) specification like
  1641. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1642. cluttered.
  1643. The option can be t or nil. It may also be the symbol `beg', indicating
  1644. that the time should only be removed when it is located at the beginning of
  1645. the headline/diary entry."
  1646. :group 'org-agenda-line-format
  1647. :type '(choice
  1648. (const :tag "Always" t)
  1649. (const :tag "Never" nil)
  1650. (const :tag "When at beginning of entry" beg)))
  1651. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1652. "Non-nil means remove time ranges specifications in agenda
  1653. items that span on several days."
  1654. :group 'org-agenda-line-format
  1655. :version "24.1"
  1656. :type 'boolean)
  1657. (defcustom org-agenda-default-appointment-duration nil
  1658. "Default duration for appointments that only have a starting time.
  1659. When nil, no duration is specified in such cases.
  1660. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1661. :group 'org-agenda-line-format
  1662. :type '(choice
  1663. (integer :tag "Minutes")
  1664. (const :tag "No default duration")))
  1665. (defcustom org-agenda-show-inherited-tags t
  1666. "Non-nil means show inherited tags in each agenda line.
  1667. When this option is set to `always', it takes precedence over
  1668. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1669. in every agenda.
  1670. When this option is set to t (the default), inherited tags are
  1671. shown when they are available, i.e. when the value of
  1672. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1673. given agenda type.
  1674. This can be set to a list of agenda types in which the agenda
  1675. must display the inherited tags. Available types are `todo',
  1676. `agenda' and `search'.
  1677. When set to nil, never show inherited tags in agenda lines."
  1678. :group 'org-agenda-line-format
  1679. :group 'org-agenda
  1680. :version "24.3"
  1681. :type '(choice
  1682. (const :tag "Show inherited tags when available" t)
  1683. (const :tag "Always show inherited tags" always)
  1684. (repeat :tag "Show inherited tags only in selected agenda types"
  1685. (symbol :tag "Agenda type"))))
  1686. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1687. "List of agenda view types where to use tag inheritance.
  1688. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1689. controlled by `org-use-tag-inheritance'. In other agenda types,
  1690. `org-use-tag-inheritance' is not used for the selection of the
  1691. agenda entries. Still, you may want the agenda to be aware of
  1692. the inherited tags anyway, e.g. for later tag filtering.
  1693. Allowed value are `todo', `search' and `agenda'.
  1694. This variable has no effect if `org-agenda-show-inherited-tags'
  1695. is set to `always'. In that case, the agenda is aware of those
  1696. tags.
  1697. The default value sets tags in every agenda type. Setting this
  1698. option to nil will speed up non-tags agenda view a lot."
  1699. :group 'org-agenda
  1700. :version "26.1"
  1701. :package-version '(Org . "9.1")
  1702. :type '(choice
  1703. (const :tag "Use tag inheritance in all agenda types" t)
  1704. (repeat :tag "Use tag inheritance in selected agenda types"
  1705. (symbol :tag "Agenda type"))))
  1706. (defcustom org-agenda-hide-tags-regexp nil
  1707. "Regular expression used to filter away specific tags in agenda views.
  1708. This means that these tags will be present, but not be shown in the agenda
  1709. line. Secondary filtering will still work on the hidden tags.
  1710. Nil means don't hide any tags."
  1711. :group 'org-agenda-line-format
  1712. :type '(choice
  1713. (const :tag "Hide none" nil)
  1714. (regexp :tag "Regexp ")))
  1715. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1716. 'org-agenda-remove-tags)
  1717. (defcustom org-agenda-remove-tags nil
  1718. "Non-nil means remove the tags from the headline copy in the agenda.
  1719. When this is the symbol `prefix', only remove tags when
  1720. `org-agenda-prefix-format' contains a `%T' specifier."
  1721. :group 'org-agenda-line-format
  1722. :type '(choice
  1723. (const :tag "Always" t)
  1724. (const :tag "Never" nil)
  1725. (const :tag "When prefix format contains %T" prefix)))
  1726. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1727. (defcustom org-agenda-tags-column 'auto
  1728. "Shift tags in agenda items to this column.
  1729. If set to `auto', tags will be automatically aligned to the right
  1730. edge of the window.
  1731. If set to a positive number, tags will be left-aligned to that
  1732. column. If set to a negative number, tags will be right-aligned
  1733. to that column. For example, -80 works well for a normal 80
  1734. character screen."
  1735. :group 'org-agenda-line-format
  1736. :type '(choice
  1737. (const :tag "Automatically align to right edge of window" auto)
  1738. (integer :tag "Specific column" -80))
  1739. :package-version '(Org . "9.1")
  1740. :version "26.1")
  1741. (defcustom org-agenda-fontify-priorities 'cookies
  1742. "Non-nil means highlight low and high priorities in agenda.
  1743. When t, the highest priority entries are bold, lowest priority italic.
  1744. However, settings in `org-priority-faces' will overrule these faces.
  1745. When this variable is the symbol `cookies', only fontify the
  1746. cookies, not the entire task.
  1747. This may also be an association list of priority faces, whose
  1748. keys are the character values of `org-priority-highest',
  1749. `org-priority-default', and `org-priority-lowest' (the default values
  1750. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1751. color as a string, or a list like `(:background \"Red\")'.
  1752. If it is a color, the variable `org-faces-easy-properties'
  1753. determines if it is a foreground or a background color."
  1754. :group 'org-agenda-line-format
  1755. :type '(choice
  1756. (const :tag "Never" nil)
  1757. (const :tag "Defaults" t)
  1758. (const :tag "Cookies only" cookies)
  1759. (repeat :tag "Specify"
  1760. (list (character :tag "Priority" :value ?A)
  1761. (choice :tag "Face "
  1762. (string :tag "Color")
  1763. (sexp :tag "Face"))))))
  1764. (defcustom org-agenda-day-face-function nil
  1765. "Function called to determine what face should be used to display a day.
  1766. The only argument passed to that function is the day. It should
  1767. returns a face, or nil if does not want to specify a face and let
  1768. the normal rules apply."
  1769. :group 'org-agenda-line-format
  1770. :version "24.1"
  1771. :type '(choice (const nil) (function)))
  1772. (defcustom org-agenda-category-icon-alist nil
  1773. "Alist of category icon to be displayed in agenda views.
  1774. Each entry should have the following format:
  1775. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1776. Where CATEGORY-REGEXP is a regexp matching the categories where
  1777. the icon should be displayed.
  1778. FILE-OR-DATA either a file path or a string containing image data.
  1779. The other fields can be omitted safely if not needed:
  1780. TYPE indicates the image type.
  1781. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1782. image data.
  1783. PROPS are additional image attributes to assign to the image,
  1784. like, e.g. `:ascent center'.
  1785. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1786. If you want to set the display properties yourself, just put a
  1787. list as second element:
  1788. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1789. For example, to display a 16px horizontal space for Emacs
  1790. category, you can use:
  1791. (\"Emacs\" \\='(space . (:width (16))))"
  1792. :group 'org-agenda-line-format
  1793. :version "24.1"
  1794. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1795. :value-type (choice (list :tag "Icon"
  1796. (string :tag "File or data")
  1797. (symbol :tag "Type")
  1798. (boolean :tag "Data?")
  1799. (repeat :tag "Extra image properties" :inline t sexp))
  1800. (list :tag "Display properties" sexp))))
  1801. (defgroup org-agenda-column-view nil
  1802. "Options concerning column view in the agenda."
  1803. :tag "Org Agenda Column View"
  1804. :group 'org-agenda)
  1805. (defcustom org-agenda-view-columns-initially nil
  1806. "When non-nil, switch to columns view right after creating the agenda."
  1807. :group 'org-agenda-column-view
  1808. :type 'boolean
  1809. :version "26.1"
  1810. :package-version '(Org . "9.0")
  1811. :safe #'booleanp)
  1812. (defcustom org-agenda-columns-show-summaries t
  1813. "Non-nil means show summaries for columns displayed in the agenda view."
  1814. :group 'org-agenda-column-view
  1815. :type 'boolean)
  1816. (defcustom org-agenda-columns-compute-summary-properties t
  1817. "Non-nil means recompute all summary properties before column view.
  1818. When column view in the agenda is listing properties that have a summary
  1819. operator, it can go to all relevant buffers and recompute the summaries
  1820. there. This can mean overhead for the agenda column view, but is necessary
  1821. to have thing up to date.
  1822. As a special case, a CLOCKSUM property also makes sure that the clock
  1823. computations are current."
  1824. :group 'org-agenda-column-view
  1825. :type 'boolean)
  1826. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1827. "Non-nil means the duration of an appointment will add to day effort.
  1828. The property to which appointment durations will be added is the one given
  1829. in the option `org-effort-property'. If an appointment does not have
  1830. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1831. is not set, an appointment without end time will not contribute to the time
  1832. estimate."
  1833. :group 'org-agenda-column-view
  1834. :type 'boolean)
  1835. (defcustom org-agenda-auto-exclude-function nil
  1836. "A function called with a tag to decide if it is filtered on \
  1837. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1838. The sole argument to the function, which is called once for each
  1839. possible tag, is a string giving the name of the tag. The
  1840. function should return either nil if the tag should be included
  1841. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1842. lines not carrying this tag.
  1843. Note that for the purpose of tag filtering, only the lower-case version of
  1844. all tags will be considered, so that this function will only ever see
  1845. the lower-case version of all tags."
  1846. :group 'org-agenda
  1847. :type '(choice (const nil) (function)))
  1848. (defcustom org-agenda-bulk-custom-functions nil
  1849. "Alist of characters and custom functions for bulk actions.
  1850. For example, this value makes those two functions available:
  1851. \\='((?R set-category)
  1852. (?C bulk-cut))
  1853. With selected entries in an agenda buffer, `B R' will call
  1854. the custom function `set-category' on the selected entries.
  1855. Note that functions in this alist don't need to be quoted.
  1856. You can also specify a function which collects arguments to be
  1857. used for each call to your bulk custom function. The argument
  1858. collecting function will be run once and should return a list of
  1859. arguments to pass to the bulk function. For example:
  1860. \\='((?R set-category get-category))
  1861. Now, `B R' will call the custom `get-category' which would prompt
  1862. the user once for a category. That category is then passed as an
  1863. argument to `set-category' for each entry it's called against."
  1864. :type
  1865. '(alist :key-type character
  1866. :value-type
  1867. (group (function :tag "Bulk Custom Function")
  1868. (choice (function :tag "Bulk Custom Argument Function")
  1869. (const :tag "No Bulk Custom Argument Function" nil))))
  1870. :package-version '(Org . "9.5")
  1871. :group 'org-agenda)
  1872. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1873. "Execute BODY with point at location given by `org-hd-marker' property.
  1874. If STRING is non-nil, the text property will be fetched from position 0
  1875. in that string. If STRING is nil, it will be fetched from the beginning
  1876. of the current line."
  1877. (declare (debug t) (indent 1))
  1878. (org-with-gensyms (marker)
  1879. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1880. 'org-hd-marker ,string)))
  1881. (with-current-buffer (marker-buffer ,marker)
  1882. (save-excursion
  1883. (goto-char ,marker)
  1884. ,@body)))))
  1885. (defun org-add-agenda-custom-command (entry)
  1886. "Replace or add a command in `org-agenda-custom-commands'.
  1887. This is mostly for hacking and trying a new command - once the command
  1888. works you probably want to add it to `org-agenda-custom-commands' for good."
  1889. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1890. (if ass
  1891. (setcdr ass (cdr entry))
  1892. (push entry org-agenda-custom-commands))))
  1893. (defmacro org-agenda--insert-overriding-header (default)
  1894. "Insert header into agenda view.
  1895. The inserted header depends on `org-agenda-overriding-header'.
  1896. If the empty string, don't insert a header. If any other string,
  1897. insert it as a header. If nil, insert DEFAULT, which should
  1898. evaluate to a string. If a function, call it and insert the
  1899. string that it returns."
  1900. (declare (debug (form)) (indent defun))
  1901. `(cond
  1902. ((not org-agenda-overriding-header) (insert ,default))
  1903. ((equal org-agenda-overriding-header "") nil)
  1904. ((stringp org-agenda-overriding-header)
  1905. (insert (propertize org-agenda-overriding-header
  1906. 'face 'org-agenda-structure)
  1907. "\n"))
  1908. ((functionp org-agenda-overriding-header)
  1909. (insert (funcall org-agenda-overriding-header)))
  1910. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1911. org-agenda-overriding-header))))
  1912. ;;; Define the org-agenda-mode
  1913. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1914. (defvar org-agenda-mode-map (make-sparse-keymap)
  1915. "Keymap for `org-agenda-mode'.")
  1916. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1917. (defvar org-agenda-menu) ; defined later in this file.
  1918. (defvar org-agenda-restrict nil)
  1919. (defvar org-agenda-follow-mode nil)
  1920. (defvar org-agenda-entry-text-mode nil)
  1921. (defvar org-agenda-clockreport-mode nil)
  1922. (defvar org-agenda-show-log nil
  1923. "When non-nil, show the log in the agenda.
  1924. Do not set this directly; instead use
  1925. `org-agenda-start-with-log-mode', which see.")
  1926. (defvar org-agenda-redo-command nil)
  1927. (defvar org-agenda-query-string nil)
  1928. (defvar org-agenda-mode-hook nil
  1929. "Hook run after `org-agenda-mode' is turned on.
  1930. The buffer is still writable when this hook is called.")
  1931. (defvar org-agenda-type nil)
  1932. (defvar org-agenda-force-single-file nil)
  1933. (defvar org-agenda-bulk-marked-entries nil
  1934. "List of markers that refer to marked entries in the agenda.")
  1935. (defvar org-agenda-current-date nil
  1936. "Active date when building the agenda.")
  1937. ;;; Multiple agenda buffers support
  1938. (defcustom org-agenda-sticky nil
  1939. "Non-nil means agenda q key will bury agenda buffers.
  1940. Agenda commands will then show existing buffer instead of generating new ones.
  1941. When nil, `q' will kill the single agenda buffer."
  1942. :group 'org-agenda
  1943. :version "24.3"
  1944. :type 'boolean)
  1945. ;;;###autoload
  1946. (defun org-toggle-sticky-agenda (&optional arg)
  1947. "Toggle `org-agenda-sticky'."
  1948. (interactive "P")
  1949. (let ((new-value (if arg
  1950. (> (prefix-numeric-value arg) 0)
  1951. (not org-agenda-sticky))))
  1952. (if (equal new-value org-agenda-sticky)
  1953. (and (called-interactively-p 'interactive)
  1954. (message "Sticky agenda was already %s"
  1955. (if org-agenda-sticky "enabled" "disabled")))
  1956. (setq org-agenda-sticky new-value)
  1957. (org-agenda-kill-all-agenda-buffers)
  1958. (and (called-interactively-p 'interactive)
  1959. (message "Sticky agenda %s"
  1960. (if org-agenda-sticky "enabled" "disabled"))))))
  1961. (defvar org-agenda-buffer nil
  1962. "Agenda buffer currently being generated.")
  1963. (defvar org-agenda-last-prefix-arg nil)
  1964. (defvar org-agenda-this-buffer-name nil)
  1965. (defvar org-agenda-doing-sticky-redo nil)
  1966. (defvar org-agenda-this-buffer-is-sticky nil)
  1967. (defvar org-agenda-last-indirect-buffer nil
  1968. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1969. (defconst org-agenda-local-vars
  1970. '(org-agenda-this-buffer-name
  1971. org-agenda-undo-list
  1972. org-agenda-pending-undo-list
  1973. org-agenda-follow-mode
  1974. org-agenda-entry-text-mode
  1975. org-agenda-clockreport-mode
  1976. org-agenda-show-log
  1977. org-agenda-redo-command
  1978. org-agenda-query-string
  1979. org-agenda-type
  1980. org-agenda-bulk-marked-entries
  1981. org-agenda-undo-has-started-in
  1982. org-agenda-info
  1983. org-agenda-pre-window-conf
  1984. org-agenda-columns-active
  1985. org-agenda-tag-filter
  1986. org-agenda-category-filter
  1987. org-agenda-top-headline-filter
  1988. org-agenda-regexp-filter
  1989. org-agenda-effort-filter
  1990. org-agenda-markers
  1991. org-agenda-last-search-view-search-was-boolean
  1992. org-agenda-last-indirect-buffer
  1993. org-agenda-filtered-by-category
  1994. org-agenda-filter-form
  1995. org-agenda-cycle-counter
  1996. org-agenda-last-prefix-arg)
  1997. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1998. (defun org-agenda-mode ()
  1999. "Mode for time-sorted view on action items in Org files.
  2000. The following commands are available:
  2001. \\{org-agenda-mode-map}"
  2002. (interactive)
  2003. (ignore-errors (require 'face-remap))
  2004. (let ((agenda-local-vars-to-keep
  2005. '(text-scale-mode-amount
  2006. text-scale-mode
  2007. text-scale-mode-lighter
  2008. face-remapping-alist))
  2009. (save (buffer-local-variables)))
  2010. (kill-all-local-variables)
  2011. (cl-flet ((reset-saved (var-set)
  2012. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2013. (dolist (elem save)
  2014. (pcase elem
  2015. (`(,var . ,val) ;ignore unbound variables
  2016. (when (and val (memq var var-set))
  2017. (set var val)))))))
  2018. (cond (org-agenda-doing-sticky-redo
  2019. ;; Refreshing sticky agenda-buffer
  2020. ;;
  2021. ;; Preserve the value of `org-agenda-local-vars' variables.
  2022. (mapc #'make-local-variable org-agenda-local-vars)
  2023. (reset-saved org-agenda-local-vars)
  2024. (setq-local org-agenda-this-buffer-is-sticky t))
  2025. (org-agenda-sticky
  2026. ;; Creating a sticky Agenda buffer for the first time
  2027. (mapc #'make-local-variable org-agenda-local-vars)
  2028. (setq-local org-agenda-this-buffer-is-sticky t))
  2029. (t
  2030. ;; Creating a non-sticky agenda buffer
  2031. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2032. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2033. (reset-saved agenda-local-vars-to-keep)))
  2034. (setq org-agenda-undo-list nil
  2035. org-agenda-pending-undo-list nil
  2036. org-agenda-bulk-marked-entries nil)
  2037. (setq major-mode 'org-agenda-mode)
  2038. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2039. (setq-local font-lock-global-modes (list 'not major-mode))
  2040. (setq mode-name "Org-Agenda")
  2041. (setq indent-tabs-mode nil)
  2042. (use-local-map org-agenda-mode-map)
  2043. (when org-startup-truncated (setq truncate-lines t))
  2044. (setq-local line-move-visual nil)
  2045. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2046. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2047. ;; Make sure properties are removed when copying text
  2048. (if (boundp 'filter-buffer-substring-functions)
  2049. (add-hook 'filter-buffer-substring-functions
  2050. (lambda (fun start end delete)
  2051. (substring-no-properties (funcall fun start end delete)))
  2052. nil t)
  2053. ;; Emacs >= 24.4.
  2054. (add-function :filter-return (local 'filter-buffer-substring-function)
  2055. #'substring-no-properties))
  2056. (unless org-agenda-keep-modes
  2057. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2058. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2059. org-agenda-show-log org-agenda-start-with-log-mode
  2060. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2061. (add-to-invisibility-spec '(org-filtered))
  2062. (org-fold-core-initialize `(,org-link--description-folding-spec
  2063. ,org-link--link-folding-spec))
  2064. (easy-menu-change
  2065. '("Agenda") "Agenda Files"
  2066. (append
  2067. (list
  2068. (vector
  2069. (if (get 'org-agenda-files 'org-restrict)
  2070. "Restricted to single file"
  2071. "Edit File List")
  2072. '(org-edit-agenda-file-list)
  2073. (not (get 'org-agenda-files 'org-restrict)))
  2074. "--")
  2075. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2076. (org-agenda-set-mode-name)
  2077. (run-mode-hooks 'org-agenda-mode-hook))
  2078. (substitute-key-definition #'undo #'org-agenda-undo
  2079. org-agenda-mode-map global-map)
  2080. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2081. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2082. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2083. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2085. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2086. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2087. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2088. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2089. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2090. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2091. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2092. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2093. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2094. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2095. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2096. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2097. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2099. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2100. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2101. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2103. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2104. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2105. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2106. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2107. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2108. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2109. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2110. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2111. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2112. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2113. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2114. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2115. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2116. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2117. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2119. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2120. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2121. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2122. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2123. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2125. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2126. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2127. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2128. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2129. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2130. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2131. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2132. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2133. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2134. (while l (org-defkey org-agenda-mode-map
  2135. (number-to-string (pop l)) #'digit-argument)))
  2136. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2137. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2138. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2139. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2140. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2141. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2142. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2143. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2144. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2145. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2146. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2147. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2148. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2149. #'org-clock-modify-effort-estimate)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2151. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2152. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2153. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2154. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2155. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2156. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2157. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2158. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2159. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2160. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2161. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2162. (substitute-key-definition #'next-line #'org-agenda-next-line
  2163. org-agenda-mode-map global-map)
  2164. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2165. org-agenda-mode-map global-map)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2167. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2168. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2169. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2170. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2171. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2172. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2173. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2174. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2175. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2176. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2177. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2178. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2179. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2180. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2181. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2182. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2183. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2185. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2186. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2187. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2188. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2189. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2190. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2191. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2192. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2193. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2194. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2195. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2196. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2197. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2198. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2199. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2200. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2201. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2202. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2203. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2204. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2205. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2206. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2207. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2208. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2209. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2210. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2211. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2212. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2213. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2214. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2215. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2216. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2217. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2218. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2219. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2220. (when org-agenda-mouse-1-follows-link
  2221. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2222. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2223. '("Agenda"
  2224. ("Agenda Files")
  2225. "--"
  2226. ("Agenda Dates"
  2227. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2228. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2229. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2230. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2231. "--"
  2232. ("View"
  2233. ["Day View" org-agenda-day-view
  2234. :active (org-agenda-check-type nil 'agenda)
  2235. :style radio :selected (eq org-agenda-current-span 'day)
  2236. :keys "v d (or just d)"]
  2237. ["Week View" org-agenda-week-view
  2238. :active (org-agenda-check-type nil 'agenda)
  2239. :style radio :selected (eq org-agenda-current-span 'week)
  2240. :keys "v w"]
  2241. ["Fortnight View" org-agenda-fortnight-view
  2242. :active (org-agenda-check-type nil 'agenda)
  2243. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2244. :keys "v t"]
  2245. ["Month View" org-agenda-month-view
  2246. :active (org-agenda-check-type nil 'agenda)
  2247. :style radio :selected (eq org-agenda-current-span 'month)
  2248. :keys "v m"]
  2249. ["Year View" org-agenda-year-view
  2250. :active (org-agenda-check-type nil 'agenda)
  2251. :style radio :selected (eq org-agenda-current-span 'year)
  2252. :keys "v y"]
  2253. "--"
  2254. ["Include Diary" org-agenda-toggle-diary
  2255. :style toggle :selected org-agenda-include-diary
  2256. :active (org-agenda-check-type nil 'agenda)]
  2257. ["Include Deadlines" org-agenda-toggle-deadlines
  2258. :style toggle :selected org-agenda-include-deadlines
  2259. :active (org-agenda-check-type nil 'agenda)]
  2260. ["Use Time Grid" org-agenda-toggle-time-grid
  2261. :style toggle :selected org-agenda-use-time-grid
  2262. :active (org-agenda-check-type nil 'agenda)]
  2263. "--"
  2264. ["Show clock report" org-agenda-clockreport-mode
  2265. :style toggle :selected org-agenda-clockreport-mode
  2266. :active (org-agenda-check-type nil 'agenda)]
  2267. ["Show some entry text" org-agenda-entry-text-mode
  2268. :style toggle :selected org-agenda-entry-text-mode
  2269. :active t]
  2270. "--"
  2271. ["Show Logbook entries" org-agenda-log-mode
  2272. :style toggle :selected org-agenda-show-log
  2273. :active (org-agenda-check-type nil 'agenda)
  2274. :keys "v l (or just l)"]
  2275. ["Include archived trees" org-agenda-archives-mode
  2276. :style toggle :selected org-agenda-archives-mode :active t
  2277. :keys "v a"]
  2278. ["Include archive files" (org-agenda-archives-mode t)
  2279. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2280. :keys "v A"]
  2281. "--"
  2282. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2283. ("Filter current view"
  2284. ["with generic interface" org-agenda-filter t]
  2285. "--"
  2286. ["by category at cursor" org-agenda-filter-by-category t]
  2287. ["by tag" org-agenda-filter-by-tag t]
  2288. ["by effort" org-agenda-filter-by-effort t]
  2289. ["by regexp" org-agenda-filter-by-regexp t]
  2290. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2291. "--"
  2292. ["Remove all filtering" org-agenda-filter-remove-all t]
  2293. "--"
  2294. ["limit" org-agenda-limit-interactively t])
  2295. ["Rebuild buffer" org-agenda-redo t]
  2296. ["Write view to file" org-agenda-write t]
  2297. ["Save all Org buffers" org-save-all-org-buffers t]
  2298. "--"
  2299. ["Show original entry" org-agenda-show t]
  2300. ["Go To (other window)" org-agenda-goto t]
  2301. ["Go To (this window)" org-agenda-switch-to t]
  2302. ["Capture with cursor date" org-agenda-capture t]
  2303. ["Follow Mode" org-agenda-follow-mode
  2304. :style toggle :selected org-agenda-follow-mode :active t]
  2305. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2306. "--"
  2307. ("TODO"
  2308. ["Cycle TODO" org-agenda-todo t]
  2309. ["Next TODO set" org-agenda-todo-nextset t]
  2310. ["Previous TODO set" org-agenda-todo-previousset t]
  2311. ["Add note" org-agenda-add-note t])
  2312. ("Archive/Refile/Delete"
  2313. ["Archive default" org-agenda-archive-default t]
  2314. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2315. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2316. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2317. ["Archive subtree" org-agenda-archive t]
  2318. "--"
  2319. ["Refile" org-agenda-refile t]
  2320. "--"
  2321. ["Delete subtree" org-agenda-kill t])
  2322. ("Bulk action"
  2323. ["Mark entry" org-agenda-bulk-mark t]
  2324. ["Mark all" org-agenda-bulk-mark-all t]
  2325. ["Unmark entry" org-agenda-bulk-unmark t]
  2326. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2327. ["Toggle mark" org-agenda-bulk-toggle t]
  2328. ["Toggle all" org-agenda-bulk-toggle-all t]
  2329. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2330. ["Act on all marked" org-agenda-bulk-action t]
  2331. "--"
  2332. ("Tags and Properties"
  2333. ["Show all Tags" org-agenda-show-tags t]
  2334. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2335. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2336. "--"
  2337. ["Column View" org-columns t])
  2338. ("Deadline/Schedule"
  2339. ["Schedule" org-agenda-schedule t]
  2340. ["Set Deadline" org-agenda-deadline t]
  2341. "--"
  2342. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2343. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2344. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2345. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2346. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2347. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2348. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2349. ("Clock and Effort"
  2350. ["Clock in" org-agenda-clock-in t]
  2351. ["Clock out" org-agenda-clock-out t]
  2352. ["Clock cancel" org-agenda-clock-cancel t]
  2353. ["Goto running clock" org-clock-goto t]
  2354. "--"
  2355. ["Set Effort" org-agenda-set-effort t]
  2356. ["Change clocked effort" org-clock-modify-effort-estimate
  2357. (org-clock-is-active)])
  2358. ("Priority"
  2359. ["Set Priority" org-agenda-priority t]
  2360. ["Increase Priority" org-agenda-priority-up t]
  2361. ["Decrease Priority" org-agenda-priority-down t]
  2362. ["Show Priority" org-priority-show t])
  2363. ("Calendar/Diary"
  2364. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2365. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2366. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2367. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2368. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2369. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2370. "--"
  2371. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2372. "--"
  2373. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2374. "--"
  2375. ("MobileOrg"
  2376. ["Push Files and Views" org-mobile-push t]
  2377. ["Get Captured and Flagged" org-mobile-pull t]
  2378. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2379. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2380. "--"
  2381. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2382. "--"
  2383. ["Quit" org-agenda-quit t]
  2384. ["Exit and Release Buffers" org-agenda-exit t]
  2385. ))
  2386. ;;; Agenda undo
  2387. (defvar org-agenda-allow-remote-undo t
  2388. "Non-nil means allow remote undo from the agenda buffer.")
  2389. (defvar org-agenda-undo-has-started-in nil
  2390. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2391. (defun org-agenda-undo ()
  2392. "Undo a remote editing step in the agenda.
  2393. This undoes changes both in the agenda buffer and in the remote buffer
  2394. that have been changed along."
  2395. (interactive)
  2396. (or org-agenda-allow-remote-undo
  2397. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2398. (when (not (eq this-command last-command))
  2399. (setq org-agenda-undo-has-started-in nil
  2400. org-agenda-pending-undo-list org-agenda-undo-list))
  2401. (when (not org-agenda-pending-undo-list)
  2402. (user-error "No further undo information"))
  2403. (let* ((entry (pop org-agenda-pending-undo-list))
  2404. buf line cmd rembuf)
  2405. (setq cmd (pop entry) line (pop entry))
  2406. (setq rembuf (nth 2 entry))
  2407. (org-with-remote-undo rembuf
  2408. (while (bufferp (setq buf (pop entry)))
  2409. (when (pop entry)
  2410. (with-current-buffer buf
  2411. (let (;; (last-undo-buffer buf)
  2412. (inhibit-read-only t))
  2413. (unless (memq buf org-agenda-undo-has-started-in)
  2414. (push buf org-agenda-undo-has-started-in)
  2415. (make-local-variable 'pending-undo-list)
  2416. (undo-start))
  2417. (while (and pending-undo-list
  2418. (listp pending-undo-list)
  2419. (not (car pending-undo-list)))
  2420. (pop pending-undo-list))
  2421. (undo-more 1))))))
  2422. (org-goto-line line)
  2423. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2424. (defun org-verify-change-for-undo (l1 l2)
  2425. "Verify that a real change occurred between the undo lists L1 and L2."
  2426. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2427. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2428. (not (eq l1 l2)))
  2429. ;;; Agenda dispatch
  2430. (defvar org-agenda-restrict-begin (make-marker))
  2431. (defvar org-agenda-restrict-end (make-marker))
  2432. (defvar org-agenda-last-dispatch-buffer nil)
  2433. (defvar org-agenda-overriding-restriction nil)
  2434. (defcustom org-agenda-custom-commands-contexts nil
  2435. "Alist of custom agenda keys and contextual rules.
  2436. For example, if you have a custom agenda command \"p\" and you
  2437. want this command to be accessible only from plain text files,
  2438. use this:
  2439. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2440. Here are the available contexts definitions:
  2441. in-file: command displayed only in matching files
  2442. in-mode: command displayed only in matching modes
  2443. not-in-file: command not displayed in matching files
  2444. not-in-mode: command not displayed in matching modes
  2445. in-buffer: command displayed only in matching buffers
  2446. not-in-buffer: command not displayed in matching buffers
  2447. [function]: a custom function taking no argument
  2448. If you define several checks, the agenda command will be
  2449. accessible if there is at least one valid check.
  2450. You can also bind a key to another agenda custom command
  2451. depending on contextual rules.
  2452. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2453. Here it means: in .txt files, use \"p\" as the key for the
  2454. agenda command otherwise associated with \"q\". (The command
  2455. originally associated with \"q\" is not displayed to avoid
  2456. duplicates.)"
  2457. :version "24.3"
  2458. :group 'org-agenda-custom-commands
  2459. :type '(repeat (list :tag "Rule"
  2460. (string :tag " Agenda key")
  2461. (string :tag "Replace by command")
  2462. (repeat :tag "Available when"
  2463. (choice
  2464. (cons :tag "Condition"
  2465. (choice
  2466. (const :tag "In file" in-file)
  2467. (const :tag "Not in file" not-in-file)
  2468. (const :tag "In buffer" in-buffer)
  2469. (const :tag "Not in buffer" not-in-buffer)
  2470. (const :tag "In mode" in-mode)
  2471. (const :tag "Not in mode" not-in-mode))
  2472. (regexp))
  2473. (function :tag "Custom function"))))))
  2474. (defcustom org-agenda-max-entries nil
  2475. "Maximum number of entries to display in an agenda.
  2476. This can be nil (no limit) or an integer or an alist of agenda
  2477. types with an associated number of entries to display in this
  2478. type."
  2479. :version "24.4"
  2480. :package-version '(Org . "8.0")
  2481. :group 'org-agenda-custom-commands
  2482. :type '(choice (symbol :tag "No limit" nil)
  2483. (integer :tag "Max number of entries")
  2484. (repeat
  2485. (cons (choice :tag "Agenda type"
  2486. (const agenda)
  2487. (const todo)
  2488. (const tags)
  2489. (const search))
  2490. (integer :tag "Max number of entries")))))
  2491. (defcustom org-agenda-max-todos nil
  2492. "Maximum number of TODOs to display in an agenda.
  2493. This can be nil (no limit) or an integer or an alist of agenda
  2494. types with an associated number of entries to display in this
  2495. type."
  2496. :version "24.4"
  2497. :package-version '(Org . "8.0")
  2498. :group 'org-agenda-custom-commands
  2499. :type '(choice (symbol :tag "No limit" nil)
  2500. (integer :tag "Max number of TODOs")
  2501. (repeat
  2502. (cons (choice :tag "Agenda type"
  2503. (const agenda)
  2504. (const todo)
  2505. (const tags)
  2506. (const search))
  2507. (integer :tag "Max number of TODOs")))))
  2508. (defcustom org-agenda-max-tags nil
  2509. "Maximum number of tagged entries to display in an agenda.
  2510. This can be nil (no limit) or an integer or an alist of agenda
  2511. types with an associated number of entries to display in this
  2512. type."
  2513. :version "24.4"
  2514. :package-version '(Org . "8.0")
  2515. :group 'org-agenda-custom-commands
  2516. :type '(choice (symbol :tag "No limit" nil)
  2517. (integer :tag "Max number of tagged entries")
  2518. (repeat
  2519. (cons (choice :tag "Agenda type"
  2520. (const agenda)
  2521. (const todo)
  2522. (const tags)
  2523. (const search))
  2524. (integer :tag "Max number of tagged entries")))))
  2525. (defcustom org-agenda-max-effort nil
  2526. "Maximum cumulated effort duration for the agenda.
  2527. This can be nil (no limit) or a number of minutes (as an integer)
  2528. or an alist of agenda types with an associated number of minutes
  2529. to limit entries to in this type."
  2530. :version "24.4"
  2531. :package-version '(Org . "8.0")
  2532. :group 'org-agenda-custom-commands
  2533. :type '(choice (symbol :tag "No limit" nil)
  2534. (integer :tag "Max number of minutes")
  2535. (repeat
  2536. (cons (choice :tag "Agenda type"
  2537. (const agenda)
  2538. (const todo)
  2539. (const tags)
  2540. (const search))
  2541. (integer :tag "Max number of minutes")))))
  2542. (defvar org-agenda-keep-restricted-file-list nil)
  2543. (defvar org-keys nil)
  2544. (defvar org-match nil)
  2545. ;;;###autoload
  2546. (defun org-agenda (&optional arg keys restriction)
  2547. "Dispatch agenda commands to collect entries to the agenda buffer.
  2548. Prompts for a command to execute. Any prefix arg will be passed
  2549. on to the selected command. The default selections are:
  2550. a Call `org-agenda-list' to display the agenda for current day or week.
  2551. t Call `org-todo-list' to display the global todo list.
  2552. T Call `org-todo-list' to display the global todo list, select only
  2553. entries with a specific TODO keyword (the user gets a prompt).
  2554. m Call `org-tags-view' to display headlines with tags matching
  2555. a condition (the user is prompted for the condition).
  2556. M Like `m', but select only TODO entries, no ordinary headlines.
  2557. e Export views to associated files.
  2558. s Search entries for keywords.
  2559. S Search entries for keywords, only with TODO keywords.
  2560. / Multi occur across all agenda files and also files listed
  2561. in `org-agenda-text-search-extra-files'.
  2562. < Restrict agenda commands to buffer, subtree, or region.
  2563. Press several times to get the desired effect.
  2564. > Remove a previous restriction.
  2565. # List \"stuck\" projects.
  2566. ! Configure what \"stuck\" means.
  2567. C Configure custom agenda commands.
  2568. More commands can be added by configuring the variable
  2569. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2570. searches can be pre-defined in this way.
  2571. If the current buffer is in Org mode and visiting a file, you can also
  2572. first press `<' once to indicate that the agenda should be temporarily
  2573. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2574. Pressing `<' twice means to restrict to the current subtree or region
  2575. \(if active)."
  2576. (interactive "P")
  2577. (catch 'exit
  2578. (let* ((org-keys keys)
  2579. (prefix-descriptions nil)
  2580. (org-agenda-buffer-name org-agenda-buffer-name)
  2581. (org-agenda-window-setup (if (equal (buffer-name)
  2582. org-agenda-buffer-name)
  2583. 'current-window
  2584. org-agenda-window-setup))
  2585. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2586. (org-agenda-custom-commands
  2587. ;; normalize different versions
  2588. (delq nil
  2589. (mapcar
  2590. (lambda (x)
  2591. (cond ((stringp (cdr x))
  2592. (push x prefix-descriptions)
  2593. nil)
  2594. ((stringp (nth 1 x)) x)
  2595. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2596. (t (cons (car x) (cons "" (cdr x))))))
  2597. org-agenda-custom-commands)))
  2598. (org-agenda-custom-commands
  2599. (org-contextualize-keys
  2600. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2601. ;; (buf (current-buffer))
  2602. (bfn (buffer-file-name (buffer-base-buffer)))
  2603. entry type org-match lprops ans) ;; key
  2604. ;; Turn off restriction unless there is an overriding one,
  2605. (unless org-agenda-overriding-restriction
  2606. (unless org-agenda-keep-restricted-file-list
  2607. ;; There is a request to keep the file list in place
  2608. (put 'org-agenda-files 'org-restrict nil))
  2609. (setq org-agenda-restrict nil)
  2610. (move-marker org-agenda-restrict-begin nil)
  2611. (move-marker org-agenda-restrict-end nil))
  2612. ;; Delete old local properties
  2613. (put 'org-agenda-redo-command 'org-lprops nil)
  2614. ;; Delete previously set last-arguments
  2615. (put 'org-agenda-redo-command 'last-args nil)
  2616. ;; Remember where this call originated
  2617. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2618. (unless org-keys
  2619. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2620. org-keys (car ans)
  2621. restriction (cdr ans)))
  2622. ;; If we have sticky agenda buffers, set a name for the buffer,
  2623. ;; depending on the invoking keys. The user may still set this
  2624. ;; as a command option, which will overwrite what we do here.
  2625. (when org-agenda-sticky
  2626. (setq org-agenda-buffer-name
  2627. (format "*Org Agenda(%s)*" org-keys)))
  2628. ;; Establish the restriction, if any
  2629. (when (and (not org-agenda-overriding-restriction) restriction)
  2630. (put 'org-agenda-files 'org-restrict (list bfn))
  2631. (cond
  2632. ((eq restriction 'region)
  2633. (setq org-agenda-restrict (current-buffer))
  2634. (move-marker org-agenda-restrict-begin (region-beginning))
  2635. (move-marker org-agenda-restrict-end (region-end)))
  2636. ((eq restriction 'subtree)
  2637. (save-excursion
  2638. (setq org-agenda-restrict (current-buffer))
  2639. (org-back-to-heading t)
  2640. (move-marker org-agenda-restrict-begin (point))
  2641. (move-marker org-agenda-restrict-end
  2642. (progn (org-end-of-subtree t)))))
  2643. ((and (eq restriction 'buffer)
  2644. (or (< 1 (point-min))
  2645. (< (point-max) (1+ (buffer-size)))))
  2646. (setq org-agenda-restrict (current-buffer))
  2647. (move-marker org-agenda-restrict-begin (point-min))
  2648. (move-marker org-agenda-restrict-end (point-max)))))
  2649. ;; For example the todo list should not need it (but does...)
  2650. (cond
  2651. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2652. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2653. (progn
  2654. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2655. ;; to some of the local variables? There's no doc about
  2656. ;; that for `org-agenda-custom-commands'.
  2657. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2658. lprops (nth 4 entry))
  2659. (when org-agenda-sticky
  2660. (setq org-agenda-buffer-name
  2661. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2662. (format "*Org Agenda(%s)*" org-keys))))
  2663. (put 'org-agenda-redo-command 'org-lprops lprops)
  2664. (cl-progv
  2665. (mapcar #'car lprops)
  2666. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2667. (pcase type
  2668. (`agenda
  2669. (org-agenda-list arg))
  2670. (`agenda*
  2671. (org-agenda-list arg nil nil t))
  2672. (`alltodo
  2673. (org-todo-list arg))
  2674. (`search
  2675. (org-search-view arg org-match nil))
  2676. (`stuck
  2677. (org-agenda-list-stuck-projects arg))
  2678. (`tags
  2679. (org-tags-view arg org-match))
  2680. (`tags-todo
  2681. (org-tags-view '(4) org-match))
  2682. (`todo
  2683. (org-todo-list org-match))
  2684. (`tags-tree
  2685. (org-check-for-org-mode)
  2686. (org-match-sparse-tree arg org-match))
  2687. (`todo-tree
  2688. (org-check-for-org-mode)
  2689. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2690. (regexp-quote org-match) "\\>")))
  2691. (`occur-tree
  2692. (org-check-for-org-mode)
  2693. (org-occur org-match))
  2694. ((pred functionp)
  2695. (funcall type org-match))
  2696. ;; FIXME: Will signal an error since it's not `functionp'!
  2697. ((pred fboundp) (funcall type org-match))
  2698. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2699. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2700. ((equal org-keys "C")
  2701. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2702. (customize-variable 'org-agenda-custom-commands))
  2703. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2704. ((equal org-keys "s") (call-interactively 'org-search-view))
  2705. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2706. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2707. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2708. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2709. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2710. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2711. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2712. (add-hook
  2713. 'post-command-hook
  2714. (lambda ()
  2715. (unless (current-message)
  2716. (let* ((m (org-agenda-get-any-marker))
  2717. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2718. (when note
  2719. (message "FLAGGING-NOTE ([?] for more info): %s"
  2720. (org-add-props
  2721. (replace-regexp-in-string
  2722. "\\\\n" "//"
  2723. (copy-sequence note))
  2724. nil 'face 'org-warning))))))
  2725. t t))
  2726. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2727. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2728. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2729. (t (user-error "Invalid agenda key"))))))
  2730. (defvar org-agenda-multi)
  2731. (defun org-agenda-append-agenda ()
  2732. "Append another agenda view to the current one.
  2733. This function allows interactive building of block agendas.
  2734. Agenda views are separated by `org-agenda-block-separator'."
  2735. (interactive)
  2736. (unless (derived-mode-p 'org-agenda-mode)
  2737. (user-error "Can only append from within agenda buffer"))
  2738. (let ((org-agenda-multi t))
  2739. (org-agenda)
  2740. (widen)
  2741. (org-agenda-finalize)
  2742. (setq buffer-read-only t)
  2743. (org-agenda-fit-window-to-buffer)))
  2744. (defun org-agenda-normalize-custom-commands (cmds)
  2745. "Normalize custom commands CMDS."
  2746. (delq nil
  2747. (mapcar
  2748. (lambda (x)
  2749. (cond ((stringp (cdr x)) nil)
  2750. ((stringp (nth 1 x)) x)
  2751. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2752. (t (cons (car x) (cons "" (cdr x))))))
  2753. cmds)))
  2754. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2755. "The user interface for selecting an agenda command."
  2756. (catch 'exit
  2757. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2758. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2759. (region-p (org-region-active-p))
  2760. (custom org-agenda-custom-commands)
  2761. (selstring "")
  2762. restriction second-time
  2763. c entry key type match prefixes rmheader header-end custom1 desc
  2764. line lines left right n n1)
  2765. (save-window-excursion
  2766. (delete-other-windows)
  2767. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2768. (erase-buffer)
  2769. (insert (eval-when-compile
  2770. (let ((header
  2771. (copy-sequence
  2772. "Press key for an agenda command:
  2773. -------------------------------- < Buffer, subtree/region restriction
  2774. a Agenda for current week or day > Remove restriction
  2775. t List of all TODO entries e Export agenda views
  2776. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2777. s Search for keywords M Like m, but only TODO entries
  2778. / Multi-occur S Like s, but only TODO entries
  2779. ? Find :FLAGGED: entries C Configure custom agenda commands
  2780. * Toggle sticky agenda views # List stuck projects (!=configure)
  2781. "))
  2782. (start 0))
  2783. (while (string-match
  2784. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2785. header start)
  2786. (setq start (match-end 0))
  2787. (add-text-properties (match-beginning 2) (match-end 2)
  2788. '(face bold) header))
  2789. header)))
  2790. (setq header-end (point-marker))
  2791. (while t
  2792. (setq custom1 custom)
  2793. (when (eq rmheader t)
  2794. (org-goto-line 1)
  2795. (re-search-forward ":" nil t)
  2796. (delete-region (match-end 0) (point-at-eol))
  2797. (forward-char 1)
  2798. (looking-at "-+")
  2799. (delete-region (match-end 0) (point-at-eol))
  2800. (move-marker header-end (match-end 0)))
  2801. (goto-char header-end)
  2802. (delete-region (point) (point-max))
  2803. ;; Produce all the lines that describe custom commands and prefixes
  2804. (setq lines nil)
  2805. (while (setq entry (pop custom1))
  2806. (setq key (car entry) desc (nth 1 entry)
  2807. type (nth 2 entry)
  2808. match (nth 3 entry))
  2809. (if (> (length key) 1)
  2810. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2811. (setq line
  2812. (format
  2813. "%-4s%-14s"
  2814. (org-add-props (copy-sequence key)
  2815. '(face bold))
  2816. (cond
  2817. ((string-match "\\S-" desc) desc)
  2818. ((eq type 'agenda) "Agenda for current week or day")
  2819. ((eq type 'agenda*) "Appointments for current week or day")
  2820. ((eq type 'alltodo) "List of all TODO entries")
  2821. ((eq type 'search) "Word search")
  2822. ((eq type 'stuck) "List of stuck projects")
  2823. ((eq type 'todo) "TODO keyword")
  2824. ((eq type 'tags) "Tags query")
  2825. ((eq type 'tags-todo) "Tags (TODO)")
  2826. ((eq type 'tags-tree) "Tags tree")
  2827. ((eq type 'todo-tree) "TODO kwd tree")
  2828. ((eq type 'occur-tree) "Occur tree")
  2829. ((functionp type) (if (symbolp type)
  2830. (symbol-name type)
  2831. "Lambda expression"))
  2832. (t "???"))))
  2833. (cond
  2834. ((not (org-string-nw-p match)) nil)
  2835. (org-agenda-menu-show-matcher
  2836. (setq line
  2837. (concat line ": "
  2838. (cond
  2839. ((stringp match)
  2840. (propertize match 'face 'org-warning))
  2841. ((listp type)
  2842. (format "set of %d commands" (length type)))))))
  2843. (t
  2844. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2845. (push line lines)))
  2846. (setq lines (nreverse lines))
  2847. (when prefixes
  2848. (mapc (lambda (x)
  2849. (push
  2850. (format "%s %s"
  2851. (org-add-props (char-to-string x)
  2852. nil 'face 'bold)
  2853. (or (cdr (assoc (concat selstring
  2854. (char-to-string x))
  2855. prefix-descriptions))
  2856. "Prefix key"))
  2857. lines))
  2858. prefixes))
  2859. ;; Check if we should display in two columns
  2860. (if org-agenda-menu-two-columns
  2861. (progn
  2862. (setq n (length lines)
  2863. n1 (+ (/ n 2) (mod n 2))
  2864. right (nthcdr n1 lines)
  2865. left (copy-sequence lines))
  2866. (setcdr (nthcdr (1- n1) left) nil))
  2867. (setq left lines right nil))
  2868. (while left
  2869. (insert "\n" (pop left))
  2870. (when right
  2871. (if (< (current-column) 40)
  2872. (move-to-column 40 t)
  2873. (insert " "))
  2874. (insert (pop right))))
  2875. ;; Make the window the right size
  2876. (goto-char (point-min))
  2877. (if second-time
  2878. (when (not (pos-visible-in-window-p (point-max)))
  2879. (org-fit-window-to-buffer))
  2880. (setq second-time t)
  2881. (org-fit-window-to-buffer))
  2882. ;; Hint to navigation if window too small for all information
  2883. (setq header-line-format
  2884. (when (not (pos-visible-in-window-p (point-max)))
  2885. "Use C-v, M-v, C-n or C-p to navigate."))
  2886. ;; Ask for selection
  2887. (cl-loop
  2888. do (progn
  2889. (message "Press key for agenda command%s:"
  2890. (if (or restrict-ok org-agenda-overriding-restriction)
  2891. (if org-agenda-overriding-restriction
  2892. " (restriction lock active)"
  2893. (if restriction
  2894. (format " (restricted to %s)" restriction)
  2895. " (unrestricted)"))
  2896. ""))
  2897. (setq c (read-char-exclusive)))
  2898. until (not (memq c '(14 16 22 134217846)))
  2899. do (org-scroll c))
  2900. (message "")
  2901. (cond
  2902. ((assoc (char-to-string c) custom)
  2903. (setq selstring (concat selstring (char-to-string c)))
  2904. (throw 'exit (cons selstring restriction)))
  2905. ((memq c prefixes)
  2906. (setq selstring (concat selstring (char-to-string c))
  2907. prefixes nil
  2908. rmheader (or rmheader t)
  2909. custom (delq nil (mapcar
  2910. (lambda (x)
  2911. (if (or (= (length (car x)) 1)
  2912. (/= (string-to-char (car x)) c))
  2913. nil
  2914. (cons (substring (car x) 1) (cdr x))))
  2915. custom))))
  2916. ((eq c ?*)
  2917. (call-interactively 'org-toggle-sticky-agenda)
  2918. (sit-for 2))
  2919. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2920. (message "Restriction is only possible in Org buffers")
  2921. (ding) (sit-for 1))
  2922. ((eq c ?1)
  2923. (org-agenda-remove-restriction-lock 'noupdate)
  2924. (setq restriction 'buffer))
  2925. ((eq c ?0)
  2926. (org-agenda-remove-restriction-lock 'noupdate)
  2927. (setq restriction (if region-p 'region 'subtree)))
  2928. ((eq c ?<)
  2929. (org-agenda-remove-restriction-lock 'noupdate)
  2930. (setq restriction
  2931. (cond
  2932. ((eq restriction 'buffer)
  2933. (if region-p 'region 'subtree))
  2934. ((memq restriction '(subtree region))
  2935. nil)
  2936. (t 'buffer))))
  2937. ((eq c ?>)
  2938. (org-agenda-remove-restriction-lock 'noupdate)
  2939. (setq restriction nil))
  2940. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2941. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2942. ((and (> (length selstring) 0) (eq c ?\d))
  2943. (delete-window)
  2944. (org-agenda-get-restriction-and-command prefix-descriptions))
  2945. ((equal c ?q) (user-error "Abort"))
  2946. (t (user-error "Invalid key %c" c))))))))
  2947. (defun org-agenda-fit-window-to-buffer ()
  2948. "Fit the window to the buffer size."
  2949. (and (memq org-agenda-window-setup '(reorganize-frame))
  2950. (fboundp 'fit-window-to-buffer)
  2951. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2952. (= (car org-agenda-window-frame-fractions) 1.0))
  2953. (delete-other-windows)
  2954. (org-fit-window-to-buffer
  2955. nil
  2956. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2957. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2958. (defvar org-cmd nil)
  2959. (defvar org-agenda-overriding-cmd nil)
  2960. (defvar org-agenda-overriding-arguments nil)
  2961. (defvar org-agenda-overriding-cmd-arguments nil)
  2962. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2963. (declare (indent 1) (obsolete cl-progv "2021"))
  2964. (eval (cons 'let (cons list body))))
  2965. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2966. (declare (indent 2) (obsolete cl-progv "2021"))
  2967. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2968. (defun org-agenda-run-series (name series)
  2969. "Run agenda NAME as a SERIES of agenda commands."
  2970. (let* ((gprops (nth 1 series))
  2971. (gvars (mapcar #'car gprops))
  2972. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2973. (cl-progv gvars gvals (org-agenda-prepare name))
  2974. ;; We need to reset agenda markers here, because when constructing a
  2975. ;; block agenda, the individual blocks do not do that.
  2976. (org-agenda-reset-markers)
  2977. (with-no-warnings
  2978. (defvar match)) ;Used via the `eval' below.
  2979. (let* ((org-agenda-multi t)
  2980. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2981. ;; than expressions, so you don't need to `quote' the args
  2982. ;; and you just need to `apply' instead of `eval' when using it.
  2983. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2984. (cmds (car series))
  2985. match
  2986. org-cmd type lprops)
  2987. (while (setq org-cmd (pop cmds))
  2988. (setq type (car org-cmd))
  2989. (setq match (eval (nth 1 org-cmd) t))
  2990. (setq lprops (nth 2 org-cmd))
  2991. (let ((org-agenda-overriding-arguments
  2992. (if (eq org-agenda-overriding-cmd org-cmd)
  2993. (or org-agenda-overriding-arguments
  2994. org-agenda-overriding-cmd-arguments)))
  2995. (lvars (mapcar #'car lprops))
  2996. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2997. (cl-progv (append gvars lvars) (append gvals lvals)
  2998. (pcase type
  2999. (`agenda
  3000. (call-interactively 'org-agenda-list))
  3001. (`agenda*
  3002. (funcall 'org-agenda-list nil nil t))
  3003. (`alltodo
  3004. (call-interactively 'org-todo-list))
  3005. (`search
  3006. (org-search-view current-prefix-arg match nil))
  3007. (`stuck
  3008. (call-interactively 'org-agenda-list-stuck-projects))
  3009. (`tags
  3010. (org-tags-view current-prefix-arg match))
  3011. (`tags-todo
  3012. (org-tags-view '(4) match))
  3013. (`todo
  3014. (org-todo-list match))
  3015. ((pred fboundp)
  3016. (funcall type match))
  3017. (_ (error "Invalid type in command series"))))))
  3018. (widen)
  3019. (let ((inhibit-read-only t))
  3020. (add-text-properties (point-min) (point-max)
  3021. `(org-series t org-series-redo-cmd ,redo)))
  3022. (setq org-agenda-redo-command redo)
  3023. (goto-char (point-min)))
  3024. (org-agenda-fit-window-to-buffer)
  3025. (cl-progv gvars gvals (org-agenda-finalize))))
  3026. (defun org-agenda--split-plist (plist)
  3027. ;; We could/should arguably use `map-keys' and `map-values'.
  3028. (let (keys vals)
  3029. (while plist
  3030. (push (pop plist) keys)
  3031. (push (pop plist) vals))
  3032. (cons (nreverse keys) (nreverse vals))))
  3033. ;;;###autoload
  3034. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3035. "Run an agenda command in batch mode and send the result to STDOUT.
  3036. If CMD-KEY is a string of length 1, it is used as a key in
  3037. `org-agenda-custom-commands' and triggers this command. If it is a
  3038. longer string it is used as a tags/todo match string.
  3039. Parameters are alternating variable names and values that will be bound
  3040. before running the agenda command."
  3041. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3042. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3043. (defun org--batch-agenda (cmd-key vars vals)
  3044. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3045. ;; a variable name rather than an expression to evaluate. Yuck!
  3046. (cl-progv vars vals
  3047. (let (org-agenda-sticky)
  3048. (if (> (length cmd-key) 1)
  3049. (org-tags-view nil cmd-key)
  3050. (org-agenda nil cmd-key))))
  3051. (set-buffer org-agenda-buffer-name)
  3052. (princ (buffer-string)))
  3053. (defvar org-agenda-info nil)
  3054. ;;;###autoload
  3055. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3056. "Run an agenda command in batch mode and send the result to STDOUT.
  3057. If CMD-KEY is a string of length 1, it is used as a key in
  3058. `org-agenda-custom-commands' and triggers this command. If it is a
  3059. longer string it is used as a tags/todo match string.
  3060. Parameters are alternating variable names and values that will be bound
  3061. before running the agenda command.
  3062. The output gives a line for each selected agenda item. Each
  3063. item is a list of comma-separated values, like this:
  3064. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3065. category The category of the item
  3066. head The headline, without TODO kwd, TAGS and PRIORITY
  3067. type The type of the agenda entry, can be
  3068. todo selected in TODO match
  3069. tagsmatch selected in tags match
  3070. diary imported from diary
  3071. deadline a deadline on given date
  3072. scheduled scheduled on given date
  3073. timestamp entry has timestamp on given date
  3074. closed entry was closed on given date
  3075. upcoming-deadline warning about deadline
  3076. past-scheduled forwarded scheduled item
  3077. block entry has date block including g. date
  3078. todo The todo keyword, if any
  3079. tags All tags including inherited ones, separated by colons
  3080. date The relevant date, like 2007-2-14
  3081. time The time, like 15:00-16:50
  3082. extra String with extra planning info
  3083. priority-l The priority letter if any was given
  3084. priority-n The computed numerical priority
  3085. agenda-day The day in the agenda where this is listed"
  3086. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3087. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3088. (defun org--batch-agenda-csv (cmd-key vars vals)
  3089. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3090. ;; a variable name rather than an expression to evaluate. Yuck!
  3091. (let ((org-agenda-remove-tags t))
  3092. (cl-progv vars vals
  3093. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3094. (if (> (length cmd-key) 2)
  3095. (org-tags-view nil cmd-key)
  3096. (org-agenda nil cmd-key))))
  3097. (set-buffer org-agenda-buffer-name)
  3098. (let ((lines (org-split-string (buffer-string) "\n")))
  3099. (dolist (line lines)
  3100. (when (get-text-property 0 'org-category line)
  3101. (setq org-agenda-info
  3102. (org-fix-agenda-info (text-properties-at 0 line)))
  3103. (princ
  3104. (mapconcat #'org-agenda-export-csv-mapper
  3105. '(org-category txt type todo tags date time extra
  3106. priority-letter priority agenda-day)
  3107. ","))
  3108. (princ "\n")))))
  3109. (defun org-fix-agenda-info (props)
  3110. "Make sure all properties on an agenda item have a canonical form.
  3111. This ensures the export commands can easily use it."
  3112. (let (tmp re)
  3113. (when (setq tmp (plist-get props 'tags))
  3114. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3115. (when (setq tmp (plist-get props 'date))
  3116. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3117. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3118. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3119. (setq tmp (calendar-date-string tmp)))
  3120. (setq props (plist-put props 'date tmp)))
  3121. (when (setq tmp (plist-get props 'day))
  3122. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3123. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3124. (setq tmp (calendar-date-string tmp)))
  3125. (setq props (plist-put props 'day tmp))
  3126. (setq props (plist-put props 'agenda-day tmp)))
  3127. (when (setq tmp (plist-get props 'txt))
  3128. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3129. (plist-put props 'priority-letter (match-string 1 tmp))
  3130. (setq tmp (replace-match "" t t tmp)))
  3131. (when (and (setq re (plist-get props 'org-todo-regexp))
  3132. (setq re (concat "\\`\\.*" re " ?"))
  3133. (let ((case-fold-search nil)) (string-match re tmp)))
  3134. (plist-put props 'todo (match-string 1 tmp))
  3135. (setq tmp (replace-match "" t t tmp)))
  3136. (plist-put props 'txt tmp)))
  3137. props)
  3138. (defun org-agenda-export-csv-mapper (prop)
  3139. (let ((res (plist-get org-agenda-info prop)))
  3140. (setq res
  3141. (cond
  3142. ((not res) "")
  3143. ((stringp res) res)
  3144. (t (prin1-to-string res))))
  3145. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3146. ;;;###autoload
  3147. (defun org-store-agenda-views (&rest _parameters)
  3148. "Store agenda views."
  3149. (interactive)
  3150. (org--batch-store-agenda-views nil nil))
  3151. ;;;###autoload
  3152. (defmacro org-batch-store-agenda-views (&rest parameters)
  3153. "Run all custom agenda commands that have a file argument."
  3154. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3155. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3156. (defun org--batch-store-agenda-views (vars vals)
  3157. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3158. (pop-up-frames nil)
  3159. (dir default-directory)
  3160. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3161. (save-window-excursion
  3162. (while cmds
  3163. (setq cmd (pop cmds)
  3164. thiscmdkey (car cmd)
  3165. thiscmdcmd (cdr cmd)
  3166. match (nth 2 thiscmdcmd)
  3167. bufname (if org-agenda-sticky
  3168. (or (and (stringp match)
  3169. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3170. (format "*Org Agenda(%s)*" thiscmdkey))
  3171. org-agenda-buffer-name)
  3172. cmd-or-set (nth 2 cmd)
  3173. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3174. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3175. (if (stringp files) (setq files (list files)))
  3176. (when files
  3177. (let* ((opts (append org-agenda-exporter-settings opts))
  3178. (vars (append (mapcar #'car opts) vars))
  3179. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3180. opts)
  3181. vals)))
  3182. (cl-progv vars vals
  3183. (org-agenda nil thiscmdkey))
  3184. (set-buffer bufname)
  3185. (while files
  3186. (cl-progv vars vals
  3187. (org-agenda-write (expand-file-name (pop files) dir)
  3188. nil t bufname))))
  3189. (and (get-buffer bufname)
  3190. (kill-buffer bufname)))))))
  3191. (defvar org-agenda-current-span nil
  3192. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3193. (defun org-agenda-mark-header-line (pos)
  3194. "Mark the line at POS as an agenda structure header."
  3195. (save-excursion
  3196. (goto-char pos)
  3197. (put-text-property (point-at-bol) (point-at-eol)
  3198. 'org-agenda-structural-header t)
  3199. (when org-agenda-title-append
  3200. (put-text-property (point-at-bol) (point-at-eol)
  3201. 'org-agenda-title-append org-agenda-title-append))))
  3202. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3203. (defvar org-agenda-write-buffer-name "Agenda View")
  3204. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3205. "Write the current buffer (an agenda view) as a file.
  3206. Depending on the extension of the file name, plain text (.txt),
  3207. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3208. If the extension is .ics, translate visible agenda into iCalendar
  3209. format. If the extension is .org, collect all subtrees
  3210. corresponding to the agenda entries and add them in an .org file.
  3211. With prefix argument OPEN, open the new file immediately. If
  3212. NOSETTINGS is given, do not scope the settings of
  3213. `org-agenda-exporter-settings' into the export commands. This is
  3214. used when the settings have already been scoped and we do not
  3215. wish to overrule other, higher priority settings. If
  3216. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3217. the agenda to write."
  3218. (interactive "FWrite agenda to file: \nP")
  3219. (if (or (not (file-writable-p file))
  3220. (and (file-exists-p file)
  3221. (if (called-interactively-p 'any)
  3222. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3223. (user-error "Cannot write agenda to file %s" file))
  3224. (cl-progv
  3225. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3226. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3227. org-agenda-exporter-settings))
  3228. (save-excursion
  3229. (save-window-excursion
  3230. (let ((bs (copy-sequence (buffer-string)))
  3231. (extension (file-name-extension file))
  3232. (default-directory (file-name-directory file))
  3233. ) ;; beg content
  3234. (with-temp-buffer
  3235. (rename-buffer org-agenda-write-buffer-name t)
  3236. (set-buffer-modified-p nil)
  3237. (insert bs)
  3238. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3239. (run-hooks 'org-agenda-before-write-hook)
  3240. (cond
  3241. ((bound-and-true-p org-mobile-creating-agendas)
  3242. (org-mobile-write-agenda-for-mobile file))
  3243. ((string= "org" extension)
  3244. (let (content p m message-log-max)
  3245. (goto-char (point-min))
  3246. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3247. (goto-char p)
  3248. (setq m (get-text-property (point) 'org-hd-marker))
  3249. (when m
  3250. (push (with-current-buffer (marker-buffer m)
  3251. (goto-char m)
  3252. (org-copy-subtree 1 nil t t)
  3253. org-subtree-clip)
  3254. content)))
  3255. (find-file file)
  3256. (erase-buffer)
  3257. (dolist (s content) (org-paste-subtree 1 s))
  3258. (write-file file)
  3259. (kill-buffer (current-buffer))
  3260. (message "Org file written to %s" file)))
  3261. ((member extension '("html" "htm"))
  3262. (or (require 'htmlize nil t)
  3263. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3264. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3265. (set-buffer (htmlize-buffer (current-buffer)))
  3266. (when org-agenda-export-html-style
  3267. ;; replace <style> section with org-agenda-export-html-style
  3268. (goto-char (point-min))
  3269. (kill-region (- (search-forward "<style") 6)
  3270. (search-forward "</style>"))
  3271. (insert org-agenda-export-html-style))
  3272. (write-file file)
  3273. (kill-buffer (current-buffer))
  3274. (message "HTML written to %s" file))
  3275. ((string= "ps" extension)
  3276. (require 'ps-print)
  3277. (ps-print-buffer-with-faces file)
  3278. (message "Postscript written to %s" file))
  3279. ((string= "pdf" extension)
  3280. (require 'ps-print)
  3281. (ps-print-buffer-with-faces
  3282. (concat (file-name-sans-extension file) ".ps"))
  3283. (call-process "ps2pdf" nil nil nil
  3284. (expand-file-name
  3285. (concat (file-name-sans-extension file) ".ps"))
  3286. (expand-file-name file))
  3287. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3288. (message "PDF written to %s" file))
  3289. ((string= "ics" extension)
  3290. (require 'ox-icalendar)
  3291. (declare-function org-icalendar-export-current-agenda
  3292. "ox-icalendar" (file))
  3293. (org-icalendar-export-current-agenda (expand-file-name file)))
  3294. (t
  3295. (let ((bs (buffer-string)))
  3296. (find-file file)
  3297. (erase-buffer)
  3298. (insert bs)
  3299. (save-buffer 0)
  3300. (kill-buffer (current-buffer))
  3301. (message "Plain text written to %s" file))))))))
  3302. (set-buffer (or agenda-bufname
  3303. ;; FIXME: I'm pretty sure called-interactively-p
  3304. ;; doesn't do what we want here!
  3305. (and (called-interactively-p 'any) (buffer-name))
  3306. org-agenda-buffer-name)))
  3307. (when open (org-open-file file)))
  3308. (defun org-agenda-remove-marked-text (property &optional value)
  3309. "Delete all text marked with VALUE of PROPERTY.
  3310. VALUE defaults to t."
  3311. (let (beg)
  3312. (setq value (or value t))
  3313. (while (setq beg (text-property-any (point-min) (point-max)
  3314. property value))
  3315. (delete-region
  3316. beg (or (next-single-property-change beg property)
  3317. (point-max))))))
  3318. (defun org-agenda-add-entry-text ()
  3319. "Add entry text to agenda lines.
  3320. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3321. entry text following headings shown in the agenda.
  3322. Drawers will be excluded, also the line with scheduling/deadline info."
  3323. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3324. (not (bound-and-true-p org-mobile-creating-agendas)))
  3325. (let (m txt)
  3326. (goto-char (point-min))
  3327. (while (not (eobp))
  3328. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3329. (beginning-of-line 2)
  3330. (setq txt (org-agenda-get-some-entry-text
  3331. m org-agenda-add-entry-text-maxlines " > "))
  3332. (end-of-line 1)
  3333. (if (string-match "\\S-" txt)
  3334. (insert "\n" txt)
  3335. (or (eobp) (forward-char 1))))))))
  3336. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3337. &rest keep)
  3338. "Extract entry text from MARKER, at most N-LINES lines.
  3339. This will ignore drawers etc, just get the text.
  3340. If INDENT is given, prefix every line with this string. If KEEP is
  3341. given, it is a list of symbols, defining stuff that should not be
  3342. removed from the entry content. Currently only `planning' is allowed here."
  3343. (let (txt drawer-re kwd-time-re ind)
  3344. (save-excursion
  3345. (with-current-buffer (marker-buffer marker)
  3346. (if (not (derived-mode-p 'org-mode))
  3347. (setq txt "")
  3348. (org-with-wide-buffer
  3349. (goto-char marker)
  3350. (end-of-line 1)
  3351. (setq txt (buffer-substring
  3352. (min (1+ (point)) (point-max))
  3353. (progn (outline-next-heading) (point)))
  3354. drawer-re org-drawer-regexp
  3355. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3356. ".*\n?"))
  3357. (with-temp-buffer
  3358. (insert txt)
  3359. (when org-agenda-add-entry-text-descriptive-links
  3360. (goto-char (point-min))
  3361. (while (org-activate-links (point-max))
  3362. (goto-char (match-end 0))))
  3363. (goto-char (point-min))
  3364. (while (re-search-forward org-link-bracket-re (point-max) t)
  3365. (set-text-properties (match-beginning 0) (match-end 0)
  3366. nil))
  3367. (goto-char (point-min))
  3368. (while (re-search-forward drawer-re nil t)
  3369. (delete-region
  3370. (match-beginning 0)
  3371. (progn (re-search-forward
  3372. "^[ \t]*:END:.*\n?" nil 'move)
  3373. (point))))
  3374. (unless (member 'planning keep)
  3375. (goto-char (point-min))
  3376. (while (re-search-forward kwd-time-re nil t)
  3377. (replace-match "")))
  3378. (goto-char (point-min))
  3379. (when org-agenda-entry-text-exclude-regexps
  3380. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3381. (while (setq re (pop re-list))
  3382. (goto-char (point-min))
  3383. (while (re-search-forward re nil t)
  3384. (replace-match "")))))
  3385. (goto-char (point-max))
  3386. (skip-chars-backward " \t\n")
  3387. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3388. ;; find and remove min common indentation
  3389. (goto-char (point-min))
  3390. (untabify (point-min) (point-max))
  3391. (setq ind (current-indentation))
  3392. (while (not (eobp))
  3393. (unless (looking-at "[ \t]*$")
  3394. (setq ind (min ind (current-indentation))))
  3395. (beginning-of-line 2))
  3396. (goto-char (point-min))
  3397. (while (not (eobp))
  3398. (unless (looking-at "[ \t]*$")
  3399. (move-to-column ind)
  3400. (delete-region (point-at-bol) (point)))
  3401. (beginning-of-line 2))
  3402. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3403. (goto-char (point-min))
  3404. (when indent
  3405. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3406. (replace-match indent t t)))
  3407. (goto-char (point-min))
  3408. (while (looking-at "[ \t]*\n") (replace-match ""))
  3409. (goto-char (point-max))
  3410. (when (> (org-current-line)
  3411. n-lines)
  3412. (org-goto-line (1+ n-lines))
  3413. (backward-char 1))
  3414. (setq txt (buffer-substring (point-min) (point))))))))
  3415. txt))
  3416. (defun org-check-for-org-mode ()
  3417. "Make sure current buffer is in Org mode. Error if not."
  3418. (or (derived-mode-p 'org-mode)
  3419. (error "Cannot execute Org agenda command on buffer in %s"
  3420. major-mode)))
  3421. ;;; Agenda prepare and finalize
  3422. (defvar org-agenda-multi nil) ; dynamically scoped
  3423. (defvar org-agenda-pre-window-conf nil)
  3424. (defvar org-agenda-columns-active nil)
  3425. (defvar org-agenda-name nil)
  3426. (defvar org-agenda-tag-filter nil)
  3427. (defvar org-agenda-category-filter nil)
  3428. (defvar org-agenda-regexp-filter nil)
  3429. (defvar org-agenda-effort-filter nil)
  3430. (defvar org-agenda-top-headline-filter nil)
  3431. (defvar org-agenda-represented-categories nil
  3432. "Cache for the list of all categories in the agenda.")
  3433. (defvar org-agenda-represented-tags nil
  3434. "Cache for the list of all categories in the agenda.")
  3435. (defvar org-agenda-tag-filter-preset nil
  3436. "A preset of the tags filter used for secondary agenda filtering.
  3437. This must be a list of strings, each string must be a single tag preceded
  3438. by \"+\" or \"-\".
  3439. This variable should not be set directly, but agenda custom commands can
  3440. bind it in the options section. The preset filter is a global property of
  3441. the entire agenda view. In a block agenda, it will not work reliably to
  3442. define a filter for one of the individual blocks. You need to set it in
  3443. the global options and expect it to be applied to the entire view.")
  3444. (defconst org-agenda-filter-variables
  3445. '((category . org-agenda-category-filter)
  3446. (tag . org-agenda-tag-filter)
  3447. (effort . org-agenda-effort-filter)
  3448. (regexp . org-agenda-regexp-filter))
  3449. "Alist of filter types and associated variables.")
  3450. (defun org-agenda-filter-any ()
  3451. "Is any filter active?"
  3452. (cl-some (lambda (x)
  3453. (or (symbol-value (cdr x))
  3454. (get :preset-filter x)))
  3455. org-agenda-filter-variables))
  3456. (defvar org-agenda-category-filter-preset nil
  3457. "A preset of the category filter used for secondary agenda filtering.
  3458. This must be a list of strings, each string must be a single category
  3459. preceded by \"+\" or \"-\".
  3460. This variable should not be set directly, but agenda custom commands can
  3461. bind it in the options section. The preset filter is a global property of
  3462. the entire agenda view. In a block agenda, it will not work reliably to
  3463. define a filter for one of the individual blocks. You need to set it in
  3464. the global options and expect it to be applied to the entire view.")
  3465. (defvar org-agenda-regexp-filter-preset nil
  3466. "A preset of the regexp filter used for secondary agenda filtering.
  3467. This must be a list of strings, each string must be a single regexp
  3468. preceded by \"+\" or \"-\".
  3469. This variable should not be set directly, but agenda custom commands can
  3470. bind it in the options section. The preset filter is a global property of
  3471. the entire agenda view. In a block agenda, it will not work reliably to
  3472. define a filter for one of the individual blocks. You need to set it in
  3473. the global options and expect it to be applied to the entire view.")
  3474. (defvar org-agenda-effort-filter-preset nil
  3475. "A preset of the effort condition used for secondary agenda filtering.
  3476. This must be a list of strings, each string must be a single regexp
  3477. preceded by \"+\" or \"-\".
  3478. This variable should not be set directly, but agenda custom commands can
  3479. bind it in the options section. The preset filter is a global property of
  3480. the entire agenda view. In a block agenda, it will not work reliably to
  3481. define a filter for one of the individual blocks. You need to set it in
  3482. the global options and expect it to be applied to the entire view.")
  3483. (defun org-agenda-use-sticky-p ()
  3484. "Return non-nil if an agenda buffer named
  3485. `org-agenda-buffer-name' exists and should be shown instead of
  3486. generating a new one."
  3487. (and
  3488. ;; turned off by user
  3489. org-agenda-sticky
  3490. ;; For multi-agenda buffer already exists
  3491. (not org-agenda-multi)
  3492. ;; buffer found
  3493. (get-buffer org-agenda-buffer-name)
  3494. ;; C-u parameter is same as last call
  3495. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3496. (and
  3497. (equal current-prefix-arg
  3498. org-agenda-last-prefix-arg)
  3499. ;; In case user turned stickiness on, while having existing
  3500. ;; Agenda buffer active, don't reuse that buffer, because it
  3501. ;; does not have org variables local
  3502. org-agenda-this-buffer-is-sticky))))
  3503. (defvar org-agenda-buffer-tmp-name nil)
  3504. (defun org-agenda--get-buffer-name (sticky-name)
  3505. (or org-agenda-buffer-tmp-name
  3506. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3507. sticky-name
  3508. "*Org Agenda*"))
  3509. (defun org-agenda-prepare-window (abuf filter-alist)
  3510. "Setup agenda buffer in the window.
  3511. ABUF is the buffer for the agenda window.
  3512. FILTER-ALIST is an alist of filters we need to apply when
  3513. `org-agenda-persistent-filter' is non-nil."
  3514. (let* ((awin (get-buffer-window abuf)) wconf)
  3515. (cond
  3516. ((equal (current-buffer) abuf) nil)
  3517. (awin (select-window awin))
  3518. ((not (setq wconf (current-window-configuration))))
  3519. ((eq org-agenda-window-setup 'current-window)
  3520. (pop-to-buffer-same-window abuf))
  3521. ((eq org-agenda-window-setup 'other-window)
  3522. (org-switch-to-buffer-other-window abuf))
  3523. ((eq org-agenda-window-setup 'other-frame)
  3524. (switch-to-buffer-other-frame abuf))
  3525. ((eq org-agenda-window-setup 'other-tab)
  3526. (if (fboundp 'switch-to-buffer-other-tab)
  3527. (switch-to-buffer-other-tab abuf)
  3528. (user-error "Your version of Emacs does not have tab bar support")))
  3529. ((eq org-agenda-window-setup 'only-window)
  3530. (delete-other-windows)
  3531. (pop-to-buffer-same-window abuf))
  3532. ((eq org-agenda-window-setup 'reorganize-frame)
  3533. (delete-other-windows)
  3534. (org-switch-to-buffer-other-window abuf)))
  3535. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3536. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3537. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3538. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3539. ;; Additional test in case agenda is invoked from within agenda
  3540. ;; buffer via elisp link.
  3541. (unless (equal (current-buffer) abuf)
  3542. (pop-to-buffer-same-window abuf))
  3543. (setq org-agenda-pre-window-conf
  3544. (or wconf org-agenda-pre-window-conf))))
  3545. (defun org-agenda-prepare (&optional name)
  3546. (let ((filter-alist (when org-agenda-persistent-filter
  3547. (with-current-buffer
  3548. (get-buffer-create org-agenda-buffer-name)
  3549. `((tag . ,org-agenda-tag-filter)
  3550. (re . ,org-agenda-regexp-filter)
  3551. (effort . ,org-agenda-effort-filter)
  3552. (cat . ,org-agenda-category-filter))))))
  3553. (if (org-agenda-use-sticky-p)
  3554. (progn
  3555. (put 'org-agenda-tag-filter :preset-filter nil)
  3556. (put 'org-agenda-category-filter :preset-filter nil)
  3557. (put 'org-agenda-regexp-filter :preset-filter nil)
  3558. (put 'org-agenda-effort-filter :preset-filter nil)
  3559. ;; Popup existing buffer
  3560. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3561. filter-alist)
  3562. (message "Sticky Agenda buffer, use `r' to refresh")
  3563. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3564. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3565. (setq org-todo-keywords-for-agenda nil)
  3566. (put 'org-agenda-tag-filter :preset-filter
  3567. org-agenda-tag-filter-preset)
  3568. (put 'org-agenda-category-filter :preset-filter
  3569. org-agenda-category-filter-preset)
  3570. (put 'org-agenda-regexp-filter :preset-filter
  3571. org-agenda-regexp-filter-preset)
  3572. (put 'org-agenda-effort-filter :preset-filter
  3573. org-agenda-effort-filter-preset)
  3574. (if org-agenda-multi
  3575. (progn
  3576. (setq buffer-read-only nil)
  3577. (goto-char (point-max))
  3578. (unless (or (bobp) org-agenda-compact-blocks
  3579. (not org-agenda-block-separator))
  3580. (insert "\n"
  3581. (if (stringp org-agenda-block-separator)
  3582. org-agenda-block-separator
  3583. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3584. "\n"))
  3585. (narrow-to-region (point) (point-max)))
  3586. (setq org-done-keywords-for-agenda nil)
  3587. ;; Setting any org variables that are in org-agenda-local-vars
  3588. ;; list need to be done after the prepare call
  3589. (org-agenda-prepare-window
  3590. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3591. (setq buffer-read-only nil)
  3592. (org-agenda-reset-markers)
  3593. (let ((inhibit-read-only t)) (erase-buffer))
  3594. (org-agenda-mode)
  3595. (setq org-agenda-buffer (current-buffer))
  3596. (setq org-agenda-contributing-files nil)
  3597. (setq org-agenda-columns-active nil)
  3598. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3599. (setq org-todo-keywords-for-agenda
  3600. (org-uniquify org-todo-keywords-for-agenda))
  3601. (setq org-done-keywords-for-agenda
  3602. (org-uniquify org-done-keywords-for-agenda))
  3603. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3604. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3605. (and name (not org-agenda-name)
  3606. (setq-local org-agenda-name name)))
  3607. (setq buffer-read-only nil))))
  3608. (defvar org-overriding-columns-format)
  3609. (defvar org-local-columns-format)
  3610. (defun org-agenda-finalize ()
  3611. "Finishing touch for the agenda buffer.
  3612. This function is called just before displaying the agenda. If
  3613. you want to add your own functions to the finalization of the
  3614. agenda display, configure `org-agenda-finalize-hook'."
  3615. (unless org-agenda-multi
  3616. (let ((inhibit-read-only t))
  3617. (save-excursion
  3618. (goto-char (point-min))
  3619. (save-excursion
  3620. (while (org-activate-links (point-max))
  3621. (goto-char (match-end 0))))
  3622. (unless (eq org-agenda-remove-tags t)
  3623. (org-agenda-align-tags))
  3624. (unless org-agenda-with-colors
  3625. (remove-text-properties (point-min) (point-max) '(face nil)))
  3626. (when (bound-and-true-p org-overriding-columns-format)
  3627. (setq-local org-local-columns-format
  3628. org-overriding-columns-format))
  3629. (when org-agenda-view-columns-initially
  3630. (org-agenda-columns))
  3631. (when org-agenda-fontify-priorities
  3632. (org-agenda-fontify-priorities))
  3633. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3634. (org-agenda-dim-blocked-tasks))
  3635. (org-agenda-mark-clocking-task)
  3636. (when org-agenda-entry-text-mode
  3637. (org-agenda-entry-text-hide)
  3638. (org-agenda-entry-text-show))
  3639. (when (and (featurep 'org-habit)
  3640. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3641. (org-habit-insert-consistency-graphs))
  3642. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3643. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3644. (and (listp org-agenda-show-inherited-tags)
  3645. (memq org-agenda-type org-agenda-show-inherited-tags))
  3646. (and (eq org-agenda-show-inherited-tags t)
  3647. (or (eq org-agenda-use-tag-inheritance t)
  3648. (and (listp org-agenda-use-tag-inheritance)
  3649. (not (memq org-agenda-type
  3650. org-agenda-use-tag-inheritance))))))
  3651. (let (mrk)
  3652. (save-excursion
  3653. (goto-char (point-min))
  3654. (while (equal (forward-line) 0)
  3655. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3656. (put-text-property (point-at-bol) (point-at-eol)
  3657. 'tags
  3658. (org-with-point-at mrk
  3659. (org-get-tags))))))))
  3660. (setq org-agenda-represented-tags nil
  3661. org-agenda-represented-categories nil)
  3662. (when org-agenda-top-headline-filter
  3663. (org-agenda-filter-top-headline-apply
  3664. org-agenda-top-headline-filter))
  3665. (when org-agenda-tag-filter
  3666. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3667. (when (get 'org-agenda-tag-filter :preset-filter)
  3668. (org-agenda-filter-apply
  3669. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3670. (when org-agenda-category-filter
  3671. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3672. (when (get 'org-agenda-category-filter :preset-filter)
  3673. (org-agenda-filter-apply
  3674. (get 'org-agenda-category-filter :preset-filter) 'category))
  3675. (when org-agenda-regexp-filter
  3676. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3677. (when (get 'org-agenda-regexp-filter :preset-filter)
  3678. (org-agenda-filter-apply
  3679. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3680. (when org-agenda-effort-filter
  3681. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3682. (when (get 'org-agenda-effort-filter :preset-filter)
  3683. (org-agenda-filter-apply
  3684. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3685. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3686. (run-hooks 'org-agenda-finalize-hook))))
  3687. (defun org-agenda-mark-clocking-task ()
  3688. "Mark the current clock entry in the agenda if it is present."
  3689. ;; We need to widen when `org-agenda-finalize' is called from
  3690. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3691. (when (bound-and-true-p org-clock-current-task)
  3692. (save-restriction
  3693. (widen)
  3694. (org-agenda-unmark-clocking-task)
  3695. (when (marker-buffer org-clock-hd-marker)
  3696. (save-excursion
  3697. (goto-char (point-min))
  3698. (let (s ov)
  3699. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3700. (goto-char s)
  3701. (when (equal (org-get-at-bol 'org-hd-marker)
  3702. org-clock-hd-marker)
  3703. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3704. (overlay-put ov 'type 'org-agenda-clocking)
  3705. (overlay-put ov 'face 'org-agenda-clocking)
  3706. (overlay-put ov 'help-echo
  3707. "The clock is running in this item")))))))))
  3708. (defun org-agenda-unmark-clocking-task ()
  3709. "Unmark the current clocking task."
  3710. (mapc (lambda (o)
  3711. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3712. (delete-overlay o)))
  3713. (overlays-in (point-min) (point-max))))
  3714. (defun org-agenda-fontify-priorities ()
  3715. "Make highest priority lines bold, and lowest italic."
  3716. (interactive)
  3717. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3718. (delete-overlay o)))
  3719. (overlays-in (point-min) (point-max)))
  3720. (save-excursion
  3721. (let (b e p ov h l)
  3722. (goto-char (point-min))
  3723. (while (re-search-forward org-priority-regexp nil t)
  3724. (setq h (or (get-char-property (point) 'org-priority-highest)
  3725. org-priority-highest)
  3726. l (or (get-char-property (point) 'org-priority-lowest)
  3727. org-priority-lowest)
  3728. p (string-to-char (match-string 2))
  3729. b (match-beginning 1)
  3730. e (if (eq org-agenda-fontify-priorities 'cookies)
  3731. (1+ (match-end 2))
  3732. (point-at-eol))
  3733. ov (make-overlay b e))
  3734. (overlay-put
  3735. ov 'face
  3736. (let ((special-face
  3737. (cond ((org-face-from-face-or-color
  3738. 'priority 'org-priority
  3739. (cdr (assoc p org-priority-faces))))
  3740. ((and (listp org-agenda-fontify-priorities)
  3741. (org-face-from-face-or-color
  3742. 'priority 'org-priority
  3743. (cdr (assoc p org-agenda-fontify-priorities)))))
  3744. ((equal p l) 'italic)
  3745. ((equal p h) 'bold))))
  3746. (if special-face (list special-face 'org-priority) 'org-priority)))
  3747. (overlay-put ov 'org-type 'org-priority)))))
  3748. (defvar org-depend-tag-blocked)
  3749. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3750. "Dim currently blocked TODOs in the agenda display.
  3751. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3752. dimming them." ;FIXME: The arg isn't used, actually!
  3753. (interactive "P")
  3754. (when (called-interactively-p 'interactive)
  3755. (message "Dim or hide blocked tasks..."))
  3756. (dolist (o (overlays-in (point-min) (point-max)))
  3757. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3758. (delete-overlay o)))
  3759. (save-excursion
  3760. (let ((inhibit-read-only t))
  3761. (goto-char (point-min))
  3762. (while (let ((pos (text-property-not-all
  3763. (point) (point-max) 'org-todo-blocked nil)))
  3764. (when pos (goto-char pos)))
  3765. (let* ((invisible
  3766. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3767. (todo-blocked
  3768. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3769. (ov (make-overlay (if invisible
  3770. (line-end-position 0)
  3771. (line-beginning-position))
  3772. (line-end-position))))
  3773. (when todo-blocked
  3774. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3775. (when invisible
  3776. (org-agenda-filter-hide-line 'todo-blocked)))
  3777. (if (= (point-max) (line-end-position))
  3778. (goto-char (point-max))
  3779. (move-beginning-of-line 2)))))
  3780. (when (called-interactively-p 'interactive)
  3781. (message "Dim or hide blocked tasks...done")))
  3782. (defun org-agenda--mark-blocked-entry (entry)
  3783. "If ENTRY is blocked, mark it for fontification or invisibility.
  3784. If the header at `org-hd-marker' is blocked according to
  3785. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3786. \\='invisible and the header is not blocked by checkboxes, set the
  3787. text property `org-todo-blocked' to `invisible', otherwise set it
  3788. to t."
  3789. (when (get-text-property 0 'todo-state entry)
  3790. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3791. (org-blocked-by-checkboxes nil)
  3792. ;; Necessary so that `org-entry-blocked-p' does not change
  3793. ;; the buffer.
  3794. (org-depend-tag-blocked nil))
  3795. (when entry-marker
  3796. (let ((blocked
  3797. (with-current-buffer (marker-buffer entry-marker)
  3798. (save-excursion
  3799. (goto-char entry-marker)
  3800. (org-entry-blocked-p)))))
  3801. (when blocked
  3802. (let ((really-invisible
  3803. (and (not org-blocked-by-checkboxes)
  3804. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3805. (put-text-property
  3806. 0 (length entry) 'org-todo-blocked
  3807. (if really-invisible 'invisible t)
  3808. entry)
  3809. (put-text-property
  3810. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3811. entry)
  3812. (defvar org-agenda-skip-function nil
  3813. "Function to be called at each match during agenda construction.
  3814. If this function returns nil, the current match should not be skipped.
  3815. Otherwise, the function must return a position from where the search
  3816. should be continued.
  3817. This may also be a Lisp form, it will be evaluated.
  3818. Never set this variable using `setq' or so, because then it will apply
  3819. to all future agenda commands. If you do want a global skipping condition,
  3820. use the option `org-agenda-skip-function-global' instead.
  3821. The correct usage for `org-agenda-skip-function' is to bind it with
  3822. `let' to scope it dynamically into the agenda-constructing command.
  3823. A good way to set it is through options in `org-agenda-custom-commands'.")
  3824. (defun org-agenda-skip (&optional element)
  3825. "Throw to `:skip' in places that should be skipped.
  3826. Also moves point to the end of the skipped region, so that search can
  3827. continue from there.
  3828. Optional argument ELEMENT contains element at point."
  3829. (let ((p (point-at-bol)) to)
  3830. (when (or
  3831. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3832. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3833. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3834. (org-end-of-subtree t element))
  3835. (and (member org-archive-tag org-file-tags)
  3836. (goto-char (point-max)))))
  3837. (and org-agenda-skip-comment-trees
  3838. (org-in-commented-heading-p nil element)
  3839. (org-end-of-subtree t element))
  3840. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3841. (org-agenda-skip-eval org-agenda-skip-function)))
  3842. (goto-char to))
  3843. (org-in-src-block-p t))
  3844. (throw :skip t))))
  3845. (defun org-agenda-skip-eval (form)
  3846. "If FORM is a function or a list, call (or eval) it and return the result.
  3847. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3848. and match data are returned to the previous state no matter what these
  3849. functions do."
  3850. (let (fp)
  3851. (and form
  3852. (or (setq fp (functionp form))
  3853. (consp form))
  3854. (save-excursion
  3855. (save-match-data
  3856. (if fp
  3857. (funcall form)
  3858. (eval form t)))))))
  3859. (defvar org-agenda-markers nil
  3860. "List of all currently active markers created by `org-agenda'.")
  3861. (defvar org-agenda-last-marker-time (float-time)
  3862. "Creation time of the last agenda marker.")
  3863. (defun org-agenda-new-marker (&optional pos)
  3864. "Return a new agenda marker.
  3865. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3866. of these markers and resets them when they are no longer in use."
  3867. (let ((m (copy-marker (or pos (point)) t)))
  3868. (setq org-agenda-last-marker-time (float-time))
  3869. (if org-agenda-buffer
  3870. (with-current-buffer org-agenda-buffer
  3871. (push m org-agenda-markers))
  3872. (push m org-agenda-markers))
  3873. m))
  3874. (defun org-agenda-reset-markers ()
  3875. "Reset markers created by `org-agenda'."
  3876. (while org-agenda-markers
  3877. (move-marker (pop org-agenda-markers) nil)))
  3878. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3879. "Save relative positions of markers in region.
  3880. This check for agenda markers in all agenda buffers currently active."
  3881. (dolist (buf (buffer-list))
  3882. (with-current-buffer buf
  3883. (when (eq major-mode 'org-agenda-mode)
  3884. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3885. org-agenda-markers)))))
  3886. ;;; Entry text mode
  3887. (defun org-agenda-entry-text-show-here ()
  3888. "Add some text from the entry as context to the current line."
  3889. (let (m txt o)
  3890. (setq m (org-get-at-bol 'org-hd-marker))
  3891. (unless (marker-buffer m)
  3892. (error "No marker points to an entry here"))
  3893. (setq txt (concat "\n" (org-no-properties
  3894. (org-agenda-get-some-entry-text
  3895. m org-agenda-entry-text-maxlines
  3896. org-agenda-entry-text-leaders))))
  3897. (when (string-match "\\S-" txt)
  3898. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3899. (overlay-put o 'evaporate t)
  3900. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3901. (overlay-put o 'after-string txt))))
  3902. (defun org-agenda-entry-text-show ()
  3903. "Add entry context for all agenda lines."
  3904. (interactive)
  3905. (save-excursion
  3906. (goto-char (point-max))
  3907. (beginning-of-line 1)
  3908. (while (not (bobp))
  3909. (when (org-get-at-bol 'org-hd-marker)
  3910. (org-agenda-entry-text-show-here))
  3911. (beginning-of-line 0))))
  3912. (defun org-agenda-entry-text-hide ()
  3913. "Remove any shown entry context."
  3914. (mapc (lambda (o)
  3915. (when (eq (overlay-get o 'org-overlay-type)
  3916. 'agenda-entry-content)
  3917. (delete-overlay o)))
  3918. (overlays-in (point-min) (point-max))))
  3919. (defun org-agenda-get-day-face (date)
  3920. "Return the face DATE should be displayed with."
  3921. (cond ((and (functionp org-agenda-day-face-function)
  3922. (funcall org-agenda-day-face-function date)))
  3923. ((and (org-agenda-today-p date)
  3924. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3925. 'org-agenda-date-weekend-today)
  3926. ((org-agenda-today-p date) 'org-agenda-date-today)
  3927. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3928. 'org-agenda-date-weekend)
  3929. (t 'org-agenda-date)))
  3930. (defvar org-agenda-show-log-scoped)
  3931. ;;; Agenda Daily/Weekly
  3932. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3933. "Start day for the agenda view.
  3934. Custom commands can set this variable in the options section.
  3935. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3936. input allowed when reading a date through the Org calendar.
  3937. See the docstring of `org-read-date' for details.")
  3938. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3939. (defvar org-arg-loc nil) ; local variable
  3940. ;;;###autoload
  3941. (defun org-agenda-list (&optional arg start-day span with-hour)
  3942. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3943. The view will be for the current day or week, but from the overview buffer
  3944. you will be able to go to other days/weeks.
  3945. With a numeric prefix argument in an interactive call, the agenda will
  3946. span ARG days. Lisp programs should instead specify SPAN to change
  3947. the number of days. SPAN defaults to `org-agenda-span'.
  3948. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3949. given in `org-agenda-start-on-weekday'.
  3950. When WITH-HOUR is non-nil, only include scheduled and deadline
  3951. items if they have an hour specification like [h]h:mm."
  3952. (interactive "P")
  3953. (when org-agenda-overriding-arguments
  3954. (setq arg (car org-agenda-overriding-arguments)
  3955. start-day (nth 1 org-agenda-overriding-arguments)
  3956. span (nth 2 org-agenda-overriding-arguments)))
  3957. (when (and (integerp arg) (> arg 0))
  3958. (setq span arg arg nil))
  3959. (when (numberp span)
  3960. (unless (< 0 span)
  3961. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3962. (catch 'exit
  3963. (setq org-agenda-buffer-name
  3964. (org-agenda--get-buffer-name
  3965. (and org-agenda-sticky
  3966. (cond ((and org-keys (stringp org-match))
  3967. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3968. (org-keys
  3969. (format "*Org Agenda(%s)*" org-keys))
  3970. (t "*Org Agenda(a)*")))))
  3971. (org-agenda-prepare "Day/Week")
  3972. (setq start-day (or start-day org-agenda-start-day))
  3973. (when (stringp start-day)
  3974. ;; Convert to an absolute day number
  3975. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3976. (org-compile-prefix-format 'agenda)
  3977. (org-set-sorting-strategy 'agenda)
  3978. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3979. (today (org-today))
  3980. (sd (or start-day today))
  3981. (ndays (org-agenda-span-to-ndays span sd))
  3982. (org-agenda-start-on-weekday
  3983. (and (or (eq ndays 7) (eq ndays 14))
  3984. org-agenda-start-on-weekday))
  3985. (thefiles (org-agenda-files nil 'ifmode))
  3986. (files thefiles)
  3987. (start (if (or (null org-agenda-start-on-weekday)
  3988. (< ndays 7))
  3989. sd
  3990. (let* ((nt (calendar-day-of-week
  3991. (calendar-gregorian-from-absolute sd)))
  3992. (n1 org-agenda-start-on-weekday)
  3993. (d (- nt n1)))
  3994. (- sd (+ (if (< d 0) 7 0) d)))))
  3995. (day-numbers (list start))
  3996. (day-cnt 0)
  3997. (inhibit-redisplay (not debug-on-error))
  3998. (org-agenda-show-log-scoped org-agenda-show-log)
  3999. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4000. clocktable-start clocktable-end) ;; filter
  4001. (setq org-agenda-redo-command
  4002. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4003. (dotimes (_ (1- ndays))
  4004. (push (1+ (car day-numbers)) day-numbers))
  4005. (setq day-numbers (nreverse day-numbers))
  4006. (setq clocktable-start (car day-numbers)
  4007. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4008. (setq-local org-starting-day (car day-numbers))
  4009. (setq-local org-arg-loc arg)
  4010. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4011. (unless org-agenda-compact-blocks
  4012. (let* ((d1 (car day-numbers))
  4013. (d2 (org-last day-numbers))
  4014. (w1 (org-days-to-iso-week d1))
  4015. (w2 (org-days-to-iso-week d2)))
  4016. (setq s (point))
  4017. (org-agenda--insert-overriding-header
  4018. (concat (org-agenda-span-name span)
  4019. "-agenda"
  4020. (cond ((<= 350 (- d2 d1)) "")
  4021. ((= w1 w2) (format " (W%02d)" w1))
  4022. (t (format " (W%02d-W%02d)" w1 w2)))
  4023. ":\n")))
  4024. ;; Add properties if we actually inserted a header.
  4025. (when (> (point) s)
  4026. (add-text-properties s (1- (point))
  4027. (list 'face 'org-agenda-structure
  4028. 'org-date-line t))
  4029. (org-agenda-mark-header-line s)))
  4030. (while (setq d (pop day-numbers))
  4031. (setq date (calendar-gregorian-from-absolute d)
  4032. s (point))
  4033. (if (or (setq todayp (= d today))
  4034. (and (not start-pos) (= d sd)))
  4035. (setq start-pos (point))
  4036. (when (and start-pos (not end-pos))
  4037. (setq end-pos (point))))
  4038. (setq files thefiles
  4039. rtnall nil)
  4040. (while (setq file (pop files))
  4041. (catch 'nextfile
  4042. (org-check-agenda-file file)
  4043. (let ((org-agenda-entry-types org-agenda-entry-types))
  4044. ;; Starred types override non-starred equivalents
  4045. (when (member :deadline* org-agenda-entry-types)
  4046. (setq org-agenda-entry-types
  4047. (delq :deadline org-agenda-entry-types)))
  4048. (when (member :scheduled* org-agenda-entry-types)
  4049. (setq org-agenda-entry-types
  4050. (delq :scheduled org-agenda-entry-types)))
  4051. ;; Honor with-hour
  4052. (when with-hour
  4053. (when (member :deadline org-agenda-entry-types)
  4054. (setq org-agenda-entry-types
  4055. (delq :deadline org-agenda-entry-types))
  4056. (push :deadline* org-agenda-entry-types))
  4057. (when (member :scheduled org-agenda-entry-types)
  4058. (setq org-agenda-entry-types
  4059. (delq :scheduled org-agenda-entry-types))
  4060. (push :scheduled* org-agenda-entry-types)))
  4061. (unless org-agenda-include-deadlines
  4062. (setq org-agenda-entry-types
  4063. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4064. (cond
  4065. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4066. (setq rtn (org-agenda-get-day-entries
  4067. file date :closed)))
  4068. (org-agenda-show-log-scoped
  4069. (setq rtn (apply #'org-agenda-get-day-entries
  4070. file date
  4071. (append '(:closed) org-agenda-entry-types))))
  4072. (t
  4073. (setq rtn (apply #'org-agenda-get-day-entries
  4074. file date
  4075. org-agenda-entry-types)))))
  4076. (setq rtnall (append rtnall rtn)))) ;; all entries
  4077. (when org-agenda-include-diary
  4078. (let ((org-agenda-search-headline-for-time t))
  4079. (require 'diary-lib)
  4080. (setq rtn (org-get-entries-from-diary date))
  4081. (setq rtnall (append rtnall rtn))))
  4082. (when (or rtnall org-agenda-show-all-dates)
  4083. (setq day-cnt (1+ day-cnt))
  4084. (insert
  4085. (if (stringp org-agenda-format-date)
  4086. (format-time-string org-agenda-format-date
  4087. (org-time-from-absolute date))
  4088. (funcall org-agenda-format-date date))
  4089. "\n")
  4090. (put-text-property s (1- (point)) 'face
  4091. (org-agenda-get-day-face date))
  4092. (put-text-property s (1- (point)) 'org-date-line t)
  4093. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4094. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4095. (when todayp
  4096. (put-text-property s (1- (point)) 'org-today t))
  4097. (setq rtnall
  4098. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4099. (when rtnall (insert ;; all entries
  4100. (org-agenda-finalize-entries rtnall 'agenda)
  4101. "\n"))
  4102. (put-text-property s (1- (point)) 'day d)
  4103. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4104. (when (and org-agenda-clockreport-mode clocktable-start)
  4105. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4106. ;; the above line is to ensure the restricted range!
  4107. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4108. tbl)
  4109. (setq p (org-plist-delete p :block))
  4110. (setq p (plist-put p :tstart clocktable-start))
  4111. (setq p (plist-put p :tend clocktable-end))
  4112. (setq p (plist-put p :scope 'agenda))
  4113. (setq tbl (apply #'org-clock-get-clocktable p))
  4114. (when org-agenda-clock-report-header
  4115. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4116. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4117. (insert "\n")))
  4118. (insert tbl)))
  4119. (goto-char (point-min))
  4120. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4121. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4122. (and (pos-visible-in-window-p (point-min))
  4123. (pos-visible-in-window-p (point-max))))
  4124. (goto-char (1- (point-max)))
  4125. (recenter -1)
  4126. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4127. (goto-char (or start-pos 1))
  4128. (recenter 1)))
  4129. (goto-char (or start-pos 1))
  4130. (add-text-properties (point-min) (point-max)
  4131. `(org-agenda-type agenda
  4132. org-last-args (,arg ,start-day ,span)
  4133. org-redo-cmd ,org-agenda-redo-command
  4134. org-series-cmd ,org-cmd))
  4135. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4136. (org-agenda-show-clocking-issues))
  4137. (org-agenda-finalize)
  4138. (setq buffer-read-only t)
  4139. (message ""))))
  4140. (defun org-agenda-ndays-to-span (n)
  4141. "Return a span symbol for a span of N days, or N if none matches."
  4142. (cond ((symbolp n) n)
  4143. ((= n 1) 'day)
  4144. ((= n 7) 'week)
  4145. ((= n 14) 'fortnight)
  4146. (t n)))
  4147. (defun org-agenda-span-to-ndays (span &optional start-day)
  4148. "Return ndays from SPAN, possibly starting at START-DAY.
  4149. START-DAY is an absolute time value."
  4150. (cond ((numberp span) span)
  4151. ((eq span 'day) 1)
  4152. ((eq span 'week) 7)
  4153. ((eq span 'fortnight) 14)
  4154. ((eq span 'month)
  4155. (let ((date (calendar-gregorian-from-absolute start-day)))
  4156. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4157. ((eq span 'year)
  4158. (let ((date (calendar-gregorian-from-absolute start-day)))
  4159. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4160. (defun org-agenda-span-name (span)
  4161. "Return a SPAN name."
  4162. (if (null span)
  4163. ""
  4164. (if (symbolp span)
  4165. (capitalize (symbol-name span))
  4166. (format "%d days" span))))
  4167. ;;; Agenda word search
  4168. (defvar org-agenda-search-history nil)
  4169. (defvar org-search-syntax-table nil
  4170. "Special syntax table for Org search.
  4171. In this table, we have single quotes not as word constituents, to
  4172. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4173. (defvar org-mode-syntax-table) ; From org.el
  4174. (defun org-search-syntax-table ()
  4175. (unless org-search-syntax-table
  4176. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4177. (modify-syntax-entry ?' "." org-search-syntax-table)
  4178. (modify-syntax-entry ?` "." org-search-syntax-table))
  4179. org-search-syntax-table)
  4180. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4181. ;;;###autoload
  4182. (defun org-search-view (&optional todo-only string edit-at)
  4183. "Show all entries that contain a phrase or words or regular expressions.
  4184. With optional prefix argument TODO-ONLY, only consider entries that are
  4185. TODO entries. The argument STRING can be used to pass a default search
  4186. string into this function. If EDIT-AT is non-nil, it means that the
  4187. user should get a chance to edit this string, with cursor at position
  4188. EDIT-AT.
  4189. The search string can be viewed either as a phrase that should be found as
  4190. is, or it can be broken into a number of snippets, each of which must match
  4191. in a Boolean way to select an entry. The default depends on the variable
  4192. `org-agenda-search-view-always-boolean'.
  4193. Even if this is turned off (the default) you can always switch to
  4194. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4195. The default is a direct search of the whole phrase, where each space in
  4196. the search string can expand to an arbitrary amount of whitespace,
  4197. including newlines.
  4198. If using a Boolean search, the search string is split on whitespace and
  4199. each snippet is searched separately, with logical AND to select an entry.
  4200. Words prefixed with a minus must *not* occur in the entry. Words without
  4201. a prefix or prefixed with a plus must occur in the entry. Matching is
  4202. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4203. match whole words, not parts of a word) if
  4204. `org-agenda-search-view-force-full-words' is set (default is nil).
  4205. Boolean search snippets enclosed by curly braces are interpreted as
  4206. regular expressions that must or (when preceded with \"-\") must not
  4207. match in the entry. Snippets enclosed into double quotes will be taken
  4208. as a whole, to include whitespace.
  4209. - If the search string starts with an asterisk, search only in headlines.
  4210. - If (possibly after the leading star) the search string starts with an
  4211. exclamation mark, this also means to look at TODO entries only, an effect
  4212. that can also be achieved with a prefix argument.
  4213. - If (possibly after star and exclamation mark) the search string starts
  4214. with a colon, this will mean that the (non-regexp) snippets of the
  4215. Boolean search must match as full words.
  4216. This command searches the agenda files, and in addition the files
  4217. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4218. is active."
  4219. (interactive "P")
  4220. (when org-agenda-overriding-arguments
  4221. (setq todo-only (car org-agenda-overriding-arguments)
  4222. string (nth 1 org-agenda-overriding-arguments)
  4223. edit-at (nth 2 org-agenda-overriding-arguments)))
  4224. (let* ((props (list 'face nil
  4225. 'done-face 'org-agenda-done
  4226. 'org-not-done-regexp org-not-done-regexp
  4227. 'org-todo-regexp org-todo-regexp
  4228. 'org-complex-heading-regexp org-complex-heading-regexp
  4229. 'mouse-face 'highlight
  4230. 'help-echo "mouse-2 or RET jump to location"))
  4231. (full-words org-agenda-search-view-force-full-words)
  4232. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4233. regexp rtn rtnall files file pos inherited-tags
  4234. marker category level tags c neg re boolean
  4235. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4236. (unless (and (not edit-at)
  4237. (stringp string)
  4238. (string-match "\\S-" string))
  4239. (setq string (read-string
  4240. (if org-agenda-search-view-always-boolean
  4241. "[+-]Word/{Regexp} ...: "
  4242. "Phrase or [+-]Word/{Regexp} ...: ")
  4243. (cond
  4244. ((integerp edit-at) (cons string edit-at))
  4245. (edit-at string))
  4246. 'org-agenda-search-history)))
  4247. (catch 'exit
  4248. (setq org-agenda-buffer-name
  4249. (org-agenda--get-buffer-name
  4250. (and org-agenda-sticky
  4251. (if (stringp string)
  4252. (format "*Org Agenda(%s:%s)*"
  4253. (or org-keys (or (and todo-only "S") "s"))
  4254. string)
  4255. (format "*Org Agenda(%s)*"
  4256. (or (and todo-only "S") "s"))))))
  4257. (org-agenda-prepare "SEARCH")
  4258. (org-compile-prefix-format 'search)
  4259. (org-set-sorting-strategy 'search)
  4260. (setq org-agenda-redo-command
  4261. (list 'org-search-view (if todo-only t nil)
  4262. (list 'if 'current-prefix-arg nil string)))
  4263. (setq org-agenda-query-string string)
  4264. (if (equal (string-to-char string) ?*)
  4265. (setq hdl-only t
  4266. words (substring string 1))
  4267. (setq words string))
  4268. (when (equal (string-to-char words) ?!)
  4269. (setq todo-only t
  4270. words (substring words 1)))
  4271. (when (equal (string-to-char words) ?:)
  4272. (setq full-words t
  4273. words (substring words 1)))
  4274. (when (or org-agenda-search-view-always-boolean
  4275. (member (string-to-char words) '(?- ?+ ?\{)))
  4276. (setq boolean t))
  4277. (setq words (split-string words))
  4278. (let (www w)
  4279. (while (setq w (pop words))
  4280. (while (and (string-match "\\\\\\'" w) words)
  4281. (setq w (concat (substring w 0 -1) " " (pop words))))
  4282. (push w www))
  4283. (setq words (nreverse www) www nil)
  4284. (while (setq w (pop words))
  4285. (when (and (string-match "\\`[-+]?{" w)
  4286. (not (string-match "}\\'" w)))
  4287. (while (and words (not (string-match "}\\'" (car words))))
  4288. (setq w (concat w " " (pop words))))
  4289. (setq w (concat w " " (pop words))))
  4290. (push w www))
  4291. (setq words (nreverse www)))
  4292. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4293. (when boolean
  4294. (let (wds w)
  4295. (while (setq w (pop words))
  4296. (when (or (equal (substring w 0 1) "\"")
  4297. (and (> (length w) 1)
  4298. (member (substring w 0 1) '("+" "-"))
  4299. (equal (substring w 1 2) "\"")))
  4300. (while (and words (not (equal (substring w -1) "\"")))
  4301. (setq w (concat w " " (pop words)))))
  4302. (and (string-match "\\`\\([-+]?\\)\"" w)
  4303. (setq w (replace-match "\\1" nil nil w)))
  4304. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4305. (push w wds))
  4306. (setq words (nreverse wds))))
  4307. (if boolean
  4308. (mapc (lambda (w)
  4309. (setq c (string-to-char w))
  4310. (if (equal c ?-)
  4311. (setq neg t w (substring w 1))
  4312. (if (equal c ?+)
  4313. (setq neg nil w (substring w 1))
  4314. (setq neg nil)))
  4315. (if (string-match "\\`{.*}\\'" w)
  4316. (setq re (substring w 1 -1))
  4317. (if full-words
  4318. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4319. (setq re (regexp-quote (downcase w)))))
  4320. (if neg (push re regexps-) (push re regexps+)))
  4321. words)
  4322. (push (mapconcat #'regexp-quote words "\\s-+")
  4323. regexps+))
  4324. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4325. (if (not regexps+)
  4326. (setq regexp org-outline-regexp-bol)
  4327. (setq regexp (pop regexps+))
  4328. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4329. regexp))))
  4330. (setq files (org-agenda-files nil 'ifmode))
  4331. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4332. ;; restriction.
  4333. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4334. (pop org-agenda-text-search-extra-files)
  4335. (unless (get 'org-agenda-files 'org-restrict)
  4336. (setq files (org-add-archive-files files))))
  4337. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4338. ;; non-existent ones.
  4339. (setq files (cl-remove-duplicates
  4340. (append files org-agenda-text-search-extra-files)
  4341. :test (lambda (a b)
  4342. (and (file-exists-p a)
  4343. (file-exists-p b)
  4344. (file-equal-p a b))))
  4345. rtnall nil)
  4346. (while (setq file (pop files))
  4347. (setq ee nil)
  4348. (catch 'nextfile
  4349. (org-check-agenda-file file)
  4350. (setq buffer (if (file-exists-p file)
  4351. (org-get-agenda-file-buffer file)
  4352. (error "No such file %s" file)))
  4353. (unless buffer
  4354. ;; If file does not exist, make sure an error message is sent
  4355. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4356. file))))
  4357. (with-current-buffer buffer
  4358. (with-syntax-table (org-search-syntax-table)
  4359. (unless (derived-mode-p 'org-mode)
  4360. (error "Agenda file %s is not in Org mode" file))
  4361. (let ((case-fold-search t))
  4362. (save-excursion
  4363. (save-restriction
  4364. (if (eq buffer org-agenda-restrict)
  4365. (narrow-to-region org-agenda-restrict-begin
  4366. org-agenda-restrict-end)
  4367. (widen))
  4368. (goto-char (point-min))
  4369. (unless (or (org-at-heading-p)
  4370. (outline-next-heading))
  4371. (throw 'nextfile t))
  4372. (goto-char (max (point-min) (1- (point))))
  4373. (while (re-search-forward regexp nil t)
  4374. (org-back-to-heading t)
  4375. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4376. (> (org-reduced-level (org-outline-level))
  4377. org-agenda-search-view-max-outline-level)
  4378. (forward-line -1)
  4379. (org-back-to-heading t)))
  4380. (skip-chars-forward "* ")
  4381. (setq beg (point-at-bol)
  4382. beg1 (point)
  4383. end (progn
  4384. (outline-next-heading)
  4385. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4386. (> (org-reduced-level (org-outline-level))
  4387. org-agenda-search-view-max-outline-level)
  4388. (forward-line 1)
  4389. (outline-next-heading)))
  4390. (point)))
  4391. (catch :skip
  4392. (goto-char beg)
  4393. (org-agenda-skip)
  4394. (setq str (buffer-substring-no-properties
  4395. (point-at-bol)
  4396. (if hdl-only (point-at-eol) end)))
  4397. (mapc (lambda (wr) (when (string-match wr str)
  4398. (goto-char (1- end))
  4399. (throw :skip t)))
  4400. regexps-)
  4401. (mapc (lambda (wr) (unless (string-match wr str)
  4402. (goto-char (1- end))
  4403. (throw :skip t)))
  4404. (if todo-only
  4405. (cons (concat "^\\*+[ \t]+"
  4406. org-not-done-regexp)
  4407. regexps+)
  4408. regexps+))
  4409. (goto-char beg)
  4410. (setq marker (org-agenda-new-marker (point))
  4411. category (org-get-category)
  4412. level (make-string (org-reduced-level (org-outline-level)) ? )
  4413. inherited-tags
  4414. (or (eq org-agenda-show-inherited-tags 'always)
  4415. (and (listp org-agenda-show-inherited-tags)
  4416. (memq 'todo org-agenda-show-inherited-tags))
  4417. (and (eq org-agenda-show-inherited-tags t)
  4418. (or (eq org-agenda-use-tag-inheritance t)
  4419. (memq 'todo org-agenda-use-tag-inheritance))))
  4420. tags (org-get-tags nil (not inherited-tags))
  4421. txt (org-agenda-format-item
  4422. ""
  4423. (buffer-substring-no-properties
  4424. beg1 (point-at-eol))
  4425. level category tags t))
  4426. (org-add-props txt props
  4427. 'org-marker marker 'org-hd-marker marker
  4428. 'org-todo-regexp org-todo-regexp
  4429. 'level level
  4430. 'org-complex-heading-regexp org-complex-heading-regexp
  4431. 'priority 1000
  4432. 'type "search")
  4433. (push txt ee)
  4434. (goto-char (1- end))))))))))
  4435. (setq rtn (nreverse ee))
  4436. (setq rtnall (append rtnall rtn)))
  4437. (org-agenda--insert-overriding-header
  4438. (with-temp-buffer
  4439. (insert "Search words: ")
  4440. (add-text-properties (point-min) (1- (point))
  4441. (list 'face 'org-agenda-structure))
  4442. (setq pos (point))
  4443. (insert string "\n")
  4444. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4445. (setq pos (point))
  4446. (unless org-agenda-multi
  4447. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4448. Press `\\[org-agenda-manipulate-query-add]', \
  4449. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4450. `\\[org-agenda-manipulate-query-add-re]', \
  4451. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4452. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4453. (add-text-properties pos (1- (point))
  4454. (list 'face 'org-agenda-structure-secondary)))
  4455. (buffer-string)))
  4456. (org-agenda-mark-header-line (point-min))
  4457. (when rtnall
  4458. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4459. (goto-char (point-min))
  4460. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4461. (add-text-properties (point-min) (point-max)
  4462. `(org-agenda-type search
  4463. org-last-args (,todo-only ,string ,edit-at)
  4464. org-redo-cmd ,org-agenda-redo-command
  4465. org-series-cmd ,org-cmd))
  4466. (org-agenda-finalize)
  4467. (setq buffer-read-only t))))
  4468. ;;; Agenda TODO list
  4469. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4470. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4471. (concat
  4472. (if (or (equal keywords "ALL") (not keywords))
  4473. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4474. (mapconcat
  4475. (lambda (kw)
  4476. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4477. (org-split-string keywords "|")
  4478. "|"))
  4479. "\n"))
  4480. (defvar org-select-this-todo-keyword nil)
  4481. (defvar org-last-arg nil)
  4482. (defvar crm-separator)
  4483. ;;;###autoload
  4484. (defun org-todo-list (&optional arg)
  4485. "Show all (not done) TODO entries from all agenda files in a single list.
  4486. The prefix arg can be used to select a specific TODO keyword and limit
  4487. the list to these. When using `\\[universal-argument]', you will be prompted
  4488. for a keyword. A numeric prefix directly selects the Nth keyword in
  4489. `org-todo-keywords-1'."
  4490. (interactive "P")
  4491. (when org-agenda-overriding-arguments
  4492. (setq arg org-agenda-overriding-arguments))
  4493. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4494. (let* ((today (org-today))
  4495. (date (calendar-gregorian-from-absolute today))
  4496. (completion-ignore-case t)
  4497. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4498. (catch 'exit
  4499. (setq org-agenda-buffer-name
  4500. (org-agenda--get-buffer-name
  4501. (and org-agenda-sticky
  4502. (if (stringp org-select-this-todo-keyword)
  4503. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4504. org-select-this-todo-keyword)
  4505. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4506. (org-agenda-prepare "TODO")
  4507. (setq kwds org-todo-keywords-for-agenda
  4508. org-select-this-todo-keyword (if (stringp arg) arg
  4509. (and (integerp arg)
  4510. (> arg 0)
  4511. (nth (1- arg) kwds))))
  4512. (when (equal arg '(4))
  4513. (setq org-select-this-todo-keyword
  4514. (mapconcat #'identity
  4515. (let ((crm-separator "|"))
  4516. (completing-read-multiple
  4517. "Keyword (or KWD1|KWD2|...): "
  4518. (mapcar #'list kwds) nil nil))
  4519. "|")))
  4520. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4521. (org-compile-prefix-format 'todo)
  4522. (org-set-sorting-strategy 'todo)
  4523. (setq org-agenda-redo-command
  4524. `(org-todo-list (or (and (numberp current-prefix-arg)
  4525. current-prefix-arg)
  4526. ,org-select-this-todo-keyword
  4527. current-prefix-arg ,arg)))
  4528. (setq files (org-agenda-files nil 'ifmode)
  4529. rtnall nil)
  4530. (while (setq file (pop files))
  4531. (catch 'nextfile
  4532. (org-check-agenda-file file)
  4533. (setq rtn (org-agenda-get-day-entries file date :todo))
  4534. (setq rtnall (append rtnall rtn))))
  4535. (org-agenda--insert-overriding-header
  4536. (with-temp-buffer
  4537. (insert "Global list of TODO items of type: ")
  4538. (add-text-properties (point-min) (1- (point))
  4539. (list 'face 'org-agenda-structure
  4540. 'short-heading
  4541. (concat "ToDo: "
  4542. (or org-select-this-todo-keyword "ALL"))))
  4543. (org-agenda-mark-header-line (point-min))
  4544. (insert (org-agenda-propertize-selected-todo-keywords
  4545. org-select-this-todo-keyword))
  4546. (setq pos (point))
  4547. (unless org-agenda-multi
  4548. (insert (substitute-command-keys "Press \
  4549. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4550. to search again: (0)[ALL]"))
  4551. (let ((n 0))
  4552. (dolist (k kwds)
  4553. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4554. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4555. (insert "\n "))
  4556. (insert " " s))))
  4557. (insert "\n"))
  4558. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4559. (buffer-string)))
  4560. (org-agenda-mark-header-line (point-min))
  4561. (when rtnall
  4562. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4563. (goto-char (point-min))
  4564. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4565. (add-text-properties (point-min) (point-max)
  4566. `(org-agenda-type todo
  4567. org-last-args ,arg
  4568. org-redo-cmd ,org-agenda-redo-command
  4569. org-series-cmd ,org-cmd))
  4570. (org-agenda-finalize)
  4571. (setq buffer-read-only t))))
  4572. ;;; Agenda tags match
  4573. ;;;###autoload
  4574. (defun org-tags-view (&optional todo-only match)
  4575. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4576. The prefix arg TODO-ONLY limits the search to TODO entries."
  4577. (interactive "P")
  4578. (when org-agenda-overriding-arguments
  4579. (setq todo-only (car org-agenda-overriding-arguments)
  4580. match (nth 1 org-agenda-overriding-arguments)))
  4581. (let* ((org-tags-match-list-sublevels
  4582. org-tags-match-list-sublevels)
  4583. (completion-ignore-case t)
  4584. (org--matcher-tags-todo-only todo-only)
  4585. rtn rtnall files file pos matcher
  4586. buffer)
  4587. (when (and (stringp match) (not (string-match "\\S-" match)))
  4588. (setq match nil))
  4589. (catch 'exit
  4590. (setq org-agenda-buffer-name
  4591. (org-agenda--get-buffer-name
  4592. (and org-agenda-sticky
  4593. (if (stringp match)
  4594. (format "*Org Agenda(%s:%s)*"
  4595. (or org-keys (or (and todo-only "M") "m"))
  4596. match)
  4597. (format "*Org Agenda(%s)*"
  4598. (or (and todo-only "M") "m"))))))
  4599. (setq matcher (org-make-tags-matcher match))
  4600. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4601. ;; expanding tags within `org-make-tags-matcher'
  4602. (org-agenda-prepare (concat "TAGS " match))
  4603. (setq match (car matcher)
  4604. matcher (cdr matcher))
  4605. (org-compile-prefix-format 'tags)
  4606. (org-set-sorting-strategy 'tags)
  4607. (setq org-agenda-query-string match)
  4608. (setq org-agenda-redo-command
  4609. (list 'org-tags-view
  4610. `(quote ,org--matcher-tags-todo-only)
  4611. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4612. (setq files (org-agenda-files nil 'ifmode)
  4613. rtnall nil)
  4614. (while (setq file (pop files))
  4615. (catch 'nextfile
  4616. (org-check-agenda-file file)
  4617. (setq buffer (if (file-exists-p file)
  4618. (org-get-agenda-file-buffer file)
  4619. (error "No such file %s" file)))
  4620. (if (not buffer)
  4621. ;; If file does not exist, error message to agenda
  4622. (setq rtn (list
  4623. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4624. rtnall (append rtnall rtn))
  4625. (with-current-buffer buffer
  4626. (unless (derived-mode-p 'org-mode)
  4627. (error "Agenda file %s is not in Org mode" file))
  4628. (save-excursion
  4629. (save-restriction
  4630. (if (eq buffer org-agenda-restrict)
  4631. (narrow-to-region org-agenda-restrict-begin
  4632. org-agenda-restrict-end)
  4633. (widen))
  4634. (setq rtn (org-scan-tags 'agenda
  4635. matcher
  4636. org--matcher-tags-todo-only))
  4637. (setq rtnall (append rtnall rtn))))))))
  4638. (org-agenda--insert-overriding-header
  4639. (with-temp-buffer
  4640. (insert "Headlines with TAGS match: ")
  4641. (add-text-properties (point-min) (1- (point))
  4642. (list 'face 'org-agenda-structure
  4643. 'short-heading
  4644. (concat "Match: " match)))
  4645. (setq pos (point))
  4646. (insert match "\n")
  4647. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4648. (setq pos (point))
  4649. (unless org-agenda-multi
  4650. (insert (substitute-command-keys
  4651. "Press \
  4652. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4653. to search again\n")))
  4654. (add-text-properties pos (1- (point))
  4655. (list 'face 'org-agenda-structure-secondary))
  4656. (buffer-string)))
  4657. (org-agenda-mark-header-line (point-min))
  4658. (when rtnall
  4659. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4660. (goto-char (point-min))
  4661. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4662. (add-text-properties
  4663. (point-min) (point-max)
  4664. `(org-agenda-type tags
  4665. org-last-args (,org--matcher-tags-todo-only ,match)
  4666. org-redo-cmd ,org-agenda-redo-command
  4667. org-series-cmd ,org-cmd))
  4668. (org-agenda-finalize)
  4669. (setq buffer-read-only t))))
  4670. ;;; Agenda Finding stuck projects
  4671. (defvar org-agenda-skip-regexp nil
  4672. "Regular expression used in skipping subtrees for the agenda.
  4673. This is basically a temporary global variable that can be set and then
  4674. used by user-defined selections using `org-agenda-skip-function'.")
  4675. (defvar org-agenda-overriding-header nil
  4676. "When set during agenda, todo and tags searches it replaces the header.
  4677. If an empty string, no header will be inserted. If any other
  4678. string, it will be inserted as a header. If a function, insert
  4679. the string returned by the function as a header. If nil, a
  4680. header will be generated automatically according to the command.
  4681. This variable should not be set directly, but custom commands can
  4682. bind it in the options section.")
  4683. (defun org-agenda-skip-entry-if (&rest conditions)
  4684. "Skip entry if any of CONDITIONS is true.
  4685. See `org-agenda-skip-if' for details."
  4686. (org-agenda-skip-if nil conditions))
  4687. (defun org-agenda-skip-subtree-if (&rest conditions)
  4688. "Skip subtree if any of CONDITIONS is true.
  4689. See `org-agenda-skip-if' for details."
  4690. (org-agenda-skip-if t conditions))
  4691. (defun org-agenda-skip-if (subtree conditions)
  4692. "Check current entity for CONDITIONS.
  4693. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4694. the entry (i.e. the text before the next heading) is checked.
  4695. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4696. from different tests. Valid conditions are:
  4697. scheduled Check if there is a scheduled cookie
  4698. notscheduled Check if there is no scheduled cookie
  4699. deadline Check if there is a deadline
  4700. notdeadline Check if there is no deadline
  4701. timestamp Check if there is a timestamp (also deadline or scheduled)
  4702. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4703. regexp Check if regexp matches
  4704. notregexp Check if regexp does not match.
  4705. todo Check if TODO keyword matches
  4706. nottodo Check if TODO keyword does not match
  4707. The regexp is taken from the conditions list, it must come right after
  4708. the `regexp' or `notregexp' element.
  4709. `todo' and `nottodo' accept as an argument a list of todo
  4710. keywords, which may include \"*\" to match any todo keyword.
  4711. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4712. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4713. Instead of a list, a keyword class may be given. For example:
  4714. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4715. would skip entries that haven't been marked with any of \"DONE\"
  4716. keywords. Possible classes are: `todo', `done', `any'.
  4717. If any of these conditions is met, this function returns the end point of
  4718. the entity, causing the search to continue from there. This is a function
  4719. that can be put into `org-agenda-skip-function' for the duration of a command."
  4720. (org-back-to-heading t)
  4721. (let* (;; (beg (point))
  4722. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4723. (org-entry-end-position)))
  4724. (planning-end (if subtree end (line-end-position 2)))
  4725. m)
  4726. (and
  4727. (or (and (memq 'scheduled conditions)
  4728. (re-search-forward org-scheduled-time-regexp planning-end t))
  4729. (and (memq 'notscheduled conditions)
  4730. (not
  4731. (save-excursion
  4732. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4733. (and (memq 'deadline conditions)
  4734. (re-search-forward org-deadline-time-regexp planning-end t))
  4735. (and (memq 'notdeadline conditions)
  4736. (not
  4737. (save-excursion
  4738. (re-search-forward org-deadline-time-regexp planning-end t))))
  4739. (and (memq 'timestamp conditions)
  4740. (re-search-forward org-ts-regexp end t))
  4741. (and (memq 'nottimestamp conditions)
  4742. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4743. (and (setq m (memq 'regexp conditions))
  4744. (stringp (nth 1 m))
  4745. (re-search-forward (nth 1 m) end t))
  4746. (and (setq m (memq 'notregexp conditions))
  4747. (stringp (nth 1 m))
  4748. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4749. (and (or
  4750. (setq m (memq 'nottodo conditions))
  4751. (setq m (memq 'todo-unblocked conditions))
  4752. (setq m (memq 'nottodo-unblocked conditions))
  4753. (setq m (memq 'todo conditions)))
  4754. (org-agenda-skip-if-todo m end)))
  4755. end)))
  4756. (defun org-agenda-skip-if-todo (args end)
  4757. "Helper function for `org-agenda-skip-if', do not use it directly.
  4758. ARGS is a list with first element either `todo', `nottodo',
  4759. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4760. a list of TODO keywords, or a state symbol `todo' or `done' or
  4761. `any'."
  4762. (let ((todo-re
  4763. (concat "^\\*+[ \t]+"
  4764. (regexp-opt
  4765. (pcase args
  4766. (`(,_ todo)
  4767. (org-delete-all org-done-keywords
  4768. (copy-sequence org-todo-keywords-1)))
  4769. (`(,_ done) org-done-keywords)
  4770. (`(,_ any) org-todo-keywords-1)
  4771. (`(,_ ,(pred atom))
  4772. (error "Invalid TODO class or type: %S" args))
  4773. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4774. (`(,_ ,todo-list) todo-list))
  4775. 'words))))
  4776. (pcase args
  4777. (`(todo . ,_)
  4778. (let (case-fold-search) (re-search-forward todo-re end t)))
  4779. (`(nottodo . ,_)
  4780. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4781. (`(todo-unblocked . ,_)
  4782. (catch :unblocked
  4783. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4784. (when (org-entry-blocked-p) (throw :unblocked t)))
  4785. nil))
  4786. (`(nottodo-unblocked . ,_)
  4787. (catch :unblocked
  4788. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4789. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4790. t))
  4791. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4792. ;;;###autoload
  4793. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4794. "Create agenda view for projects that are stuck.
  4795. Stuck projects are project that have no next actions. For the definitions
  4796. of what a project is and how to check if it stuck, customize the variable
  4797. `org-stuck-projects'."
  4798. (interactive)
  4799. (let* ((org-agenda-overriding-header
  4800. (or org-agenda-overriding-header "List of stuck projects: "))
  4801. (matcher (nth 0 org-stuck-projects))
  4802. (todo (nth 1 org-stuck-projects))
  4803. (tags (nth 2 org-stuck-projects))
  4804. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4805. (todo-wds
  4806. (if (not (member "*" todo)) todo
  4807. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4808. (org-delete-all org-done-keywords-for-agenda
  4809. (copy-sequence org-todo-keywords-for-agenda))))
  4810. (todo-re (and todo
  4811. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4812. (mapconcat #'identity todo-wds "\\|"))))
  4813. (tags-re (cond ((null tags) nil)
  4814. ((member "*" tags) org-tag-line-re)
  4815. (tags
  4816. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4817. (concat org-outline-regexp-bol
  4818. ".*?[ \t]:"
  4819. other-tags
  4820. (regexp-opt tags t)
  4821. ":" other-tags "[ \t]*$")))
  4822. (t nil)))
  4823. (re-list (delq nil (list todo-re tags-re gen-re)))
  4824. (skip-re
  4825. (if (null re-list)
  4826. (error "Missing information to identify unstuck projects")
  4827. (mapconcat #'identity re-list "\\|")))
  4828. (org-agenda-skip-function
  4829. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4830. ;; in the subtree.
  4831. (lambda ()
  4832. (and (save-excursion
  4833. (let ((case-fold-search nil))
  4834. (re-search-forward
  4835. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4836. (progn (outline-next-heading) (point))))))
  4837. (org-tags-view nil matcher)
  4838. (setq org-agenda-buffer-name (buffer-name))
  4839. (with-current-buffer org-agenda-buffer-name
  4840. (setq org-agenda-redo-command
  4841. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4842. (let ((inhibit-read-only t))
  4843. (add-text-properties
  4844. (point-min) (point-max)
  4845. `(org-redo-cmd ,org-agenda-redo-command))))))
  4846. ;;; Diary integration
  4847. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4848. (defvar diary-list-entries-hook)
  4849. (defvar diary-time-regexp)
  4850. (defvar diary-modify-entry-list-string-function)
  4851. (defvar diary-file-name-prefix)
  4852. (defvar diary-display-function)
  4853. (defun org-get-entries-from-diary (date)
  4854. "Get the (Emacs Calendar) diary entries for DATE."
  4855. (require 'diary-lib)
  4856. (declare-function diary-fancy-display "diary-lib" ())
  4857. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4858. (diary-display-function #'diary-fancy-display)
  4859. (pop-up-frames nil)
  4860. (diary-list-entries-hook
  4861. (cons 'org-diary-default-entry diary-list-entries-hook))
  4862. (diary-file-name-prefix nil) ; turn this feature off
  4863. (diary-modify-entry-list-string-function
  4864. #'org-modify-diary-entry-string)
  4865. (diary-time-regexp (concat "^" diary-time-regexp))
  4866. entries
  4867. (org-disable-agenda-to-diary t))
  4868. (save-excursion
  4869. (save-window-excursion
  4870. (diary-list-entries date 1)))
  4871. (if (not (get-buffer diary-fancy-buffer))
  4872. (setq entries nil)
  4873. (with-current-buffer diary-fancy-buffer
  4874. (setq buffer-read-only nil)
  4875. (if (zerop (buffer-size))
  4876. ;; No entries
  4877. (setq entries nil)
  4878. ;; Omit the date and other unnecessary stuff
  4879. (org-agenda-cleanup-fancy-diary)
  4880. ;; Add prefix to each line and extend the text properties
  4881. (if (zerop (buffer-size))
  4882. (setq entries nil)
  4883. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4884. (setq entries
  4885. (with-temp-buffer
  4886. (insert entries) (goto-char (point-min))
  4887. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4888. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4889. (replace-match (concat "; " (match-string 1)))))
  4890. (buffer-string)))))
  4891. (set-buffer-modified-p nil)
  4892. (kill-buffer diary-fancy-buffer)))
  4893. (when entries
  4894. (setq entries (org-split-string entries "\n"))
  4895. (setq entries
  4896. (mapcar
  4897. (lambda (x)
  4898. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4899. ;; Extend the text properties to the beginning of the line
  4900. (org-add-props x (text-properties-at (1- (length x)) x)
  4901. 'type "diary" 'date date 'face 'org-agenda-diary))
  4902. entries)))))
  4903. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4904. "Hook run when the fancy diary buffer is cleaned up.")
  4905. (defun org-agenda-cleanup-fancy-diary ()
  4906. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4907. This gets rid of the date, the underline under the date, and the
  4908. dummy entry installed by Org mode to ensure non-empty diary for
  4909. each date. It also removes lines that contain only whitespace."
  4910. (goto-char (point-min))
  4911. (if (looking-at ".*?:[ \t]*")
  4912. (progn
  4913. (replace-match "")
  4914. (re-search-forward "\n=+$" nil t)
  4915. (replace-match "")
  4916. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4917. (re-search-forward "\n=+$" nil t)
  4918. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4919. (goto-char (point-min))
  4920. (while (re-search-forward "^ +\n" nil t)
  4921. (replace-match ""))
  4922. (goto-char (point-min))
  4923. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4924. (replace-match ""))
  4925. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4926. (defun org-modify-diary-entry-string (string)
  4927. "Add text properties to string, allowing Org to act on it."
  4928. (org-add-props string nil
  4929. 'mouse-face 'highlight
  4930. 'help-echo (if buffer-file-name
  4931. (format "mouse-2 or RET jump to diary file %s"
  4932. (abbreviate-file-name buffer-file-name))
  4933. "")
  4934. 'org-agenda-diary-link t
  4935. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4936. (defun org-diary-default-entry ()
  4937. "Add a dummy entry to the diary.
  4938. Needed to avoid empty dates which mess up holiday display."
  4939. ;; Catch the error if dealing with the new add-to-diary-alist
  4940. (when org-disable-agenda-to-diary
  4941. (diary-add-to-list original-date "Org mode dummy" "")))
  4942. (defvar org-diary-last-run-time nil)
  4943. ;;;###autoload
  4944. (defun org-diary (&rest args)
  4945. "Return diary information from org files.
  4946. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4947. It accesses org files and extracts information from those files to be
  4948. listed in the diary. The function accepts arguments specifying what
  4949. items should be listed. For a list of arguments allowed here, see the
  4950. variable `org-agenda-entry-types'.
  4951. The call in the diary file should look like this:
  4952. &%%(org-diary) ~/path/to/some/orgfile.org
  4953. Use a separate line for each org file to check. Or, if you omit the file name,
  4954. all files listed in `org-agenda-files' will be checked automatically:
  4955. &%%(org-diary)
  4956. If you don't give any arguments (as in the example above), the default value
  4957. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4958. So the example above may also be written as
  4959. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4960. The function expects the lisp variables `entry' and `date' to be provided
  4961. by the caller, because this is how the calendar works. Don't use this
  4962. function from a program - use `org-agenda-get-day-entries' instead."
  4963. (with-no-warnings (defvar date) (defvar entry))
  4964. (when (> (- (float-time)
  4965. org-agenda-last-marker-time)
  4966. 5)
  4967. ;; I am not sure if this works with sticky agendas, because the marker
  4968. ;; list is then no longer a global variable.
  4969. (org-agenda-reset-markers))
  4970. (org-compile-prefix-format 'agenda)
  4971. (org-set-sorting-strategy 'agenda)
  4972. (setq args (or args org-agenda-entry-types))
  4973. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4974. (list entry)
  4975. (org-agenda-files t)))
  4976. (time (float-time))
  4977. file rtn results)
  4978. (when (or (not org-diary-last-run-time)
  4979. (> (- time
  4980. org-diary-last-run-time)
  4981. 3))
  4982. (org-agenda-prepare-buffers files))
  4983. (setq org-diary-last-run-time time)
  4984. ;; If this is called during org-agenda, don't return any entries to
  4985. ;; the calendar. Org Agenda will list these entries itself.
  4986. (when org-disable-agenda-to-diary (setq files nil))
  4987. (while (setq file (pop files))
  4988. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4989. (setq results (append results rtn)))
  4990. (when results
  4991. (setq results
  4992. (mapcar (lambda (i) (replace-regexp-in-string
  4993. org-link-bracket-re "\\2" i))
  4994. results))
  4995. (concat (org-agenda-finalize-entries results) "\n"))))
  4996. ;;; Agenda entry finders
  4997. (defun org-agenda--timestamp-to-absolute (&rest args)
  4998. "Call `org-time-string-to-absolute' with ARGS.
  4999. However, throw `:skip' whenever an error is raised."
  5000. (condition-case e
  5001. (apply #'org-time-string-to-absolute args)
  5002. (org-diary-sexp-no-match (throw :skip nil))
  5003. (error
  5004. (message "%s; Skipping entry" (error-message-string e))
  5005. (throw :skip nil))))
  5006. (defun org-agenda-get-day-entries (file date &rest args)
  5007. "Does the work for `org-diary' and `org-agenda'.
  5008. FILE is the path to a file to be checked for entries. DATE is date like
  5009. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5010. which kind of entries should be extracted. For details about these, see
  5011. the documentation of `org-diary'."
  5012. (let* ((org-startup-folded nil)
  5013. (org-startup-align-all-tables nil)
  5014. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5015. (error "No such file %s" file))))
  5016. (if (not buffer)
  5017. ;; If file does not exist, signal it in diary nonetheless.
  5018. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5019. (with-current-buffer buffer
  5020. (unless (derived-mode-p 'org-mode)
  5021. (error "Agenda file %s is not in Org mode" file))
  5022. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5023. (setf org-agenda-current-date date)
  5024. (save-excursion
  5025. (save-restriction
  5026. (if (eq buffer org-agenda-restrict)
  5027. (narrow-to-region org-agenda-restrict-begin
  5028. org-agenda-restrict-end)
  5029. (widen))
  5030. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5031. ;; first in order to populate DEADLINES before passing it.
  5032. ;;
  5033. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5034. ;; guarding us from modifying `org-agenda-entry-types'.
  5035. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5036. (when (and (memq :scheduled args) (memq :scheduled* args))
  5037. (setf args (delq :scheduled* args)))
  5038. (cond
  5039. ((memq :deadline args)
  5040. (setf args (cons :deadline
  5041. (delq :deadline (delq :deadline* args)))))
  5042. ((memq :deadline* args)
  5043. (setf args (cons :deadline* (delq :deadline* args)))))
  5044. ;; Collect list of headlines. Return them flattened.
  5045. (let ((case-fold-search nil) results deadlines)
  5046. (org-dlet
  5047. ((date date))
  5048. (dolist (arg args (apply #'nconc (nreverse results)))
  5049. (pcase arg
  5050. ((and :todo (guard (org-agenda-today-p date)))
  5051. (push (org-agenda-get-todos) results))
  5052. (:timestamp
  5053. (push (org-agenda-get-blocks) results)
  5054. (push (org-agenda-get-timestamps deadlines) results))
  5055. (:sexp
  5056. (push (org-agenda-get-sexps) results))
  5057. (:scheduled
  5058. (push (org-agenda-get-scheduled deadlines) results))
  5059. (:scheduled*
  5060. (push (org-agenda-get-scheduled deadlines t) results))
  5061. (:closed
  5062. (push (org-agenda-get-progress) results))
  5063. (:deadline
  5064. (setf deadlines (org-agenda-get-deadlines))
  5065. (push deadlines results))
  5066. (:deadline*
  5067. (setf deadlines (org-agenda-get-deadlines t))
  5068. (push deadlines results))))))))))))
  5069. (defsubst org-em (x y list)
  5070. "Is X or Y a member of LIST?"
  5071. (or (memq x list) (memq y list)))
  5072. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5073. (defvar org-agenda-sorting-strategy-selected nil)
  5074. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5075. "Retrieve timestamp information for sorting agenda views.
  5076. Given a point or marker POM, returns a cons cell of the timestamp
  5077. and the timestamp type relevant for the sorting strategy in
  5078. `org-agenda-sorting-strategy-selected'."
  5079. (let (ts ts-date-type)
  5080. (save-match-data
  5081. (cond ((org-em 'scheduled-up 'scheduled-down
  5082. org-agenda-sorting-strategy-selected)
  5083. (setq ts (org-entry-get pom "SCHEDULED")
  5084. ts-date-type " scheduled"))
  5085. ((org-em 'deadline-up 'deadline-down
  5086. org-agenda-sorting-strategy-selected)
  5087. (setq ts (org-entry-get pom "DEADLINE")
  5088. ts-date-type " deadline"))
  5089. ((org-em 'ts-up 'ts-down
  5090. org-agenda-sorting-strategy-selected)
  5091. (setq ts (org-entry-get pom "TIMESTAMP")
  5092. ts-date-type " timestamp"))
  5093. ((org-em 'tsia-up 'tsia-down
  5094. org-agenda-sorting-strategy-selected)
  5095. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5096. ts-date-type " timestamp_ia"))
  5097. ((org-em 'timestamp-up 'timestamp-down
  5098. org-agenda-sorting-strategy-selected)
  5099. (setq ts (or (org-entry-get pom "SCHEDULED")
  5100. (org-entry-get pom "DEADLINE")
  5101. (org-entry-get pom "TIMESTAMP")
  5102. (org-entry-get pom "TIMESTAMP_IA"))
  5103. ts-date-type ""))
  5104. (t (setq ts-date-type "")))
  5105. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5106. ts-date-type))))
  5107. (defun org-agenda-get-todos ()
  5108. "Return the TODO information for agenda display."
  5109. (let* ((props (list 'face nil
  5110. 'done-face 'org-agenda-done
  5111. 'org-not-done-regexp org-not-done-regexp
  5112. 'org-todo-regexp org-todo-regexp
  5113. 'org-complex-heading-regexp org-complex-heading-regexp
  5114. 'mouse-face 'highlight
  5115. 'help-echo
  5116. (format "mouse-2 or RET jump to org file %s"
  5117. (abbreviate-file-name buffer-file-name))))
  5118. (case-fold-search nil)
  5119. (regexp (format org-heading-keyword-regexp-format
  5120. (cond
  5121. ((and org-select-this-todo-keyword
  5122. (equal org-select-this-todo-keyword "*"))
  5123. org-todo-regexp)
  5124. (org-select-this-todo-keyword
  5125. (concat "\\("
  5126. (mapconcat #'identity
  5127. (org-split-string
  5128. org-select-this-todo-keyword
  5129. "|")
  5130. "\\|")
  5131. "\\)"))
  5132. (t org-not-done-regexp))))
  5133. marker priority category level tags todo-state
  5134. ts-date ts-date-type ts-date-pair
  5135. ee txt beg end inherited-tags todo-state-end-pos
  5136. effort effort-minutes)
  5137. (goto-char (point-min))
  5138. (while (re-search-forward regexp nil t)
  5139. (catch :skip
  5140. (save-match-data
  5141. (beginning-of-line)
  5142. (org-agenda-skip)
  5143. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5144. (unless (and (setq todo-state (org-get-todo-state))
  5145. (setq todo-state-end-pos (match-end 2)))
  5146. (goto-char end)
  5147. (throw :skip nil))
  5148. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5149. (goto-char (1+ beg))
  5150. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5151. (throw :skip nil)))
  5152. (goto-char (match-beginning 2))
  5153. (setq marker (org-agenda-new-marker (match-beginning 0))
  5154. category (org-get-category)
  5155. effort (save-match-data (or (get-text-property (point) 'effort)
  5156. (org-entry-get (point) org-effort-property)))
  5157. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5158. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5159. ts-date (car ts-date-pair)
  5160. ts-date-type (cdr ts-date-pair)
  5161. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5162. inherited-tags
  5163. (or (eq org-agenda-show-inherited-tags 'always)
  5164. (and (listp org-agenda-show-inherited-tags)
  5165. (memq 'todo org-agenda-show-inherited-tags))
  5166. (and (eq org-agenda-show-inherited-tags t)
  5167. (or (eq org-agenda-use-tag-inheritance t)
  5168. (memq 'todo org-agenda-use-tag-inheritance))))
  5169. tags (org-get-tags nil (not inherited-tags))
  5170. level (make-string (org-reduced-level (org-outline-level)) ? )
  5171. txt (org-agenda-format-item ""
  5172. (org-add-props txt nil
  5173. 'effort effort
  5174. 'effort-minutes effort-minutes)
  5175. level category tags t)
  5176. priority (1+ (org-get-priority txt)))
  5177. (org-add-props txt props
  5178. 'org-marker marker 'org-hd-marker marker
  5179. 'priority priority
  5180. 'effort effort 'effort-minutes effort-minutes
  5181. 'level level
  5182. 'ts-date ts-date
  5183. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5184. (push txt ee)
  5185. (if org-agenda-todo-list-sublevels
  5186. (goto-char todo-state-end-pos)
  5187. (org-end-of-subtree 'invisible))))
  5188. (nreverse ee)))
  5189. (defun org-agenda-todo-custom-ignore-p (time n)
  5190. "Check whether timestamp is farther away than n number of days.
  5191. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5192. `org-agenda-todo-ignore-scheduled' or
  5193. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5194. (let ((days (org-time-stamp-to-now
  5195. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5196. (if (>= n 0)
  5197. (>= days n)
  5198. (<= days n))))
  5199. ;;;###autoload
  5200. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5201. (&optional end)
  5202. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5203. (when (or org-agenda-todo-ignore-with-date
  5204. org-agenda-todo-ignore-scheduled
  5205. org-agenda-todo-ignore-deadlines
  5206. org-agenda-todo-ignore-timestamp)
  5207. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5208. (save-excursion
  5209. (or (and org-agenda-todo-ignore-with-date
  5210. (re-search-forward org-ts-regexp end t))
  5211. (and org-agenda-todo-ignore-scheduled
  5212. (re-search-forward org-scheduled-time-regexp end t)
  5213. (cond
  5214. ((eq org-agenda-todo-ignore-scheduled '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-scheduled '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-scheduled)
  5223. (org-agenda-todo-custom-ignore-p
  5224. (match-string 1) org-agenda-todo-ignore-scheduled))
  5225. (t)))
  5226. (and org-agenda-todo-ignore-deadlines
  5227. (re-search-forward org-deadline-time-regexp end t)
  5228. (cond
  5229. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5230. ((eq org-agenda-todo-ignore-deadlines 'far)
  5231. (not (org-deadline-close-p (match-string 1))))
  5232. ((eq org-agenda-todo-ignore-deadlines 'future)
  5233. (> (org-time-stamp-to-now
  5234. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5235. 0))
  5236. ((eq org-agenda-todo-ignore-deadlines 'past)
  5237. (<= (org-time-stamp-to-now
  5238. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5239. 0))
  5240. ((numberp org-agenda-todo-ignore-deadlines)
  5241. (org-agenda-todo-custom-ignore-p
  5242. (match-string 1) org-agenda-todo-ignore-deadlines))
  5243. (t (org-deadline-close-p (match-string 1)))))
  5244. (and org-agenda-todo-ignore-timestamp
  5245. (let ((buffer (current-buffer))
  5246. (regexp
  5247. (concat
  5248. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5249. (start (point)))
  5250. ;; Copy current buffer into a temporary one
  5251. (with-temp-buffer
  5252. (insert-buffer-substring buffer start end)
  5253. (goto-char (point-min))
  5254. ;; Delete SCHEDULED and DEADLINE items
  5255. (while (re-search-forward regexp end t)
  5256. (delete-region (match-beginning 0) (match-end 0)))
  5257. (goto-char (point-min))
  5258. ;; No search for timestamp left
  5259. (when (re-search-forward org-ts-regexp nil t)
  5260. (cond
  5261. ((eq org-agenda-todo-ignore-timestamp 'future)
  5262. (> (org-time-stamp-to-now
  5263. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5264. 0))
  5265. ((eq org-agenda-todo-ignore-timestamp 'past)
  5266. (<= (org-time-stamp-to-now
  5267. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5268. 0))
  5269. ((numberp org-agenda-todo-ignore-timestamp)
  5270. (org-agenda-todo-custom-ignore-p
  5271. (match-string 1) org-agenda-todo-ignore-timestamp))
  5272. (t))))))))))
  5273. (defun org-agenda-get-timestamps (&optional deadlines)
  5274. "Return the date stamp information for agenda display.
  5275. Optional argument DEADLINES is a list of deadline items to be
  5276. displayed in agenda view."
  5277. (with-no-warnings (defvar date))
  5278. (let* ((props (list 'face 'org-agenda-calendar-event
  5279. 'org-not-done-regexp org-not-done-regexp
  5280. 'org-todo-regexp org-todo-regexp
  5281. 'org-complex-heading-regexp org-complex-heading-regexp
  5282. 'mouse-face 'highlight
  5283. 'help-echo
  5284. (format "mouse-2 or RET jump to Org file %s"
  5285. (abbreviate-file-name buffer-file-name))))
  5286. (current (calendar-absolute-from-gregorian date))
  5287. (today (org-today))
  5288. (deadline-position-alist
  5289. (mapcar (lambda (d)
  5290. (let ((m (get-text-property 0 'org-hd-marker d)))
  5291. (and m (marker-position m))))
  5292. deadlines))
  5293. ;; Match time-stamps set to current date, time-stamps with
  5294. ;; a repeater, and S-exp time-stamps.
  5295. (regexp
  5296. (concat
  5297. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5298. (regexp-quote
  5299. (substring
  5300. (format-time-string
  5301. (car org-time-stamp-formats)
  5302. (org-encode-time ; DATE bound by calendar
  5303. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5304. 1 11))
  5305. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5306. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5307. timestamp-items)
  5308. (goto-char (point-min))
  5309. (while (re-search-forward regexp nil t)
  5310. ;; Skip date ranges, scheduled and deadlines, which are handled
  5311. ;; specially. Also skip time-stamps before first headline as
  5312. ;; there would be no entry to add to the agenda. Eventually,
  5313. ;; ignore clock entries.
  5314. (catch :skip
  5315. (save-match-data
  5316. (when (or (org-at-date-range-p)
  5317. (org-at-planning-p)
  5318. (org-before-first-heading-p)
  5319. (and org-agenda-include-inactive-timestamps
  5320. (org-at-clock-log-p))
  5321. (not (org-at-timestamp-p 'agenda)))
  5322. (throw :skip nil))
  5323. (org-agenda-skip))
  5324. (let* ((pos (match-beginning 0))
  5325. (repeat (match-string 1))
  5326. (sexp-entry (match-string 3))
  5327. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5328. (save-excursion
  5329. (goto-char pos)
  5330. (looking-at org-ts-regexp-both)
  5331. (match-string 0))))
  5332. (todo-state (org-get-todo-state))
  5333. (warntime (get-text-property (point) 'org-appt-warntime))
  5334. (done? (member todo-state org-done-keywords)))
  5335. ;; Possibly skip done tasks.
  5336. (when (and done? org-agenda-skip-timestamp-if-done)
  5337. (throw :skip t))
  5338. ;; S-exp entry doesn't match current day: skip it.
  5339. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5340. (throw :skip nil))
  5341. (when repeat
  5342. (let* ((past
  5343. ;; A repeating time stamp is shown at its base
  5344. ;; date and every repeated date up to TODAY. If
  5345. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5346. ;; however, only the last repeat before today
  5347. ;; (inclusive) is shown.
  5348. (org-agenda--timestamp-to-absolute
  5349. repeat
  5350. (if (or (> current today)
  5351. (eq org-agenda-prefer-last-repeat t)
  5352. (member todo-state org-agenda-prefer-last-repeat))
  5353. today
  5354. current)
  5355. 'past (current-buffer) pos))
  5356. (future
  5357. ;; Display every repeated date past TODAY
  5358. ;; (exclusive) unless
  5359. ;; `org-agenda-show-future-repeats' is nil. If
  5360. ;; this variable is set to `next', only display
  5361. ;; the first repeated date after TODAY
  5362. ;; (exclusive).
  5363. (cond
  5364. ((<= current today) past)
  5365. ((not org-agenda-show-future-repeats) past)
  5366. (t
  5367. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5368. (1+ today)
  5369. current)))
  5370. (org-agenda--timestamp-to-absolute
  5371. repeat base 'future (current-buffer) pos))))))
  5372. (when (and (/= current past) (/= current future))
  5373. (throw :skip nil))))
  5374. (save-excursion
  5375. (re-search-backward org-outline-regexp-bol nil t)
  5376. ;; Possibly skip time-stamp when a deadline is set.
  5377. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5378. (assq (point) deadline-position-alist))
  5379. (throw :skip nil))
  5380. (let* ((category (org-get-category pos))
  5381. (effort (org-entry-get pos org-effort-property))
  5382. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5383. (inherited-tags
  5384. (or (eq org-agenda-show-inherited-tags 'always)
  5385. (and (consp org-agenda-show-inherited-tags)
  5386. (memq 'agenda org-agenda-show-inherited-tags))
  5387. (and (eq org-agenda-show-inherited-tags t)
  5388. (or (eq org-agenda-use-tag-inheritance t)
  5389. (memq 'agenda
  5390. org-agenda-use-tag-inheritance)))))
  5391. (tags (org-get-tags nil (not inherited-tags)))
  5392. (level (make-string (org-reduced-level (org-outline-level))
  5393. ?\s))
  5394. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5395. (match-string 1)))
  5396. (inactive? (= (char-after pos) ?\[))
  5397. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5398. (item
  5399. (org-agenda-format-item
  5400. (and inactive? org-agenda-inactive-leader)
  5401. (org-add-props head nil
  5402. 'effort effort
  5403. 'effort-minutes effort-minutes)
  5404. level category tags time-stamp org-ts-regexp habit?)))
  5405. (org-add-props item props
  5406. 'priority (if habit?
  5407. (org-habit-get-priority (org-habit-parse-todo))
  5408. (org-get-priority item))
  5409. 'org-marker (org-agenda-new-marker pos)
  5410. 'org-hd-marker (org-agenda-new-marker)
  5411. 'date date
  5412. 'level level
  5413. 'effort effort 'effort-minutes effort-minutes
  5414. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5415. current)
  5416. 'todo-state todo-state
  5417. 'warntime warntime
  5418. 'type "timestamp")
  5419. (push item timestamp-items))))
  5420. (when org-agenda-skip-additional-timestamps-same-entry
  5421. (outline-next-heading))))
  5422. (nreverse timestamp-items)))
  5423. (defun org-agenda-get-sexps ()
  5424. "Return the sexp information for agenda display."
  5425. (require 'diary-lib)
  5426. (with-no-warnings (defvar date) (defvar entry))
  5427. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5428. 'mouse-face 'highlight
  5429. 'help-echo
  5430. (format "mouse-2 or RET jump to org file %s"
  5431. (abbreviate-file-name buffer-file-name))))
  5432. (regexp "^&?%%(")
  5433. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5434. ;; so as to "hide" any current binding for it?
  5435. marker category extra level ee txt tags entry
  5436. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5437. effort effort-minutes)
  5438. (goto-char (point-min))
  5439. (while (re-search-forward regexp nil t)
  5440. (catch :skip
  5441. (org-agenda-skip)
  5442. (setq beg (match-beginning 0))
  5443. (goto-char (1- (match-end 0)))
  5444. (setq b (point))
  5445. (forward-sexp 1)
  5446. (setq sexp (buffer-substring b (point)))
  5447. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5448. (org-trim (match-string 1))
  5449. ""))
  5450. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5451. (when result
  5452. (setq marker (org-agenda-new-marker beg)
  5453. level (make-string (org-reduced-level (org-outline-level)) ? )
  5454. category (org-get-category beg)
  5455. effort (save-match-data (or (get-text-property (point) 'effort)
  5456. (org-entry-get (point) org-effort-property)))
  5457. inherited-tags
  5458. (or (eq org-agenda-show-inherited-tags 'always)
  5459. (and (listp org-agenda-show-inherited-tags)
  5460. (memq 'agenda org-agenda-show-inherited-tags))
  5461. (and (eq org-agenda-show-inherited-tags t)
  5462. (or (eq org-agenda-use-tag-inheritance t)
  5463. (memq 'agenda org-agenda-use-tag-inheritance))))
  5464. tags (org-get-tags nil (not inherited-tags))
  5465. todo-state (org-get-todo-state)
  5466. warntime (get-text-property (point) 'org-appt-warntime)
  5467. extra nil)
  5468. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5469. (dolist (r (if (stringp result)
  5470. (list result)
  5471. result)) ;; we expect a list here
  5472. (when (and org-agenda-diary-sexp-prefix
  5473. (string-match org-agenda-diary-sexp-prefix r))
  5474. (setq extra (match-string 0 r)
  5475. r (replace-match "" nil nil r)))
  5476. (if (string-match "\\S-" r)
  5477. (setq txt r)
  5478. (setq txt "SEXP entry returned empty string"))
  5479. (setq txt (org-agenda-format-item extra
  5480. (org-add-props txt nil
  5481. 'effort effort
  5482. 'effort-minutes effort-minutes)
  5483. level category tags 'time))
  5484. (org-add-props txt props 'org-marker marker
  5485. 'date date 'todo-state todo-state
  5486. 'effort effort 'effort-minutes effort-minutes
  5487. 'level level 'type "sexp" 'warntime warntime)
  5488. (push txt ee)))))
  5489. (nreverse ee)))
  5490. ;; Calendar sanity: define some functions that are independent of
  5491. ;; `calendar-date-style'.
  5492. (defun org-anniversary (year month day &optional mark)
  5493. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5494. (with-no-warnings
  5495. (let ((calendar-date-style 'iso))
  5496. (diary-anniversary year month day mark))))
  5497. (defun org-cyclic (N year month day &optional mark)
  5498. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5499. (with-no-warnings
  5500. (let ((calendar-date-style 'iso))
  5501. (diary-cyclic N year month day mark))))
  5502. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5503. "Like `diary-block', but with fixed (ISO) order of arguments."
  5504. (with-no-warnings
  5505. (let ((calendar-date-style 'iso))
  5506. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5507. (defun org-date (year month day &optional mark)
  5508. "Like `diary-date', but with fixed (ISO) order of arguments."
  5509. (with-no-warnings
  5510. (let ((calendar-date-style 'iso))
  5511. (diary-date year month day mark))))
  5512. ;; Define the `org-class' function
  5513. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5514. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5515. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5516. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5517. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5518. `holidays', then any date that is known by the Emacs calendar to be a
  5519. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5520. then those holidays will be skipped."
  5521. (with-no-warnings (defvar date) (defvar entry))
  5522. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5523. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5524. (d (calendar-absolute-from-gregorian date))
  5525. (h (when skip-weeks (calendar-check-holidays date))))
  5526. (and
  5527. (<= date1 d)
  5528. (<= d date2)
  5529. (= (calendar-day-of-week date) dayname)
  5530. (or (not skip-weeks)
  5531. (progn
  5532. (require 'cal-iso)
  5533. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5534. (not (or (and h (memq 'holidays skip-weeks))
  5535. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5536. entry)))
  5537. (defalias 'org-get-closed #'org-agenda-get-progress)
  5538. (defun org-agenda-get-progress ()
  5539. "Return the logged TODO entries for agenda display."
  5540. (with-no-warnings (defvar date))
  5541. (let* ((props (list 'mouse-face 'highlight
  5542. 'org-not-done-regexp org-not-done-regexp
  5543. 'org-todo-regexp org-todo-regexp
  5544. 'org-complex-heading-regexp org-complex-heading-regexp
  5545. 'help-echo
  5546. (format "mouse-2 or RET jump to org file %s"
  5547. (abbreviate-file-name buffer-file-name))))
  5548. (items (if (consp org-agenda-show-log-scoped)
  5549. org-agenda-show-log-scoped
  5550. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5551. '(clock)
  5552. org-agenda-log-mode-items)))
  5553. (parts
  5554. (delq nil
  5555. (list
  5556. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5557. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5558. (when (memq 'state items)
  5559. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5560. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5561. (error "`org-agenda-log-mode-items' is empty")))
  5562. (regexp (concat
  5563. "\\(" parts-re "\\)"
  5564. " *\\["
  5565. (regexp-quote
  5566. (substring
  5567. (format-time-string
  5568. (car org-time-stamp-formats)
  5569. (org-encode-time ; DATE bound by calendar
  5570. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5571. 1 11))))
  5572. (org-agenda-search-headline-for-time nil)
  5573. marker hdmarker priority category level tags closedp type
  5574. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5575. effort effort-minutes)
  5576. (goto-char (point-min))
  5577. (while (re-search-forward regexp nil t)
  5578. (catch :skip
  5579. (org-agenda-skip)
  5580. (setq marker (org-agenda-new-marker (match-beginning 0))
  5581. closedp (equal (match-string 1) org-closed-string)
  5582. statep (equal (string-to-char (match-string 1)) ?-)
  5583. clockp (not (or closedp statep))
  5584. state (and statep (match-string 2))
  5585. category (org-get-category (match-beginning 0))
  5586. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5587. effort (save-match-data (or (get-text-property (point) 'effort)
  5588. (org-entry-get (point) org-effort-property))))
  5589. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5590. (when (string-match "\\]" timestr)
  5591. ;; substring should only run to end of time stamp
  5592. (setq rest (substring timestr (match-end 0))
  5593. timestr (substring timestr 0 (match-end 0)))
  5594. (if (and (not closedp) (not statep)
  5595. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5596. rest))
  5597. (progn (setq timestr (concat (substring timestr 0 -1)
  5598. "-" (match-string 1 rest) "]"))
  5599. (setq clocked (match-string 2 rest)))
  5600. (setq clocked "-")))
  5601. (save-excursion
  5602. (setq extra
  5603. (cond
  5604. ((not org-agenda-log-mode-add-notes) nil)
  5605. (statep
  5606. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5607. (match-string 1)))
  5608. (clockp
  5609. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5610. (match-string 1)))))
  5611. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5612. (throw :skip nil)
  5613. (goto-char (match-beginning 0))
  5614. (setq hdmarker (org-agenda-new-marker)
  5615. inherited-tags
  5616. (or (eq org-agenda-show-inherited-tags 'always)
  5617. (and (listp org-agenda-show-inherited-tags)
  5618. (memq 'todo org-agenda-show-inherited-tags))
  5619. (and (eq org-agenda-show-inherited-tags t)
  5620. (or (eq org-agenda-use-tag-inheritance t)
  5621. (memq 'todo org-agenda-use-tag-inheritance))))
  5622. tags (org-get-tags nil (not inherited-tags))
  5623. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5624. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5625. (setq txt (match-string 1))
  5626. (when extra
  5627. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5628. (setq txt (concat (substring txt 0 (match-beginning 1))
  5629. " - " extra " " (match-string 2 txt)))
  5630. (setq txt (concat txt " - " extra))))
  5631. (setq txt (org-agenda-format-item
  5632. (cond
  5633. (closedp "Closed: ")
  5634. (statep (concat "State: (" state ")"))
  5635. (t (concat "Clocked: (" clocked ")")))
  5636. (org-add-props txt nil
  5637. 'effort effort
  5638. 'effort-minutes effort-minutes)
  5639. level category tags timestr)))
  5640. (setq type (cond (closedp "closed")
  5641. (statep "state")
  5642. (t "clock")))
  5643. (setq priority 100000)
  5644. (org-add-props txt props
  5645. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5646. 'priority priority 'level level
  5647. 'effort effort 'effort-minutes effort-minutes
  5648. 'type type 'date date
  5649. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5650. (push txt ee))
  5651. (goto-char (point-at-eol))))
  5652. (nreverse ee)))
  5653. (defun org-agenda-show-clocking-issues ()
  5654. "Add overlays, showing issues with clocking.
  5655. See also the user option `org-agenda-clock-consistency-checks'."
  5656. (interactive)
  5657. (let* ((pl org-agenda-clock-consistency-checks)
  5658. (re (concat "^[ \t]*"
  5659. org-clock-string
  5660. "[ \t]+"
  5661. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5662. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5663. (tlstart 0.)
  5664. (tlend 0.)
  5665. (maxtime (org-duration-to-minutes
  5666. (or (plist-get pl :max-duration) "24:00")))
  5667. (mintime (org-duration-to-minutes
  5668. (or (plist-get pl :min-duration) 0)))
  5669. (maxgap (org-duration-to-minutes
  5670. ;; default 30:00 means never complain
  5671. (or (plist-get pl :max-gap) "30:00")))
  5672. (gapok (mapcar #'org-duration-to-minutes
  5673. (plist-get pl :gap-ok-around)))
  5674. (def-face (or (plist-get pl :default-face)
  5675. '((:background "DarkRed") (:foreground "white"))))
  5676. issue face m te ts dt ov)
  5677. (goto-char (point-min))
  5678. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5679. (setq issue nil face def-face)
  5680. (catch 'next
  5681. (setq m (org-get-at-bol 'org-marker)
  5682. te nil ts nil)
  5683. (unless (and m (markerp m))
  5684. (setq issue "No valid clock line") (throw 'next t))
  5685. (org-with-point-at m
  5686. (save-excursion
  5687. (goto-char (point-at-bol))
  5688. (unless (looking-at re)
  5689. (error "No valid Clock line")
  5690. (throw 'next t))
  5691. (unless (match-end 3)
  5692. (setq issue
  5693. (format
  5694. "No end time: (%s)"
  5695. (org-duration-from-minutes
  5696. (floor
  5697. (- (float-time (org-current-time))
  5698. (float-time (org-time-string-to-time (match-string 1))))
  5699. 60)))
  5700. face (or (plist-get pl :no-end-time-face) face))
  5701. (throw 'next t))
  5702. (setq ts (match-string 1)
  5703. te (match-string 3)
  5704. ts (float-time (org-time-string-to-time ts))
  5705. te (float-time (org-time-string-to-time te))
  5706. dt (- te ts))))
  5707. (cond
  5708. ((> dt (* 60 maxtime))
  5709. ;; a very long clocking chunk
  5710. (setq issue (format "Clocking interval is very long: %s"
  5711. (org-duration-from-minutes (floor dt 60)))
  5712. face (or (plist-get pl :long-face) face)))
  5713. ((< dt (* 60 mintime))
  5714. ;; a very short clocking chunk
  5715. (setq issue (format "Clocking interval is very short: %s"
  5716. (org-duration-from-minutes (floor dt 60)))
  5717. face (or (plist-get pl :short-face) face)))
  5718. ((and (> tlend 0) (< ts tlend))
  5719. ;; Two clock entries are overlapping
  5720. (setq issue (format "Clocking overlap: %d minutes"
  5721. (/ (- tlend ts) 60))
  5722. face (or (plist-get pl :overlap-face) face)))
  5723. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5724. ;; There is a gap, lets see if we need to report it
  5725. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5726. (setq issue (format "Clocking gap: %d minutes"
  5727. (/ (- ts tlend) 60))
  5728. face (or (plist-get pl :gap-face) face))))
  5729. (t nil)))
  5730. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5731. (when issue
  5732. ;; OK, there was some issue, add an overlay to show the issue
  5733. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5734. (overlay-put ov 'before-string
  5735. (concat
  5736. (org-add-props
  5737. (format "%-43s" (concat " " issue))
  5738. nil
  5739. 'face face)
  5740. "\n"))
  5741. (overlay-put ov 'evaporate t)))))
  5742. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5743. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5744. (catch 'exit
  5745. (unless ok-list
  5746. ;; there are no OK times for gaps...
  5747. (throw 'exit nil))
  5748. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5749. ;; This is more than 24 hours, so it is OK.
  5750. ;; because we have at least one OK time, that must be in the
  5751. ;; 24 hour interval.
  5752. (throw 'exit t))
  5753. ;; We have a shorter gap.
  5754. ;; Now we have to get the minute of the day when these times are
  5755. (let* ((t1dec (decode-time t1))
  5756. (t2dec (decode-time t2))
  5757. ;; compute the minute on the day
  5758. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5759. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5760. (when (< min2 min1)
  5761. ;; if min2 is smaller than min1, this means it is on the next day.
  5762. ;; Wrap it to after midnight.
  5763. (setq min2 (+ min2 1440)))
  5764. ;; Now check if any of the OK times is in the gap
  5765. (mapc (lambda (x)
  5766. ;; Wrap the time to after midnight if necessary
  5767. (when (< x min1) (setq x (+ x 1440)))
  5768. ;; Check if in interval
  5769. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5770. ok-list)
  5771. ;; Nope, this gap is not OK
  5772. nil)))
  5773. (defun org-agenda-get-deadlines (&optional with-hour)
  5774. "Return the deadline information for agenda display.
  5775. When WITH-HOUR is non-nil, only return deadlines with an hour
  5776. specification like [h]h:mm."
  5777. (with-no-warnings (defvar date))
  5778. (let* ((props (list 'mouse-face 'highlight
  5779. 'org-not-done-regexp org-not-done-regexp
  5780. 'org-todo-regexp org-todo-regexp
  5781. 'org-complex-heading-regexp org-complex-heading-regexp
  5782. 'help-echo
  5783. (format "mouse-2 or RET jump to org file %s"
  5784. (abbreviate-file-name buffer-file-name))))
  5785. (regexp (if with-hour
  5786. org-deadline-time-hour-regexp
  5787. org-deadline-time-regexp))
  5788. (today (org-today))
  5789. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5790. (current (calendar-absolute-from-gregorian date))
  5791. deadline-items)
  5792. (goto-char (point-min))
  5793. (if (org-element--cache-active-p)
  5794. (org-element-cache-map
  5795. (lambda (el)
  5796. (when (and (org-element-property :deadline el)
  5797. (or (not with-hour)
  5798. (org-element-property
  5799. :hour-start
  5800. (org-element-property :deadline el))
  5801. (org-element-property
  5802. :hour-end
  5803. (org-element-property :deadline el))))
  5804. (goto-char (org-element-property :contents-begin el))
  5805. (catch :skip
  5806. (org-agenda-skip el)
  5807. (let* ((s (substring (org-element-property
  5808. :raw-value
  5809. (org-element-property :deadline el))
  5810. 1 -1))
  5811. (pos (save-excursion
  5812. (goto-char (org-element-property :contents-begin el))
  5813. ;; We intentionally leave NOERROR
  5814. ;; argument in `re-search-forward' nil. If
  5815. ;; the search fails here, something went
  5816. ;; wrong and we are looking at
  5817. ;; non-matching headline.
  5818. (re-search-forward regexp (line-end-position))
  5819. (1- (match-beginning 1))))
  5820. (todo-state (org-element-property :todo-keyword el))
  5821. (done? (eq 'done (org-element-property :todo-type el)))
  5822. (sexp? (eq 'diary
  5823. (org-element-property
  5824. :type (org-element-property :deadline el))))
  5825. ;; DEADLINE is the deadline date for the entry. It is
  5826. ;; either the base date or the last repeat, according
  5827. ;; to `org-agenda-prefer-last-repeat'.
  5828. (deadline
  5829. (cond
  5830. (sexp? (org-agenda--timestamp-to-absolute s current))
  5831. ((or (eq org-agenda-prefer-last-repeat t)
  5832. (member todo-state org-agenda-prefer-last-repeat))
  5833. (org-agenda--timestamp-to-absolute
  5834. s today 'past (current-buffer) pos))
  5835. (t (org-agenda--timestamp-to-absolute s))))
  5836. ;; REPEAT is the future repeat closest from CURRENT,
  5837. ;; according to `org-agenda-show-future-repeats'. If
  5838. ;; the latter is nil, or if the time stamp has no
  5839. ;; repeat part, default to DEADLINE.
  5840. (repeat
  5841. (cond
  5842. (sexp? deadline)
  5843. ((<= current today) deadline)
  5844. ((not org-agenda-show-future-repeats) deadline)
  5845. (t
  5846. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5847. (1+ today)
  5848. current)))
  5849. (org-agenda--timestamp-to-absolute
  5850. s base 'future (current-buffer) pos)))))
  5851. (diff (- deadline current))
  5852. (suppress-prewarning
  5853. (let ((scheduled
  5854. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5855. (org-element-property
  5856. :raw-value
  5857. (org-element-property :scheduled el)))))
  5858. (cond
  5859. ((not scheduled) nil)
  5860. ;; The current item has a scheduled date, so
  5861. ;; evaluate its prewarning lead time.
  5862. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5863. ;; Use global prewarning-restart lead time.
  5864. org-agenda-skip-deadline-prewarning-if-scheduled)
  5865. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5866. 'pre-scheduled)
  5867. ;; Set pre-warning to no earlier than SCHEDULED.
  5868. (min (- deadline
  5869. (org-agenda--timestamp-to-absolute scheduled))
  5870. org-deadline-warning-days))
  5871. ;; Set pre-warning to deadline.
  5872. (t 0))))
  5873. (wdays (or suppress-prewarning (org-get-wdays s))))
  5874. (cond
  5875. ;; Only display deadlines at their base date, at future
  5876. ;; repeat occurrences or in today agenda.
  5877. ((= current deadline) nil)
  5878. ((= current repeat) nil)
  5879. ((not today?) (throw :skip nil))
  5880. ;; Upcoming deadline: display within warning period WDAYS.
  5881. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5882. ;; Overdue deadline: warn about it for
  5883. ;; `org-deadline-past-days' duration.
  5884. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5885. ;; Possibly skip done tasks.
  5886. (when (and done?
  5887. (or org-agenda-skip-deadline-if-done
  5888. (/= deadline current)))
  5889. (throw :skip nil))
  5890. (save-excursion
  5891. (goto-char (org-element-property :begin el))
  5892. (let* ((category (org-get-category))
  5893. (effort (save-match-data (or (get-text-property (point) 'effort)
  5894. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5895. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5896. (level (make-string (org-element-property :level el)
  5897. ?\s))
  5898. (head (save-excursion
  5899. (goto-char (org-element-property :begin el))
  5900. (re-search-forward org-outline-regexp-bol)
  5901. (buffer-substring-no-properties (point) (line-end-position))))
  5902. (inherited-tags
  5903. (or (eq org-agenda-show-inherited-tags 'always)
  5904. (and (listp org-agenda-show-inherited-tags)
  5905. (memq 'agenda org-agenda-show-inherited-tags))
  5906. (and (eq org-agenda-show-inherited-tags t)
  5907. (or (eq org-agenda-use-tag-inheritance t)
  5908. (memq 'agenda
  5909. org-agenda-use-tag-inheritance)))))
  5910. (tags (org-get-tags el (not inherited-tags)))
  5911. (time
  5912. (cond
  5913. ;; No time of day designation if it is only
  5914. ;; a reminder.
  5915. ((and (/= current deadline) (/= current repeat)) nil)
  5916. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5917. (concat (substring s (match-beginning 1)) " "))
  5918. (t 'time)))
  5919. (item
  5920. (org-agenda-format-item
  5921. ;; Insert appropriate suffixes before deadlines.
  5922. ;; Those only apply to today agenda.
  5923. (pcase-let ((`(,now ,future ,past)
  5924. org-agenda-deadline-leaders))
  5925. (cond
  5926. ((and today? (< deadline today)) (format past (- diff)))
  5927. ((and today? (> deadline today)) (format future diff))
  5928. (t now)))
  5929. (org-add-props head nil
  5930. 'effort effort
  5931. 'effort-minutes effort-minutes)
  5932. level category tags time))
  5933. (face (org-agenda-deadline-face
  5934. (- 1 (/ (float diff) (max wdays 1)))))
  5935. (upcoming? (and today? (> deadline today)))
  5936. (warntime (get-text-property (point) 'org-appt-warntime)))
  5937. (org-add-props item props
  5938. 'org-marker (org-agenda-new-marker pos)
  5939. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5940. 'warntime warntime
  5941. 'level level
  5942. 'effort effort 'effort-minutes effort-minutes
  5943. 'ts-date deadline
  5944. 'priority
  5945. ;; Adjust priority to today reminders about deadlines.
  5946. ;; Overdue deadlines get the highest priority
  5947. ;; increase, then imminent deadlines and eventually
  5948. ;; more distant deadlines.
  5949. (let ((adjust (if today? (- diff) 0)))
  5950. (+ adjust (org-get-priority item)))
  5951. 'todo-state todo-state
  5952. 'type (if upcoming? "upcoming-deadline" "deadline")
  5953. 'date (if upcoming? date deadline)
  5954. 'face (if done? 'org-agenda-done face)
  5955. 'undone-face face
  5956. 'done-face 'org-agenda-done)
  5957. (push item deadline-items)))))))
  5958. :next-re regexp
  5959. :fail-re regexp
  5960. :narrow t)
  5961. (while (re-search-forward regexp nil t)
  5962. (catch :skip
  5963. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5964. (org-agenda-skip)
  5965. (let* ((s (match-string 1))
  5966. (pos (1- (match-beginning 1)))
  5967. (todo-state (save-match-data (org-get-todo-state)))
  5968. (done? (member todo-state org-done-keywords))
  5969. (sexp? (string-prefix-p "%%" s))
  5970. ;; DEADLINE is the deadline date for the entry. It is
  5971. ;; either the base date or the last repeat, according
  5972. ;; to `org-agenda-prefer-last-repeat'.
  5973. (deadline
  5974. (cond
  5975. (sexp? (org-agenda--timestamp-to-absolute s current))
  5976. ((or (eq org-agenda-prefer-last-repeat t)
  5977. (member todo-state org-agenda-prefer-last-repeat))
  5978. (org-agenda--timestamp-to-absolute
  5979. s today 'past (current-buffer) pos))
  5980. (t (org-agenda--timestamp-to-absolute s))))
  5981. ;; REPEAT is the future repeat closest from CURRENT,
  5982. ;; according to `org-agenda-show-future-repeats'. If
  5983. ;; the latter is nil, or if the time stamp has no
  5984. ;; repeat part, default to DEADLINE.
  5985. (repeat
  5986. (cond
  5987. (sexp? deadline)
  5988. ((<= current today) deadline)
  5989. ((not org-agenda-show-future-repeats) deadline)
  5990. (t
  5991. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5992. (1+ today)
  5993. current)))
  5994. (org-agenda--timestamp-to-absolute
  5995. s base 'future (current-buffer) pos)))))
  5996. (diff (- deadline current))
  5997. (suppress-prewarning
  5998. (let ((scheduled
  5999. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6000. (org-entry-get nil "SCHEDULED"))))
  6001. (cond
  6002. ((not scheduled) nil)
  6003. ;; The current item has a scheduled date, so
  6004. ;; evaluate its prewarning lead time.
  6005. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6006. ;; Use global prewarning-restart lead time.
  6007. org-agenda-skip-deadline-prewarning-if-scheduled)
  6008. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6009. 'pre-scheduled)
  6010. ;; Set pre-warning to no earlier than SCHEDULED.
  6011. (min (- deadline
  6012. (org-agenda--timestamp-to-absolute scheduled))
  6013. org-deadline-warning-days))
  6014. ;; Set pre-warning to deadline.
  6015. (t 0))))
  6016. (wdays (or suppress-prewarning (org-get-wdays s))))
  6017. (cond
  6018. ;; Only display deadlines at their base date, at future
  6019. ;; repeat occurrences or in today agenda.
  6020. ((= current deadline) nil)
  6021. ((= current repeat) nil)
  6022. ((not today?) (throw :skip nil))
  6023. ;; Upcoming deadline: display within warning period WDAYS.
  6024. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6025. ;; Overdue deadline: warn about it for
  6026. ;; `org-deadline-past-days' duration.
  6027. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6028. ;; Possibly skip done tasks.
  6029. (when (and done?
  6030. (or org-agenda-skip-deadline-if-done
  6031. (/= deadline current)))
  6032. (throw :skip nil))
  6033. (save-excursion
  6034. (re-search-backward "^\\*+[ \t]+" nil t)
  6035. (goto-char (match-end 0))
  6036. (let* ((category (org-get-category))
  6037. (effort (save-match-data (or (get-text-property (point) 'effort)
  6038. (org-entry-get (point) org-effort-property))))
  6039. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6040. (level (make-string (org-reduced-level (org-outline-level))
  6041. ?\s))
  6042. (head (buffer-substring-no-properties
  6043. (point) (line-end-position)))
  6044. (inherited-tags
  6045. (or (eq org-agenda-show-inherited-tags 'always)
  6046. (and (listp org-agenda-show-inherited-tags)
  6047. (memq 'agenda org-agenda-show-inherited-tags))
  6048. (and (eq org-agenda-show-inherited-tags t)
  6049. (or (eq org-agenda-use-tag-inheritance t)
  6050. (memq 'agenda
  6051. org-agenda-use-tag-inheritance)))))
  6052. (tags (org-get-tags nil (not inherited-tags)))
  6053. (time
  6054. (cond
  6055. ;; No time of day designation if it is only
  6056. ;; a reminder.
  6057. ((and (/= current deadline) (/= current repeat)) nil)
  6058. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6059. (concat (substring s (match-beginning 1)) " "))
  6060. (t 'time)))
  6061. (item
  6062. (org-agenda-format-item
  6063. ;; Insert appropriate suffixes before deadlines.
  6064. ;; Those only apply to today agenda.
  6065. (pcase-let ((`(,now ,future ,past)
  6066. org-agenda-deadline-leaders))
  6067. (cond
  6068. ((and today? (< deadline today)) (format past (- diff)))
  6069. ((and today? (> deadline today)) (format future diff))
  6070. (t now)))
  6071. (org-add-props head nil
  6072. 'effort effort
  6073. 'effort-minutes effort-minutes)
  6074. level category tags time))
  6075. (face (org-agenda-deadline-face
  6076. (- 1 (/ (float diff) (max wdays 1)))))
  6077. (upcoming? (and today? (> deadline today)))
  6078. (warntime (get-text-property (point) 'org-appt-warntime)))
  6079. (org-add-props item props
  6080. 'org-marker (org-agenda-new-marker pos)
  6081. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6082. 'warntime warntime
  6083. 'level level
  6084. 'effort effort 'effort-minutes effort-minutes
  6085. 'ts-date deadline
  6086. 'priority
  6087. ;; Adjust priority to today reminders about deadlines.
  6088. ;; Overdue deadlines get the highest priority
  6089. ;; increase, then imminent deadlines and eventually
  6090. ;; more distant deadlines.
  6091. (let ((adjust (if today? (- diff) 0)))
  6092. (+ adjust (org-get-priority item)))
  6093. 'todo-state todo-state
  6094. 'type (if upcoming? "upcoming-deadline" "deadline")
  6095. 'date (if upcoming? date deadline)
  6096. 'face (if done? 'org-agenda-done face)
  6097. 'undone-face face
  6098. 'done-face 'org-agenda-done)
  6099. (push item deadline-items)))))))
  6100. (nreverse deadline-items)))
  6101. (defun org-agenda-deadline-face (fraction)
  6102. "Return the face to displaying a deadline item.
  6103. FRACTION is what fraction of the head-warning time has passed."
  6104. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6105. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6106. "Return the scheduled information for agenda display.
  6107. Optional argument DEADLINES is a list of deadline items to be
  6108. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6109. scheduled items with an hour specification like [h]h:mm."
  6110. (with-no-warnings (defvar date))
  6111. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6112. 'org-todo-regexp org-todo-regexp
  6113. 'org-complex-heading-regexp org-complex-heading-regexp
  6114. 'done-face 'org-agenda-done
  6115. 'mouse-face 'highlight
  6116. 'help-echo
  6117. (format "mouse-2 or RET jump to Org file %s"
  6118. (abbreviate-file-name buffer-file-name))))
  6119. (regexp (if with-hour
  6120. org-scheduled-time-hour-regexp
  6121. org-scheduled-time-regexp))
  6122. (today (org-today))
  6123. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6124. (current (calendar-absolute-from-gregorian date))
  6125. (deadline-pos
  6126. (mapcar (lambda (d)
  6127. (let ((m (get-text-property 0 'org-hd-marker d)))
  6128. (and m (marker-position m))))
  6129. deadlines))
  6130. scheduled-items)
  6131. (goto-char (point-min))
  6132. (if (org-element--cache-active-p)
  6133. (org-element-cache-map
  6134. (lambda (el)
  6135. (when (and (org-element-property :scheduled el)
  6136. (or (not with-hour)
  6137. (org-element-property
  6138. :hour-start
  6139. (org-element-property :scheduled el))
  6140. (org-element-property
  6141. :hour-end
  6142. (org-element-property :scheduled el))))
  6143. (goto-char (org-element-property :contents-begin el))
  6144. (catch :skip
  6145. (org-agenda-skip el)
  6146. (let* ((s (substring (org-element-property
  6147. :raw-value
  6148. (org-element-property :scheduled el))
  6149. 1 -1))
  6150. (pos (save-excursion
  6151. (goto-char (org-element-property :contents-begin el))
  6152. ;; We intentionally leave NOERROR
  6153. ;; argument in `re-search-forward' nil. If
  6154. ;; the search fails here, something went
  6155. ;; wrong and we are looking at
  6156. ;; non-matching headline.
  6157. (re-search-forward regexp (line-end-position))
  6158. (1- (match-beginning 1))))
  6159. (todo-state (org-element-property :todo-keyword el))
  6160. (donep (eq 'done (org-element-property :todo-type el)))
  6161. (sexp? (eq 'diary
  6162. (org-element-property
  6163. :type (org-element-property :scheduled el))))
  6164. ;; SCHEDULE is the scheduled date for the entry. It is
  6165. ;; either the bare date or the last repeat, according
  6166. ;; to `org-agenda-prefer-last-repeat'.
  6167. (schedule
  6168. (cond
  6169. (sexp? (org-agenda--timestamp-to-absolute s current))
  6170. ((or (eq org-agenda-prefer-last-repeat t)
  6171. (member todo-state org-agenda-prefer-last-repeat))
  6172. (org-agenda--timestamp-to-absolute
  6173. s today 'past (current-buffer) pos))
  6174. (t (org-agenda--timestamp-to-absolute s))))
  6175. ;; REPEAT is the future repeat closest from CURRENT,
  6176. ;; according to `org-agenda-show-future-repeats'. If
  6177. ;; the latter is nil, or if the time stamp has no
  6178. ;; repeat part, default to SCHEDULE.
  6179. (repeat
  6180. (cond
  6181. (sexp? schedule)
  6182. ((<= current today) schedule)
  6183. ((not org-agenda-show-future-repeats) schedule)
  6184. (t
  6185. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6186. (1+ today)
  6187. current)))
  6188. (org-agenda--timestamp-to-absolute
  6189. s base 'future (current-buffer) pos)))))
  6190. (diff (- current schedule))
  6191. (warntime (get-text-property (point) 'org-appt-warntime))
  6192. (pastschedp (< schedule today))
  6193. (futureschedp (> schedule today))
  6194. (habitp (and (fboundp 'org-is-habit-p)
  6195. (string= "habit" (org-element-property :STYLE el))))
  6196. (suppress-delay
  6197. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6198. (org-element-property
  6199. :raw-value
  6200. (org-element-property :deadline el)))))
  6201. (cond
  6202. ((not deadline) nil)
  6203. ;; The current item has a deadline date, so
  6204. ;; evaluate its delay time.
  6205. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6206. ;; Use global delay time.
  6207. (- org-agenda-skip-scheduled-delay-if-deadline))
  6208. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6209. 'post-deadline)
  6210. ;; Set delay to no later than DEADLINE.
  6211. (min (- schedule
  6212. (org-agenda--timestamp-to-absolute deadline))
  6213. org-scheduled-delay-days))
  6214. (t 0))))
  6215. (ddays
  6216. (cond
  6217. ;; Nullify delay when a repeater triggered already
  6218. ;; and the delay is of the form --Xd.
  6219. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6220. (> schedule (org-agenda--timestamp-to-absolute s)))
  6221. 0)
  6222. (suppress-delay
  6223. (let ((org-scheduled-delay-days suppress-delay))
  6224. (org-get-wdays s t t)))
  6225. (t (org-get-wdays s t)))))
  6226. ;; Display scheduled items at base date (SCHEDULE), today if
  6227. ;; scheduled before the current date, and at any repeat past
  6228. ;; today. However, skip delayed items and items that have
  6229. ;; been displayed for more than `org-scheduled-past-days'.
  6230. (unless (and todayp
  6231. habitp
  6232. (bound-and-true-p org-habit-show-all-today))
  6233. (when (or (and (> ddays 0) (< diff ddays))
  6234. (> diff (or (and habitp org-habit-scheduled-past-days)
  6235. org-scheduled-past-days))
  6236. (> schedule current)
  6237. (and (/= current schedule)
  6238. (/= current today)
  6239. (/= current repeat)))
  6240. (throw :skip nil)))
  6241. ;; Possibly skip done tasks.
  6242. (when (and donep
  6243. (or org-agenda-skip-scheduled-if-done
  6244. (/= schedule current)))
  6245. (throw :skip nil))
  6246. ;; Skip entry if it already appears as a deadline, per
  6247. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6248. ;; doesn't apply to habits.
  6249. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6250. ((guard
  6251. (or (not (memq (line-beginning-position 0) deadline-pos))
  6252. habitp))
  6253. nil)
  6254. (`repeated-after-deadline
  6255. (let ((deadline (time-to-days
  6256. (when (org-element-property :deadline el)
  6257. (org-time-string-to-time
  6258. (org-element-property :deadline el))))))
  6259. (and (<= schedule deadline) (> current deadline))))
  6260. (`not-today pastschedp)
  6261. (`t t)
  6262. (_ nil))
  6263. (throw :skip nil))
  6264. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6265. ;; only show them for today. Also skip done habits.
  6266. (when (and habitp
  6267. (or donep
  6268. (not (bound-and-true-p org-habit-show-habits))
  6269. (and (not todayp)
  6270. (bound-and-true-p
  6271. org-habit-show-habits-only-for-today))))
  6272. (throw :skip nil))
  6273. (save-excursion
  6274. (goto-char (org-element-property :begin el))
  6275. (let* ((category (org-get-category))
  6276. (effort (save-match-data
  6277. (or (get-text-property (point) 'effort)
  6278. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6279. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6280. (inherited-tags
  6281. (or (eq org-agenda-show-inherited-tags 'always)
  6282. (and (listp org-agenda-show-inherited-tags)
  6283. (memq 'agenda org-agenda-show-inherited-tags))
  6284. (and (eq org-agenda-show-inherited-tags t)
  6285. (or (eq org-agenda-use-tag-inheritance t)
  6286. (memq 'agenda
  6287. org-agenda-use-tag-inheritance)))))
  6288. (tags (org-get-tags el (not inherited-tags)))
  6289. (level (make-string (org-element-property :level el)
  6290. ?\s))
  6291. (head (save-excursion
  6292. (goto-char (org-element-property :begin el))
  6293. (re-search-forward org-outline-regexp-bol)
  6294. (buffer-substring (point) (line-end-position))))
  6295. (time
  6296. (cond
  6297. ;; No time of day designation if it is only a
  6298. ;; reminder, except for habits, which always show
  6299. ;; the time of day. Habits are an exception
  6300. ;; because if there is a time of day, that is
  6301. ;; interpreted to mean they should usually happen
  6302. ;; then, even if doing the habit was missed.
  6303. ((and
  6304. (not habitp)
  6305. (/= current schedule)
  6306. (/= current repeat))
  6307. nil)
  6308. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6309. (concat (substring s (match-beginning 1)) " "))
  6310. (t 'time)))
  6311. (item
  6312. (org-agenda-format-item
  6313. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6314. ;; Show a reminder of a past scheduled today.
  6315. (if (and todayp pastschedp)
  6316. (format past diff)
  6317. first))
  6318. (org-add-props head nil
  6319. 'effort effort
  6320. 'effort-minutes effort-minutes)
  6321. level category tags time nil habitp))
  6322. (face (cond ((and (not habitp) pastschedp)
  6323. 'org-scheduled-previously)
  6324. ((and habitp futureschedp)
  6325. 'org-agenda-done)
  6326. (todayp 'org-scheduled-today)
  6327. (t 'org-scheduled)))
  6328. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6329. (org-add-props item props
  6330. 'undone-face face
  6331. 'face (if donep 'org-agenda-done face)
  6332. 'org-marker (org-agenda-new-marker pos)
  6333. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6334. 'type (if pastschedp "past-scheduled" "scheduled")
  6335. 'date (if pastschedp schedule date)
  6336. 'ts-date schedule
  6337. 'warntime warntime
  6338. 'level level
  6339. 'effort effort 'effort-minutes effort-minutes
  6340. 'priority (if habitp (org-habit-get-priority habitp)
  6341. (+ 99 diff (org-get-priority item)))
  6342. 'org-habit-p habitp
  6343. 'todo-state todo-state)
  6344. (push item scheduled-items)))))))
  6345. :next-re regexp
  6346. :fail-re regexp
  6347. :narrow t)
  6348. (while (re-search-forward regexp nil t)
  6349. (catch :skip
  6350. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6351. (org-agenda-skip)
  6352. (let* ((s (match-string 1))
  6353. (pos (1- (match-beginning 1)))
  6354. (todo-state (save-match-data (org-get-todo-state)))
  6355. (donep (member todo-state org-done-keywords))
  6356. (sexp? (string-prefix-p "%%" s))
  6357. ;; SCHEDULE is the scheduled date for the entry. It is
  6358. ;; either the bare date or the last repeat, according
  6359. ;; to `org-agenda-prefer-last-repeat'.
  6360. (schedule
  6361. (cond
  6362. (sexp? (org-agenda--timestamp-to-absolute s current))
  6363. ((or (eq org-agenda-prefer-last-repeat t)
  6364. (member todo-state org-agenda-prefer-last-repeat))
  6365. (org-agenda--timestamp-to-absolute
  6366. s today 'past (current-buffer) pos))
  6367. (t (org-agenda--timestamp-to-absolute s))))
  6368. ;; REPEAT is the future repeat closest from CURRENT,
  6369. ;; according to `org-agenda-show-future-repeats'. If
  6370. ;; the latter is nil, or if the time stamp has no
  6371. ;; repeat part, default to SCHEDULE.
  6372. (repeat
  6373. (cond
  6374. (sexp? schedule)
  6375. ((<= current today) schedule)
  6376. ((not org-agenda-show-future-repeats) schedule)
  6377. (t
  6378. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6379. (1+ today)
  6380. current)))
  6381. (org-agenda--timestamp-to-absolute
  6382. s base 'future (current-buffer) pos)))))
  6383. (diff (- current schedule))
  6384. (warntime (get-text-property (point) 'org-appt-warntime))
  6385. (pastschedp (< schedule today))
  6386. (futureschedp (> schedule today))
  6387. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6388. (suppress-delay
  6389. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6390. (org-entry-get nil "DEADLINE"))))
  6391. (cond
  6392. ((not deadline) nil)
  6393. ;; The current item has a deadline date, so
  6394. ;; evaluate its delay time.
  6395. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6396. ;; Use global delay time.
  6397. (- org-agenda-skip-scheduled-delay-if-deadline))
  6398. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6399. 'post-deadline)
  6400. ;; Set delay to no later than DEADLINE.
  6401. (min (- schedule
  6402. (org-agenda--timestamp-to-absolute deadline))
  6403. org-scheduled-delay-days))
  6404. (t 0))))
  6405. (ddays
  6406. (cond
  6407. ;; Nullify delay when a repeater triggered already
  6408. ;; and the delay is of the form --Xd.
  6409. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6410. (> schedule (org-agenda--timestamp-to-absolute s)))
  6411. 0)
  6412. (suppress-delay
  6413. (let ((org-scheduled-delay-days suppress-delay))
  6414. (org-get-wdays s t t)))
  6415. (t (org-get-wdays s t)))))
  6416. ;; Display scheduled items at base date (SCHEDULE), today if
  6417. ;; scheduled before the current date, and at any repeat past
  6418. ;; today. However, skip delayed items and items that have
  6419. ;; been displayed for more than `org-scheduled-past-days'.
  6420. (unless (and todayp
  6421. habitp
  6422. (bound-and-true-p org-habit-show-all-today))
  6423. (when (or (and (> ddays 0) (< diff ddays))
  6424. (> diff (or (and habitp org-habit-scheduled-past-days)
  6425. org-scheduled-past-days))
  6426. (> schedule current)
  6427. (and (/= current schedule)
  6428. (/= current today)
  6429. (/= current repeat)))
  6430. (throw :skip nil)))
  6431. ;; Possibly skip done tasks.
  6432. (when (and donep
  6433. (or org-agenda-skip-scheduled-if-done
  6434. (/= schedule current)))
  6435. (throw :skip nil))
  6436. ;; Skip entry if it already appears as a deadline, per
  6437. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6438. ;; doesn't apply to habits.
  6439. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6440. ((guard
  6441. (or (not (memq (line-beginning-position 0) deadline-pos))
  6442. habitp))
  6443. nil)
  6444. (`repeated-after-deadline
  6445. (let ((deadline (time-to-days
  6446. (org-get-deadline-time (point)))))
  6447. (and (<= schedule deadline) (> current deadline))))
  6448. (`not-today pastschedp)
  6449. (`t t)
  6450. (_ nil))
  6451. (throw :skip nil))
  6452. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6453. ;; only show them for today. Also skip done habits.
  6454. (when (and habitp
  6455. (or donep
  6456. (not (bound-and-true-p org-habit-show-habits))
  6457. (and (not todayp)
  6458. (bound-and-true-p
  6459. org-habit-show-habits-only-for-today))))
  6460. (throw :skip nil))
  6461. (save-excursion
  6462. (re-search-backward "^\\*+[ \t]+" nil t)
  6463. (goto-char (match-end 0))
  6464. (let* ((category (org-get-category))
  6465. (effort (save-match-data (or (get-text-property (point) 'effort)
  6466. (org-entry-get (point) org-effort-property))))
  6467. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6468. (inherited-tags
  6469. (or (eq org-agenda-show-inherited-tags 'always)
  6470. (and (listp org-agenda-show-inherited-tags)
  6471. (memq 'agenda org-agenda-show-inherited-tags))
  6472. (and (eq org-agenda-show-inherited-tags t)
  6473. (or (eq org-agenda-use-tag-inheritance t)
  6474. (memq 'agenda
  6475. org-agenda-use-tag-inheritance)))))
  6476. (tags (org-get-tags nil (not inherited-tags)))
  6477. (level (make-string (org-reduced-level (org-outline-level))
  6478. ?\s))
  6479. (head (buffer-substring (point) (line-end-position)))
  6480. (time
  6481. (cond
  6482. ;; No time of day designation if it is only a
  6483. ;; reminder, except for habits, which always show
  6484. ;; the time of day. Habits are an exception
  6485. ;; because if there is a time of day, that is
  6486. ;; interpreted to mean they should usually happen
  6487. ;; then, even if doing the habit was missed.
  6488. ((and
  6489. (not habitp)
  6490. (/= current schedule)
  6491. (/= current repeat))
  6492. nil)
  6493. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6494. (concat (substring s (match-beginning 1)) " "))
  6495. (t 'time)))
  6496. (item
  6497. (org-agenda-format-item
  6498. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6499. ;; Show a reminder of a past scheduled today.
  6500. (if (and todayp pastschedp)
  6501. (format past diff)
  6502. first))
  6503. (org-add-props head nil
  6504. 'effort effort
  6505. 'effort-minutes effort-minutes)
  6506. level category tags time nil habitp))
  6507. (face (cond ((and (not habitp) pastschedp)
  6508. 'org-scheduled-previously)
  6509. ((and habitp futureschedp)
  6510. 'org-agenda-done)
  6511. (todayp 'org-scheduled-today)
  6512. (t 'org-scheduled)))
  6513. (habitp (and habitp (org-habit-parse-todo))))
  6514. (org-add-props item props
  6515. 'undone-face face
  6516. 'face (if donep 'org-agenda-done face)
  6517. 'org-marker (org-agenda-new-marker pos)
  6518. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6519. 'type (if pastschedp "past-scheduled" "scheduled")
  6520. 'date (if pastschedp schedule date)
  6521. 'ts-date schedule
  6522. 'warntime warntime
  6523. 'level level
  6524. 'effort effort 'effort-minutes effort-minutes
  6525. 'priority (if habitp (org-habit-get-priority habitp)
  6526. (+ 99 diff (org-get-priority item)))
  6527. 'org-habit-p habitp
  6528. 'todo-state todo-state)
  6529. (push item scheduled-items)))))))
  6530. (nreverse scheduled-items)))
  6531. (defun org-agenda-get-blocks ()
  6532. "Return the date-range information for agenda display."
  6533. (with-no-warnings (defvar date))
  6534. (let* ((props (list 'face nil
  6535. 'org-not-done-regexp org-not-done-regexp
  6536. 'org-todo-regexp org-todo-regexp
  6537. 'org-complex-heading-regexp org-complex-heading-regexp
  6538. 'mouse-face 'highlight
  6539. 'help-echo
  6540. (format "mouse-2 or RET jump to org file %s"
  6541. (abbreviate-file-name buffer-file-name))))
  6542. (regexp org-tr-regexp)
  6543. (d0 (calendar-absolute-from-gregorian date))
  6544. marker hdmarker ee txt d1 d2 s1 s2 category
  6545. level todo-state tags pos head donep inherited-tags
  6546. effort effort-minutes)
  6547. (goto-char (point-min))
  6548. (while (re-search-forward regexp nil t)
  6549. (catch :skip
  6550. (org-agenda-skip)
  6551. (setq pos (point))
  6552. (let ((start-time (match-string 1))
  6553. (end-time (match-string 2)))
  6554. (setq s1 (match-string 1)
  6555. s2 (match-string 2)
  6556. d1 (time-to-days
  6557. (condition-case err
  6558. (org-time-string-to-time s1)
  6559. (error
  6560. (error
  6561. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6562. s1
  6563. pos
  6564. (current-buffer)
  6565. (error-message-string err)))))
  6566. d2 (time-to-days
  6567. (condition-case err
  6568. (org-time-string-to-time s2)
  6569. (error
  6570. (error
  6571. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6572. s2
  6573. pos
  6574. (current-buffer)
  6575. (error-message-string err))))))
  6576. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6577. ;; Only allow days between the limits, because the normal
  6578. ;; date stamps will catch the limits.
  6579. (save-excursion
  6580. (setq todo-state (org-get-todo-state))
  6581. (setq donep (member todo-state org-done-keywords))
  6582. (when (and donep org-agenda-skip-timestamp-if-done)
  6583. (throw :skip t))
  6584. (setq marker (org-agenda-new-marker (point))
  6585. category (org-get-category))
  6586. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6587. (org-entry-get (point) org-effort-property))))
  6588. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6589. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6590. (throw :skip nil)
  6591. (goto-char (match-beginning 0))
  6592. (setq hdmarker (org-agenda-new-marker (point))
  6593. inherited-tags
  6594. (or (eq org-agenda-show-inherited-tags 'always)
  6595. (and (listp org-agenda-show-inherited-tags)
  6596. (memq 'agenda org-agenda-show-inherited-tags))
  6597. (and (eq org-agenda-show-inherited-tags t)
  6598. (or (eq org-agenda-use-tag-inheritance t)
  6599. (memq 'agenda org-agenda-use-tag-inheritance))))
  6600. tags (org-get-tags nil (not inherited-tags)))
  6601. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6602. (looking-at "\\*+[ \t]+\\(.*\\)")
  6603. (setq head (match-string 1))
  6604. (let ((remove-re
  6605. (if org-agenda-remove-timeranges-from-blocks
  6606. (concat
  6607. "<" (regexp-quote s1) ".*?>"
  6608. "--"
  6609. "<" (regexp-quote s2) ".*?>")
  6610. nil)))
  6611. (setq txt (org-agenda-format-item
  6612. (format
  6613. (nth (if (= d1 d2) 0 1)
  6614. org-agenda-timerange-leaders)
  6615. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6616. (org-add-props head nil
  6617. 'effort effort
  6618. 'effort-minutes effort-minutes)
  6619. level category tags
  6620. (save-match-data
  6621. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6622. (match-string 6 s1)))
  6623. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6624. (match-string 6 s2))))
  6625. (cond ((string= hhmm1 hhmm2)
  6626. (concat "<" start-time ">--<" end-time ">"))
  6627. ((and (= d1 d0) (= d2 d0))
  6628. (concat "<" start-time ">--<" end-time ">"))
  6629. ((= d1 d0)
  6630. (concat "<" start-time ">"))
  6631. ((= d2 d0)
  6632. (concat "<" end-time ">")))))
  6633. remove-re))))
  6634. (org-add-props txt props
  6635. 'org-marker marker 'org-hd-marker hdmarker
  6636. 'type "block" 'date date
  6637. 'level level
  6638. 'effort effort 'effort-minutes effort-minutes
  6639. 'todo-state todo-state
  6640. 'priority (org-get-priority txt))
  6641. (push txt ee))))
  6642. (goto-char pos)))
  6643. ;; Sort the entries by expiration date.
  6644. (nreverse ee)))
  6645. ;;; Agenda presentation and sorting
  6646. (defvar org-prefix-has-time nil
  6647. "A flag, set by `org-compile-prefix-format'.
  6648. The flag is set if the currently compiled format contains a `%t'.")
  6649. (defvar org-prefix-has-tag nil
  6650. "A flag, set by `org-compile-prefix-format'.
  6651. The flag is set if the currently compiled format contains a `%T'.")
  6652. (defvar org-prefix-has-effort nil
  6653. "A flag, set by `org-compile-prefix-format'.
  6654. The flag is set if the currently compiled format contains a `%e'.")
  6655. (defvar org-prefix-has-breadcrumbs nil
  6656. "A flag, set by `org-compile-prefix-format'.
  6657. The flag is set if the currently compiled format contains a `%b'.")
  6658. (defvar org-prefix-category-length nil
  6659. "Used by `org-compile-prefix-format' to remember the category field width.")
  6660. (defvar org-prefix-category-max-length nil
  6661. "Used by `org-compile-prefix-format' to remember the category field width.")
  6662. (defun org-agenda-get-category-icon (category)
  6663. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6664. (cl-dolist (entry org-agenda-category-icon-alist)
  6665. (when (string-match-p (car entry) category)
  6666. (if (listp (cadr entry))
  6667. (cl-return (cadr entry))
  6668. (cl-return (apply #'create-image (cdr entry)))))))
  6669. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6670. remove-re habitp)
  6671. "Format TXT to be inserted into the agenda buffer.
  6672. In particular, add the prefix and corresponding text properties.
  6673. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6674. WITH-LEVEL may be a string to replace the `%l' specifier.
  6675. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6676. category taken from local variable or file name. It will replace the `%c'
  6677. specifier in the format.
  6678. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6679. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6680. When DOTIME is a string, this string is searched for a time before TXT is.
  6681. TAGS can be the tags of the headline.
  6682. Any match of REMOVE-RE will be removed from TXT."
  6683. ;; We keep the org-prefix-* variable values along with a compiled
  6684. ;; formatter, so that multiple agendas existing at the same time do
  6685. ;; not step on each other toes.
  6686. ;;
  6687. ;; It was inconvenient to make these variables buffer local in
  6688. ;; Agenda buffers, because this function expects to be called with
  6689. ;; the buffer where item comes from being current, and not agenda
  6690. ;; buffer
  6691. (let* ((bindings (car org-prefix-format-compiled))
  6692. (formatter (cadr org-prefix-format-compiled)))
  6693. (cl-loop for (var value) in bindings
  6694. do (set var value))
  6695. (save-match-data
  6696. ;; Diary entries sometimes have extra whitespace at the beginning
  6697. (setq txt (org-trim txt))
  6698. ;; Fix the tags part in txt
  6699. (setq txt (org-agenda-fix-displayed-tags
  6700. txt tags
  6701. org-agenda-show-inherited-tags
  6702. org-agenda-hide-tags-regexp))
  6703. (with-no-warnings
  6704. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6705. ;; Based on what I see in `org-compile-prefix-format', I added
  6706. ;; a few more.
  6707. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6708. (defvar effort) (defvar extra)
  6709. (defvar level) (defvar tag) (defvar time))
  6710. (let* ((category (or with-category
  6711. (if buffer-file-name
  6712. (file-name-sans-extension
  6713. (file-name-nondirectory buffer-file-name))
  6714. "")))
  6715. (category-icon (org-agenda-get-category-icon category))
  6716. (category-icon (if category-icon
  6717. (propertize " " 'display category-icon)
  6718. ""))
  6719. (effort (and (not (string= txt ""))
  6720. (get-text-property 1 'effort txt)))
  6721. (tag (if tags (nth (1- (length tags)) tags) ""))
  6722. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6723. (extra (or (and (not habitp) extra) ""))
  6724. time
  6725. (ts (when dotime (concat
  6726. (if (stringp dotime) dotime "")
  6727. (and org-agenda-search-headline-for-time txt))))
  6728. (time-of-day (and dotime (org-get-time-of-day ts)))
  6729. stamp plain s0 s1 s2 rtn srp l
  6730. duration breadcrumbs)
  6731. (and (derived-mode-p 'org-mode) buffer-file-name
  6732. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6733. (when (and dotime time-of-day)
  6734. ;; Extract starting and ending time and move them to prefix
  6735. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6736. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6737. (setq s0 (match-string 0 ts)
  6738. srp (and stamp (match-end 3))
  6739. s1 (match-string (if plain 1 2) ts)
  6740. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6741. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6742. ;; them, we might want to remove them there to avoid duplication.
  6743. ;; The user can turn this off with a variable.
  6744. (when (and org-prefix-has-time
  6745. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6746. (string-match (concat (regexp-quote s0) " *") txt)
  6747. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6748. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6749. (= (match-beginning 0) 0)
  6750. t))
  6751. (setq txt (replace-match "" nil nil txt))))
  6752. ;; Normalize the time(s) to 24 hour.
  6753. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6754. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6755. ;; Try to set s2 if s1 and
  6756. ;; `org-agenda-default-appointment-duration' are set
  6757. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6758. (setq s2
  6759. (org-duration-from-minutes
  6760. (+ (org-duration-to-minutes s1 t)
  6761. org-agenda-default-appointment-duration)
  6762. nil t)))
  6763. ;; Compute the duration
  6764. (when s2
  6765. (setq duration (- (org-duration-to-minutes s2)
  6766. (org-duration-to-minutes s1))))
  6767. ;; Format S1 and S2 for display.
  6768. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6769. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6770. (when (string-match org-tag-group-re txt)
  6771. ;; Tags are in the string
  6772. (if (or (eq org-agenda-remove-tags t)
  6773. (and org-agenda-remove-tags
  6774. org-prefix-has-tag))
  6775. (setq txt (replace-match "" t t txt))
  6776. (setq txt (replace-match
  6777. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6778. (match-string 1 txt))
  6779. t t txt))))
  6780. (when remove-re
  6781. (while (string-match remove-re txt)
  6782. (setq txt (replace-match "" t t txt))))
  6783. ;; Set org-heading property on `txt' to mark the start of the
  6784. ;; heading.
  6785. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6786. ;; Prepare the variables needed in the eval of the compiled format
  6787. (when org-prefix-has-breadcrumbs
  6788. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6789. (let ((s (org-format-outline-path (org-get-outline-path)
  6790. (1- (frame-width))
  6791. nil org-agenda-breadcrumbs-separator)))
  6792. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6793. (setq time (cond (s2 (concat
  6794. (org-agenda-time-of-day-to-ampm-maybe s1)
  6795. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6796. (when org-agenda-timegrid-use-ampm " ")))
  6797. (s1 (concat
  6798. (org-agenda-time-of-day-to-ampm-maybe s1)
  6799. (if org-agenda-timegrid-use-ampm
  6800. (concat time-grid-trailing-characters " ")
  6801. time-grid-trailing-characters)))
  6802. (t ""))
  6803. category (if (symbolp category) (symbol-name category) category)
  6804. level (or with-level ""))
  6805. (if (string-match org-link-bracket-re category)
  6806. (progn
  6807. (setq l (string-width (or (match-string 2) (match-string 1))))
  6808. (when (< l (or org-prefix-category-length 0))
  6809. (setq category (copy-sequence category))
  6810. (org-add-props category nil
  6811. 'extra-space (make-string
  6812. (- org-prefix-category-length l 1) ?\ ))))
  6813. (when (and org-prefix-category-max-length
  6814. (>= (length category) org-prefix-category-max-length))
  6815. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6816. ;; Evaluate the compiled format
  6817. (setq rtn (concat (eval formatter t) txt))
  6818. ;; And finally add the text properties
  6819. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6820. (org-add-props rtn nil
  6821. 'org-category category
  6822. 'tags tags
  6823. 'org-priority-highest org-priority-highest
  6824. 'org-priority-lowest org-priority-lowest
  6825. 'time-of-day time-of-day
  6826. 'duration duration
  6827. 'breadcrumbs breadcrumbs
  6828. 'txt txt
  6829. 'level level
  6830. 'time time
  6831. 'extra extra
  6832. 'format org-prefix-format-compiled
  6833. 'dotime dotime)))))
  6834. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6835. "Remove tags string from TXT, and add a modified list of tags.
  6836. The modified list may contain inherited tags, and tags matched by
  6837. `org-agenda-hide-tags-regexp' will be removed."
  6838. (when (or add-inherited hide-re)
  6839. (when (string-match org-tag-group-re txt)
  6840. (setq txt (substring txt 0 (match-beginning 0))))
  6841. (setq tags
  6842. (delq nil
  6843. (mapcar (lambda (tg)
  6844. (if (or (and hide-re (string-match hide-re tg))
  6845. (and (not add-inherited)
  6846. (get-text-property 0 'inherited tg)))
  6847. nil
  6848. tg))
  6849. tags)))
  6850. (when tags
  6851. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6852. i)
  6853. (setq txt (concat txt " :"
  6854. (mapconcat
  6855. (lambda (x)
  6856. (setq i (get-text-property 0 'inherited x))
  6857. (if (and have-i (not i))
  6858. (progn
  6859. (setq have-i nil)
  6860. (concat ":" x))
  6861. x))
  6862. tags ":")
  6863. (if have-i "::" ":"))))))
  6864. txt)
  6865. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6866. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6867. "Add a time-grid for agenda items which need it.
  6868. LIST is the list of agenda items formatted by `org-agenda-list'.
  6869. NDAYS is the span of the current agenda view.
  6870. TODAYP is t when the current agenda view is on today."
  6871. (catch 'exit
  6872. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6873. ((and todayp (member 'today (car org-agenda-time-grid))))
  6874. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6875. ((member 'weekly (car org-agenda-time-grid)))
  6876. (t (throw 'exit list)))
  6877. (let* ((have (delq nil (mapcar
  6878. (lambda (x) (get-text-property 1 'time-of-day x))
  6879. list)))
  6880. (string (nth 3 org-agenda-time-grid))
  6881. (gridtimes (nth 1 org-agenda-time-grid))
  6882. (req (car org-agenda-time-grid))
  6883. (remove (member 'remove-match req))
  6884. new time)
  6885. (when (and (member 'require-timed req) (not have))
  6886. ;; don't show empty grid
  6887. (throw 'exit list))
  6888. (while (setq time (pop gridtimes))
  6889. (unless (and remove (member time have))
  6890. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6891. (push (org-agenda-format-item
  6892. nil string nil "" nil
  6893. (concat (substring time 0 -2) ":" (substring time -2)))
  6894. new)
  6895. (put-text-property
  6896. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6897. (when (and todayp org-agenda-show-current-time-in-grid)
  6898. (push (org-agenda-format-item
  6899. nil org-agenda-current-time-string nil "" nil
  6900. (format-time-string "%H:%M "))
  6901. new)
  6902. (put-text-property
  6903. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6904. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6905. (append new list)
  6906. (append list new)))))
  6907. (defun org-compile-prefix-format (key)
  6908. "Compile the prefix format into a Lisp form that can be evaluated.
  6909. KEY is the agenda type (see `org-agenda-prefix-format').
  6910. The resulting form and associated variable bindings is returned
  6911. and stored in the variable `org-prefix-format-compiled'."
  6912. (setq org-prefix-has-time nil
  6913. org-prefix-has-tag nil
  6914. org-prefix-category-length nil
  6915. org-prefix-has-effort nil
  6916. org-prefix-has-breadcrumbs nil)
  6917. (let ((s (cond
  6918. ((stringp org-agenda-prefix-format)
  6919. org-agenda-prefix-format)
  6920. ((assq key org-agenda-prefix-format)
  6921. (cdr (assq key org-agenda-prefix-format)))
  6922. (t " %-12:c%?-12t% s")))
  6923. (start 0)
  6924. varform vars var c f opt) ;; e
  6925. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6926. s start)
  6927. (setq var (or (cdr (assoc (match-string 4 s)
  6928. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6929. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6930. 'eval)
  6931. c (or (match-string 3 s) "")
  6932. opt (match-beginning 1)
  6933. start (1+ (match-beginning 0)))
  6934. (cl-case var
  6935. (time (setq org-prefix-has-time t))
  6936. (tag (setq org-prefix-has-tag t))
  6937. (effort (setq org-prefix-has-effort t))
  6938. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6939. (setq f (concat "%" (match-string 2 s) "s"))
  6940. (when (eq var 'category)
  6941. (setq org-prefix-category-length
  6942. (floor (abs (string-to-number (match-string 2 s)))))
  6943. (setq org-prefix-category-max-length
  6944. (let ((x (match-string 2 s)))
  6945. (save-match-data
  6946. (and (string-match "\\.[0-9]+" x)
  6947. (string-to-number (substring (match-string 0 x) 1)))))))
  6948. (if (eq var 'eval)
  6949. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6950. (if opt
  6951. (setq varform
  6952. `(if (member ,var '("" nil))
  6953. ""
  6954. (format ,f (concat ,var ,c))))
  6955. (setq varform
  6956. `(format ,f (if (member ,var '("" nil)) ""
  6957. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6958. (if (eq var 'eval)
  6959. (setf (substring s (match-beginning 0)
  6960. (+ (match-beginning 4)
  6961. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6962. "%s")
  6963. (setq s (replace-match "%s" t nil s)))
  6964. (push varform vars))
  6965. (setq vars (nreverse vars))
  6966. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6967. (setq org-prefix-format-compiled
  6968. (list
  6969. `((org-prefix-has-time ,org-prefix-has-time)
  6970. (org-prefix-has-tag ,org-prefix-has-tag)
  6971. (org-prefix-category-length ,org-prefix-category-length)
  6972. (org-prefix-has-effort ,org-prefix-has-effort)
  6973. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6974. `(format ,s ,@vars))))))
  6975. (defun org-set-sorting-strategy (key)
  6976. (setq org-agenda-sorting-strategy-selected
  6977. (if (symbolp (car org-agenda-sorting-strategy))
  6978. ;; the old format
  6979. org-agenda-sorting-strategy
  6980. (or (cdr (assq key org-agenda-sorting-strategy))
  6981. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6982. '(time-up category-keep priority-down)))))
  6983. (defun org-get-time-of-day (s &optional string)
  6984. "Check string S for a time of day.
  6985. If found, return it as a military time number between 0 and 2400.
  6986. If not found, return nil.
  6987. The optional STRING argument forces conversion into a 5 character wide string
  6988. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6989. where H:MM is the duration above midnight."
  6990. (let ((case-fold-search t)
  6991. (time-regexp
  6992. (rx word-start
  6993. (group (opt (any "012")) digit) ;group 1: hours
  6994. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6995. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6996. ;; Special "HHam/pm" case.
  6997. (group-n 3 (or "am" "pm")))
  6998. word-end)))
  6999. (save-match-data
  7000. (when (and (string-match time-regexp s)
  7001. (not (eq 'org-link (get-text-property 1 'face s))))
  7002. (let ((hours
  7003. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7004. (am-p (equal ampm "am")))
  7005. (pcase (string-to-number (match-string 1 s))
  7006. ((and (guard (not ampm)) h) h)
  7007. (12 (if am-p 0 12))
  7008. (h (+ h (if am-p 0 12))))))
  7009. (minutes
  7010. (if (match-end 2)
  7011. (string-to-number (match-string 2 s))
  7012. 0)))
  7013. (pcase string
  7014. (`nil (+ minutes (* hours 100)))
  7015. ((and `overtime
  7016. (guard (or (> hours 24)
  7017. (and (= hours 24)
  7018. (> minutes 0)))))
  7019. (format "+%d:%02d" (- hours 24) minutes))
  7020. ((guard org-agenda-time-leading-zero)
  7021. (format "%02d:%02d" hours minutes))
  7022. (_
  7023. (format "%d:%02d" hours minutes))))))))
  7024. (defvar org-agenda-before-sorting-filter-function nil
  7025. "Function to be applied to agenda items prior to sorting.
  7026. Prior to sorting also means just before they are inserted into the agenda.
  7027. To aid sorting, you may revisit the original entries and add more text
  7028. properties which will later be used by the sorting functions.
  7029. The function should take a string argument, an agenda line.
  7030. It has access to the text properties in that line, which contain among
  7031. other things, the property `org-hd-marker' that points to the entry
  7032. where the line comes from. Note that not all lines going into the agenda
  7033. have this property, only most.
  7034. The function should return the modified string. It is probably best
  7035. to ONLY change text properties.
  7036. You can also use this function as a filter, by returning nil for lines
  7037. you don't want to have in the agenda at all. For this application, you
  7038. could bind the variable in the options section of a custom command.")
  7039. (defun org-agenda-finalize-entries (list &optional type)
  7040. "Sort, limit and concatenate the LIST of agenda items.
  7041. The optional argument TYPE tells the agenda type."
  7042. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7043. (cdr (assoc type org-agenda-max-effort)))
  7044. (t org-agenda-max-effort)))
  7045. (max-todo (cond ((listp org-agenda-max-todos)
  7046. (cdr (assoc type org-agenda-max-todos)))
  7047. (t org-agenda-max-todos)))
  7048. (max-tags (cond ((listp org-agenda-max-tags)
  7049. (cdr (assoc type org-agenda-max-tags)))
  7050. (t org-agenda-max-tags)))
  7051. (max-entries (cond ((listp org-agenda-max-entries)
  7052. (cdr (assoc type org-agenda-max-entries)))
  7053. (t org-agenda-max-entries))))
  7054. (when org-agenda-before-sorting-filter-function
  7055. (setq list
  7056. (delq nil
  7057. (mapcar
  7058. org-agenda-before-sorting-filter-function list))))
  7059. (setq list (mapcar #'org-agenda-highlight-todo list)
  7060. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7061. (when max-effort
  7062. (setq list (org-agenda-limit-entries
  7063. list 'effort-minutes max-effort
  7064. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7065. 32767 -1))))))
  7066. (when max-todo
  7067. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7068. (when max-tags
  7069. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7070. (when max-entries
  7071. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7072. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7073. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7074. (mapconcat #'identity list "\n")))
  7075. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7076. "Limit the number of agenda entries."
  7077. (let ((include (and limit (< limit 0))))
  7078. (if limit
  7079. (let ((fun (or fn (lambda (p) (when p 1))))
  7080. (lim 0))
  7081. (delq nil
  7082. (mapcar
  7083. (lambda (e)
  7084. (let ((pval (funcall
  7085. fun (get-text-property (1- (length e))
  7086. prop e))))
  7087. (when pval (setq lim (+ lim pval)))
  7088. (cond ((and pval (<= lim (abs limit))) e)
  7089. ((and include (not pval)) e))))
  7090. list)))
  7091. list)))
  7092. (defun org-agenda-limit-interactively (remove)
  7093. "In agenda, interactively limit entries to various maximums."
  7094. (interactive "P")
  7095. (if remove
  7096. (progn (setq org-agenda-max-entries nil
  7097. org-agenda-max-todos nil
  7098. org-agenda-max-tags nil
  7099. org-agenda-max-effort nil)
  7100. (org-agenda-redo))
  7101. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7102. (msg (cond ((= max ?E) "How many minutes? ")
  7103. ((= max ?e) "How many entries? ")
  7104. ((= max ?t) "How many TODO entries? ")
  7105. ((= max ?T) "How many tagged entries? ")
  7106. (t (user-error "Wrong input"))))
  7107. (num (string-to-number (read-from-minibuffer msg))))
  7108. (cond ((equal max ?e)
  7109. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7110. ((equal max ?t)
  7111. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7112. ((equal max ?T)
  7113. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7114. ((equal max ?E)
  7115. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7116. (org-agenda-fit-window-to-buffer))
  7117. (defun org-agenda-highlight-todo (x)
  7118. (let ((org-done-keywords org-done-keywords-for-agenda)
  7119. (case-fold-search nil)
  7120. re)
  7121. (if (eq x 'line)
  7122. (save-excursion
  7123. (beginning-of-line 1)
  7124. (setq re (org-get-at-bol 'org-todo-regexp))
  7125. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7126. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7127. (add-text-properties (match-beginning 0) (match-end 1)
  7128. (list 'face (org-get-todo-face 1)))
  7129. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7130. (delete-region (match-beginning 1) (1- (match-end 0)))
  7131. (goto-char (match-beginning 1))
  7132. (insert (format org-agenda-todo-keyword-format s)))))
  7133. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7134. (setq re (get-text-property 0 'org-todo-regexp x))
  7135. (when (and re
  7136. ;; Test `pl' because if there's no heading content,
  7137. ;; there's no point matching to highlight. Note
  7138. ;; that if we didn't test `pl' first, and there
  7139. ;; happened to be no keyword from `org-todo-regexp'
  7140. ;; on this heading line, then the `equal' comparison
  7141. ;; afterwards would spuriously succeed in the case
  7142. ;; where `pl' is nil -- causing an args-out-of-range
  7143. ;; error when we try to add text properties to text
  7144. ;; that isn't there.
  7145. pl
  7146. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7147. x pl)
  7148. pl))
  7149. (add-text-properties
  7150. (or (match-end 1) (match-end 0)) (match-end 0)
  7151. (list 'face (org-get-todo-face (match-string 2 x)))
  7152. x)
  7153. (when (match-end 1)
  7154. (setq x
  7155. (concat
  7156. (substring x 0 (match-end 1))
  7157. (unless (string= org-agenda-todo-keyword-format "")
  7158. (format org-agenda-todo-keyword-format
  7159. (match-string 2 x)))
  7160. (unless (string= org-agenda-todo-keyword-format "")
  7161. ;; Remove `display' property as the icon could leak
  7162. ;; on the white space.
  7163. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7164. 'display)))
  7165. (substring x (match-end 3)))))))
  7166. x)))
  7167. (defsubst org-cmp-values (a b property)
  7168. "Compare the numeric value of text PROPERTY for string A and B."
  7169. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7170. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7171. (cond ((> pa pb) +1)
  7172. ((< pa pb) -1))))
  7173. (defsubst org-cmp-effort (a b)
  7174. "Compare the effort values of string A and B."
  7175. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7176. ;; `effort-minutes' property is not directly accessible from
  7177. ;; the strings, but is stored as a property in `txt'.
  7178. (ea (or (get-text-property
  7179. 0 'effort-minutes (get-text-property 0 'txt a))
  7180. def))
  7181. (eb (or (get-text-property
  7182. 0 'effort-minutes (get-text-property 0 'txt b))
  7183. def)))
  7184. (cond ((> ea eb) +1)
  7185. ((< ea eb) -1))))
  7186. (defsubst org-cmp-category (a b)
  7187. "Compare the string values of categories of strings A and B."
  7188. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7189. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7190. (cond ((string-lessp ca cb) -1)
  7191. ((string-lessp cb ca) +1))))
  7192. (defsubst org-cmp-todo-state (a b)
  7193. "Compare the todo states of strings A and B."
  7194. (let* ((ma (or (get-text-property 1 'org-marker a)
  7195. (get-text-property 1 'org-hd-marker a)))
  7196. (mb (or (get-text-property 1 'org-marker b)
  7197. (get-text-property 1 'org-hd-marker b)))
  7198. (fa (and ma (marker-buffer ma)))
  7199. (fb (and mb (marker-buffer mb)))
  7200. (todo-kwds
  7201. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7202. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7203. (ta (or (get-text-property 1 'todo-state a) ""))
  7204. (tb (or (get-text-property 1 'todo-state b) ""))
  7205. (la (- (length (member ta todo-kwds))))
  7206. (lb (- (length (member tb todo-kwds))))
  7207. (donepa (member ta org-done-keywords-for-agenda))
  7208. (donepb (member tb org-done-keywords-for-agenda)))
  7209. (cond ((and donepa (not donepb)) -1)
  7210. ((and (not donepa) donepb) +1)
  7211. ((< la lb) -1)
  7212. ((< lb la) +1))))
  7213. (defsubst org-cmp-alpha (a b)
  7214. "Compare the headlines, alphabetically."
  7215. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7216. (plb (text-property-any 0 (length b) 'org-heading t b))
  7217. (ta (and pla (substring a pla)))
  7218. (tb (and plb (substring b plb)))
  7219. (case-fold-search nil))
  7220. (when pla
  7221. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7222. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7223. ta)
  7224. (setq ta (substring ta (match-end 0))))
  7225. (setq ta (downcase ta)))
  7226. (when plb
  7227. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7228. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7229. tb)
  7230. (setq tb (substring tb (match-end 0))))
  7231. (setq tb (downcase tb)))
  7232. (cond ((not (or ta tb)) nil)
  7233. ((not ta) +1)
  7234. ((not tb) -1)
  7235. ((string-lessp ta tb) -1)
  7236. ((string-lessp tb ta) +1))))
  7237. (defsubst org-cmp-tag (a b)
  7238. "Compare the string values of the first tags of A and B."
  7239. (let ((ta (car (last (get-text-property 1 'tags a))))
  7240. (tb (car (last (get-text-property 1 'tags b)))))
  7241. (cond ((not (or ta tb)) nil)
  7242. ((not ta) +1)
  7243. ((not tb) -1)
  7244. ((string-lessp ta tb) -1)
  7245. ((string-lessp tb ta) +1))))
  7246. (defsubst org-cmp-time (a b)
  7247. "Compare the time-of-day values of strings A and B."
  7248. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7249. (ta (or (get-text-property 1 'time-of-day a) def))
  7250. (tb (or (get-text-property 1 'time-of-day b) def)))
  7251. (cond ((< ta tb) -1)
  7252. ((< tb ta) +1))))
  7253. (defsubst org-cmp-ts (a b type)
  7254. "Compare the timestamps values of entries A and B.
  7255. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7256. \"timestamp_ia\", compare within each of these type. When TYPE
  7257. is the empty string, compare all timestamps without respect of
  7258. their type."
  7259. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7260. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7261. (get-text-property 1 'ts-date a))
  7262. def))
  7263. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7264. (get-text-property 1 'ts-date b))
  7265. def)))
  7266. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7267. ((if tb (and ta (< tb ta)) ta) +1))))
  7268. (defsubst org-cmp-habit-p (a b)
  7269. "Compare the todo states of strings A and B."
  7270. (let ((ha (get-text-property 1 'org-habit-p a))
  7271. (hb (get-text-property 1 'org-habit-p b)))
  7272. (cond ((and ha (not hb)) -1)
  7273. ((and (not ha) hb) +1))))
  7274. (defun org-entries-lessp (a b)
  7275. "Predicate for sorting agenda entries."
  7276. ;; The following variables will be used when the form is evaluated.
  7277. ;; So even though the compiler complains, keep them.
  7278. (let ((ss org-agenda-sorting-strategy-selected))
  7279. (org-dlet
  7280. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7281. (org-cmp-ts a b "")))
  7282. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7283. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7284. (org-cmp-ts a b "scheduled")))
  7285. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7286. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7287. (org-cmp-ts a b "deadline")))
  7288. (deadline-down (if deadline-up (- deadline-up) nil))
  7289. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7290. (org-cmp-ts a b "timestamp_ia")))
  7291. (tsia-down (if tsia-up (- tsia-up) nil))
  7292. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7293. (org-cmp-ts a b "timestamp")))
  7294. (ts-down (if ts-up (- ts-up) nil))
  7295. (time-up (and (org-em 'time-up 'time-down ss)
  7296. (org-cmp-time a b)))
  7297. (time-down (if time-up (- time-up) nil))
  7298. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7299. (org-cmp-values a b 'org-stats)))
  7300. (stats-down (if stats-up (- stats-up) nil))
  7301. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7302. (org-cmp-values a b 'priority)))
  7303. (priority-down (if priority-up (- priority-up) nil))
  7304. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7305. (org-cmp-effort a b)))
  7306. (effort-down (if effort-up (- effort-up) nil))
  7307. (category-up (and (or (org-em 'category-up 'category-down ss)
  7308. (memq 'category-keep ss))
  7309. (org-cmp-category a b)))
  7310. (category-down (if category-up (- category-up) nil))
  7311. (category-keep (if category-up +1 nil))
  7312. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7313. (org-cmp-tag a b)))
  7314. (tag-down (if tag-up (- tag-up) nil))
  7315. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7316. (org-cmp-todo-state a b)))
  7317. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7318. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7319. (org-cmp-habit-p a b)))
  7320. (habit-down (if habit-up (- habit-up) nil))
  7321. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7322. (org-cmp-alpha a b)))
  7323. (alpha-down (if alpha-up (- alpha-up) nil))
  7324. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7325. user-defined-up user-defined-down)
  7326. (when (and need-user-cmp org-agenda-cmp-user-defined
  7327. (functionp org-agenda-cmp-user-defined))
  7328. (setq user-defined-up
  7329. (funcall org-agenda-cmp-user-defined a b)
  7330. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7331. (cdr (assoc
  7332. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7333. '((-1 . t) (1 . nil) (nil . nil)))))))
  7334. ;;; Agenda restriction lock
  7335. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7336. "Overlay to mark the headline to which agenda commands are restricted.")
  7337. (overlay-put org-agenda-restriction-lock-overlay
  7338. 'face 'org-agenda-restriction-lock)
  7339. (overlay-put org-agenda-restriction-lock-overlay
  7340. 'help-echo "Agendas are currently limited to this subtree.")
  7341. (delete-overlay org-agenda-restriction-lock-overlay)
  7342. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7343. "Set the restriction lock to the agenda item at point from within the agenda.
  7344. When called with a `\\[universal-argument]' prefix, restrict to
  7345. the file which contains the item.
  7346. Argument ARG is the prefix argument."
  7347. (interactive "P")
  7348. (unless (derived-mode-p 'org-agenda-mode)
  7349. (user-error "Not in an Org agenda buffer"))
  7350. (let* ((marker (or (org-get-at-bol 'org-marker)
  7351. (org-agenda-error)))
  7352. (buffer (marker-buffer marker))
  7353. (pos (marker-position marker)))
  7354. (with-current-buffer buffer
  7355. (goto-char pos)
  7356. (org-agenda-set-restriction-lock arg))))
  7357. ;;;###autoload
  7358. (defun org-agenda-set-restriction-lock (&optional type)
  7359. "Set restriction lock for agenda to current subtree or file.
  7360. When in a restricted subtree, remove it.
  7361. The restriction will span over the entire file if TYPE is `file',
  7362. or if type is \\='(4), or if the cursor is before the first headline
  7363. in the file. Otherwise, only apply the restriction to the current
  7364. subtree."
  7365. (interactive "P")
  7366. (if (and org-agenda-overriding-restriction
  7367. (member org-agenda-restriction-lock-overlay
  7368. (overlays-at (point)))
  7369. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7370. (point)))
  7371. (org-agenda-remove-restriction-lock 'noupdate)
  7372. (org-agenda-remove-restriction-lock 'noupdate)
  7373. (and (equal type '(4)) (setq type 'file))
  7374. (setq type (cond
  7375. (type type)
  7376. ((org-at-heading-p) 'subtree)
  7377. ((condition-case nil (org-back-to-heading t) (error nil))
  7378. 'subtree)
  7379. (t 'file)))
  7380. (if (eq type 'subtree)
  7381. (progn
  7382. (setq org-agenda-restrict (current-buffer))
  7383. (setq org-agenda-overriding-restriction 'subtree)
  7384. (put 'org-agenda-files 'org-restrict
  7385. (list (buffer-file-name (buffer-base-buffer))))
  7386. (org-back-to-heading t)
  7387. (move-overlay org-agenda-restriction-lock-overlay
  7388. (point)
  7389. (if org-agenda-restriction-lock-highlight-subtree
  7390. (save-excursion (org-end-of-subtree t t) (point))
  7391. (point-at-eol)))
  7392. (move-marker org-agenda-restrict-begin (point))
  7393. (move-marker org-agenda-restrict-end
  7394. (save-excursion (org-end-of-subtree t t)))
  7395. (message "Locking agenda restriction to subtree"))
  7396. (put 'org-agenda-files 'org-restrict
  7397. (list (buffer-file-name (buffer-base-buffer))))
  7398. (setq org-agenda-restrict nil)
  7399. (setq org-agenda-overriding-restriction 'file)
  7400. (move-marker org-agenda-restrict-begin nil)
  7401. (move-marker org-agenda-restrict-end nil)
  7402. (message "Locking agenda restriction to file"))
  7403. (setq current-prefix-arg nil))
  7404. (org-agenda-maybe-redo))
  7405. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7406. "Remove agenda restriction lock."
  7407. (interactive "P")
  7408. (if (not org-agenda-restrict)
  7409. (message "No agenda restriction to remove.")
  7410. (delete-overlay org-agenda-restriction-lock-overlay)
  7411. (delete-overlay org-speedbar-restriction-lock-overlay)
  7412. (setq org-agenda-overriding-restriction nil)
  7413. (setq org-agenda-restrict nil)
  7414. (put 'org-agenda-files 'org-restrict nil)
  7415. (move-marker org-agenda-restrict-begin nil)
  7416. (move-marker org-agenda-restrict-end nil)
  7417. (setq current-prefix-arg nil)
  7418. (message "Agenda restriction lock removed")
  7419. (or noupdate (org-agenda-maybe-redo))))
  7420. (defun org-agenda-maybe-redo ()
  7421. "If there is any window showing the agenda view, update it."
  7422. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7423. org-agenda-buffer-name)
  7424. t))
  7425. (w0 (selected-window)))
  7426. (when w
  7427. (select-window w)
  7428. (org-agenda-redo)
  7429. (select-window w0)
  7430. (if org-agenda-overriding-restriction
  7431. (message "Agenda view shifted to new %s restriction"
  7432. org-agenda-overriding-restriction)
  7433. (message "Agenda restriction lock removed")))))
  7434. ;;; Agenda commands
  7435. (defun org-agenda-check-type (error &rest types)
  7436. "Check if agenda buffer or component is of allowed type.
  7437. If ERROR is non-nil, throw an error, otherwise just return nil.
  7438. Allowed types are `agenda' `todo' `tags' `search'."
  7439. (cond ((not org-agenda-type)
  7440. (error "No Org agenda currently displayed"))
  7441. ((memq org-agenda-type types) t)
  7442. (error
  7443. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7444. (t nil)))
  7445. (defun org-agenda-Quit ()
  7446. "Exit the agenda, killing the agenda buffer.
  7447. Like `org-agenda-quit', but kill the buffer even when
  7448. `org-agenda-sticky' is non-nil."
  7449. (interactive)
  7450. (org-agenda--quit))
  7451. (defun org-agenda-quit ()
  7452. "Exit the agenda.
  7453. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7454. instead of killing it.
  7455. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7456. the pre-agenda window configuration.
  7457. When column view is active, exit column view instead of the
  7458. agenda."
  7459. (interactive)
  7460. (org-agenda--quit org-agenda-sticky))
  7461. (defun org-agenda--quit (&optional bury)
  7462. (if org-agenda-columns-active
  7463. (org-columns-quit)
  7464. (let ((wconf org-agenda-pre-window-conf)
  7465. (buf (current-buffer))
  7466. (org-agenda-last-indirect-window
  7467. (and (eq org-indirect-buffer-display 'other-window)
  7468. org-agenda-last-indirect-buffer
  7469. (get-buffer-window org-agenda-last-indirect-buffer))))
  7470. (cond
  7471. ((eq org-agenda-window-setup 'other-frame)
  7472. (delete-frame))
  7473. ((eq org-agenda-window-setup 'other-tab)
  7474. (if (fboundp 'tab-bar-close-tab)
  7475. (tab-bar-close-tab)
  7476. (user-error "Your version of Emacs does not have tab bar mode support")))
  7477. ((and org-agenda-restore-windows-after-quit
  7478. wconf)
  7479. ;; Maybe restore the pre-agenda window configuration. Reset
  7480. ;; `org-agenda-pre-window-conf' before running
  7481. ;; `set-window-configuration', which loses the current buffer.
  7482. (setq org-agenda-pre-window-conf nil)
  7483. (set-window-configuration wconf))
  7484. (t
  7485. (when org-agenda-last-indirect-window
  7486. (delete-window org-agenda-last-indirect-window))
  7487. (and (not (eq org-agenda-window-setup 'current-window))
  7488. (not (one-window-p))
  7489. (delete-window))))
  7490. (if bury
  7491. ;; Set the agenda buffer as the current buffer instead of
  7492. ;; passing it as an argument to `bury-buffer' so that
  7493. ;; `bury-buffer' removes it from the window.
  7494. (with-current-buffer buf
  7495. (bury-buffer))
  7496. (kill-buffer buf)
  7497. (setq org-agenda-archives-mode nil
  7498. org-agenda-buffer nil)))))
  7499. (defun org-agenda-exit ()
  7500. "Exit the agenda, killing Org buffers loaded by the agenda.
  7501. Like `org-agenda-Quit', but kill any buffers that were created by
  7502. the agenda. Org buffers visited directly by the user will not be
  7503. touched. Also, exit the agenda even if it is in column view."
  7504. (interactive)
  7505. (when org-agenda-columns-active
  7506. (org-columns-quit))
  7507. (org-release-buffers org-agenda-new-buffers)
  7508. (setq org-agenda-new-buffers nil)
  7509. (org-agenda-Quit))
  7510. (defun org-agenda-kill-all-agenda-buffers ()
  7511. "Kill all buffers in `org-agenda-mode'.
  7512. This is used when toggling sticky agendas."
  7513. (interactive)
  7514. (let (blist)
  7515. (dolist (buf (buffer-list))
  7516. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7517. (push buf blist)))
  7518. (mapc #'kill-buffer blist)))
  7519. (defun org-agenda-execute (arg)
  7520. "Execute another agenda command, keeping same window.
  7521. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7522. in the agenda."
  7523. (interactive "P")
  7524. (let ((org-agenda-window-setup 'current-window))
  7525. (org-agenda arg)))
  7526. (defun org-agenda-redo (&optional all)
  7527. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7528. (interactive "P")
  7529. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7530. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7531. (cpa (unless (eq all t) current-prefix-arg))
  7532. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7533. (org-agenda-sticky nil)
  7534. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7535. org-agenda-buffer-name))
  7536. (org-agenda-keep-modes t)
  7537. (tag-filter org-agenda-tag-filter)
  7538. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7539. (top-hl-filter org-agenda-top-headline-filter)
  7540. (cat-filter org-agenda-category-filter)
  7541. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7542. (re-filter org-agenda-regexp-filter)
  7543. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7544. (effort-filter org-agenda-effort-filter)
  7545. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7546. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7547. (cols org-agenda-columns-active)
  7548. (line (org-current-line))
  7549. (window-line (- line (org-current-line (window-start))))
  7550. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7551. (redo-cmd (get-text-property p 'org-redo-cmd))
  7552. (last-args (get-text-property p 'org-last-args))
  7553. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7554. (org-agenda-overriding-cmd-arguments
  7555. (unless (eq all t)
  7556. (cond ((listp last-args)
  7557. (cons (or cpa (car last-args)) (cdr last-args)))
  7558. ((stringp last-args)
  7559. last-args))))
  7560. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7561. (put 'org-agenda-tag-filter :preset-filter nil)
  7562. (put 'org-agenda-category-filter :preset-filter nil)
  7563. (put 'org-agenda-regexp-filter :preset-filter nil)
  7564. (put 'org-agenda-effort-filter :preset-filter nil)
  7565. (and cols (org-columns-quit))
  7566. (message "Rebuilding agenda buffer...")
  7567. (if series-redo-cmd
  7568. (eval series-redo-cmd t)
  7569. (cl-progv
  7570. (mapcar #'car lprops)
  7571. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7572. (eval redo-cmd t)))
  7573. (setq org-agenda-undo-list nil
  7574. org-agenda-pending-undo-list nil
  7575. org-agenda-tag-filter tag-filter
  7576. org-agenda-category-filter cat-filter
  7577. org-agenda-regexp-filter re-filter
  7578. org-agenda-effort-filter effort-filter
  7579. org-agenda-top-headline-filter top-hl-filter)
  7580. (message "Rebuilding agenda buffer...done")
  7581. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7582. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7583. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7584. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7585. (let ((tag (or tag-filter tag-preset))
  7586. (cat (or cat-filter cat-preset))
  7587. (effort (or effort-filter effort-preset))
  7588. (re (or re-filter re-preset)))
  7589. (when tag (org-agenda-filter-apply tag 'tag t))
  7590. (when cat (org-agenda-filter-apply cat 'category))
  7591. (when effort (org-agenda-filter-apply effort 'effort))
  7592. (when re (org-agenda-filter-apply re 'regexp)))
  7593. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7594. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7595. (org-goto-line line)
  7596. (when (called-interactively-p 'any) (recenter window-line))))
  7597. (defun org-agenda-redo-all (&optional exhaustive)
  7598. "Rebuild all agenda views in the current buffer.
  7599. With a prefix argument, do so in all agenda buffers."
  7600. (interactive "P")
  7601. (if exhaustive
  7602. (dolist (buffer (buffer-list))
  7603. (with-current-buffer buffer
  7604. (when (derived-mode-p 'org-agenda-mode)
  7605. (org-agenda-redo t))))
  7606. (org-agenda-redo t)))
  7607. (defvar org-global-tags-completion-table nil)
  7608. (defvar org-agenda-filter-form nil)
  7609. (defvar org-agenda-filtered-by-category nil)
  7610. (defsubst org-agenda-get-category ()
  7611. "Return the category of the agenda line."
  7612. (org-get-at-bol 'org-category))
  7613. (defun org-agenda-filter-by-category (strip)
  7614. "Filter lines in the agenda buffer that have a specific category.
  7615. The category is that of the current line.
  7616. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7617. When there is already a category filter in place, this command removes the
  7618. filter."
  7619. (interactive "P")
  7620. (if (and org-agenda-filtered-by-category
  7621. org-agenda-category-filter)
  7622. (org-agenda-filter-show-all-cat)
  7623. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7624. (cond
  7625. ((and cat strip)
  7626. (org-agenda-filter-apply
  7627. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7628. (cat
  7629. (org-agenda-filter-apply
  7630. (setq org-agenda-category-filter
  7631. (list (concat "+" cat)))
  7632. 'category))
  7633. (t (error "No category at point"))))))
  7634. (defun org-find-top-headline (&optional pos)
  7635. "Find the topmost parent headline and return it.
  7636. POS when non-nil is the marker or buffer position to start the
  7637. search from."
  7638. (save-excursion
  7639. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7640. (when pos (goto-char pos))
  7641. ;; Skip up to the topmost parent.
  7642. (while (org-up-heading-safe))
  7643. (ignore-errors
  7644. (replace-regexp-in-string
  7645. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7646. (nth 4 (org-heading-components)))))))
  7647. (defvar org-agenda-filtered-by-top-headline nil)
  7648. (defun org-agenda-filter-by-top-headline (strip)
  7649. "Keep only those lines that are descendants from the same top headline.
  7650. The top headline is that of the current line. With prefix arg STRIP, hide
  7651. all lines of the category at point."
  7652. (interactive "P")
  7653. (if org-agenda-filtered-by-top-headline
  7654. (progn
  7655. (setq org-agenda-filtered-by-top-headline nil
  7656. org-agenda-top-headline-filter nil)
  7657. (org-agenda-filter-show-all-top-filter))
  7658. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7659. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7660. (error "No top-level headline at point")))))
  7661. (defvar org-agenda-regexp-filter nil)
  7662. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7663. "Filter agenda entries by a regular expressions.
  7664. You will be prompted for the regular expression, and the agenda
  7665. view will only show entries that are matched by that expression.
  7666. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7667. When there is already a regexp filter active, this command removed the
  7668. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7669. an already existing regexp filter."
  7670. (interactive "P")
  7671. (let* ((strip (equal strip-or-accumulate '(4)))
  7672. (accumulate (equal strip-or-accumulate '(16))))
  7673. (cond
  7674. ((and org-agenda-regexp-filter (not accumulate))
  7675. (org-agenda-filter-show-all-re)
  7676. (message "Regexp filter removed"))
  7677. (t (let ((flt (concat (if strip "-" "+")
  7678. (read-from-minibuffer
  7679. (if strip
  7680. "Hide entries matching regexp: "
  7681. "Narrow to entries matching regexp: ")))))
  7682. (push flt org-agenda-regexp-filter)
  7683. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7684. (defvar org-agenda-effort-filter nil)
  7685. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7686. "Filter agenda entries by effort.
  7687. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7688. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7689. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7690. This last option is in practice not very useful, but it is available for
  7691. consistency with the other filter commands."
  7692. (interactive "P")
  7693. (let* ((efforts (split-string
  7694. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7695. org-global-properties
  7696. t))
  7697. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7698. ;; XXX: the following handles only up to 10 different
  7699. ;; effort values.
  7700. (allowed-keys (if (null efforts) nil
  7701. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7702. (number-sequence 1 (length efforts)))))
  7703. (keep (equal strip-or-accumulate '(16)))
  7704. (negative (equal strip-or-accumulate '(4)))
  7705. (current org-agenda-effort-filter)
  7706. (op nil))
  7707. (while (not (memq op '(?< ?> ?= ?_)))
  7708. (setq op (read-char-exclusive
  7709. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7710. ;; Select appropriate duration. Ignore non-digit characters.
  7711. (if (eq op ?_)
  7712. (progn
  7713. (org-agenda-filter-show-all-effort)
  7714. (message "Effort filter removed"))
  7715. (let ((prompt
  7716. (apply #'format
  7717. (concat "Effort %c "
  7718. (mapconcat (lambda (s) (concat "[%d]" s))
  7719. efforts
  7720. " "))
  7721. op allowed-keys))
  7722. (eff -1))
  7723. (while (not (memq eff allowed-keys))
  7724. (message prompt)
  7725. (setq eff (- (read-char-exclusive) 48)))
  7726. (org-agenda-filter-show-all-effort)
  7727. (setq org-agenda-effort-filter
  7728. (append
  7729. (list (concat (if negative "-" "+")
  7730. (char-to-string op)
  7731. ;; Numbering is 1 2 3 ... 9 0, but we want
  7732. ;; 0 1 2 ... 8 9.
  7733. (nth (mod (1- eff) 10) efforts)))
  7734. (if keep current nil)))
  7735. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7736. (defun org-agenda-filter (&optional strip-or-accumulate)
  7737. "Prompt for a general filter string and apply it to the agenda.
  7738. The string may contain filter elements like
  7739. +category
  7740. +tag
  7741. +<effort > and = are also allowed as effort operators
  7742. +/regexp/
  7743. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7744. `+' is optional if it is not required to separate two string parts.
  7745. Multiple filter elements can be concatenated without spaces, for example
  7746. +work-John<0:10-/plot/
  7747. selects entries with category `work' and effort estimates below 10 minutes,
  7748. and deselects entries with tag `John' or matching the regexp `plot'.
  7749. During entry of the filter, completion for tags, categories and effort
  7750. values is offered. Since the syntax for categories and tags is identical
  7751. there should be no overlap between categories and tags. If there is, tags
  7752. get priority.
  7753. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7754. entire filter, which can be useful in connection with the prompt history.
  7755. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7756. existing ones. A shortcut for this is to add an additional `+' at the
  7757. beginning of the string, like `+-John'.
  7758. With a triple prefix argument, execute the computed filtering defined in
  7759. the variable `org-agenda-auto-exclude-function'."
  7760. (interactive "P")
  7761. (if (equal strip-or-accumulate '(64))
  7762. ;; Execute the auto-exclude action
  7763. (if (not org-agenda-auto-exclude-function)
  7764. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7765. (org-agenda-filter-show-all-tag)
  7766. (setq org-agenda-tag-filter nil)
  7767. (dolist (tag (org-agenda-get-represented-tags))
  7768. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7769. (when modifier
  7770. (push modifier org-agenda-tag-filter))))
  7771. (unless (null org-agenda-tag-filter)
  7772. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7773. ;; Prompt for a filter and act
  7774. (let* ((tag-list (org-agenda-get-represented-tags))
  7775. (category-list (org-agenda-get-represented-categories))
  7776. (negate (equal strip-or-accumulate '(4)))
  7777. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7778. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7779. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7780. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7781. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7782. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7783. (f-string (completing-read
  7784. (concat
  7785. (if negate "Negative filter" "Filter")
  7786. " [+cat-tag<0:10-/regexp/]: ")
  7787. #'org-agenda-filter-completion-function
  7788. nil nil ff))
  7789. (keep (or (if (string-match "^\\+[+-]" f-string)
  7790. (progn (setq f-string (substring f-string 1)) t))
  7791. (equal strip-or-accumulate '(16))))
  7792. (fc (if keep org-agenda-category-filter))
  7793. (ft (if keep org-agenda-tag-filter))
  7794. (fe (if keep org-agenda-effort-filter))
  7795. (fr (if keep org-agenda-regexp-filter))
  7796. pm s)
  7797. ;; If the filter contains a double-quoted string, replace a
  7798. ;; single hyphen by the arbitrary and temporary string "~~~"
  7799. ;; to disambiguate such hyphens from syntactic ones.
  7800. (setq f-string (replace-regexp-in-string
  7801. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7802. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7803. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7804. (when negate
  7805. (setq pm (if (equal pm "+") "-" "+")))
  7806. (cond
  7807. ((match-beginning 3)
  7808. ;; category or tag
  7809. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7810. "~~~" "-" (match-string 3 f-string)))
  7811. (cond
  7812. ((member s tag-list)
  7813. (org-pushnew-to-end (concat pm s) ft))
  7814. ((member s category-list)
  7815. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7816. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7817. fc))
  7818. (t (message
  7819. "`%s%s' filter ignored because tag/category is not represented"
  7820. pm s))))
  7821. ((match-beginning 4)
  7822. ;; effort
  7823. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7824. ((match-beginning 5)
  7825. ;; regexp
  7826. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7827. (setq f-string (substring f-string (match-end 0))))
  7828. (org-agenda-filter-remove-all)
  7829. (and fc (org-agenda-filter-apply
  7830. (setq org-agenda-category-filter fc) 'category))
  7831. (and ft (org-agenda-filter-apply
  7832. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7833. (and fe (org-agenda-filter-apply
  7834. (setq org-agenda-effort-filter fe) 'effort))
  7835. (and fr (org-agenda-filter-apply
  7836. (setq org-agenda-regexp-filter fr) 'regexp))
  7837. (run-hooks 'org-agenda-filter-hook))))
  7838. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7839. "Complete a complex filter string.
  7840. FLAG specifies the type of completion operation to perform. This
  7841. function is passed as a collection function to `completing-read',
  7842. which see."
  7843. (let ((completion-ignore-case t) ;tags are case-sensitive
  7844. (confirm (lambda (x) (stringp x)))
  7845. (prefix "")
  7846. (operator "")
  7847. table)
  7848. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7849. (setq prefix (match-string 1 string)
  7850. operator (match-string 2 string)
  7851. string (match-string 3 string)))
  7852. (cond
  7853. ((member operator '("+" "-" "" nil))
  7854. (setq table (append (org-agenda-get-represented-categories)
  7855. (org-agenda-get-represented-tags))))
  7856. ((member operator '("<" ">" "="))
  7857. (setq table (split-string
  7858. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7859. org-global-properties
  7860. t))
  7861. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7862. " +")))
  7863. (t (setq table nil)))
  7864. (pcase flag
  7865. (`t (all-completions string table confirm))
  7866. (`lambda (assoc string table)) ;exact match?
  7867. (`nil
  7868. (pcase (try-completion string table confirm)
  7869. ((and completion (pred stringp))
  7870. (concat prefix completion))
  7871. (completion completion)))
  7872. (_ nil))))
  7873. (defun org-agenda-filter-remove-all ()
  7874. "Remove all filters from the current agenda buffer."
  7875. (interactive)
  7876. (when org-agenda-tag-filter
  7877. (org-agenda-filter-show-all-tag))
  7878. (when org-agenda-category-filter
  7879. (org-agenda-filter-show-all-cat))
  7880. (when org-agenda-regexp-filter
  7881. (org-agenda-filter-show-all-re))
  7882. (when org-agenda-top-headline-filter
  7883. (org-agenda-filter-show-all-top-filter))
  7884. (when org-agenda-effort-filter
  7885. (org-agenda-filter-show-all-effort))
  7886. (org-agenda-finalize)
  7887. (when (called-interactively-p 'interactive)
  7888. (message "All agenda filters removed")))
  7889. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7890. "Keep only those lines in the agenda buffer that have a specific tag.
  7891. The tag is selected with its fast selection letter, as configured.
  7892. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7893. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7894. instead of replacing it.
  7895. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7896. i.e. don't
  7897. filter on all its group members.
  7898. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7899. should be used to exclude the search - the interactive user can
  7900. also press `-' or `+' to switch between filtering and excluding."
  7901. (interactive "P")
  7902. (let* ((alist org-tag-alist-for-agenda)
  7903. (seen-chars nil)
  7904. (tag-chars (mapconcat
  7905. (lambda (x) (if (and (not (symbolp (car x)))
  7906. (cdr x)
  7907. (not (member (cdr x) seen-chars)))
  7908. (progn
  7909. (push (cdr x) seen-chars)
  7910. (char-to-string (cdr x)))
  7911. ""))
  7912. org-tag-alist-for-agenda ""))
  7913. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7914. (string-to-list tag-chars)))
  7915. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7916. (accumulate (equal strip-or-accumulate '(16)))
  7917. (expand (not (equal strip-or-accumulate '(64))))
  7918. (inhibit-read-only t)
  7919. (current org-agenda-tag-filter)
  7920. a tag) ;; n
  7921. (unless char
  7922. (while (not (memq char valid-char-list))
  7923. (org-unlogged-message
  7924. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7925. (if exclude "Exclude[+]" "Filter[-]")
  7926. (if expand "" " (no grouptag expand)")
  7927. tag-chars
  7928. (if org-agenda-auto-exclude-function "[RET] " ""))
  7929. (setq char (read-char-exclusive))
  7930. ;; Excluding or filtering down
  7931. (cond ((eq char ?-) (setq exclude t))
  7932. ((eq char ?+) (setq exclude nil)))))
  7933. (when (eq char ?\t)
  7934. (unless (local-variable-p 'org-global-tags-completion-table)
  7935. (setq-local org-global-tags-completion-table
  7936. (org-global-tags-completion-table)))
  7937. (let ((completion-ignore-case t))
  7938. (setq tag (completing-read
  7939. "Tag: " org-global-tags-completion-table nil t))))
  7940. (cond
  7941. ((eq char ?\r)
  7942. (org-agenda-filter-show-all-tag)
  7943. (when org-agenda-auto-exclude-function
  7944. (setq org-agenda-tag-filter nil)
  7945. (dolist (tag (org-agenda-get-represented-tags))
  7946. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7947. (when modifier
  7948. (push modifier org-agenda-tag-filter))))
  7949. (unless (null org-agenda-tag-filter)
  7950. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7951. ((eq char ?\\)
  7952. (org-agenda-filter-show-all-tag)
  7953. (when (get 'org-agenda-tag-filter :preset-filter)
  7954. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7955. ((eq char ?.)
  7956. (setq org-agenda-tag-filter
  7957. (mapcar (lambda(tag) (concat "+" tag))
  7958. (org-get-at-bol 'tags)))
  7959. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7960. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7961. ((or (eq char ?\s)
  7962. (setq a (rassoc char alist))
  7963. (and tag (setq a (cons tag nil))))
  7964. (org-agenda-filter-show-all-tag)
  7965. (setq tag (car a))
  7966. (setq org-agenda-tag-filter
  7967. (cons (concat (if exclude "-" "+") tag)
  7968. (if accumulate current nil)))
  7969. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7970. (t (error "Invalid tag selection character %c" char)))))
  7971. (defun org-agenda-get-represented-categories ()
  7972. "Return a list of all categories used in this agenda buffer."
  7973. (or org-agenda-represented-categories
  7974. (when (derived-mode-p 'org-agenda-mode)
  7975. (let ((pos (point-min)) categories)
  7976. (while (and (< pos (point-max))
  7977. (setq pos (next-single-property-change
  7978. pos 'org-category nil (point-max))))
  7979. (push (get-text-property pos 'org-category) categories))
  7980. (setq org-agenda-represented-categories
  7981. ;; Enclose category names with a hyphen in double
  7982. ;; quotes to process them specially in `org-agenda-filter'.
  7983. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7984. (nreverse (org-uniquify (delq nil categories)))))))))
  7985. (defvar org-tag-groups-alist-for-agenda)
  7986. (defun org-agenda-get-represented-tags ()
  7987. "Return a list of all tags used in this agenda buffer.
  7988. These will be lower-case, for filtering."
  7989. (or org-agenda-represented-tags
  7990. (when (derived-mode-p 'org-agenda-mode)
  7991. (let ((pos (point-min)) tags-lists tt)
  7992. (while (and (< pos (point-max))
  7993. (setq pos (next-single-property-change
  7994. pos 'tags nil (point-max))))
  7995. (setq tt (get-text-property pos 'tags))
  7996. (if tt (push tt tags-lists)))
  7997. (setq tags-lists
  7998. (nreverse (org-uniquify
  7999. (delq nil (apply #'append tags-lists)))))
  8000. (dolist (tag tags-lists)
  8001. (mapc
  8002. (lambda (group)
  8003. (when (member tag group)
  8004. (push (car group) tags-lists)))
  8005. org-tag-groups-alist-for-agenda))
  8006. (setq org-agenda-represented-tags tags-lists)))))
  8007. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8008. "Create the form that tests a line for agenda filter.
  8009. Optional argument EXPAND can be used for the TYPE tag and will
  8010. expand the tags in the FILTER if any of the tags in FILTER are
  8011. grouptags."
  8012. (let ((multi-pos-cats
  8013. (and (eq type 'category)
  8014. (string-match-p "\\+.*\\+"
  8015. (mapconcat (lambda (cat) (substring cat 0 1))
  8016. filter ""))))
  8017. f f1)
  8018. (cond
  8019. ;; Tag filter
  8020. ((eq type 'tag)
  8021. (setq filter
  8022. (delete-dups
  8023. (append (get 'org-agenda-tag-filter :preset-filter)
  8024. filter)))
  8025. (dolist (x filter)
  8026. (let ((op (string-to-char x)))
  8027. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8028. (setq x (list x)))
  8029. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8030. (push f1 f))))
  8031. ;; Category filter
  8032. ((eq type 'category)
  8033. (setq filter
  8034. (delete-dups
  8035. (append (get 'org-agenda-category-filter :preset-filter)
  8036. filter)))
  8037. (dolist (x filter)
  8038. (if (equal "-" (substring x 0 1))
  8039. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8040. (setq f1 (list 'equal (substring x 1) 'cat)))
  8041. (push f1 f)))
  8042. ;; Regexp filter
  8043. ((eq type 'regexp)
  8044. (setq filter
  8045. (delete-dups
  8046. (append (get 'org-agenda-regexp-filter :preset-filter)
  8047. filter)))
  8048. (dolist (x filter)
  8049. (if (equal "-" (substring x 0 1))
  8050. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8051. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8052. (push f1 f)))
  8053. ;; Effort filter
  8054. ((eq type 'effort)
  8055. (setq filter
  8056. (delete-dups
  8057. (append (get 'org-agenda-effort-filter :preset-filter)
  8058. filter)))
  8059. (dolist (x filter)
  8060. (push (org-agenda-filter-effort-form x) f))))
  8061. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8062. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8063. "Return a form associated to tag-expression TAGS.
  8064. Build a form testing a line for agenda filter for
  8065. tag-expressions. OP is an operator of type CHAR that allows the
  8066. function to set the right switches in the returned form."
  8067. (let (form)
  8068. ;; Any of the expressions can match if OP is +, all must match if
  8069. ;; the operator is -.
  8070. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8071. (let* ((tag (substring x 1))
  8072. (f (cond
  8073. ((string= "" tag) 'tags)
  8074. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8075. ;; TAG is a regexp.
  8076. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8077. (t (list 'member tag 'tags)))))
  8078. (push (if (eq op ?-) (list 'not f) f) form)))))
  8079. (defun org-agenda-filter-effort-form (e)
  8080. "Return the form to compare the effort of the current line with what E says.
  8081. E looks like \"+<2:25\"."
  8082. (let (op)
  8083. (setq e (substring e 1))
  8084. (setq op (string-to-char e) e (substring e 1))
  8085. (setq op (cond ((equal op ?<) '<=)
  8086. ((equal op ?>) '>=)
  8087. ((equal op ??) op)
  8088. (t '=)))
  8089. (list 'org-agenda-compare-effort (list 'quote op)
  8090. (org-duration-to-minutes e))))
  8091. (defun org-agenda-compare-effort (op value)
  8092. "Compare the effort of the current line with VALUE, using OP.
  8093. If the line does not have an effort defined, return nil."
  8094. ;; `effort-minutes' property cannot be extracted directly from
  8095. ;; current line but is stored as a property in `txt'.
  8096. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8097. (funcall op
  8098. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8099. value)))
  8100. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8101. "Expand group tags in FILTER for the agenda.
  8102. When NO-OPERATOR is non-nil, do not add the + operator to
  8103. returned tags."
  8104. (if org-group-tags
  8105. (let (case-fold-search rtn)
  8106. (mapc
  8107. (lambda (f)
  8108. (let (f0 dir)
  8109. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8110. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8111. (setq dir (if no-operator "" "+") f0 f))
  8112. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8113. (org-tags-expand f0 t))
  8114. rtn))))
  8115. filter)
  8116. (reverse rtn))
  8117. filter))
  8118. (defun org-agenda-filter-apply (filter type &optional expand)
  8119. "Set FILTER as the new agenda filter and apply it.
  8120. Optional argument EXPAND can be used for the TYPE tag and will
  8121. expand the tags in the FILTER if any of the tags in FILTER are
  8122. grouptags."
  8123. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8124. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8125. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8126. filter type expand))
  8127. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8128. ;; category is used as the filter:
  8129. (setq org-agenda-filtered-by-category
  8130. (and (eq type 'category)
  8131. (not (equal (substring (car filter) 0 1) "-"))))
  8132. (org-agenda-set-mode-name)
  8133. (save-excursion
  8134. (goto-char (point-min))
  8135. (while (not (eobp))
  8136. (when (or (org-get-at-bol 'org-hd-marker)
  8137. (org-get-at-bol 'org-marker))
  8138. (org-dlet
  8139. ((tags (org-get-at-bol 'tags))
  8140. (cat (org-agenda-get-category))
  8141. (txt (or (org-get-at-bol 'txt) "")))
  8142. (unless (eval org-agenda-filter-form t)
  8143. (org-agenda-filter-hide-line type))))
  8144. (beginning-of-line 2)))
  8145. (when (get-char-property (point) 'invisible)
  8146. (ignore-errors (org-agenda-previous-line))))
  8147. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8148. "Filter by top headline HL."
  8149. (org-agenda-set-mode-name)
  8150. (save-excursion
  8151. (goto-char (point-min))
  8152. (while (not (eobp))
  8153. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8154. (tophl (and pos (org-find-top-headline pos))))
  8155. (when (and tophl (funcall (if negative 'identity 'not)
  8156. (string= hl tophl)))
  8157. (org-agenda-filter-hide-line 'top-headline)))
  8158. (beginning-of-line 2)))
  8159. (when (get-char-property (point) 'invisible)
  8160. (org-agenda-previous-line))
  8161. (setq org-agenda-top-headline-filter hl
  8162. org-agenda-filtered-by-top-headline t))
  8163. (defun org-agenda-filter-hide-line (type)
  8164. "If current line is TYPE, hide it in the agenda buffer."
  8165. (let* (buffer-invisibility-spec
  8166. (beg (max (point-min) (1- (point-at-bol))))
  8167. (end (point-at-eol)))
  8168. (let ((inhibit-read-only t))
  8169. (add-text-properties
  8170. beg end `(invisible org-filtered org-filter-type ,type)))))
  8171. (defun org-agenda-remove-filter (type)
  8172. "Remove filter of type TYPE from the agenda buffer."
  8173. (interactive)
  8174. (save-excursion
  8175. (goto-char (point-min))
  8176. (let ((inhibit-read-only t) pos)
  8177. (while (setq pos (text-property-any (point) (point-max)
  8178. 'org-filter-type type))
  8179. (goto-char pos)
  8180. (remove-text-properties
  8181. (point) (next-single-property-change (point) 'org-filter-type)
  8182. `(invisible org-filtered org-filter-type ,type))))
  8183. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8184. (setq org-agenda-filter-form nil)
  8185. (org-agenda-set-mode-name)
  8186. (org-agenda-finalize)))
  8187. (defun org-agenda-filter-show-all-tag nil
  8188. (org-agenda-remove-filter 'tag))
  8189. (defun org-agenda-filter-show-all-re nil
  8190. (org-agenda-remove-filter 'regexp))
  8191. (defun org-agenda-filter-show-all-effort nil
  8192. (org-agenda-remove-filter 'effort))
  8193. (defun org-agenda-filter-show-all-cat nil
  8194. (org-agenda-remove-filter 'category))
  8195. (defun org-agenda-filter-show-all-top-filter nil
  8196. (org-agenda-remove-filter 'top-headline))
  8197. (defun org-agenda-manipulate-query-add ()
  8198. "Manipulate the query by adding a search term with positive selection.
  8199. Positive selection means the term must be matched for selection of an entry."
  8200. (interactive)
  8201. (org-agenda-manipulate-query ?\[))
  8202. (defun org-agenda-manipulate-query-subtract ()
  8203. "Manipulate the query by adding a search term with negative selection.
  8204. Negative selection means term must not be matched for selection of an entry."
  8205. (interactive)
  8206. (org-agenda-manipulate-query ?\]))
  8207. (defun org-agenda-manipulate-query-add-re ()
  8208. "Manipulate the query by adding a search regexp with positive selection.
  8209. Positive selection means the regexp must match for selection of an entry."
  8210. (interactive)
  8211. (org-agenda-manipulate-query ?\{))
  8212. (defun org-agenda-manipulate-query-subtract-re ()
  8213. "Manipulate the query by adding a search regexp with negative selection.
  8214. Negative selection means regexp must not match for selection of an entry."
  8215. (interactive)
  8216. (org-agenda-manipulate-query ?\}))
  8217. (defun org-agenda-manipulate-query (char)
  8218. (cond
  8219. ((eq org-agenda-type 'agenda)
  8220. (let ((org-agenda-include-inactive-timestamps t))
  8221. (org-agenda-redo))
  8222. (message "Display now includes inactive timestamps as well"))
  8223. ((eq org-agenda-type 'search)
  8224. (org-add-to-string
  8225. 'org-agenda-query-string
  8226. (if org-agenda-last-search-view-search-was-boolean
  8227. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8228. (?\{ . " +{}") (?\} . " -{}"))))
  8229. " "))
  8230. (setq org-agenda-redo-command
  8231. (list 'org-search-view
  8232. (car (get-text-property (min (1- (point-max)) (point))
  8233. 'org-last-args))
  8234. org-agenda-query-string
  8235. (+ (length org-agenda-query-string)
  8236. (if (member char '(?\{ ?\})) 0 1))))
  8237. (set-register org-agenda-query-register org-agenda-query-string)
  8238. (let ((org-agenda-overriding-arguments
  8239. (cdr org-agenda-redo-command)))
  8240. (org-agenda-redo)))
  8241. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8242. org-agenda-type))))
  8243. (defun org-add-to-string (var string)
  8244. (set var (concat (symbol-value var) string)))
  8245. (defun org-agenda-goto-date (date)
  8246. "Jump to DATE in the agenda buffer.
  8247. When called interactively, prompt for the date.
  8248. When called from Lisp, DATE should be a date as returned by
  8249. `org-read-date'.
  8250. See also:
  8251. `org-agenda-earlier' (\\[org-agenda-earlier])
  8252. `org-agenda-later' (\\[org-agenda-later])
  8253. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8254. (interactive
  8255. (list
  8256. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8257. (org-read-date))))
  8258. (let* ((day (time-to-days (org-time-string-to-time date)))
  8259. (org-agenda-sticky-orig org-agenda-sticky)
  8260. (org-agenda-buffer-tmp-name (buffer-name))
  8261. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8262. (0-arg (or current-prefix-arg (car args)))
  8263. (2-arg (nth 2 args))
  8264. (with-hour-p (nth 4 org-agenda-redo-command))
  8265. (newcmd (list 'org-agenda-list 0-arg date
  8266. (org-agenda-span-to-ndays
  8267. 2-arg (org-time-string-to-absolute date))
  8268. with-hour-p))
  8269. (newargs (cdr newcmd))
  8270. (inhibit-read-only t)
  8271. org-agenda-sticky)
  8272. (if (not (org-agenda-check-type t 'agenda))
  8273. (error "Not available in non-agenda views")
  8274. (add-text-properties (point-min) (point-max)
  8275. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8276. (org-agenda-redo)
  8277. (goto-char (point-min))
  8278. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8279. (save-excursion (move-beginning-of-line 2) (eobp))))
  8280. (move-beginning-of-line 2))
  8281. (setq org-agenda-sticky org-agenda-sticky-orig
  8282. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8283. (defun org-agenda-goto-today ()
  8284. "Go to today's date in the agenda buffer.
  8285. See also:
  8286. `org-agenda-later' (\\[org-agenda-later])
  8287. `org-agenda-earlier' (\\[org-agenda-earlier])
  8288. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8289. (interactive)
  8290. (org-agenda-check-type t 'agenda)
  8291. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8292. (curspan (nth 2 args))
  8293. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8294. (cond
  8295. (tdpos (goto-char tdpos))
  8296. ((eq org-agenda-type 'agenda)
  8297. (let* ((sd (org-agenda-compute-starting-span
  8298. (org-today) (or curspan org-agenda-span)))
  8299. (org-agenda-overriding-arguments args))
  8300. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8301. (org-agenda-redo)
  8302. (org-agenda-find-same-or-today-or-agenda)))
  8303. (t (error "Cannot find today")))))
  8304. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8305. (goto-char
  8306. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8307. (text-property-any (point-min) (point-max) 'org-today t)
  8308. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8309. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8310. (org-agenda-backward-block))
  8311. (point-min))))
  8312. (defun org-agenda-backward-block ()
  8313. "Move backward by one agenda block."
  8314. (interactive)
  8315. (org-agenda-forward-block 'backward))
  8316. (defun org-agenda-forward-block (&optional backward)
  8317. "Move forward by one agenda block.
  8318. When optional argument BACKWARD is set, go backward."
  8319. (interactive)
  8320. (cond ((not (derived-mode-p 'org-agenda-mode))
  8321. (user-error
  8322. "Cannot execute this command outside of org-agenda-mode buffers"))
  8323. ((looking-at (if backward "\\`" "\\'"))
  8324. (message "Already at the %s block" (if backward "first" "last")))
  8325. (t (let ((_pos (prog1 (point)
  8326. (ignore-errors (if backward (backward-char 1)
  8327. (move-end-of-line 1)))))
  8328. (f (if backward
  8329. #'previous-single-property-change
  8330. #'next-single-property-change))
  8331. moved dest)
  8332. (while (and (setq dest (funcall
  8333. f (point) 'org-agenda-structural-header))
  8334. (not (get-text-property
  8335. (point) 'org-agenda-structural-header)))
  8336. (setq moved t)
  8337. (goto-char dest))
  8338. (if moved (move-beginning-of-line 1)
  8339. (goto-char (if backward (point-min) (point-max)))
  8340. (move-beginning-of-line 1)
  8341. (message "No %s block" (if backward "previous" "further")))))))
  8342. (defun org-agenda-later (arg)
  8343. "Go forward in time by the current span in the agenda buffer.
  8344. With prefix ARG, go forward that many times the current span.
  8345. See also:
  8346. `org-agenda-earlier' (\\[org-agenda-earlier])
  8347. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8348. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8349. (interactive "p")
  8350. (org-agenda-check-type t 'agenda)
  8351. (let* ((wstart (window-start))
  8352. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8353. (span (or (nth 2 args) org-agenda-current-span))
  8354. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8355. (greg (calendar-gregorian-from-absolute sd))
  8356. (cnt (org-get-at-bol 'org-day-cnt))
  8357. greg2)
  8358. (cond
  8359. ((numberp span)
  8360. (setq sd (+ (* span arg) sd)))
  8361. ((eq span 'day)
  8362. (setq sd (+ arg sd)))
  8363. ((eq span 'week)
  8364. (setq sd (+ (* 7 arg) sd)))
  8365. ((eq span 'fortnight)
  8366. (setq sd (+ (* 14 arg) sd)))
  8367. ((eq span 'month)
  8368. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8369. sd (calendar-absolute-from-gregorian greg2))
  8370. (setcar greg2 (1+ (car greg2))))
  8371. ((eq span 'year)
  8372. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8373. sd (calendar-absolute-from-gregorian greg2))
  8374. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8375. (t
  8376. (setq sd (+ (* span arg) sd))))
  8377. (let ((org-agenda-overriding-cmd
  8378. ;; `cmd' may have been set by `org-agenda-run-series' which
  8379. ;; uses `org-agenda-overriding-cmd' to decide whether
  8380. ;; overriding is allowed for `cmd'
  8381. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8382. (org-agenda-overriding-arguments
  8383. (list (car args) sd span)))
  8384. (org-agenda-redo)
  8385. (org-agenda-find-same-or-today-or-agenda cnt))
  8386. (set-window-start nil wstart)))
  8387. (defun org-agenda-earlier (arg)
  8388. "Go backward in time by the current span in the agenda buffer.
  8389. With prefix ARG, go backward that many times the current span.
  8390. See also:
  8391. `org-agenda-later' (\\[org-agenda-later])
  8392. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8393. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8394. (interactive "p")
  8395. (org-agenda-later (- arg)))
  8396. (defun org-agenda-view-mode-dispatch ()
  8397. "Call one of the view mode commands."
  8398. (interactive)
  8399. (org-unlogged-message
  8400. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8401. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8402. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8403. (pcase (read-char-exclusive)
  8404. (?\ (call-interactively 'org-agenda-reset-view))
  8405. (?d (call-interactively 'org-agenda-day-view))
  8406. (?w (call-interactively 'org-agenda-week-view))
  8407. (?t (call-interactively 'org-agenda-fortnight-view))
  8408. (?m (call-interactively 'org-agenda-month-view))
  8409. (?y (call-interactively 'org-agenda-year-view))
  8410. (?l (call-interactively 'org-agenda-log-mode))
  8411. (?L (org-agenda-log-mode '(4)))
  8412. (?c (org-agenda-log-mode 'clockcheck))
  8413. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8414. (?a (call-interactively 'org-agenda-archives-mode))
  8415. (?A (org-agenda-archives-mode 'files))
  8416. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8417. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8418. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8419. (?D (call-interactively 'org-agenda-toggle-diary))
  8420. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8421. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8422. (org-agenda-check-type t 'agenda)
  8423. (org-agenda-redo))
  8424. (message "Display now includes inactive timestamps as well"))
  8425. (?q (message "Abort"))
  8426. (key (user-error "Invalid key: %s" key))))
  8427. (defun org-agenda-reset-view ()
  8428. "Switch to default view for agenda."
  8429. (interactive)
  8430. (org-agenda-change-time-span org-agenda-span))
  8431. (defun org-agenda-day-view (&optional day-of-month)
  8432. "Switch to daily view for agenda.
  8433. With argument DAY-OF-MONTH, switch to that day of the month."
  8434. (interactive "P")
  8435. (org-agenda-change-time-span 'day day-of-month))
  8436. (defun org-agenda-week-view (&optional iso-week)
  8437. "Switch to weekly view for agenda.
  8438. With argument ISO-WEEK, switch to the corresponding ISO week.
  8439. If ISO-WEEK has more then 2 digits, only the last two encode
  8440. the week. Any digits before this encode a year. So 200712
  8441. means week 12 of year 2007. Years ranging from 70 years ago
  8442. to 30 years in the future can also be written as 2-digit years."
  8443. (interactive "P")
  8444. (org-agenda-change-time-span 'week iso-week))
  8445. (defun org-agenda-fortnight-view (&optional iso-week)
  8446. "Switch to fortnightly view for agenda.
  8447. With argument ISO-WEEK, switch to the corresponding ISO week.
  8448. If ISO-WEEK has more then 2 digits, only the last two encode
  8449. the week. Any digits before this encode a year. So 200712
  8450. means week 12 of year 2007. Years ranging from 70 years ago
  8451. to 30 years in the future can also be written as 2-digit years."
  8452. (interactive "P")
  8453. (org-agenda-change-time-span 'fortnight iso-week))
  8454. (defun org-agenda-month-view (&optional month)
  8455. "Switch to monthly view for agenda.
  8456. With argument MONTH, switch to that month. If MONTH has more
  8457. then 2 digits, only the last two encode the month. Any digits
  8458. before this encode a year. So 200712 means December year 2007.
  8459. Years ranging from 70 years ago to 30 years in the future can
  8460. also be written as 2-digit years."
  8461. (interactive "P")
  8462. (org-agenda-change-time-span 'month month))
  8463. (defun org-agenda-year-view (&optional year)
  8464. "Switch to yearly view for agenda.
  8465. With argument YEAR, switch to that year. Years ranging from 70
  8466. years ago to 30 years in the future can also be written as
  8467. 2-digit years."
  8468. (interactive "P")
  8469. (when year
  8470. (setq year (org-small-year-to-year year)))
  8471. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8472. (org-agenda-change-time-span 'year year)
  8473. (error "Abort")))
  8474. (defun org-agenda-change-time-span (span &optional n)
  8475. "Change the agenda view to SPAN.
  8476. SPAN may be `day', `week', `fortnight', `month', `year'."
  8477. (org-agenda-check-type t 'agenda)
  8478. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8479. (curspan (nth 2 args)))
  8480. (when (and (not n) (equal curspan span))
  8481. (error "Viewing span is already \"%s\"" span))
  8482. (let* ((sd (or (org-get-at-bol 'day)
  8483. (nth 1 args)
  8484. org-starting-day))
  8485. (sd (org-agenda-compute-starting-span sd span n))
  8486. (org-agenda-overriding-cmd
  8487. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8488. (org-agenda-overriding-arguments
  8489. (list (car args) sd span)))
  8490. (org-agenda-redo)
  8491. (org-agenda-find-same-or-today-or-agenda))
  8492. (org-agenda-set-mode-name)
  8493. (message "Switched to %s view" span)))
  8494. (defun org-agenda-compute-starting-span (sd span &optional n)
  8495. "Compute starting date for agenda.
  8496. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8497. is a cons cell with the starting date and the number of days,
  8498. so that the date SD will be in that range."
  8499. (let* ((greg (calendar-gregorian-from-absolute sd))
  8500. ;; (dg (nth 1 greg))
  8501. (mg (car greg))
  8502. (yg (nth 2 greg)))
  8503. (cond
  8504. ((eq span 'day)
  8505. (when n
  8506. (setq sd (+ (calendar-absolute-from-gregorian
  8507. (list mg 1 yg))
  8508. n -1))))
  8509. ((or (eq span 'week) (eq span 'fortnight))
  8510. (let* ((nt (calendar-day-of-week
  8511. (calendar-gregorian-from-absolute sd)))
  8512. (d (if org-agenda-start-on-weekday
  8513. (- nt org-agenda-start-on-weekday)
  8514. 0))
  8515. y1)
  8516. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8517. (when n
  8518. (require 'cal-iso)
  8519. (when (> n 99)
  8520. (setq y1 (org-small-year-to-year (/ n 100))
  8521. n (mod n 100)))
  8522. (setq sd
  8523. (calendar-iso-to-absolute
  8524. (list n 1
  8525. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8526. ((eq span 'month)
  8527. (let (y1)
  8528. (when (and n (> n 99))
  8529. (setq y1 (org-small-year-to-year (/ n 100))
  8530. n (mod n 100)))
  8531. (setq sd (calendar-absolute-from-gregorian
  8532. (list (or n mg) 1 (or y1 yg))))))
  8533. ((eq span 'year)
  8534. (setq sd (calendar-absolute-from-gregorian
  8535. (list 1 1 (or n yg))))))
  8536. sd))
  8537. (defun org-agenda-next-date-line (&optional arg)
  8538. "Jump to the next line indicating a date in agenda buffer."
  8539. (interactive "p")
  8540. (org-agenda-check-type t 'agenda)
  8541. (beginning-of-line 1)
  8542. ;; This does not work if user makes date format that starts with a blank
  8543. (when (looking-at-p "^\\S-") (forward-char 1))
  8544. (unless (re-search-forward "^\\S-" nil t arg)
  8545. (backward-char 1)
  8546. (error "No next date after this line in this buffer"))
  8547. (goto-char (match-beginning 0)))
  8548. (defun org-agenda-previous-date-line (&optional arg)
  8549. "Jump to the previous line indicating a date in agenda buffer."
  8550. (interactive "p")
  8551. (org-agenda-check-type t 'agenda)
  8552. (beginning-of-line 1)
  8553. (unless (re-search-backward "^\\S-" nil t arg)
  8554. (error "No previous date before this line in this buffer")))
  8555. ;; Initialize the highlight
  8556. (defvar org-hl (make-overlay 1 1))
  8557. (overlay-put org-hl 'face 'highlight)
  8558. (defun org-highlight (begin end &optional buffer)
  8559. "Highlight a region with overlay."
  8560. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8561. (defun org-unhighlight ()
  8562. "Detach overlay INDEX."
  8563. (delete-overlay org-hl))
  8564. (defun org-unhighlight-once ()
  8565. "Remove the highlight from its position, and this function from the hook."
  8566. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8567. (org-unhighlight))
  8568. (defvar org-agenda-pre-follow-window-conf nil)
  8569. (defun org-agenda-follow-mode ()
  8570. "Toggle follow mode in an agenda buffer."
  8571. (interactive)
  8572. (unless org-agenda-follow-mode
  8573. (setq org-agenda-pre-follow-window-conf
  8574. (current-window-configuration)))
  8575. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8576. (unless org-agenda-follow-mode
  8577. (set-window-configuration org-agenda-pre-follow-window-conf))
  8578. (org-agenda-set-mode-name)
  8579. (org-agenda-do-context-action)
  8580. (message "Follow mode is %s"
  8581. (if org-agenda-follow-mode "on" "off")))
  8582. (defun org-agenda-entry-text-mode (&optional arg)
  8583. "Toggle entry text mode in an agenda buffer."
  8584. (interactive "P")
  8585. (if (or org-agenda-tag-filter
  8586. org-agenda-category-filter
  8587. org-agenda-regexp-filter
  8588. org-agenda-top-headline-filter)
  8589. (user-error "Can't show entry text in filtered views")
  8590. (setq org-agenda-entry-text-mode (or (integerp arg)
  8591. (not org-agenda-entry-text-mode)))
  8592. (org-agenda-entry-text-hide)
  8593. (and org-agenda-entry-text-mode
  8594. (let ((org-agenda-entry-text-maxlines
  8595. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8596. (org-agenda-entry-text-show)))
  8597. (org-agenda-set-mode-name)
  8598. (message "Entry text mode is %s%s"
  8599. (if org-agenda-entry-text-mode "on" "off")
  8600. (if (not org-agenda-entry-text-mode) ""
  8601. (format " (maximum number of lines is %d)"
  8602. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8603. (defun org-agenda-clockreport-mode ()
  8604. "Toggle clocktable mode in an agenda buffer."
  8605. (interactive)
  8606. (org-agenda-check-type t 'agenda)
  8607. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8608. (org-agenda-set-mode-name)
  8609. (org-agenda-redo)
  8610. (message "Clocktable mode is %s"
  8611. (if org-agenda-clockreport-mode "on" "off")))
  8612. (defun org-agenda-log-mode (&optional special)
  8613. "Toggle log mode in an agenda buffer.
  8614. With argument SPECIAL, show all possible log items, not only the ones
  8615. configured in `org-agenda-log-mode-items'.
  8616. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8617. log items, nothing else."
  8618. (interactive "P")
  8619. (org-agenda-check-type t 'agenda)
  8620. (setq org-agenda-show-log
  8621. (cond
  8622. ((equal special '(16)) 'only)
  8623. ((eq special 'clockcheck)
  8624. (if (eq org-agenda-show-log 'clockcheck)
  8625. nil 'clockcheck))
  8626. (special '(closed clock state))
  8627. (t (not org-agenda-show-log))))
  8628. (org-agenda-set-mode-name)
  8629. (org-agenda-redo)
  8630. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8631. (defun org-agenda-archives-mode (&optional with-files)
  8632. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8633. When called with a prefix argument, include all archive files as well."
  8634. (interactive "P")
  8635. (setq org-agenda-archives-mode
  8636. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8637. (with-files t)
  8638. (org-agenda-archives-mode nil)
  8639. (t 'trees)))
  8640. (org-agenda-set-mode-name)
  8641. (org-agenda-redo)
  8642. (message
  8643. "%s"
  8644. (cond
  8645. ((eq org-agenda-archives-mode nil)
  8646. "No archives are included")
  8647. ((eq org-agenda-archives-mode 'trees)
  8648. (format "Trees with :%s: tag are included" org-archive-tag))
  8649. ((eq org-agenda-archives-mode t)
  8650. (format "Trees with :%s: tag and all active archive files are included"
  8651. org-archive-tag)))))
  8652. (defun org-agenda-toggle-diary ()
  8653. "Toggle diary inclusion in an agenda buffer."
  8654. (interactive)
  8655. (org-agenda-check-type t 'agenda)
  8656. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8657. (org-agenda-redo)
  8658. (org-agenda-set-mode-name)
  8659. (message "Diary inclusion turned %s"
  8660. (if org-agenda-include-diary "on" "off")))
  8661. (defun org-agenda-toggle-deadlines ()
  8662. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8663. (interactive)
  8664. (org-agenda-check-type t 'agenda)
  8665. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8666. (org-agenda-redo)
  8667. (org-agenda-set-mode-name)
  8668. (message "Deadlines inclusion turned %s"
  8669. (if org-agenda-include-deadlines "on" "off")))
  8670. (defun org-agenda-toggle-time-grid ()
  8671. "Toggle time grid in an agenda buffer."
  8672. (interactive)
  8673. (org-agenda-check-type t 'agenda)
  8674. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8675. (org-agenda-redo)
  8676. (org-agenda-set-mode-name)
  8677. (message "Time-grid turned %s"
  8678. (if org-agenda-use-time-grid "on" "off")))
  8679. (defun org-agenda-set-mode-name ()
  8680. "Set the mode name to indicate all the small mode settings."
  8681. (setq mode-name
  8682. (list "Org-Agenda"
  8683. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8684. " "
  8685. '(:eval (org-agenda-span-name org-agenda-current-span))
  8686. (if org-agenda-follow-mode " Follow" "")
  8687. (if org-agenda-entry-text-mode " ETxt" "")
  8688. (if org-agenda-include-diary " Diary" "")
  8689. (if org-agenda-include-deadlines " Ddl" "")
  8690. (if org-agenda-use-time-grid " Grid" "")
  8691. (if (and (boundp 'org-habit-show-habits)
  8692. org-habit-show-habits)
  8693. " Habit" "")
  8694. (cond
  8695. ((consp org-agenda-show-log) " LogAll")
  8696. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8697. (org-agenda-show-log " Log")
  8698. (t ""))
  8699. (if (org-agenda-filter-any) " " "")
  8700. (if (or org-agenda-category-filter
  8701. (get 'org-agenda-category-filter :preset-filter))
  8702. '(:eval (propertize
  8703. (concat "["
  8704. (mapconcat
  8705. #'identity
  8706. (append
  8707. (get 'org-agenda-category-filter :preset-filter)
  8708. org-agenda-category-filter)
  8709. "")
  8710. "]")
  8711. 'face 'org-agenda-filter-category
  8712. 'help-echo "Category used in filtering"))
  8713. "")
  8714. (if (or org-agenda-tag-filter
  8715. (get 'org-agenda-tag-filter :preset-filter))
  8716. '(:eval (propertize
  8717. (concat (mapconcat
  8718. #'identity
  8719. (append
  8720. (get 'org-agenda-tag-filter :preset-filter)
  8721. org-agenda-tag-filter)
  8722. ""))
  8723. 'face 'org-agenda-filter-tags
  8724. 'help-echo "Tags used in filtering"))
  8725. "")
  8726. (if (or org-agenda-effort-filter
  8727. (get 'org-agenda-effort-filter :preset-filter))
  8728. '(:eval (propertize
  8729. (concat (mapconcat
  8730. #'identity
  8731. (append
  8732. (get 'org-agenda-effort-filter :preset-filter)
  8733. org-agenda-effort-filter)
  8734. ""))
  8735. 'face 'org-agenda-filter-effort
  8736. 'help-echo "Effort conditions used in filtering"))
  8737. "")
  8738. (if (or org-agenda-regexp-filter
  8739. (get 'org-agenda-regexp-filter :preset-filter))
  8740. '(:eval (propertize
  8741. (concat (mapconcat
  8742. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8743. (append
  8744. (get 'org-agenda-regexp-filter :preset-filter)
  8745. org-agenda-regexp-filter)
  8746. ""))
  8747. 'face 'org-agenda-filter-regexp
  8748. 'help-echo "Regexp used in filtering"))
  8749. "")
  8750. (if org-agenda-archives-mode
  8751. (if (eq org-agenda-archives-mode t)
  8752. " Archives"
  8753. (format " :%s:" org-archive-tag))
  8754. "")
  8755. (if org-agenda-clockreport-mode " Clock" "")))
  8756. (force-mode-line-update))
  8757. (defun org-agenda-update-agenda-type ()
  8758. "Update the agenda type after each command."
  8759. (setq org-agenda-type
  8760. (or (get-text-property (point) 'org-agenda-type)
  8761. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8762. (defun org-agenda-next-line ()
  8763. "Move cursor to the next line, and show if follow mode is active."
  8764. (interactive)
  8765. (call-interactively 'next-line)
  8766. (org-agenda-do-context-action))
  8767. (defun org-agenda-previous-line ()
  8768. "Move cursor to the previous line, and show if follow-mode is active."
  8769. (interactive)
  8770. (call-interactively 'previous-line)
  8771. (org-agenda-do-context-action))
  8772. (defun org-agenda-next-item (n)
  8773. "Move cursor to next agenda item."
  8774. (interactive "p")
  8775. (let ((col (current-column)))
  8776. (dotimes (_ n)
  8777. (when (next-single-property-change (point-at-eol) 'org-marker)
  8778. (move-end-of-line 1)
  8779. (goto-char (next-single-property-change (point) 'org-marker))))
  8780. (org-move-to-column col))
  8781. (org-agenda-do-context-action))
  8782. (defun org-agenda-previous-item (n)
  8783. "Move cursor to next agenda item."
  8784. (interactive "p")
  8785. (dotimes (_ n)
  8786. (let ((col (current-column))
  8787. (goto (save-excursion
  8788. (move-end-of-line 0)
  8789. (previous-single-property-change (point) 'org-marker))))
  8790. (when goto (goto-char goto))
  8791. (org-move-to-column col)))
  8792. (org-agenda-do-context-action))
  8793. (defun org-agenda-do-context-action ()
  8794. "Show outline path and, maybe, follow mode window."
  8795. (let ((m (org-get-at-bol 'org-marker)))
  8796. (when (and (markerp m) (marker-buffer m))
  8797. (and org-agenda-follow-mode
  8798. (if org-agenda-follow-indirect
  8799. (org-agenda-tree-to-indirect-buffer nil)
  8800. (org-agenda-show)))
  8801. (and org-agenda-show-outline-path
  8802. (org-with-point-at m (org-display-outline-path t))))))
  8803. (defun org-agenda-show-tags ()
  8804. "Show the tags applicable to the current item."
  8805. (interactive)
  8806. (let* ((tags (org-get-at-bol 'tags)))
  8807. (if tags
  8808. (message "Tags are :%s:"
  8809. (org-no-properties (mapconcat #'identity tags ":")))
  8810. (message "No tags associated with this line"))))
  8811. (defun org-agenda-goto (&optional highlight)
  8812. "Go to the entry at point in the corresponding Org file."
  8813. (interactive)
  8814. (let* ((marker (or (org-get-at-bol 'org-marker)
  8815. (org-agenda-error)))
  8816. (buffer (marker-buffer marker))
  8817. (pos (marker-position marker)))
  8818. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8819. (switch-to-buffer-other-window buffer)
  8820. (widen)
  8821. (push-mark)
  8822. (goto-char pos)
  8823. (when (derived-mode-p 'org-mode)
  8824. (org-fold-show-context 'agenda)
  8825. (recenter (/ (window-height) 2))
  8826. (org-back-to-heading t)
  8827. (let ((case-fold-search nil))
  8828. (when (re-search-forward org-complex-heading-regexp nil t)
  8829. (goto-char (match-beginning 4)))))
  8830. (run-hooks 'org-agenda-after-show-hook)
  8831. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8832. (defvar org-agenda-after-show-hook nil
  8833. "Normal hook run after an item has been shown from the agenda.
  8834. Point is in the buffer where the item originated.")
  8835. ;; Defined later in org-agenda.el
  8836. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8837. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8838. "Between region BEG and END, call agenda command CMD.
  8839. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8840. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8841. deletes the agenda entry and don't move to the next entry."
  8842. (save-excursion
  8843. (goto-char beg)
  8844. (let ((mend (move-marker (make-marker) end))
  8845. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8846. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8847. org-agenda-loop-over-headlines-in-active-region))
  8848. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8849. (org-get-at-bol 'level))))
  8850. (while (< (point) mend)
  8851. (let ((ov (make-overlay (point) (point-at-eol))))
  8852. (if (not (or all
  8853. (and match (looking-at-p match))
  8854. (eq level (org-get-at-bol 'level))))
  8855. (org-agenda-next-item 1)
  8856. (overlay-put ov 'face 'region)
  8857. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8858. (when (not delete) (org-agenda-next-item 1))
  8859. (delete-overlay ov)))))))
  8860. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8861. ;; kill,set-property,set-effort] commands may loop over agenda
  8862. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8863. ;; use their own mechanisms on active regions.
  8864. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8865. "Maybe loop over agenda entries and perform CMD.
  8866. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8867. (declare (debug t))
  8868. `(if (and (called-interactively-p 'any)
  8869. org-agenda-loop-over-headlines-in-active-region
  8870. (org-region-active-p))
  8871. (org-agenda-do-in-region
  8872. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8873. ,@body))
  8874. (defun org-agenda-kill ()
  8875. "Kill the entry or subtree belonging to the current agenda entry."
  8876. (interactive)
  8877. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8878. (org-agenda-maybe-loop
  8879. #'org-agenda-kill nil nil t
  8880. (let* ((bufname-orig (buffer-name))
  8881. (marker (or (org-get-at-bol 'org-marker)
  8882. (org-agenda-error)))
  8883. (buffer (marker-buffer marker))
  8884. (pos (marker-position marker))
  8885. (type (org-get-at-bol 'type))
  8886. dbeg dend (n 0))
  8887. (org-with-remote-undo buffer
  8888. (with-current-buffer buffer
  8889. (save-excursion
  8890. (goto-char pos)
  8891. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8892. (setq dbeg (progn (org-back-to-heading t) (point))
  8893. dend (org-end-of-subtree t t))
  8894. (setq dbeg (point-at-bol)
  8895. dend (min (point-max) (1+ (point-at-eol)))))
  8896. (goto-char dbeg)
  8897. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8898. (when (or (eq t org-agenda-confirm-kill)
  8899. (and (numberp org-agenda-confirm-kill)
  8900. (> n org-agenda-confirm-kill)))
  8901. (let ((win-conf (current-window-configuration)))
  8902. (unwind-protect
  8903. (and
  8904. (prog2
  8905. (org-agenda-tree-to-indirect-buffer nil)
  8906. (not (y-or-n-p
  8907. (format "Delete entry with %d lines in buffer \"%s\"? "
  8908. n (buffer-name buffer))))
  8909. (kill-buffer org-last-indirect-buffer))
  8910. (error "Abort"))
  8911. (set-window-configuration win-conf))))
  8912. (let ((org-agenda-buffer-name bufname-orig))
  8913. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8914. (with-current-buffer buffer (delete-region dbeg dend))
  8915. (message "Agenda item and source killed")))))
  8916. (defvar org-archive-default-command) ; defined in org-archive.el
  8917. (defun org-agenda-archive-default ()
  8918. "Archive the entry or subtree belonging to the current agenda entry."
  8919. (interactive)
  8920. (require 'org-archive)
  8921. (funcall-interactively
  8922. #'org-agenda-archive-with org-archive-default-command))
  8923. (defun org-agenda-archive-default-with-confirmation ()
  8924. "Archive the entry or subtree belonging to the current agenda entry."
  8925. (interactive)
  8926. (require 'org-archive)
  8927. (funcall-interactively
  8928. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8929. (defun org-agenda-archive ()
  8930. "Archive the entry or subtree belonging to the current agenda entry."
  8931. (interactive)
  8932. (funcall-interactively
  8933. #'org-agenda-archive-with 'org-archive-subtree))
  8934. (defun org-agenda-archive-to-archive-sibling ()
  8935. "Move the entry to the archive sibling."
  8936. (interactive)
  8937. (funcall-interactively
  8938. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8939. (defvar org-archive-from-agenda)
  8940. (defun org-agenda-archive-with (cmd &optional confirm)
  8941. "Move the entry to the archive sibling."
  8942. (interactive)
  8943. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8944. (org-agenda-maybe-loop
  8945. #'org-agenda-archive-with cmd nil t
  8946. (let* ((bufname-orig (buffer-name))
  8947. (marker (or (org-get-at-bol 'org-marker)
  8948. (org-agenda-error)))
  8949. (buffer (marker-buffer marker))
  8950. (pos (marker-position marker)))
  8951. (org-with-remote-undo buffer
  8952. (with-current-buffer buffer
  8953. (if (derived-mode-p 'org-mode)
  8954. (if (and confirm
  8955. (not (y-or-n-p "Archive this subtree or entry? ")))
  8956. (error "Abort")
  8957. (save-window-excursion
  8958. (goto-char pos)
  8959. (let ((org-agenda-buffer-name bufname-orig))
  8960. (org-remove-subtree-entries-from-agenda))
  8961. (org-back-to-heading t)
  8962. (let ((org-archive-from-agenda t))
  8963. (funcall cmd))))
  8964. (error "Archiving works only in Org files")))))))
  8965. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8966. "Remove all lines in the agenda that correspond to a given subtree.
  8967. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8968. If this information is not given, the function uses the tree at point."
  8969. (let ((buf (or buf (current-buffer))) m p)
  8970. (save-excursion
  8971. (unless (and beg end)
  8972. (org-back-to-heading t)
  8973. (setq beg (point))
  8974. (org-end-of-subtree t)
  8975. (setq end (point)))
  8976. (set-buffer (get-buffer org-agenda-buffer-name))
  8977. (save-excursion
  8978. (goto-char (point-max))
  8979. (beginning-of-line 1)
  8980. (while (not (bobp))
  8981. (when (and (setq m (org-get-at-bol 'org-marker))
  8982. (equal buf (marker-buffer m))
  8983. (setq p (marker-position m))
  8984. (>= p beg)
  8985. (< p end))
  8986. (let ((inhibit-read-only t))
  8987. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8988. (beginning-of-line 0))))))
  8989. (defun org-agenda-refile (&optional goto rfloc no-update)
  8990. "Refile the item at point.
  8991. When called with `\\[universal-argument] \\[universal-argument]', \
  8992. go to the location of the last
  8993. refiled item.
  8994. When called with `\\[universal-argument] \\[universal-argument] \
  8995. \\[universal-argument]' prefix or when GOTO is 0, clear
  8996. the refile cache.
  8997. RFLOC can be a refile location obtained in a different way.
  8998. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8999. (interactive "P")
  9000. (cond
  9001. ((member goto '(0 (64)))
  9002. (org-refile-cache-clear))
  9003. ((equal goto '(16))
  9004. (org-refile-goto-last-stored))
  9005. (t
  9006. (let* ((buffer-orig (buffer-name))
  9007. (marker (or (org-get-at-bol 'org-hd-marker)
  9008. (org-agenda-error)))
  9009. (buffer (marker-buffer marker))
  9010. ;; (pos (marker-position marker))
  9011. (rfloc (or rfloc
  9012. (org-refile-get-location
  9013. (if goto "Goto" "Refile to") buffer
  9014. org-refile-allow-creating-parent-nodes))))
  9015. (with-current-buffer buffer
  9016. (org-with-wide-buffer
  9017. (goto-char marker)
  9018. (let ((org-agenda-buffer-name buffer-orig))
  9019. (org-remove-subtree-entries-from-agenda))
  9020. (org-refile goto buffer rfloc))))
  9021. (unless no-update (org-agenda-redo)))))
  9022. (defun org-agenda-open-link (&optional arg)
  9023. "Open the link(s) in the current entry, if any.
  9024. This looks for a link in the displayed line in the agenda.
  9025. It also looks at the text of the entry itself."
  9026. (interactive "P")
  9027. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9028. (org-get-at-bol 'org-marker)))
  9029. (buffer (and marker (marker-buffer marker)))
  9030. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  9031. (lkall (and buffer (org-offer-links-in-entry
  9032. buffer marker arg prefix)))
  9033. (lk0 (car lkall))
  9034. (lk (if (stringp lk0) (list lk0) lk0))
  9035. (lkend (cdr lkall))
  9036. trg)
  9037. (cond
  9038. ((and buffer lk)
  9039. (mapcar (lambda(l)
  9040. (with-current-buffer buffer
  9041. (setq trg (and (string-match org-link-bracket-re l)
  9042. (match-string 1 l)))
  9043. (if (or (not trg) (string-match org-link-any-re trg))
  9044. ;; Don't use `org-with-wide-buffer' here as
  9045. ;; opening the link may result in moving the point
  9046. (save-restriction
  9047. (widen)
  9048. (goto-char marker)
  9049. (when (search-forward l nil lkend)
  9050. (goto-char (match-beginning 0))
  9051. (org-open-at-point)))
  9052. ;; This is an internal link, widen the buffer
  9053. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9054. (switch-to-buffer-other-window buffer)
  9055. (widen)
  9056. (goto-char marker)
  9057. (when (search-forward l nil lkend)
  9058. (goto-char (match-beginning 0))
  9059. (org-open-at-point)))))
  9060. lk))
  9061. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9062. (save-excursion
  9063. (beginning-of-line 1)
  9064. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9065. (org-link-open-from-string (match-string 1)))
  9066. (t (message "No link to open here")))))
  9067. (defun org-agenda-copy-local-variable (var)
  9068. "Get a variable from a referenced buffer and install it here."
  9069. (let ((m (org-get-at-bol 'org-marker)))
  9070. (when (and m (buffer-live-p (marker-buffer m)))
  9071. (set (make-local-variable var)
  9072. (with-current-buffer (marker-buffer m)
  9073. (symbol-value var))))))
  9074. (defun org-agenda-switch-to (&optional delete-other-windows)
  9075. "Go to the Org mode file which contains the item at point.
  9076. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9077. displayed Org file fills the frame."
  9078. (interactive)
  9079. (if (and org-return-follows-link
  9080. (not (org-get-at-bol 'org-marker))
  9081. (org-in-regexp org-link-bracket-re))
  9082. (org-link-open-from-string (match-string 0))
  9083. (let* ((marker (or (org-get-at-bol 'org-marker)
  9084. (org-agenda-error)))
  9085. (buffer (marker-buffer marker))
  9086. (pos (marker-position marker)))
  9087. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9088. (pop-to-buffer-same-window buffer)
  9089. (when delete-other-windows (delete-other-windows))
  9090. (widen)
  9091. (goto-char pos)
  9092. (when (derived-mode-p 'org-mode)
  9093. (org-fold-show-context 'agenda)
  9094. (run-hooks 'org-agenda-after-show-hook)))))
  9095. (defun org-agenda-goto-mouse (ev)
  9096. "Go to the Org file which contains the item at the mouse click."
  9097. (interactive "e")
  9098. (mouse-set-point ev)
  9099. (org-agenda-goto))
  9100. (defun org-agenda-show (&optional full-entry)
  9101. "Display the Org file which contains the item at point.
  9102. With prefix argument FULL-ENTRY, make the entire entry visible
  9103. if it was hidden in the outline."
  9104. (interactive "P")
  9105. (let ((win (selected-window)))
  9106. (org-agenda-goto t)
  9107. (when full-entry (org-fold-show-entry))
  9108. (select-window win)))
  9109. (defvar org-agenda-show-window nil)
  9110. (defun org-agenda-show-and-scroll-up (&optional arg)
  9111. "Display the Org file which contains the item at point.
  9112. When called repeatedly, scroll the window that is displaying the buffer.
  9113. With a `\\[universal-argument]' prefix argument, display the item, but \
  9114. fold drawers."
  9115. (interactive "P")
  9116. (let ((win (selected-window)))
  9117. (if (and (window-live-p org-agenda-show-window)
  9118. (eq this-command last-command))
  9119. (progn
  9120. (select-window org-agenda-show-window)
  9121. (ignore-errors (scroll-up)))
  9122. (org-agenda-goto t)
  9123. (org-fold-show-entry)
  9124. (if arg (org-cycle-hide-drawers 'children)
  9125. (org-with-wide-buffer
  9126. (narrow-to-region (org-entry-beginning-position)
  9127. (org-entry-end-position))
  9128. (org-fold-show-all '(drawers))))
  9129. (setq org-agenda-show-window (selected-window)))
  9130. (select-window win)))
  9131. (defun org-agenda-show-scroll-down ()
  9132. "Scroll down the window showing the agenda."
  9133. (interactive)
  9134. (let ((win (selected-window)))
  9135. (when (window-live-p org-agenda-show-window)
  9136. (select-window org-agenda-show-window)
  9137. (ignore-errors (scroll-down))
  9138. (select-window win))))
  9139. (defun org-agenda-show-1 (&optional more)
  9140. "Display the Org file which contains the item at point.
  9141. The prefix arg selects the amount of information to display:
  9142. 0 hide the subtree
  9143. 1 just show the entry according to defaults.
  9144. 2 show the children view
  9145. 3 show the subtree view
  9146. 4 show the entire subtree and any drawers
  9147. With prefix argument FULL-ENTRY, make the entire entry visible
  9148. if it was hidden in the outline."
  9149. (interactive "p")
  9150. (let ((win (selected-window)))
  9151. (org-agenda-goto t)
  9152. (org-back-to-heading)
  9153. (set-window-start (selected-window) (point-at-bol))
  9154. (cond
  9155. ((= more 0)
  9156. (org-fold-subtree t)
  9157. (save-excursion
  9158. (org-back-to-heading)
  9159. (run-hook-with-args 'org-cycle-hook 'folded))
  9160. (message "Remote: FOLDED"))
  9161. ((and (called-interactively-p 'any) (= more 1))
  9162. (message "Remote: show with default settings"))
  9163. ((= more 2)
  9164. (org-fold-show-entry)
  9165. (org-fold-show-children)
  9166. (save-excursion
  9167. (org-back-to-heading)
  9168. (run-hook-with-args 'org-cycle-hook 'children))
  9169. (message "Remote: CHILDREN"))
  9170. ((= more 3)
  9171. (org-fold-show-subtree)
  9172. (save-excursion
  9173. (org-back-to-heading)
  9174. (run-hook-with-args 'org-cycle-hook 'subtree))
  9175. (message "Remote: SUBTREE"))
  9176. ((> more 3)
  9177. (org-fold-show-subtree)
  9178. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9179. (select-window win)))
  9180. (defvar org-agenda-cycle-counter nil)
  9181. (defun org-agenda-cycle-show (&optional n)
  9182. "Show the current entry in another window, with default settings.
  9183. Default settings are taken from `org-show-context-detail'. When
  9184. use repeatedly in immediate succession, the remote entry will
  9185. cycle through visibility
  9186. children -> subtree -> folded
  9187. When called with a numeric prefix arg, that arg will be passed through to
  9188. `org-agenda-show-1'. For the interpretation of that argument, see the
  9189. docstring of `org-agenda-show-1'."
  9190. (interactive "P")
  9191. (if (integerp n)
  9192. (setq org-agenda-cycle-counter n)
  9193. (if (not (eq last-command this-command))
  9194. (setq org-agenda-cycle-counter 1)
  9195. (if (equal org-agenda-cycle-counter 0)
  9196. (setq org-agenda-cycle-counter 2)
  9197. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9198. (when (> org-agenda-cycle-counter 3)
  9199. (setq org-agenda-cycle-counter 0)))))
  9200. (org-agenda-show-1 org-agenda-cycle-counter))
  9201. (defun org-agenda-recenter (arg)
  9202. "Display the Org file which contains the item at point and recenter."
  9203. (interactive "P")
  9204. (let ((win (selected-window)))
  9205. (org-agenda-goto t)
  9206. (recenter arg)
  9207. (select-window win)))
  9208. (defun org-agenda-show-mouse (ev)
  9209. "Display the Org file which contains the item at the mouse click."
  9210. (interactive "e")
  9211. (mouse-set-point ev)
  9212. (org-agenda-show))
  9213. (defun org-agenda-check-no-diary ()
  9214. "Check if the entry is a diary link and abort if yes."
  9215. (when (org-get-at-bol 'org-agenda-diary-link)
  9216. (org-agenda-error)))
  9217. (defun org-agenda-error ()
  9218. "Throw an error when a command is not allowed in the agenda."
  9219. (user-error "Command not allowed in this line"))
  9220. (defun org-agenda-tree-to-indirect-buffer (arg)
  9221. "Show the subtree corresponding to the current entry in an indirect buffer.
  9222. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9223. With a numerical prefix ARG, go up to this level and then take that tree.
  9224. With a negative numeric ARG, go up by this number of levels.
  9225. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9226. i.e. don't use
  9227. the dedicated frame."
  9228. (interactive "P")
  9229. (if current-prefix-arg
  9230. (org-agenda-do-tree-to-indirect-buffer arg)
  9231. (let ((agenda-buffer (buffer-name))
  9232. (agenda-window (selected-window))
  9233. (indirect-window
  9234. (and org-last-indirect-buffer
  9235. (get-buffer-window org-last-indirect-buffer))))
  9236. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9237. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9238. (eq org-indirect-buffer-display 'dedicated-frame))
  9239. (unwind-protect
  9240. (unless (and indirect-window (window-live-p indirect-window))
  9241. (setq indirect-window (split-window agenda-window)))
  9242. (and indirect-window (select-window indirect-window))
  9243. (switch-to-buffer org-last-indirect-buffer :norecord)
  9244. (fit-window-to-buffer indirect-window)))
  9245. (select-window (get-buffer-window agenda-buffer))
  9246. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9247. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9248. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9249. (org-agenda-check-no-diary)
  9250. (let* ((marker (or (org-get-at-bol 'org-marker)
  9251. (org-agenda-error)))
  9252. (buffer (marker-buffer marker))
  9253. (pos (marker-position marker)))
  9254. (with-current-buffer buffer
  9255. (save-excursion
  9256. (goto-char pos)
  9257. (org-tree-to-indirect-buffer arg)))))
  9258. (defvar org-last-heading-marker (make-marker)
  9259. "Marker pointing to the headline that last changed its TODO state
  9260. by a remote command from the agenda.")
  9261. (defun org-agenda-todo-nextset ()
  9262. "Switch TODO entry to next sequence."
  9263. (interactive)
  9264. (org-agenda-todo 'nextset))
  9265. (defun org-agenda-todo-previousset ()
  9266. "Switch TODO entry to previous sequence."
  9267. (interactive)
  9268. (org-agenda-todo 'previousset))
  9269. (defvar org-agenda-headline-snapshot-before-repeat)
  9270. (defun org-agenda-todo (&optional arg)
  9271. "Cycle TODO state of line at point, also in Org file.
  9272. This changes the line at point, all other lines in the agenda referring to
  9273. the same tree node, and the headline of the tree node in the Org file."
  9274. (interactive "P")
  9275. (org-agenda-check-no-diary)
  9276. (org-agenda-maybe-loop
  9277. #'org-agenda-todo arg nil nil
  9278. (let* ((col (current-column))
  9279. (marker (or (org-get-at-bol 'org-marker)
  9280. (org-agenda-error)))
  9281. (buffer (marker-buffer marker))
  9282. (pos (marker-position marker))
  9283. (hdmarker (org-get-at-bol 'org-hd-marker))
  9284. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9285. (inhibit-read-only t)
  9286. org-loop-over-headlines-in-active-region
  9287. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9288. (org-with-remote-undo buffer
  9289. (with-current-buffer buffer
  9290. (widen)
  9291. (goto-char pos)
  9292. (org-fold-show-context 'agenda)
  9293. (let ((current-prefix-arg arg))
  9294. (call-interactively 'org-todo)
  9295. ;; Make sure that log is recorded in current undo.
  9296. (when (and org-log-setup
  9297. (not (eq org-log-note-how 'note)))
  9298. (org-add-log-note)))
  9299. (and (bolp) (forward-char 1))
  9300. (setq newhead (org-get-heading))
  9301. (when (and org-agenda-headline-snapshot-before-repeat
  9302. (not (equal org-agenda-headline-snapshot-before-repeat
  9303. newhead))
  9304. todayp)
  9305. (setq newhead org-agenda-headline-snapshot-before-repeat
  9306. just-one t))
  9307. (save-excursion
  9308. (org-back-to-heading)
  9309. (move-marker org-last-heading-marker (point))))
  9310. (beginning-of-line 1)
  9311. (save-window-excursion
  9312. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9313. (when (bound-and-true-p org-clock-out-when-done)
  9314. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9315. newhead)
  9316. (org-agenda-unmark-clocking-task))
  9317. (org-move-to-column col)
  9318. (org-agenda-mark-clocking-task)))))
  9319. (defun org-agenda-add-note (&optional _arg)
  9320. "Add a time-stamped note to the entry at point."
  9321. (interactive) ;; "P"
  9322. (org-agenda-check-no-diary)
  9323. (let* ((marker (or (org-get-at-bol 'org-marker)
  9324. (org-agenda-error)))
  9325. (buffer (marker-buffer marker))
  9326. (pos (marker-position marker))
  9327. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9328. (inhibit-read-only t))
  9329. (with-current-buffer buffer
  9330. (widen)
  9331. (goto-char pos)
  9332. (org-fold-show-context 'agenda)
  9333. (org-add-note))))
  9334. (defun org-agenda-change-all-lines (newhead hdmarker
  9335. &optional fixface just-this)
  9336. "Change all lines in the agenda buffer which match HDMARKER.
  9337. The new content of the line will be NEWHEAD (as modified by
  9338. `org-agenda-format-item'). HDMARKER is checked with
  9339. `equal' against all `org-hd-marker' text properties in the file.
  9340. If FIXFACE is non-nil, the face of each item is modified according to
  9341. the new TODO state.
  9342. If JUST-THIS is non-nil, change just the current line, not all.
  9343. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9344. (let* ((inhibit-read-only t)
  9345. (line (org-current-line))
  9346. (org-agenda-buffer (current-buffer))
  9347. (thetags (with-current-buffer (marker-buffer hdmarker)
  9348. (org-get-tags hdmarker)))
  9349. props m undone-face done-face finish new dotime level cat tags
  9350. effort effort-minutes) ;; pl
  9351. (save-excursion
  9352. (goto-char (point-max))
  9353. (beginning-of-line 1)
  9354. (while (not finish)
  9355. (setq finish (bobp))
  9356. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9357. (or (not just-this) (= (org-current-line) line))
  9358. (equal m hdmarker))
  9359. (setq props (text-properties-at (point))
  9360. dotime (org-get-at-bol 'dotime)
  9361. cat (org-agenda-get-category)
  9362. level (org-get-at-bol 'level)
  9363. tags thetags
  9364. effort (org-get-at-bol 'effort)
  9365. effort-minutes (org-get-at-bol 'effort-minutes)
  9366. new
  9367. (let ((org-prefix-format-compiled
  9368. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9369. org-prefix-format-compiled))
  9370. (extra (org-get-at-bol 'extra)))
  9371. (with-current-buffer (marker-buffer hdmarker)
  9372. (org-with-wide-buffer
  9373. (org-agenda-format-item extra
  9374. (org-add-props newhead nil
  9375. 'effort effort
  9376. 'effort-minutes effort-minutes)
  9377. level cat tags dotime))))
  9378. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9379. undone-face (org-get-at-bol 'undone-face)
  9380. done-face (org-get-at-bol 'done-face))
  9381. (beginning-of-line 1)
  9382. (cond
  9383. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9384. ((looking-at ".*")
  9385. ;; When replacing the whole line, preserve bulk mark
  9386. ;; overlay, if any.
  9387. (let ((mark (catch :overlay
  9388. (dolist (o (overlays-in (point) (+ 2 (point))))
  9389. (when (eq (overlay-get o 'type)
  9390. 'org-marked-entry-overlay)
  9391. (throw :overlay o))))))
  9392. (replace-match new t t)
  9393. (beginning-of-line)
  9394. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9395. (add-text-properties (point-at-bol) (point-at-eol) props)
  9396. (when fixface
  9397. (add-text-properties
  9398. (point-at-bol) (point-at-eol)
  9399. (list 'face
  9400. (if org-last-todo-state-is-todo
  9401. undone-face done-face))))
  9402. (org-agenda-highlight-todo 'line)
  9403. (beginning-of-line 1))
  9404. (t (error "Line update did not work")))
  9405. (save-restriction
  9406. (narrow-to-region (point-at-bol) (point-at-eol))
  9407. (org-agenda-finalize)))
  9408. (beginning-of-line 0)))))
  9409. (defun org-agenda-align-tags (&optional line)
  9410. "Align all tags in agenda items to `org-agenda-tags-column'.
  9411. When optional argument LINE is non-nil, align tags only on the
  9412. current line."
  9413. (let ((inhibit-read-only t)
  9414. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9415. (- (window-max-chars-per-line))
  9416. org-agenda-tags-column))
  9417. (end (and line (line-end-position)))
  9418. l c)
  9419. (save-excursion
  9420. (goto-char (if line (line-beginning-position) (point-min)))
  9421. (while (re-search-forward org-tag-group-re end t)
  9422. (add-text-properties
  9423. (match-beginning 1) (match-end 1)
  9424. (list 'face (delq nil (let ((prop (get-text-property
  9425. (match-beginning 1) 'face)))
  9426. (or (listp prop) (setq prop (list prop)))
  9427. (if (memq 'org-tag prop)
  9428. prop
  9429. (cons 'org-tag prop))))))
  9430. (setq l (string-width (match-string 1))
  9431. c (if (< org-agenda-tags-column 0)
  9432. (- (abs org-agenda-tags-column) l)
  9433. org-agenda-tags-column))
  9434. (goto-char (match-beginning 1))
  9435. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9436. (point))
  9437. (insert (org-add-props
  9438. (make-string (max 1 (- c (current-column))) ?\s)
  9439. (plist-put (copy-sequence (text-properties-at (point)))
  9440. 'face nil))))
  9441. (goto-char (point-min))
  9442. (org-font-lock-add-tag-faces (point-max)))))
  9443. (defun org-agenda-priority-up ()
  9444. "Increase the priority of line at point, also in Org file."
  9445. (interactive)
  9446. (org-agenda-priority 'up))
  9447. (defun org-agenda-priority-down ()
  9448. "Decrease the priority of line at point, also in Org file."
  9449. (interactive)
  9450. (org-agenda-priority 'down))
  9451. (defun org-agenda-priority (&optional force-direction)
  9452. "Set the priority of line at point, also in Org file.
  9453. This changes the line at point, all other lines in the agenda
  9454. referring to the same tree node, and the headline of the tree
  9455. node in the Org file.
  9456. Called with one universal prefix arg, show the priority instead
  9457. of setting it.
  9458. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9459. `down', or a character."
  9460. (interactive "P")
  9461. (unless org-priority-enable-commands
  9462. (user-error "Priority commands are disabled"))
  9463. (org-agenda-check-no-diary)
  9464. (let* ((col (current-column))
  9465. (hdmarker (org-get-at-bol 'org-hd-marker))
  9466. (buffer (marker-buffer hdmarker))
  9467. (pos (marker-position hdmarker))
  9468. (inhibit-read-only t)
  9469. newhead)
  9470. (org-with-remote-undo buffer
  9471. (with-current-buffer buffer
  9472. (widen)
  9473. (goto-char pos)
  9474. (org-fold-show-context 'agenda)
  9475. (org-priority force-direction)
  9476. (end-of-line 1)
  9477. (setq newhead (org-get-heading)))
  9478. (org-agenda-change-all-lines newhead hdmarker)
  9479. (org-move-to-column col))))
  9480. ;; FIXME: should fix the tags property of the agenda line.
  9481. (defun org-agenda-set-tags (&optional tag onoff)
  9482. "Set tags for the current headline."
  9483. (interactive)
  9484. (org-agenda-check-no-diary)
  9485. (if (and (org-region-active-p) (called-interactively-p 'any))
  9486. (call-interactively 'org-change-tag-in-region)
  9487. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9488. (org-agenda-error)))
  9489. (buffer (marker-buffer hdmarker))
  9490. (pos (marker-position hdmarker))
  9491. (inhibit-read-only t)
  9492. newhead)
  9493. (org-with-remote-undo buffer
  9494. (with-current-buffer buffer
  9495. (widen)
  9496. (goto-char pos)
  9497. (org-fold-show-context 'agenda)
  9498. (if tag
  9499. (org-toggle-tag tag onoff)
  9500. (call-interactively #'org-set-tags-command))
  9501. (end-of-line 1)
  9502. (setq newhead (org-get-heading)))
  9503. (org-agenda-change-all-lines newhead hdmarker)
  9504. (beginning-of-line 1)))))
  9505. (defun org-agenda-set-property ()
  9506. "Set a property for the current headline."
  9507. (interactive)
  9508. (org-agenda-check-no-diary)
  9509. (org-agenda-maybe-loop
  9510. #'org-agenda-set-property nil nil nil
  9511. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9512. (org-agenda-error)))
  9513. (buffer (marker-buffer hdmarker))
  9514. (pos (marker-position hdmarker))
  9515. (inhibit-read-only t)
  9516. ) ;; newhead
  9517. (org-with-remote-undo buffer
  9518. (with-current-buffer buffer
  9519. (widen)
  9520. (goto-char pos)
  9521. (org-fold-show-context 'agenda)
  9522. (call-interactively 'org-set-property))))))
  9523. (defun org-agenda-set-effort ()
  9524. "Set the effort property for the current headline."
  9525. (interactive)
  9526. (org-agenda-check-no-diary)
  9527. (org-agenda-maybe-loop
  9528. #'org-agenda-set-effort nil nil nil
  9529. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9530. (org-agenda-error)))
  9531. (buffer (marker-buffer hdmarker))
  9532. (pos (marker-position hdmarker))
  9533. (inhibit-read-only t)
  9534. newhead)
  9535. (org-with-remote-undo buffer
  9536. (with-current-buffer buffer
  9537. (widen)
  9538. (goto-char pos)
  9539. (org-fold-show-context 'agenda)
  9540. (call-interactively 'org-set-effort)
  9541. (end-of-line 1)
  9542. (setq newhead (org-get-heading)))
  9543. (org-agenda-change-all-lines newhead hdmarker)))))
  9544. (defun org-agenda-toggle-archive-tag ()
  9545. "Toggle the archive tag for the current entry."
  9546. (interactive)
  9547. (org-agenda-check-no-diary)
  9548. (org-agenda-maybe-loop
  9549. #'org-agenda-toggle-archive-tag nil nil nil
  9550. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9551. (org-agenda-error)))
  9552. (buffer (marker-buffer hdmarker))
  9553. (pos (marker-position hdmarker))
  9554. (inhibit-read-only t)
  9555. newhead)
  9556. (org-with-remote-undo buffer
  9557. (with-current-buffer buffer
  9558. (widen)
  9559. (goto-char pos)
  9560. (org-fold-show-context 'agenda)
  9561. (call-interactively 'org-toggle-archive-tag)
  9562. (end-of-line 1)
  9563. (setq newhead (org-get-heading)))
  9564. (org-agenda-change-all-lines newhead hdmarker)
  9565. (beginning-of-line 1)))))
  9566. (defun org-agenda-do-date-later (arg)
  9567. (interactive "P")
  9568. (cond
  9569. ((or (equal arg '(16))
  9570. (memq last-command
  9571. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9572. (setq this-command 'org-agenda-date-later-minutes)
  9573. (org-agenda-date-later-minutes 1))
  9574. ((or (equal arg '(4))
  9575. (memq last-command
  9576. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9577. (setq this-command 'org-agenda-date-later-hours)
  9578. (org-agenda-date-later-hours 1))
  9579. (t
  9580. (org-agenda-date-later (prefix-numeric-value arg)))))
  9581. (defun org-agenda-do-date-earlier (arg)
  9582. (interactive "P")
  9583. (cond
  9584. ((or (equal arg '(16))
  9585. (memq last-command
  9586. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9587. (setq this-command 'org-agenda-date-earlier-minutes)
  9588. (org-agenda-date-earlier-minutes 1))
  9589. ((or (equal arg '(4))
  9590. (memq last-command
  9591. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9592. (setq this-command 'org-agenda-date-earlier-hours)
  9593. (org-agenda-date-earlier-hours 1))
  9594. (t
  9595. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9596. (defun org-agenda-date-later (arg &optional what)
  9597. "Change the date of this item to ARG day(s) later."
  9598. (interactive "p")
  9599. (org-agenda-check-type t 'agenda)
  9600. (org-agenda-check-no-diary)
  9601. (let* ((marker (or (org-get-at-bol 'org-marker)
  9602. (org-agenda-error)))
  9603. (buffer (marker-buffer marker))
  9604. (pos (marker-position marker))
  9605. cdate today)
  9606. (org-with-remote-undo buffer
  9607. (with-current-buffer buffer
  9608. (widen)
  9609. (goto-char pos)
  9610. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9611. (when (and org-agenda-move-date-from-past-immediately-to-today
  9612. (equal arg 1)
  9613. (or (not what) (eq what 'day))
  9614. (not (save-match-data (org-at-date-range-p))))
  9615. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9616. cdate (calendar-absolute-from-gregorian
  9617. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9618. today (org-today))
  9619. (when (> today cdate)
  9620. ;; immediately shift to today
  9621. (setq arg (- today cdate))))
  9622. (org-timestamp-change arg (or what 'day))
  9623. (when (and (org-at-date-range-p)
  9624. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9625. (let ((end org-last-changed-timestamp))
  9626. (org-timestamp-change arg (or what 'day))
  9627. (setq org-last-changed-timestamp
  9628. (concat org-last-changed-timestamp "--" end)))))
  9629. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9630. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9631. (defun org-agenda-date-earlier (arg &optional what)
  9632. "Change the date of this item to ARG day(s) earlier."
  9633. (interactive "p")
  9634. (org-agenda-date-later (- arg) what))
  9635. (defun org-agenda-date-later-minutes (arg)
  9636. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9637. (interactive "p")
  9638. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9639. (org-agenda-date-later arg 'minute))
  9640. (defun org-agenda-date-earlier-minutes (arg)
  9641. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9642. (interactive "p")
  9643. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9644. (org-agenda-date-earlier arg 'minute))
  9645. (defun org-agenda-date-later-hours (arg)
  9646. "Change the time of this item, in hour steps."
  9647. (interactive "p")
  9648. (org-agenda-date-later arg 'hour))
  9649. (defun org-agenda-date-earlier-hours (arg)
  9650. "Change the time of this item, in hour steps."
  9651. (interactive "p")
  9652. (org-agenda-date-earlier arg 'hour))
  9653. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9654. "Show new date stamp via text properties."
  9655. ;; We use text properties to make this undoable
  9656. (let ((inhibit-read-only t))
  9657. (setq stamp (concat prefix " => " stamp " "))
  9658. (save-excursion
  9659. (goto-char (point-max))
  9660. (while (not (bobp))
  9661. (when (equal marker (org-get-at-bol 'org-marker))
  9662. (remove-text-properties (line-beginning-position)
  9663. (line-end-position)
  9664. '(display nil))
  9665. (org-move-to-column
  9666. (- (window-max-chars-per-line)
  9667. (length stamp))
  9668. t)
  9669. (add-text-properties
  9670. (1- (point)) (point-at-eol)
  9671. (list 'display (org-add-props stamp nil
  9672. 'face '(secondary-selection default))))
  9673. (beginning-of-line 1))
  9674. (beginning-of-line 0)))))
  9675. (defun org-agenda-date-prompt (arg)
  9676. "Change the date of this item. Date is prompted for, with default today.
  9677. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9678. be used to request time specification in the time stamp."
  9679. (interactive "P")
  9680. (org-agenda-check-type t 'agenda)
  9681. (org-agenda-check-no-diary)
  9682. (org-agenda-maybe-loop
  9683. #'org-agenda-date-prompt arg t nil
  9684. (let* ((marker (or (org-get-at-bol 'org-marker)
  9685. (org-agenda-error)))
  9686. (buffer (marker-buffer marker))
  9687. (pos (marker-position marker)))
  9688. (org-with-remote-undo buffer
  9689. (with-current-buffer buffer
  9690. (widen)
  9691. (goto-char pos)
  9692. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9693. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9694. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9695. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9696. (defun org-agenda-schedule (arg &optional time)
  9697. "Schedule the item at point.
  9698. ARG is passed through to `org-schedule'."
  9699. (interactive "P")
  9700. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9701. (org-agenda-check-no-diary)
  9702. (org-agenda-maybe-loop
  9703. #'org-agenda-schedule arg t nil
  9704. (let* ((marker (or (org-get-at-bol 'org-marker)
  9705. (org-agenda-error)))
  9706. ;; (type (marker-insertion-type marker))
  9707. (buffer (marker-buffer marker))
  9708. (pos (marker-position marker))
  9709. ts)
  9710. (set-marker-insertion-type marker t)
  9711. (org-with-remote-undo buffer
  9712. (with-current-buffer buffer
  9713. (widen)
  9714. (goto-char pos)
  9715. (setq ts (org-schedule arg time)))
  9716. (org-agenda-show-new-time marker ts " S"))
  9717. (message "%s" ts))))
  9718. (defun org-agenda-deadline (arg &optional time)
  9719. "Schedule the item at point.
  9720. ARG is passed through to `org-deadline'."
  9721. (interactive "P")
  9722. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9723. (org-agenda-check-no-diary)
  9724. (org-agenda-maybe-loop
  9725. #'org-agenda-deadline arg t nil
  9726. (let* ((marker (or (org-get-at-bol 'org-marker)
  9727. (org-agenda-error)))
  9728. (buffer (marker-buffer marker))
  9729. (pos (marker-position marker))
  9730. ts)
  9731. (org-with-remote-undo buffer
  9732. (with-current-buffer buffer
  9733. (widen)
  9734. (goto-char pos)
  9735. (setq ts (org-deadline arg time)))
  9736. (org-agenda-show-new-time marker ts " D"))
  9737. (message "%s" ts))))
  9738. (defun org-agenda-clock-in (&optional arg)
  9739. "Start the clock on the currently selected item."
  9740. (interactive "P")
  9741. (org-agenda-check-no-diary)
  9742. (if (equal arg '(4))
  9743. (org-clock-in arg)
  9744. (let* ((marker (or (org-get-at-bol 'org-marker)
  9745. (org-agenda-error)))
  9746. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9747. (pos (marker-position marker))
  9748. (col (current-column))
  9749. newhead)
  9750. (org-with-remote-undo (marker-buffer marker)
  9751. (with-current-buffer (marker-buffer marker)
  9752. (widen)
  9753. (goto-char pos)
  9754. (org-fold-show-context 'agenda)
  9755. (org-clock-in arg)
  9756. (setq newhead (org-get-heading)))
  9757. (org-agenda-change-all-lines newhead hdmarker))
  9758. (org-move-to-column col))))
  9759. (defun org-agenda-clock-out ()
  9760. "Stop the currently running clock."
  9761. (interactive)
  9762. (unless (marker-buffer org-clock-marker)
  9763. (user-error "No running clock"))
  9764. (let ((marker (make-marker)) (col (current-column)) newhead)
  9765. (org-with-remote-undo (marker-buffer org-clock-marker)
  9766. (with-current-buffer (marker-buffer org-clock-marker)
  9767. (org-with-wide-buffer
  9768. (goto-char org-clock-marker)
  9769. (org-back-to-heading t)
  9770. (move-marker marker (point))
  9771. (org-clock-out)
  9772. (setq newhead (org-get-heading)))))
  9773. (org-agenda-change-all-lines newhead marker)
  9774. (move-marker marker nil)
  9775. (org-move-to-column col)
  9776. (org-agenda-unmark-clocking-task)))
  9777. (defun org-agenda-clock-cancel (&optional _arg)
  9778. "Cancel the currently running clock."
  9779. (interactive) ;; "P"
  9780. (unless (marker-buffer org-clock-marker)
  9781. (user-error "No running clock"))
  9782. (org-with-remote-undo (marker-buffer org-clock-marker)
  9783. (org-clock-cancel)))
  9784. (defun org-agenda-clock-goto ()
  9785. "Jump to the currently clocked in task within the agenda.
  9786. If the currently clocked in task is not listed in the agenda
  9787. buffer, display it in another window."
  9788. (interactive)
  9789. (let (pos)
  9790. (mapc (lambda (o)
  9791. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9792. (setq pos (overlay-start o))))
  9793. (overlays-in (point-min) (point-max)))
  9794. (cond (pos (goto-char pos))
  9795. ;; If the currently clocked entry is not in the agenda
  9796. ;; buffer, we visit it in another window:
  9797. ((bound-and-true-p org-clock-current-task)
  9798. (org-switch-to-buffer-other-window (org-clock-goto)))
  9799. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9800. (defun org-agenda-diary-entry-in-org-file ()
  9801. "Make a diary entry in the file `org-agenda-diary-file'."
  9802. (let (d1 d2 char (text "") dp1 dp2)
  9803. (if (equal (buffer-name) "*Calendar*")
  9804. (setq d1 (calendar-cursor-to-date t)
  9805. d2 (car calendar-mark-ring))
  9806. (setq dp1 (get-text-property (point-at-bol) 'day))
  9807. (unless dp1 (user-error "No date defined in current line"))
  9808. (setq d1 (calendar-gregorian-from-absolute dp1)
  9809. d2 (and (ignore-errors (mark))
  9810. (save-excursion
  9811. (goto-char (mark))
  9812. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9813. (calendar-gregorian-from-absolute dp2))))
  9814. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9815. (setq char (read-char-exclusive))
  9816. (cond
  9817. ((equal char ?d)
  9818. (setq text (read-string "Day entry: "))
  9819. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9820. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9821. ((equal char ?a)
  9822. (setq d1 (list (car d1) (nth 1 d1)
  9823. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9824. (nth 2 d1))))
  9825. (setq text (read-string "Anniversary (use %d to show years): "))
  9826. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9827. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9828. ((equal char ?b)
  9829. (setq text (read-string "Block entry: "))
  9830. (unless (and d1 d2 (not (equal d1 d2)))
  9831. (user-error "No block of days selected"))
  9832. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9833. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9834. ((equal char ?j)
  9835. (org-switch-to-buffer-other-window
  9836. (find-file-noselect org-agenda-diary-file))
  9837. (require 'org-datetree)
  9838. (org-datetree-find-date-create d1)
  9839. (org-fold-reveal t))
  9840. (t (user-error "Invalid selection character `%c'" char)))))
  9841. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9842. "Where in `org-agenda-diary-file' should new entries be added?
  9843. Valid values:
  9844. date-tree in the date tree, as first child of the date
  9845. date-tree-last in the date tree, as last child of the date
  9846. top-level as top-level entries at the end of the file."
  9847. :group 'org-agenda
  9848. :type '(choice
  9849. (const :tag "first in a date tree" date-tree)
  9850. (const :tag "last in a date tree" date-tree-last)
  9851. (const :tag "as top level at end of file" top-level)))
  9852. (defcustom org-agenda-insert-diary-extract-time nil
  9853. "Non-nil means extract any time specification from the diary entry."
  9854. :group 'org-agenda
  9855. :version "24.1"
  9856. :type 'boolean)
  9857. (defcustom org-agenda-bulk-mark-char ">"
  9858. "A single-character string to be used as the bulk mark."
  9859. :group 'org-agenda
  9860. :version "24.1"
  9861. :type 'string)
  9862. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9863. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9864. If TEXT is not empty, it will become the headline of the new entry, and
  9865. the resulting entry will not be shown. When TEXT is empty, switch to
  9866. `org-agenda-diary-file' and let the user finish the entry there."
  9867. (let ((cw (current-window-configuration)))
  9868. (org-switch-to-buffer-other-window
  9869. (find-file-noselect org-agenda-diary-file))
  9870. (widen)
  9871. (goto-char (point-min))
  9872. (cl-case type
  9873. (anniversary
  9874. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9875. (progn
  9876. (or (org-at-heading-p)
  9877. (progn
  9878. (outline-next-heading)
  9879. (insert "* Anniversaries\n\n")
  9880. (beginning-of-line -1)))))
  9881. (outline-next-heading)
  9882. (org-back-over-empty-lines)
  9883. (backward-char 1)
  9884. (insert "\n")
  9885. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9886. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9887. (day
  9888. (let ((org-prefix-has-time t)
  9889. (org-agenda-time-leading-zero t)
  9890. fmt time time2)
  9891. (when org-agenda-insert-diary-extract-time
  9892. ;; Use org-agenda-format-item to parse text for a time-range and
  9893. ;; remove it. FIXME: This is a hack, we should refactor
  9894. ;; that function to make time extraction available separately
  9895. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9896. time (get-text-property 0 'time fmt)
  9897. time2 (if (> (length time) 0)
  9898. ;; split-string removes trailing ...... if
  9899. ;; no end time given. First space
  9900. ;; separates time from date.
  9901. (concat " " (car (split-string time "\\.")))
  9902. nil)
  9903. text (get-text-property 0 'txt fmt)))
  9904. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9905. (org-agenda-insert-diary-as-top-level text)
  9906. (require 'org-datetree)
  9907. (org-datetree-find-date-create d1)
  9908. (org-agenda-insert-diary-make-new-entry text))
  9909. (org-insert-time-stamp (org-time-from-absolute
  9910. (calendar-absolute-from-gregorian d1))
  9911. nil nil nil nil time2))
  9912. (end-of-line 0))
  9913. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9914. ;; otherwise the indentation gets confused by the
  9915. ;; special meaning of 'block
  9916. (when (> (calendar-absolute-from-gregorian d1)
  9917. (calendar-absolute-from-gregorian d2))
  9918. (setq d1 (prog1 d2 (setq d2 d1))))
  9919. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9920. (org-agenda-insert-diary-as-top-level text)
  9921. (require 'org-datetree)
  9922. (org-datetree-find-date-create d1)
  9923. (org-agenda-insert-diary-make-new-entry text))
  9924. (org-insert-time-stamp (org-time-from-absolute
  9925. (calendar-absolute-from-gregorian d1)))
  9926. (insert "--")
  9927. (org-insert-time-stamp (org-time-from-absolute
  9928. (calendar-absolute-from-gregorian d2)))
  9929. (end-of-line 0)))
  9930. (if (string-match "\\S-" text)
  9931. (progn
  9932. (set-window-configuration cw)
  9933. (message "%s entry added to %s"
  9934. (capitalize (symbol-name type))
  9935. (abbreviate-file-name org-agenda-diary-file)))
  9936. (org-fold-reveal t)
  9937. (message "Please finish entry here"))))
  9938. (defun org-agenda-insert-diary-as-top-level (text)
  9939. "Make new entry as a top-level entry at the end of the file.
  9940. Add TEXT as headline, and position the cursor in the second line so that
  9941. a timestamp can be added there."
  9942. (widen)
  9943. (goto-char (point-max))
  9944. (unless (bolp) (insert "\n"))
  9945. (org-insert-heading nil t t)
  9946. (insert text)
  9947. (org-end-of-meta-data)
  9948. (unless (bolp) (insert "\n"))
  9949. (when org-adapt-indentation (indent-to-column 2)))
  9950. (defun org-agenda-insert-diary-make-new-entry (text)
  9951. "Make a new entry with TEXT as a child of the current subtree.
  9952. Position the point in the heading's first body line so that
  9953. a timestamp can be added there."
  9954. (cond
  9955. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9956. (end-of-line)
  9957. (org-insert-heading '(4) t)
  9958. (org-do-demote))
  9959. (t
  9960. (outline-next-heading)
  9961. (org-back-over-empty-lines)
  9962. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9963. (org-insert-heading nil t)
  9964. (org-do-demote)))
  9965. (let ((col (current-column)))
  9966. (insert text)
  9967. (org-end-of-meta-data)
  9968. ;; Ensure point is left on a blank line, at proper indentation.
  9969. (unless (bolp) (insert "\n"))
  9970. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9971. (when org-adapt-indentation (indent-to-column col)))
  9972. (org-fold-show-set-visibility 'lineage))
  9973. (defun org-agenda-diary-entry ()
  9974. "Make a diary entry, like the `i' command from the calendar.
  9975. All the standard commands work: block, weekly etc.
  9976. When `org-agenda-diary-file' points to a file,
  9977. `org-agenda-diary-entry-in-org-file' is called instead to create
  9978. entries in that Org file."
  9979. (interactive)
  9980. (if (not (eq org-agenda-diary-file 'diary-file))
  9981. (org-agenda-diary-entry-in-org-file)
  9982. (require 'diary-lib)
  9983. (let* ((char (read-char-exclusive
  9984. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9985. [a]nniversary [b]lock [c]yclic"))
  9986. (cmd (cdr (assoc char
  9987. '((?d . diary-insert-entry)
  9988. (?w . diary-insert-weekly-entry)
  9989. (?m . diary-insert-monthly-entry)
  9990. (?y . diary-insert-yearly-entry)
  9991. (?a . diary-insert-anniversary-entry)
  9992. (?b . diary-insert-block-entry)
  9993. (?c . diary-insert-cyclic-entry)))))
  9994. (oldf (symbol-function 'calendar-cursor-to-date))
  9995. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9996. (point (point))
  9997. (mark (or (mark t) (point))))
  9998. (unless cmd
  9999. (user-error "No command associated with <%c>" char))
  10000. (unless (and (get-text-property point 'day)
  10001. (or (not (equal ?b char))
  10002. (get-text-property mark 'day)))
  10003. (user-error "Don't know which date to use for diary entry"))
  10004. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10005. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10006. (let ((calendar-mark-ring
  10007. (list (calendar-gregorian-from-absolute
  10008. (or (get-text-property mark 'day)
  10009. (get-text-property point 'day))))))
  10010. (unwind-protect
  10011. (progn
  10012. (fset 'calendar-cursor-to-date
  10013. (lambda (&optional _error _dummy)
  10014. (calendar-gregorian-from-absolute
  10015. (get-text-property point 'day))))
  10016. (call-interactively cmd))
  10017. (fset 'calendar-cursor-to-date oldf))))))
  10018. (defun org-agenda-execute-calendar-command (cmd)
  10019. "Execute a calendar command from the agenda with date from cursor."
  10020. (org-agenda-check-type t 'agenda)
  10021. (require 'diary-lib)
  10022. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10023. (user-error "Don't know which date to use for the calendar command"))
  10024. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10025. (point (point))
  10026. (date (calendar-gregorian-from-absolute
  10027. (get-text-property point 'day))))
  10028. ;; the following 2 vars are needed in the calendar
  10029. (org-dlet
  10030. ((displayed-month (car date))
  10031. (displayed-year (nth 2 date)))
  10032. (unwind-protect
  10033. (progn
  10034. (fset 'calendar-cursor-to-date
  10035. (lambda (&optional _error _dummy)
  10036. (calendar-gregorian-from-absolute
  10037. (get-text-property point 'day))))
  10038. (call-interactively cmd))
  10039. (fset 'calendar-cursor-to-date oldf)))))
  10040. (defun org-agenda-phases-of-moon ()
  10041. "Display the phases of the moon for the 3 months around the cursor date."
  10042. (interactive)
  10043. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10044. (defun org-agenda-holidays ()
  10045. "Display the holidays for the 3 months around the cursor date."
  10046. (interactive)
  10047. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10048. (defvar calendar-longitude) ; defined in calendar.el
  10049. (defvar calendar-latitude) ; defined in calendar.el
  10050. (defvar calendar-location-name) ; defined in calendar.el
  10051. (defun org-agenda-sunrise-sunset (arg)
  10052. "Display sunrise and sunset for the cursor date.
  10053. Latitude and longitude can be specified with the variables
  10054. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10055. argument, latitude and longitude will be prompted for."
  10056. (interactive "P")
  10057. (require 'solar)
  10058. (let ((calendar-longitude (if arg nil calendar-longitude))
  10059. (calendar-latitude (if arg nil calendar-latitude))
  10060. (calendar-location-name
  10061. (if arg "the given coordinates" calendar-location-name)))
  10062. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10063. (defun org-agenda-goto-calendar ()
  10064. "Open the Emacs calendar with the date at the cursor."
  10065. (interactive)
  10066. (org-agenda-check-type t 'agenda)
  10067. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10068. (user-error "Don't know which date to open in calendar")))
  10069. (date (calendar-gregorian-from-absolute day))
  10070. (calendar-move-hook nil)
  10071. (calendar-view-holidays-initially-flag nil)
  10072. (calendar-view-diary-initially-flag nil))
  10073. (calendar)
  10074. (calendar-goto-date date)))
  10075. ;;;###autoload
  10076. (defun org-calendar-goto-agenda ()
  10077. "Compute the Org agenda for the calendar date displayed at the cursor.
  10078. This is a command that has to be installed in `calendar-mode-map'."
  10079. (interactive)
  10080. ;; Temporarily disable sticky agenda since user clearly wants to
  10081. ;; refresh view anyway.
  10082. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10083. (org-agenda-sticky nil))
  10084. (org-agenda-list nil (calendar-absolute-from-gregorian
  10085. (calendar-cursor-to-date))
  10086. nil)))
  10087. (defun org-agenda-convert-date ()
  10088. (interactive)
  10089. (org-agenda-check-type t 'agenda)
  10090. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10091. date s)
  10092. (unless day
  10093. (user-error "Don't know which date to convert"))
  10094. (setq date (calendar-gregorian-from-absolute day))
  10095. (setq s (concat
  10096. "Gregorian: " (calendar-date-string date) "\n"
  10097. "ISO: " (calendar-iso-date-string date) "\n"
  10098. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10099. "Julian: " (calendar-julian-date-string date) "\n"
  10100. "Astron. JD: " (calendar-astro-date-string date)
  10101. " (Julian date number at noon UTC)\n"
  10102. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10103. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10104. "French: " (calendar-french-date-string date) "\n"
  10105. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10106. "Mayan: " (calendar-mayan-date-string date) "\n"
  10107. "Coptic: " (calendar-coptic-date-string date) "\n"
  10108. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10109. "Persian: " (calendar-persian-date-string date) "\n"
  10110. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10111. (with-output-to-temp-buffer "*Dates*"
  10112. (princ s))
  10113. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10114. ;;; Bulk commands
  10115. (defun org-agenda-bulk-marked-p ()
  10116. "Non-nil when current entry is marked for bulk action."
  10117. (eq (get-char-property (point-at-bol) 'type)
  10118. 'org-marked-entry-overlay))
  10119. (defun org-agenda-bulk-mark (&optional arg)
  10120. "Mark entries for future bulk action.
  10121. When ARG is nil or one and region is not active then mark the
  10122. entry at point.
  10123. When ARG is nil or one and region is active then mark the entries
  10124. in the region.
  10125. When ARG is greater than one mark ARG lines."
  10126. (interactive "p")
  10127. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10128. (setq arg (count-lines (region-beginning) (region-end)))
  10129. (goto-char (region-beginning))
  10130. (deactivate-mark))
  10131. (dotimes (_ (or arg 1))
  10132. (unless (org-get-at-bol 'org-agenda-diary-link)
  10133. (let* ((m (org-get-at-bol 'org-hd-marker))
  10134. ov)
  10135. (unless (org-agenda-bulk-marked-p)
  10136. (unless m (user-error "Nothing to mark at point"))
  10137. (push m org-agenda-bulk-marked-entries)
  10138. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10139. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10140. (org-get-todo-face "TODO")
  10141. 'evaporate)
  10142. (overlay-put ov 'type 'org-marked-entry-overlay))
  10143. (end-of-line 1)
  10144. (or (ignore-errors
  10145. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10146. (beginning-of-line 2))
  10147. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10148. (beginning-of-line 2)))))
  10149. (message "%d entries marked for bulk action"
  10150. (length org-agenda-bulk-marked-entries)))
  10151. (defun org-agenda-bulk-mark-all ()
  10152. "Mark all entries for future agenda bulk action."
  10153. (interactive)
  10154. (org-agenda-bulk-mark-regexp "."))
  10155. (defun org-agenda-bulk-mark-regexp (regexp)
  10156. "Mark entries matching REGEXP for future agenda bulk action."
  10157. (interactive "sMark entries matching regexp: ")
  10158. (let ((entries-marked 0) txt-at-point)
  10159. (save-excursion
  10160. (goto-char (point-min))
  10161. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10162. (while (and (re-search-forward regexp nil t)
  10163. (setq txt-at-point
  10164. (get-text-property (match-beginning 0) 'txt)))
  10165. (if (get-char-property (point) 'invisible)
  10166. (beginning-of-line 2)
  10167. (when (string-match-p regexp txt-at-point)
  10168. (setq entries-marked (1+ entries-marked))
  10169. (call-interactively 'org-agenda-bulk-mark)))))
  10170. (unless entries-marked
  10171. (message "No entry matching this regexp."))))
  10172. (defun org-agenda-bulk-unmark (&optional arg)
  10173. "Unmark the entry at point for future bulk action."
  10174. (interactive "P")
  10175. (if arg
  10176. (org-agenda-bulk-unmark-all)
  10177. (cond ((org-agenda-bulk-marked-p)
  10178. (org-agenda-bulk-remove-overlays
  10179. (point-at-bol) (+ 2 (point-at-bol)))
  10180. (setq org-agenda-bulk-marked-entries
  10181. (delete (org-get-at-bol 'org-hd-marker)
  10182. org-agenda-bulk-marked-entries))
  10183. (end-of-line 1)
  10184. (or (ignore-errors
  10185. (goto-char (next-single-property-change (point) 'txt)))
  10186. (beginning-of-line 2))
  10187. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10188. (beginning-of-line 2))
  10189. (message "%d entries left marked for bulk action"
  10190. (length org-agenda-bulk-marked-entries)))
  10191. (t (message "No entry to unmark here")))))
  10192. (defun org-agenda-bulk-toggle-all ()
  10193. "Toggle all marks for bulk action."
  10194. (interactive)
  10195. (save-excursion
  10196. (goto-char (point-min))
  10197. (while (ignore-errors
  10198. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10199. (org-agenda-bulk-toggle))))
  10200. (defun org-agenda-bulk-toggle ()
  10201. "Toggle the mark at point for bulk action."
  10202. (interactive)
  10203. (if (org-agenda-bulk-marked-p)
  10204. (org-agenda-bulk-unmark)
  10205. (org-agenda-bulk-mark)))
  10206. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10207. "Remove the mark overlays between BEG and END in the agenda buffer.
  10208. BEG and END default to the buffer limits.
  10209. This only removes the overlays, it does not remove the markers
  10210. from the list in `org-agenda-bulk-marked-entries'."
  10211. (interactive)
  10212. (mapc (lambda (ov)
  10213. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10214. (delete-overlay ov)))
  10215. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10216. (defun org-agenda-bulk-unmark-all ()
  10217. "Remove all marks in the agenda buffer.
  10218. This will remove the markers and the overlays."
  10219. (interactive)
  10220. (if (null org-agenda-bulk-marked-entries)
  10221. (message "No entry to unmark")
  10222. (setq org-agenda-bulk-marked-entries nil)
  10223. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10224. (defcustom org-agenda-persistent-marks nil
  10225. "Non-nil means marked items will stay marked after a bulk action.
  10226. You can toggle this interactively by typing `p' when prompted for a
  10227. bulk action."
  10228. :group 'org-agenda
  10229. :version "24.1"
  10230. :type 'boolean)
  10231. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10232. "Shall some commands act upon headlines in the active region?
  10233. When set to t, some commands will be performed in all headlines
  10234. within the active region.
  10235. When set to `start-level', some commands will be performed in all
  10236. headlines within the active region, provided that these headlines
  10237. are of the same level than the first one.
  10238. When set to a regular expression, those commands will be
  10239. performed on the matching headlines within the active region.
  10240. The list of commands is: `org-agenda-schedule',
  10241. `org-agenda-deadline', `org-agenda-date-prompt',
  10242. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10243. See `org-loop-over-headlines-in-active-region' for the equivalent
  10244. option for Org buffers."
  10245. :type '(choice (const :tag "Don't loop" nil)
  10246. (const :tag "All headlines in active region" t)
  10247. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10248. (regexp :tag "Regular expression matcher"))
  10249. :version "27.1"
  10250. :package-version '(Org . "9.4")
  10251. :group 'org-agenda)
  10252. (defun org-agenda-bulk-action (&optional arg)
  10253. "Execute an remote-editing action on all marked entries.
  10254. The prefix arg is passed through to the command if possible."
  10255. (interactive "P")
  10256. ;; When there is no mark, act on the agenda entry at point.
  10257. (if (not org-agenda-bulk-marked-entries)
  10258. (save-excursion (org-agenda-bulk-mark)))
  10259. (dolist (m org-agenda-bulk-marked-entries)
  10260. (unless (and (markerp m)
  10261. (marker-buffer m)
  10262. (buffer-live-p (marker-buffer m))
  10263. (marker-position m))
  10264. (user-error "Marker %s for bulk command is invalid" m)))
  10265. ;; Prompt for the bulk command.
  10266. (org-unlogged-message
  10267. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10268. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10269. "[S]catter [f]unction "
  10270. (and org-agenda-bulk-custom-functions
  10271. (format " Custom: [%s]"
  10272. (mapconcat (lambda (f) (char-to-string (car f)))
  10273. org-agenda-bulk-custom-functions
  10274. "")))))
  10275. (catch 'exit
  10276. (let* ((org-log-refile (if org-log-refile 'time nil))
  10277. (entries (reverse org-agenda-bulk-marked-entries))
  10278. (org-overriding-default-time
  10279. (and (get-text-property (point) 'org-agenda-date-header)
  10280. (org-get-cursor-date)))
  10281. redo-at-end
  10282. cmd)
  10283. (pcase (read-char-exclusive)
  10284. (?p
  10285. (let ((org-agenda-persistent-marks
  10286. (not org-agenda-persistent-marks)))
  10287. (org-agenda-bulk-action)
  10288. (throw 'exit nil)))
  10289. (?$
  10290. (setq cmd #'org-agenda-archive))
  10291. (?A
  10292. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10293. ((or ?r ?w)
  10294. (let ((refile-location
  10295. (org-refile-get-location
  10296. "Refile to"
  10297. (marker-buffer (car entries))
  10298. org-refile-allow-creating-parent-nodes)))
  10299. (when (nth 3 refile-location)
  10300. (setcar (nthcdr 3 refile-location)
  10301. (move-marker
  10302. (make-marker)
  10303. (nth 3 refile-location)
  10304. (or (get-file-buffer (nth 1 refile-location))
  10305. (find-buffer-visiting (nth 1 refile-location))
  10306. (error "This should not happen")))))
  10307. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10308. (setq redo-at-end t)))
  10309. (?t
  10310. (let ((state (completing-read
  10311. "Todo state: "
  10312. (with-current-buffer (marker-buffer (car entries))
  10313. (mapcar #'list org-todo-keywords-1)))))
  10314. (setq cmd (lambda ()
  10315. (let ((org-inhibit-blocking t)
  10316. (org-inhibit-logging 'note))
  10317. (org-agenda-todo state))))))
  10318. ((and (or ?- ?+) action)
  10319. (let ((tag (completing-read
  10320. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10321. (with-current-buffer (marker-buffer (car entries))
  10322. (delq nil
  10323. (mapcar (lambda (x) (and (stringp (car x)) x))
  10324. org-current-tag-alist))))))
  10325. (setq cmd
  10326. (lambda ()
  10327. (org-agenda-set-tags tag
  10328. (if (eq action ?+) 'on 'off))))))
  10329. ((and (or ?s ?d) c)
  10330. (let* ((schedule? (eq c ?s))
  10331. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10332. (time
  10333. (and (not arg)
  10334. (let ((new (org-read-date
  10335. nil nil nil prompt org-overriding-default-time)))
  10336. ;; A "double plus" answer applies to every
  10337. ;; scheduled time. Do not turn it into
  10338. ;; a fixed date yet.
  10339. (if (string-match-p "\\`[ \t]*\\+\\+"
  10340. org-read-date-final-answer)
  10341. org-read-date-final-answer
  10342. new)))))
  10343. ;; Make sure to not prompt for a note when bulk
  10344. ;; rescheduling/resetting deadline as Org cannot cope with
  10345. ;; simultaneous notes. Besides, it could be annoying
  10346. ;; depending on the number of marked items.
  10347. (setq cmd
  10348. (if schedule?
  10349. (lambda ()
  10350. (let ((org-log-reschedule
  10351. (and org-log-reschedule 'time)))
  10352. (org-agenda-schedule arg time)))
  10353. (lambda ()
  10354. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10355. (org-agenda-deadline arg time)))))))
  10356. (?S
  10357. (unless (org-agenda-check-type nil 'agenda 'todo)
  10358. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10359. (let ((days (read-number
  10360. (format "Scatter tasks across how many %sdays: "
  10361. (if arg "week" ""))
  10362. 7)))
  10363. (setq cmd
  10364. (lambda ()
  10365. (let ((distance (1+ (random days))))
  10366. (when arg
  10367. (let ((dist distance)
  10368. (day-of-week
  10369. (calendar-day-of-week
  10370. (calendar-gregorian-from-absolute (org-today)))))
  10371. (dotimes (_ (1+ dist))
  10372. (while (member day-of-week org-agenda-weekend-days)
  10373. (cl-incf distance)
  10374. (cl-incf day-of-week)
  10375. (when (= day-of-week 7)
  10376. (setq day-of-week 0)))
  10377. (cl-incf day-of-week)
  10378. (when (= day-of-week 7)
  10379. (setq day-of-week 0)))))
  10380. ;; Silently fail when try to replan a sexp entry.
  10381. (ignore-errors
  10382. (let* ((date (calendar-gregorian-from-absolute
  10383. (+ (org-today) distance)))
  10384. (time (org-encode-time
  10385. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10386. (org-agenda-schedule nil time))))))))
  10387. (?f
  10388. (setq cmd
  10389. (intern
  10390. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10391. (action
  10392. (setq cmd
  10393. (pcase (assoc action org-agenda-bulk-custom-functions)
  10394. (`(,_ ,fn)
  10395. fn)
  10396. (`(,_ ,fn ,arg-fn)
  10397. (apply #'apply-partially fn (funcall arg-fn)))
  10398. (_
  10399. (user-error "Invalid bulk action: %c" action))))
  10400. (setq redo-at-end t)))
  10401. ;; Sort the markers, to make sure that parents are handled
  10402. ;; before children.
  10403. (setq entries (sort entries
  10404. (lambda (a b)
  10405. (cond
  10406. ((eq (marker-buffer a) (marker-buffer b))
  10407. (< (marker-position a) (marker-position b)))
  10408. (t
  10409. (string< (buffer-name (marker-buffer a))
  10410. (buffer-name (marker-buffer b))))))))
  10411. ;; Now loop over all markers and apply CMD.
  10412. (let ((processed 0)
  10413. (skipped 0))
  10414. (dolist (e entries)
  10415. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10416. (if (not pos)
  10417. (progn (message "Skipping removed entry at %s" e)
  10418. (cl-incf skipped))
  10419. (goto-char pos)
  10420. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10421. ;; `post-command-hook' is not run yet. We make sure any
  10422. ;; pending log note is processed.
  10423. (when org-log-setup (org-add-log-note))
  10424. (cl-incf processed))))
  10425. (when redo-at-end (org-agenda-redo))
  10426. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10427. (message "Acted on %d entries%s%s"
  10428. processed
  10429. (if (= skipped 0)
  10430. ""
  10431. (format ", skipped %d (disappeared before their turn)"
  10432. skipped))
  10433. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10434. (defun org-agenda-capture (&optional with-time)
  10435. "Call `org-capture' with the date at point.
  10436. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10437. current HH:MM time."
  10438. (interactive "P")
  10439. (if (not (eq major-mode 'org-agenda-mode))
  10440. (user-error "You cannot do this outside of agenda buffers")
  10441. (let ((org-overriding-default-time
  10442. (org-get-cursor-date (equal with-time 1))))
  10443. (call-interactively 'org-capture))))
  10444. ;;; Dragging agenda lines forward/backward
  10445. (defun org-agenda-reapply-filters ()
  10446. "Re-apply all agenda filters."
  10447. (mapcar
  10448. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10449. `((,org-agenda-tag-filter tag)
  10450. (,org-agenda-category-filter category)
  10451. (,org-agenda-regexp-filter regexp)
  10452. (,org-agenda-effort-filter effort)
  10453. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10454. (,(get 'org-agenda-category-filter :preset-filter) category)
  10455. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10456. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10457. (defun org-agenda-drag-line-forward (arg &optional backward)
  10458. "Drag an agenda line forward by ARG lines.
  10459. When the optional argument `backward' is non-nil, move backward."
  10460. (interactive "p")
  10461. (let ((inhibit-read-only t) lst line)
  10462. (if (or (not (get-text-property (point) 'txt))
  10463. (save-excursion
  10464. (dotimes (_ arg)
  10465. (move-beginning-of-line (if backward 0 2))
  10466. (push (not (get-text-property (point) 'txt)) lst))
  10467. (delq nil lst)))
  10468. (message "Cannot move line forward")
  10469. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10470. (move-beginning-of-line 1)
  10471. (setq line (buffer-substring (point) end))
  10472. (delete-region (point) end)
  10473. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10474. (insert line)
  10475. (org-agenda-reapply-filters)
  10476. (org-agenda-mark-clocking-task)
  10477. (move-beginning-of-line 0)))))
  10478. (defun org-agenda-drag-line-backward (arg)
  10479. "Drag an agenda line backward by ARG lines."
  10480. (interactive "p")
  10481. (org-agenda-drag-line-forward arg t))
  10482. ;;; Flagging notes
  10483. (defun org-agenda-show-the-flagging-note ()
  10484. "Display the flagging note in the other window.
  10485. When called a second time in direct sequence, offer to remove the FLAGGING
  10486. tag and (if present) the flagging note."
  10487. (interactive)
  10488. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10489. (win (selected-window))
  10490. note) ;; heading newhead
  10491. (unless hdmarker
  10492. (user-error "No linked entry at point"))
  10493. (if (and (eq this-command last-command)
  10494. (y-or-n-p "Unflag and remove any flagging note? "))
  10495. (progn
  10496. (org-agenda-remove-flag hdmarker)
  10497. (let ((win (get-buffer-window "*Flagging Note*")))
  10498. (and win (delete-window win)))
  10499. (message "Entry unflagged"))
  10500. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10501. (unless note
  10502. (user-error "No flagging note"))
  10503. (org-kill-new note)
  10504. (org-switch-to-buffer-other-window "*Flagging Note*")
  10505. (erase-buffer)
  10506. (insert note)
  10507. (goto-char (point-min))
  10508. (while (re-search-forward "\\\\n" nil t)
  10509. (replace-match "\n" t t))
  10510. (goto-char (point-min))
  10511. (select-window win)
  10512. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10513. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10514. tag and note")))))
  10515. (defun org-agenda-remove-flag (marker)
  10516. "Remove the FLAGGED tag and any flagging note in the entry."
  10517. (let ((newhead
  10518. (org-with-point-at marker
  10519. (org-toggle-tag "FLAGGED" 'off)
  10520. (org-entry-delete nil "THEFLAGGINGNOTE")
  10521. (org-get-heading))))
  10522. (org-agenda-change-all-lines newhead marker)
  10523. (message "Entry unflagged")))
  10524. (defun org-agenda-get-any-marker (&optional pos)
  10525. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10526. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10527. ;;; Appointment reminders
  10528. (defvar appt-time-msg-list) ; defined in appt.el
  10529. ;;;###autoload
  10530. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10531. "Activate appointments found in `org-agenda-files'.
  10532. With a `\\[universal-argument]' prefix, refresh the list of \
  10533. appointments.
  10534. If FILTER is t, interactively prompt the user for a regular
  10535. expression, and filter out entries that don't match it.
  10536. If FILTER is a string, use this string as a regular expression
  10537. for filtering entries out.
  10538. If FILTER is a function, filter out entries against which
  10539. calling the function returns nil. This function takes one
  10540. argument: an entry from `org-agenda-get-day-entries'.
  10541. FILTER can also be an alist with the car of each cell being
  10542. either `headline' or `category'. For example:
  10543. \\='((headline \"IMPORTANT\")
  10544. (category \"Work\"))
  10545. will only add headlines containing IMPORTANT or headlines
  10546. belonging to the \"Work\" category.
  10547. ARGS are symbols indicating what kind of entries to consider.
  10548. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10549. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10550. and :timestamp entries. See the docstring of `org-diary' for
  10551. details and examples.
  10552. If an entry has a APPT_WARNTIME property, its value will be used
  10553. to override `appt-message-warning-time'."
  10554. (interactive "P")
  10555. (when refresh (setq appt-time-msg-list nil))
  10556. (when (eq filter t)
  10557. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10558. (let* ((cnt 0) ; count added events
  10559. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10560. (org-agenda-new-buffers nil)
  10561. (org-deadline-warning-days 0)
  10562. ;; Do not use `org-today' here because appt only takes
  10563. ;; time and without date as argument, so it may pass wrong
  10564. ;; information otherwise
  10565. (today (org-date-to-gregorian
  10566. (time-to-days nil)))
  10567. (org-agenda-restrict nil)
  10568. (files (org-agenda-files 'unrestricted)) entries file
  10569. (org-agenda-buffer nil))
  10570. ;; Get all entries which may contain an appt
  10571. (org-agenda-prepare-buffers files)
  10572. (while (setq file (pop files))
  10573. (setq entries
  10574. (delq nil
  10575. (append entries
  10576. (apply #'org-agenda-get-day-entries
  10577. file today scope)))))
  10578. ;; Map through entries and find if we should filter them out
  10579. (mapc
  10580. (lambda (x)
  10581. (let* ((evt (org-trim
  10582. (replace-regexp-in-string
  10583. org-link-bracket-re "\\2"
  10584. (or (get-text-property 1 'txt x) ""))))
  10585. (cat (get-text-property (1- (length x)) 'org-category x))
  10586. (tod (get-text-property 1 'time-of-day x))
  10587. (ok (or (null filter)
  10588. (and (stringp filter) (string-match filter evt))
  10589. (and (functionp filter) (funcall filter x))
  10590. (and (listp filter)
  10591. (let ((cat-filter (cadr (assq 'category filter)))
  10592. (evt-filter (cadr (assq 'headline filter))))
  10593. (or (and (stringp cat-filter)
  10594. (string-match cat-filter cat))
  10595. (and (stringp evt-filter)
  10596. (string-match evt-filter evt)))))))
  10597. (wrn (get-text-property 1 'warntime x)))
  10598. ;; FIXME: Shall we remove text-properties for the appt text?
  10599. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10600. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10601. (setq tod (concat "00" (number-to-string tod)))
  10602. (setq tod (when (string-match
  10603. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10604. (concat (match-string 1 tod) ":"
  10605. (match-string 2 tod))))
  10606. (when (appt-add tod evt wrn)
  10607. (setq cnt (1+ cnt))))))
  10608. entries)
  10609. (org-release-buffers org-agenda-new-buffers)
  10610. (if (eq cnt 0)
  10611. (message "No event to add")
  10612. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10613. (defun org-agenda-today-p (date)
  10614. "Non-nil when DATE means today.
  10615. DATE is either a list of the form (month day year) or a number of
  10616. days as returned by `calendar-absolute-from-gregorian' or
  10617. `org-today'. This function considers `org-extend-today-until'
  10618. when defining today."
  10619. (eq (org-today)
  10620. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10621. (defun org-agenda-todo-yesterday (&optional arg)
  10622. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10623. (interactive "P")
  10624. (let* ((org-use-effective-time t)
  10625. (hour (nth 2 (decode-time (org-current-time))))
  10626. (org-extend-today-until (1+ hour)))
  10627. (org-agenda-todo arg)))
  10628. (defun org-agenda-ctrl-c-ctrl-c ()
  10629. "Set tags in agenda buffer."
  10630. (interactive)
  10631. (org-agenda-set-tags))
  10632. (provide 'org-agenda)
  10633. ;;; org-agenda.el ends here