org-agenda.el 444 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'ol)
  43. (require 'org)
  44. (require 'org-macs)
  45. (require 'org-refile)
  46. (declare-function diary-add-to-list "diary-lib"
  47. (date string specifier &optional marker globcolor literal))
  48. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  49. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  50. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  51. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  52. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-french-date-string "cal-french" (&optional date))
  55. (declare-function calendar-goto-date "cal-move" (date))
  56. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  57. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  58. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  59. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  60. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  61. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  62. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  63. (declare-function calendar-check-holidays "holidays" (date))
  64. (declare-function org-columns-remove-overlays "org-colview" ())
  65. (declare-function org-datetree-find-date-create "org-datetree"
  66. (date &optional keep-restriction))
  67. (declare-function org-columns-quit "org-colview" ())
  68. (declare-function diary-date-display-form "diary-lib" (&optional type))
  69. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  70. (declare-function org-element-property "org-element" (property element))
  71. (declare-function org-element--cache-active-p "org-element"
  72. (&optional called-from-cache-change-func-p))
  73. (declare-function org-habit-insert-consistency-graphs
  74. "org-habit" (&optional line))
  75. (declare-function org-is-habit-p "org-habit" (&optional pom))
  76. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  77. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  78. (declare-function org-agenda-columns "org-colview" ())
  79. (declare-function org-add-archive-files "org-archive" (files))
  80. (declare-function org-capture "org-capture" (&optional goto keys))
  81. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  82. (declare-function org-element-type "org-element" (&optional element))
  83. (defvar calendar-mode-map)
  84. (defvar org-clock-current-task)
  85. (defvar org-current-tag-alist)
  86. (defvar org-mobile-force-id-on-agenda-items)
  87. (defvar org-habit-show-habits)
  88. (defvar org-habit-show-habits-only-for-today)
  89. (defvar org-habit-show-all-today)
  90. (defvar org-habit-scheduled-past-days)
  91. ;; Defined somewhere in this file, but used before definition.
  92. (defvar org-agenda-buffer-name "*Org Agenda*")
  93. (defvar org-agenda-overriding-header nil)
  94. (defvar org-agenda-title-append nil)
  95. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  96. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  97. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  98. (defvar org-agenda-undo-list nil
  99. "List of undoable operations in the agenda since last refresh.")
  100. (defvar org-agenda-pending-undo-list nil
  101. "In a series of undo commands, this is the list of remaining undo items.")
  102. (defcustom org-agenda-confirm-kill 1
  103. "When set, remote killing from the agenda buffer needs confirmation.
  104. When t, a confirmation is always needed. When a number N, confirmation is
  105. only needed when the text to be killed contains more than N non-white lines."
  106. :group 'org-agenda
  107. :type '(choice
  108. (const :tag "Never" nil)
  109. (const :tag "Always" t)
  110. (integer :tag "When more than N lines")))
  111. (defcustom org-agenda-compact-blocks nil
  112. "Non-nil means make the block agenda more compact.
  113. This is done globally by leaving out lines like the agenda span
  114. name and week number or the separator lines."
  115. :group 'org-agenda
  116. :type 'boolean)
  117. (defcustom org-agenda-block-separator ?=
  118. "The separator between blocks in the agenda.
  119. If this is a string, it will be used as the separator, with a newline added.
  120. If it is a character, it will be repeated to fill the window width.
  121. If nil the separator is disabled. In `org-agenda-custom-commands' this
  122. addresses the separator between the current and the previous block."
  123. :group 'org-agenda
  124. :type '(choice
  125. (const :tag "Disabled" nil)
  126. (character)
  127. (string)))
  128. (defgroup org-agenda-export nil
  129. "Options concerning exporting agenda views in Org mode."
  130. :tag "Org Agenda Export"
  131. :group 'org-agenda)
  132. (defcustom org-agenda-with-colors t
  133. "Non-nil means use colors in agenda views."
  134. :group 'org-agenda-export
  135. :type 'boolean)
  136. (defcustom org-agenda-exporter-settings nil
  137. ;; FIXME: Do we really want to evaluate those settings and thus force
  138. ;; the user to use `quote' all the time?
  139. "Alist of variable/value pairs that should be active during agenda export.
  140. This is a good place to set options for ps-print and for htmlize.
  141. Note that the way this is implemented, the values will be evaluated
  142. before assigned to the variables. So make sure to quote values you do
  143. *not* want evaluated, for example
  144. (setq org-agenda-exporter-settings
  145. \\='((ps-print-color-p \\='black-white)))"
  146. :group 'org-agenda-export
  147. :type '(repeat
  148. (list
  149. (variable)
  150. (sexp :tag "Value"))))
  151. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  152. "Hook run in a temporary buffer before writing the agenda to an export file.
  153. A useful function for this hook is `org-agenda-add-entry-text'."
  154. :group 'org-agenda-export
  155. :type 'hook
  156. :options '(org-agenda-add-entry-text))
  157. (defcustom org-agenda-add-entry-text-maxlines 0
  158. "Maximum number of entry text lines to be added to agenda.
  159. This is only relevant when `org-agenda-add-entry-text' is part of
  160. `org-agenda-before-write-hook', which is the default.
  161. When this is 0, nothing will happen. When it is greater than 0, it
  162. specifies the maximum number of lines that will be added for each entry
  163. that is listed in the agenda view.
  164. Note that this variable is not used during display, only when exporting
  165. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  166. and `org-agenda-entry-text-maxlines'."
  167. :group 'org-agenda
  168. :type 'integer)
  169. (defcustom org-agenda-add-entry-text-descriptive-links t
  170. "Non-nil means export org-links as descriptive links in agenda added text.
  171. This variable applies to the text added to the agenda when
  172. `org-agenda-add-entry-text-maxlines' is larger than 0.
  173. When this variable is nil, the URL will (also) be shown."
  174. :group 'org-agenda
  175. :type 'boolean)
  176. (defcustom org-agenda-export-html-style nil
  177. "The style specification for exported HTML Agenda files.
  178. If this variable contains a string, it will replace the default <style>
  179. section as produced by `htmlize'.
  180. Since there are different ways of setting style information, this variable
  181. needs to contain the full HTML structure to provide a style, including the
  182. surrounding HTML tags. The style specifications should include definitions
  183. the fonts used by the agenda, here is an example:
  184. <style type=\"text/css\">
  185. p { font-weight: normal; color: gray; }
  186. .org-agenda-structure {
  187. font-size: 110%;
  188. color: #003399;
  189. font-weight: 600;
  190. }
  191. .org-todo {
  192. color: #cc6666;
  193. font-weight: bold;
  194. }
  195. .org-agenda-done {
  196. color: #339933;
  197. }
  198. .org-done {
  199. color: #339933;
  200. }
  201. .title { text-align: center; }
  202. .todo, .deadline { color: red; }
  203. .done { color: green; }
  204. </style>
  205. or, if you want to keep the style in a file,
  206. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  207. As the value of this option simply gets inserted into the HTML <head> header,
  208. you can \"misuse\" it to also add other text to the header."
  209. :group 'org-agenda-export
  210. :group 'org-export-html
  211. :type '(choice
  212. (const nil)
  213. (string)))
  214. (defcustom org-agenda-persistent-filter nil
  215. "When set, keep filters from one agenda view to the next."
  216. :group 'org-agenda
  217. :type 'boolean)
  218. (defgroup org-agenda-custom-commands nil
  219. "Options concerning agenda views in Org mode."
  220. :tag "Org Agenda Custom Commands"
  221. :group 'org-agenda)
  222. (defconst org-sorting-choice
  223. '(choice
  224. (const time-up) (const time-down)
  225. (const timestamp-up) (const timestamp-down)
  226. (const scheduled-up) (const scheduled-down)
  227. (const deadline-up) (const deadline-down)
  228. (const ts-up) (const ts-down)
  229. (const tsia-up) (const tsia-down)
  230. (const category-keep) (const category-up) (const category-down)
  231. (const tag-down) (const tag-up)
  232. (const priority-up) (const priority-down)
  233. (const todo-state-up) (const todo-state-down)
  234. (const effort-up) (const effort-down)
  235. (const habit-up) (const habit-down)
  236. (const alpha-up) (const alpha-down)
  237. (const user-defined-up) (const user-defined-down))
  238. "Sorting choices.")
  239. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  240. ;; the new variable `org-agenda-tag-filter-preset'.
  241. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  242. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  243. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  244. "List of types searched for when creating the daily/weekly agenda.
  245. This variable is a list of symbols that controls the types of
  246. items that appear in the daily/weekly agenda. Allowed symbols in this
  247. list are
  248. :timestamp List items containing a date stamp or date range matching
  249. the selected date. This includes sexp entries in angular
  250. brackets.
  251. :sexp List entries resulting from plain diary-like sexps.
  252. :deadline List deadline due on that date. When the date is today,
  253. also list any deadlines past due, or due within
  254. `org-deadline-warning-days'.
  255. :deadline* Same as above, but only include the deadline if it has an
  256. hour specification as [h]h:mm.
  257. :scheduled List all items which are scheduled for the given date.
  258. The diary for *today* also contains items which were
  259. scheduled earlier and are not yet marked DONE.
  260. :scheduled* Same as above, but only include the scheduled item if it
  261. has an hour specification as [h]h:mm.
  262. By default, all four non-starred types are turned on.
  263. When :scheduled* or :deadline* are included, :schedule or :deadline
  264. will be ignored.
  265. Never set this variable globally using `setq', because then it
  266. will apply to all future agenda commands. Instead, bind it with
  267. `let' to scope it dynamically into the agenda-constructing
  268. command. A good way to set it is through options in
  269. `org-agenda-custom-commands'. For a more flexible (though
  270. somewhat less efficient) way of determining what is included in
  271. the daily/weekly agenda, see `org-agenda-skip-function'.")
  272. (defconst org-agenda-custom-commands-local-options
  273. `(repeat :tag "Local settings for this command. Remember to quote values"
  274. (choice :tag "Setting"
  275. (list :tag "Heading for this block"
  276. (const org-agenda-overriding-header)
  277. (string :tag "Headline"))
  278. (list :tag "Files to be searched"
  279. (const org-agenda-files)
  280. (list
  281. (const :format "" quote)
  282. (repeat (file))))
  283. (list :tag "Sorting strategy"
  284. (const org-agenda-sorting-strategy)
  285. (list
  286. (const :format "" quote)
  287. (repeat
  288. ,org-sorting-choice)))
  289. (list :tag "Prefix format"
  290. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  291. (string))
  292. (list :tag "Number of days in agenda"
  293. (const org-agenda-span)
  294. (list
  295. (const :format "" quote)
  296. (choice (const :tag "Day" day)
  297. (const :tag "Week" week)
  298. (const :tag "Fortnight" fortnight)
  299. (const :tag "Month" month)
  300. (const :tag "Year" year)
  301. (integer :tag "Custom"))))
  302. (list :tag "Fixed starting date"
  303. (const org-agenda-start-day)
  304. (string :value "2007-11-01"))
  305. (list :tag "Start on day of week"
  306. (const org-agenda-start-on-weekday)
  307. (choice :value 1
  308. (const :tag "Today" nil)
  309. (integer :tag "Weekday No.")))
  310. (list :tag "Include data from diary"
  311. (const org-agenda-include-diary)
  312. (boolean))
  313. (list :tag "Deadline Warning days"
  314. (const org-deadline-warning-days)
  315. (integer :value 1))
  316. (list :tag "Category filter preset"
  317. (const org-agenda-category-filter-preset)
  318. (list
  319. (const :format "" quote)
  320. (repeat
  321. (string :tag "+category or -category"))))
  322. (list :tag "Tags filter preset"
  323. (const org-agenda-tag-filter-preset)
  324. (list
  325. (const :format "" quote)
  326. (repeat
  327. (string :tag "+tag or -tag"))))
  328. (list :tag "Effort filter preset"
  329. (const org-agenda-effort-filter-preset)
  330. (list
  331. (const :format "" quote)
  332. (repeat
  333. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  334. (list :tag "Regexp filter preset"
  335. (const org-agenda-regexp-filter-preset)
  336. (list
  337. (const :format "" quote)
  338. (repeat
  339. (string :tag "+regexp or -regexp"))))
  340. (list :tag "Set daily/weekly entry types"
  341. (const org-agenda-entry-types)
  342. (list
  343. (const :format "" quote)
  344. (set :greedy t :value ,org-agenda-entry-types
  345. (const :deadline)
  346. (const :scheduled)
  347. (const :deadline*)
  348. (const :scheduled*)
  349. (const :timestamp)
  350. (const :sexp))))
  351. (list :tag "Columns format"
  352. (const org-overriding-columns-format)
  353. (string :tag "Format"))
  354. (list :tag "Standard skipping condition"
  355. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  356. (const org-agenda-skip-function)
  357. (list
  358. (const :format "" quote)
  359. (list
  360. (choice
  361. :tag "Skipping range"
  362. (const :tag "Skip entry" org-agenda-skip-entry-if)
  363. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  364. (repeat :inline t :tag "Conditions for skipping"
  365. (choice
  366. :tag "Condition type"
  367. (list :tag "Regexp matches" :inline t
  368. (const :format "" regexp)
  369. (regexp))
  370. (list :tag "Regexp does not match" :inline t
  371. (const :format "" notregexp)
  372. (regexp))
  373. (list :tag "TODO state is" :inline t
  374. (const todo)
  375. (choice
  376. (const :tag "Any not-done state" todo)
  377. (const :tag "Any done state" done)
  378. (const :tag "Any state" any)
  379. (list :tag "Keyword list"
  380. (const :format "" quote)
  381. (repeat (string :tag "Keyword")))))
  382. (list :tag "TODO state is not" :inline t
  383. (const nottodo)
  384. (choice
  385. (const :tag "Any not-done state" todo)
  386. (const :tag "Any done state" done)
  387. (const :tag "Any state" any)
  388. (list :tag "Keyword list"
  389. (const :format "" quote)
  390. (repeat (string :tag "Keyword")))))
  391. (const :tag "scheduled" scheduled)
  392. (const :tag "not scheduled" notscheduled)
  393. (const :tag "deadline" deadline)
  394. (const :tag "no deadline" notdeadline)
  395. (const :tag "timestamp" timestamp)
  396. (const :tag "no timestamp" nottimestamp))))))
  397. (list :tag "Non-standard skipping condition"
  398. :value (org-agenda-skip-function)
  399. (const org-agenda-skip-function)
  400. (sexp :tag "Function or form (quoted!)"))
  401. (list :tag "Any variable"
  402. (variable :tag "Variable")
  403. (sexp :tag "Value (sexp)"))))
  404. "Selection of examples for agenda command settings.
  405. This will be spliced into the custom type of
  406. `org-agenda-custom-commands'.")
  407. (defcustom org-agenda-custom-commands
  408. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  409. "Custom commands for the agenda.
  410. \\<org-mode-map>
  411. These commands will be offered on the splash screen displayed by the
  412. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  413. (key desc type match settings files)
  414. key The key (one or more characters as a string) to be associated
  415. with the command.
  416. desc A description of the command, when omitted or nil, a default
  417. description is built using MATCH.
  418. type The command type, any of the following symbols:
  419. agenda The daily/weekly agenda.
  420. todo Entries with a specific TODO keyword, in all agenda files.
  421. search Entries containing search words entry or headline.
  422. tags Tags/Property/TODO match in all agenda files.
  423. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  424. todo-tree Sparse tree of specific TODO keyword in *current* file.
  425. tags-tree Sparse tree with all tags matches in *current* file.
  426. occur-tree Occur sparse tree for *current* file.
  427. ... A user-defined function.
  428. match What to search for:
  429. - a single keyword for TODO keyword searches
  430. - a tags/property/todo match expression for searches
  431. - a word search expression for text searches.
  432. - a regular expression for occur searches
  433. For all other commands, this should be the empty string.
  434. settings A list of option settings, similar to that in a let form, so like
  435. this: ((opt1 val1) (opt2 val2) ...). The values will be
  436. evaluated at the moment of execution, so quote them when needed.
  437. files A list of files to write the produced agenda buffer to with
  438. the command `org-store-agenda-views'.
  439. If a file name ends in \".html\", an HTML version of the buffer
  440. is written out. If it ends in \".ps\", a postscript version is
  441. produced. Otherwise, only the plain text is written to the file.
  442. You can also define a set of commands, to create a composite agenda buffer.
  443. In this case, an entry looks like this:
  444. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  445. where
  446. desc A description string to be displayed in the dispatcher menu.
  447. cmd An agenda command, similar to the above. However, tree commands
  448. are not allowed, but instead you can get agenda and global todo list.
  449. So valid commands for a set are:
  450. (agenda \"\" settings)
  451. (alltodo \"\" settings)
  452. (stuck \"\" settings)
  453. (todo \"match\" settings files)
  454. (search \"match\" settings files)
  455. (tags \"match\" settings files)
  456. (tags-todo \"match\" settings files)
  457. Each command can carry a list of options, and another set of options can be
  458. given for the whole set of commands. Individual command options take
  459. precedence over the general options.
  460. When using several characters as key to a command, the first characters
  461. are prefix commands. For the dispatcher to display useful information, you
  462. should provide a description for the prefix, like
  463. (setq org-agenda-custom-commands
  464. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  465. (\"hl\" tags \"+HOME+Lisa\")
  466. (\"hp\" tags \"+HOME+Peter\")
  467. (\"hk\" tags \"+HOME+Kim\")))"
  468. :group 'org-agenda-custom-commands
  469. :type `(repeat
  470. (choice :value ("x" "Describe command here" tags "" nil)
  471. (list :tag "Single command"
  472. (string :tag "Access Key(s) ")
  473. (option (string :tag "Description"))
  474. (choice
  475. (const :tag "Agenda" agenda)
  476. (const :tag "TODO list" alltodo)
  477. (const :tag "Search words" search)
  478. (const :tag "Stuck projects" stuck)
  479. (const :tag "Tags/Property match (all agenda files)" tags)
  480. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  481. (const :tag "TODO keyword search (all agenda files)" todo)
  482. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  483. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  484. (const :tag "Occur tree (current buffer)" occur-tree)
  485. (sexp :tag "Other, user-defined function"))
  486. (string :tag "Match (only for some commands)")
  487. ,org-agenda-custom-commands-local-options
  488. (option (repeat :tag "Export" (file :tag "Export to"))))
  489. (list :tag "Command series, all agenda files"
  490. (string :tag "Access Key(s)")
  491. (string :tag "Description ")
  492. (repeat :tag "Component"
  493. (choice
  494. (list :tag "Agenda"
  495. (const :format "" agenda)
  496. (const :tag "" :format "" "")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "TODO list (all keywords)"
  499. (const :format "" alltodo)
  500. (const :tag "" :format "" "")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Search words"
  503. (const :format "" search)
  504. (string :tag "Match")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "Stuck projects"
  507. (const :format "" stuck)
  508. (const :tag "" :format "" "")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "Tags/Property match (all agenda files)"
  511. (const :format "" tags)
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)
  514. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  515. (const :format "" tags-todo)
  516. (string :tag "Match")
  517. ,org-agenda-custom-commands-local-options)
  518. (list :tag "TODO keyword search"
  519. (const :format "" todo)
  520. (string :tag "Match")
  521. ,org-agenda-custom-commands-local-options)
  522. (list :tag "Other, user-defined function"
  523. (symbol :tag "function")
  524. (string :tag "Match")
  525. ,org-agenda-custom-commands-local-options)))
  526. (repeat :tag "Settings for entire command set"
  527. (list (variable :tag "Any variable")
  528. (sexp :tag "Value")))
  529. (option (repeat :tag "Export" (file :tag "Export to"))))
  530. (cons :tag "Prefix key documentation"
  531. (string :tag "Access Key(s)")
  532. (string :tag "Description ")))))
  533. (defcustom org-agenda-query-register ?o
  534. "The register holding the current query string.
  535. The purpose of this is that if you construct a query string interactively,
  536. you can then use it to define a custom command."
  537. :group 'org-agenda-custom-commands
  538. :type 'character)
  539. (defcustom org-stuck-projects
  540. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  541. "How to identify stuck projects.
  542. This is a list of four items:
  543. 1. A tags/todo/property matcher string that is used to identify a project.
  544. See the manual for a description of tag and property searches.
  545. The entire tree below a headline matched by this is considered one project.
  546. 2. A list of TODO keywords identifying non-stuck projects.
  547. If the project subtree contains any headline with one of these todo
  548. keywords, the project is considered to be not stuck. If you specify
  549. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  550. 3. A list of tags identifying non-stuck projects.
  551. If the project subtree contains any headline with one of these tags,
  552. the project is considered to be not stuck. If you specify \"*\" as
  553. a tag, any tag will mark the project unstuck. Note that this is about
  554. the explicit presence of a tag somewhere in the subtree, inherited
  555. tags do not count here. If inherited tags make a project not stuck,
  556. use \"-TAG\" in the tags part of the matcher under (1.) above.
  557. 4. An arbitrary regular expression matching non-stuck projects.
  558. If the project turns out to be not stuck, search continues also in the
  559. subtree to see if any of the subtasks have project status.
  560. See also the variable `org-tags-match-list-sublevels' which applies
  561. to projects matched by this search as well.
  562. After defining this variable, you may use `org-agenda-list-stuck-projects'
  563. \(bound to `\\[org-agenda] #') to produce the list."
  564. :group 'org-agenda-custom-commands
  565. :type '(list
  566. (string :tag "Tags/TODO match to identify a project")
  567. (repeat :tag "Projects are *not* stuck if they have an entry with \
  568. TODO keyword any of" (string))
  569. (repeat :tag "Projects are *not* stuck if they have an entry with \
  570. TAG being any of" (string))
  571. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  572. the subtree")))
  573. (defgroup org-agenda-skip nil
  574. "Options concerning skipping parts of agenda files."
  575. :tag "Org Agenda Skip"
  576. :group 'org-agenda)
  577. (defcustom org-agenda-skip-function-global nil
  578. "Function to be called at each match during agenda construction.
  579. If this function returns nil, the current match should not be skipped.
  580. If the function decided to skip an agenda match, is must return the
  581. buffer position from which the search should be continued.
  582. This may also be a Lisp form, which will be evaluated.
  583. This variable will be applied to every agenda match, including
  584. tags/property searches and TODO lists. So try to make the test function
  585. do its checking as efficiently as possible. To implement a skipping
  586. condition just for specific agenda commands, use the variable
  587. `org-agenda-skip-function' which can be set in the options section
  588. of custom agenda commands."
  589. :group 'org-agenda-skip
  590. :type 'sexp)
  591. (defgroup org-agenda-daily/weekly nil
  592. "Options concerning the daily/weekly agenda."
  593. :tag "Org Agenda Daily/Weekly"
  594. :group 'org-agenda)
  595. (defgroup org-agenda-todo-list nil
  596. "Options concerning the global todo list agenda view."
  597. :tag "Org Agenda Todo List"
  598. :group 'org-agenda)
  599. (defgroup org-agenda-match-view nil
  600. "Options concerning the general tags/property/todo match agenda view."
  601. :tag "Org Agenda Match View"
  602. :group 'org-agenda)
  603. (defgroup org-agenda-search-view nil
  604. "Options concerning the search agenda view."
  605. :tag "Org Agenda Search View"
  606. :group 'org-agenda)
  607. (defvar org-agenda-archives-mode nil
  608. "Non-nil means the agenda will include archived items.
  609. If this is the symbol `trees', trees in the selected agenda scope
  610. that are marked with the ARCHIVE tag will be included anyway. When this is
  611. t, also all archive files associated with the current selection of agenda
  612. files will be included.")
  613. (defcustom org-agenda-restriction-lock-highlight-subtree t
  614. "Non-nil means highlight the whole subtree when restriction is active.
  615. Otherwise only highlight the headline. Highlighting the whole subtree is
  616. useful to ensure no edits happen beyond the restricted region."
  617. :group 'org-agenda
  618. :type 'boolean)
  619. (defcustom org-agenda-skip-comment-trees t
  620. "Non-nil means skip trees that start with the COMMENT keyword.
  621. When nil, these trees are also scanned by agenda commands."
  622. :group 'org-agenda-skip
  623. :type 'boolean)
  624. (defcustom org-agenda-todo-list-sublevels t
  625. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  626. When nil, the sublevels of a TODO entry are not checked, resulting in
  627. potentially much shorter TODO lists."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :type 'boolean)
  631. (defcustom org-agenda-todo-ignore-with-date nil
  632. "Non-nil means don't show entries with a date in the global todo list.
  633. You can use this if you prefer to mark mere appointments with a TODO keyword,
  634. but don't want them to show up in the TODO list.
  635. When this is set, it also covers deadlines and scheduled items, the settings
  636. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  637. will be ignored.
  638. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  639. :group 'org-agenda-skip
  640. :group 'org-agenda-todo-list
  641. :type 'boolean)
  642. (defcustom org-agenda-todo-ignore-timestamp nil
  643. "Non-nil means don't show entries with a timestamp.
  644. This applies when creating the global todo list.
  645. Valid values are:
  646. past Don't show entries for today or in the past.
  647. future Don't show entries with a timestamp in the future.
  648. The idea behind this is that if it has a future
  649. timestamp, you don't want to think about it until the
  650. date.
  651. all Don't show any entries with a timestamp in the global todo list.
  652. The idea behind this is that by setting a timestamp, you
  653. have already \"taken care\" of this item.
  654. This variable can also have an integer as a value. If positive (N),
  655. todos with a timestamp N or more days in the future will be ignored. If
  656. negative (-N), todos with a timestamp N or more days in the past will be
  657. ignored. If 0, todos with a timestamp either today or in the future will
  658. be ignored. For example, a value of -1 will exclude todos with a
  659. timestamp in the past (yesterday or earlier), while a value of 7 will
  660. exclude todos with a timestamp a week or more in the future.
  661. See also `org-agenda-todo-ignore-with-date'.
  662. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  663. to make his option also apply to the tags-todo list."
  664. :group 'org-agenda-skip
  665. :group 'org-agenda-todo-list
  666. :version "24.1"
  667. :type '(choice
  668. (const :tag "Ignore future timestamp todos" future)
  669. (const :tag "Ignore past or present timestamp todos" past)
  670. (const :tag "Ignore all timestamp todos" all)
  671. (const :tag "Show timestamp todos" nil)
  672. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  673. (defcustom org-agenda-todo-ignore-scheduled nil
  674. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  675. This applies when creating the global todo list.
  676. Valid values are:
  677. past Don't show entries scheduled today or in the past.
  678. future Don't show entries scheduled in the future.
  679. The idea behind this is that by scheduling it, you don't want to
  680. think about it until the scheduled date.
  681. all Don't show any scheduled entries in the global todo list.
  682. The idea behind this is that by scheduling it, you have already
  683. \"taken care\" of this item.
  684. t Same as `all', for backward compatibility.
  685. This variable can also have an integer as a value. See
  686. `org-agenda-todo-ignore-timestamp' for more details.
  687. See also `org-agenda-todo-ignore-with-date'.
  688. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  689. to make his option also apply to the tags-todo list."
  690. :group 'org-agenda-skip
  691. :group 'org-agenda-todo-list
  692. :type '(choice
  693. (const :tag "Ignore future-scheduled todos" future)
  694. (const :tag "Ignore past- or present-scheduled todos" past)
  695. (const :tag "Ignore all scheduled todos" all)
  696. (const :tag "Ignore all scheduled todos (compatibility)" t)
  697. (const :tag "Show scheduled todos" nil)
  698. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  699. (defcustom org-agenda-todo-ignore-deadlines nil
  700. "Non-nil means ignore some deadline TODO items when making TODO list.
  701. There are different motivations for using different values, please think
  702. carefully when configuring this variable.
  703. This applies when creating the global TODO list.
  704. Valid values are:
  705. near Don't show near deadline entries. A deadline is near when it is
  706. closer than `org-deadline-warning-days' days. The idea behind this
  707. is that such items will appear in the agenda anyway.
  708. far Don't show TODO entries where a deadline has been defined, but
  709. is not going to happen anytime soon. This is useful if you want to use
  710. the TODO list to figure out what to do now.
  711. past Don't show entries with a deadline timestamp for today or in the past.
  712. future Don't show entries with a deadline timestamp in the future, not even
  713. when they become `near' ones. Use it with caution.
  714. all Ignore all TODO entries that do have a deadline.
  715. t Same as `near', for backward compatibility.
  716. This variable can also have an integer as a value. See
  717. `org-agenda-todo-ignore-timestamp' for more details.
  718. See also `org-agenda-todo-ignore-with-date'.
  719. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  720. to make his option also apply to the tags-todo list."
  721. :group 'org-agenda-skip
  722. :group 'org-agenda-todo-list
  723. :type '(choice
  724. (const :tag "Ignore near deadlines" near)
  725. (const :tag "Ignore near deadlines (compatibility)" t)
  726. (const :tag "Ignore far deadlines" far)
  727. (const :tag "Ignore all TODOs with a deadlines" all)
  728. (const :tag "Show all TODOs, even if they have a deadline" nil)
  729. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  730. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  731. "Time unit to use when possibly ignoring an agenda item.
  732. See the docstring of various `org-agenda-todo-ignore-*' options.
  733. The default is to compare time stamps using days. An item is thus
  734. considered to be in the future if it is at least one day after today.
  735. Non-nil means to compare time stamps using seconds. An item is then
  736. considered future if it has a time value later than current time."
  737. :group 'org-agenda-skip
  738. :group 'org-agenda-todo-list
  739. :version "24.4"
  740. :package-version '(Org . "8.0")
  741. :type '(choice
  742. (const :tag "Compare time with days" nil)
  743. (const :tag "Compare time with seconds" t)))
  744. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  745. "Non-nil means honor todo-list ignores options also in tags-todo search.
  746. The variables
  747. `org-agenda-todo-ignore-with-date',
  748. `org-agenda-todo-ignore-timestamp',
  749. `org-agenda-todo-ignore-scheduled',
  750. `org-agenda-todo-ignore-deadlines'
  751. make the global TODO list skip entries that have time stamps of certain
  752. kinds. If this option is set, the same options will also apply for the
  753. tags-todo search, which is the general tags/property matcher
  754. restricted to unfinished TODO entries only."
  755. :group 'org-agenda-skip
  756. :group 'org-agenda-todo-list
  757. :group 'org-agenda-match-view
  758. :type 'boolean)
  759. (defcustom org-agenda-skip-scheduled-if-done nil
  760. "Non-nil means don't show scheduled items in agenda when they are done.
  761. This is relevant for the daily/weekly agenda, not for the TODO list. It
  762. applies only to the actual date of the scheduling. Warnings about an item
  763. with a past scheduling dates are always turned off when the item is DONE."
  764. :group 'org-agenda-skip
  765. :group 'org-agenda-daily/weekly
  766. :type 'boolean)
  767. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  768. "Non-nil means skip scheduling line if same entry shows because of deadline.
  769. In the agenda of today, an entry can show up multiple times
  770. because it is both scheduled and has a nearby deadline, and maybe
  771. a plain time stamp as well.
  772. When this variable is nil, the entry will be shown several times.
  773. When set to t, then only the deadline is shown and the fact that
  774. the entry is scheduled today or was scheduled previously is not
  775. shown.
  776. When set to the symbol `not-today', skip scheduled previously,
  777. but not scheduled today.
  778. When set to the symbol `repeated-after-deadline', skip scheduled
  779. items if they are repeated beyond the current deadline."
  780. :group 'org-agenda-skip
  781. :group 'org-agenda-daily/weekly
  782. :type '(choice
  783. (const :tag "Never" nil)
  784. (const :tag "Always" t)
  785. (const :tag "Not when scheduled today" not-today)
  786. (const :tag "When repeated past deadline" repeated-after-deadline)))
  787. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  788. "Non-nil means skip timestamp line if same entry shows because of deadline.
  789. In the agenda of today, an entry can show up multiple times
  790. because it has both a plain timestamp and has a nearby deadline.
  791. When this variable is t, then only the deadline is shown and the
  792. fact that the entry has a timestamp for or including today is not
  793. shown. When this variable is nil, the entry will be shown
  794. several times."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :version "24.1"
  798. :type '(choice
  799. (const :tag "Never" nil)
  800. (const :tag "Always" t)))
  801. (defcustom org-agenda-skip-deadline-if-done nil
  802. "Non-nil means don't show deadlines when the corresponding item is done.
  803. When nil, the deadline is still shown and should give you a happy feeling.
  804. This is relevant for the daily/weekly agenda. It applies only to the
  805. actual date of the deadline. Warnings about approaching and past-due
  806. deadlines are always turned off when the item is DONE."
  807. :group 'org-agenda-skip
  808. :group 'org-agenda-daily/weekly
  809. :type 'boolean)
  810. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  811. "Non-nil means skip deadline prewarning when entry is also scheduled.
  812. This will apply on all days where a prewarning for the deadline would
  813. be shown, but not at the day when the entry is actually due. On that day,
  814. the deadline will be shown anyway.
  815. This variable may be set to nil, t, the symbol `pre-scheduled',
  816. or a number which will then give the number of days before the actual
  817. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  818. eliminates the deadline prewarning only prior to the scheduled date.
  819. This can be used in a workflow where the first showing of the deadline will
  820. trigger you to schedule it, and then you don't want to be reminded of it
  821. because you will take care of it on the day when scheduled."
  822. :group 'org-agenda-skip
  823. :group 'org-agenda-daily/weekly
  824. :version "24.1"
  825. :type '(choice
  826. (const :tag "Always show prewarning" nil)
  827. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  828. (const :tag "Remove prewarning if entry is scheduled" t)
  829. (integer :tag "Restart prewarning N days before deadline")))
  830. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  831. "Non-nil means skip scheduled delay when entry also has a deadline.
  832. This variable may be set to nil, t, the symbol `post-deadline',
  833. or a number which will then give the number of days after the actual
  834. scheduled date when the delay should expire. The symbol `post-deadline'
  835. eliminates the schedule delay when the date is posterior to the deadline."
  836. :group 'org-agenda-skip
  837. :group 'org-agenda-daily/weekly
  838. :version "24.4"
  839. :package-version '(Org . "8.0")
  840. :type '(choice
  841. (const :tag "Always honor delay" nil)
  842. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  843. (const :tag "Ignore delay if entry has a deadline" t)
  844. (integer :tag "Honor delay up until N days after the scheduled date")))
  845. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  846. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  847. When non-nil, after the search for timestamps has matched once in an
  848. entry, the rest of the entry will not be searched."
  849. :group 'org-agenda-skip
  850. :type 'boolean)
  851. (defcustom org-agenda-skip-timestamp-if-done nil
  852. "Non-nil means don't select item by timestamp or -range if it is DONE."
  853. :group 'org-agenda-skip
  854. :group 'org-agenda-daily/weekly
  855. :type 'boolean)
  856. (defcustom org-agenda-dim-blocked-tasks t
  857. "Non-nil means dim blocked tasks in the agenda display.
  858. This causes some overhead during agenda construction, but if you
  859. have turned on `org-enforce-todo-dependencies',
  860. `org-enforce-todo-checkbox-dependencies', or any other blocking
  861. mechanism, this will create useful feedback in the agenda.
  862. Instead of t, this variable can also have the value `invisible'.
  863. Then blocked tasks will be invisible and only become visible when
  864. they become unblocked. An exemption to this behavior is when a task is
  865. blocked because of unchecked checkboxes below it. Since checkboxes do
  866. not show up in the agenda views, making this task invisible you remove any
  867. trace from agenda views that there is something to do. Therefore, a task
  868. that is blocked because of checkboxes will never be made invisible, it
  869. will only be dimmed."
  870. :group 'org-agenda-daily/weekly
  871. :group 'org-agenda-todo-list
  872. :version "24.3"
  873. :type '(choice
  874. (const :tag "Do not dim" nil)
  875. (const :tag "Dim to a gray face" t)
  876. (const :tag "Make invisible" invisible)))
  877. (defgroup org-agenda-startup nil
  878. "Options concerning initial settings in the Agenda in Org Mode."
  879. :tag "Org Agenda Startup"
  880. :group 'org-agenda)
  881. (defcustom org-agenda-menu-show-matcher t
  882. "Non-nil means show the match string in the agenda dispatcher menu.
  883. When nil, the matcher string is not shown, but is put into the help-echo
  884. property so than moving the mouse over the command shows it.
  885. Setting it to nil is good if matcher strings are very long and/or if
  886. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  887. :group 'org-agenda
  888. :version "24.1"
  889. :type 'boolean)
  890. (defcustom org-agenda-menu-two-columns nil
  891. "Non-nil means, use two columns to show custom commands in the dispatcher.
  892. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  893. to nil."
  894. :group 'org-agenda
  895. :version "24.1"
  896. :type 'boolean)
  897. (defcustom org-agenda-finalize-hook nil
  898. "Hook run just before displaying an agenda buffer.
  899. The buffer is still writable when the hook is called.
  900. You can modify some of the buffer substrings but you should be
  901. extra careful not to modify the text properties of the agenda
  902. headlines as the agenda display heavily relies on them."
  903. :group 'org-agenda-startup
  904. :type 'hook)
  905. (defcustom org-agenda-filter-hook nil
  906. "Hook run just after filtering with `org-agenda-filter'."
  907. :group 'org-agenda-startup
  908. :package-version '(Org . "9.4")
  909. :type 'hook)
  910. (defcustom org-agenda-mouse-1-follows-link nil
  911. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  912. A longer mouse click will still set point. Needs to be set
  913. before org.el is loaded."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-start-with-follow-mode nil
  917. "The initial value of follow mode in a newly created agenda window."
  918. :group 'org-agenda-startup
  919. :type 'boolean)
  920. (defcustom org-agenda-follow-indirect nil
  921. "Non-nil means `org-agenda-follow-mode' displays only the
  922. current item's tree, in an indirect buffer."
  923. :group 'org-agenda
  924. :version "24.1"
  925. :type 'boolean)
  926. (defcustom org-agenda-show-outline-path t
  927. "Non-nil means show outline path in echo area after line motion."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-start-with-entry-text-mode nil
  931. "The initial value of entry-text-mode in a newly created agenda window."
  932. :group 'org-agenda-startup
  933. :type 'boolean)
  934. (defcustom org-agenda-entry-text-maxlines 5
  935. "Number of text lines to be added when `E' is pressed in the agenda.
  936. Note that this variable only used during agenda display. To add entry text
  937. when exporting the agenda, configure the variable
  938. `org-agenda-add-entry-text-maxlines'."
  939. :group 'org-agenda
  940. :type 'integer)
  941. (defcustom org-agenda-entry-text-exclude-regexps nil
  942. "List of regular expressions to clean up entry text.
  943. The complete matches of all regular expressions in this list will be
  944. removed from entry text before it is shown in the agenda."
  945. :group 'org-agenda
  946. :type '(repeat (regexp)))
  947. (defcustom org-agenda-entry-text-leaders " > "
  948. "Text prepended to the entry text in agenda buffers."
  949. :version "24.4"
  950. :package-version '(Org . "8.0")
  951. :group 'org-agenda
  952. :type 'string)
  953. (defvar org-agenda-entry-text-cleanup-hook nil
  954. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  955. This cleanup is done in a temporary buffer, so the function may inspect and
  956. change the entire buffer.
  957. Some default stuff like drawers and scheduling/deadline dates will already
  958. have been removed when this is called, as will any matches for regular
  959. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  960. (defvar org-agenda-include-inactive-timestamps nil
  961. "Non-nil means include inactive time stamps in agenda.
  962. Dynamically scoped.")
  963. (defgroup org-agenda-windows nil
  964. "Options concerning the windows used by the Agenda in Org Mode."
  965. :tag "Org Agenda Windows"
  966. :group 'org-agenda)
  967. (defcustom org-agenda-window-setup 'reorganize-frame
  968. "How the agenda buffer should be displayed.
  969. Possible values for this option are:
  970. current-window Show agenda in the current window, keeping all other windows.
  971. other-window Use `switch-to-buffer-other-window' to display agenda.
  972. only-window Show agenda, deleting all other windows.
  973. reorganize-frame Show only two windows on the current frame, the current
  974. window and the agenda.
  975. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  976. Also, when exiting the agenda, kill that frame.
  977. other-tab Use `switch-to-buffer-other-tab' to display the
  978. agenda, making use of the `tab-bar-mode' introduced
  979. in Emacs version 27.1. Also, kill that tab when
  980. exiting the agenda view.
  981. See also the variable `org-agenda-restore-windows-after-quit'."
  982. :group 'org-agenda-windows
  983. :type '(choice
  984. (const current-window)
  985. (const other-frame)
  986. (const other-tab)
  987. (const other-window)
  988. (const only-window)
  989. (const reorganize-frame))
  990. :package-version '(Org . "9.4"))
  991. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  992. "The min and max height of the agenda window as a fraction of frame height.
  993. The value of the variable is a cons cell with two numbers between 0 and 1.
  994. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  995. :group 'org-agenda-windows
  996. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  997. (defcustom org-agenda-restore-windows-after-quit nil
  998. "Non-nil means restore window configuration upon exiting agenda.
  999. Before the window configuration is changed for displaying the
  1000. agenda, the current status is recorded. When the agenda is
  1001. exited with `q' or `x' and this option is set, the old state is
  1002. restored. If `org-agenda-window-setup' is `other-frame' or
  1003. `other-tab', the value of this option will be ignored."
  1004. :group 'org-agenda-windows
  1005. :type 'boolean)
  1006. (defcustom org-agenda-span 'week
  1007. "Number of days to include in overview display.
  1008. Can be day, week, month, year, or any number of days.
  1009. Custom commands can set this variable in the options section."
  1010. :group 'org-agenda-daily/weekly
  1011. :type '(choice (const :tag "Day" day)
  1012. (const :tag "Week" week)
  1013. (const :tag "Fortnight" fortnight)
  1014. (const :tag "Month" month)
  1015. (const :tag "Year" year)
  1016. (integer :tag "Custom")))
  1017. (defcustom org-agenda-start-on-weekday 1
  1018. "Non-nil means start the overview always on the specified weekday.
  1019. 0 denotes Sunday, 1 denotes Monday, etc.
  1020. When nil, always start on the current day.
  1021. Custom commands can set this variable in the options section."
  1022. :group 'org-agenda-daily/weekly
  1023. :type '(choice (const :tag "Today" nil)
  1024. (integer :tag "Weekday No.")))
  1025. (defcustom org-agenda-show-all-dates t
  1026. "Non-nil means `org-agenda' shows every day in the selected range.
  1027. When nil, only the days which actually have entries are shown."
  1028. :group 'org-agenda-daily/weekly
  1029. :type 'boolean)
  1030. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1031. "Format string for displaying dates in the agenda.
  1032. Used by the daily/weekly agenda. This should be a format string
  1033. understood by `format-time-string', or a function returning the
  1034. formatted date as a string. The function must take a single
  1035. argument, a calendar-style date list like (month day year)."
  1036. :group 'org-agenda-daily/weekly
  1037. :type '(choice
  1038. (string :tag "Format string")
  1039. (function :tag "Function")))
  1040. (defun org-agenda-end-of-line ()
  1041. "Go to the end of visible line."
  1042. (interactive)
  1043. (goto-char (line-end-position)))
  1044. (defun org-agenda-format-date-aligned (date)
  1045. "Format a DATE string for display in the daily/weekly agenda.
  1046. This function makes sure that dates are aligned for easy reading."
  1047. (require 'cal-iso)
  1048. (let* ((dayname (calendar-day-name date))
  1049. (day (cadr date))
  1050. (day-of-week (calendar-day-of-week date))
  1051. (month (car date))
  1052. (monthname (calendar-month-name month))
  1053. (year (nth 2 date))
  1054. (iso-week (org-days-to-iso-week
  1055. (calendar-absolute-from-gregorian date)))
  1056. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1057. ;; (1- year))
  1058. ;; ((and (= month 12) (<= iso-week 1))
  1059. ;; (1+ year))
  1060. ;; (t year)))
  1061. (weekstring (if (= day-of-week 1)
  1062. (format " W%02d" iso-week)
  1063. "")))
  1064. (format "%-10s %2d %s %4d%s"
  1065. dayname day monthname year weekstring)))
  1066. (defcustom org-agenda-time-leading-zero nil
  1067. "Non-nil means use leading zero for military times in agenda.
  1068. For example, 9:30am would become 09:30 rather than 9:30."
  1069. :group 'org-agenda-daily/weekly
  1070. :version "24.1"
  1071. :type 'boolean)
  1072. (defcustom org-agenda-timegrid-use-ampm nil
  1073. "When set, show AM/PM style timestamps on the timegrid."
  1074. :group 'org-agenda
  1075. :version "24.1"
  1076. :type 'boolean)
  1077. (defun org-agenda-time-of-day-to-ampm (time)
  1078. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1079. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1080. (minute (substring time -2))
  1081. (ampm "am"))
  1082. (cond
  1083. ((equal hour-number 12)
  1084. (setq ampm "pm"))
  1085. ((> hour-number 12)
  1086. (setq ampm "pm")
  1087. (setq hour-number (- hour-number 12))))
  1088. (concat
  1089. (if org-agenda-time-leading-zero
  1090. (format "%02d" hour-number)
  1091. (format "%02s" (number-to-string hour-number)))
  1092. ":" minute ampm)))
  1093. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1094. "Conditionally convert TIME to AM/PM format.
  1095. This is based on `org-agenda-timegrid-use-ampm'."
  1096. (if org-agenda-timegrid-use-ampm
  1097. (org-agenda-time-of-day-to-ampm time)
  1098. time))
  1099. (defcustom org-agenda-weekend-days '(6 0)
  1100. "Which days are weekend?
  1101. These days get the special face `org-agenda-date-weekend' in the agenda."
  1102. :group 'org-agenda-daily/weekly
  1103. :type '(set :greedy t
  1104. (const :tag "Monday" 1)
  1105. (const :tag "Tuesday" 2)
  1106. (const :tag "Wednesday" 3)
  1107. (const :tag "Thursday" 4)
  1108. (const :tag "Friday" 5)
  1109. (const :tag "Saturday" 6)
  1110. (const :tag "Sunday" 0)))
  1111. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1112. "Non-nil means jump to today when moving a past date forward in time.
  1113. When using S-right in the agenda to move a date forward, and the date
  1114. stamp currently points to the past, the first key press will move it
  1115. to today. When nil, just move one day forward even if the date stays
  1116. in the past."
  1117. :group 'org-agenda-daily/weekly
  1118. :version "24.1"
  1119. :type 'boolean)
  1120. (defcustom org-agenda-diary-file 'diary-file
  1121. "File to which to add new entries with the `i' key in agenda and calendar.
  1122. When this is the symbol `diary-file', the functionality in the Emacs
  1123. calendar will be used to add entries to the `diary-file'. But when this
  1124. points to a file, `org-agenda-diary-entry' will be used instead."
  1125. :group 'org-agenda
  1126. :type '(choice
  1127. (const :tag "The standard Emacs diary file" diary-file)
  1128. (file :tag "Special Org file diary entries")))
  1129. (defcustom org-agenda-include-diary nil
  1130. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1131. Custom commands can set this variable in the options section."
  1132. :group 'org-agenda-daily/weekly
  1133. :type 'boolean)
  1134. (defcustom org-agenda-include-deadlines t
  1135. "If non-nil, include entries within their deadline warning period.
  1136. Custom commands can set this variable in the options section."
  1137. :group 'org-agenda-daily/weekly
  1138. :version "24.1"
  1139. :type 'boolean)
  1140. (defcustom org-agenda-show-future-repeats t
  1141. "Non-nil shows repeated entries in the future part of the agenda.
  1142. When set to the symbol `next' only the first future repeat is shown."
  1143. :group 'org-agenda-daily/weekly
  1144. :type '(choice
  1145. (const :tag "Show all repeated entries" t)
  1146. (const :tag "Show next repeated entry" next)
  1147. (const :tag "Do not show repeated entries" nil))
  1148. :version "26.1"
  1149. :package-version '(Org . "9.1")
  1150. :safe #'symbolp)
  1151. (defcustom org-agenda-prefer-last-repeat nil
  1152. "Non-nil sets date for repeated entries to their last repeat.
  1153. When nil, display SCHEDULED and DEADLINE dates at their base
  1154. date, and in today's agenda, as a reminder. Display plain
  1155. time-stamps, on the other hand, at every repeat date in the past
  1156. in addition to the base date.
  1157. When non-nil, show a repeated entry at its latest repeat date,
  1158. possibly being today even if it wasn't marked as done. This
  1159. setting is useful if you do not always mark repeated entries as
  1160. done and, yet, consider that reaching repeat date starts the task
  1161. anew.
  1162. When set to a list of strings, prefer last repeats only for
  1163. entries with these TODO keywords."
  1164. :group 'org-agenda-daily/weekly
  1165. :type '(choice
  1166. (const :tag "Prefer last repeat" t)
  1167. (const :tag "Prefer base date" nil)
  1168. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1169. (string :tag "TODO keyword")))
  1170. :version "26.1"
  1171. :package-version '(Org . "9.1")
  1172. :safe (lambda (x) (or (booleanp x) (consp x))))
  1173. (defcustom org-scheduled-past-days 10000
  1174. "Number of days to continue listing scheduled items not marked DONE.
  1175. When an item is scheduled on a date, it shows up in the agenda on
  1176. this day and will be listed until it is marked done or for the
  1177. number of days given here."
  1178. :group 'org-agenda-daily/weekly
  1179. :type 'integer
  1180. :safe 'integerp)
  1181. (defcustom org-deadline-past-days 10000
  1182. "Number of days to warn about missed deadlines.
  1183. When an item has deadline on a date, it shows up in the agenda on
  1184. this day and will appear as a reminder until it is marked DONE or
  1185. for the number of days given here."
  1186. :group 'org-agenda-daily/weekly
  1187. :type 'integer
  1188. :version "26.1"
  1189. :package-version '(Org . "9.1")
  1190. :safe 'integerp)
  1191. (defcustom org-agenda-log-mode-items '(closed clock)
  1192. "List of items that should be shown in agenda log mode.
  1193. \\<org-agenda-mode-map>\
  1194. This list may contain the following symbols:
  1195. closed Show entries that have been closed on that day.
  1196. clock Show entries that have received clocked time on that day.
  1197. state Show all logged state changes.
  1198. Note that instead of changing this variable, you can also press \
  1199. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1200. the agenda to display all available LOG items temporarily."
  1201. :group 'org-agenda-daily/weekly
  1202. :type '(set :greedy t (const closed) (const clock) (const state)))
  1203. (defcustom org-agenda-clock-consistency-checks
  1204. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1205. :gap-ok-around ("4:00")
  1206. :default-face ((:background "DarkRed") (:foreground "white"))
  1207. :overlap-face nil :gap-face nil :no-end-time-face nil
  1208. :long-face nil :short-face nil)
  1209. "This is a property list, with the following keys:
  1210. :max-duration Mark clocking chunks that are longer than this time.
  1211. This is a time string like \"HH:MM\", or the number
  1212. of minutes as an integer.
  1213. :min-duration Mark clocking chunks that are shorter that this.
  1214. This is a time string like \"HH:MM\", or the number
  1215. of minutes as an integer.
  1216. :max-gap Mark gaps between clocking chunks that are longer than
  1217. this duration. A number of minutes, or a string
  1218. like \"HH:MM\".
  1219. :gap-ok-around List of times during the day which are usually not working
  1220. times. When a gap is detected, but the gap contains any
  1221. of these times, the gap is *not* reported. For example,
  1222. if this is (\"4:00\" \"13:00\") then gaps that contain
  1223. 4:00 in the morning (i.e. the night) and 13:00
  1224. (i.e. a typical lunch time) do not cause a warning.
  1225. You should have at least one time during the night in this
  1226. list, or otherwise the first task each morning will trigger
  1227. a warning because it follows a long gap.
  1228. Furthermore, the following properties can be used to define faces for
  1229. issue display.
  1230. :default-face the default face, if the specific face is undefined
  1231. :overlap-face face for overlapping clocks
  1232. :gap-face face for gaps between clocks
  1233. :no-end-time-face face for incomplete clocks
  1234. :long-face face for clock intervals that are too long
  1235. :short-face face for clock intervals that are too short"
  1236. :group 'org-agenda-daily/weekly
  1237. :group 'org-clock
  1238. :version "24.1"
  1239. :type 'plist)
  1240. (defcustom org-agenda-log-mode-add-notes t
  1241. "Non-nil means add first line of notes to log entries in agenda views.
  1242. If a log item like a state change or a clock entry is associated with
  1243. notes, the first line of these notes will be added to the entry in the
  1244. agenda display."
  1245. :group 'org-agenda-daily/weekly
  1246. :type 'boolean)
  1247. (defcustom org-agenda-start-with-log-mode nil
  1248. "The initial value of log-mode in a newly created agenda window.
  1249. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1250. explanations on the possible values."
  1251. :group 'org-agenda-startup
  1252. :group 'org-agenda-daily/weekly
  1253. :type '(choice (const :tag "Don't show log items" nil)
  1254. (const :tag "Show only log items" only)
  1255. (const :tag "Show all possible log items" clockcheck)
  1256. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1257. (choice (const :tag "Show closed log items" closed)
  1258. (const :tag "Show clocked log items" clock)
  1259. (const :tag "Show all logged state changes" state)))))
  1260. (defcustom org-agenda-start-with-clockreport-mode nil
  1261. "The initial value of clockreport-mode in a newly created agenda window."
  1262. :group 'org-agenda-startup
  1263. :group 'org-agenda-daily/weekly
  1264. :type 'boolean)
  1265. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1266. "Property list with parameters for the clocktable in clockreport mode.
  1267. This is the display mode that shows a clock table in the daily/weekly
  1268. agenda, the properties for this dynamic block can be set here.
  1269. The usual clocktable parameters are allowed here, but you cannot set
  1270. the properties :name, :tstart, :tend, :block, and :scope - these will
  1271. be overwritten to make sure the content accurately reflects the
  1272. current display in the agenda."
  1273. :group 'org-agenda-daily/weekly
  1274. :type 'plist)
  1275. (defvaralias 'org-agenda-search-view-search-words-only
  1276. 'org-agenda-search-view-always-boolean)
  1277. (defcustom org-agenda-search-view-always-boolean nil
  1278. "Non-nil means the search string is interpreted as individual parts.
  1279. The search string for search view can either be interpreted as a phrase,
  1280. or as a list of snippets that define a boolean search for a number of
  1281. strings.
  1282. When this is non-nil, the string will be split on whitespace, and each
  1283. snippet will be searched individually, and all must match in order to
  1284. select an entry. A snippet is then a single string of non-white
  1285. characters, or a string in double quotes, or a regexp in {} braces.
  1286. If a snippet is preceded by \"-\", the snippet must *not* match.
  1287. \"+\" is syntactic sugar for positive selection. Each snippet may
  1288. be found as a full word or a partial word, but see the variable
  1289. `org-agenda-search-view-force-full-words'.
  1290. When this is nil, search will look for the entire search phrase as one,
  1291. with each space character matching any amount of whitespace, including
  1292. line breaks.
  1293. Even when this is nil, you can still switch to Boolean search dynamically
  1294. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1295. is a regexp marked with braces like \"{abc}\", this will also switch to
  1296. boolean search."
  1297. :group 'org-agenda-search-view
  1298. :version "24.1"
  1299. :type 'boolean)
  1300. (defcustom org-agenda-search-view-force-full-words nil
  1301. "Non-nil means, search words must be matches as complete words.
  1302. When nil, they may also match part of a word."
  1303. :group 'org-agenda-search-view
  1304. :version "24.1"
  1305. :type 'boolean)
  1306. (defcustom org-agenda-search-view-max-outline-level 0
  1307. "Maximum outline level to display in search view.
  1308. E.g. when this is set to 1, the search view will only
  1309. show headlines of level 1. When set to 0, the default
  1310. value, don't limit agenda view by outline level."
  1311. :group 'org-agenda-search-view
  1312. :version "26.1"
  1313. :package-version '(Org . "8.3")
  1314. :type 'integer)
  1315. (defgroup org-agenda-time-grid nil
  1316. "Options concerning the time grid in the Org Agenda."
  1317. :tag "Org Agenda Time Grid"
  1318. :group 'org-agenda)
  1319. (defcustom org-agenda-search-headline-for-time t
  1320. "Non-nil means search headline for a time-of-day.
  1321. If the headline contains a time-of-day in one format or another, it will
  1322. be used to sort the entry into the time sequence of items for a day.
  1323. Some people have time stamps in the headline that refer to the creation
  1324. time or so, and then this produces an unwanted side effect. If this is
  1325. the case for your, use this variable to turn off searching the headline
  1326. for a time."
  1327. :group 'org-agenda-time-grid
  1328. :type 'boolean)
  1329. (defcustom org-agenda-use-time-grid t
  1330. "Non-nil means show a time grid in the agenda schedule.
  1331. A time grid is a set of lines for specific times (like every two hours between
  1332. 8:00 and 20:00). The items scheduled for a day at specific times are
  1333. sorted in between these lines.
  1334. For details about when the grid will be shown, and what it will look like, see
  1335. the variable `org-agenda-time-grid'."
  1336. :group 'org-agenda-time-grid
  1337. :type 'boolean)
  1338. (defcustom org-agenda-time-grid
  1339. '((daily today require-timed)
  1340. (800 1000 1200 1400 1600 1800 2000)
  1341. "......"
  1342. "----------------")
  1343. "The settings for time grid for agenda display.
  1344. This is a list of four items. The first item is again a list. It contains
  1345. symbols specifying conditions when the grid should be displayed:
  1346. daily if the agenda shows a single day
  1347. weekly if the agenda shows an entire week
  1348. today show grid on current date, independent of daily/weekly display
  1349. require-timed show grid only if at least one item has a time specification
  1350. remove-match skip grid times already present in an entry
  1351. The second item is a list of integers, indicating the times that
  1352. should have a grid line.
  1353. The third item is a string which will be placed right after the
  1354. times that have a grid line.
  1355. The fourth item is a string placed after the grid times. This
  1356. will align with agenda items."
  1357. :group 'org-agenda-time-grid
  1358. :type
  1359. '(list
  1360. (set :greedy t :tag "Grid Display Options"
  1361. (const :tag "Show grid in single day agenda display" daily)
  1362. (const :tag "Show grid in weekly agenda display" weekly)
  1363. (const :tag "Always show grid for today" today)
  1364. (const :tag "Show grid only if any timed entries are present"
  1365. require-timed)
  1366. (const :tag "Skip grid times already present in an entry"
  1367. remove-match))
  1368. (repeat :tag "Grid Times" (integer :tag "Time"))
  1369. (string :tag "Grid String (after agenda times)")
  1370. (string :tag "Grid String (aligns with agenda items)")))
  1371. (defcustom org-agenda-show-current-time-in-grid t
  1372. "Non-nil means show the current time in the time grid."
  1373. :group 'org-agenda-time-grid
  1374. :version "24.1"
  1375. :type 'boolean)
  1376. (defcustom org-agenda-current-time-string
  1377. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1378. "The string for the current time marker in the agenda."
  1379. :group 'org-agenda-time-grid
  1380. :version "24.1"
  1381. :type 'string)
  1382. (defgroup org-agenda-sorting nil
  1383. "Options concerning sorting in the Org Agenda."
  1384. :tag "Org Agenda Sorting"
  1385. :group 'org-agenda)
  1386. (defcustom org-agenda-sorting-strategy
  1387. '((agenda habit-down time-up priority-down category-keep)
  1388. (todo priority-down category-keep)
  1389. (tags priority-down category-keep)
  1390. (search category-keep))
  1391. "Sorting structure for the agenda items of a single day.
  1392. This is a list of symbols which will be used in sequence to determine
  1393. if an entry should be listed before another entry. The following
  1394. symbols are recognized:
  1395. time-up Put entries with time-of-day indications first, early first.
  1396. time-down Put entries with time-of-day indications first, late first.
  1397. timestamp-up Sort by any timestamp, early first.
  1398. timestamp-down Sort by any timestamp, late first.
  1399. scheduled-up Sort by scheduled timestamp, early first.
  1400. scheduled-down Sort by scheduled timestamp, late first.
  1401. deadline-up Sort by deadline timestamp, early first.
  1402. deadline-down Sort by deadline timestamp, late first.
  1403. ts-up Sort by active timestamp, early first.
  1404. ts-down Sort by active timestamp, late first.
  1405. tsia-up Sort by inactive timestamp, early first.
  1406. tsia-down Sort by inactive timestamp, late first.
  1407. category-keep Keep the default order of categories, corresponding to the
  1408. sequence in `org-agenda-files'.
  1409. category-up Sort alphabetically by category, A-Z.
  1410. category-down Sort alphabetically by category, Z-A.
  1411. tag-up Sort alphabetically by last tag, A-Z.
  1412. tag-down Sort alphabetically by last tag, Z-A.
  1413. priority-up Sort numerically by priority, high priority last.
  1414. priority-down Sort numerically by priority, high priority first.
  1415. todo-state-up Sort by todo state, tasks that are done last.
  1416. todo-state-down Sort by todo state, tasks that are done first.
  1417. effort-up Sort numerically by estimated effort, high effort last.
  1418. effort-down Sort numerically by estimated effort, high effort first.
  1419. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1420. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1421. habit-up Put entries that are habits first.
  1422. habit-down Put entries that are habits last.
  1423. alpha-up Sort headlines alphabetically.
  1424. alpha-down Sort headlines alphabetically, reversed.
  1425. The different possibilities will be tried in sequence, and testing stops
  1426. if one comparison returns a \"not-equal\". For example, the default
  1427. '(time-up category-keep priority-down)
  1428. means: Pull out all entries having a specified time of day and sort them,
  1429. in order to make a time schedule for the current day the first thing in the
  1430. agenda listing for the day. Of the entries without a time indication, keep
  1431. the grouped in categories, don't sort the categories, but keep them in
  1432. the sequence given in `org-agenda-files'. Within each category sort by
  1433. priority.
  1434. Leaving out `category-keep' would mean that items will be sorted across
  1435. categories by priority.
  1436. Instead of a single list, this can also be a set of list for specific
  1437. contents, with a context symbol in the car of the list, any of
  1438. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1439. Custom commands can bind this variable in the options section."
  1440. :group 'org-agenda-sorting
  1441. :type `(choice
  1442. (repeat :tag "General" ,org-sorting-choice)
  1443. (list :tag "Individually"
  1444. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1445. (repeat ,org-sorting-choice))
  1446. (cons (const :tag "Strategy for TODO lists" todo)
  1447. (repeat ,org-sorting-choice))
  1448. (cons (const :tag "Strategy for Tags matches" tags)
  1449. (repeat ,org-sorting-choice))
  1450. (cons (const :tag "Strategy for search matches" search)
  1451. (repeat ,org-sorting-choice)))))
  1452. (defcustom org-agenda-cmp-user-defined nil
  1453. "A function to define the comparison `user-defined'.
  1454. This function must receive two arguments, agenda entry a and b.
  1455. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1456. the user comparison, return nil.
  1457. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1458. part of an agenda sorting strategy."
  1459. :group 'org-agenda-sorting
  1460. :type 'symbol)
  1461. (defcustom org-agenda-sort-notime-is-late t
  1462. "Non-nil means items without time are considered late.
  1463. This is only relevant for sorting. When t, items which have no explicit
  1464. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1465. do have a time. When nil, the default time is before 0:00. You can use this
  1466. option to decide if the schedule for today should come before or after timeless
  1467. agenda entries."
  1468. :group 'org-agenda-sorting
  1469. :type 'boolean)
  1470. (defcustom org-agenda-sort-noeffort-is-high t
  1471. "Non-nil means items without effort estimate are sorted as high effort.
  1472. This also applies when filtering an agenda view with respect to the
  1473. < or > effort operator. Then, tasks with no effort defined will be treated
  1474. as tasks with high effort.
  1475. When nil, such items are sorted as 0 minutes effort."
  1476. :group 'org-agenda-sorting
  1477. :type 'boolean)
  1478. (defgroup org-agenda-line-format nil
  1479. "Options concerning the entry prefix in the Org agenda display."
  1480. :tag "Org Agenda Line Format"
  1481. :group 'org-agenda)
  1482. (defcustom org-agenda-prefix-format
  1483. '((agenda . " %i %-12:c%?-12t% s")
  1484. (todo . " %i %-12:c")
  1485. (tags . " %i %-12:c")
  1486. (search . " %i %-12:c"))
  1487. "Format specifications for the prefix of items in the agenda views.
  1488. An alist with one entry per agenda type. The keys of the
  1489. sublists are `agenda', `todo', `search' and `tags'. The values
  1490. are format strings.
  1491. This format works similar to a printf format, with the following meaning:
  1492. %c the category of the item, \"Diary\" for entries from the diary,
  1493. or as given by the CATEGORY keyword or derived from the file name
  1494. %e the effort required by the item
  1495. %l the level of the item (insert X space(s) if item is of level X)
  1496. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1497. %T the last tag of the item (ignore inherited tags, which come first)
  1498. %t the HH:MM time-of-day specification if one applies to the entry
  1499. %s Scheduling/Deadline information, a short string
  1500. %b show breadcrumbs, i.e., the names of the higher levels
  1501. %(expression) Eval EXPRESSION and replace the control string
  1502. by the result
  1503. All specifiers work basically like the standard `%s' of printf, but may
  1504. contain two additional characters: a question mark just after the `%'
  1505. and a whitespace/punctuation character just before the final letter.
  1506. If the first character after `%' is a question mark, the entire field
  1507. will only be included if the corresponding value applies to the current
  1508. entry. This is useful for fields which should have fixed width when
  1509. present, but zero width when absent. For example, \"%?-12t\" will
  1510. result in a 12 character time field if a time of the day is specified,
  1511. but will completely disappear in entries which do not contain a time.
  1512. If there is punctuation or whitespace character just before the
  1513. final format letter, this character will be appended to the field
  1514. value if the value is not empty. For example, the format
  1515. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1516. the category is empty, no additional colon is inserted.
  1517. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1518. which means:
  1519. - Indent the line with two space characters
  1520. - Give the category a 12 chars wide field, padded with whitespace on
  1521. the right (because of `-'). Append a colon if there is a category
  1522. (because of `:').
  1523. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1524. time, don't put in an empty field, just skip it (because of '?').
  1525. - Finally, put the scheduling information.
  1526. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1527. `org-agenda-remove-tags'.
  1528. Custom commands can set this variable in the options section."
  1529. :type '(choice
  1530. (string :tag "General format")
  1531. (list :greedy t :tag "View dependent"
  1532. (cons (const agenda) (string :tag "Format"))
  1533. (cons (const todo) (string :tag "Format"))
  1534. (cons (const tags) (string :tag "Format"))
  1535. (cons (const search) (string :tag "Format"))))
  1536. :group 'org-agenda-line-format
  1537. :version "26.1"
  1538. :package-version '(Org . "9.1"))
  1539. (defcustom org-agenda-breadcrumbs-separator "->"
  1540. "The separator of breadcrumbs in agenda lines."
  1541. :group 'org-agenda-line-format
  1542. :package-version '(Org . "9.3")
  1543. :type 'string
  1544. :safe #'stringp)
  1545. (defvar org-prefix-format-compiled nil
  1546. "The compiled prefix format and associated variables.
  1547. This is a list where first element is a list of variable bindings, and second
  1548. element is the compiled format expression. See the variable
  1549. `org-agenda-prefix-format'.")
  1550. (defcustom org-agenda-todo-keyword-format "%-1s"
  1551. "Format for the TODO keyword in agenda lines.
  1552. Set this to something like \"%-12s\" if you want all TODO keywords
  1553. to occupy a fixed space in the agenda display."
  1554. :group 'org-agenda-line-format
  1555. :type 'string)
  1556. (defcustom org-agenda-diary-sexp-prefix nil
  1557. "A regexp that matches part of a diary sexp entry
  1558. which should be treated as scheduling/deadline information in
  1559. `org-agenda'.
  1560. For example, you can use this to extract the `diary-remind-message' from
  1561. `diary-remind' entries."
  1562. :group 'org-agenda-line-format
  1563. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1564. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1565. "Text preceding timerange entries in the agenda view.
  1566. This is a list with two strings. The first applies when the range
  1567. is entirely on one day. The second applies if the range spans several days.
  1568. The strings may have two \"%d\" format specifiers which will be filled
  1569. with the sequence number of the days, and the total number of days in the
  1570. range, respectively."
  1571. :group 'org-agenda-line-format
  1572. :type '(list
  1573. (string :tag "Deadline today ")
  1574. (choice :tag "Deadline relative"
  1575. (string :tag "Format string")
  1576. (function))))
  1577. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1578. "Text preceding scheduled items in the agenda view.
  1579. This is a list with two strings. The first applies when the item is
  1580. scheduled on the current day. The second applies when it has been scheduled
  1581. previously, it may contain a %d indicating that this is the nth time that
  1582. this item is scheduled, due to automatic rescheduling of unfinished items
  1583. for the following day. So this number is one larger than the number of days
  1584. that passed since this item was scheduled first."
  1585. :group 'org-agenda-line-format
  1586. :version "24.4"
  1587. :package-version '(Org . "8.0")
  1588. :type '(list
  1589. (string :tag "Scheduled today ")
  1590. (string :tag "Scheduled previously")))
  1591. (defcustom org-agenda-inactive-leader "["
  1592. "Text preceding item pulled into the agenda by inactive time stamps.
  1593. These entries are added to the agenda when pressing \"[\"."
  1594. :group 'org-agenda-line-format
  1595. :version "24.1"
  1596. :type 'string)
  1597. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1598. "Text preceding deadline items in the agenda view.
  1599. This is a list with three strings. The first applies when the item has its
  1600. deadline on the current day. The second applies when the deadline is in the
  1601. future, the third one when it is in the past. The strings may contain %d
  1602. to capture the number of days."
  1603. :group 'org-agenda-line-format
  1604. :version "24.4"
  1605. :package-version '(Org . "8.0")
  1606. :type '(list
  1607. (string :tag "Deadline today ")
  1608. (string :tag "Deadline in the future ")
  1609. (string :tag "Deadline in the past ")))
  1610. (defcustom org-agenda-remove-times-when-in-prefix t
  1611. "Non-nil means remove duplicate time specifications in agenda items.
  1612. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1613. time-of-day specification in a headline or diary entry is extracted and
  1614. placed into the prefix. If this option is non-nil, the original specification
  1615. \(a timestamp or -range, or just a plain time(range) specification like
  1616. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1617. cluttered.
  1618. The option can be t or nil. It may also be the symbol `beg', indicating
  1619. that the time should only be removed when it is located at the beginning of
  1620. the headline/diary entry."
  1621. :group 'org-agenda-line-format
  1622. :type '(choice
  1623. (const :tag "Always" t)
  1624. (const :tag "Never" nil)
  1625. (const :tag "When at beginning of entry" beg)))
  1626. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1627. "Non-nil means remove time ranges specifications in agenda
  1628. items that span on several days."
  1629. :group 'org-agenda-line-format
  1630. :version "24.1"
  1631. :type 'boolean)
  1632. (defcustom org-agenda-default-appointment-duration nil
  1633. "Default duration for appointments that only have a starting time.
  1634. When nil, no duration is specified in such cases.
  1635. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1636. :group 'org-agenda-line-format
  1637. :type '(choice
  1638. (integer :tag "Minutes")
  1639. (const :tag "No default duration")))
  1640. (defcustom org-agenda-show-inherited-tags t
  1641. "Non-nil means show inherited tags in each agenda line.
  1642. When this option is set to `always', it takes precedence over
  1643. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1644. in every agenda.
  1645. When this option is set to t (the default), inherited tags are
  1646. shown when they are available, i.e. when the value of
  1647. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1648. given agenda type.
  1649. This can be set to a list of agenda types in which the agenda
  1650. must display the inherited tags. Available types are `todo',
  1651. `agenda' and `search'.
  1652. When set to nil, never show inherited tags in agenda lines."
  1653. :group 'org-agenda-line-format
  1654. :group 'org-agenda
  1655. :version "24.3"
  1656. :type '(choice
  1657. (const :tag "Show inherited tags when available" t)
  1658. (const :tag "Always show inherited tags" always)
  1659. (repeat :tag "Show inherited tags only in selected agenda types"
  1660. (symbol :tag "Agenda type"))))
  1661. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1662. "List of agenda view types where to use tag inheritance.
  1663. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1664. controlled by `org-use-tag-inheritance'. In other agenda types,
  1665. `org-use-tag-inheritance' is not used for the selection of the
  1666. agenda entries. Still, you may want the agenda to be aware of
  1667. the inherited tags anyway, e.g. for later tag filtering.
  1668. Allowed value are `todo', `search' and `agenda'.
  1669. This variable has no effect if `org-agenda-show-inherited-tags'
  1670. is set to `always'. In that case, the agenda is aware of those
  1671. tags.
  1672. The default value sets tags in every agenda type. Setting this
  1673. option to nil will speed up non-tags agenda view a lot."
  1674. :group 'org-agenda
  1675. :version "26.1"
  1676. :package-version '(Org . "9.1")
  1677. :type '(choice
  1678. (const :tag "Use tag inheritance in all agenda types" t)
  1679. (repeat :tag "Use tag inheritance in selected agenda types"
  1680. (symbol :tag "Agenda type"))))
  1681. (defcustom org-agenda-hide-tags-regexp nil
  1682. "Regular expression used to filter away specific tags in agenda views.
  1683. This means that these tags will be present, but not be shown in the agenda
  1684. line. Secondary filtering will still work on the hidden tags.
  1685. Nil means don't hide any tags."
  1686. :group 'org-agenda-line-format
  1687. :type '(choice
  1688. (const :tag "Hide none" nil)
  1689. (regexp :tag "Regexp ")))
  1690. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1691. 'org-agenda-remove-tags)
  1692. (defcustom org-agenda-remove-tags nil
  1693. "Non-nil means remove the tags from the headline copy in the agenda.
  1694. When this is the symbol `prefix', only remove tags when
  1695. `org-agenda-prefix-format' contains a `%T' specifier."
  1696. :group 'org-agenda-line-format
  1697. :type '(choice
  1698. (const :tag "Always" t)
  1699. (const :tag "Never" nil)
  1700. (const :tag "When prefix format contains %T" prefix)))
  1701. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1702. (defcustom org-agenda-tags-column 'auto
  1703. "Shift tags in agenda items to this column.
  1704. If set to `auto', tags will be automatically aligned to the right
  1705. edge of the window.
  1706. If set to a positive number, tags will be left-aligned to that
  1707. column. If set to a negative number, tags will be right-aligned
  1708. to that column. For example, -80 works well for a normal 80
  1709. character screen."
  1710. :group 'org-agenda-line-format
  1711. :type '(choice
  1712. (const :tag "Automatically align to right edge of window" auto)
  1713. (integer :tag "Specific column" -80))
  1714. :package-version '(Org . "9.1")
  1715. :version "26.1")
  1716. (defcustom org-agenda-fontify-priorities 'cookies
  1717. "Non-nil means highlight low and high priorities in agenda.
  1718. When t, the highest priority entries are bold, lowest priority italic.
  1719. However, settings in `org-priority-faces' will overrule these faces.
  1720. When this variable is the symbol `cookies', only fontify the
  1721. cookies, not the entire task.
  1722. This may also be an association list of priority faces, whose
  1723. keys are the character values of `org-priority-highest',
  1724. `org-priority-default', and `org-priority-lowest' (the default values
  1725. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1726. color as a string, or a list like `(:background \"Red\")'.
  1727. If it is a color, the variable `org-faces-easy-properties'
  1728. determines if it is a foreground or a background color."
  1729. :group 'org-agenda-line-format
  1730. :type '(choice
  1731. (const :tag "Never" nil)
  1732. (const :tag "Defaults" t)
  1733. (const :tag "Cookies only" cookies)
  1734. (repeat :tag "Specify"
  1735. (list (character :tag "Priority" :value ?A)
  1736. (choice :tag "Face "
  1737. (string :tag "Color")
  1738. (sexp :tag "Face"))))))
  1739. (defcustom org-agenda-day-face-function nil
  1740. "Function called to determine what face should be used to display a day.
  1741. The only argument passed to that function is the day. It should
  1742. returns a face, or nil if does not want to specify a face and let
  1743. the normal rules apply."
  1744. :group 'org-agenda-line-format
  1745. :version "24.1"
  1746. :type '(choice (const nil) (function)))
  1747. (defcustom org-agenda-category-icon-alist nil
  1748. "Alist of category icon to be displayed in agenda views.
  1749. Each entry should have the following format:
  1750. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1751. Where CATEGORY-REGEXP is a regexp matching the categories where
  1752. the icon should be displayed.
  1753. FILE-OR-DATA either a file path or a string containing image data.
  1754. The other fields can be omitted safely if not needed:
  1755. TYPE indicates the image type.
  1756. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1757. image data.
  1758. PROPS are additional image attributes to assign to the image,
  1759. like, e.g. `:ascent center'.
  1760. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1761. If you want to set the display properties yourself, just put a
  1762. list as second element:
  1763. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1764. For example, to display a 16px horizontal space for Emacs
  1765. category, you can use:
  1766. (\"Emacs\" \\='(space . (:width (16))))"
  1767. :group 'org-agenda-line-format
  1768. :version "24.1"
  1769. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1770. :value-type (choice (list :tag "Icon"
  1771. (string :tag "File or data")
  1772. (symbol :tag "Type")
  1773. (boolean :tag "Data?")
  1774. (repeat :tag "Extra image properties" :inline t sexp))
  1775. (list :tag "Display properties" sexp))))
  1776. (defgroup org-agenda-column-view nil
  1777. "Options concerning column view in the agenda."
  1778. :tag "Org Agenda Column View"
  1779. :group 'org-agenda)
  1780. (defcustom org-agenda-view-columns-initially nil
  1781. "When non-nil, switch to columns view right after creating the agenda."
  1782. :group 'org-agenda-column-view
  1783. :type 'boolean
  1784. :version "26.1"
  1785. :package-version '(Org . "9.0")
  1786. :safe #'booleanp)
  1787. (defcustom org-agenda-columns-show-summaries t
  1788. "Non-nil means show summaries for columns displayed in the agenda view."
  1789. :group 'org-agenda-column-view
  1790. :type 'boolean)
  1791. (defcustom org-agenda-columns-compute-summary-properties t
  1792. "Non-nil means recompute all summary properties before column view.
  1793. When column view in the agenda is listing properties that have a summary
  1794. operator, it can go to all relevant buffers and recompute the summaries
  1795. there. This can mean overhead for the agenda column view, but is necessary
  1796. to have thing up to date.
  1797. As a special case, a CLOCKSUM property also makes sure that the clock
  1798. computations are current."
  1799. :group 'org-agenda-column-view
  1800. :type 'boolean)
  1801. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1802. "Non-nil means the duration of an appointment will add to day effort.
  1803. The property to which appointment durations will be added is the one given
  1804. in the option `org-effort-property'. If an appointment does not have
  1805. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1806. is not set, an appointment without end time will not contribute to the time
  1807. estimate."
  1808. :group 'org-agenda-column-view
  1809. :type 'boolean)
  1810. (defcustom org-agenda-auto-exclude-function nil
  1811. "A function called with a tag to decide if it is filtered on \
  1812. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1813. The sole argument to the function, which is called once for each
  1814. possible tag, is a string giving the name of the tag. The
  1815. function should return either nil if the tag should be included
  1816. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1817. lines not carrying this tag.
  1818. Note that for the purpose of tag filtering, only the lower-case version of
  1819. all tags will be considered, so that this function will only ever see
  1820. the lower-case version of all tags."
  1821. :group 'org-agenda
  1822. :type '(choice (const nil) (function)))
  1823. (defcustom org-agenda-bulk-custom-functions nil
  1824. "Alist of characters and custom functions for bulk actions.
  1825. For example, this value makes those two functions available:
  1826. \\='((?R set-category)
  1827. (?C bulk-cut))
  1828. With selected entries in an agenda buffer, `B R' will call
  1829. the custom function `set-category' on the selected entries.
  1830. Note that functions in this alist don't need to be quoted.
  1831. You can also specify a function which collects arguments to be
  1832. used for each call to your bulk custom function. The argument
  1833. collecting function will be run once and should return a list of
  1834. arguments to pass to the bulk function. For example:
  1835. \\='((?R set-category get-category))
  1836. Now, `B R' will call the custom `get-category' which would prompt
  1837. the user once for a category. That category is then passed as an
  1838. argument to `set-category' for each entry it's called against."
  1839. :type
  1840. '(alist :key-type character
  1841. :value-type
  1842. (group (function :tag "Bulk Custom Function")
  1843. (choice (function :tag "Bulk Custom Argument Function")
  1844. (const :tag "No Bulk Custom Argument Function" nil))))
  1845. :package-version '(Org . "9.5")
  1846. :group 'org-agenda)
  1847. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1848. "Execute BODY with point at location given by `org-hd-marker' property.
  1849. If STRING is non-nil, the text property will be fetched from position 0
  1850. in that string. If STRING is nil, it will be fetched from the beginning
  1851. of the current line."
  1852. (declare (debug t))
  1853. (org-with-gensyms (marker)
  1854. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1855. 'org-hd-marker ,string)))
  1856. (with-current-buffer (marker-buffer ,marker)
  1857. (save-excursion
  1858. (goto-char ,marker)
  1859. ,@body)))))
  1860. (defun org-add-agenda-custom-command (entry)
  1861. "Replace or add a command in `org-agenda-custom-commands'.
  1862. This is mostly for hacking and trying a new command - once the command
  1863. works you probably want to add it to `org-agenda-custom-commands' for good."
  1864. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1865. (if ass
  1866. (setcdr ass (cdr entry))
  1867. (push entry org-agenda-custom-commands))))
  1868. (defmacro org-agenda--insert-overriding-header (default)
  1869. "Insert header into agenda view.
  1870. The inserted header depends on `org-agenda-overriding-header'.
  1871. If the empty string, don't insert a header. If any other string,
  1872. insert it as a header. If nil, insert DEFAULT, which should
  1873. evaluate to a string. If a function, call it and insert the
  1874. string that it returns."
  1875. (declare (debug (form)) (indent defun))
  1876. `(cond
  1877. ((not org-agenda-overriding-header) (insert ,default))
  1878. ((equal org-agenda-overriding-header "") nil)
  1879. ((stringp org-agenda-overriding-header)
  1880. (insert (propertize org-agenda-overriding-header
  1881. 'face 'org-agenda-structure)
  1882. "\n"))
  1883. ((functionp org-agenda-overriding-header)
  1884. (insert (funcall org-agenda-overriding-header)))
  1885. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1886. org-agenda-overriding-header))))
  1887. ;;; Define the org-agenda-mode
  1888. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1889. (defvar org-agenda-mode-map (make-sparse-keymap)
  1890. "Keymap for `org-agenda-mode'.")
  1891. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1892. (defvar org-agenda-menu) ; defined later in this file.
  1893. (defvar org-agenda-restrict nil) ; defined later in this file.
  1894. (defvar org-agenda-follow-mode nil)
  1895. (defvar org-agenda-entry-text-mode nil)
  1896. (defvar org-agenda-clockreport-mode nil)
  1897. (defvar org-agenda-show-log nil
  1898. "When non-nil, show the log in the agenda.
  1899. Do not set this directly; instead use
  1900. `org-agenda-start-with-log-mode', which see.")
  1901. (defvar org-agenda-redo-command nil)
  1902. (defvar org-agenda-query-string nil)
  1903. (defvar org-agenda-mode-hook nil
  1904. "Hook run after `org-agenda-mode' is turned on.
  1905. The buffer is still writable when this hook is called.")
  1906. (defvar org-agenda-type nil)
  1907. (defvar org-agenda-force-single-file nil)
  1908. (defvar org-agenda-bulk-marked-entries nil
  1909. "List of markers that refer to marked entries in the agenda.")
  1910. (defvar org-agenda-current-date nil
  1911. "Active date when building the agenda.")
  1912. ;;; Multiple agenda buffers support
  1913. (defcustom org-agenda-sticky nil
  1914. "Non-nil means agenda q key will bury agenda buffers.
  1915. Agenda commands will then show existing buffer instead of generating new ones.
  1916. When nil, `q' will kill the single agenda buffer."
  1917. :group 'org-agenda
  1918. :version "24.3"
  1919. :type 'boolean)
  1920. ;;;###autoload
  1921. (defun org-toggle-sticky-agenda (&optional arg)
  1922. "Toggle `org-agenda-sticky'."
  1923. (interactive "P")
  1924. (let ((new-value (if arg
  1925. (> (prefix-numeric-value arg) 0)
  1926. (not org-agenda-sticky))))
  1927. (if (equal new-value org-agenda-sticky)
  1928. (and (called-interactively-p 'interactive)
  1929. (message "Sticky agenda was already %s"
  1930. (if org-agenda-sticky "enabled" "disabled")))
  1931. (setq org-agenda-sticky new-value)
  1932. (org-agenda-kill-all-agenda-buffers)
  1933. (and (called-interactively-p 'interactive)
  1934. (message "Sticky agenda %s"
  1935. (if org-agenda-sticky "enabled" "disabled"))))))
  1936. (defvar org-agenda-buffer nil
  1937. "Agenda buffer currently being generated.")
  1938. (defvar org-agenda-last-prefix-arg nil)
  1939. (defvar org-agenda-this-buffer-name nil)
  1940. (defvar org-agenda-doing-sticky-redo nil)
  1941. (defvar org-agenda-this-buffer-is-sticky nil)
  1942. (defvar org-agenda-last-indirect-buffer nil
  1943. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1944. (defconst org-agenda-local-vars
  1945. '(org-agenda-this-buffer-name
  1946. org-agenda-undo-list
  1947. org-agenda-pending-undo-list
  1948. org-agenda-follow-mode
  1949. org-agenda-entry-text-mode
  1950. org-agenda-clockreport-mode
  1951. org-agenda-show-log
  1952. org-agenda-redo-command
  1953. org-agenda-query-string
  1954. org-agenda-type
  1955. org-agenda-bulk-marked-entries
  1956. org-agenda-undo-has-started-in
  1957. org-agenda-info
  1958. org-agenda-pre-window-conf
  1959. org-agenda-columns-active
  1960. org-agenda-tag-filter
  1961. org-agenda-category-filter
  1962. org-agenda-top-headline-filter
  1963. org-agenda-regexp-filter
  1964. org-agenda-effort-filter
  1965. org-agenda-markers
  1966. org-agenda-last-search-view-search-was-boolean
  1967. org-agenda-last-indirect-buffer
  1968. org-agenda-filtered-by-category
  1969. org-agenda-filter-form
  1970. org-agenda-cycle-counter
  1971. org-agenda-last-prefix-arg)
  1972. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1973. (defun org-agenda-mode ()
  1974. "Mode for time-sorted view on action items in Org files.
  1975. The following commands are available:
  1976. \\{org-agenda-mode-map}"
  1977. (interactive)
  1978. (ignore-errors (require 'face-remap))
  1979. (let ((agenda-local-vars-to-keep
  1980. '(text-scale-mode-amount
  1981. text-scale-mode
  1982. text-scale-mode-lighter
  1983. face-remapping-alist))
  1984. (save (buffer-local-variables)))
  1985. (kill-all-local-variables)
  1986. (cl-flet ((reset-saved (var-set)
  1987. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1988. (dolist (elem save)
  1989. (pcase elem
  1990. (`(,var . ,val) ;ignore unbound variables
  1991. (when (and val (memq var var-set))
  1992. (set var val)))))))
  1993. (cond (org-agenda-doing-sticky-redo
  1994. ;; Refreshing sticky agenda-buffer
  1995. ;;
  1996. ;; Preserve the value of `org-agenda-local-vars' variables.
  1997. (mapc #'make-local-variable org-agenda-local-vars)
  1998. (reset-saved org-agenda-local-vars)
  1999. (setq-local org-agenda-this-buffer-is-sticky t))
  2000. (org-agenda-sticky
  2001. ;; Creating a sticky Agenda buffer for the first time
  2002. (mapc #'make-local-variable org-agenda-local-vars)
  2003. (setq-local org-agenda-this-buffer-is-sticky t))
  2004. (t
  2005. ;; Creating a non-sticky agenda buffer
  2006. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2007. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2008. (reset-saved agenda-local-vars-to-keep)))
  2009. (setq org-agenda-undo-list nil
  2010. org-agenda-pending-undo-list nil
  2011. org-agenda-bulk-marked-entries nil)
  2012. (setq major-mode 'org-agenda-mode)
  2013. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2014. (setq-local font-lock-global-modes (list 'not major-mode))
  2015. (setq mode-name "Org-Agenda")
  2016. (setq indent-tabs-mode nil)
  2017. (use-local-map org-agenda-mode-map)
  2018. (when org-startup-truncated (setq truncate-lines t))
  2019. (setq-local line-move-visual nil)
  2020. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2021. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2022. ;; Make sure properties are removed when copying text
  2023. (if (boundp 'filter-buffer-substring-functions)
  2024. (add-hook 'filter-buffer-substring-functions
  2025. (lambda (fun start end delete)
  2026. (substring-no-properties (funcall fun start end delete)))
  2027. nil t)
  2028. ;; Emacs >= 24.4.
  2029. (add-function :filter-return (local 'filter-buffer-substring-function)
  2030. #'substring-no-properties))
  2031. (unless org-agenda-keep-modes
  2032. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2033. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2034. org-agenda-show-log org-agenda-start-with-log-mode
  2035. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2036. (add-to-invisibility-spec '(org-filtered))
  2037. (add-to-invisibility-spec '(org-link))
  2038. (easy-menu-change
  2039. '("Agenda") "Agenda Files"
  2040. (append
  2041. (list
  2042. (vector
  2043. (if (get 'org-agenda-files 'org-restrict)
  2044. "Restricted to single file"
  2045. "Edit File List")
  2046. '(org-edit-agenda-file-list)
  2047. (not (get 'org-agenda-files 'org-restrict)))
  2048. "--")
  2049. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2050. (org-agenda-set-mode-name)
  2051. (run-mode-hooks 'org-agenda-mode-hook))
  2052. (substitute-key-definition #'undo #'org-agenda-undo
  2053. org-agenda-mode-map global-map)
  2054. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2055. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2056. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2057. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2058. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2059. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2060. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2061. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2062. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2063. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2064. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2065. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2066. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2067. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2068. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2069. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2070. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2071. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2072. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2074. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2075. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2076. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2077. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2078. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2079. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2080. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2081. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2082. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2083. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2084. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2085. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2086. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2087. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2088. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2089. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2090. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2091. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2092. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2093. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2094. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2095. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2096. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2097. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2099. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2100. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2101. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2102. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2103. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2104. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2105. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2107. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2108. (while l (org-defkey org-agenda-mode-map
  2109. (number-to-string (pop l)) #'digit-argument)))
  2110. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2111. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2112. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2113. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2114. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2115. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2116. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2117. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2118. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2119. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2120. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2121. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2122. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2123. #'org-clock-modify-effort-estimate)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2125. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2126. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2127. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2128. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2129. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2130. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2131. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2132. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2133. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2134. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2135. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2136. (substitute-key-definition #'next-line #'org-agenda-next-line
  2137. org-agenda-mode-map global-map)
  2138. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2139. org-agenda-mode-map global-map)
  2140. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2141. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2142. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2143. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2144. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2145. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2146. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2147. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2148. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2149. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2150. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2151. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2152. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2153. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2154. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2155. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2156. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2157. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2158. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2159. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2160. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2161. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2162. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2163. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2164. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2165. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2166. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2167. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2168. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2169. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2170. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2171. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2172. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2173. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2174. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2175. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2176. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2177. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2178. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2179. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2180. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2181. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2182. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2183. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2185. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2187. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2188. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2189. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2190. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2191. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2192. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2193. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2194. (when org-agenda-mouse-1-follows-link
  2195. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2196. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2197. '("Agenda"
  2198. ("Agenda Files")
  2199. "--"
  2200. ("Agenda Dates"
  2201. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2202. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2203. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2204. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2205. "--"
  2206. ("View"
  2207. ["Day View" org-agenda-day-view
  2208. :active (org-agenda-check-type nil 'agenda)
  2209. :style radio :selected (eq org-agenda-current-span 'day)
  2210. :keys "v d (or just d)"]
  2211. ["Week View" org-agenda-week-view
  2212. :active (org-agenda-check-type nil 'agenda)
  2213. :style radio :selected (eq org-agenda-current-span 'week)
  2214. :keys "v w"]
  2215. ["Fortnight View" org-agenda-fortnight-view
  2216. :active (org-agenda-check-type nil 'agenda)
  2217. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2218. :keys "v t"]
  2219. ["Month View" org-agenda-month-view
  2220. :active (org-agenda-check-type nil 'agenda)
  2221. :style radio :selected (eq org-agenda-current-span 'month)
  2222. :keys "v m"]
  2223. ["Year View" org-agenda-year-view
  2224. :active (org-agenda-check-type nil 'agenda)
  2225. :style radio :selected (eq org-agenda-current-span 'year)
  2226. :keys "v y"]
  2227. "--"
  2228. ["Include Diary" org-agenda-toggle-diary
  2229. :style toggle :selected org-agenda-include-diary
  2230. :active (org-agenda-check-type nil 'agenda)]
  2231. ["Include Deadlines" org-agenda-toggle-deadlines
  2232. :style toggle :selected org-agenda-include-deadlines
  2233. :active (org-agenda-check-type nil 'agenda)]
  2234. ["Use Time Grid" org-agenda-toggle-time-grid
  2235. :style toggle :selected org-agenda-use-time-grid
  2236. :active (org-agenda-check-type nil 'agenda)]
  2237. "--"
  2238. ["Show clock report" org-agenda-clockreport-mode
  2239. :style toggle :selected org-agenda-clockreport-mode
  2240. :active (org-agenda-check-type nil 'agenda)]
  2241. ["Show some entry text" org-agenda-entry-text-mode
  2242. :style toggle :selected org-agenda-entry-text-mode
  2243. :active t]
  2244. "--"
  2245. ["Show Logbook entries" org-agenda-log-mode
  2246. :style toggle :selected org-agenda-show-log
  2247. :active (org-agenda-check-type nil 'agenda)
  2248. :keys "v l (or just l)"]
  2249. ["Include archived trees" org-agenda-archives-mode
  2250. :style toggle :selected org-agenda-archives-mode :active t
  2251. :keys "v a"]
  2252. ["Include archive files" (org-agenda-archives-mode t)
  2253. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2254. :keys "v A"]
  2255. "--"
  2256. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2257. ("Filter current view"
  2258. ["with generic interface" org-agenda-filter t]
  2259. "--"
  2260. ["by category at cursor" org-agenda-filter-by-category t]
  2261. ["by tag" org-agenda-filter-by-tag t]
  2262. ["by effort" org-agenda-filter-by-effort t]
  2263. ["by regexp" org-agenda-filter-by-regexp t]
  2264. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2265. "--"
  2266. ["Remove all filtering" org-agenda-filter-remove-all t]
  2267. "--"
  2268. ["limit" org-agenda-limit-interactively t])
  2269. ["Rebuild buffer" org-agenda-redo t]
  2270. ["Write view to file" org-agenda-write t]
  2271. ["Save all Org buffers" org-save-all-org-buffers t]
  2272. "--"
  2273. ["Show original entry" org-agenda-show t]
  2274. ["Go To (other window)" org-agenda-goto t]
  2275. ["Go To (this window)" org-agenda-switch-to t]
  2276. ["Capture with cursor date" org-agenda-capture t]
  2277. ["Follow Mode" org-agenda-follow-mode
  2278. :style toggle :selected org-agenda-follow-mode :active t]
  2279. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2280. "--"
  2281. ("TODO"
  2282. ["Cycle TODO" org-agenda-todo t]
  2283. ["Next TODO set" org-agenda-todo-nextset t]
  2284. ["Previous TODO set" org-agenda-todo-previousset t]
  2285. ["Add note" org-agenda-add-note t])
  2286. ("Archive/Refile/Delete"
  2287. ["Archive default" org-agenda-archive-default t]
  2288. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2289. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2290. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2291. ["Archive subtree" org-agenda-archive t]
  2292. "--"
  2293. ["Refile" org-agenda-refile t]
  2294. "--"
  2295. ["Delete subtree" org-agenda-kill t])
  2296. ("Bulk action"
  2297. ["Mark entry" org-agenda-bulk-mark t]
  2298. ["Mark all" org-agenda-bulk-mark-all t]
  2299. ["Unmark entry" org-agenda-bulk-unmark t]
  2300. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2301. ["Toggle mark" org-agenda-bulk-toggle t]
  2302. ["Toggle all" org-agenda-bulk-toggle-all t]
  2303. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2304. ["Act on all marked" org-agenda-bulk-action t]
  2305. "--"
  2306. ("Tags and Properties"
  2307. ["Show all Tags" org-agenda-show-tags t]
  2308. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2309. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2310. "--"
  2311. ["Column View" org-columns t])
  2312. ("Deadline/Schedule"
  2313. ["Schedule" org-agenda-schedule t]
  2314. ["Set Deadline" org-agenda-deadline t]
  2315. "--"
  2316. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2317. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2318. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2319. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2320. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2321. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2322. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2323. ("Clock and Effort"
  2324. ["Clock in" org-agenda-clock-in t]
  2325. ["Clock out" org-agenda-clock-out t]
  2326. ["Clock cancel" org-agenda-clock-cancel t]
  2327. ["Goto running clock" org-clock-goto t]
  2328. "--"
  2329. ["Set Effort" org-agenda-set-effort t]
  2330. ["Change clocked effort" org-clock-modify-effort-estimate
  2331. (org-clock-is-active)])
  2332. ("Priority"
  2333. ["Set Priority" org-agenda-priority t]
  2334. ["Increase Priority" org-agenda-priority-up t]
  2335. ["Decrease Priority" org-agenda-priority-down t]
  2336. ["Show Priority" org-priority-show t])
  2337. ("Calendar/Diary"
  2338. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2339. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2340. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2341. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2342. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2343. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2344. "--"
  2345. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2346. "--"
  2347. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2348. "--"
  2349. ("MobileOrg"
  2350. ["Push Files and Views" org-mobile-push t]
  2351. ["Get Captured and Flagged" org-mobile-pull t]
  2352. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2353. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2354. "--"
  2355. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2356. "--"
  2357. ["Quit" org-agenda-quit t]
  2358. ["Exit and Release Buffers" org-agenda-exit t]
  2359. ))
  2360. ;;; Agenda undo
  2361. (defvar org-agenda-allow-remote-undo t
  2362. "Non-nil means allow remote undo from the agenda buffer.")
  2363. (defvar org-agenda-undo-has-started-in nil
  2364. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2365. (defun org-agenda-undo ()
  2366. "Undo a remote editing step in the agenda.
  2367. This undoes changes both in the agenda buffer and in the remote buffer
  2368. that have been changed along."
  2369. (interactive)
  2370. (or org-agenda-allow-remote-undo
  2371. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2372. (when (not (eq this-command last-command))
  2373. (setq org-agenda-undo-has-started-in nil
  2374. org-agenda-pending-undo-list org-agenda-undo-list))
  2375. (when (not org-agenda-pending-undo-list)
  2376. (user-error "No further undo information"))
  2377. (let* ((entry (pop org-agenda-pending-undo-list))
  2378. buf line cmd rembuf)
  2379. (setq cmd (pop entry) line (pop entry))
  2380. (setq rembuf (nth 2 entry))
  2381. (org-with-remote-undo rembuf
  2382. (while (bufferp (setq buf (pop entry)))
  2383. (when (pop entry)
  2384. (with-current-buffer buf
  2385. (let (;; (last-undo-buffer buf)
  2386. (inhibit-read-only t))
  2387. (unless (memq buf org-agenda-undo-has-started-in)
  2388. (push buf org-agenda-undo-has-started-in)
  2389. (make-local-variable 'pending-undo-list)
  2390. (undo-start))
  2391. (while (and pending-undo-list
  2392. (listp pending-undo-list)
  2393. (not (car pending-undo-list)))
  2394. (pop pending-undo-list))
  2395. (undo-more 1))))))
  2396. (org-goto-line line)
  2397. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2398. (defun org-verify-change-for-undo (l1 l2)
  2399. "Verify that a real change occurred between the undo lists L1 and L2."
  2400. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2401. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2402. (not (eq l1 l2)))
  2403. ;;; Agenda dispatch
  2404. (defvar org-agenda-restrict-begin (make-marker))
  2405. (defvar org-agenda-restrict-end (make-marker))
  2406. (defvar org-agenda-last-dispatch-buffer nil)
  2407. (defvar org-agenda-overriding-restriction nil)
  2408. (defcustom org-agenda-custom-commands-contexts nil
  2409. "Alist of custom agenda keys and contextual rules.
  2410. For example, if you have a custom agenda command \"p\" and you
  2411. want this command to be accessible only from plain text files,
  2412. use this:
  2413. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2414. Here are the available contexts definitions:
  2415. in-file: command displayed only in matching files
  2416. in-mode: command displayed only in matching modes
  2417. not-in-file: command not displayed in matching files
  2418. not-in-mode: command not displayed in matching modes
  2419. in-buffer: command displayed only in matching buffers
  2420. not-in-buffer: command not displayed in matching buffers
  2421. [function]: a custom function taking no argument
  2422. If you define several checks, the agenda command will be
  2423. accessible if there is at least one valid check.
  2424. You can also bind a key to another agenda custom command
  2425. depending on contextual rules.
  2426. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2427. Here it means: in .txt files, use \"p\" as the key for the
  2428. agenda command otherwise associated with \"q\". (The command
  2429. originally associated with \"q\" is not displayed to avoid
  2430. duplicates.)"
  2431. :version "24.3"
  2432. :group 'org-agenda-custom-commands
  2433. :type '(repeat (list :tag "Rule"
  2434. (string :tag " Agenda key")
  2435. (string :tag "Replace by command")
  2436. (repeat :tag "Available when"
  2437. (choice
  2438. (cons :tag "Condition"
  2439. (choice
  2440. (const :tag "In file" in-file)
  2441. (const :tag "Not in file" not-in-file)
  2442. (const :tag "In buffer" in-buffer)
  2443. (const :tag "Not in buffer" not-in-buffer)
  2444. (const :tag "In mode" in-mode)
  2445. (const :tag "Not in mode" not-in-mode))
  2446. (regexp))
  2447. (function :tag "Custom function"))))))
  2448. (defcustom org-agenda-max-entries nil
  2449. "Maximum number of entries to display in an agenda.
  2450. This can be nil (no limit) or an integer or an alist of agenda
  2451. types with an associated number of entries to display in this
  2452. type."
  2453. :version "24.4"
  2454. :package-version '(Org . "8.0")
  2455. :group 'org-agenda-custom-commands
  2456. :type '(choice (symbol :tag "No limit" nil)
  2457. (integer :tag "Max number of entries")
  2458. (repeat
  2459. (cons (choice :tag "Agenda type"
  2460. (const agenda)
  2461. (const todo)
  2462. (const tags)
  2463. (const search))
  2464. (integer :tag "Max number of entries")))))
  2465. (defcustom org-agenda-max-todos nil
  2466. "Maximum number of TODOs to display in an agenda.
  2467. This can be nil (no limit) or an integer or an alist of agenda
  2468. types with an associated number of entries to display in this
  2469. type."
  2470. :version "24.4"
  2471. :package-version '(Org . "8.0")
  2472. :group 'org-agenda-custom-commands
  2473. :type '(choice (symbol :tag "No limit" nil)
  2474. (integer :tag "Max number of TODOs")
  2475. (repeat
  2476. (cons (choice :tag "Agenda type"
  2477. (const agenda)
  2478. (const todo)
  2479. (const tags)
  2480. (const search))
  2481. (integer :tag "Max number of TODOs")))))
  2482. (defcustom org-agenda-max-tags nil
  2483. "Maximum number of tagged entries to display in an agenda.
  2484. This can be nil (no limit) or an integer or an alist of agenda
  2485. types with an associated number of entries to display in this
  2486. type."
  2487. :version "24.4"
  2488. :package-version '(Org . "8.0")
  2489. :group 'org-agenda-custom-commands
  2490. :type '(choice (symbol :tag "No limit" nil)
  2491. (integer :tag "Max number of tagged entries")
  2492. (repeat
  2493. (cons (choice :tag "Agenda type"
  2494. (const agenda)
  2495. (const todo)
  2496. (const tags)
  2497. (const search))
  2498. (integer :tag "Max number of tagged entries")))))
  2499. (defcustom org-agenda-max-effort nil
  2500. "Maximum cumulated effort duration for the agenda.
  2501. This can be nil (no limit) or a number of minutes (as an integer)
  2502. or an alist of agenda types with an associated number of minutes
  2503. to limit entries to in this type."
  2504. :version "24.4"
  2505. :package-version '(Org . "8.0")
  2506. :group 'org-agenda-custom-commands
  2507. :type '(choice (symbol :tag "No limit" nil)
  2508. (integer :tag "Max number of minutes")
  2509. (repeat
  2510. (cons (choice :tag "Agenda type"
  2511. (const agenda)
  2512. (const todo)
  2513. (const tags)
  2514. (const search))
  2515. (integer :tag "Max number of minutes")))))
  2516. (defvar org-agenda-keep-restricted-file-list nil)
  2517. (defvar org-keys nil)
  2518. (defvar org-match nil)
  2519. ;;;###autoload
  2520. (defun org-agenda (&optional arg keys restriction)
  2521. "Dispatch agenda commands to collect entries to the agenda buffer.
  2522. Prompts for a command to execute. Any prefix arg will be passed
  2523. on to the selected command. The default selections are:
  2524. a Call `org-agenda-list' to display the agenda for current day or week.
  2525. t Call `org-todo-list' to display the global todo list.
  2526. T Call `org-todo-list' to display the global todo list, select only
  2527. entries with a specific TODO keyword (the user gets a prompt).
  2528. m Call `org-tags-view' to display headlines with tags matching
  2529. a condition (the user is prompted for the condition).
  2530. M Like `m', but select only TODO entries, no ordinary headlines.
  2531. e Export views to associated files.
  2532. s Search entries for keywords.
  2533. S Search entries for keywords, only with TODO keywords.
  2534. / Multi occur across all agenda files and also files listed
  2535. in `org-agenda-text-search-extra-files'.
  2536. < Restrict agenda commands to buffer, subtree, or region.
  2537. Press several times to get the desired effect.
  2538. > Remove a previous restriction.
  2539. # List \"stuck\" projects.
  2540. ! Configure what \"stuck\" means.
  2541. C Configure custom agenda commands.
  2542. More commands can be added by configuring the variable
  2543. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2544. searches can be pre-defined in this way.
  2545. If the current buffer is in Org mode and visiting a file, you can also
  2546. first press `<' once to indicate that the agenda should be temporarily
  2547. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2548. Pressing `<' twice means to restrict to the current subtree or region
  2549. \(if active)."
  2550. (interactive "P")
  2551. (catch 'exit
  2552. (let* ((org-keys keys)
  2553. (prefix-descriptions nil)
  2554. (org-agenda-buffer-name org-agenda-buffer-name)
  2555. (org-agenda-window-setup (if (equal (buffer-name)
  2556. org-agenda-buffer-name)
  2557. 'current-window
  2558. org-agenda-window-setup))
  2559. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2560. (org-agenda-custom-commands
  2561. ;; normalize different versions
  2562. (delq nil
  2563. (mapcar
  2564. (lambda (x)
  2565. (cond ((stringp (cdr x))
  2566. (push x prefix-descriptions)
  2567. nil)
  2568. ((stringp (nth 1 x)) x)
  2569. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2570. (t (cons (car x) (cons "" (cdr x))))))
  2571. org-agenda-custom-commands)))
  2572. (org-agenda-custom-commands
  2573. (org-contextualize-keys
  2574. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2575. ;; (buf (current-buffer))
  2576. (bfn (buffer-file-name (buffer-base-buffer)))
  2577. entry type org-match lprops ans) ;; key
  2578. ;; Turn off restriction unless there is an overriding one,
  2579. (unless org-agenda-overriding-restriction
  2580. (unless org-agenda-keep-restricted-file-list
  2581. ;; There is a request to keep the file list in place
  2582. (put 'org-agenda-files 'org-restrict nil))
  2583. (setq org-agenda-restrict nil)
  2584. (move-marker org-agenda-restrict-begin nil)
  2585. (move-marker org-agenda-restrict-end nil))
  2586. ;; Delete old local properties
  2587. (put 'org-agenda-redo-command 'org-lprops nil)
  2588. ;; Delete previously set last-arguments
  2589. (put 'org-agenda-redo-command 'last-args nil)
  2590. ;; Remember where this call originated
  2591. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2592. (unless org-keys
  2593. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2594. org-keys (car ans)
  2595. restriction (cdr ans)))
  2596. ;; If we have sticky agenda buffers, set a name for the buffer,
  2597. ;; depending on the invoking keys. The user may still set this
  2598. ;; as a command option, which will overwrite what we do here.
  2599. (when org-agenda-sticky
  2600. (setq org-agenda-buffer-name
  2601. (format "*Org Agenda(%s)*" org-keys)))
  2602. ;; Establish the restriction, if any
  2603. (when (and (not org-agenda-overriding-restriction) restriction)
  2604. (put 'org-agenda-files 'org-restrict (list bfn))
  2605. (cond
  2606. ((eq restriction 'region)
  2607. (setq org-agenda-restrict (current-buffer))
  2608. (move-marker org-agenda-restrict-begin (region-beginning))
  2609. (move-marker org-agenda-restrict-end (region-end)))
  2610. ((eq restriction 'subtree)
  2611. (save-excursion
  2612. (setq org-agenda-restrict (current-buffer))
  2613. (org-back-to-heading t)
  2614. (move-marker org-agenda-restrict-begin (point))
  2615. (move-marker org-agenda-restrict-end
  2616. (progn (org-end-of-subtree t)))))
  2617. ((and (eq restriction 'buffer)
  2618. (or (< 1 (point-min))
  2619. (< (point-max) (1+ (buffer-size)))))
  2620. (setq org-agenda-restrict (current-buffer))
  2621. (move-marker org-agenda-restrict-begin (point-min))
  2622. (move-marker org-agenda-restrict-end (point-max)))))
  2623. ;; For example the todo list should not need it (but does...)
  2624. (cond
  2625. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2626. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2627. (progn
  2628. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2629. ;; to some of the local variables? There's no doc about
  2630. ;; that for `org-agenda-custom-commands'.
  2631. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2632. lprops (nth 4 entry))
  2633. (when org-agenda-sticky
  2634. (setq org-agenda-buffer-name
  2635. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2636. (format "*Org Agenda(%s)*" org-keys))))
  2637. (put 'org-agenda-redo-command 'org-lprops lprops)
  2638. (cl-progv
  2639. (mapcar #'car lprops)
  2640. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2641. (pcase type
  2642. (`agenda
  2643. (org-agenda-list current-prefix-arg))
  2644. (`agenda*
  2645. (org-agenda-list current-prefix-arg nil nil t))
  2646. (`alltodo
  2647. (org-todo-list current-prefix-arg))
  2648. (`search
  2649. (org-search-view current-prefix-arg org-match nil))
  2650. (`stuck
  2651. (org-agenda-list-stuck-projects current-prefix-arg))
  2652. (`tags
  2653. (org-tags-view current-prefix-arg org-match))
  2654. (`tags-todo
  2655. (org-tags-view '(4) org-match))
  2656. (`todo
  2657. (org-todo-list org-match))
  2658. (`tags-tree
  2659. (org-check-for-org-mode)
  2660. (org-match-sparse-tree current-prefix-arg org-match))
  2661. (`todo-tree
  2662. (org-check-for-org-mode)
  2663. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2664. (regexp-quote org-match) "\\>")))
  2665. (`occur-tree
  2666. (org-check-for-org-mode)
  2667. (org-occur org-match))
  2668. ((pred functionp)
  2669. (funcall type org-match))
  2670. ;; FIXME: Will signal an error since it's not `functionp'!
  2671. ((pred fboundp) (funcall type org-match))
  2672. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2673. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2674. ((equal org-keys "C")
  2675. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2676. (customize-variable 'org-agenda-custom-commands))
  2677. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2678. ((equal org-keys "s") (call-interactively 'org-search-view))
  2679. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2680. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2681. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2682. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2683. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2684. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2685. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2686. (add-hook
  2687. 'post-command-hook
  2688. (lambda ()
  2689. (unless (current-message)
  2690. (let* ((m (org-agenda-get-any-marker))
  2691. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2692. (when note
  2693. (message "FLAGGING-NOTE ([?] for more info): %s"
  2694. (org-add-props
  2695. (replace-regexp-in-string
  2696. "\\\\n" "//"
  2697. (copy-sequence note))
  2698. nil 'face 'org-warning))))))
  2699. t t))
  2700. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2701. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2702. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2703. (t (user-error "Invalid agenda key"))))))
  2704. (defvar org-agenda-multi)
  2705. (defun org-agenda-append-agenda ()
  2706. "Append another agenda view to the current one.
  2707. This function allows interactive building of block agendas.
  2708. Agenda views are separated by `org-agenda-block-separator'."
  2709. (interactive)
  2710. (unless (derived-mode-p 'org-agenda-mode)
  2711. (user-error "Can only append from within agenda buffer"))
  2712. (let ((org-agenda-multi t))
  2713. (org-agenda)
  2714. (widen)
  2715. (org-agenda-finalize)
  2716. (setq buffer-read-only t)
  2717. (org-agenda-fit-window-to-buffer)))
  2718. (defun org-agenda-normalize-custom-commands (cmds)
  2719. "Normalize custom commands CMDS."
  2720. (delq nil
  2721. (mapcar
  2722. (lambda (x)
  2723. (cond ((stringp (cdr x)) nil)
  2724. ((stringp (nth 1 x)) x)
  2725. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2726. (t (cons (car x) (cons "" (cdr x))))))
  2727. cmds)))
  2728. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2729. "The user interface for selecting an agenda command."
  2730. (catch 'exit
  2731. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2732. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2733. (region-p (org-region-active-p))
  2734. (custom org-agenda-custom-commands)
  2735. (selstring "")
  2736. restriction second-time
  2737. c entry key type match prefixes rmheader header-end custom1 desc
  2738. line lines left right n n1)
  2739. (save-window-excursion
  2740. (delete-other-windows)
  2741. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2742. (erase-buffer)
  2743. (insert (eval-when-compile
  2744. (let ((header
  2745. (copy-sequence
  2746. "Press key for an agenda command:
  2747. -------------------------------- < Buffer, subtree/region restriction
  2748. a Agenda for current week or day > Remove restriction
  2749. t List of all TODO entries e Export agenda views
  2750. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2751. s Search for keywords M Like m, but only TODO entries
  2752. / Multi-occur S Like s, but only TODO entries
  2753. ? Find :FLAGGED: entries C Configure custom agenda commands
  2754. * Toggle sticky agenda views # List stuck projects (!=configure)
  2755. "))
  2756. (start 0))
  2757. (while (string-match
  2758. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2759. header start)
  2760. (setq start (match-end 0))
  2761. (add-text-properties (match-beginning 2) (match-end 2)
  2762. '(face bold) header))
  2763. header)))
  2764. (setq header-end (point-marker))
  2765. (while t
  2766. (setq custom1 custom)
  2767. (when (eq rmheader t)
  2768. (org-goto-line 1)
  2769. (re-search-forward ":" nil t)
  2770. (delete-region (match-end 0) (point-at-eol))
  2771. (forward-char 1)
  2772. (looking-at "-+")
  2773. (delete-region (match-end 0) (point-at-eol))
  2774. (move-marker header-end (match-end 0)))
  2775. (goto-char header-end)
  2776. (delete-region (point) (point-max))
  2777. ;; Produce all the lines that describe custom commands and prefixes
  2778. (setq lines nil)
  2779. (while (setq entry (pop custom1))
  2780. (setq key (car entry) desc (nth 1 entry)
  2781. type (nth 2 entry)
  2782. match (nth 3 entry))
  2783. (if (> (length key) 1)
  2784. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2785. (setq line
  2786. (format
  2787. "%-4s%-14s"
  2788. (org-add-props (copy-sequence key)
  2789. '(face bold))
  2790. (cond
  2791. ((string-match "\\S-" desc) desc)
  2792. ((eq type 'agenda) "Agenda for current week or day")
  2793. ((eq type 'agenda*) "Appointments for current week or day")
  2794. ((eq type 'alltodo) "List of all TODO entries")
  2795. ((eq type 'search) "Word search")
  2796. ((eq type 'stuck) "List of stuck projects")
  2797. ((eq type 'todo) "TODO keyword")
  2798. ((eq type 'tags) "Tags query")
  2799. ((eq type 'tags-todo) "Tags (TODO)")
  2800. ((eq type 'tags-tree) "Tags tree")
  2801. ((eq type 'todo-tree) "TODO kwd tree")
  2802. ((eq type 'occur-tree) "Occur tree")
  2803. ((functionp type) (if (symbolp type)
  2804. (symbol-name type)
  2805. "Lambda expression"))
  2806. (t "???"))))
  2807. (cond
  2808. ((not (org-string-nw-p match)) nil)
  2809. (org-agenda-menu-show-matcher
  2810. (setq line
  2811. (concat line ": "
  2812. (cond
  2813. ((stringp match)
  2814. (propertize match 'face 'org-warning))
  2815. ((listp type)
  2816. (format "set of %d commands" (length type)))))))
  2817. (t
  2818. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2819. (push line lines)))
  2820. (setq lines (nreverse lines))
  2821. (when prefixes
  2822. (mapc (lambda (x)
  2823. (push
  2824. (format "%s %s"
  2825. (org-add-props (char-to-string x)
  2826. nil 'face 'bold)
  2827. (or (cdr (assoc (concat selstring
  2828. (char-to-string x))
  2829. prefix-descriptions))
  2830. "Prefix key"))
  2831. lines))
  2832. prefixes))
  2833. ;; Check if we should display in two columns
  2834. (if org-agenda-menu-two-columns
  2835. (progn
  2836. (setq n (length lines)
  2837. n1 (+ (/ n 2) (mod n 2))
  2838. right (nthcdr n1 lines)
  2839. left (copy-sequence lines))
  2840. (setcdr (nthcdr (1- n1) left) nil))
  2841. (setq left lines right nil))
  2842. (while left
  2843. (insert "\n" (pop left))
  2844. (when right
  2845. (if (< (current-column) 40)
  2846. (move-to-column 40 t)
  2847. (insert " "))
  2848. (insert (pop right))))
  2849. ;; Make the window the right size
  2850. (goto-char (point-min))
  2851. (if second-time
  2852. (when (not (pos-visible-in-window-p (point-max)))
  2853. (org-fit-window-to-buffer))
  2854. (setq second-time t)
  2855. (org-fit-window-to-buffer))
  2856. ;; Hint to navigation if window too small for all information
  2857. (setq header-line-format
  2858. (when (not (pos-visible-in-window-p (point-max)))
  2859. "Use C-v, M-v, C-n or C-p to navigate."))
  2860. ;; Ask for selection
  2861. (cl-loop
  2862. do (progn
  2863. (message "Press key for agenda command%s:"
  2864. (if (or restrict-ok org-agenda-overriding-restriction)
  2865. (if org-agenda-overriding-restriction
  2866. " (restriction lock active)"
  2867. (if restriction
  2868. (format " (restricted to %s)" restriction)
  2869. " (unrestricted)"))
  2870. ""))
  2871. (setq c (read-char-exclusive)))
  2872. until (not (memq c '(14 16 22 134217846)))
  2873. do (org-scroll c))
  2874. (message "")
  2875. (cond
  2876. ((assoc (char-to-string c) custom)
  2877. (setq selstring (concat selstring (char-to-string c)))
  2878. (throw 'exit (cons selstring restriction)))
  2879. ((memq c prefixes)
  2880. (setq selstring (concat selstring (char-to-string c))
  2881. prefixes nil
  2882. rmheader (or rmheader t)
  2883. custom (delq nil (mapcar
  2884. (lambda (x)
  2885. (if (or (= (length (car x)) 1)
  2886. (/= (string-to-char (car x)) c))
  2887. nil
  2888. (cons (substring (car x) 1) (cdr x))))
  2889. custom))))
  2890. ((eq c ?*)
  2891. (call-interactively 'org-toggle-sticky-agenda)
  2892. (sit-for 2))
  2893. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2894. (message "Restriction is only possible in Org buffers")
  2895. (ding) (sit-for 1))
  2896. ((eq c ?1)
  2897. (org-agenda-remove-restriction-lock 'noupdate)
  2898. (setq restriction 'buffer))
  2899. ((eq c ?0)
  2900. (org-agenda-remove-restriction-lock 'noupdate)
  2901. (setq restriction (if region-p 'region 'subtree)))
  2902. ((eq c ?<)
  2903. (org-agenda-remove-restriction-lock 'noupdate)
  2904. (setq restriction
  2905. (cond
  2906. ((eq restriction 'buffer)
  2907. (if region-p 'region 'subtree))
  2908. ((memq restriction '(subtree region))
  2909. nil)
  2910. (t 'buffer))))
  2911. ((eq c ?>)
  2912. (org-agenda-remove-restriction-lock 'noupdate)
  2913. (setq restriction nil))
  2914. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2915. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2916. ((and (> (length selstring) 0) (eq c ?\d))
  2917. (delete-window)
  2918. (org-agenda-get-restriction-and-command prefix-descriptions))
  2919. ((equal c ?q) (user-error "Abort"))
  2920. (t (user-error "Invalid key %c" c))))))))
  2921. (defun org-agenda-fit-window-to-buffer ()
  2922. "Fit the window to the buffer size."
  2923. (and (memq org-agenda-window-setup '(reorganize-frame))
  2924. (fboundp 'fit-window-to-buffer)
  2925. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2926. (= (car org-agenda-window-frame-fractions) 1.0))
  2927. (delete-other-windows)
  2928. (org-fit-window-to-buffer
  2929. nil
  2930. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2931. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2932. (defvar org-cmd nil)
  2933. (defvar org-agenda-overriding-cmd nil)
  2934. (defvar org-agenda-overriding-arguments nil)
  2935. (defvar org-agenda-overriding-cmd-arguments nil)
  2936. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2937. (declare (indent 1) (obsolete cl-progv "2021"))
  2938. (eval (cons 'let (cons list body))))
  2939. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2940. (declare (indent 2) (obsolete cl-progv "2021"))
  2941. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2942. (defun org-agenda-run-series (name series)
  2943. "Run agenda NAME as a SERIES of agenda commands."
  2944. (let* ((gprops (nth 1 series))
  2945. (gvars (mapcar #'car gprops))
  2946. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2947. (cl-progv gvars gvals (org-agenda-prepare name))
  2948. ;; We need to reset agenda markers here, because when constructing a
  2949. ;; block agenda, the individual blocks do not do that.
  2950. (org-agenda-reset-markers)
  2951. (with-no-warnings
  2952. (defvar match)) ;Used via the `eval' below.
  2953. (let* ((org-agenda-multi t)
  2954. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2955. ;; than expressions, so you don't need to `quote' the args
  2956. ;; and you just need to `apply' instead of `eval' when using it.
  2957. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2958. (cmds (car series))
  2959. match
  2960. org-cmd type lprops)
  2961. (while (setq org-cmd (pop cmds))
  2962. (setq type (car org-cmd))
  2963. (setq match (eval (nth 1 org-cmd) t))
  2964. (setq lprops (nth 2 org-cmd))
  2965. (let ((org-agenda-overriding-arguments
  2966. (if (eq org-agenda-overriding-cmd org-cmd)
  2967. (or org-agenda-overriding-arguments
  2968. org-agenda-overriding-cmd-arguments)))
  2969. (lvars (mapcar #'car lprops))
  2970. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2971. (cl-progv (append gvars lvars) (append gvals lvals)
  2972. (pcase type
  2973. (`agenda
  2974. (call-interactively 'org-agenda-list))
  2975. (`agenda*
  2976. (funcall 'org-agenda-list nil nil t))
  2977. (`alltodo
  2978. (call-interactively 'org-todo-list))
  2979. (`search
  2980. (org-search-view current-prefix-arg match nil))
  2981. (`stuck
  2982. (call-interactively 'org-agenda-list-stuck-projects))
  2983. (`tags
  2984. (org-tags-view current-prefix-arg match))
  2985. (`tags-todo
  2986. (org-tags-view '(4) match))
  2987. (`todo
  2988. (org-todo-list match))
  2989. ((pred fboundp)
  2990. (funcall type match))
  2991. (_ (error "Invalid type in command series"))))))
  2992. (widen)
  2993. (let ((inhibit-read-only t))
  2994. (add-text-properties (point-min) (point-max)
  2995. `(org-series t org-series-redo-cmd ,redo)))
  2996. (setq org-agenda-redo-command redo)
  2997. (goto-char (point-min)))
  2998. (org-agenda-fit-window-to-buffer)
  2999. (cl-progv gvars gvals (org-agenda-finalize))))
  3000. (defun org-agenda--split-plist (plist)
  3001. ;; We could/should arguably use `map-keys' and `map-values'.
  3002. (let (keys vals)
  3003. (while plist
  3004. (push (pop plist) keys)
  3005. (push (pop plist) vals))
  3006. (cons (nreverse keys) (nreverse vals))))
  3007. ;;;###autoload
  3008. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3009. "Run an agenda command in batch mode and send the result to STDOUT.
  3010. If CMD-KEY is a string of length 1, it is used as a key in
  3011. `org-agenda-custom-commands' and triggers this command. If it is a
  3012. longer string it is used as a tags/todo match string.
  3013. Parameters are alternating variable names and values that will be bound
  3014. before running the agenda command."
  3015. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3016. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3017. (defun org--batch-agenda (cmd-key vars vals)
  3018. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3019. ;; a variable name rather than an expression to evaluate. Yuck!
  3020. (cl-progv vars vals
  3021. (let (org-agenda-sticky)
  3022. (if (> (length cmd-key) 1)
  3023. (org-tags-view nil cmd-key)
  3024. (org-agenda nil cmd-key))))
  3025. (set-buffer org-agenda-buffer-name)
  3026. (princ (buffer-string)))
  3027. (defvar org-agenda-info nil)
  3028. ;;;###autoload
  3029. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3030. "Run an agenda command in batch mode and send the result to STDOUT.
  3031. If CMD-KEY is a string of length 1, it is used as a key in
  3032. `org-agenda-custom-commands' and triggers this command. If it is a
  3033. longer string it is used as a tags/todo match string.
  3034. Parameters are alternating variable names and values that will be bound
  3035. before running the agenda command.
  3036. The output gives a line for each selected agenda item. Each
  3037. item is a list of comma-separated values, like this:
  3038. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3039. category The category of the item
  3040. head The headline, without TODO kwd, TAGS and PRIORITY
  3041. type The type of the agenda entry, can be
  3042. todo selected in TODO match
  3043. tagsmatch selected in tags match
  3044. diary imported from diary
  3045. deadline a deadline on given date
  3046. scheduled scheduled on given date
  3047. timestamp entry has timestamp on given date
  3048. closed entry was closed on given date
  3049. upcoming-deadline warning about deadline
  3050. past-scheduled forwarded scheduled item
  3051. block entry has date block including g. date
  3052. todo The todo keyword, if any
  3053. tags All tags including inherited ones, separated by colons
  3054. date The relevant date, like 2007-2-14
  3055. time The time, like 15:00-16:50
  3056. extra String with extra planning info
  3057. priority-l The priority letter if any was given
  3058. priority-n The computed numerical priority
  3059. agenda-day The day in the agenda where this is listed"
  3060. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3061. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3062. (defun org--batch-agenda-csv (cmd-key vars vals)
  3063. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3064. ;; a variable name rather than an expression to evaluate. Yuck!
  3065. (let ((org-agenda-remove-tags t))
  3066. (cl-progv vars vals
  3067. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3068. (if (> (length cmd-key) 2)
  3069. (org-tags-view nil cmd-key)
  3070. (org-agenda nil cmd-key))))
  3071. (set-buffer org-agenda-buffer-name)
  3072. (let ((lines (org-split-string (buffer-string) "\n")))
  3073. (dolist (line lines)
  3074. (when (get-text-property 0 'org-category line)
  3075. (setq org-agenda-info
  3076. (org-fix-agenda-info (text-properties-at 0 line)))
  3077. (princ
  3078. (mapconcat #'org-agenda-export-csv-mapper
  3079. '(org-category txt type todo tags date time extra
  3080. priority-letter priority agenda-day)
  3081. ","))
  3082. (princ "\n")))))
  3083. (defun org-fix-agenda-info (props)
  3084. "Make sure all properties on an agenda item have a canonical form.
  3085. This ensures the export commands can easily use it."
  3086. (let (tmp re)
  3087. (when (setq tmp (plist-get props 'tags))
  3088. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3089. (when (setq tmp (plist-get props 'date))
  3090. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3091. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3092. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3093. (setq tmp (calendar-date-string tmp)))
  3094. (setq props (plist-put props 'date tmp)))
  3095. (when (setq tmp (plist-get props 'day))
  3096. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3097. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3098. (setq tmp (calendar-date-string tmp)))
  3099. (setq props (plist-put props 'day tmp))
  3100. (setq props (plist-put props 'agenda-day tmp)))
  3101. (when (setq tmp (plist-get props 'txt))
  3102. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3103. (plist-put props 'priority-letter (match-string 1 tmp))
  3104. (setq tmp (replace-match "" t t tmp)))
  3105. (when (and (setq re (plist-get props 'org-todo-regexp))
  3106. (setq re (concat "\\`\\.*" re " ?"))
  3107. (let ((case-fold-search nil)) (string-match re tmp)))
  3108. (plist-put props 'todo (match-string 1 tmp))
  3109. (setq tmp (replace-match "" t t tmp)))
  3110. (plist-put props 'txt tmp)))
  3111. props)
  3112. (defun org-agenda-export-csv-mapper (prop)
  3113. (let ((res (plist-get org-agenda-info prop)))
  3114. (setq res
  3115. (cond
  3116. ((not res) "")
  3117. ((stringp res) res)
  3118. (t (prin1-to-string res))))
  3119. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3120. ;;;###autoload
  3121. (defun org-store-agenda-views (&rest _parameters)
  3122. "Store agenda views."
  3123. (interactive)
  3124. (org--batch-store-agenda-views nil nil))
  3125. ;;;###autoload
  3126. (defmacro org-batch-store-agenda-views (&rest parameters)
  3127. "Run all custom agenda commands that have a file argument."
  3128. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3129. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3130. (defun org--batch-store-agenda-views (vars vals)
  3131. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3132. (pop-up-frames nil)
  3133. (dir default-directory)
  3134. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3135. (save-window-excursion
  3136. (while cmds
  3137. (setq cmd (pop cmds)
  3138. thiscmdkey (car cmd)
  3139. thiscmdcmd (cdr cmd)
  3140. match (nth 2 thiscmdcmd)
  3141. bufname (if org-agenda-sticky
  3142. (or (and (stringp match)
  3143. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3144. (format "*Org Agenda(%s)*" thiscmdkey))
  3145. org-agenda-buffer-name)
  3146. cmd-or-set (nth 2 cmd)
  3147. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3148. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3149. (if (stringp files) (setq files (list files)))
  3150. (when files
  3151. (let* ((opts (append org-agenda-exporter-settings opts))
  3152. (vars (append (mapcar #'car opts) vars))
  3153. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3154. opts)
  3155. vals)))
  3156. (cl-progv vars vals
  3157. (org-agenda nil thiscmdkey))
  3158. (set-buffer bufname)
  3159. (while files
  3160. (cl-progv vars vals
  3161. (org-agenda-write (expand-file-name (pop files) dir)
  3162. nil t bufname))))
  3163. (and (get-buffer bufname)
  3164. (kill-buffer bufname)))))))
  3165. (defvar org-agenda-current-span nil
  3166. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3167. (defun org-agenda-mark-header-line (pos)
  3168. "Mark the line at POS as an agenda structure header."
  3169. (save-excursion
  3170. (goto-char pos)
  3171. (put-text-property (point-at-bol) (point-at-eol)
  3172. 'org-agenda-structural-header t)
  3173. (when org-agenda-title-append
  3174. (put-text-property (point-at-bol) (point-at-eol)
  3175. 'org-agenda-title-append org-agenda-title-append))))
  3176. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3177. (defvar org-agenda-write-buffer-name "Agenda View")
  3178. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3179. "Write the current buffer (an agenda view) as a file.
  3180. Depending on the extension of the file name, plain text (.txt),
  3181. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3182. If the extension is .ics, translate visible agenda into iCalendar
  3183. format. If the extension is .org, collect all subtrees
  3184. corresponding to the agenda entries and add them in an .org file.
  3185. With prefix argument OPEN, open the new file immediately. If
  3186. NOSETTINGS is given, do not scope the settings of
  3187. `org-agenda-exporter-settings' into the export commands. This is
  3188. used when the settings have already been scoped and we do not
  3189. wish to overrule other, higher priority settings. If
  3190. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3191. the agenda to write."
  3192. (interactive "FWrite agenda to file: \nP")
  3193. (if (or (not (file-writable-p file))
  3194. (and (file-exists-p file)
  3195. (if (called-interactively-p 'any)
  3196. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3197. (user-error "Cannot write agenda to file %s" file))
  3198. (cl-progv
  3199. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3200. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3201. org-agenda-exporter-settings))
  3202. (save-excursion
  3203. (save-window-excursion
  3204. (let ((bs (copy-sequence (buffer-string)))
  3205. (extension (file-name-extension file))
  3206. (default-directory (file-name-directory file))
  3207. ) ;; beg content
  3208. (with-temp-buffer
  3209. (rename-buffer org-agenda-write-buffer-name t)
  3210. (set-buffer-modified-p nil)
  3211. (insert bs)
  3212. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3213. (run-hooks 'org-agenda-before-write-hook)
  3214. (cond
  3215. ((bound-and-true-p org-mobile-creating-agendas)
  3216. (org-mobile-write-agenda-for-mobile file))
  3217. ((string= "org" extension)
  3218. (let (content p m message-log-max)
  3219. (goto-char (point-min))
  3220. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3221. (goto-char p)
  3222. (setq m (get-text-property (point) 'org-hd-marker))
  3223. (when m
  3224. (push (with-current-buffer (marker-buffer m)
  3225. (goto-char m)
  3226. (org-copy-subtree 1 nil t t)
  3227. org-subtree-clip)
  3228. content)))
  3229. (find-file file)
  3230. (erase-buffer)
  3231. (dolist (s content) (org-paste-subtree 1 s))
  3232. (write-file file)
  3233. (kill-buffer (current-buffer))
  3234. (message "Org file written to %s" file)))
  3235. ((member extension '("html" "htm"))
  3236. (or (require 'htmlize nil t)
  3237. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3238. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3239. (set-buffer (htmlize-buffer (current-buffer)))
  3240. (when org-agenda-export-html-style
  3241. ;; replace <style> section with org-agenda-export-html-style
  3242. (goto-char (point-min))
  3243. (kill-region (- (search-forward "<style") 6)
  3244. (search-forward "</style>"))
  3245. (insert org-agenda-export-html-style))
  3246. (write-file file)
  3247. (kill-buffer (current-buffer))
  3248. (message "HTML written to %s" file))
  3249. ((string= "ps" extension)
  3250. (require 'ps-print)
  3251. (ps-print-buffer-with-faces file)
  3252. (message "Postscript written to %s" file))
  3253. ((string= "pdf" extension)
  3254. (require 'ps-print)
  3255. (ps-print-buffer-with-faces
  3256. (concat (file-name-sans-extension file) ".ps"))
  3257. (call-process "ps2pdf" nil nil nil
  3258. (expand-file-name
  3259. (concat (file-name-sans-extension file) ".ps"))
  3260. (expand-file-name file))
  3261. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3262. (message "PDF written to %s" file))
  3263. ((string= "ics" extension)
  3264. (require 'ox-icalendar)
  3265. (declare-function org-icalendar-export-current-agenda
  3266. "ox-icalendar" (file))
  3267. (org-icalendar-export-current-agenda (expand-file-name file)))
  3268. (t
  3269. (let ((bs (buffer-string)))
  3270. (find-file file)
  3271. (erase-buffer)
  3272. (insert bs)
  3273. (save-buffer 0)
  3274. (kill-buffer (current-buffer))
  3275. (message "Plain text written to %s" file))))))))
  3276. (set-buffer (or agenda-bufname
  3277. ;; FIXME: I'm pretty sure called-interactively-p
  3278. ;; doesn't do what we want here!
  3279. (and (called-interactively-p 'any) (buffer-name))
  3280. org-agenda-buffer-name)))
  3281. (when open (org-open-file file)))
  3282. (defun org-agenda-remove-marked-text (property &optional value)
  3283. "Delete all text marked with VALUE of PROPERTY.
  3284. VALUE defaults to t."
  3285. (let (beg)
  3286. (setq value (or value t))
  3287. (while (setq beg (text-property-any (point-min) (point-max)
  3288. property value))
  3289. (delete-region
  3290. beg (or (next-single-property-change beg property)
  3291. (point-max))))))
  3292. (defun org-agenda-add-entry-text ()
  3293. "Add entry text to agenda lines.
  3294. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3295. entry text following headings shown in the agenda.
  3296. Drawers will be excluded, also the line with scheduling/deadline info."
  3297. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3298. (not (bound-and-true-p org-mobile-creating-agendas)))
  3299. (let (m txt)
  3300. (goto-char (point-min))
  3301. (while (not (eobp))
  3302. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3303. (beginning-of-line 2)
  3304. (setq txt (org-agenda-get-some-entry-text
  3305. m org-agenda-add-entry-text-maxlines " > "))
  3306. (end-of-line 1)
  3307. (if (string-match "\\S-" txt)
  3308. (insert "\n" txt)
  3309. (or (eobp) (forward-char 1))))))))
  3310. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3311. &rest keep)
  3312. "Extract entry text from MARKER, at most N-LINES lines.
  3313. This will ignore drawers etc, just get the text.
  3314. If INDENT is given, prefix every line with this string. If KEEP is
  3315. given, it is a list of symbols, defining stuff that should not be
  3316. removed from the entry content. Currently only `planning' is allowed here."
  3317. (let (txt drawer-re kwd-time-re ind)
  3318. (save-excursion
  3319. (with-current-buffer (marker-buffer marker)
  3320. (if (not (derived-mode-p 'org-mode))
  3321. (setq txt "")
  3322. (org-with-wide-buffer
  3323. (goto-char marker)
  3324. (end-of-line 1)
  3325. (setq txt (buffer-substring
  3326. (min (1+ (point)) (point-max))
  3327. (progn (outline-next-heading) (point)))
  3328. drawer-re org-drawer-regexp
  3329. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3330. ".*\n?"))
  3331. (with-temp-buffer
  3332. (insert txt)
  3333. (when org-agenda-add-entry-text-descriptive-links
  3334. (goto-char (point-min))
  3335. (while (org-activate-links (point-max))
  3336. (goto-char (match-end 0))))
  3337. (goto-char (point-min))
  3338. (while (re-search-forward org-link-bracket-re (point-max) t)
  3339. (set-text-properties (match-beginning 0) (match-end 0)
  3340. nil))
  3341. (goto-char (point-min))
  3342. (while (re-search-forward drawer-re nil t)
  3343. (delete-region
  3344. (match-beginning 0)
  3345. (progn (re-search-forward
  3346. "^[ \t]*:END:.*\n?" nil 'move)
  3347. (point))))
  3348. (unless (member 'planning keep)
  3349. (goto-char (point-min))
  3350. (while (re-search-forward kwd-time-re nil t)
  3351. (replace-match "")))
  3352. (goto-char (point-min))
  3353. (when org-agenda-entry-text-exclude-regexps
  3354. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3355. (while (setq re (pop re-list))
  3356. (goto-char (point-min))
  3357. (while (re-search-forward re nil t)
  3358. (replace-match "")))))
  3359. (goto-char (point-max))
  3360. (skip-chars-backward " \t\n")
  3361. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3362. ;; find and remove min common indentation
  3363. (goto-char (point-min))
  3364. (untabify (point-min) (point-max))
  3365. (setq ind (current-indentation))
  3366. (while (not (eobp))
  3367. (unless (looking-at "[ \t]*$")
  3368. (setq ind (min ind (current-indentation))))
  3369. (beginning-of-line 2))
  3370. (goto-char (point-min))
  3371. (while (not (eobp))
  3372. (unless (looking-at "[ \t]*$")
  3373. (move-to-column ind)
  3374. (delete-region (point-at-bol) (point)))
  3375. (beginning-of-line 2))
  3376. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3377. (goto-char (point-min))
  3378. (when indent
  3379. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3380. (replace-match indent t t)))
  3381. (goto-char (point-min))
  3382. (while (looking-at "[ \t]*\n") (replace-match ""))
  3383. (goto-char (point-max))
  3384. (when (> (org-current-line)
  3385. n-lines)
  3386. (org-goto-line (1+ n-lines))
  3387. (backward-char 1))
  3388. (setq txt (buffer-substring (point-min) (point))))))))
  3389. txt))
  3390. (defun org-check-for-org-mode ()
  3391. "Make sure current buffer is in Org mode. Error if not."
  3392. (or (derived-mode-p 'org-mode)
  3393. (error "Cannot execute Org agenda command on buffer in %s"
  3394. major-mode)))
  3395. ;;; Agenda prepare and finalize
  3396. (defvar org-agenda-multi nil) ; dynamically scoped
  3397. (defvar org-agenda-pre-window-conf nil)
  3398. (defvar org-agenda-columns-active nil)
  3399. (defvar org-agenda-name nil)
  3400. (defvar org-agenda-tag-filter nil)
  3401. (defvar org-agenda-category-filter nil)
  3402. (defvar org-agenda-regexp-filter nil)
  3403. (defvar org-agenda-effort-filter nil)
  3404. (defvar org-agenda-top-headline-filter nil)
  3405. (defvar org-agenda-represented-categories nil
  3406. "Cache for the list of all categories in the agenda.")
  3407. (defvar org-agenda-represented-tags nil
  3408. "Cache for the list of all categories in the agenda.")
  3409. (defvar org-agenda-tag-filter-preset nil
  3410. "A preset of the tags filter used for secondary agenda filtering.
  3411. This must be a list of strings, each string must be a single tag preceded
  3412. by \"+\" or \"-\".
  3413. This variable should not be set directly, but agenda custom commands can
  3414. bind it in the options section. The preset filter is a global property of
  3415. the entire agenda view. In a block agenda, it will not work reliably to
  3416. define a filter for one of the individual blocks. You need to set it in
  3417. the global options and expect it to be applied to the entire view.")
  3418. (defconst org-agenda-filter-variables
  3419. '((category . org-agenda-category-filter)
  3420. (tag . org-agenda-tag-filter)
  3421. (effort . org-agenda-effort-filter)
  3422. (regexp . org-agenda-regexp-filter))
  3423. "Alist of filter types and associated variables.")
  3424. (defun org-agenda-filter-any ()
  3425. "Is any filter active?"
  3426. (cl-some (lambda (x)
  3427. (or (symbol-value (cdr x))
  3428. (get :preset-filter x)))
  3429. org-agenda-filter-variables))
  3430. (defvar org-agenda-category-filter-preset nil
  3431. "A preset of the category filter used for secondary agenda filtering.
  3432. This must be a list of strings, each string must be a single category
  3433. preceded by \"+\" or \"-\".
  3434. This variable should not be set directly, but agenda custom commands can
  3435. bind it in the options section. The preset filter is a global property of
  3436. the entire agenda view. In a block agenda, it will not work reliably to
  3437. define a filter for one of the individual blocks. You need to set it in
  3438. the global options and expect it to be applied to the entire view.")
  3439. (defvar org-agenda-regexp-filter-preset nil
  3440. "A preset of the regexp filter used for secondary agenda filtering.
  3441. This must be a list of strings, each string must be a single regexp
  3442. preceded by \"+\" or \"-\".
  3443. This variable should not be set directly, but agenda custom commands can
  3444. bind it in the options section. The preset filter is a global property of
  3445. the entire agenda view. In a block agenda, it will not work reliably to
  3446. define a filter for one of the individual blocks. You need to set it in
  3447. the global options and expect it to be applied to the entire view.")
  3448. (defvar org-agenda-effort-filter-preset nil
  3449. "A preset of the effort condition used for secondary agenda filtering.
  3450. This must be a list of strings, each string must be a single regexp
  3451. preceded by \"+\" or \"-\".
  3452. This variable should not be set directly, but agenda custom commands can
  3453. bind it in the options section. The preset filter is a global property of
  3454. the entire agenda view. In a block agenda, it will not work reliably to
  3455. define a filter for one of the individual blocks. You need to set it in
  3456. the global options and expect it to be applied to the entire view.")
  3457. (defun org-agenda-use-sticky-p ()
  3458. "Return non-nil if an agenda buffer named
  3459. `org-agenda-buffer-name' exists and should be shown instead of
  3460. generating a new one."
  3461. (and
  3462. ;; turned off by user
  3463. org-agenda-sticky
  3464. ;; For multi-agenda buffer already exists
  3465. (not org-agenda-multi)
  3466. ;; buffer found
  3467. (get-buffer org-agenda-buffer-name)
  3468. ;; C-u parameter is same as last call
  3469. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3470. (and
  3471. (equal current-prefix-arg
  3472. org-agenda-last-prefix-arg)
  3473. ;; In case user turned stickiness on, while having existing
  3474. ;; Agenda buffer active, don't reuse that buffer, because it
  3475. ;; does not have org variables local
  3476. org-agenda-this-buffer-is-sticky))))
  3477. (defvar org-agenda-buffer-tmp-name nil)
  3478. (defun org-agenda--get-buffer-name (sticky-name)
  3479. (or org-agenda-buffer-tmp-name
  3480. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3481. sticky-name
  3482. "*Org Agenda*"))
  3483. (defun org-agenda-prepare-window (abuf filter-alist)
  3484. "Setup agenda buffer in the window.
  3485. ABUF is the buffer for the agenda window.
  3486. FILTER-ALIST is an alist of filters we need to apply when
  3487. `org-agenda-persistent-filter' is non-nil."
  3488. (let* ((awin (get-buffer-window abuf)) wconf)
  3489. (cond
  3490. ((equal (current-buffer) abuf) nil)
  3491. (awin (select-window awin))
  3492. ((not (setq wconf (current-window-configuration))))
  3493. ((eq org-agenda-window-setup 'current-window)
  3494. (pop-to-buffer-same-window abuf))
  3495. ((eq org-agenda-window-setup 'other-window)
  3496. (org-switch-to-buffer-other-window abuf))
  3497. ((eq org-agenda-window-setup 'other-frame)
  3498. (switch-to-buffer-other-frame abuf))
  3499. ((eq org-agenda-window-setup 'other-tab)
  3500. (if (fboundp 'switch-to-buffer-other-tab)
  3501. (switch-to-buffer-other-tab abuf)
  3502. (user-error "Your version of Emacs does not have tab bar support")))
  3503. ((eq org-agenda-window-setup 'only-window)
  3504. (delete-other-windows)
  3505. (pop-to-buffer-same-window abuf))
  3506. ((eq org-agenda-window-setup 'reorganize-frame)
  3507. (delete-other-windows)
  3508. (org-switch-to-buffer-other-window abuf)))
  3509. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3510. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3511. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3512. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3513. ;; Additional test in case agenda is invoked from within agenda
  3514. ;; buffer via elisp link.
  3515. (unless (equal (current-buffer) abuf)
  3516. (pop-to-buffer-same-window abuf))
  3517. (setq org-agenda-pre-window-conf
  3518. (or wconf org-agenda-pre-window-conf))))
  3519. (defun org-agenda-prepare (&optional name)
  3520. (let ((filter-alist (when org-agenda-persistent-filter
  3521. (with-current-buffer
  3522. (get-buffer-create org-agenda-buffer-name)
  3523. `((tag . ,org-agenda-tag-filter)
  3524. (re . ,org-agenda-regexp-filter)
  3525. (effort . ,org-agenda-effort-filter)
  3526. (cat . ,org-agenda-category-filter))))))
  3527. (if (org-agenda-use-sticky-p)
  3528. (progn
  3529. (put 'org-agenda-tag-filter :preset-filter nil)
  3530. (put 'org-agenda-category-filter :preset-filter nil)
  3531. (put 'org-agenda-regexp-filter :preset-filter nil)
  3532. (put 'org-agenda-effort-filter :preset-filter nil)
  3533. ;; Popup existing buffer
  3534. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3535. filter-alist)
  3536. (message "Sticky Agenda buffer, use `r' to refresh")
  3537. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3538. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3539. (setq org-todo-keywords-for-agenda nil)
  3540. (put 'org-agenda-tag-filter :preset-filter
  3541. org-agenda-tag-filter-preset)
  3542. (put 'org-agenda-category-filter :preset-filter
  3543. org-agenda-category-filter-preset)
  3544. (put 'org-agenda-regexp-filter :preset-filter
  3545. org-agenda-regexp-filter-preset)
  3546. (put 'org-agenda-effort-filter :preset-filter
  3547. org-agenda-effort-filter-preset)
  3548. (if org-agenda-multi
  3549. (progn
  3550. (setq buffer-read-only nil)
  3551. (goto-char (point-max))
  3552. (unless (or (bobp) org-agenda-compact-blocks
  3553. (not org-agenda-block-separator))
  3554. (insert "\n"
  3555. (if (stringp org-agenda-block-separator)
  3556. org-agenda-block-separator
  3557. (make-string (window-width) org-agenda-block-separator))
  3558. "\n"))
  3559. (narrow-to-region (point) (point-max)))
  3560. (setq org-done-keywords-for-agenda nil)
  3561. ;; Setting any org variables that are in org-agenda-local-vars
  3562. ;; list need to be done after the prepare call
  3563. (org-agenda-prepare-window
  3564. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3565. (setq buffer-read-only nil)
  3566. (org-agenda-reset-markers)
  3567. (let ((inhibit-read-only t)) (erase-buffer))
  3568. (org-agenda-mode)
  3569. (setq org-agenda-buffer (current-buffer))
  3570. (setq org-agenda-contributing-files nil)
  3571. (setq org-agenda-columns-active nil)
  3572. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3573. (setq org-todo-keywords-for-agenda
  3574. (org-uniquify org-todo-keywords-for-agenda))
  3575. (setq org-done-keywords-for-agenda
  3576. (org-uniquify org-done-keywords-for-agenda))
  3577. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3578. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3579. (and name (not org-agenda-name)
  3580. (setq-local org-agenda-name name)))
  3581. (setq buffer-read-only nil))))
  3582. (defvar org-overriding-columns-format)
  3583. (defvar org-local-columns-format)
  3584. (defun org-agenda-finalize ()
  3585. "Finishing touch for the agenda buffer.
  3586. This function is called just before displaying the agenda. If
  3587. you want to add your own functions to the finalization of the
  3588. agenda display, configure `org-agenda-finalize-hook'."
  3589. (unless org-agenda-multi
  3590. (let ((inhibit-read-only t))
  3591. (save-excursion
  3592. (goto-char (point-min))
  3593. (save-excursion
  3594. (while (org-activate-links (point-max))
  3595. (goto-char (match-end 0))))
  3596. (unless (eq org-agenda-remove-tags t)
  3597. (org-agenda-align-tags))
  3598. (unless org-agenda-with-colors
  3599. (remove-text-properties (point-min) (point-max) '(face nil)))
  3600. (when (bound-and-true-p org-overriding-columns-format)
  3601. (setq-local org-local-columns-format
  3602. org-overriding-columns-format))
  3603. (when org-agenda-view-columns-initially
  3604. (org-agenda-columns))
  3605. (when org-agenda-fontify-priorities
  3606. (org-agenda-fontify-priorities))
  3607. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3608. (org-agenda-dim-blocked-tasks))
  3609. (org-agenda-mark-clocking-task)
  3610. (when org-agenda-entry-text-mode
  3611. (org-agenda-entry-text-hide)
  3612. (org-agenda-entry-text-show))
  3613. (when (and (featurep 'org-habit)
  3614. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3615. (org-habit-insert-consistency-graphs))
  3616. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3617. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3618. (and (listp org-agenda-show-inherited-tags)
  3619. (memq org-agenda-type org-agenda-show-inherited-tags))
  3620. (and (eq org-agenda-show-inherited-tags t)
  3621. (or (eq org-agenda-use-tag-inheritance t)
  3622. (and (listp org-agenda-use-tag-inheritance)
  3623. (not (memq org-agenda-type
  3624. org-agenda-use-tag-inheritance))))))
  3625. (let (mrk)
  3626. (save-excursion
  3627. (goto-char (point-min))
  3628. (while (equal (forward-line) 0)
  3629. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3630. (put-text-property (point-at-bol) (point-at-eol)
  3631. 'tags
  3632. (org-with-point-at mrk
  3633. (org-get-tags))))))))
  3634. (setq org-agenda-represented-tags nil
  3635. org-agenda-represented-categories nil)
  3636. (when org-agenda-top-headline-filter
  3637. (org-agenda-filter-top-headline-apply
  3638. org-agenda-top-headline-filter))
  3639. (when org-agenda-tag-filter
  3640. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3641. (when (get 'org-agenda-tag-filter :preset-filter)
  3642. (org-agenda-filter-apply
  3643. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3644. (when org-agenda-category-filter
  3645. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3646. (when (get 'org-agenda-category-filter :preset-filter)
  3647. (org-agenda-filter-apply
  3648. (get 'org-agenda-category-filter :preset-filter) 'category))
  3649. (when org-agenda-regexp-filter
  3650. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3651. (when (get 'org-agenda-regexp-filter :preset-filter)
  3652. (org-agenda-filter-apply
  3653. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3654. (when org-agenda-effort-filter
  3655. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3656. (when (get 'org-agenda-effort-filter :preset-filter)
  3657. (org-agenda-filter-apply
  3658. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3659. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3660. (run-hooks 'org-agenda-finalize-hook))))
  3661. (defun org-agenda-mark-clocking-task ()
  3662. "Mark the current clock entry in the agenda if it is present."
  3663. ;; We need to widen when `org-agenda-finalize' is called from
  3664. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3665. (when (bound-and-true-p org-clock-current-task)
  3666. (save-restriction
  3667. (widen)
  3668. (org-agenda-unmark-clocking-task)
  3669. (when (marker-buffer org-clock-hd-marker)
  3670. (save-excursion
  3671. (goto-char (point-min))
  3672. (let (s ov)
  3673. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3674. (goto-char s)
  3675. (when (equal (org-get-at-bol 'org-hd-marker)
  3676. org-clock-hd-marker)
  3677. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3678. (overlay-put ov 'type 'org-agenda-clocking)
  3679. (overlay-put ov 'face 'org-agenda-clocking)
  3680. (overlay-put ov 'help-echo
  3681. "The clock is running in this item")))))))))
  3682. (defun org-agenda-unmark-clocking-task ()
  3683. "Unmark the current clocking task."
  3684. (mapc (lambda (o)
  3685. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3686. (delete-overlay o)))
  3687. (overlays-in (point-min) (point-max))))
  3688. (defun org-agenda-fontify-priorities ()
  3689. "Make highest priority lines bold, and lowest italic."
  3690. (interactive)
  3691. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3692. (delete-overlay o)))
  3693. (overlays-in (point-min) (point-max)))
  3694. (save-excursion
  3695. (let (b e p ov h l)
  3696. (goto-char (point-min))
  3697. (while (re-search-forward org-priority-regexp nil t)
  3698. (setq h (or (get-char-property (point) 'org-priority-highest)
  3699. org-priority-highest)
  3700. l (or (get-char-property (point) 'org-priority-lowest)
  3701. org-priority-lowest)
  3702. p (string-to-char (match-string 2))
  3703. b (match-beginning 1)
  3704. e (if (eq org-agenda-fontify-priorities 'cookies)
  3705. (1+ (match-end 2))
  3706. (point-at-eol))
  3707. ov (make-overlay b e))
  3708. (overlay-put
  3709. ov 'face
  3710. (let ((special-face
  3711. (cond ((org-face-from-face-or-color
  3712. 'priority 'org-priority
  3713. (cdr (assoc p org-priority-faces))))
  3714. ((and (listp org-agenda-fontify-priorities)
  3715. (org-face-from-face-or-color
  3716. 'priority 'org-priority
  3717. (cdr (assoc p org-agenda-fontify-priorities)))))
  3718. ((equal p l) 'italic)
  3719. ((equal p h) 'bold))))
  3720. (if special-face (list special-face 'org-priority) 'org-priority)))
  3721. (overlay-put ov 'org-type 'org-priority)))))
  3722. (defvar org-depend-tag-blocked)
  3723. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3724. "Dim currently blocked TODOs in the agenda display.
  3725. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3726. dimming them." ;FIXME: The arg isn't used, actually!
  3727. (interactive "P")
  3728. (when (called-interactively-p 'interactive)
  3729. (message "Dim or hide blocked tasks..."))
  3730. (dolist (o (overlays-in (point-min) (point-max)))
  3731. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3732. (delete-overlay o)))
  3733. (save-excursion
  3734. (let ((inhibit-read-only t))
  3735. (goto-char (point-min))
  3736. (while (let ((pos (text-property-not-all
  3737. (point) (point-max) 'org-todo-blocked nil)))
  3738. (when pos (goto-char pos)))
  3739. (let* ((invisible
  3740. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3741. (todo-blocked
  3742. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3743. (ov (make-overlay (if invisible
  3744. (line-end-position 0)
  3745. (line-beginning-position))
  3746. (line-end-position))))
  3747. (when todo-blocked
  3748. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3749. (when invisible
  3750. (org-agenda-filter-hide-line 'todo-blocked)))
  3751. (if (= (point-max) (line-end-position))
  3752. (goto-char (point-max))
  3753. (move-beginning-of-line 2)))))
  3754. (when (called-interactively-p 'interactive)
  3755. (message "Dim or hide blocked tasks...done")))
  3756. (defun org-agenda--mark-blocked-entry (entry)
  3757. "If ENTRY is blocked, mark it for fontification or invisibility.
  3758. If the header at `org-hd-marker' is blocked according to
  3759. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3760. 'invisible and the header is not blocked by checkboxes, set the
  3761. text property `org-todo-blocked' to `invisible', otherwise set it
  3762. to t."
  3763. (when (get-text-property 0 'todo-state entry)
  3764. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3765. (org-blocked-by-checkboxes nil)
  3766. ;; Necessary so that `org-entry-blocked-p' does not change
  3767. ;; the buffer.
  3768. (org-depend-tag-blocked nil))
  3769. (when entry-marker
  3770. (let ((blocked
  3771. (with-current-buffer (marker-buffer entry-marker)
  3772. (save-excursion
  3773. (goto-char entry-marker)
  3774. (org-entry-blocked-p)))))
  3775. (when blocked
  3776. (let ((really-invisible
  3777. (and (not org-blocked-by-checkboxes)
  3778. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3779. (put-text-property
  3780. 0 (length entry) 'org-todo-blocked
  3781. (if really-invisible 'invisible t)
  3782. entry)
  3783. (put-text-property
  3784. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3785. entry)
  3786. (defvar org-agenda-skip-function nil
  3787. "Function to be called at each match during agenda construction.
  3788. If this function returns nil, the current match should not be skipped.
  3789. Otherwise, the function must return a position from where the search
  3790. should be continued.
  3791. This may also be a Lisp form, it will be evaluated.
  3792. Never set this variable using `setq' or so, because then it will apply
  3793. to all future agenda commands. If you do want a global skipping condition,
  3794. use the option `org-agenda-skip-function-global' instead.
  3795. The correct usage for `org-agenda-skip-function' is to bind it with
  3796. `let' to scope it dynamically into the agenda-constructing command.
  3797. A good way to set it is through options in `org-agenda-custom-commands'.")
  3798. (defun org-agenda-skip (&optional element)
  3799. "Throw to `:skip' in places that should be skipped.
  3800. Also moves point to the end of the skipped region, so that search can
  3801. continue from there.
  3802. Optional argument ELEMENT contains element at point."
  3803. (let ((p (point-at-bol)) to)
  3804. (when (or
  3805. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3806. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3807. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3808. (org-end-of-subtree t element))
  3809. (and (member org-archive-tag org-file-tags)
  3810. (goto-char (point-max)))))
  3811. (and org-agenda-skip-comment-trees
  3812. (org-in-commented-heading-p nil element)
  3813. (org-end-of-subtree t element))
  3814. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3815. (org-agenda-skip-eval org-agenda-skip-function)))
  3816. (goto-char to))
  3817. (org-in-src-block-p t))
  3818. (throw :skip t))))
  3819. (defun org-agenda-skip-eval (form)
  3820. "If FORM is a function or a list, call (or eval) it and return the result.
  3821. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3822. and match data are returned to the previous state no matter what these
  3823. functions do."
  3824. (let (fp)
  3825. (and form
  3826. (or (setq fp (functionp form))
  3827. (consp form))
  3828. (save-excursion
  3829. (save-match-data
  3830. (if fp
  3831. (funcall form)
  3832. (eval form t)))))))
  3833. (defvar org-agenda-markers nil
  3834. "List of all currently active markers created by `org-agenda'.")
  3835. (defvar org-agenda-last-marker-time (float-time)
  3836. "Creation time of the last agenda marker.")
  3837. (defun org-agenda-new-marker (&optional pos)
  3838. "Return a new agenda marker.
  3839. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3840. of these markers and resets them when they are no longer in use."
  3841. (let ((m (copy-marker (or pos (point)) t)))
  3842. (setq org-agenda-last-marker-time (float-time))
  3843. (if org-agenda-buffer
  3844. (with-current-buffer org-agenda-buffer
  3845. (push m org-agenda-markers))
  3846. (push m org-agenda-markers))
  3847. m))
  3848. (defun org-agenda-reset-markers ()
  3849. "Reset markers created by `org-agenda'."
  3850. (while org-agenda-markers
  3851. (move-marker (pop org-agenda-markers) nil)))
  3852. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3853. "Save relative positions of markers in region.
  3854. This check for agenda markers in all agenda buffers currently active."
  3855. (dolist (buf (buffer-list))
  3856. (with-current-buffer buf
  3857. (when (eq major-mode 'org-agenda-mode)
  3858. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3859. org-agenda-markers)))))
  3860. ;;; Entry text mode
  3861. (defun org-agenda-entry-text-show-here ()
  3862. "Add some text from the entry as context to the current line."
  3863. (let (m txt o)
  3864. (setq m (org-get-at-bol 'org-hd-marker))
  3865. (unless (marker-buffer m)
  3866. (error "No marker points to an entry here"))
  3867. (setq txt (concat "\n" (org-no-properties
  3868. (org-agenda-get-some-entry-text
  3869. m org-agenda-entry-text-maxlines
  3870. org-agenda-entry-text-leaders))))
  3871. (when (string-match "\\S-" txt)
  3872. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3873. (overlay-put o 'evaporate t)
  3874. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3875. (overlay-put o 'after-string txt))))
  3876. (defun org-agenda-entry-text-show ()
  3877. "Add entry context for all agenda lines."
  3878. (interactive)
  3879. (save-excursion
  3880. (goto-char (point-max))
  3881. (beginning-of-line 1)
  3882. (while (not (bobp))
  3883. (when (org-get-at-bol 'org-hd-marker)
  3884. (org-agenda-entry-text-show-here))
  3885. (beginning-of-line 0))))
  3886. (defun org-agenda-entry-text-hide ()
  3887. "Remove any shown entry context."
  3888. (mapc (lambda (o)
  3889. (when (eq (overlay-get o 'org-overlay-type)
  3890. 'agenda-entry-content)
  3891. (delete-overlay o)))
  3892. (overlays-in (point-min) (point-max))))
  3893. (defun org-agenda-get-day-face (date)
  3894. "Return the face DATE should be displayed with."
  3895. (cond ((and (functionp org-agenda-day-face-function)
  3896. (funcall org-agenda-day-face-function date)))
  3897. ((and (org-agenda-today-p date)
  3898. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3899. 'org-agenda-date-weekend-today)
  3900. ((org-agenda-today-p date) 'org-agenda-date-today)
  3901. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3902. 'org-agenda-date-weekend)
  3903. (t 'org-agenda-date)))
  3904. (defvar org-agenda-show-log-scoped)
  3905. ;;; Agenda Daily/Weekly
  3906. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3907. "Start day for the agenda view.
  3908. Custom commands can set this variable in the options section.
  3909. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3910. input allowed when reading a date through the Org calendar.
  3911. See the docstring of `org-read-date' for details.")
  3912. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3913. (defvar org-arg-loc nil) ; local variable
  3914. ;;;###autoload
  3915. (defun org-agenda-list (&optional arg start-day span with-hour)
  3916. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3917. The view will be for the current day or week, but from the overview buffer
  3918. you will be able to go to other days/weeks.
  3919. With a numeric prefix argument in an interactive call, the agenda will
  3920. span ARG days. Lisp programs should instead specify SPAN to change
  3921. the number of days. SPAN defaults to `org-agenda-span'.
  3922. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3923. given in `org-agenda-start-on-weekday'.
  3924. When WITH-HOUR is non-nil, only include scheduled and deadline
  3925. items if they have an hour specification like [h]h:mm."
  3926. (interactive "P")
  3927. (when org-agenda-overriding-arguments
  3928. (setq arg (car org-agenda-overriding-arguments)
  3929. start-day (nth 1 org-agenda-overriding-arguments)
  3930. span (nth 2 org-agenda-overriding-arguments)))
  3931. (when (and (integerp arg) (> arg 0))
  3932. (setq span arg arg nil))
  3933. (when (numberp span)
  3934. (unless (< 0 span)
  3935. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3936. (catch 'exit
  3937. (setq org-agenda-buffer-name
  3938. (org-agenda--get-buffer-name
  3939. (and org-agenda-sticky
  3940. (cond ((and org-keys (stringp org-match))
  3941. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3942. (org-keys
  3943. (format "*Org Agenda(%s)*" org-keys))
  3944. (t "*Org Agenda(a)*")))))
  3945. (org-agenda-prepare "Day/Week")
  3946. (setq start-day (or start-day org-agenda-start-day))
  3947. (when (stringp start-day)
  3948. ;; Convert to an absolute day number
  3949. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3950. (org-compile-prefix-format 'agenda)
  3951. (org-set-sorting-strategy 'agenda)
  3952. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3953. (today (org-today))
  3954. (sd (or start-day today))
  3955. (ndays (org-agenda-span-to-ndays span sd))
  3956. (org-agenda-start-on-weekday
  3957. (and (or (eq ndays 7) (eq ndays 14))
  3958. org-agenda-start-on-weekday))
  3959. (thefiles (org-agenda-files nil 'ifmode))
  3960. (files thefiles)
  3961. (start (if (or (null org-agenda-start-on-weekday)
  3962. (< ndays 7))
  3963. sd
  3964. (let* ((nt (calendar-day-of-week
  3965. (calendar-gregorian-from-absolute sd)))
  3966. (n1 org-agenda-start-on-weekday)
  3967. (d (- nt n1)))
  3968. (- sd (+ (if (< d 0) 7 0) d)))))
  3969. (day-numbers (list start))
  3970. (day-cnt 0)
  3971. (inhibit-redisplay (not debug-on-error))
  3972. (org-agenda-show-log-scoped org-agenda-show-log)
  3973. s rtn rtnall file date d start-pos end-pos todayp ;; e
  3974. clocktable-start clocktable-end) ;; filter
  3975. (setq org-agenda-redo-command
  3976. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3977. (dotimes (_ (1- ndays))
  3978. (push (1+ (car day-numbers)) day-numbers))
  3979. (setq day-numbers (nreverse day-numbers))
  3980. (setq clocktable-start (car day-numbers)
  3981. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3982. (setq-local org-starting-day (car day-numbers))
  3983. (setq-local org-arg-loc arg)
  3984. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3985. (unless org-agenda-compact-blocks
  3986. (let* ((d1 (car day-numbers))
  3987. (d2 (org-last day-numbers))
  3988. (w1 (org-days-to-iso-week d1))
  3989. (w2 (org-days-to-iso-week d2)))
  3990. (setq s (point))
  3991. (org-agenda--insert-overriding-header
  3992. (concat (org-agenda-span-name span)
  3993. "-agenda"
  3994. (cond ((<= 350 (- d2 d1)) "")
  3995. ((= w1 w2) (format " (W%02d)" w1))
  3996. (t (format " (W%02d-W%02d)" w1 w2)))
  3997. ":\n")))
  3998. ;; Add properties if we actually inserted a header.
  3999. (when (> (point) s)
  4000. (add-text-properties s (1- (point))
  4001. (list 'face 'org-agenda-structure
  4002. 'org-date-line t))
  4003. (org-agenda-mark-header-line s)))
  4004. (while (setq d (pop day-numbers))
  4005. (setq date (calendar-gregorian-from-absolute d)
  4006. s (point))
  4007. (if (or (setq todayp (= d today))
  4008. (and (not start-pos) (= d sd)))
  4009. (setq start-pos (point))
  4010. (when (and start-pos (not end-pos))
  4011. (setq end-pos (point))))
  4012. (setq files thefiles
  4013. rtnall nil)
  4014. (while (setq file (pop files))
  4015. (catch 'nextfile
  4016. (org-check-agenda-file file)
  4017. (let ((org-agenda-entry-types org-agenda-entry-types))
  4018. ;; Starred types override non-starred equivalents
  4019. (when (member :deadline* org-agenda-entry-types)
  4020. (setq org-agenda-entry-types
  4021. (delq :deadline org-agenda-entry-types)))
  4022. (when (member :scheduled* org-agenda-entry-types)
  4023. (setq org-agenda-entry-types
  4024. (delq :scheduled org-agenda-entry-types)))
  4025. ;; Honor with-hour
  4026. (when with-hour
  4027. (when (member :deadline org-agenda-entry-types)
  4028. (setq org-agenda-entry-types
  4029. (delq :deadline org-agenda-entry-types))
  4030. (push :deadline* org-agenda-entry-types))
  4031. (when (member :scheduled org-agenda-entry-types)
  4032. (setq org-agenda-entry-types
  4033. (delq :scheduled org-agenda-entry-types))
  4034. (push :scheduled* org-agenda-entry-types)))
  4035. (unless org-agenda-include-deadlines
  4036. (setq org-agenda-entry-types
  4037. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4038. (cond
  4039. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4040. (setq rtn (org-agenda-get-day-entries
  4041. file date :closed)))
  4042. (org-agenda-show-log-scoped
  4043. (setq rtn (apply #'org-agenda-get-day-entries
  4044. file date
  4045. (append '(:closed) org-agenda-entry-types))))
  4046. (t
  4047. (setq rtn (apply #'org-agenda-get-day-entries
  4048. file date
  4049. org-agenda-entry-types)))))
  4050. (setq rtnall (append rtnall rtn)))) ;; all entries
  4051. (when org-agenda-include-diary
  4052. (let ((org-agenda-search-headline-for-time t))
  4053. (require 'diary-lib)
  4054. (setq rtn (org-get-entries-from-diary date))
  4055. (setq rtnall (append rtnall rtn))))
  4056. (when (or rtnall org-agenda-show-all-dates)
  4057. (setq day-cnt (1+ day-cnt))
  4058. (insert
  4059. (if (stringp org-agenda-format-date)
  4060. (format-time-string org-agenda-format-date
  4061. (org-time-from-absolute date))
  4062. (funcall org-agenda-format-date date))
  4063. "\n")
  4064. (put-text-property s (1- (point)) 'face
  4065. (org-agenda-get-day-face date))
  4066. (put-text-property s (1- (point)) 'org-date-line t)
  4067. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4068. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4069. (when todayp
  4070. (put-text-property s (1- (point)) 'org-today t))
  4071. (setq rtnall
  4072. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4073. (when rtnall (insert ;; all entries
  4074. (org-agenda-finalize-entries rtnall 'agenda)
  4075. "\n"))
  4076. (put-text-property s (1- (point)) 'day d)
  4077. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4078. (when (and org-agenda-clockreport-mode clocktable-start)
  4079. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4080. ;; the above line is to ensure the restricted range!
  4081. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4082. tbl)
  4083. (setq p (org-plist-delete p :block))
  4084. (setq p (plist-put p :tstart clocktable-start))
  4085. (setq p (plist-put p :tend clocktable-end))
  4086. (setq p (plist-put p :scope 'agenda))
  4087. (setq tbl (apply #'org-clock-get-clocktable p))
  4088. (insert tbl)))
  4089. (goto-char (point-min))
  4090. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4091. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4092. (and (pos-visible-in-window-p (point-min))
  4093. (pos-visible-in-window-p (point-max))))
  4094. (goto-char (1- (point-max)))
  4095. (recenter -1)
  4096. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4097. (goto-char (or start-pos 1))
  4098. (recenter 1)))
  4099. (goto-char (or start-pos 1))
  4100. (add-text-properties (point-min) (point-max)
  4101. `(org-agenda-type agenda
  4102. org-last-args (,arg ,start-day ,span)
  4103. org-redo-cmd ,org-agenda-redo-command
  4104. org-series-cmd ,org-cmd))
  4105. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4106. (org-agenda-show-clocking-issues))
  4107. (org-agenda-finalize)
  4108. (setq buffer-read-only t)
  4109. (message ""))))
  4110. (defun org-agenda-ndays-to-span (n)
  4111. "Return a span symbol for a span of N days, or N if none matches."
  4112. (cond ((symbolp n) n)
  4113. ((= n 1) 'day)
  4114. ((= n 7) 'week)
  4115. ((= n 14) 'fortnight)
  4116. (t n)))
  4117. (defun org-agenda-span-to-ndays (span &optional start-day)
  4118. "Return ndays from SPAN, possibly starting at START-DAY.
  4119. START-DAY is an absolute time value."
  4120. (cond ((numberp span) span)
  4121. ((eq span 'day) 1)
  4122. ((eq span 'week) 7)
  4123. ((eq span 'fortnight) 14)
  4124. ((eq span 'month)
  4125. (let ((date (calendar-gregorian-from-absolute start-day)))
  4126. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4127. ((eq span 'year)
  4128. (let ((date (calendar-gregorian-from-absolute start-day)))
  4129. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4130. (defun org-agenda-span-name (span)
  4131. "Return a SPAN name."
  4132. (if (null span)
  4133. ""
  4134. (if (symbolp span)
  4135. (capitalize (symbol-name span))
  4136. (format "%d days" span))))
  4137. ;;; Agenda word search
  4138. (defvar org-agenda-search-history nil)
  4139. (defvar org-search-syntax-table nil
  4140. "Special syntax table for Org search.
  4141. In this table, we have single quotes not as word constituents, to
  4142. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4143. (defvar org-mode-syntax-table) ; From org.el
  4144. (defun org-search-syntax-table ()
  4145. (unless org-search-syntax-table
  4146. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4147. (modify-syntax-entry ?' "." org-search-syntax-table)
  4148. (modify-syntax-entry ?` "." org-search-syntax-table))
  4149. org-search-syntax-table)
  4150. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4151. ;;;###autoload
  4152. (defun org-search-view (&optional todo-only string edit-at)
  4153. "Show all entries that contain a phrase or words or regular expressions.
  4154. With optional prefix argument TODO-ONLY, only consider entries that are
  4155. TODO entries. The argument STRING can be used to pass a default search
  4156. string into this function. If EDIT-AT is non-nil, it means that the
  4157. user should get a chance to edit this string, with cursor at position
  4158. EDIT-AT.
  4159. The search string can be viewed either as a phrase that should be found as
  4160. is, or it can be broken into a number of snippets, each of which must match
  4161. in a Boolean way to select an entry. The default depends on the variable
  4162. `org-agenda-search-view-always-boolean'.
  4163. Even if this is turned off (the default) you can always switch to
  4164. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4165. The default is a direct search of the whole phrase, where each space in
  4166. the search string can expand to an arbitrary amount of whitespace,
  4167. including newlines.
  4168. If using a Boolean search, the search string is split on whitespace and
  4169. each snippet is searched separately, with logical AND to select an entry.
  4170. Words prefixed with a minus must *not* occur in the entry. Words without
  4171. a prefix or prefixed with a plus must occur in the entry. Matching is
  4172. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4173. match whole words, not parts of a word) if
  4174. `org-agenda-search-view-force-full-words' is set (default is nil).
  4175. Boolean search snippets enclosed by curly braces are interpreted as
  4176. regular expressions that must or (when preceded with \"-\") must not
  4177. match in the entry. Snippets enclosed into double quotes will be taken
  4178. as a whole, to include whitespace.
  4179. - If the search string starts with an asterisk, search only in headlines.
  4180. - If (possibly after the leading star) the search string starts with an
  4181. exclamation mark, this also means to look at TODO entries only, an effect
  4182. that can also be achieved with a prefix argument.
  4183. - If (possibly after star and exclamation mark) the search string starts
  4184. with a colon, this will mean that the (non-regexp) snippets of the
  4185. Boolean search must match as full words.
  4186. This command searches the agenda files, and in addition the files
  4187. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4188. is active."
  4189. (interactive "P")
  4190. (when org-agenda-overriding-arguments
  4191. (setq todo-only (car org-agenda-overriding-arguments)
  4192. string (nth 1 org-agenda-overriding-arguments)
  4193. edit-at (nth 2 org-agenda-overriding-arguments)))
  4194. (let* ((props (list 'face nil
  4195. 'done-face 'org-agenda-done
  4196. 'org-not-done-regexp org-not-done-regexp
  4197. 'org-todo-regexp org-todo-regexp
  4198. 'org-complex-heading-regexp org-complex-heading-regexp
  4199. 'mouse-face 'highlight
  4200. 'help-echo "mouse-2 or RET jump to location"))
  4201. (full-words org-agenda-search-view-force-full-words)
  4202. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4203. regexp rtn rtnall files file pos inherited-tags
  4204. marker category level tags c neg re boolean
  4205. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4206. (unless (and (not edit-at)
  4207. (stringp string)
  4208. (string-match "\\S-" string))
  4209. (setq string (read-string
  4210. (if org-agenda-search-view-always-boolean
  4211. "[+-]Word/{Regexp} ...: "
  4212. "Phrase or [+-]Word/{Regexp} ...: ")
  4213. (cond
  4214. ((integerp edit-at) (cons string edit-at))
  4215. (edit-at string))
  4216. 'org-agenda-search-history)))
  4217. (catch 'exit
  4218. (setq org-agenda-buffer-name
  4219. (org-agenda--get-buffer-name
  4220. (and org-agenda-sticky
  4221. (if (stringp string)
  4222. (format "*Org Agenda(%s:%s)*"
  4223. (or org-keys (or (and todo-only "S") "s"))
  4224. string)
  4225. (format "*Org Agenda(%s)*"
  4226. (or (and todo-only "S") "s"))))))
  4227. (org-agenda-prepare "SEARCH")
  4228. (org-compile-prefix-format 'search)
  4229. (org-set-sorting-strategy 'search)
  4230. (setq org-agenda-redo-command
  4231. (list 'org-search-view (if todo-only t nil)
  4232. (list 'if 'current-prefix-arg nil string)))
  4233. (setq org-agenda-query-string string)
  4234. (if (equal (string-to-char string) ?*)
  4235. (setq hdl-only t
  4236. words (substring string 1))
  4237. (setq words string))
  4238. (when (equal (string-to-char words) ?!)
  4239. (setq todo-only t
  4240. words (substring words 1)))
  4241. (when (equal (string-to-char words) ?:)
  4242. (setq full-words t
  4243. words (substring words 1)))
  4244. (when (or org-agenda-search-view-always-boolean
  4245. (member (string-to-char words) '(?- ?+ ?\{)))
  4246. (setq boolean t))
  4247. (setq words (split-string words))
  4248. (let (www w)
  4249. (while (setq w (pop words))
  4250. (while (and (string-match "\\\\\\'" w) words)
  4251. (setq w (concat (substring w 0 -1) " " (pop words))))
  4252. (push w www))
  4253. (setq words (nreverse www) www nil)
  4254. (while (setq w (pop words))
  4255. (when (and (string-match "\\`[-+]?{" w)
  4256. (not (string-match "}\\'" w)))
  4257. (while (and words (not (string-match "}\\'" (car words))))
  4258. (setq w (concat w " " (pop words))))
  4259. (setq w (concat w " " (pop words))))
  4260. (push w www))
  4261. (setq words (nreverse www)))
  4262. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4263. (when boolean
  4264. (let (wds w)
  4265. (while (setq w (pop words))
  4266. (when (or (equal (substring w 0 1) "\"")
  4267. (and (> (length w) 1)
  4268. (member (substring w 0 1) '("+" "-"))
  4269. (equal (substring w 1 2) "\"")))
  4270. (while (and words (not (equal (substring w -1) "\"")))
  4271. (setq w (concat w " " (pop words)))))
  4272. (and (string-match "\\`\\([-+]?\\)\"" w)
  4273. (setq w (replace-match "\\1" nil nil w)))
  4274. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4275. (push w wds))
  4276. (setq words (nreverse wds))))
  4277. (if boolean
  4278. (mapc (lambda (w)
  4279. (setq c (string-to-char w))
  4280. (if (equal c ?-)
  4281. (setq neg t w (substring w 1))
  4282. (if (equal c ?+)
  4283. (setq neg nil w (substring w 1))
  4284. (setq neg nil)))
  4285. (if (string-match "\\`{.*}\\'" w)
  4286. (setq re (substring w 1 -1))
  4287. (if full-words
  4288. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4289. (setq re (regexp-quote (downcase w)))))
  4290. (if neg (push re regexps-) (push re regexps+)))
  4291. words)
  4292. (push (mapconcat #'regexp-quote words "\\s-+")
  4293. regexps+))
  4294. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4295. (if (not regexps+)
  4296. (setq regexp org-outline-regexp-bol)
  4297. (setq regexp (pop regexps+))
  4298. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4299. regexp))))
  4300. (setq files (org-agenda-files nil 'ifmode))
  4301. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4302. ;; restriction.
  4303. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4304. (pop org-agenda-text-search-extra-files)
  4305. (unless (get 'org-agenda-files 'org-restrict)
  4306. (setq files (org-add-archive-files files))))
  4307. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4308. ;; non-existent ones.
  4309. (setq files (cl-remove-duplicates
  4310. (append files org-agenda-text-search-extra-files)
  4311. :test (lambda (a b)
  4312. (and (file-exists-p a)
  4313. (file-exists-p b)
  4314. (file-equal-p a b))))
  4315. rtnall nil)
  4316. (while (setq file (pop files))
  4317. (setq ee nil)
  4318. (catch 'nextfile
  4319. (org-check-agenda-file file)
  4320. (setq buffer (if (file-exists-p file)
  4321. (org-get-agenda-file-buffer file)
  4322. (error "No such file %s" file)))
  4323. (unless buffer
  4324. ;; If file does not exist, make sure an error message is sent
  4325. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4326. file))))
  4327. (with-current-buffer buffer
  4328. (with-syntax-table (org-search-syntax-table)
  4329. (unless (derived-mode-p 'org-mode)
  4330. (error "Agenda file %s is not in Org mode" file))
  4331. (let ((case-fold-search t))
  4332. (save-excursion
  4333. (save-restriction
  4334. (if (eq buffer org-agenda-restrict)
  4335. (narrow-to-region org-agenda-restrict-begin
  4336. org-agenda-restrict-end)
  4337. (widen))
  4338. (goto-char (point-min))
  4339. (unless (or (org-at-heading-p)
  4340. (outline-next-heading))
  4341. (throw 'nextfile t))
  4342. (goto-char (max (point-min) (1- (point))))
  4343. (while (re-search-forward regexp nil t)
  4344. (org-back-to-heading t)
  4345. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4346. (> (org-reduced-level (org-outline-level))
  4347. org-agenda-search-view-max-outline-level)
  4348. (forward-line -1)
  4349. (org-back-to-heading t)))
  4350. (skip-chars-forward "* ")
  4351. (setq beg (point-at-bol)
  4352. beg1 (point)
  4353. end (progn
  4354. (outline-next-heading)
  4355. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4356. (> (org-reduced-level (org-outline-level))
  4357. org-agenda-search-view-max-outline-level)
  4358. (forward-line 1)
  4359. (outline-next-heading)))
  4360. (point)))
  4361. (catch :skip
  4362. (goto-char beg)
  4363. (org-agenda-skip)
  4364. (setq str (buffer-substring-no-properties
  4365. (point-at-bol)
  4366. (if hdl-only (point-at-eol) end)))
  4367. (mapc (lambda (wr) (when (string-match wr str)
  4368. (goto-char (1- end))
  4369. (throw :skip t)))
  4370. regexps-)
  4371. (mapc (lambda (wr) (unless (string-match wr str)
  4372. (goto-char (1- end))
  4373. (throw :skip t)))
  4374. (if todo-only
  4375. (cons (concat "^\\*+[ \t]+"
  4376. org-not-done-regexp)
  4377. regexps+)
  4378. regexps+))
  4379. (goto-char beg)
  4380. (setq marker (org-agenda-new-marker (point))
  4381. category (org-get-category)
  4382. level (make-string (org-reduced-level (org-outline-level)) ? )
  4383. inherited-tags
  4384. (or (eq org-agenda-show-inherited-tags 'always)
  4385. (and (listp org-agenda-show-inherited-tags)
  4386. (memq 'todo org-agenda-show-inherited-tags))
  4387. (and (eq org-agenda-show-inherited-tags t)
  4388. (or (eq org-agenda-use-tag-inheritance t)
  4389. (memq 'todo org-agenda-use-tag-inheritance))))
  4390. tags (org-get-tags nil (not inherited-tags))
  4391. txt (org-agenda-format-item
  4392. ""
  4393. (buffer-substring-no-properties
  4394. beg1 (point-at-eol))
  4395. level category tags t))
  4396. (org-add-props txt props
  4397. 'org-marker marker 'org-hd-marker marker
  4398. 'org-todo-regexp org-todo-regexp
  4399. 'level level
  4400. 'org-complex-heading-regexp org-complex-heading-regexp
  4401. 'priority 1000
  4402. 'type "search")
  4403. (push txt ee)
  4404. (goto-char (1- end))))))))))
  4405. (setq rtn (nreverse ee))
  4406. (setq rtnall (append rtnall rtn)))
  4407. (org-agenda--insert-overriding-header
  4408. (with-temp-buffer
  4409. (insert "Search words: ")
  4410. (add-text-properties (point-min) (1- (point))
  4411. (list 'face 'org-agenda-structure))
  4412. (setq pos (point))
  4413. (insert string "\n")
  4414. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4415. (setq pos (point))
  4416. (unless org-agenda-multi
  4417. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4418. Press `\\[org-agenda-manipulate-query-add]', \
  4419. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4420. `\\[org-agenda-manipulate-query-add-re]', \
  4421. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4422. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4423. (add-text-properties pos (1- (point))
  4424. (list 'face 'org-agenda-structure-secondary)))
  4425. (buffer-string)))
  4426. (org-agenda-mark-header-line (point-min))
  4427. (when rtnall
  4428. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4429. (goto-char (point-min))
  4430. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4431. (add-text-properties (point-min) (point-max)
  4432. `(org-agenda-type search
  4433. org-last-args (,todo-only ,string ,edit-at)
  4434. org-redo-cmd ,org-agenda-redo-command
  4435. org-series-cmd ,org-cmd))
  4436. (org-agenda-finalize)
  4437. (setq buffer-read-only t))))
  4438. ;;; Agenda TODO list
  4439. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4440. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4441. (concat
  4442. (if (or (equal keywords "ALL") (not keywords))
  4443. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4444. (mapconcat
  4445. (lambda (kw)
  4446. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4447. (org-split-string keywords "|")
  4448. "|"))
  4449. "\n"))
  4450. (defvar org-select-this-todo-keyword nil)
  4451. (defvar org-last-arg nil)
  4452. (defvar crm-separator)
  4453. ;;;###autoload
  4454. (defun org-todo-list (&optional arg)
  4455. "Show all (not done) TODO entries from all agenda file in a single list.
  4456. The prefix arg can be used to select a specific TODO keyword and limit
  4457. the list to these. When using `\\[universal-argument]', you will be prompted
  4458. for a keyword. A numeric prefix directly selects the Nth keyword in
  4459. `org-todo-keywords-1'."
  4460. (interactive "P")
  4461. (when org-agenda-overriding-arguments
  4462. (setq arg org-agenda-overriding-arguments))
  4463. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4464. (let* ((today (org-today))
  4465. (date (calendar-gregorian-from-absolute today))
  4466. (completion-ignore-case t)
  4467. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4468. (catch 'exit
  4469. (setq org-agenda-buffer-name
  4470. (org-agenda--get-buffer-name
  4471. (and org-agenda-sticky
  4472. (if (stringp org-select-this-todo-keyword)
  4473. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4474. org-select-this-todo-keyword)
  4475. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4476. (org-agenda-prepare "TODO")
  4477. (setq kwds org-todo-keywords-for-agenda
  4478. org-select-this-todo-keyword (if (stringp arg) arg
  4479. (and (integerp arg)
  4480. (> arg 0)
  4481. (nth (1- arg) kwds))))
  4482. (when (equal arg '(4))
  4483. (setq org-select-this-todo-keyword
  4484. (mapconcat #'identity
  4485. (let ((crm-separator "|"))
  4486. (completing-read-multiple
  4487. "Keyword (or KWD1|KWD2|...): "
  4488. (mapcar #'list kwds) nil nil))
  4489. "|")))
  4490. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4491. (org-compile-prefix-format 'todo)
  4492. (org-set-sorting-strategy 'todo)
  4493. (setq org-agenda-redo-command
  4494. `(org-todo-list (or (and (numberp current-prefix-arg)
  4495. current-prefix-arg)
  4496. ,org-select-this-todo-keyword
  4497. current-prefix-arg ,arg)))
  4498. (setq files (org-agenda-files nil 'ifmode)
  4499. rtnall nil)
  4500. (while (setq file (pop files))
  4501. (catch 'nextfile
  4502. (org-check-agenda-file file)
  4503. (setq rtn (org-agenda-get-day-entries file date :todo))
  4504. (setq rtnall (append rtnall rtn))))
  4505. (org-agenda--insert-overriding-header
  4506. (with-temp-buffer
  4507. (insert "Global list of TODO items of type: ")
  4508. (add-text-properties (point-min) (1- (point))
  4509. (list 'face 'org-agenda-structure
  4510. 'short-heading
  4511. (concat "ToDo: "
  4512. (or org-select-this-todo-keyword "ALL"))))
  4513. (org-agenda-mark-header-line (point-min))
  4514. (insert (org-agenda-propertize-selected-todo-keywords
  4515. org-select-this-todo-keyword))
  4516. (setq pos (point))
  4517. (unless org-agenda-multi
  4518. (insert (substitute-command-keys "Press \
  4519. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4520. to search again: (0)[ALL]"))
  4521. (let ((n 0))
  4522. (dolist (k kwds)
  4523. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4524. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4525. (insert "\n "))
  4526. (insert " " s))))
  4527. (insert "\n"))
  4528. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4529. (buffer-string)))
  4530. (org-agenda-mark-header-line (point-min))
  4531. (when rtnall
  4532. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4533. (goto-char (point-min))
  4534. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4535. (add-text-properties (point-min) (point-max)
  4536. `(org-agenda-type todo
  4537. org-last-args ,arg
  4538. org-redo-cmd ,org-agenda-redo-command
  4539. org-series-cmd ,org-cmd))
  4540. (org-agenda-finalize)
  4541. (setq buffer-read-only t))))
  4542. ;;; Agenda tags match
  4543. ;;;###autoload
  4544. (defun org-tags-view (&optional todo-only match)
  4545. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4546. The prefix arg TODO-ONLY limits the search to TODO entries."
  4547. (interactive "P")
  4548. (when org-agenda-overriding-arguments
  4549. (setq todo-only (car org-agenda-overriding-arguments)
  4550. match (nth 1 org-agenda-overriding-arguments)))
  4551. (let* ((org-tags-match-list-sublevels
  4552. org-tags-match-list-sublevels)
  4553. (completion-ignore-case t)
  4554. (org--matcher-tags-todo-only todo-only)
  4555. rtn rtnall files file pos matcher
  4556. buffer)
  4557. (when (and (stringp match) (not (string-match "\\S-" match)))
  4558. (setq match nil))
  4559. (catch 'exit
  4560. (setq org-agenda-buffer-name
  4561. (org-agenda--get-buffer-name
  4562. (and org-agenda-sticky
  4563. (if (stringp match)
  4564. (format "*Org Agenda(%s:%s)*"
  4565. (or org-keys (or (and todo-only "M") "m"))
  4566. match)
  4567. (format "*Org Agenda(%s)*"
  4568. (or (and todo-only "M") "m"))))))
  4569. (setq matcher (org-make-tags-matcher match))
  4570. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4571. ;; expanding tags within `org-make-tags-matcher'
  4572. (org-agenda-prepare (concat "TAGS " match))
  4573. (setq match (car matcher)
  4574. matcher (cdr matcher))
  4575. (org-compile-prefix-format 'tags)
  4576. (org-set-sorting-strategy 'tags)
  4577. (setq org-agenda-query-string match)
  4578. (setq org-agenda-redo-command
  4579. (list 'org-tags-view
  4580. `(quote ,org--matcher-tags-todo-only)
  4581. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4582. (setq files (org-agenda-files nil 'ifmode)
  4583. rtnall nil)
  4584. (while (setq file (pop files))
  4585. (catch 'nextfile
  4586. (org-check-agenda-file file)
  4587. (setq buffer (if (file-exists-p file)
  4588. (org-get-agenda-file-buffer file)
  4589. (error "No such file %s" file)))
  4590. (if (not buffer)
  4591. ;; If file does not exist, error message to agenda
  4592. (setq rtn (list
  4593. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4594. rtnall (append rtnall rtn))
  4595. (with-current-buffer buffer
  4596. (unless (derived-mode-p 'org-mode)
  4597. (error "Agenda file %s is not in Org mode" file))
  4598. (save-excursion
  4599. (save-restriction
  4600. (if (eq buffer org-agenda-restrict)
  4601. (narrow-to-region org-agenda-restrict-begin
  4602. org-agenda-restrict-end)
  4603. (widen))
  4604. (setq rtn (org-scan-tags 'agenda
  4605. matcher
  4606. org--matcher-tags-todo-only))
  4607. (setq rtnall (append rtnall rtn))))))))
  4608. (org-agenda--insert-overriding-header
  4609. (with-temp-buffer
  4610. (insert "Headlines with TAGS match: ")
  4611. (add-text-properties (point-min) (1- (point))
  4612. (list 'face 'org-agenda-structure
  4613. 'short-heading
  4614. (concat "Match: " match)))
  4615. (setq pos (point))
  4616. (insert match "\n")
  4617. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4618. (setq pos (point))
  4619. (unless org-agenda-multi
  4620. (insert (substitute-command-keys
  4621. "Press \
  4622. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4623. to search again\n")))
  4624. (add-text-properties pos (1- (point))
  4625. (list 'face 'org-agenda-structure-secondary))
  4626. (buffer-string)))
  4627. (org-agenda-mark-header-line (point-min))
  4628. (when rtnall
  4629. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4630. (goto-char (point-min))
  4631. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4632. (add-text-properties
  4633. (point-min) (point-max)
  4634. `(org-agenda-type tags
  4635. org-last-args (,org--matcher-tags-todo-only ,match)
  4636. org-redo-cmd ,org-agenda-redo-command
  4637. org-series-cmd ,org-cmd))
  4638. (org-agenda-finalize)
  4639. (setq buffer-read-only t))))
  4640. ;;; Agenda Finding stuck projects
  4641. (defvar org-agenda-skip-regexp nil
  4642. "Regular expression used in skipping subtrees for the agenda.
  4643. This is basically a temporary global variable that can be set and then
  4644. used by user-defined selections using `org-agenda-skip-function'.")
  4645. (defvar org-agenda-overriding-header nil
  4646. "When set during agenda, todo and tags searches it replaces the header.
  4647. If an empty string, no header will be inserted. If any other
  4648. string, it will be inserted as a header. If a function, insert
  4649. the string returned by the function as a header. If nil, a
  4650. header will be generated automatically according to the command.
  4651. This variable should not be set directly, but custom commands can
  4652. bind it in the options section.")
  4653. (defun org-agenda-skip-entry-if (&rest conditions)
  4654. "Skip entry if any of CONDITIONS is true.
  4655. See `org-agenda-skip-if' for details."
  4656. (org-agenda-skip-if nil conditions))
  4657. (defun org-agenda-skip-subtree-if (&rest conditions)
  4658. "Skip subtree if any of CONDITIONS is true.
  4659. See `org-agenda-skip-if' for details."
  4660. (org-agenda-skip-if t conditions))
  4661. (defun org-agenda-skip-if (subtree conditions)
  4662. "Check current entity for CONDITIONS.
  4663. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4664. the entry (i.e. the text before the next heading) is checked.
  4665. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4666. from different tests. Valid conditions are:
  4667. scheduled Check if there is a scheduled cookie
  4668. notscheduled Check if there is no scheduled cookie
  4669. deadline Check if there is a deadline
  4670. notdeadline Check if there is no deadline
  4671. timestamp Check if there is a timestamp (also deadline or scheduled)
  4672. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4673. regexp Check if regexp matches
  4674. notregexp Check if regexp does not match.
  4675. todo Check if TODO keyword matches
  4676. nottodo Check if TODO keyword does not match
  4677. The regexp is taken from the conditions list, it must come right after
  4678. the `regexp' or `notregexp' element.
  4679. `todo' and `nottodo' accept as an argument a list of todo
  4680. keywords, which may include \"*\" to match any todo keyword.
  4681. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4682. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4683. Instead of a list, a keyword class may be given. For example:
  4684. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4685. would skip entries that haven't been marked with any of \"DONE\"
  4686. keywords. Possible classes are: `todo', `done', `any'.
  4687. If any of these conditions is met, this function returns the end point of
  4688. the entity, causing the search to continue from there. This is a function
  4689. that can be put into `org-agenda-skip-function' for the duration of a command."
  4690. (org-back-to-heading t)
  4691. (let* (;; (beg (point))
  4692. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4693. (org-entry-end-position)))
  4694. (planning-end (if subtree end (line-end-position 2)))
  4695. m)
  4696. (and
  4697. (or (and (memq 'scheduled conditions)
  4698. (re-search-forward org-scheduled-time-regexp planning-end t))
  4699. (and (memq 'notscheduled conditions)
  4700. (not
  4701. (save-excursion
  4702. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4703. (and (memq 'deadline conditions)
  4704. (re-search-forward org-deadline-time-regexp planning-end t))
  4705. (and (memq 'notdeadline conditions)
  4706. (not
  4707. (save-excursion
  4708. (re-search-forward org-deadline-time-regexp planning-end t))))
  4709. (and (memq 'timestamp conditions)
  4710. (re-search-forward org-ts-regexp end t))
  4711. (and (memq 'nottimestamp conditions)
  4712. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4713. (and (setq m (memq 'regexp conditions))
  4714. (stringp (nth 1 m))
  4715. (re-search-forward (nth 1 m) end t))
  4716. (and (setq m (memq 'notregexp conditions))
  4717. (stringp (nth 1 m))
  4718. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4719. (and (or
  4720. (setq m (memq 'nottodo conditions))
  4721. (setq m (memq 'todo-unblocked conditions))
  4722. (setq m (memq 'nottodo-unblocked conditions))
  4723. (setq m (memq 'todo conditions)))
  4724. (org-agenda-skip-if-todo m end)))
  4725. end)))
  4726. (defun org-agenda-skip-if-todo (args end)
  4727. "Helper function for `org-agenda-skip-if', do not use it directly.
  4728. ARGS is a list with first element either `todo', `nottodo',
  4729. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4730. a list of TODO keywords, or a state symbol `todo' or `done' or
  4731. `any'."
  4732. (let ((todo-re
  4733. (concat "^\\*+[ \t]+"
  4734. (regexp-opt
  4735. (pcase args
  4736. (`(,_ todo)
  4737. (org-delete-all org-done-keywords
  4738. (copy-sequence org-todo-keywords-1)))
  4739. (`(,_ done) org-done-keywords)
  4740. (`(,_ any) org-todo-keywords-1)
  4741. (`(,_ ,(pred atom))
  4742. (error "Invalid TODO class or type: %S" args))
  4743. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4744. (`(,_ ,todo-list) todo-list))
  4745. 'words))))
  4746. (pcase args
  4747. (`(todo . ,_)
  4748. (let (case-fold-search) (re-search-forward todo-re end t)))
  4749. (`(nottodo . ,_)
  4750. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4751. (`(todo-unblocked . ,_)
  4752. (catch :unblocked
  4753. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4754. (when (org-entry-blocked-p) (throw :unblocked t)))
  4755. nil))
  4756. (`(nottodo-unblocked . ,_)
  4757. (catch :unblocked
  4758. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4759. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4760. t))
  4761. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4762. ;;;###autoload
  4763. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4764. "Create agenda view for projects that are stuck.
  4765. Stuck projects are project that have no next actions. For the definitions
  4766. of what a project is and how to check if it stuck, customize the variable
  4767. `org-stuck-projects'."
  4768. (interactive)
  4769. (let* ((org-agenda-overriding-header
  4770. (or org-agenda-overriding-header "List of stuck projects: "))
  4771. (matcher (nth 0 org-stuck-projects))
  4772. (todo (nth 1 org-stuck-projects))
  4773. (tags (nth 2 org-stuck-projects))
  4774. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4775. (todo-wds
  4776. (if (not (member "*" todo)) todo
  4777. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4778. (org-delete-all org-done-keywords-for-agenda
  4779. (copy-sequence org-todo-keywords-for-agenda))))
  4780. (todo-re (and todo
  4781. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4782. (mapconcat #'identity todo-wds "\\|"))))
  4783. (tags-re (cond ((null tags) nil)
  4784. ((member "*" tags) org-tag-line-re)
  4785. (tags
  4786. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4787. (concat org-outline-regexp-bol
  4788. ".*?[ \t]:"
  4789. other-tags
  4790. (regexp-opt tags t)
  4791. ":" other-tags "[ \t]*$")))
  4792. (t nil)))
  4793. (re-list (delq nil (list todo-re tags-re gen-re)))
  4794. (skip-re
  4795. (if (null re-list)
  4796. (error "Missing information to identify unstuck projects")
  4797. (mapconcat #'identity re-list "\\|")))
  4798. (org-agenda-skip-function
  4799. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4800. ;; in the subtree.
  4801. (lambda ()
  4802. (and (save-excursion
  4803. (let ((case-fold-search nil))
  4804. (re-search-forward
  4805. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4806. (progn (outline-next-heading) (point))))))
  4807. (org-tags-view nil matcher)
  4808. (setq org-agenda-buffer-name (buffer-name))
  4809. (with-current-buffer org-agenda-buffer-name
  4810. (setq org-agenda-redo-command
  4811. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4812. (let ((inhibit-read-only t))
  4813. (add-text-properties
  4814. (point-min) (point-max)
  4815. `(org-redo-cmd ,org-agenda-redo-command))))))
  4816. ;;; Diary integration
  4817. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4818. (defvar diary-list-entries-hook)
  4819. (defvar diary-time-regexp)
  4820. (defvar diary-modify-entry-list-string-function)
  4821. (defvar diary-file-name-prefix)
  4822. (defvar diary-display-function)
  4823. (defun org-get-entries-from-diary (date)
  4824. "Get the (Emacs Calendar) diary entries for DATE."
  4825. (require 'diary-lib)
  4826. (declare-function diary-fancy-display "diary-lib" ())
  4827. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4828. (diary-display-function #'diary-fancy-display)
  4829. (pop-up-frames nil)
  4830. (diary-list-entries-hook
  4831. (cons 'org-diary-default-entry diary-list-entries-hook))
  4832. (diary-file-name-prefix nil) ; turn this feature off
  4833. (diary-modify-entry-list-string-function
  4834. #'org-modify-diary-entry-string)
  4835. (diary-time-regexp (concat "^" diary-time-regexp))
  4836. entries
  4837. (org-disable-agenda-to-diary t))
  4838. (save-excursion
  4839. (save-window-excursion
  4840. (diary-list-entries date 1)))
  4841. (if (not (get-buffer diary-fancy-buffer))
  4842. (setq entries nil)
  4843. (with-current-buffer diary-fancy-buffer
  4844. (setq buffer-read-only nil)
  4845. (if (zerop (buffer-size))
  4846. ;; No entries
  4847. (setq entries nil)
  4848. ;; Omit the date and other unnecessary stuff
  4849. (org-agenda-cleanup-fancy-diary)
  4850. ;; Add prefix to each line and extend the text properties
  4851. (if (zerop (buffer-size))
  4852. (setq entries nil)
  4853. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4854. (setq entries
  4855. (with-temp-buffer
  4856. (insert entries) (goto-char (point-min))
  4857. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4858. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4859. (replace-match (concat "; " (match-string 1)))))
  4860. (buffer-string)))))
  4861. (set-buffer-modified-p nil)
  4862. (kill-buffer diary-fancy-buffer)))
  4863. (when entries
  4864. (setq entries (org-split-string entries "\n"))
  4865. (setq entries
  4866. (mapcar
  4867. (lambda (x)
  4868. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4869. ;; Extend the text properties to the beginning of the line
  4870. (org-add-props x (text-properties-at (1- (length x)) x)
  4871. 'type "diary" 'date date 'face 'org-agenda-diary))
  4872. entries)))))
  4873. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4874. "Hook run when the fancy diary buffer is cleaned up.")
  4875. (defun org-agenda-cleanup-fancy-diary ()
  4876. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4877. This gets rid of the date, the underline under the date, and the
  4878. dummy entry installed by Org mode to ensure non-empty diary for
  4879. each date. It also removes lines that contain only whitespace."
  4880. (goto-char (point-min))
  4881. (if (looking-at ".*?:[ \t]*")
  4882. (progn
  4883. (replace-match "")
  4884. (re-search-forward "\n=+$" nil t)
  4885. (replace-match "")
  4886. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4887. (re-search-forward "\n=+$" nil t)
  4888. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4889. (goto-char (point-min))
  4890. (while (re-search-forward "^ +\n" nil t)
  4891. (replace-match ""))
  4892. (goto-char (point-min))
  4893. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4894. (replace-match ""))
  4895. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4896. (defun org-modify-diary-entry-string (string)
  4897. "Add text properties to string, allowing Org to act on it."
  4898. (org-add-props string nil
  4899. 'mouse-face 'highlight
  4900. 'help-echo (if buffer-file-name
  4901. (format "mouse-2 or RET jump to diary file %s"
  4902. (abbreviate-file-name buffer-file-name))
  4903. "")
  4904. 'org-agenda-diary-link t
  4905. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4906. (defun org-diary-default-entry ()
  4907. "Add a dummy entry to the diary.
  4908. Needed to avoid empty dates which mess up holiday display."
  4909. ;; Catch the error if dealing with the new add-to-diary-alist
  4910. (when org-disable-agenda-to-diary
  4911. (diary-add-to-list original-date "Org mode dummy" "")))
  4912. (defvar org-diary-last-run-time nil)
  4913. ;;;###autoload
  4914. (defun org-diary (&rest args)
  4915. "Return diary information from org files.
  4916. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4917. It accesses org files and extracts information from those files to be
  4918. listed in the diary. The function accepts arguments specifying what
  4919. items should be listed. For a list of arguments allowed here, see the
  4920. variable `org-agenda-entry-types'.
  4921. The call in the diary file should look like this:
  4922. &%%(org-diary) ~/path/to/some/orgfile.org
  4923. Use a separate line for each org file to check. Or, if you omit the file name,
  4924. all files listed in `org-agenda-files' will be checked automatically:
  4925. &%%(org-diary)
  4926. If you don't give any arguments (as in the example above), the default value
  4927. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4928. So the example above may also be written as
  4929. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4930. The function expects the lisp variables `entry' and `date' to be provided
  4931. by the caller, because this is how the calendar works. Don't use this
  4932. function from a program - use `org-agenda-get-day-entries' instead."
  4933. (with-no-warnings (defvar date) (defvar entry))
  4934. (when (> (- (float-time)
  4935. org-agenda-last-marker-time)
  4936. 5)
  4937. ;; I am not sure if this works with sticky agendas, because the marker
  4938. ;; list is then no longer a global variable.
  4939. (org-agenda-reset-markers))
  4940. (org-compile-prefix-format 'agenda)
  4941. (org-set-sorting-strategy 'agenda)
  4942. (setq args (or args org-agenda-entry-types))
  4943. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4944. (list entry)
  4945. (org-agenda-files t)))
  4946. (time (float-time))
  4947. file rtn results)
  4948. (when (or (not org-diary-last-run-time)
  4949. (> (- time
  4950. org-diary-last-run-time)
  4951. 3))
  4952. (org-agenda-prepare-buffers files))
  4953. (setq org-diary-last-run-time time)
  4954. ;; If this is called during org-agenda, don't return any entries to
  4955. ;; the calendar. Org Agenda will list these entries itself.
  4956. (when org-disable-agenda-to-diary (setq files nil))
  4957. (while (setq file (pop files))
  4958. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4959. (setq results (append results rtn)))
  4960. (when results
  4961. (setq results
  4962. (mapcar (lambda (i) (replace-regexp-in-string
  4963. org-link-bracket-re "\\2" i))
  4964. results))
  4965. (concat (org-agenda-finalize-entries results) "\n"))))
  4966. ;;; Agenda entry finders
  4967. (defun org-agenda--timestamp-to-absolute (&rest args)
  4968. "Call `org-time-string-to-absolute' with ARGS.
  4969. However, throw `:skip' whenever an error is raised."
  4970. (condition-case e
  4971. (apply #'org-time-string-to-absolute args)
  4972. (org-diary-sexp-no-match (throw :skip nil))
  4973. (error
  4974. (message "%s; Skipping entry" (error-message-string e))
  4975. (throw :skip nil))))
  4976. (defun org-agenda-get-day-entries (file date &rest args)
  4977. "Does the work for `org-diary' and `org-agenda'.
  4978. FILE is the path to a file to be checked for entries. DATE is date like
  4979. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4980. which kind of entries should be extracted. For details about these, see
  4981. the documentation of `org-diary'."
  4982. (let* ((org-startup-folded nil)
  4983. (org-startup-align-all-tables nil)
  4984. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4985. (error "No such file %s" file))))
  4986. (if (not buffer)
  4987. ;; If file does not exist, signal it in diary nonetheless.
  4988. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4989. (with-current-buffer buffer
  4990. (unless (derived-mode-p 'org-mode)
  4991. (error "Agenda file %s is not in Org mode" file))
  4992. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4993. (setf org-agenda-current-date date)
  4994. (save-excursion
  4995. (save-restriction
  4996. (if (eq buffer org-agenda-restrict)
  4997. (narrow-to-region org-agenda-restrict-begin
  4998. org-agenda-restrict-end)
  4999. (widen))
  5000. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5001. ;; first in order to populate DEADLINES before passing it.
  5002. ;;
  5003. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5004. ;; guarding us from modifying `org-agenda-entry-types'.
  5005. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5006. (when (and (memq :scheduled args) (memq :scheduled* args))
  5007. (setf args (delq :scheduled* args)))
  5008. (cond
  5009. ((memq :deadline args)
  5010. (setf args (cons :deadline
  5011. (delq :deadline (delq :deadline* args)))))
  5012. ((memq :deadline* args)
  5013. (setf args (cons :deadline* (delq :deadline* args)))))
  5014. ;; Collect list of headlines. Return them flattened.
  5015. (let ((case-fold-search nil) results deadlines)
  5016. (org-dlet
  5017. ((date date))
  5018. (dolist (arg args (apply #'nconc (nreverse results)))
  5019. (pcase arg
  5020. ((and :todo (guard (org-agenda-today-p date)))
  5021. (push (org-agenda-get-todos) results))
  5022. (:timestamp
  5023. (push (org-agenda-get-blocks) results)
  5024. (push (org-agenda-get-timestamps deadlines) results))
  5025. (:sexp
  5026. (push (org-agenda-get-sexps) results))
  5027. (:scheduled
  5028. (push (org-agenda-get-scheduled deadlines) results))
  5029. (:scheduled*
  5030. (push (org-agenda-get-scheduled deadlines t) results))
  5031. (:closed
  5032. (push (org-agenda-get-progress) results))
  5033. (:deadline
  5034. (setf deadlines (org-agenda-get-deadlines))
  5035. (push deadlines results))
  5036. (:deadline*
  5037. (setf deadlines (org-agenda-get-deadlines t))
  5038. (push deadlines results))))))))))))
  5039. (defsubst org-em (x y list)
  5040. "Is X or Y a member of LIST?"
  5041. (or (memq x list) (memq y list)))
  5042. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5043. (defvar org-agenda-sorting-strategy-selected nil)
  5044. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5045. "Retrieve timestamp information for sorting agenda views.
  5046. Given a point or marker POM, returns a cons cell of the timestamp
  5047. and the timestamp type relevant for the sorting strategy in
  5048. `org-agenda-sorting-strategy-selected'."
  5049. (let (ts ts-date-type)
  5050. (save-match-data
  5051. (cond ((org-em 'scheduled-up 'scheduled-down
  5052. org-agenda-sorting-strategy-selected)
  5053. (setq ts (org-entry-get pom "SCHEDULED")
  5054. ts-date-type " scheduled"))
  5055. ((org-em 'deadline-up 'deadline-down
  5056. org-agenda-sorting-strategy-selected)
  5057. (setq ts (org-entry-get pom "DEADLINE")
  5058. ts-date-type " deadline"))
  5059. ((org-em 'ts-up 'ts-down
  5060. org-agenda-sorting-strategy-selected)
  5061. (setq ts (org-entry-get pom "TIMESTAMP")
  5062. ts-date-type " timestamp"))
  5063. ((org-em 'tsia-up 'tsia-down
  5064. org-agenda-sorting-strategy-selected)
  5065. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5066. ts-date-type " timestamp_ia"))
  5067. ((org-em 'timestamp-up 'timestamp-down
  5068. org-agenda-sorting-strategy-selected)
  5069. (setq ts (or (org-entry-get pom "SCHEDULED")
  5070. (org-entry-get pom "DEADLINE")
  5071. (org-entry-get pom "TIMESTAMP")
  5072. (org-entry-get pom "TIMESTAMP_IA"))
  5073. ts-date-type ""))
  5074. (t (setq ts-date-type "")))
  5075. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5076. ts-date-type))))
  5077. (defun org-agenda-get-todos ()
  5078. "Return the TODO information for agenda display."
  5079. (let* ((props (list 'face nil
  5080. 'done-face 'org-agenda-done
  5081. 'org-not-done-regexp org-not-done-regexp
  5082. 'org-todo-regexp org-todo-regexp
  5083. 'org-complex-heading-regexp org-complex-heading-regexp
  5084. 'mouse-face 'highlight
  5085. 'help-echo
  5086. (format "mouse-2 or RET jump to org file %s"
  5087. (abbreviate-file-name buffer-file-name))))
  5088. (case-fold-search nil)
  5089. (regexp (format org-heading-keyword-regexp-format
  5090. (cond
  5091. ((and org-select-this-todo-keyword
  5092. (equal org-select-this-todo-keyword "*"))
  5093. org-todo-regexp)
  5094. (org-select-this-todo-keyword
  5095. (concat "\\("
  5096. (mapconcat #'identity
  5097. (org-split-string
  5098. org-select-this-todo-keyword
  5099. "|")
  5100. "\\|")
  5101. "\\)"))
  5102. (t org-not-done-regexp))))
  5103. marker priority category level tags todo-state
  5104. ts-date ts-date-type ts-date-pair
  5105. ee txt beg end inherited-tags todo-state-end-pos
  5106. effort effort-minutes)
  5107. (goto-char (point-min))
  5108. (while (re-search-forward regexp nil t)
  5109. (catch :skip
  5110. (save-match-data
  5111. (beginning-of-line)
  5112. (org-agenda-skip)
  5113. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5114. (unless (and (setq todo-state (org-get-todo-state))
  5115. (setq todo-state-end-pos (match-end 2)))
  5116. (goto-char end)
  5117. (throw :skip nil))
  5118. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5119. (goto-char (1+ beg))
  5120. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5121. (throw :skip nil)))
  5122. (goto-char (match-beginning 2))
  5123. (setq marker (org-agenda-new-marker (match-beginning 0))
  5124. category (org-get-category)
  5125. effort (save-match-data (or (get-text-property (point) 'effort)
  5126. (org-entry-get (point) org-effort-property)))
  5127. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5128. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5129. ts-date (car ts-date-pair)
  5130. ts-date-type (cdr ts-date-pair)
  5131. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5132. inherited-tags
  5133. (or (eq org-agenda-show-inherited-tags 'always)
  5134. (and (listp org-agenda-show-inherited-tags)
  5135. (memq 'todo org-agenda-show-inherited-tags))
  5136. (and (eq org-agenda-show-inherited-tags t)
  5137. (or (eq org-agenda-use-tag-inheritance t)
  5138. (memq 'todo org-agenda-use-tag-inheritance))))
  5139. tags (org-get-tags nil (not inherited-tags))
  5140. level (make-string (org-reduced-level (org-outline-level)) ? )
  5141. txt (org-agenda-format-item ""
  5142. (org-add-props txt nil
  5143. 'effort effort
  5144. 'effort-minutes effort-minutes)
  5145. level category tags t)
  5146. priority (1+ (org-get-priority txt)))
  5147. (org-add-props txt props
  5148. 'org-marker marker 'org-hd-marker marker
  5149. 'priority priority
  5150. 'effort effort 'effort-minutes effort-minutes
  5151. 'level level
  5152. 'ts-date ts-date
  5153. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5154. (push txt ee)
  5155. (if org-agenda-todo-list-sublevels
  5156. (goto-char todo-state-end-pos)
  5157. (org-end-of-subtree 'invisible))))
  5158. (nreverse ee)))
  5159. (defun org-agenda-todo-custom-ignore-p (time n)
  5160. "Check whether timestamp is farther away than n number of days.
  5161. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5162. `org-agenda-todo-ignore-scheduled' or
  5163. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5164. (let ((days (org-time-stamp-to-now
  5165. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5166. (if (>= n 0)
  5167. (>= days n)
  5168. (<= days n))))
  5169. ;;;###autoload
  5170. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5171. (&optional end)
  5172. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5173. (when (or org-agenda-todo-ignore-with-date
  5174. org-agenda-todo-ignore-scheduled
  5175. org-agenda-todo-ignore-deadlines
  5176. org-agenda-todo-ignore-timestamp)
  5177. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5178. (save-excursion
  5179. (or (and org-agenda-todo-ignore-with-date
  5180. (re-search-forward org-ts-regexp end t))
  5181. (and org-agenda-todo-ignore-scheduled
  5182. (re-search-forward org-scheduled-time-regexp end t)
  5183. (cond
  5184. ((eq org-agenda-todo-ignore-scheduled 'future)
  5185. (> (org-time-stamp-to-now
  5186. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5187. 0))
  5188. ((eq org-agenda-todo-ignore-scheduled 'past)
  5189. (<= (org-time-stamp-to-now
  5190. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5191. 0))
  5192. ((numberp org-agenda-todo-ignore-scheduled)
  5193. (org-agenda-todo-custom-ignore-p
  5194. (match-string 1) org-agenda-todo-ignore-scheduled))
  5195. (t)))
  5196. (and org-agenda-todo-ignore-deadlines
  5197. (re-search-forward org-deadline-time-regexp end t)
  5198. (cond
  5199. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5200. ((eq org-agenda-todo-ignore-deadlines 'far)
  5201. (not (org-deadline-close-p (match-string 1))))
  5202. ((eq org-agenda-todo-ignore-deadlines 'future)
  5203. (> (org-time-stamp-to-now
  5204. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5205. 0))
  5206. ((eq org-agenda-todo-ignore-deadlines 'past)
  5207. (<= (org-time-stamp-to-now
  5208. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5209. 0))
  5210. ((numberp org-agenda-todo-ignore-deadlines)
  5211. (org-agenda-todo-custom-ignore-p
  5212. (match-string 1) org-agenda-todo-ignore-deadlines))
  5213. (t (org-deadline-close-p (match-string 1)))))
  5214. (and org-agenda-todo-ignore-timestamp
  5215. (let ((buffer (current-buffer))
  5216. (regexp
  5217. (concat
  5218. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5219. (start (point)))
  5220. ;; Copy current buffer into a temporary one
  5221. (with-temp-buffer
  5222. (insert-buffer-substring buffer start end)
  5223. (goto-char (point-min))
  5224. ;; Delete SCHEDULED and DEADLINE items
  5225. (while (re-search-forward regexp end t)
  5226. (delete-region (match-beginning 0) (match-end 0)))
  5227. (goto-char (point-min))
  5228. ;; No search for timestamp left
  5229. (when (re-search-forward org-ts-regexp nil t)
  5230. (cond
  5231. ((eq org-agenda-todo-ignore-timestamp 'future)
  5232. (> (org-time-stamp-to-now
  5233. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5234. 0))
  5235. ((eq org-agenda-todo-ignore-timestamp 'past)
  5236. (<= (org-time-stamp-to-now
  5237. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5238. 0))
  5239. ((numberp org-agenda-todo-ignore-timestamp)
  5240. (org-agenda-todo-custom-ignore-p
  5241. (match-string 1) org-agenda-todo-ignore-timestamp))
  5242. (t))))))))))
  5243. (defun org-agenda-get-timestamps (&optional deadlines)
  5244. "Return the date stamp information for agenda display.
  5245. Optional argument DEADLINES is a list of deadline items to be
  5246. displayed in agenda view."
  5247. (with-no-warnings (defvar date))
  5248. (let* ((props (list 'face 'org-agenda-calendar-event
  5249. 'org-not-done-regexp org-not-done-regexp
  5250. 'org-todo-regexp org-todo-regexp
  5251. 'org-complex-heading-regexp org-complex-heading-regexp
  5252. 'mouse-face 'highlight
  5253. 'help-echo
  5254. (format "mouse-2 or RET jump to Org file %s"
  5255. (abbreviate-file-name buffer-file-name))))
  5256. (current (calendar-absolute-from-gregorian date))
  5257. (today (org-today))
  5258. (deadline-position-alist
  5259. (mapcar (lambda (d)
  5260. (let ((m (get-text-property 0 'org-hd-marker d)))
  5261. (and m (marker-position m))))
  5262. deadlines))
  5263. ;; Match time-stamps set to current date, time-stamps with
  5264. ;; a repeater, and S-exp time-stamps.
  5265. (regexp
  5266. (concat
  5267. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5268. (regexp-quote
  5269. (substring
  5270. (format-time-string
  5271. (car org-time-stamp-formats)
  5272. (encode-time ; DATE bound by calendar
  5273. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5274. 1 11))
  5275. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5276. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5277. timestamp-items)
  5278. (goto-char (point-min))
  5279. (while (re-search-forward regexp nil t)
  5280. ;; Skip date ranges, scheduled and deadlines, which are handled
  5281. ;; specially. Also skip time-stamps before first headline as
  5282. ;; there would be no entry to add to the agenda. Eventually,
  5283. ;; ignore clock entries.
  5284. (catch :skip
  5285. (save-match-data
  5286. (when (or (org-at-date-range-p)
  5287. (org-at-planning-p)
  5288. (org-before-first-heading-p)
  5289. (and org-agenda-include-inactive-timestamps
  5290. (org-at-clock-log-p))
  5291. (not (eq 'timestamp (org-element-type (org-element-context)))))
  5292. (throw :skip nil))
  5293. (org-agenda-skip))
  5294. (let* ((pos (match-beginning 0))
  5295. (repeat (match-string 1))
  5296. (sexp-entry (match-string 3))
  5297. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5298. (save-excursion
  5299. (goto-char pos)
  5300. (looking-at org-ts-regexp-both)
  5301. (match-string 0))))
  5302. (todo-state (org-get-todo-state))
  5303. (warntime (get-text-property (point) 'org-appt-warntime))
  5304. (done? (member todo-state org-done-keywords)))
  5305. ;; Possibly skip done tasks.
  5306. (when (and done? org-agenda-skip-timestamp-if-done)
  5307. (throw :skip t))
  5308. ;; S-exp entry doesn't match current day: skip it.
  5309. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5310. (throw :skip nil))
  5311. (when repeat
  5312. (let* ((past
  5313. ;; A repeating time stamp is shown at its base
  5314. ;; date and every repeated date up to TODAY. If
  5315. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5316. ;; however, only the last repeat before today
  5317. ;; (inclusive) is shown.
  5318. (org-agenda--timestamp-to-absolute
  5319. repeat
  5320. (if (or (> current today)
  5321. (eq org-agenda-prefer-last-repeat t)
  5322. (member todo-state org-agenda-prefer-last-repeat))
  5323. today
  5324. current)
  5325. 'past (current-buffer) pos))
  5326. (future
  5327. ;; Display every repeated date past TODAY
  5328. ;; (exclusive) unless
  5329. ;; `org-agenda-show-future-repeats' is nil. If
  5330. ;; this variable is set to `next', only display
  5331. ;; the first repeated date after TODAY
  5332. ;; (exclusive).
  5333. (cond
  5334. ((<= current today) past)
  5335. ((not org-agenda-show-future-repeats) past)
  5336. (t
  5337. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5338. (1+ today)
  5339. current)))
  5340. (org-agenda--timestamp-to-absolute
  5341. repeat base 'future (current-buffer) pos))))))
  5342. (when (and (/= current past) (/= current future))
  5343. (throw :skip nil))))
  5344. (save-excursion
  5345. (re-search-backward org-outline-regexp-bol nil t)
  5346. ;; Possibly skip time-stamp when a deadline is set.
  5347. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5348. (assq (point) deadline-position-alist))
  5349. (throw :skip nil))
  5350. (let* ((category (org-get-category pos))
  5351. (effort (org-entry-get pos org-effort-property))
  5352. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5353. (inherited-tags
  5354. (or (eq org-agenda-show-inherited-tags 'always)
  5355. (and (consp org-agenda-show-inherited-tags)
  5356. (memq 'agenda org-agenda-show-inherited-tags))
  5357. (and (eq org-agenda-show-inherited-tags t)
  5358. (or (eq org-agenda-use-tag-inheritance t)
  5359. (memq 'agenda
  5360. org-agenda-use-tag-inheritance)))))
  5361. (tags (org-get-tags nil (not inherited-tags)))
  5362. (level (make-string (org-reduced-level (org-outline-level))
  5363. ?\s))
  5364. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5365. (match-string 1)))
  5366. (inactive? (= (char-after pos) ?\[))
  5367. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5368. (item
  5369. (org-agenda-format-item
  5370. (and inactive? org-agenda-inactive-leader)
  5371. (org-add-props head nil
  5372. 'effort effort
  5373. 'effort-minutes effort-minutes)
  5374. level category tags time-stamp org-ts-regexp habit?)))
  5375. (org-add-props item props
  5376. 'priority (if habit?
  5377. (org-habit-get-priority (org-habit-parse-todo))
  5378. (org-get-priority item))
  5379. 'org-marker (org-agenda-new-marker pos)
  5380. 'org-hd-marker (org-agenda-new-marker)
  5381. 'date date
  5382. 'level level
  5383. 'effort effort 'effort-minutes effort-minutes
  5384. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5385. current)
  5386. 'todo-state todo-state
  5387. 'warntime warntime
  5388. 'type "timestamp")
  5389. (push item timestamp-items))))
  5390. (when org-agenda-skip-additional-timestamps-same-entry
  5391. (outline-next-heading))))
  5392. (nreverse timestamp-items)))
  5393. (defun org-agenda-get-sexps ()
  5394. "Return the sexp information for agenda display."
  5395. (require 'diary-lib)
  5396. (with-no-warnings (defvar date) (defvar entry))
  5397. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5398. 'mouse-face 'highlight
  5399. 'help-echo
  5400. (format "mouse-2 or RET jump to org file %s"
  5401. (abbreviate-file-name buffer-file-name))))
  5402. (regexp "^&?%%(")
  5403. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5404. ;; so as to "hide" any current binding for it?
  5405. marker category extra level ee txt tags entry
  5406. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5407. effort effort-minutes)
  5408. (goto-char (point-min))
  5409. (while (re-search-forward regexp nil t)
  5410. (catch :skip
  5411. (org-agenda-skip)
  5412. (setq beg (match-beginning 0))
  5413. (goto-char (1- (match-end 0)))
  5414. (setq b (point))
  5415. (forward-sexp 1)
  5416. (setq sexp (buffer-substring b (point)))
  5417. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5418. (org-trim (match-string 1))
  5419. ""))
  5420. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5421. (when result
  5422. (setq marker (org-agenda-new-marker beg)
  5423. level (make-string (org-reduced-level (org-outline-level)) ? )
  5424. category (org-get-category beg)
  5425. effort (save-match-data (or (get-text-property (point) 'effort)
  5426. (org-entry-get (point) org-effort-property)))
  5427. inherited-tags
  5428. (or (eq org-agenda-show-inherited-tags 'always)
  5429. (and (listp org-agenda-show-inherited-tags)
  5430. (memq 'agenda org-agenda-show-inherited-tags))
  5431. (and (eq org-agenda-show-inherited-tags t)
  5432. (or (eq org-agenda-use-tag-inheritance t)
  5433. (memq 'agenda org-agenda-use-tag-inheritance))))
  5434. tags (org-get-tags nil (not inherited-tags))
  5435. todo-state (org-get-todo-state)
  5436. warntime (get-text-property (point) 'org-appt-warntime)
  5437. extra nil)
  5438. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5439. (dolist (r (if (stringp result)
  5440. (list result)
  5441. result)) ;; we expect a list here
  5442. (when (and org-agenda-diary-sexp-prefix
  5443. (string-match org-agenda-diary-sexp-prefix r))
  5444. (setq extra (match-string 0 r)
  5445. r (replace-match "" nil nil r)))
  5446. (if (string-match "\\S-" r)
  5447. (setq txt r)
  5448. (setq txt "SEXP entry returned empty string"))
  5449. (setq txt (org-agenda-format-item extra
  5450. (org-add-props txt nil
  5451. 'effort effort
  5452. 'effort-minutes effort-minutes)
  5453. level category tags 'time))
  5454. (org-add-props txt props 'org-marker marker
  5455. 'date date 'todo-state todo-state
  5456. 'effort effort 'effort-minutes effort-minutes
  5457. 'level level 'type "sexp" 'warntime warntime)
  5458. (push txt ee)))))
  5459. (nreverse ee)))
  5460. ;; Calendar sanity: define some functions that are independent of
  5461. ;; `calendar-date-style'.
  5462. (defun org-anniversary (year month day &optional mark)
  5463. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5464. (with-no-warnings
  5465. (let ((calendar-date-style 'iso))
  5466. (diary-anniversary year month day mark))))
  5467. (defun org-cyclic (N year month day &optional mark)
  5468. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5469. (with-no-warnings
  5470. (let ((calendar-date-style 'iso))
  5471. (diary-cyclic N year month day mark))))
  5472. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5473. "Like `diary-block', but with fixed (ISO) order of arguments."
  5474. (with-no-warnings
  5475. (let ((calendar-date-style 'iso))
  5476. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5477. (defun org-date (year month day &optional mark)
  5478. "Like `diary-date', but with fixed (ISO) order of arguments."
  5479. (with-no-warnings
  5480. (let ((calendar-date-style 'iso))
  5481. (diary-date year month day mark))))
  5482. ;; Define the `org-class' function
  5483. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5484. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5485. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5486. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5487. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5488. `holidays', then any date that is known by the Emacs calendar to be a
  5489. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5490. then those holidays will be skipped."
  5491. (with-no-warnings (defvar date) (defvar entry))
  5492. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5493. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5494. (d (calendar-absolute-from-gregorian date))
  5495. (h (when skip-weeks (calendar-check-holidays date))))
  5496. (and
  5497. (<= date1 d)
  5498. (<= d date2)
  5499. (= (calendar-day-of-week date) dayname)
  5500. (or (not skip-weeks)
  5501. (progn
  5502. (require 'cal-iso)
  5503. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5504. (not (or (and h (memq 'holidays skip-weeks))
  5505. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5506. entry)))
  5507. (defalias 'org-get-closed #'org-agenda-get-progress)
  5508. (defun org-agenda-get-progress ()
  5509. "Return the logged TODO entries for agenda display."
  5510. (with-no-warnings (defvar date))
  5511. (let* ((props (list 'mouse-face 'highlight
  5512. 'org-not-done-regexp org-not-done-regexp
  5513. 'org-todo-regexp org-todo-regexp
  5514. 'org-complex-heading-regexp org-complex-heading-regexp
  5515. 'help-echo
  5516. (format "mouse-2 or RET jump to org file %s"
  5517. (abbreviate-file-name buffer-file-name))))
  5518. (items (if (consp org-agenda-show-log-scoped)
  5519. org-agenda-show-log-scoped
  5520. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5521. '(clock)
  5522. org-agenda-log-mode-items)))
  5523. (parts
  5524. (delq nil
  5525. (list
  5526. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5527. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5528. (when (memq 'state items)
  5529. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5530. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5531. (error "`org-agenda-log-mode-items' is empty")))
  5532. (regexp (concat
  5533. "\\(" parts-re "\\)"
  5534. " *\\["
  5535. (regexp-quote
  5536. (substring
  5537. (format-time-string
  5538. (car org-time-stamp-formats)
  5539. (encode-time ; DATE bound by calendar
  5540. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5541. 1 11))))
  5542. (org-agenda-search-headline-for-time nil)
  5543. marker hdmarker priority category level tags closedp type
  5544. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5545. effort effort-minutes)
  5546. (goto-char (point-min))
  5547. (while (re-search-forward regexp nil t)
  5548. (catch :skip
  5549. (org-agenda-skip)
  5550. (setq marker (org-agenda-new-marker (match-beginning 0))
  5551. closedp (equal (match-string 1) org-closed-string)
  5552. statep (equal (string-to-char (match-string 1)) ?-)
  5553. clockp (not (or closedp statep))
  5554. state (and statep (match-string 2))
  5555. category (org-get-category (match-beginning 0))
  5556. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5557. effort (save-match-data (or (get-text-property (point) 'effort)
  5558. (org-entry-get (point) org-effort-property))))
  5559. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5560. (when (string-match "\\]" timestr)
  5561. ;; substring should only run to end of time stamp
  5562. (setq rest (substring timestr (match-end 0))
  5563. timestr (substring timestr 0 (match-end 0)))
  5564. (if (and (not closedp) (not statep)
  5565. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5566. rest))
  5567. (progn (setq timestr (concat (substring timestr 0 -1)
  5568. "-" (match-string 1 rest) "]"))
  5569. (setq clocked (match-string 2 rest)))
  5570. (setq clocked "-")))
  5571. (save-excursion
  5572. (setq extra
  5573. (cond
  5574. ((not org-agenda-log-mode-add-notes) nil)
  5575. (statep
  5576. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5577. (match-string 1)))
  5578. (clockp
  5579. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5580. (match-string 1)))))
  5581. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5582. (throw :skip nil)
  5583. (goto-char (match-beginning 0))
  5584. (setq hdmarker (org-agenda-new-marker)
  5585. inherited-tags
  5586. (or (eq org-agenda-show-inherited-tags 'always)
  5587. (and (listp org-agenda-show-inherited-tags)
  5588. (memq 'todo org-agenda-show-inherited-tags))
  5589. (and (eq org-agenda-show-inherited-tags t)
  5590. (or (eq org-agenda-use-tag-inheritance t)
  5591. (memq 'todo org-agenda-use-tag-inheritance))))
  5592. tags (org-get-tags nil (not inherited-tags))
  5593. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5594. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5595. (setq txt (match-string 1))
  5596. (when extra
  5597. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5598. (setq txt (concat (substring txt 0 (match-beginning 1))
  5599. " - " extra " " (match-string 2 txt)))
  5600. (setq txt (concat txt " - " extra))))
  5601. (setq txt (org-agenda-format-item
  5602. (cond
  5603. (closedp "Closed: ")
  5604. (statep (concat "State: (" state ")"))
  5605. (t (concat "Clocked: (" clocked ")")))
  5606. (org-add-props txt nil
  5607. 'effort effort
  5608. 'effort-minutes effort-minutes)
  5609. level category tags timestr)))
  5610. (setq type (cond (closedp "closed")
  5611. (statep "state")
  5612. (t "clock")))
  5613. (setq priority 100000)
  5614. (org-add-props txt props
  5615. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5616. 'priority priority 'level level
  5617. 'effort effort 'effort-minutes effort-minutes
  5618. 'type type 'date date
  5619. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5620. (push txt ee))
  5621. (goto-char (point-at-eol))))
  5622. (nreverse ee)))
  5623. (defun org-agenda-show-clocking-issues ()
  5624. "Add overlays, showing issues with clocking.
  5625. See also the user option `org-agenda-clock-consistency-checks'."
  5626. (interactive)
  5627. (let* ((pl org-agenda-clock-consistency-checks)
  5628. (re (concat "^[ \t]*"
  5629. org-clock-string
  5630. "[ \t]+"
  5631. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5632. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5633. (tlstart 0.)
  5634. (tlend 0.)
  5635. (maxtime (org-duration-to-minutes
  5636. (or (plist-get pl :max-duration) "24:00")))
  5637. (mintime (org-duration-to-minutes
  5638. (or (plist-get pl :min-duration) 0)))
  5639. (maxgap (org-duration-to-minutes
  5640. ;; default 30:00 means never complain
  5641. (or (plist-get pl :max-gap) "30:00")))
  5642. (gapok (mapcar #'org-duration-to-minutes
  5643. (plist-get pl :gap-ok-around)))
  5644. (def-face (or (plist-get pl :default-face)
  5645. '((:background "DarkRed") (:foreground "white"))))
  5646. issue face m te ts dt ov)
  5647. (goto-char (point-min))
  5648. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5649. (setq issue nil face def-face)
  5650. (catch 'next
  5651. (setq m (org-get-at-bol 'org-marker)
  5652. te nil ts nil)
  5653. (unless (and m (markerp m))
  5654. (setq issue "No valid clock line") (throw 'next t))
  5655. (org-with-point-at m
  5656. (save-excursion
  5657. (goto-char (point-at-bol))
  5658. (unless (looking-at re)
  5659. (error "No valid Clock line")
  5660. (throw 'next t))
  5661. (unless (match-end 3)
  5662. (setq issue
  5663. (format
  5664. "No end time: (%s)"
  5665. (org-duration-from-minutes
  5666. (floor
  5667. (- (float-time (org-current-time))
  5668. (float-time (org-time-string-to-time (match-string 1))))
  5669. 60)))
  5670. face (or (plist-get pl :no-end-time-face) face))
  5671. (throw 'next t))
  5672. (setq ts (match-string 1)
  5673. te (match-string 3)
  5674. ts (float-time (org-time-string-to-time ts))
  5675. te (float-time (org-time-string-to-time te))
  5676. dt (- te ts))))
  5677. (cond
  5678. ((> dt (* 60 maxtime))
  5679. ;; a very long clocking chunk
  5680. (setq issue (format "Clocking interval is very long: %s"
  5681. (org-duration-from-minutes (floor dt 60)))
  5682. face (or (plist-get pl :long-face) face)))
  5683. ((< dt (* 60 mintime))
  5684. ;; a very short clocking chunk
  5685. (setq issue (format "Clocking interval is very short: %s"
  5686. (org-duration-from-minutes (floor dt 60)))
  5687. face (or (plist-get pl :short-face) face)))
  5688. ((and (> tlend 0) (< ts tlend))
  5689. ;; Two clock entries are overlapping
  5690. (setq issue (format "Clocking overlap: %d minutes"
  5691. (/ (- tlend ts) 60))
  5692. face (or (plist-get pl :overlap-face) face)))
  5693. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5694. ;; There is a gap, lets see if we need to report it
  5695. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5696. (setq issue (format "Clocking gap: %d minutes"
  5697. (/ (- ts tlend) 60))
  5698. face (or (plist-get pl :gap-face) face))))
  5699. (t nil)))
  5700. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5701. (when issue
  5702. ;; OK, there was some issue, add an overlay to show the issue
  5703. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5704. (overlay-put ov 'before-string
  5705. (concat
  5706. (org-add-props
  5707. (format "%-43s" (concat " " issue))
  5708. nil
  5709. 'face face)
  5710. "\n"))
  5711. (overlay-put ov 'evaporate t)))))
  5712. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5713. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5714. (catch 'exit
  5715. (unless ok-list
  5716. ;; there are no OK times for gaps...
  5717. (throw 'exit nil))
  5718. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5719. ;; This is more than 24 hours, so it is OK.
  5720. ;; because we have at least one OK time, that must be in the
  5721. ;; 24 hour interval.
  5722. (throw 'exit t))
  5723. ;; We have a shorter gap.
  5724. ;; Now we have to get the minute of the day when these times are
  5725. (let* ((t1dec (decode-time t1))
  5726. (t2dec (decode-time t2))
  5727. ;; compute the minute on the day
  5728. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5729. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5730. (when (< min2 min1)
  5731. ;; if min2 is smaller than min1, this means it is on the next day.
  5732. ;; Wrap it to after midnight.
  5733. (setq min2 (+ min2 1440)))
  5734. ;; Now check if any of the OK times is in the gap
  5735. (mapc (lambda (x)
  5736. ;; Wrap the time to after midnight if necessary
  5737. (when (< x min1) (setq x (+ x 1440)))
  5738. ;; Check if in interval
  5739. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5740. ok-list)
  5741. ;; Nope, this gap is not OK
  5742. nil)))
  5743. (defun org-agenda-get-deadlines (&optional with-hour)
  5744. "Return the deadline information for agenda display.
  5745. When WITH-HOUR is non-nil, only return deadlines with an hour
  5746. specification like [h]h:mm."
  5747. (with-no-warnings (defvar date))
  5748. (let* ((props (list 'mouse-face 'highlight
  5749. 'org-not-done-regexp org-not-done-regexp
  5750. 'org-todo-regexp org-todo-regexp
  5751. 'org-complex-heading-regexp org-complex-heading-regexp
  5752. 'help-echo
  5753. (format "mouse-2 or RET jump to org file %s"
  5754. (abbreviate-file-name buffer-file-name))))
  5755. (regexp (if with-hour
  5756. org-deadline-time-hour-regexp
  5757. org-deadline-time-regexp))
  5758. (today (org-today))
  5759. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5760. (current (calendar-absolute-from-gregorian date))
  5761. deadline-items)
  5762. (goto-char (point-min))
  5763. (if (org-element--cache-active-p)
  5764. (org-element-cache-map
  5765. (lambda (el)
  5766. (when (and (org-element-property :deadline el)
  5767. (or (not with-hour)
  5768. (org-element-property
  5769. :hour-start
  5770. (org-element-property :deadline el))
  5771. (org-element-property
  5772. :hour-end
  5773. (org-element-property :deadline el))))
  5774. (goto-char (org-element-property :contents-begin el))
  5775. (catch :skip
  5776. (org-agenda-skip el)
  5777. (let* ((s (substring (org-element-property
  5778. :raw-value
  5779. (org-element-property :deadline el))
  5780. 1 -1))
  5781. (pos (save-excursion
  5782. (goto-char (org-element-property :contents-begin el))
  5783. ;; We intentionally leave NOERROR
  5784. ;; argument in `re-search-forward' nil. If
  5785. ;; the search fails here, something went
  5786. ;; wrong and we are looking at
  5787. ;; non-matching headline.
  5788. (re-search-forward regexp (line-end-position))
  5789. (1- (match-beginning 1))))
  5790. (todo-state (org-element-property :todo-keyword el))
  5791. (done? (eq 'done (org-element-property :todo-type el)))
  5792. (sexp? (eq 'diary
  5793. (org-element-property
  5794. :type (org-element-property :deadline el))))
  5795. ;; DEADLINE is the deadline date for the entry. It is
  5796. ;; either the base date or the last repeat, according
  5797. ;; to `org-agenda-prefer-last-repeat'.
  5798. (deadline
  5799. (cond
  5800. (sexp? (org-agenda--timestamp-to-absolute s current))
  5801. ((or (eq org-agenda-prefer-last-repeat t)
  5802. (member todo-state org-agenda-prefer-last-repeat))
  5803. (org-agenda--timestamp-to-absolute
  5804. s today 'past (current-buffer) pos))
  5805. (t (org-agenda--timestamp-to-absolute s))))
  5806. ;; REPEAT is the future repeat closest from CURRENT,
  5807. ;; according to `org-agenda-show-future-repeats'. If
  5808. ;; the latter is nil, or if the time stamp has no
  5809. ;; repeat part, default to DEADLINE.
  5810. (repeat
  5811. (cond
  5812. (sexp? deadline)
  5813. ((<= current today) deadline)
  5814. ((not org-agenda-show-future-repeats) deadline)
  5815. (t
  5816. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5817. (1+ today)
  5818. current)))
  5819. (org-agenda--timestamp-to-absolute
  5820. s base 'future (current-buffer) pos)))))
  5821. (diff (- deadline current))
  5822. (suppress-prewarning
  5823. (let ((scheduled
  5824. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5825. (org-element-property
  5826. :raw-value
  5827. (org-element-property :scheduled el)))))
  5828. (cond
  5829. ((not scheduled) nil)
  5830. ;; The current item has a scheduled date, so
  5831. ;; evaluate its prewarning lead time.
  5832. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5833. ;; Use global prewarning-restart lead time.
  5834. org-agenda-skip-deadline-prewarning-if-scheduled)
  5835. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5836. 'pre-scheduled)
  5837. ;; Set pre-warning to no earlier than SCHEDULED.
  5838. (min (- deadline
  5839. (org-agenda--timestamp-to-absolute scheduled))
  5840. org-deadline-warning-days))
  5841. ;; Set pre-warning to deadline.
  5842. (t 0))))
  5843. (wdays (or suppress-prewarning (org-get-wdays s))))
  5844. (cond
  5845. ;; Only display deadlines at their base date, at future
  5846. ;; repeat occurrences or in today agenda.
  5847. ((= current deadline) nil)
  5848. ((= current repeat) nil)
  5849. ((not today?) (throw :skip nil))
  5850. ;; Upcoming deadline: display within warning period WDAYS.
  5851. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5852. ;; Overdue deadline: warn about it for
  5853. ;; `org-deadline-past-days' duration.
  5854. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5855. ;; Possibly skip done tasks.
  5856. (when (and done?
  5857. (or org-agenda-skip-deadline-if-done
  5858. (/= deadline current)))
  5859. (throw :skip nil))
  5860. (save-excursion
  5861. (goto-char (org-element-property :begin el))
  5862. (let* ((category (org-get-category))
  5863. (effort (save-match-data (or (get-text-property (point) 'effort)
  5864. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5865. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5866. (level (make-string (org-element-property :level el)
  5867. ?\s))
  5868. (head (save-excursion
  5869. (goto-char (org-element-property :begin el))
  5870. (re-search-forward org-outline-regexp-bol)
  5871. (buffer-substring-no-properties (point) (line-end-position))))
  5872. (inherited-tags
  5873. (or (eq org-agenda-show-inherited-tags 'always)
  5874. (and (listp org-agenda-show-inherited-tags)
  5875. (memq 'agenda org-agenda-show-inherited-tags))
  5876. (and (eq org-agenda-show-inherited-tags t)
  5877. (or (eq org-agenda-use-tag-inheritance t)
  5878. (memq 'agenda
  5879. org-agenda-use-tag-inheritance)))))
  5880. (tags (org-get-tags el (not inherited-tags)))
  5881. (time
  5882. (cond
  5883. ;; No time of day designation if it is only
  5884. ;; a reminder.
  5885. ((and (/= current deadline) (/= current repeat)) nil)
  5886. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5887. (concat (substring s (match-beginning 1)) " "))
  5888. (t 'time)))
  5889. (item
  5890. (org-agenda-format-item
  5891. ;; Insert appropriate suffixes before deadlines.
  5892. ;; Those only apply to today agenda.
  5893. (pcase-let ((`(,now ,future ,past)
  5894. org-agenda-deadline-leaders))
  5895. (cond
  5896. ((and today? (< deadline today)) (format past (- diff)))
  5897. ((and today? (> deadline today)) (format future diff))
  5898. (t now)))
  5899. (org-add-props head nil
  5900. 'effort effort
  5901. 'effort-minutes effort-minutes)
  5902. level category tags time))
  5903. (face (org-agenda-deadline-face
  5904. (- 1 (/ (float diff) (max wdays 1)))))
  5905. (upcoming? (and today? (> deadline today)))
  5906. (warntime (get-text-property (point) 'org-appt-warntime)))
  5907. (org-add-props item props
  5908. 'org-marker (org-agenda-new-marker pos)
  5909. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5910. 'warntime warntime
  5911. 'level level
  5912. 'effort effort 'effort-minutes effort-minutes
  5913. 'ts-date deadline
  5914. 'priority
  5915. ;; Adjust priority to today reminders about deadlines.
  5916. ;; Overdue deadlines get the highest priority
  5917. ;; increase, then imminent deadlines and eventually
  5918. ;; more distant deadlines.
  5919. (let ((adjust (if today? (- diff) 0)))
  5920. (+ adjust (org-get-priority item)))
  5921. 'todo-state todo-state
  5922. 'type (if upcoming? "upcoming-deadline" "deadline")
  5923. 'date (if upcoming? date deadline)
  5924. 'face (if done? 'org-agenda-done face)
  5925. 'undone-face face
  5926. 'done-face 'org-agenda-done)
  5927. (push item deadline-items)))))))
  5928. :next-re regexp
  5929. :fail-re regexp
  5930. :narrow t)
  5931. (while (re-search-forward regexp nil t)
  5932. (catch :skip
  5933. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5934. (org-agenda-skip)
  5935. (let* ((s (match-string 1))
  5936. (pos (1- (match-beginning 1)))
  5937. (todo-state (save-match-data (org-get-todo-state)))
  5938. (done? (member todo-state org-done-keywords))
  5939. (sexp? (string-prefix-p "%%" s))
  5940. ;; DEADLINE is the deadline date for the entry. It is
  5941. ;; either the base date or the last repeat, according
  5942. ;; to `org-agenda-prefer-last-repeat'.
  5943. (deadline
  5944. (cond
  5945. (sexp? (org-agenda--timestamp-to-absolute s current))
  5946. ((or (eq org-agenda-prefer-last-repeat t)
  5947. (member todo-state org-agenda-prefer-last-repeat))
  5948. (org-agenda--timestamp-to-absolute
  5949. s today 'past (current-buffer) pos))
  5950. (t (org-agenda--timestamp-to-absolute s))))
  5951. ;; REPEAT is the future repeat closest from CURRENT,
  5952. ;; according to `org-agenda-show-future-repeats'. If
  5953. ;; the latter is nil, or if the time stamp has no
  5954. ;; repeat part, default to DEADLINE.
  5955. (repeat
  5956. (cond
  5957. (sexp? deadline)
  5958. ((<= current today) deadline)
  5959. ((not org-agenda-show-future-repeats) deadline)
  5960. (t
  5961. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5962. (1+ today)
  5963. current)))
  5964. (org-agenda--timestamp-to-absolute
  5965. s base 'future (current-buffer) pos)))))
  5966. (diff (- deadline current))
  5967. (suppress-prewarning
  5968. (let ((scheduled
  5969. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5970. (org-entry-get nil "SCHEDULED"))))
  5971. (cond
  5972. ((not scheduled) nil)
  5973. ;; The current item has a scheduled date, so
  5974. ;; evaluate its prewarning lead time.
  5975. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5976. ;; Use global prewarning-restart lead time.
  5977. org-agenda-skip-deadline-prewarning-if-scheduled)
  5978. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5979. 'pre-scheduled)
  5980. ;; Set pre-warning to no earlier than SCHEDULED.
  5981. (min (- deadline
  5982. (org-agenda--timestamp-to-absolute scheduled))
  5983. org-deadline-warning-days))
  5984. ;; Set pre-warning to deadline.
  5985. (t 0))))
  5986. (wdays (or suppress-prewarning (org-get-wdays s))))
  5987. (cond
  5988. ;; Only display deadlines at their base date, at future
  5989. ;; repeat occurrences or in today agenda.
  5990. ((= current deadline) nil)
  5991. ((= current repeat) nil)
  5992. ((not today?) (throw :skip nil))
  5993. ;; Upcoming deadline: display within warning period WDAYS.
  5994. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5995. ;; Overdue deadline: warn about it for
  5996. ;; `org-deadline-past-days' duration.
  5997. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5998. ;; Possibly skip done tasks.
  5999. (when (and done?
  6000. (or org-agenda-skip-deadline-if-done
  6001. (/= deadline current)))
  6002. (throw :skip nil))
  6003. (save-excursion
  6004. (re-search-backward "^\\*+[ \t]+" nil t)
  6005. (goto-char (match-end 0))
  6006. (let* ((category (org-get-category))
  6007. (effort (save-match-data (or (get-text-property (point) 'effort)
  6008. (org-entry-get (point) org-effort-property))))
  6009. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6010. (level (make-string (org-reduced-level (org-outline-level))
  6011. ?\s))
  6012. (head (buffer-substring-no-properties
  6013. (point) (line-end-position)))
  6014. (inherited-tags
  6015. (or (eq org-agenda-show-inherited-tags 'always)
  6016. (and (listp org-agenda-show-inherited-tags)
  6017. (memq 'agenda org-agenda-show-inherited-tags))
  6018. (and (eq org-agenda-show-inherited-tags t)
  6019. (or (eq org-agenda-use-tag-inheritance t)
  6020. (memq 'agenda
  6021. org-agenda-use-tag-inheritance)))))
  6022. (tags (org-get-tags nil (not inherited-tags)))
  6023. (time
  6024. (cond
  6025. ;; No time of day designation if it is only
  6026. ;; a reminder.
  6027. ((and (/= current deadline) (/= current repeat)) nil)
  6028. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6029. (concat (substring s (match-beginning 1)) " "))
  6030. (t 'time)))
  6031. (item
  6032. (org-agenda-format-item
  6033. ;; Insert appropriate suffixes before deadlines.
  6034. ;; Those only apply to today agenda.
  6035. (pcase-let ((`(,now ,future ,past)
  6036. org-agenda-deadline-leaders))
  6037. (cond
  6038. ((and today? (< deadline today)) (format past (- diff)))
  6039. ((and today? (> deadline today)) (format future diff))
  6040. (t now)))
  6041. (org-add-props head nil
  6042. 'effort effort
  6043. 'effort-minutes effort-minutes)
  6044. level category tags time))
  6045. (face (org-agenda-deadline-face
  6046. (- 1 (/ (float diff) (max wdays 1)))))
  6047. (upcoming? (and today? (> deadline today)))
  6048. (warntime (get-text-property (point) 'org-appt-warntime)))
  6049. (org-add-props item props
  6050. 'org-marker (org-agenda-new-marker pos)
  6051. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6052. 'warntime warntime
  6053. 'level level
  6054. 'effort effort 'effort-minutes effort-minutes
  6055. 'ts-date deadline
  6056. 'priority
  6057. ;; Adjust priority to today reminders about deadlines.
  6058. ;; Overdue deadlines get the highest priority
  6059. ;; increase, then imminent deadlines and eventually
  6060. ;; more distant deadlines.
  6061. (let ((adjust (if today? (- diff) 0)))
  6062. (+ adjust (org-get-priority item)))
  6063. 'todo-state todo-state
  6064. 'type (if upcoming? "upcoming-deadline" "deadline")
  6065. 'date (if upcoming? date deadline)
  6066. 'face (if done? 'org-agenda-done face)
  6067. 'undone-face face
  6068. 'done-face 'org-agenda-done)
  6069. (push item deadline-items)))))))
  6070. (nreverse deadline-items)))
  6071. (defun org-agenda-deadline-face (fraction)
  6072. "Return the face to displaying a deadline item.
  6073. FRACTION is what fraction of the head-warning time has passed."
  6074. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6075. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6076. "Return the scheduled information for agenda display.
  6077. Optional argument DEADLINES is a list of deadline items to be
  6078. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6079. scheduled items with an hour specification like [h]h:mm."
  6080. (with-no-warnings (defvar date))
  6081. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6082. 'org-todo-regexp org-todo-regexp
  6083. 'org-complex-heading-regexp org-complex-heading-regexp
  6084. 'done-face 'org-agenda-done
  6085. 'mouse-face 'highlight
  6086. 'help-echo
  6087. (format "mouse-2 or RET jump to Org file %s"
  6088. (abbreviate-file-name buffer-file-name))))
  6089. (regexp (if with-hour
  6090. org-scheduled-time-hour-regexp
  6091. org-scheduled-time-regexp))
  6092. (today (org-today))
  6093. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6094. (current (calendar-absolute-from-gregorian date))
  6095. (deadline-pos
  6096. (mapcar (lambda (d)
  6097. (let ((m (get-text-property 0 'org-hd-marker d)))
  6098. (and m (marker-position m))))
  6099. deadlines))
  6100. scheduled-items)
  6101. (goto-char (point-min))
  6102. (if (org-element--cache-active-p)
  6103. (org-element-cache-map
  6104. (lambda (el)
  6105. (when (and (org-element-property :scheduled el)
  6106. (or (not with-hour)
  6107. (org-element-property
  6108. :hour-start
  6109. (org-element-property :scheduled el))
  6110. (org-element-property
  6111. :hour-end
  6112. (org-element-property :scheduled el))))
  6113. (goto-char (org-element-property :contents-begin el))
  6114. (catch :skip
  6115. (org-agenda-skip el)
  6116. (let* ((s (substring (org-element-property
  6117. :raw-value
  6118. (org-element-property :scheduled el))
  6119. 1 -1))
  6120. (pos (save-excursion
  6121. (goto-char (org-element-property :contents-begin el))
  6122. ;; We intentionally leave NOERROR
  6123. ;; argument in `re-search-forward' nil. If
  6124. ;; the search fails here, something went
  6125. ;; wrong and we are looking at
  6126. ;; non-matching headline.
  6127. (re-search-forward regexp (line-end-position))
  6128. (1- (match-beginning 1))))
  6129. (todo-state (org-element-property :todo-keyword el))
  6130. (donep (eq 'done (org-element-property :todo-type el)))
  6131. (sexp? (eq 'diary
  6132. (org-element-property
  6133. :type (org-element-property :scheduled el))))
  6134. ;; SCHEDULE is the scheduled date for the entry. It is
  6135. ;; either the bare date or the last repeat, according
  6136. ;; to `org-agenda-prefer-last-repeat'.
  6137. (schedule
  6138. (cond
  6139. (sexp? (org-agenda--timestamp-to-absolute s current))
  6140. ((or (eq org-agenda-prefer-last-repeat t)
  6141. (member todo-state org-agenda-prefer-last-repeat))
  6142. (org-agenda--timestamp-to-absolute
  6143. s today 'past (current-buffer) pos))
  6144. (t (org-agenda--timestamp-to-absolute s))))
  6145. ;; REPEAT is the future repeat closest from CURRENT,
  6146. ;; according to `org-agenda-show-future-repeats'. If
  6147. ;; the latter is nil, or if the time stamp has no
  6148. ;; repeat part, default to SCHEDULE.
  6149. (repeat
  6150. (cond
  6151. (sexp? schedule)
  6152. ((<= current today) schedule)
  6153. ((not org-agenda-show-future-repeats) schedule)
  6154. (t
  6155. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6156. (1+ today)
  6157. current)))
  6158. (org-agenda--timestamp-to-absolute
  6159. s base 'future (current-buffer) pos)))))
  6160. (diff (- current schedule))
  6161. (warntime (get-text-property (point) 'org-appt-warntime))
  6162. (pastschedp (< schedule today))
  6163. (futureschedp (> schedule today))
  6164. (habitp (and (fboundp 'org-is-habit-p)
  6165. (string= "habit" (org-element-property :STYLE el))))
  6166. (suppress-delay
  6167. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6168. (org-element-property
  6169. :raw-value
  6170. (org-element-property :deadline el)))))
  6171. (cond
  6172. ((not deadline) nil)
  6173. ;; The current item has a deadline date, so
  6174. ;; evaluate its delay time.
  6175. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6176. ;; Use global delay time.
  6177. (- org-agenda-skip-scheduled-delay-if-deadline))
  6178. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6179. 'post-deadline)
  6180. ;; Set delay to no later than DEADLINE.
  6181. (min (- schedule
  6182. (org-agenda--timestamp-to-absolute deadline))
  6183. org-scheduled-delay-days))
  6184. (t 0))))
  6185. (ddays
  6186. (cond
  6187. ;; Nullify delay when a repeater triggered already
  6188. ;; and the delay is of the form --Xd.
  6189. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6190. (> schedule (org-agenda--timestamp-to-absolute s)))
  6191. 0)
  6192. (suppress-delay
  6193. (let ((org-scheduled-delay-days suppress-delay))
  6194. (org-get-wdays s t t)))
  6195. (t (org-get-wdays s t)))))
  6196. ;; Display scheduled items at base date (SCHEDULE), today if
  6197. ;; scheduled before the current date, and at any repeat past
  6198. ;; today. However, skip delayed items and items that have
  6199. ;; been displayed for more than `org-scheduled-past-days'.
  6200. (unless (and todayp
  6201. habitp
  6202. (bound-and-true-p org-habit-show-all-today))
  6203. (when (or (and (> ddays 0) (< diff ddays))
  6204. (> diff (or (and habitp org-habit-scheduled-past-days)
  6205. org-scheduled-past-days))
  6206. (> schedule current)
  6207. (and (/= current schedule)
  6208. (/= current today)
  6209. (/= current repeat)))
  6210. (throw :skip nil)))
  6211. ;; Possibly skip done tasks.
  6212. (when (and donep
  6213. (or org-agenda-skip-scheduled-if-done
  6214. (/= schedule current)))
  6215. (throw :skip nil))
  6216. ;; Skip entry if it already appears as a deadline, per
  6217. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6218. ;; doesn't apply to habits.
  6219. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6220. ((guard
  6221. (or (not (memq (line-beginning-position 0) deadline-pos))
  6222. habitp))
  6223. nil)
  6224. (`repeated-after-deadline
  6225. (let ((deadline (time-to-days
  6226. (when (org-element-property :deadline el)
  6227. (org-time-string-to-time
  6228. (org-element-property :deadline el))))))
  6229. (and (<= schedule deadline) (> current deadline))))
  6230. (`not-today pastschedp)
  6231. (`t t)
  6232. (_ nil))
  6233. (throw :skip nil))
  6234. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6235. ;; only show them for today. Also skip done habits.
  6236. (when (and habitp
  6237. (or donep
  6238. (not (bound-and-true-p org-habit-show-habits))
  6239. (and (not todayp)
  6240. (bound-and-true-p
  6241. org-habit-show-habits-only-for-today))))
  6242. (throw :skip nil))
  6243. (save-excursion
  6244. (goto-char (org-element-property :begin el))
  6245. (let* ((category (org-get-category))
  6246. (effort (save-match-data
  6247. (or (get-text-property (point) 'effort)
  6248. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6249. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6250. (inherited-tags
  6251. (or (eq org-agenda-show-inherited-tags 'always)
  6252. (and (listp org-agenda-show-inherited-tags)
  6253. (memq 'agenda org-agenda-show-inherited-tags))
  6254. (and (eq org-agenda-show-inherited-tags t)
  6255. (or (eq org-agenda-use-tag-inheritance t)
  6256. (memq 'agenda
  6257. org-agenda-use-tag-inheritance)))))
  6258. (tags (org-get-tags el (not inherited-tags)))
  6259. (level (make-string (org-element-property :level el)
  6260. ?\s))
  6261. (head (save-excursion
  6262. (goto-char (org-element-property :begin el))
  6263. (re-search-forward org-outline-regexp-bol)
  6264. (buffer-substring (point) (line-end-position))))
  6265. (time
  6266. (cond
  6267. ;; No time of day designation if it is only a
  6268. ;; reminder, except for habits, which always show
  6269. ;; the time of day. Habits are an exception
  6270. ;; because if there is a time of day, that is
  6271. ;; interpreted to mean they should usually happen
  6272. ;; then, even if doing the habit was missed.
  6273. ((and
  6274. (not habitp)
  6275. (/= current schedule)
  6276. (/= current repeat))
  6277. nil)
  6278. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6279. (concat (substring s (match-beginning 1)) " "))
  6280. (t 'time)))
  6281. (item
  6282. (org-agenda-format-item
  6283. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6284. ;; Show a reminder of a past scheduled today.
  6285. (if (and todayp pastschedp)
  6286. (format past diff)
  6287. first))
  6288. (org-add-props head nil
  6289. 'effort effort
  6290. 'effort-minutes effort-minutes)
  6291. level category tags time nil habitp))
  6292. (face (cond ((and (not habitp) pastschedp)
  6293. 'org-scheduled-previously)
  6294. ((and habitp futureschedp)
  6295. 'org-agenda-done)
  6296. (todayp 'org-scheduled-today)
  6297. (t 'org-scheduled)))
  6298. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6299. (org-add-props item props
  6300. 'undone-face face
  6301. 'face (if donep 'org-agenda-done face)
  6302. 'org-marker (org-agenda-new-marker pos)
  6303. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6304. 'type (if pastschedp "past-scheduled" "scheduled")
  6305. 'date (if pastschedp schedule date)
  6306. 'ts-date schedule
  6307. 'warntime warntime
  6308. 'level level
  6309. 'effort effort 'effort-minutes effort-minutes
  6310. 'priority (if habitp (org-habit-get-priority habitp)
  6311. (+ 99 diff (org-get-priority item)))
  6312. 'org-habit-p habitp
  6313. 'todo-state todo-state)
  6314. (push item scheduled-items)))))))
  6315. :next-re regexp
  6316. :fail-re regexp
  6317. :narrow t)
  6318. (while (re-search-forward regexp nil t)
  6319. (catch :skip
  6320. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6321. (org-agenda-skip)
  6322. (let* ((s (match-string 1))
  6323. (pos (1- (match-beginning 1)))
  6324. (todo-state (save-match-data (org-get-todo-state)))
  6325. (donep (member todo-state org-done-keywords))
  6326. (sexp? (string-prefix-p "%%" s))
  6327. ;; SCHEDULE is the scheduled date for the entry. It is
  6328. ;; either the bare date or the last repeat, according
  6329. ;; to `org-agenda-prefer-last-repeat'.
  6330. (schedule
  6331. (cond
  6332. (sexp? (org-agenda--timestamp-to-absolute s current))
  6333. ((or (eq org-agenda-prefer-last-repeat t)
  6334. (member todo-state org-agenda-prefer-last-repeat))
  6335. (org-agenda--timestamp-to-absolute
  6336. s today 'past (current-buffer) pos))
  6337. (t (org-agenda--timestamp-to-absolute s))))
  6338. ;; REPEAT is the future repeat closest from CURRENT,
  6339. ;; according to `org-agenda-show-future-repeats'. If
  6340. ;; the latter is nil, or if the time stamp has no
  6341. ;; repeat part, default to SCHEDULE.
  6342. (repeat
  6343. (cond
  6344. (sexp? schedule)
  6345. ((<= current today) schedule)
  6346. ((not org-agenda-show-future-repeats) schedule)
  6347. (t
  6348. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6349. (1+ today)
  6350. current)))
  6351. (org-agenda--timestamp-to-absolute
  6352. s base 'future (current-buffer) pos)))))
  6353. (diff (- current schedule))
  6354. (warntime (get-text-property (point) 'org-appt-warntime))
  6355. (pastschedp (< schedule today))
  6356. (futureschedp (> schedule today))
  6357. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6358. (suppress-delay
  6359. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6360. (org-entry-get nil "DEADLINE"))))
  6361. (cond
  6362. ((not deadline) nil)
  6363. ;; The current item has a deadline date, so
  6364. ;; evaluate its delay time.
  6365. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6366. ;; Use global delay time.
  6367. (- org-agenda-skip-scheduled-delay-if-deadline))
  6368. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6369. 'post-deadline)
  6370. ;; Set delay to no later than DEADLINE.
  6371. (min (- schedule
  6372. (org-agenda--timestamp-to-absolute deadline))
  6373. org-scheduled-delay-days))
  6374. (t 0))))
  6375. (ddays
  6376. (cond
  6377. ;; Nullify delay when a repeater triggered already
  6378. ;; and the delay is of the form --Xd.
  6379. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6380. (> schedule (org-agenda--timestamp-to-absolute s)))
  6381. 0)
  6382. (suppress-delay
  6383. (let ((org-scheduled-delay-days suppress-delay))
  6384. (org-get-wdays s t t)))
  6385. (t (org-get-wdays s t)))))
  6386. ;; Display scheduled items at base date (SCHEDULE), today if
  6387. ;; scheduled before the current date, and at any repeat past
  6388. ;; today. However, skip delayed items and items that have
  6389. ;; been displayed for more than `org-scheduled-past-days'.
  6390. (unless (and todayp
  6391. habitp
  6392. (bound-and-true-p org-habit-show-all-today))
  6393. (when (or (and (> ddays 0) (< diff ddays))
  6394. (> diff (or (and habitp org-habit-scheduled-past-days)
  6395. org-scheduled-past-days))
  6396. (> schedule current)
  6397. (and (/= current schedule)
  6398. (/= current today)
  6399. (/= current repeat)))
  6400. (throw :skip nil)))
  6401. ;; Possibly skip done tasks.
  6402. (when (and donep
  6403. (or org-agenda-skip-scheduled-if-done
  6404. (/= schedule current)))
  6405. (throw :skip nil))
  6406. ;; Skip entry if it already appears as a deadline, per
  6407. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6408. ;; doesn't apply to habits.
  6409. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6410. ((guard
  6411. (or (not (memq (line-beginning-position 0) deadline-pos))
  6412. habitp))
  6413. nil)
  6414. (`repeated-after-deadline
  6415. (let ((deadline (time-to-days
  6416. (org-get-deadline-time (point)))))
  6417. (and (<= schedule deadline) (> current deadline))))
  6418. (`not-today pastschedp)
  6419. (`t t)
  6420. (_ nil))
  6421. (throw :skip nil))
  6422. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6423. ;; only show them for today. Also skip done habits.
  6424. (when (and habitp
  6425. (or donep
  6426. (not (bound-and-true-p org-habit-show-habits))
  6427. (and (not todayp)
  6428. (bound-and-true-p
  6429. org-habit-show-habits-only-for-today))))
  6430. (throw :skip nil))
  6431. (save-excursion
  6432. (re-search-backward "^\\*+[ \t]+" nil t)
  6433. (goto-char (match-end 0))
  6434. (let* ((category (org-get-category))
  6435. (effort (save-match-data (or (get-text-property (point) 'effort)
  6436. (org-entry-get (point) org-effort-property))))
  6437. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6438. (inherited-tags
  6439. (or (eq org-agenda-show-inherited-tags 'always)
  6440. (and (listp org-agenda-show-inherited-tags)
  6441. (memq 'agenda org-agenda-show-inherited-tags))
  6442. (and (eq org-agenda-show-inherited-tags t)
  6443. (or (eq org-agenda-use-tag-inheritance t)
  6444. (memq 'agenda
  6445. org-agenda-use-tag-inheritance)))))
  6446. (tags (org-get-tags nil (not inherited-tags)))
  6447. (level (make-string (org-reduced-level (org-outline-level))
  6448. ?\s))
  6449. (head (buffer-substring (point) (line-end-position)))
  6450. (time
  6451. (cond
  6452. ;; No time of day designation if it is only a
  6453. ;; reminder, except for habits, which always show
  6454. ;; the time of day. Habits are an exception
  6455. ;; because if there is a time of day, that is
  6456. ;; interpreted to mean they should usually happen
  6457. ;; then, even if doing the habit was missed.
  6458. ((and
  6459. (not habitp)
  6460. (/= current schedule)
  6461. (/= current repeat))
  6462. nil)
  6463. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6464. (concat (substring s (match-beginning 1)) " "))
  6465. (t 'time)))
  6466. (item
  6467. (org-agenda-format-item
  6468. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6469. ;; Show a reminder of a past scheduled today.
  6470. (if (and todayp pastschedp)
  6471. (format past diff)
  6472. first))
  6473. (org-add-props head nil
  6474. 'effort effort
  6475. 'effort-minutes effort-minutes)
  6476. level category tags time nil habitp))
  6477. (face (cond ((and (not habitp) pastschedp)
  6478. 'org-scheduled-previously)
  6479. ((and habitp futureschedp)
  6480. 'org-agenda-done)
  6481. (todayp 'org-scheduled-today)
  6482. (t 'org-scheduled)))
  6483. (habitp (and habitp (org-habit-parse-todo))))
  6484. (org-add-props item props
  6485. 'undone-face face
  6486. 'face (if donep 'org-agenda-done face)
  6487. 'org-marker (org-agenda-new-marker pos)
  6488. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6489. 'type (if pastschedp "past-scheduled" "scheduled")
  6490. 'date (if pastschedp schedule date)
  6491. 'ts-date schedule
  6492. 'warntime warntime
  6493. 'level level
  6494. 'effort effort 'effort-minutes effort-minutes
  6495. 'priority (if habitp (org-habit-get-priority habitp)
  6496. (+ 99 diff (org-get-priority item)))
  6497. 'org-habit-p habitp
  6498. 'todo-state todo-state)
  6499. (push item scheduled-items)))))))
  6500. (nreverse scheduled-items)))
  6501. (defun org-agenda-get-blocks ()
  6502. "Return the date-range information for agenda display."
  6503. (with-no-warnings (defvar date))
  6504. (let* ((props (list 'face nil
  6505. 'org-not-done-regexp org-not-done-regexp
  6506. 'org-todo-regexp org-todo-regexp
  6507. 'org-complex-heading-regexp org-complex-heading-regexp
  6508. 'mouse-face 'highlight
  6509. 'help-echo
  6510. (format "mouse-2 or RET jump to org file %s"
  6511. (abbreviate-file-name buffer-file-name))))
  6512. (regexp org-tr-regexp)
  6513. (d0 (calendar-absolute-from-gregorian date))
  6514. marker hdmarker ee txt d1 d2 s1 s2 category
  6515. level todo-state tags pos head donep inherited-tags
  6516. effort effort-minutes)
  6517. (goto-char (point-min))
  6518. (while (re-search-forward regexp nil t)
  6519. (catch :skip
  6520. (org-agenda-skip)
  6521. (setq pos (point))
  6522. (let ((start-time (match-string 1))
  6523. (end-time (match-string 2)))
  6524. (setq s1 (match-string 1)
  6525. s2 (match-string 2)
  6526. d1 (time-to-days
  6527. (condition-case err
  6528. (org-time-string-to-time s1)
  6529. (error
  6530. (error
  6531. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6532. s1
  6533. pos
  6534. (current-buffer)
  6535. (error-message-string err)))))
  6536. d2 (time-to-days
  6537. (condition-case err
  6538. (org-time-string-to-time s2)
  6539. (error
  6540. (error
  6541. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6542. s2
  6543. pos
  6544. (current-buffer)
  6545. (error-message-string err))))))
  6546. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6547. ;; Only allow days between the limits, because the normal
  6548. ;; date stamps will catch the limits.
  6549. (save-excursion
  6550. (setq todo-state (org-get-todo-state))
  6551. (setq donep (member todo-state org-done-keywords))
  6552. (when (and donep org-agenda-skip-timestamp-if-done)
  6553. (throw :skip t))
  6554. (setq marker (org-agenda-new-marker (point))
  6555. category (org-get-category))
  6556. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6557. (org-entry-get (point) org-effort-property))))
  6558. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6559. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6560. (throw :skip nil)
  6561. (goto-char (match-beginning 0))
  6562. (setq hdmarker (org-agenda-new-marker (point))
  6563. inherited-tags
  6564. (or (eq org-agenda-show-inherited-tags 'always)
  6565. (and (listp org-agenda-show-inherited-tags)
  6566. (memq 'agenda org-agenda-show-inherited-tags))
  6567. (and (eq org-agenda-show-inherited-tags t)
  6568. (or (eq org-agenda-use-tag-inheritance t)
  6569. (memq 'agenda org-agenda-use-tag-inheritance))))
  6570. tags (org-get-tags nil (not inherited-tags)))
  6571. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6572. (looking-at "\\*+[ \t]+\\(.*\\)")
  6573. (setq head (match-string 1))
  6574. (let ((remove-re
  6575. (if org-agenda-remove-timeranges-from-blocks
  6576. (concat
  6577. "<" (regexp-quote s1) ".*?>"
  6578. "--"
  6579. "<" (regexp-quote s2) ".*?>")
  6580. nil)))
  6581. (setq txt (org-agenda-format-item
  6582. (format
  6583. (nth (if (= d1 d2) 0 1)
  6584. org-agenda-timerange-leaders)
  6585. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6586. (org-add-props head nil
  6587. 'effort effort
  6588. 'effort-minutes effort-minutes)
  6589. level category tags
  6590. (save-match-data
  6591. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6592. (match-string 6 s1)))
  6593. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6594. (match-string 6 s2))))
  6595. (cond ((string= hhmm1 hhmm2)
  6596. (concat "<" start-time ">--<" end-time ">"))
  6597. ((and (= d1 d0) (= d2 d0))
  6598. (concat "<" start-time ">--<" end-time ">"))
  6599. ((= d1 d0)
  6600. (concat "<" start-time ">"))
  6601. ((= d2 d0)
  6602. (concat "<" end-time ">")))))
  6603. remove-re))))
  6604. (org-add-props txt props
  6605. 'org-marker marker 'org-hd-marker hdmarker
  6606. 'type "block" 'date date
  6607. 'level level
  6608. 'effort effort 'effort-minutes effort-minutes
  6609. 'todo-state todo-state
  6610. 'priority (org-get-priority txt))
  6611. (push txt ee))))
  6612. (goto-char pos)))
  6613. ;; Sort the entries by expiration date.
  6614. (nreverse ee)))
  6615. ;;; Agenda presentation and sorting
  6616. (defvar org-prefix-has-time nil
  6617. "A flag, set by `org-compile-prefix-format'.
  6618. The flag is set if the currently compiled format contains a `%t'.")
  6619. (defvar org-prefix-has-tag nil
  6620. "A flag, set by `org-compile-prefix-format'.
  6621. The flag is set if the currently compiled format contains a `%T'.")
  6622. (defvar org-prefix-has-effort nil
  6623. "A flag, set by `org-compile-prefix-format'.
  6624. The flag is set if the currently compiled format contains a `%e'.")
  6625. (defvar org-prefix-has-breadcrumbs nil
  6626. "A flag, set by `org-compile-prefix-format'.
  6627. The flag is set if the currently compiled format contains a `%b'.")
  6628. (defvar org-prefix-category-length nil
  6629. "Used by `org-compile-prefix-format' to remember the category field width.")
  6630. (defvar org-prefix-category-max-length nil
  6631. "Used by `org-compile-prefix-format' to remember the category field width.")
  6632. (defun org-agenda-get-category-icon (category)
  6633. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6634. (cl-dolist (entry org-agenda-category-icon-alist)
  6635. (when (string-match-p (car entry) category)
  6636. (if (listp (cadr entry))
  6637. (cl-return (cadr entry))
  6638. (cl-return (apply #'create-image (cdr entry)))))))
  6639. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6640. remove-re habitp)
  6641. "Format TXT to be inserted into the agenda buffer.
  6642. In particular, add the prefix and corresponding text properties.
  6643. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6644. WITH-LEVEL may be a string to replace the `%l' specifier.
  6645. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6646. category taken from local variable or file name. It will replace the `%c'
  6647. specifier in the format.
  6648. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6649. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6650. When DOTIME is a string, this string is searched for a time before TXT is.
  6651. TAGS can be the tags of the headline.
  6652. Any match of REMOVE-RE will be removed from TXT."
  6653. ;; We keep the org-prefix-* variable values along with a compiled
  6654. ;; formatter, so that multiple agendas existing at the same time do
  6655. ;; not step on each other toes.
  6656. ;;
  6657. ;; It was inconvenient to make these variables buffer local in
  6658. ;; Agenda buffers, because this function expects to be called with
  6659. ;; the buffer where item comes from being current, and not agenda
  6660. ;; buffer
  6661. (let* ((bindings (car org-prefix-format-compiled))
  6662. (formatter (cadr org-prefix-format-compiled)))
  6663. (cl-loop for (var value) in bindings
  6664. do (set var value))
  6665. (save-match-data
  6666. ;; Diary entries sometimes have extra whitespace at the beginning
  6667. (setq txt (org-trim txt))
  6668. ;; Fix the tags part in txt
  6669. (setq txt (org-agenda-fix-displayed-tags
  6670. txt tags
  6671. org-agenda-show-inherited-tags
  6672. org-agenda-hide-tags-regexp))
  6673. (with-no-warnings
  6674. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6675. ;; Based on what I see in `org-compile-prefix-format', I added
  6676. ;; a few more.
  6677. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6678. (defvar effort) (defvar extra)
  6679. (defvar level) (defvar tag) (defvar time))
  6680. (let* ((category (or with-category
  6681. (if buffer-file-name
  6682. (file-name-sans-extension
  6683. (file-name-nondirectory buffer-file-name))
  6684. "")))
  6685. (category-icon (org-agenda-get-category-icon category))
  6686. (category-icon (if category-icon
  6687. (propertize " " 'display category-icon)
  6688. ""))
  6689. (effort (and (not (string= txt ""))
  6690. (get-text-property 1 'effort txt)))
  6691. (tag (if tags (nth (1- (length tags)) tags) ""))
  6692. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6693. (extra (or (and (not habitp) extra) ""))
  6694. time
  6695. (ts (when dotime (concat
  6696. (if (stringp dotime) dotime "")
  6697. (and org-agenda-search-headline-for-time txt))))
  6698. (time-of-day (and dotime (org-get-time-of-day ts)))
  6699. stamp plain s0 s1 s2 rtn srp l
  6700. duration breadcrumbs)
  6701. (and (derived-mode-p 'org-mode) buffer-file-name
  6702. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6703. (when (and dotime time-of-day)
  6704. ;; Extract starting and ending time and move them to prefix
  6705. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6706. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6707. (setq s0 (match-string 0 ts)
  6708. srp (and stamp (match-end 3))
  6709. s1 (match-string (if plain 1 2) ts)
  6710. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6711. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6712. ;; them, we might want to remove them there to avoid duplication.
  6713. ;; The user can turn this off with a variable.
  6714. (when (and org-prefix-has-time
  6715. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6716. (string-match (concat (regexp-quote s0) " *") txt)
  6717. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6718. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6719. (= (match-beginning 0) 0)
  6720. t))
  6721. (setq txt (replace-match "" nil nil txt))))
  6722. ;; Normalize the time(s) to 24 hour.
  6723. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6724. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6725. ;; Try to set s2 if s1 and
  6726. ;; `org-agenda-default-appointment-duration' are set
  6727. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6728. (setq s2
  6729. (org-duration-from-minutes
  6730. (+ (org-duration-to-minutes s1 t)
  6731. org-agenda-default-appointment-duration)
  6732. nil t)))
  6733. ;; Compute the duration
  6734. (when s2
  6735. (setq duration (- (org-duration-to-minutes s2)
  6736. (org-duration-to-minutes s1))))
  6737. ;; Format S1 and S2 for display.
  6738. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6739. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6740. (when (string-match org-tag-group-re txt)
  6741. ;; Tags are in the string
  6742. (if (or (eq org-agenda-remove-tags t)
  6743. (and org-agenda-remove-tags
  6744. org-prefix-has-tag))
  6745. (setq txt (replace-match "" t t txt))
  6746. (setq txt (replace-match
  6747. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6748. (match-string 1 txt))
  6749. t t txt))))
  6750. (when remove-re
  6751. (while (string-match remove-re txt)
  6752. (setq txt (replace-match "" t t txt))))
  6753. ;; Set org-heading property on `txt' to mark the start of the
  6754. ;; heading.
  6755. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6756. ;; Prepare the variables needed in the eval of the compiled format
  6757. (when org-prefix-has-breadcrumbs
  6758. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6759. (let ((s (org-format-outline-path (org-get-outline-path)
  6760. (1- (frame-width))
  6761. nil org-agenda-breadcrumbs-separator)))
  6762. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6763. (setq time (cond (s2 (concat
  6764. (org-agenda-time-of-day-to-ampm-maybe s1)
  6765. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6766. (when org-agenda-timegrid-use-ampm " ")))
  6767. (s1 (concat
  6768. (org-agenda-time-of-day-to-ampm-maybe s1)
  6769. (if org-agenda-timegrid-use-ampm
  6770. (concat time-grid-trailing-characters " ")
  6771. time-grid-trailing-characters)))
  6772. (t ""))
  6773. category (if (symbolp category) (symbol-name category) category)
  6774. level (or with-level ""))
  6775. (if (string-match org-link-bracket-re category)
  6776. (progn
  6777. (setq l (string-width (or (match-string 2) (match-string 1))))
  6778. (when (< l (or org-prefix-category-length 0))
  6779. (setq category (copy-sequence category))
  6780. (org-add-props category nil
  6781. 'extra-space (make-string
  6782. (- org-prefix-category-length l 1) ?\ ))))
  6783. (when (and org-prefix-category-max-length
  6784. (>= (length category) org-prefix-category-max-length))
  6785. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6786. ;; Evaluate the compiled format
  6787. (setq rtn (concat (eval formatter t) txt))
  6788. ;; And finally add the text properties
  6789. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6790. (org-add-props rtn nil
  6791. 'org-category category
  6792. 'tags tags
  6793. 'org-priority-highest org-priority-highest
  6794. 'org-priority-lowest org-priority-lowest
  6795. 'time-of-day time-of-day
  6796. 'duration duration
  6797. 'breadcrumbs breadcrumbs
  6798. 'txt txt
  6799. 'level level
  6800. 'time time
  6801. 'extra extra
  6802. 'format org-prefix-format-compiled
  6803. 'dotime dotime)))))
  6804. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6805. "Remove tags string from TXT, and add a modified list of tags.
  6806. The modified list may contain inherited tags, and tags matched by
  6807. `org-agenda-hide-tags-regexp' will be removed."
  6808. (when (or add-inherited hide-re)
  6809. (when (string-match org-tag-group-re txt)
  6810. (setq txt (substring txt 0 (match-beginning 0))))
  6811. (setq tags
  6812. (delq nil
  6813. (mapcar (lambda (tg)
  6814. (if (or (and hide-re (string-match hide-re tg))
  6815. (and (not add-inherited)
  6816. (get-text-property 0 'inherited tg)))
  6817. nil
  6818. tg))
  6819. tags)))
  6820. (when tags
  6821. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6822. i)
  6823. (setq txt (concat txt " :"
  6824. (mapconcat
  6825. (lambda (x)
  6826. (setq i (get-text-property 0 'inherited x))
  6827. (if (and have-i (not i))
  6828. (progn
  6829. (setq have-i nil)
  6830. (concat ":" x))
  6831. x))
  6832. tags ":")
  6833. (if have-i "::" ":"))))))
  6834. txt)
  6835. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6836. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6837. "Add a time-grid for agenda items which need it.
  6838. LIST is the list of agenda items formatted by `org-agenda-list'.
  6839. NDAYS is the span of the current agenda view.
  6840. TODAYP is t when the current agenda view is on today."
  6841. (catch 'exit
  6842. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6843. ((and todayp (member 'today (car org-agenda-time-grid))))
  6844. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6845. ((member 'weekly (car org-agenda-time-grid)))
  6846. (t (throw 'exit list)))
  6847. (let* ((have (delq nil (mapcar
  6848. (lambda (x) (get-text-property 1 'time-of-day x))
  6849. list)))
  6850. (string (nth 3 org-agenda-time-grid))
  6851. (gridtimes (nth 1 org-agenda-time-grid))
  6852. (req (car org-agenda-time-grid))
  6853. (remove (member 'remove-match req))
  6854. new time)
  6855. (when (and (member 'require-timed req) (not have))
  6856. ;; don't show empty grid
  6857. (throw 'exit list))
  6858. (while (setq time (pop gridtimes))
  6859. (unless (and remove (member time have))
  6860. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6861. (push (org-agenda-format-item
  6862. nil string nil "" nil
  6863. (concat (substring time 0 -2) ":" (substring time -2)))
  6864. new)
  6865. (put-text-property
  6866. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6867. (when (and todayp org-agenda-show-current-time-in-grid)
  6868. (push (org-agenda-format-item
  6869. nil org-agenda-current-time-string nil "" nil
  6870. (format-time-string "%H:%M "))
  6871. new)
  6872. (put-text-property
  6873. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6874. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6875. (append new list)
  6876. (append list new)))))
  6877. (defun org-compile-prefix-format (key)
  6878. "Compile the prefix format into a Lisp form that can be evaluated.
  6879. The resulting form and associated variable bindings is returned
  6880. and stored in the variable `org-prefix-format-compiled'."
  6881. (setq org-prefix-has-time nil
  6882. org-prefix-has-tag nil
  6883. org-prefix-category-length nil
  6884. org-prefix-has-effort nil
  6885. org-prefix-has-breadcrumbs nil)
  6886. (let ((s (cond
  6887. ((stringp org-agenda-prefix-format)
  6888. org-agenda-prefix-format)
  6889. ((assq key org-agenda-prefix-format)
  6890. (cdr (assq key org-agenda-prefix-format)))
  6891. (t " %-12:c%?-12t% s")))
  6892. (start 0)
  6893. varform vars var c f opt) ;; e
  6894. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6895. s start)
  6896. (setq var (or (cdr (assoc (match-string 4 s)
  6897. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6898. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6899. 'eval)
  6900. c (or (match-string 3 s) "")
  6901. opt (match-beginning 1)
  6902. start (1+ (match-beginning 0)))
  6903. (cl-case var
  6904. (time (setq org-prefix-has-time t))
  6905. (tag (setq org-prefix-has-tag t))
  6906. (effort (setq org-prefix-has-effort t))
  6907. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6908. (setq f (concat "%" (match-string 2 s) "s"))
  6909. (when (eq var 'category)
  6910. (setq org-prefix-category-length
  6911. (floor (abs (string-to-number (match-string 2 s)))))
  6912. (setq org-prefix-category-max-length
  6913. (let ((x (match-string 2 s)))
  6914. (save-match-data
  6915. (and (string-match "\\.[0-9]+" x)
  6916. (string-to-number (substring (match-string 0 x) 1)))))))
  6917. (if (eq var 'eval)
  6918. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6919. (if opt
  6920. (setq varform
  6921. `(if (member ,var '("" nil))
  6922. ""
  6923. (format ,f (concat ,var ,c))))
  6924. (setq varform
  6925. `(format ,f (if (member ,var '("" nil)) ""
  6926. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6927. (if (eq var 'eval)
  6928. (setf (substring s (match-beginning 0)
  6929. (+ (match-beginning 4)
  6930. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6931. "%s")
  6932. (setq s (replace-match "%s" t nil s)))
  6933. (push varform vars))
  6934. (setq vars (nreverse vars))
  6935. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6936. (setq org-prefix-format-compiled
  6937. (list
  6938. `((org-prefix-has-time ,org-prefix-has-time)
  6939. (org-prefix-has-tag ,org-prefix-has-tag)
  6940. (org-prefix-category-length ,org-prefix-category-length)
  6941. (org-prefix-has-effort ,org-prefix-has-effort)
  6942. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6943. `(format ,s ,@vars))))))
  6944. (defun org-set-sorting-strategy (key)
  6945. (setq org-agenda-sorting-strategy-selected
  6946. (if (symbolp (car org-agenda-sorting-strategy))
  6947. ;; the old format
  6948. org-agenda-sorting-strategy
  6949. (or (cdr (assq key org-agenda-sorting-strategy))
  6950. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6951. '(time-up category-keep priority-down)))))
  6952. (defun org-get-time-of-day (s &optional string)
  6953. "Check string S for a time of day.
  6954. If found, return it as a military time number between 0 and 2400.
  6955. If not found, return nil.
  6956. The optional STRING argument forces conversion into a 5 character wide string
  6957. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6958. where H:MM is the duration above midnight."
  6959. (let ((case-fold-search t)
  6960. (time-regexp
  6961. (rx word-start
  6962. (group (opt (any "012")) digit) ;group 1: hours
  6963. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6964. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6965. ;; Special "HHam/pm" case.
  6966. (group-n 3 (or "am" "pm")))
  6967. word-end)))
  6968. (save-match-data
  6969. (when (and (string-match time-regexp s)
  6970. (not (eq 'org-link (get-text-property 1 'face s))))
  6971. (let ((hours
  6972. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  6973. (am-p (equal ampm "am")))
  6974. (pcase (string-to-number (match-string 1 s))
  6975. ((and (guard (not ampm)) h) h)
  6976. (12 (if am-p 0 12))
  6977. (h (+ h (if am-p 0 12))))))
  6978. (minutes
  6979. (if (match-end 2)
  6980. (string-to-number (match-string 2 s))
  6981. 0)))
  6982. (pcase string
  6983. (`nil (+ minutes (* hours 100)))
  6984. ((and `overtime
  6985. (guard (or (> hours 24)
  6986. (and (= hours 24)
  6987. (> minutes 0)))))
  6988. (format "+%d:%02d" (- hours 24) minutes))
  6989. ((guard org-agenda-time-leading-zero)
  6990. (format "%02d:%02d" hours minutes))
  6991. (_
  6992. (format "%d:%02d" hours minutes))))))))
  6993. (defvar org-agenda-before-sorting-filter-function nil
  6994. "Function to be applied to agenda items prior to sorting.
  6995. Prior to sorting also means just before they are inserted into the agenda.
  6996. To aid sorting, you may revisit the original entries and add more text
  6997. properties which will later be used by the sorting functions.
  6998. The function should take a string argument, an agenda line.
  6999. It has access to the text properties in that line, which contain among
  7000. other things, the property `org-hd-marker' that points to the entry
  7001. where the line comes from. Note that not all lines going into the agenda
  7002. have this property, only most.
  7003. The function should return the modified string. It is probably best
  7004. to ONLY change text properties.
  7005. You can also use this function as a filter, by returning nil for lines
  7006. you don't want to have in the agenda at all. For this application, you
  7007. could bind the variable in the options section of a custom command.")
  7008. (defun org-agenda-finalize-entries (list &optional type)
  7009. "Sort, limit and concatenate the LIST of agenda items.
  7010. The optional argument TYPE tells the agenda type."
  7011. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7012. (cdr (assoc type org-agenda-max-effort)))
  7013. (t org-agenda-max-effort)))
  7014. (max-todo (cond ((listp org-agenda-max-todos)
  7015. (cdr (assoc type org-agenda-max-todos)))
  7016. (t org-agenda-max-todos)))
  7017. (max-tags (cond ((listp org-agenda-max-tags)
  7018. (cdr (assoc type org-agenda-max-tags)))
  7019. (t org-agenda-max-tags)))
  7020. (max-entries (cond ((listp org-agenda-max-entries)
  7021. (cdr (assoc type org-agenda-max-entries)))
  7022. (t org-agenda-max-entries))))
  7023. (when org-agenda-before-sorting-filter-function
  7024. (setq list
  7025. (delq nil
  7026. (mapcar
  7027. org-agenda-before-sorting-filter-function list))))
  7028. (setq list (mapcar #'org-agenda-highlight-todo list)
  7029. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7030. (when max-effort
  7031. (setq list (org-agenda-limit-entries
  7032. list 'effort-minutes max-effort
  7033. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7034. 32767 -1))))))
  7035. (when max-todo
  7036. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7037. (when max-tags
  7038. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7039. (when max-entries
  7040. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7041. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7042. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7043. (mapconcat #'identity list "\n")))
  7044. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7045. "Limit the number of agenda entries."
  7046. (let ((include (and limit (< limit 0))))
  7047. (if limit
  7048. (let ((fun (or fn (lambda (p) (when p 1))))
  7049. (lim 0))
  7050. (delq nil
  7051. (mapcar
  7052. (lambda (e)
  7053. (let ((pval (funcall
  7054. fun (get-text-property (1- (length e))
  7055. prop e))))
  7056. (when pval (setq lim (+ lim pval)))
  7057. (cond ((and pval (<= lim (abs limit))) e)
  7058. ((and include (not pval)) e))))
  7059. list)))
  7060. list)))
  7061. (defun org-agenda-limit-interactively (remove)
  7062. "In agenda, interactively limit entries to various maximums."
  7063. (interactive "P")
  7064. (if remove
  7065. (progn (setq org-agenda-max-entries nil
  7066. org-agenda-max-todos nil
  7067. org-agenda-max-tags nil
  7068. org-agenda-max-effort nil)
  7069. (org-agenda-redo))
  7070. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7071. (msg (cond ((= max ?E) "How many minutes? ")
  7072. ((= max ?e) "How many entries? ")
  7073. ((= max ?t) "How many TODO entries? ")
  7074. ((= max ?T) "How many tagged entries? ")
  7075. (t (user-error "Wrong input"))))
  7076. (num (string-to-number (read-from-minibuffer msg))))
  7077. (cond ((equal max ?e)
  7078. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7079. ((equal max ?t)
  7080. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7081. ((equal max ?T)
  7082. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7083. ((equal max ?E)
  7084. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7085. (org-agenda-fit-window-to-buffer))
  7086. (defun org-agenda-highlight-todo (x)
  7087. (let ((org-done-keywords org-done-keywords-for-agenda)
  7088. (case-fold-search nil)
  7089. re)
  7090. (if (eq x 'line)
  7091. (save-excursion
  7092. (beginning-of-line 1)
  7093. (setq re (org-get-at-bol 'org-todo-regexp))
  7094. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7095. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7096. (add-text-properties (match-beginning 0) (match-end 1)
  7097. (list 'face (org-get-todo-face 1)))
  7098. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7099. (delete-region (match-beginning 1) (1- (match-end 0)))
  7100. (goto-char (match-beginning 1))
  7101. (insert (format org-agenda-todo-keyword-format s)))))
  7102. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7103. (setq re (get-text-property 0 'org-todo-regexp x))
  7104. (when (and re
  7105. ;; Test `pl' because if there's no heading content,
  7106. ;; there's no point matching to highlight. Note
  7107. ;; that if we didn't test `pl' first, and there
  7108. ;; happened to be no keyword from `org-todo-regexp'
  7109. ;; on this heading line, then the `equal' comparison
  7110. ;; afterwards would spuriously succeed in the case
  7111. ;; where `pl' is nil -- causing an args-out-of-range
  7112. ;; error when we try to add text properties to text
  7113. ;; that isn't there.
  7114. pl
  7115. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7116. x pl)
  7117. pl))
  7118. (add-text-properties
  7119. (or (match-end 1) (match-end 0)) (match-end 0)
  7120. (list 'face (org-get-todo-face (match-string 2 x)))
  7121. x)
  7122. (when (match-end 1)
  7123. (setq x
  7124. (concat
  7125. (substring x 0 (match-end 1))
  7126. (unless (string= org-agenda-todo-keyword-format "")
  7127. (format org-agenda-todo-keyword-format
  7128. (match-string 2 x)))
  7129. ;; Remove `display' property as the icon could leak
  7130. ;; on the white space.
  7131. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7132. 'display))
  7133. (substring x (match-end 3)))))))
  7134. x)))
  7135. (defsubst org-cmp-values (a b property)
  7136. "Compare the numeric value of text PROPERTY for string A and B."
  7137. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7138. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7139. (cond ((> pa pb) +1)
  7140. ((< pa pb) -1))))
  7141. (defsubst org-cmp-effort (a b)
  7142. "Compare the effort values of string A and B."
  7143. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7144. ;; `effort-minutes' property is not directly accessible from
  7145. ;; the strings, but is stored as a property in `txt'.
  7146. (ea (or (get-text-property
  7147. 0 'effort-minutes (get-text-property 0 'txt a))
  7148. def))
  7149. (eb (or (get-text-property
  7150. 0 'effort-minutes (get-text-property 0 'txt b))
  7151. def)))
  7152. (cond ((> ea eb) +1)
  7153. ((< ea eb) -1))))
  7154. (defsubst org-cmp-category (a b)
  7155. "Compare the string values of categories of strings A and B."
  7156. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7157. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7158. (cond ((string-lessp ca cb) -1)
  7159. ((string-lessp cb ca) +1))))
  7160. (defsubst org-cmp-todo-state (a b)
  7161. "Compare the todo states of strings A and B."
  7162. (let* ((ma (or (get-text-property 1 'org-marker a)
  7163. (get-text-property 1 'org-hd-marker a)))
  7164. (mb (or (get-text-property 1 'org-marker b)
  7165. (get-text-property 1 'org-hd-marker b)))
  7166. (fa (and ma (marker-buffer ma)))
  7167. (fb (and mb (marker-buffer mb)))
  7168. (todo-kwds
  7169. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7170. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7171. (ta (or (get-text-property 1 'todo-state a) ""))
  7172. (tb (or (get-text-property 1 'todo-state b) ""))
  7173. (la (- (length (member ta todo-kwds))))
  7174. (lb (- (length (member tb todo-kwds))))
  7175. (donepa (member ta org-done-keywords-for-agenda))
  7176. (donepb (member tb org-done-keywords-for-agenda)))
  7177. (cond ((and donepa (not donepb)) -1)
  7178. ((and (not donepa) donepb) +1)
  7179. ((< la lb) -1)
  7180. ((< lb la) +1))))
  7181. (defsubst org-cmp-alpha (a b)
  7182. "Compare the headlines, alphabetically."
  7183. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7184. (plb (text-property-any 0 (length b) 'org-heading t b))
  7185. (ta (and pla (substring a pla)))
  7186. (tb (and plb (substring b plb)))
  7187. (case-fold-search nil))
  7188. (when pla
  7189. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7190. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7191. ta)
  7192. (setq ta (substring ta (match-end 0))))
  7193. (setq ta (downcase ta)))
  7194. (when plb
  7195. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7196. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7197. tb)
  7198. (setq tb (substring tb (match-end 0))))
  7199. (setq tb (downcase tb)))
  7200. (cond ((not (or ta tb)) nil)
  7201. ((not ta) +1)
  7202. ((not tb) -1)
  7203. ((string-lessp ta tb) -1)
  7204. ((string-lessp tb ta) +1))))
  7205. (defsubst org-cmp-tag (a b)
  7206. "Compare the string values of the first tags of A and B."
  7207. (let ((ta (car (last (get-text-property 1 'tags a))))
  7208. (tb (car (last (get-text-property 1 'tags b)))))
  7209. (cond ((not (or ta tb)) nil)
  7210. ((not ta) +1)
  7211. ((not tb) -1)
  7212. ((string-lessp ta tb) -1)
  7213. ((string-lessp tb ta) +1))))
  7214. (defsubst org-cmp-time (a b)
  7215. "Compare the time-of-day values of strings A and B."
  7216. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7217. (ta (or (get-text-property 1 'time-of-day a) def))
  7218. (tb (or (get-text-property 1 'time-of-day b) def)))
  7219. (cond ((< ta tb) -1)
  7220. ((< tb ta) +1))))
  7221. (defsubst org-cmp-ts (a b type)
  7222. "Compare the timestamps values of entries A and B.
  7223. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7224. \"timestamp_ia\", compare within each of these type. When TYPE
  7225. is the empty string, compare all timestamps without respect of
  7226. their type."
  7227. (let* ((def (and (not org-agenda-sort-notime-is-late) -1))
  7228. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7229. (get-text-property 1 'ts-date a))
  7230. def))
  7231. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7232. (get-text-property 1 'ts-date b))
  7233. def)))
  7234. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7235. ((if tb (and ta (< tb ta)) ta) +1))))
  7236. (defsubst org-cmp-habit-p (a b)
  7237. "Compare the todo states of strings A and B."
  7238. (let ((ha (get-text-property 1 'org-habit-p a))
  7239. (hb (get-text-property 1 'org-habit-p b)))
  7240. (cond ((and ha (not hb)) -1)
  7241. ((and (not ha) hb) +1))))
  7242. (defun org-entries-lessp (a b)
  7243. "Predicate for sorting agenda entries."
  7244. ;; The following variables will be used when the form is evaluated.
  7245. ;; So even though the compiler complains, keep them.
  7246. (let ((ss org-agenda-sorting-strategy-selected))
  7247. (org-dlet
  7248. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7249. (org-cmp-ts a b "")))
  7250. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7251. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7252. (org-cmp-ts a b "scheduled")))
  7253. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7254. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7255. (org-cmp-ts a b "deadline")))
  7256. (deadline-down (if deadline-up (- deadline-up) nil))
  7257. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7258. (org-cmp-ts a b "timestamp_ia")))
  7259. (tsia-down (if tsia-up (- tsia-up) nil))
  7260. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7261. (org-cmp-ts a b "timestamp")))
  7262. (ts-down (if ts-up (- ts-up) nil))
  7263. (time-up (and (org-em 'time-up 'time-down ss)
  7264. (org-cmp-time a b)))
  7265. (time-down (if time-up (- time-up) nil))
  7266. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7267. (org-cmp-values a b 'org-stats)))
  7268. (stats-down (if stats-up (- stats-up) nil))
  7269. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7270. (org-cmp-values a b 'priority)))
  7271. (priority-down (if priority-up (- priority-up) nil))
  7272. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7273. (org-cmp-effort a b)))
  7274. (effort-down (if effort-up (- effort-up) nil))
  7275. (category-up (and (or (org-em 'category-up 'category-down ss)
  7276. (memq 'category-keep ss))
  7277. (org-cmp-category a b)))
  7278. (category-down (if category-up (- category-up) nil))
  7279. (category-keep (if category-up +1 nil))
  7280. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7281. (org-cmp-tag a b)))
  7282. (tag-down (if tag-up (- tag-up) nil))
  7283. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7284. (org-cmp-todo-state a b)))
  7285. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7286. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7287. (org-cmp-habit-p a b)))
  7288. (habit-down (if habit-up (- habit-up) nil))
  7289. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7290. (org-cmp-alpha a b)))
  7291. (alpha-down (if alpha-up (- alpha-up) nil))
  7292. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7293. user-defined-up user-defined-down)
  7294. (when (and need-user-cmp org-agenda-cmp-user-defined
  7295. (functionp org-agenda-cmp-user-defined))
  7296. (setq user-defined-up
  7297. (funcall org-agenda-cmp-user-defined a b)
  7298. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7299. (cdr (assoc
  7300. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7301. '((-1 . t) (1 . nil) (nil . nil)))))))
  7302. ;;; Agenda restriction lock
  7303. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7304. "Overlay to mark the headline to which agenda commands are restricted.")
  7305. (overlay-put org-agenda-restriction-lock-overlay
  7306. 'face 'org-agenda-restriction-lock)
  7307. (overlay-put org-agenda-restriction-lock-overlay
  7308. 'help-echo "Agendas are currently limited to this subtree.")
  7309. (delete-overlay org-agenda-restriction-lock-overlay)
  7310. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7311. "Set the restriction lock to the agenda item at point from within the agenda.
  7312. When called with a `\\[universal-argument]' prefix, restrict to
  7313. the file which contains the item.
  7314. Argument ARG is the prefix argument."
  7315. (interactive "P")
  7316. (unless (derived-mode-p 'org-agenda-mode)
  7317. (user-error "Not in an Org agenda buffer"))
  7318. (let* ((marker (or (org-get-at-bol 'org-marker)
  7319. (org-agenda-error)))
  7320. (buffer (marker-buffer marker))
  7321. (pos (marker-position marker)))
  7322. (with-current-buffer buffer
  7323. (goto-char pos)
  7324. (org-agenda-set-restriction-lock arg))))
  7325. ;;;###autoload
  7326. (defun org-agenda-set-restriction-lock (&optional type)
  7327. "Set restriction lock for agenda to current subtree or file.
  7328. When in a restricted subtree, remove it.
  7329. The restriction will span over the entire file if TYPE is `file',
  7330. or if type is '(4), or if the cursor is before the first headline
  7331. in the file. Otherwise, only apply the restriction to the current
  7332. subtree."
  7333. (interactive "P")
  7334. (if (and org-agenda-overriding-restriction
  7335. (member org-agenda-restriction-lock-overlay
  7336. (overlays-at (point)))
  7337. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7338. (point)))
  7339. (org-agenda-remove-restriction-lock 'noupdate)
  7340. (org-agenda-remove-restriction-lock 'noupdate)
  7341. (and (equal type '(4)) (setq type 'file))
  7342. (setq type (cond
  7343. (type type)
  7344. ((org-at-heading-p) 'subtree)
  7345. ((condition-case nil (org-back-to-heading t) (error nil))
  7346. 'subtree)
  7347. (t 'file)))
  7348. (if (eq type 'subtree)
  7349. (progn
  7350. (setq org-agenda-restrict (current-buffer))
  7351. (setq org-agenda-overriding-restriction 'subtree)
  7352. (put 'org-agenda-files 'org-restrict
  7353. (list (buffer-file-name (buffer-base-buffer))))
  7354. (org-back-to-heading t)
  7355. (move-overlay org-agenda-restriction-lock-overlay
  7356. (point)
  7357. (if org-agenda-restriction-lock-highlight-subtree
  7358. (save-excursion (org-end-of-subtree t t) (point))
  7359. (point-at-eol)))
  7360. (move-marker org-agenda-restrict-begin (point))
  7361. (move-marker org-agenda-restrict-end
  7362. (save-excursion (org-end-of-subtree t t)))
  7363. (message "Locking agenda restriction to subtree"))
  7364. (put 'org-agenda-files 'org-restrict
  7365. (list (buffer-file-name (buffer-base-buffer))))
  7366. (setq org-agenda-restrict nil)
  7367. (setq org-agenda-overriding-restriction 'file)
  7368. (move-marker org-agenda-restrict-begin nil)
  7369. (move-marker org-agenda-restrict-end nil)
  7370. (message "Locking agenda restriction to file"))
  7371. (setq current-prefix-arg nil))
  7372. (org-agenda-maybe-redo))
  7373. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7374. "Remove agenda restriction lock."
  7375. (interactive "P")
  7376. (if (not org-agenda-restrict)
  7377. (message "No agenda restriction to remove.")
  7378. (delete-overlay org-agenda-restriction-lock-overlay)
  7379. (delete-overlay org-speedbar-restriction-lock-overlay)
  7380. (setq org-agenda-overriding-restriction nil)
  7381. (setq org-agenda-restrict nil)
  7382. (put 'org-agenda-files 'org-restrict nil)
  7383. (move-marker org-agenda-restrict-begin nil)
  7384. (move-marker org-agenda-restrict-end nil)
  7385. (setq current-prefix-arg nil)
  7386. (message "Agenda restriction lock removed")
  7387. (or noupdate (org-agenda-maybe-redo))))
  7388. (defun org-agenda-maybe-redo ()
  7389. "If there is any window showing the agenda view, update it."
  7390. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7391. org-agenda-buffer-name)
  7392. t))
  7393. (w0 (selected-window)))
  7394. (when w
  7395. (select-window w)
  7396. (org-agenda-redo)
  7397. (select-window w0)
  7398. (if org-agenda-overriding-restriction
  7399. (message "Agenda view shifted to new %s restriction"
  7400. org-agenda-overriding-restriction)
  7401. (message "Agenda restriction lock removed")))))
  7402. ;;; Agenda commands
  7403. (defun org-agenda-check-type (error &rest types)
  7404. "Check if agenda buffer or component is of allowed type.
  7405. If ERROR is non-nil, throw an error, otherwise just return nil.
  7406. Allowed types are `agenda' `todo' `tags' `search'."
  7407. (cond ((not org-agenda-type)
  7408. (error "No Org agenda currently displayed"))
  7409. ((memq org-agenda-type types) t)
  7410. (error
  7411. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7412. (t nil)))
  7413. (defun org-agenda-Quit ()
  7414. "Exit the agenda, killing the agenda buffer.
  7415. Like `org-agenda-quit', but kill the buffer even when
  7416. `org-agenda-sticky' is non-nil."
  7417. (interactive)
  7418. (org-agenda--quit))
  7419. (defun org-agenda-quit ()
  7420. "Exit the agenda.
  7421. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7422. instead of killing it.
  7423. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7424. the pre-agenda window configuration.
  7425. When column view is active, exit column view instead of the
  7426. agenda."
  7427. (interactive)
  7428. (org-agenda--quit org-agenda-sticky))
  7429. (defun org-agenda--quit (&optional bury)
  7430. (if org-agenda-columns-active
  7431. (org-columns-quit)
  7432. (let ((wconf org-agenda-pre-window-conf)
  7433. (buf (current-buffer))
  7434. (org-agenda-last-indirect-window
  7435. (and (eq org-indirect-buffer-display 'other-window)
  7436. org-agenda-last-indirect-buffer
  7437. (get-buffer-window org-agenda-last-indirect-buffer))))
  7438. (cond
  7439. ((eq org-agenda-window-setup 'other-frame)
  7440. (delete-frame))
  7441. ((eq org-agenda-window-setup 'other-tab)
  7442. (if (fboundp 'tab-bar-close-tab)
  7443. (tab-bar-close-tab)
  7444. (user-error "Your version of Emacs does not have tab bar mode support")))
  7445. ((and org-agenda-restore-windows-after-quit
  7446. wconf)
  7447. ;; Maybe restore the pre-agenda window configuration. Reset
  7448. ;; `org-agenda-pre-window-conf' before running
  7449. ;; `set-window-configuration', which loses the current buffer.
  7450. (setq org-agenda-pre-window-conf nil)
  7451. (set-window-configuration wconf))
  7452. (t
  7453. (when org-agenda-last-indirect-window
  7454. (delete-window org-agenda-last-indirect-window))
  7455. (and (not (eq org-agenda-window-setup 'current-window))
  7456. (not (one-window-p))
  7457. (delete-window))))
  7458. (if bury
  7459. ;; Set the agenda buffer as the current buffer instead of
  7460. ;; passing it as an argument to `bury-buffer' so that
  7461. ;; `bury-buffer' removes it from the window.
  7462. (with-current-buffer buf
  7463. (bury-buffer))
  7464. (kill-buffer buf)
  7465. (setq org-agenda-archives-mode nil
  7466. org-agenda-buffer nil)))))
  7467. (defun org-agenda-exit ()
  7468. "Exit the agenda, killing Org buffers loaded by the agenda.
  7469. Like `org-agenda-Quit', but kill any buffers that were created by
  7470. the agenda. Org buffers visited directly by the user will not be
  7471. touched. Also, exit the agenda even if it is in column view."
  7472. (interactive)
  7473. (when org-agenda-columns-active
  7474. (org-columns-quit))
  7475. (org-release-buffers org-agenda-new-buffers)
  7476. (setq org-agenda-new-buffers nil)
  7477. (org-agenda-Quit))
  7478. (defun org-agenda-kill-all-agenda-buffers ()
  7479. "Kill all buffers in `org-agenda-mode'.
  7480. This is used when toggling sticky agendas."
  7481. (interactive)
  7482. (let (blist)
  7483. (dolist (buf (buffer-list))
  7484. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7485. (push buf blist)))
  7486. (mapc #'kill-buffer blist)))
  7487. (defun org-agenda-execute (arg)
  7488. "Execute another agenda command, keeping same window.
  7489. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7490. in the agenda."
  7491. (interactive "P")
  7492. (let ((org-agenda-window-setup 'current-window))
  7493. (org-agenda arg)))
  7494. (defun org-agenda-redo (&optional all)
  7495. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7496. (interactive "P")
  7497. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7498. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7499. (cpa (unless (eq all t) current-prefix-arg))
  7500. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7501. (org-agenda-sticky nil)
  7502. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7503. org-agenda-buffer-name))
  7504. (org-agenda-keep-modes t)
  7505. (tag-filter org-agenda-tag-filter)
  7506. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7507. (top-hl-filter org-agenda-top-headline-filter)
  7508. (cat-filter org-agenda-category-filter)
  7509. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7510. (re-filter org-agenda-regexp-filter)
  7511. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7512. (effort-filter org-agenda-effort-filter)
  7513. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7514. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7515. (cols org-agenda-columns-active)
  7516. (line (org-current-line))
  7517. (window-line (- line (org-current-line (window-start))))
  7518. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7519. (redo-cmd (get-text-property p 'org-redo-cmd))
  7520. (last-args (get-text-property p 'org-last-args))
  7521. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7522. (org-agenda-overriding-cmd-arguments
  7523. (unless (eq all t)
  7524. (cond ((listp last-args)
  7525. (cons (or cpa (car last-args)) (cdr last-args)))
  7526. ((stringp last-args)
  7527. last-args))))
  7528. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7529. (put 'org-agenda-tag-filter :preset-filter nil)
  7530. (put 'org-agenda-category-filter :preset-filter nil)
  7531. (put 'org-agenda-regexp-filter :preset-filter nil)
  7532. (put 'org-agenda-effort-filter :preset-filter nil)
  7533. (and cols (org-columns-quit))
  7534. (message "Rebuilding agenda buffer...")
  7535. (if series-redo-cmd
  7536. (eval series-redo-cmd t)
  7537. (cl-progv
  7538. (mapcar #'car lprops)
  7539. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7540. (eval redo-cmd t)))
  7541. (setq org-agenda-undo-list nil
  7542. org-agenda-pending-undo-list nil
  7543. org-agenda-tag-filter tag-filter
  7544. org-agenda-category-filter cat-filter
  7545. org-agenda-regexp-filter re-filter
  7546. org-agenda-effort-filter effort-filter
  7547. org-agenda-top-headline-filter top-hl-filter)
  7548. (message "Rebuilding agenda buffer...done")
  7549. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7550. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7551. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7552. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7553. (let ((tag (or tag-filter tag-preset))
  7554. (cat (or cat-filter cat-preset))
  7555. (effort (or effort-filter effort-preset))
  7556. (re (or re-filter re-preset)))
  7557. (when tag (org-agenda-filter-apply tag 'tag t))
  7558. (when cat (org-agenda-filter-apply cat 'category))
  7559. (when effort (org-agenda-filter-apply effort 'effort))
  7560. (when re (org-agenda-filter-apply re 'regexp)))
  7561. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7562. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7563. (org-goto-line line)
  7564. (when (called-interactively-p 'any) (recenter window-line))))
  7565. (defun org-agenda-redo-all (&optional exhaustive)
  7566. "Rebuild all agenda views in the current buffer.
  7567. With a prefix argument, do so in all agenda buffers."
  7568. (interactive "P")
  7569. (if exhaustive
  7570. (dolist (buffer (buffer-list))
  7571. (with-current-buffer buffer
  7572. (when (derived-mode-p 'org-agenda-mode)
  7573. (org-agenda-redo t))))
  7574. (org-agenda-redo t)))
  7575. (defvar org-global-tags-completion-table nil)
  7576. (defvar org-agenda-filter-form nil)
  7577. (defvar org-agenda-filtered-by-category nil)
  7578. (defsubst org-agenda-get-category ()
  7579. "Return the category of the agenda line."
  7580. (org-get-at-bol 'org-category))
  7581. (defun org-agenda-filter-by-category (strip)
  7582. "Filter lines in the agenda buffer that have a specific category.
  7583. The category is that of the current line.
  7584. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7585. When there is already a category filter in place, this command removes the
  7586. filter."
  7587. (interactive "P")
  7588. (if (and org-agenda-filtered-by-category
  7589. org-agenda-category-filter)
  7590. (org-agenda-filter-show-all-cat)
  7591. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7592. (cond
  7593. ((and cat strip)
  7594. (org-agenda-filter-apply
  7595. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7596. (cat
  7597. (org-agenda-filter-apply
  7598. (setq org-agenda-category-filter
  7599. (list (concat "+" cat)))
  7600. 'category))
  7601. (t (error "No category at point"))))))
  7602. (defun org-find-top-headline (&optional pos)
  7603. "Find the topmost parent headline and return it.
  7604. POS when non-nil is the marker or buffer position to start the
  7605. search from."
  7606. (save-excursion
  7607. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7608. (when pos (goto-char pos))
  7609. ;; Skip up to the topmost parent.
  7610. (while (org-up-heading-safe))
  7611. (ignore-errors
  7612. (replace-regexp-in-string
  7613. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7614. (nth 4 (org-heading-components)))))))
  7615. (defvar org-agenda-filtered-by-top-headline nil)
  7616. (defun org-agenda-filter-by-top-headline (strip)
  7617. "Keep only those lines that are descendants from the same top headline.
  7618. The top headline is that of the current line. With prefix arg STRIP, hide
  7619. all lines of the category at point."
  7620. (interactive "P")
  7621. (if org-agenda-filtered-by-top-headline
  7622. (progn
  7623. (setq org-agenda-filtered-by-top-headline nil
  7624. org-agenda-top-headline-filter nil)
  7625. (org-agenda-filter-show-all-top-filter))
  7626. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7627. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7628. (error "No top-level headline at point")))))
  7629. (defvar org-agenda-regexp-filter nil)
  7630. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7631. "Filter agenda entries by a regular expressions.
  7632. You will be prompted for the regular expression, and the agenda
  7633. view will only show entries that are matched by that expression.
  7634. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7635. When there is already a regexp filter active, this command removed the
  7636. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7637. an already existing regexp filter."
  7638. (interactive "P")
  7639. (let* ((strip (equal strip-or-accumulate '(4)))
  7640. (accumulate (equal strip-or-accumulate '(16))))
  7641. (cond
  7642. ((and org-agenda-regexp-filter (not accumulate))
  7643. (org-agenda-filter-show-all-re)
  7644. (message "Regexp filter removed"))
  7645. (t (let ((flt (concat (if strip "-" "+")
  7646. (read-from-minibuffer
  7647. (if strip
  7648. "Hide entries matching regexp: "
  7649. "Narrow to entries matching regexp: ")))))
  7650. (push flt org-agenda-regexp-filter)
  7651. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7652. (defvar org-agenda-effort-filter nil)
  7653. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7654. "Filter agenda entries by effort.
  7655. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7656. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7657. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7658. This last option is in practice not very useful, but it is available for
  7659. consistency with the other filter commands."
  7660. (interactive "P")
  7661. (let* ((efforts (split-string
  7662. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7663. org-global-properties
  7664. t))
  7665. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7666. ;; XXX: the following handles only up to 10 different
  7667. ;; effort values.
  7668. (allowed-keys (if (null efforts) nil
  7669. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7670. (number-sequence 1 (length efforts)))))
  7671. (keep (equal strip-or-accumulate '(16)))
  7672. (negative (equal strip-or-accumulate '(4)))
  7673. (current org-agenda-effort-filter)
  7674. (op nil))
  7675. (while (not (memq op '(?< ?> ?= ?_)))
  7676. (setq op (read-char-exclusive
  7677. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7678. ;; Select appropriate duration. Ignore non-digit characters.
  7679. (if (eq op ?_)
  7680. (progn
  7681. (org-agenda-filter-show-all-effort)
  7682. (message "Effort filter removed"))
  7683. (let ((prompt
  7684. (apply #'format
  7685. (concat "Effort %c "
  7686. (mapconcat (lambda (s) (concat "[%d]" s))
  7687. efforts
  7688. " "))
  7689. op allowed-keys))
  7690. (eff -1))
  7691. (while (not (memq eff allowed-keys))
  7692. (message prompt)
  7693. (setq eff (- (read-char-exclusive) 48)))
  7694. (org-agenda-filter-show-all-effort)
  7695. (setq org-agenda-effort-filter
  7696. (append
  7697. (list (concat (if negative "-" "+")
  7698. (char-to-string op)
  7699. ;; Numbering is 1 2 3 ... 9 0, but we want
  7700. ;; 0 1 2 ... 8 9.
  7701. (nth (mod (1- eff) 10) efforts)))
  7702. (if keep current nil)))
  7703. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7704. (defun org-agenda-filter (&optional strip-or-accumulate)
  7705. "Prompt for a general filter string and apply it to the agenda.
  7706. The string may contain filter elements like
  7707. +category
  7708. +tag
  7709. +<effort > and = are also allowed as effort operators
  7710. +/regexp/
  7711. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7712. `+' is optional if it is not required to separate two string parts.
  7713. Multiple filter elements can be concatenated without spaces, for example
  7714. +work-John<0:10-/plot/
  7715. selects entries with category `work' and effort estimates below 10 minutes,
  7716. and deselects entries with tag `John' or matching the regexp `plot'.
  7717. During entry of the filter, completion for tags, categories and effort
  7718. values is offered. Since the syntax for categories and tags is identical
  7719. there should be no overlap between categories and tags. If there is, tags
  7720. get priority.
  7721. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7722. entire filter, which can be useful in connection with the prompt history.
  7723. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7724. existing ones. A shortcut for this is to add an additional `+' at the
  7725. beginning of the string, like `+-John'.
  7726. With a triple prefix argument, execute the computed filtering defined in
  7727. the variable `org-agenda-auto-exclude-function'."
  7728. (interactive "P")
  7729. (if (equal strip-or-accumulate '(64))
  7730. ;; Execute the auto-exclude action
  7731. (if (not org-agenda-auto-exclude-function)
  7732. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7733. (org-agenda-filter-show-all-tag)
  7734. (setq org-agenda-tag-filter nil)
  7735. (dolist (tag (org-agenda-get-represented-tags))
  7736. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7737. (when modifier
  7738. (push modifier org-agenda-tag-filter))))
  7739. (unless (null org-agenda-tag-filter)
  7740. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7741. ;; Prompt for a filter and act
  7742. (let* ((tag-list (org-agenda-get-represented-tags))
  7743. (category-list (org-agenda-get-represented-categories))
  7744. (negate (equal strip-or-accumulate '(4)))
  7745. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7746. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7747. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7748. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7749. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7750. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7751. (f-string (completing-read
  7752. (concat
  7753. (if negate "Negative filter" "Filter")
  7754. " [+cat-tag<0:10-/regexp/]: ")
  7755. #'org-agenda-filter-completion-function
  7756. nil nil ff))
  7757. (keep (or (if (string-match "^\\+[+-]" f-string)
  7758. (progn (setq f-string (substring f-string 1)) t))
  7759. (equal strip-or-accumulate '(16))))
  7760. (fc (if keep org-agenda-category-filter))
  7761. (ft (if keep org-agenda-tag-filter))
  7762. (fe (if keep org-agenda-effort-filter))
  7763. (fr (if keep org-agenda-regexp-filter))
  7764. pm s)
  7765. ;; If the filter contains a double-quoted string, replace a
  7766. ;; single hyphen by the arbitrary and temporary string "~~~"
  7767. ;; to disambiguate such hyphens from syntactic ones.
  7768. (setq f-string (replace-regexp-in-string
  7769. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7770. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7771. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7772. (when negate
  7773. (setq pm (if (equal pm "+") "-" "+")))
  7774. (cond
  7775. ((match-beginning 3)
  7776. ;; category or tag
  7777. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7778. "~~~" "-" (match-string 3 f-string)))
  7779. (cond
  7780. ((member s tag-list)
  7781. (org-pushnew-to-end (concat pm s) ft))
  7782. ((member s category-list)
  7783. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7784. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7785. fc))
  7786. (t (message
  7787. "`%s%s' filter ignored because tag/category is not represented"
  7788. pm s))))
  7789. ((match-beginning 4)
  7790. ;; effort
  7791. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7792. ((match-beginning 5)
  7793. ;; regexp
  7794. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7795. (setq f-string (substring f-string (match-end 0))))
  7796. (org-agenda-filter-remove-all)
  7797. (and fc (org-agenda-filter-apply
  7798. (setq org-agenda-category-filter fc) 'category))
  7799. (and ft (org-agenda-filter-apply
  7800. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7801. (and fe (org-agenda-filter-apply
  7802. (setq org-agenda-effort-filter fe) 'effort))
  7803. (and fr (org-agenda-filter-apply
  7804. (setq org-agenda-regexp-filter fr) 'regexp))
  7805. (run-hooks 'org-agenda-filter-hook))))
  7806. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7807. "Complete a complex filter string.
  7808. FLAG specifies the type of completion operation to perform. This
  7809. function is passed as a collection function to `completing-read',
  7810. which see."
  7811. (let ((completion-ignore-case t) ;tags are case-sensitive
  7812. (confirm (lambda (x) (stringp x)))
  7813. (prefix "")
  7814. (operator "")
  7815. table)
  7816. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7817. (setq prefix (match-string 1 string)
  7818. operator (match-string 2 string)
  7819. string (match-string 3 string)))
  7820. (cond
  7821. ((member operator '("+" "-" "" nil))
  7822. (setq table (append (org-agenda-get-represented-categories)
  7823. (org-agenda-get-represented-tags))))
  7824. ((member operator '("<" ">" "="))
  7825. (setq table (split-string
  7826. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7827. org-global-properties
  7828. t))
  7829. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7830. " +")))
  7831. (t (setq table nil)))
  7832. (pcase flag
  7833. (`t (all-completions string table confirm))
  7834. (`lambda (assoc string table)) ;exact match?
  7835. (`nil
  7836. (pcase (try-completion string table confirm)
  7837. ((and completion (pred stringp))
  7838. (concat prefix completion))
  7839. (completion completion)))
  7840. (_ nil))))
  7841. (defun org-agenda-filter-remove-all ()
  7842. "Remove all filters from the current agenda buffer."
  7843. (interactive)
  7844. (when org-agenda-tag-filter
  7845. (org-agenda-filter-show-all-tag))
  7846. (when org-agenda-category-filter
  7847. (org-agenda-filter-show-all-cat))
  7848. (when org-agenda-regexp-filter
  7849. (org-agenda-filter-show-all-re))
  7850. (when org-agenda-top-headline-filter
  7851. (org-agenda-filter-show-all-top-filter))
  7852. (when org-agenda-effort-filter
  7853. (org-agenda-filter-show-all-effort))
  7854. (org-agenda-finalize)
  7855. (when (called-interactively-p 'interactive)
  7856. (message "All agenda filters removed")))
  7857. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7858. "Keep only those lines in the agenda buffer that have a specific tag.
  7859. The tag is selected with its fast selection letter, as configured.
  7860. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7861. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7862. instead of replacing it.
  7863. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7864. i.e. don't
  7865. filter on all its group members.
  7866. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7867. should be used to exclude the search - the interactive user can
  7868. also press `-' or `+' to switch between filtering and excluding."
  7869. (interactive "P")
  7870. (let* ((alist org-tag-alist-for-agenda)
  7871. (seen-chars nil)
  7872. (tag-chars (mapconcat
  7873. (lambda (x) (if (and (not (symbolp (car x)))
  7874. (cdr x)
  7875. (not (member (cdr x) seen-chars)))
  7876. (progn
  7877. (push (cdr x) seen-chars)
  7878. (char-to-string (cdr x)))
  7879. ""))
  7880. org-tag-alist-for-agenda ""))
  7881. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7882. (string-to-list tag-chars)))
  7883. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7884. (accumulate (equal strip-or-accumulate '(16)))
  7885. (expand (not (equal strip-or-accumulate '(64))))
  7886. (inhibit-read-only t)
  7887. (current org-agenda-tag-filter)
  7888. a tag) ;; n
  7889. (unless char
  7890. (while (not (memq char valid-char-list))
  7891. (org-unlogged-message
  7892. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7893. (if exclude "Exclude[+]" "Filter[-]")
  7894. (if expand "" " (no grouptag expand)")
  7895. tag-chars
  7896. (if org-agenda-auto-exclude-function "[RET] " ""))
  7897. (setq char (read-char-exclusive))
  7898. ;; Excluding or filtering down
  7899. (cond ((eq char ?-) (setq exclude t))
  7900. ((eq char ?+) (setq exclude nil)))))
  7901. (when (eq char ?\t)
  7902. (unless (local-variable-p 'org-global-tags-completion-table)
  7903. (setq-local org-global-tags-completion-table
  7904. (org-global-tags-completion-table)))
  7905. (let ((completion-ignore-case t))
  7906. (setq tag (completing-read
  7907. "Tag: " org-global-tags-completion-table nil t))))
  7908. (cond
  7909. ((eq char ?\r)
  7910. (org-agenda-filter-show-all-tag)
  7911. (when org-agenda-auto-exclude-function
  7912. (setq org-agenda-tag-filter nil)
  7913. (dolist (tag (org-agenda-get-represented-tags))
  7914. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7915. (when modifier
  7916. (push modifier org-agenda-tag-filter))))
  7917. (unless (null org-agenda-tag-filter)
  7918. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7919. ((eq char ?\\)
  7920. (org-agenda-filter-show-all-tag)
  7921. (when (get 'org-agenda-tag-filter :preset-filter)
  7922. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7923. ((eq char ?.)
  7924. (setq org-agenda-tag-filter
  7925. (mapcar (lambda(tag) (concat "+" tag))
  7926. (org-get-at-bol 'tags)))
  7927. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7928. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7929. ((or (eq char ?\s)
  7930. (setq a (rassoc char alist))
  7931. (and tag (setq a (cons tag nil))))
  7932. (org-agenda-filter-show-all-tag)
  7933. (setq tag (car a))
  7934. (setq org-agenda-tag-filter
  7935. (cons (concat (if exclude "-" "+") tag)
  7936. (if accumulate current nil)))
  7937. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7938. (t (error "Invalid tag selection character %c" char)))))
  7939. (defun org-agenda-get-represented-categories ()
  7940. "Return a list of all categories used in this agenda buffer."
  7941. (or org-agenda-represented-categories
  7942. (when (derived-mode-p 'org-agenda-mode)
  7943. (let ((pos (point-min)) categories)
  7944. (while (and (< pos (point-max))
  7945. (setq pos (next-single-property-change
  7946. pos 'org-category nil (point-max))))
  7947. (push (get-text-property pos 'org-category) categories))
  7948. (setq org-agenda-represented-categories
  7949. ;; Enclose category names with a hyphen in double
  7950. ;; quotes to process them specially in `org-agenda-filter'.
  7951. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7952. (nreverse (org-uniquify (delq nil categories)))))))))
  7953. (defvar org-tag-groups-alist-for-agenda)
  7954. (defun org-agenda-get-represented-tags ()
  7955. "Return a list of all tags used in this agenda buffer.
  7956. These will be lower-case, for filtering."
  7957. (or org-agenda-represented-tags
  7958. (when (derived-mode-p 'org-agenda-mode)
  7959. (let ((pos (point-min)) tags-lists tt)
  7960. (while (and (< pos (point-max))
  7961. (setq pos (next-single-property-change
  7962. pos 'tags nil (point-max))))
  7963. (setq tt (get-text-property pos 'tags))
  7964. (if tt (push tt tags-lists)))
  7965. (setq tags-lists
  7966. (nreverse (org-uniquify
  7967. (delq nil (apply #'append tags-lists)))))
  7968. (dolist (tag tags-lists)
  7969. (mapc
  7970. (lambda (group)
  7971. (when (member tag group)
  7972. (push (car group) tags-lists)))
  7973. org-tag-groups-alist-for-agenda))
  7974. (setq org-agenda-represented-tags tags-lists)))))
  7975. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7976. "Create the form that tests a line for agenda filter.
  7977. Optional argument EXPAND can be used for the TYPE tag and will
  7978. expand the tags in the FILTER if any of the tags in FILTER are
  7979. grouptags."
  7980. (let ((multi-pos-cats
  7981. (and (eq type 'category)
  7982. (string-match-p "\\+.*\\+"
  7983. (mapconcat (lambda (cat) (substring cat 0 1))
  7984. filter ""))))
  7985. f f1)
  7986. (cond
  7987. ;; Tag filter
  7988. ((eq type 'tag)
  7989. (setq filter
  7990. (delete-dups
  7991. (append (get 'org-agenda-tag-filter :preset-filter)
  7992. filter)))
  7993. (dolist (x filter)
  7994. (let ((op (string-to-char x)))
  7995. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7996. (setq x (list x)))
  7997. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7998. (push f1 f))))
  7999. ;; Category filter
  8000. ((eq type 'category)
  8001. (setq filter
  8002. (delete-dups
  8003. (append (get 'org-agenda-category-filter :preset-filter)
  8004. filter)))
  8005. (dolist (x filter)
  8006. (if (equal "-" (substring x 0 1))
  8007. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8008. (setq f1 (list 'equal (substring x 1) 'cat)))
  8009. (push f1 f)))
  8010. ;; Regexp filter
  8011. ((eq type 'regexp)
  8012. (setq filter
  8013. (delete-dups
  8014. (append (get 'org-agenda-regexp-filter :preset-filter)
  8015. filter)))
  8016. (dolist (x filter)
  8017. (if (equal "-" (substring x 0 1))
  8018. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8019. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8020. (push f1 f)))
  8021. ;; Effort filter
  8022. ((eq type 'effort)
  8023. (setq filter
  8024. (delete-dups
  8025. (append (get 'org-agenda-effort-filter :preset-filter)
  8026. filter)))
  8027. (dolist (x filter)
  8028. (push (org-agenda-filter-effort-form x) f))))
  8029. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8030. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8031. "Return a form associated to tag-expression TAGS.
  8032. Build a form testing a line for agenda filter for
  8033. tag-expressions. OP is an operator of type CHAR that allows the
  8034. function to set the right switches in the returned form."
  8035. (let (form)
  8036. ;; Any of the expressions can match if OP is +, all must match if
  8037. ;; the operator is -.
  8038. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8039. (let* ((tag (substring x 1))
  8040. (f (cond
  8041. ((string= "" tag) 'tags)
  8042. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8043. ;; TAG is a regexp.
  8044. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8045. (t (list 'member tag 'tags)))))
  8046. (push (if (eq op ?-) (list 'not f) f) form)))))
  8047. (defun org-agenda-filter-effort-form (e)
  8048. "Return the form to compare the effort of the current line with what E says.
  8049. E looks like \"+<2:25\"."
  8050. (let (op)
  8051. (setq e (substring e 1))
  8052. (setq op (string-to-char e) e (substring e 1))
  8053. (setq op (cond ((equal op ?<) '<=)
  8054. ((equal op ?>) '>=)
  8055. ((equal op ??) op)
  8056. (t '=)))
  8057. (list 'org-agenda-compare-effort (list 'quote op)
  8058. (org-duration-to-minutes e))))
  8059. (defun org-agenda-compare-effort (op value)
  8060. "Compare the effort of the current line with VALUE, using OP.
  8061. If the line does not have an effort defined, return nil."
  8062. ;; `effort-minutes' property cannot be extracted directly from
  8063. ;; current line but is stored as a property in `txt'.
  8064. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8065. (funcall op
  8066. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8067. value)))
  8068. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8069. "Expand group tags in FILTER for the agenda.
  8070. When NO-OPERATOR is non-nil, do not add the + operator to
  8071. returned tags."
  8072. (if org-group-tags
  8073. (let (case-fold-search rtn)
  8074. (mapc
  8075. (lambda (f)
  8076. (let (f0 dir)
  8077. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8078. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8079. (setq dir (if no-operator "" "+") f0 f))
  8080. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8081. (org-tags-expand f0 t))
  8082. rtn))))
  8083. filter)
  8084. (reverse rtn))
  8085. filter))
  8086. (defun org-agenda-filter-apply (filter type &optional expand)
  8087. "Set FILTER as the new agenda filter and apply it.
  8088. Optional argument EXPAND can be used for the TYPE tag and will
  8089. expand the tags in the FILTER if any of the tags in FILTER are
  8090. grouptags."
  8091. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8092. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8093. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8094. filter type expand))
  8095. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8096. ;; category is used as the filter:
  8097. (setq org-agenda-filtered-by-category
  8098. (and (eq type 'category)
  8099. (not (equal (substring (car filter) 0 1) "-"))))
  8100. (org-agenda-set-mode-name)
  8101. (save-excursion
  8102. (goto-char (point-min))
  8103. (while (not (eobp))
  8104. (when (or (org-get-at-bol 'org-hd-marker)
  8105. (org-get-at-bol 'org-marker))
  8106. (org-dlet
  8107. ((tags (org-get-at-bol 'tags))
  8108. (cat (org-agenda-get-category))
  8109. (txt (or (org-get-at-bol 'txt) "")))
  8110. (unless (eval org-agenda-filter-form t)
  8111. (org-agenda-filter-hide-line type))))
  8112. (beginning-of-line 2)))
  8113. (when (get-char-property (point) 'invisible)
  8114. (ignore-errors (org-agenda-previous-line))))
  8115. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8116. "Filter by top headline HL."
  8117. (org-agenda-set-mode-name)
  8118. (save-excursion
  8119. (goto-char (point-min))
  8120. (while (not (eobp))
  8121. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8122. (tophl (and pos (org-find-top-headline pos))))
  8123. (when (and tophl (funcall (if negative 'identity 'not)
  8124. (string= hl tophl)))
  8125. (org-agenda-filter-hide-line 'top-headline)))
  8126. (beginning-of-line 2)))
  8127. (when (get-char-property (point) 'invisible)
  8128. (org-agenda-previous-line))
  8129. (setq org-agenda-top-headline-filter hl
  8130. org-agenda-filtered-by-top-headline t))
  8131. (defun org-agenda-filter-hide-line (type)
  8132. "If current line is TYPE, hide it in the agenda buffer."
  8133. (let* (buffer-invisibility-spec
  8134. (beg (max (point-min) (1- (point-at-bol))))
  8135. (end (point-at-eol)))
  8136. (let ((inhibit-read-only t))
  8137. (add-text-properties
  8138. beg end `(invisible org-filtered org-filter-type ,type)))))
  8139. (defun org-agenda-remove-filter (type)
  8140. "Remove filter of type TYPE from the agenda buffer."
  8141. (interactive)
  8142. (save-excursion
  8143. (goto-char (point-min))
  8144. (let ((inhibit-read-only t) pos)
  8145. (while (setq pos (text-property-any (point) (point-max)
  8146. 'org-filter-type type))
  8147. (goto-char pos)
  8148. (remove-text-properties
  8149. (point) (next-single-property-change (point) 'org-filter-type)
  8150. `(invisible org-filtered org-filter-type ,type))))
  8151. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8152. (setq org-agenda-filter-form nil)
  8153. (org-agenda-set-mode-name)
  8154. (org-agenda-finalize)))
  8155. (defun org-agenda-filter-show-all-tag nil
  8156. (org-agenda-remove-filter 'tag))
  8157. (defun org-agenda-filter-show-all-re nil
  8158. (org-agenda-remove-filter 'regexp))
  8159. (defun org-agenda-filter-show-all-effort nil
  8160. (org-agenda-remove-filter 'effort))
  8161. (defun org-agenda-filter-show-all-cat nil
  8162. (org-agenda-remove-filter 'category))
  8163. (defun org-agenda-filter-show-all-top-filter nil
  8164. (org-agenda-remove-filter 'top-headline))
  8165. (defun org-agenda-manipulate-query-add ()
  8166. "Manipulate the query by adding a search term with positive selection.
  8167. Positive selection means the term must be matched for selection of an entry."
  8168. (interactive)
  8169. (org-agenda-manipulate-query ?\[))
  8170. (defun org-agenda-manipulate-query-subtract ()
  8171. "Manipulate the query by adding a search term with negative selection.
  8172. Negative selection means term must not be matched for selection of an entry."
  8173. (interactive)
  8174. (org-agenda-manipulate-query ?\]))
  8175. (defun org-agenda-manipulate-query-add-re ()
  8176. "Manipulate the query by adding a search regexp with positive selection.
  8177. Positive selection means the regexp must match for selection of an entry."
  8178. (interactive)
  8179. (org-agenda-manipulate-query ?\{))
  8180. (defun org-agenda-manipulate-query-subtract-re ()
  8181. "Manipulate the query by adding a search regexp with negative selection.
  8182. Negative selection means regexp must not match for selection of an entry."
  8183. (interactive)
  8184. (org-agenda-manipulate-query ?\}))
  8185. (defun org-agenda-manipulate-query (char)
  8186. (cond
  8187. ((eq org-agenda-type 'agenda)
  8188. (let ((org-agenda-include-inactive-timestamps t))
  8189. (org-agenda-redo))
  8190. (message "Display now includes inactive timestamps as well"))
  8191. ((eq org-agenda-type 'search)
  8192. (org-add-to-string
  8193. 'org-agenda-query-string
  8194. (if org-agenda-last-search-view-search-was-boolean
  8195. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8196. (?\{ . " +{}") (?\} . " -{}"))))
  8197. " "))
  8198. (setq org-agenda-redo-command
  8199. (list 'org-search-view
  8200. (car (get-text-property (min (1- (point-max)) (point))
  8201. 'org-last-args))
  8202. org-agenda-query-string
  8203. (+ (length org-agenda-query-string)
  8204. (if (member char '(?\{ ?\})) 0 1))))
  8205. (set-register org-agenda-query-register org-agenda-query-string)
  8206. (let ((org-agenda-overriding-arguments
  8207. (cdr org-agenda-redo-command)))
  8208. (org-agenda-redo)))
  8209. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8210. org-agenda-type))))
  8211. (defun org-add-to-string (var string)
  8212. (set var (concat (symbol-value var) string)))
  8213. (defun org-agenda-goto-date (date)
  8214. "Jump to DATE in agenda."
  8215. (interactive
  8216. (list
  8217. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8218. (org-read-date))))
  8219. (let* ((day (time-to-days (org-time-string-to-time date)))
  8220. (org-agenda-sticky-orig org-agenda-sticky)
  8221. (org-agenda-buffer-tmp-name (buffer-name))
  8222. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8223. (0-arg (or current-prefix-arg (car args)))
  8224. (2-arg (nth 2 args))
  8225. (with-hour-p (nth 4 org-agenda-redo-command))
  8226. (newcmd (list 'org-agenda-list 0-arg date
  8227. (org-agenda-span-to-ndays
  8228. 2-arg (org-time-string-to-absolute date))
  8229. with-hour-p))
  8230. (newargs (cdr newcmd))
  8231. (inhibit-read-only t)
  8232. org-agenda-sticky)
  8233. (if (not (org-agenda-check-type t 'agenda))
  8234. (error "Not available in non-agenda views")
  8235. (add-text-properties (point-min) (point-max)
  8236. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8237. (org-agenda-redo)
  8238. (goto-char (point-min))
  8239. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8240. (save-excursion (move-beginning-of-line 2) (eobp))))
  8241. (move-beginning-of-line 2))
  8242. (setq org-agenda-sticky org-agenda-sticky-orig
  8243. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8244. (defun org-agenda-goto-today ()
  8245. "Go to today."
  8246. (interactive)
  8247. (org-agenda-check-type t 'agenda)
  8248. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8249. (curspan (nth 2 args))
  8250. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8251. (cond
  8252. (tdpos (goto-char tdpos))
  8253. ((eq org-agenda-type 'agenda)
  8254. (let* ((sd (org-agenda-compute-starting-span
  8255. (org-today) (or curspan org-agenda-span)))
  8256. (org-agenda-overriding-arguments args))
  8257. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8258. (org-agenda-redo)
  8259. (org-agenda-find-same-or-today-or-agenda)))
  8260. (t (error "Cannot find today")))))
  8261. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8262. (goto-char
  8263. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8264. (text-property-any (point-min) (point-max) 'org-today t)
  8265. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8266. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8267. (org-agenda-backward-block))
  8268. (point-min))))
  8269. (defun org-agenda-backward-block ()
  8270. "Move backward by one agenda block."
  8271. (interactive)
  8272. (org-agenda-forward-block 'backward))
  8273. (defun org-agenda-forward-block (&optional backward)
  8274. "Move forward by one agenda block.
  8275. When optional argument BACKWARD is set, go backward."
  8276. (interactive)
  8277. (cond ((not (derived-mode-p 'org-agenda-mode))
  8278. (user-error
  8279. "Cannot execute this command outside of org-agenda-mode buffers"))
  8280. ((looking-at (if backward "\\`" "\\'"))
  8281. (message "Already at the %s block" (if backward "first" "last")))
  8282. (t (let ((_pos (prog1 (point)
  8283. (ignore-errors (if backward (backward-char 1)
  8284. (move-end-of-line 1)))))
  8285. (f (if backward
  8286. #'previous-single-property-change
  8287. #'next-single-property-change))
  8288. moved dest)
  8289. (while (and (setq dest (funcall
  8290. f (point) 'org-agenda-structural-header))
  8291. (not (get-text-property
  8292. (point) 'org-agenda-structural-header)))
  8293. (setq moved t)
  8294. (goto-char dest))
  8295. (if moved (move-beginning-of-line 1)
  8296. (goto-char (if backward (point-min) (point-max)))
  8297. (move-beginning-of-line 1)
  8298. (message "No %s block" (if backward "previous" "further")))))))
  8299. (defun org-agenda-later (arg)
  8300. "Go forward in time by the current span.
  8301. With prefix ARG, go forward that many times the current span."
  8302. (interactive "p")
  8303. (org-agenda-check-type t 'agenda)
  8304. (let* ((wstart (window-start))
  8305. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8306. (span (or (nth 2 args) org-agenda-current-span))
  8307. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8308. (greg (calendar-gregorian-from-absolute sd))
  8309. (cnt (org-get-at-bol 'org-day-cnt))
  8310. greg2)
  8311. (cond
  8312. ((numberp span)
  8313. (setq sd (+ (* span arg) sd)))
  8314. ((eq span 'day)
  8315. (setq sd (+ arg sd)))
  8316. ((eq span 'week)
  8317. (setq sd (+ (* 7 arg) sd)))
  8318. ((eq span 'fortnight)
  8319. (setq sd (+ (* 14 arg) sd)))
  8320. ((eq span 'month)
  8321. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8322. sd (calendar-absolute-from-gregorian greg2))
  8323. (setcar greg2 (1+ (car greg2))))
  8324. ((eq span 'year)
  8325. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8326. sd (calendar-absolute-from-gregorian greg2))
  8327. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8328. (t
  8329. (setq sd (+ (* span arg) sd))))
  8330. (let ((org-agenda-overriding-cmd
  8331. ;; `cmd' may have been set by `org-agenda-run-series' which
  8332. ;; uses `org-agenda-overriding-cmd' to decide whether
  8333. ;; overriding is allowed for `cmd'
  8334. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8335. (org-agenda-overriding-arguments
  8336. (list (car args) sd span)))
  8337. (org-agenda-redo)
  8338. (org-agenda-find-same-or-today-or-agenda cnt))
  8339. (set-window-start nil wstart)))
  8340. (defun org-agenda-earlier (arg)
  8341. "Go backward in time by the current span.
  8342. With prefix ARG, go backward that many times the current span."
  8343. (interactive "p")
  8344. (org-agenda-later (- arg)))
  8345. (defun org-agenda-view-mode-dispatch ()
  8346. "Call one of the view mode commands."
  8347. (interactive)
  8348. (org-unlogged-message
  8349. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8350. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8351. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8352. (pcase (read-char-exclusive)
  8353. (?\ (call-interactively 'org-agenda-reset-view))
  8354. (?d (call-interactively 'org-agenda-day-view))
  8355. (?w (call-interactively 'org-agenda-week-view))
  8356. (?t (call-interactively 'org-agenda-fortnight-view))
  8357. (?m (call-interactively 'org-agenda-month-view))
  8358. (?y (call-interactively 'org-agenda-year-view))
  8359. (?l (call-interactively 'org-agenda-log-mode))
  8360. (?L (org-agenda-log-mode '(4)))
  8361. (?c (org-agenda-log-mode 'clockcheck))
  8362. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8363. (?a (call-interactively 'org-agenda-archives-mode))
  8364. (?A (org-agenda-archives-mode 'files))
  8365. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8366. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8367. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8368. (?D (call-interactively 'org-agenda-toggle-diary))
  8369. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8370. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8371. (org-agenda-check-type t 'agenda)
  8372. (org-agenda-redo))
  8373. (message "Display now includes inactive timestamps as well"))
  8374. (?q (message "Abort"))
  8375. (key (user-error "Invalid key: %s" key))))
  8376. (defun org-agenda-reset-view ()
  8377. "Switch to default view for agenda."
  8378. (interactive)
  8379. (org-agenda-change-time-span org-agenda-span))
  8380. (defun org-agenda-day-view (&optional day-of-month)
  8381. "Switch to daily view for agenda.
  8382. With argument DAY-OF-MONTH, switch to that day of the month."
  8383. (interactive "P")
  8384. (org-agenda-change-time-span 'day day-of-month))
  8385. (defun org-agenda-week-view (&optional iso-week)
  8386. "Switch to weekly view for agenda.
  8387. With argument ISO-WEEK, switch to the corresponding ISO week.
  8388. If ISO-WEEK has more then 2 digits, only the last two encode
  8389. the week. Any digits before this encode a year. So 200712
  8390. means week 12 of year 2007. Years ranging from 70 years ago
  8391. to 30 years in the future can also be written as 2-digit years."
  8392. (interactive "P")
  8393. (org-agenda-change-time-span 'week iso-week))
  8394. (defun org-agenda-fortnight-view (&optional iso-week)
  8395. "Switch to fortnightly view for agenda.
  8396. With argument ISO-WEEK, switch to the corresponding ISO week.
  8397. If ISO-WEEK has more then 2 digits, only the last two encode
  8398. the week. Any digits before this encode a year. So 200712
  8399. means week 12 of year 2007. Years ranging from 70 years ago
  8400. to 30 years in the future can also be written as 2-digit years."
  8401. (interactive "P")
  8402. (org-agenda-change-time-span 'fortnight iso-week))
  8403. (defun org-agenda-month-view (&optional month)
  8404. "Switch to monthly view for agenda.
  8405. With argument MONTH, switch to that month. If MONTH has more
  8406. then 2 digits, only the last two encode the month. Any digits
  8407. before this encode a year. So 200712 means December year 2007.
  8408. Years ranging from 70 years ago to 30 years in the future can
  8409. also be written as 2-digit years."
  8410. (interactive "P")
  8411. (org-agenda-change-time-span 'month month))
  8412. (defun org-agenda-year-view (&optional year)
  8413. "Switch to yearly view for agenda.
  8414. With argument YEAR, switch to that year. Years ranging from 70
  8415. years ago to 30 years in the future can also be written as
  8416. 2-digit years."
  8417. (interactive "P")
  8418. (when year
  8419. (setq year (org-small-year-to-year year)))
  8420. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8421. (org-agenda-change-time-span 'year year)
  8422. (error "Abort")))
  8423. (defun org-agenda-change-time-span (span &optional n)
  8424. "Change the agenda view to SPAN.
  8425. SPAN may be `day', `week', `fortnight', `month', `year'."
  8426. (org-agenda-check-type t 'agenda)
  8427. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8428. (curspan (nth 2 args)))
  8429. (when (and (not n) (equal curspan span))
  8430. (error "Viewing span is already \"%s\"" span))
  8431. (let* ((sd (or (org-get-at-bol 'day)
  8432. (nth 1 args)
  8433. org-starting-day))
  8434. (sd (org-agenda-compute-starting-span sd span n))
  8435. (org-agenda-overriding-cmd
  8436. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8437. (org-agenda-overriding-arguments
  8438. (list (car args) sd span)))
  8439. (org-agenda-redo)
  8440. (org-agenda-find-same-or-today-or-agenda))
  8441. (org-agenda-set-mode-name)
  8442. (message "Switched to %s view" span)))
  8443. (defun org-agenda-compute-starting-span (sd span &optional n)
  8444. "Compute starting date for agenda.
  8445. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8446. is a cons cell with the starting date and the number of days,
  8447. so that the date SD will be in that range."
  8448. (let* ((greg (calendar-gregorian-from-absolute sd))
  8449. ;; (dg (nth 1 greg))
  8450. (mg (car greg))
  8451. (yg (nth 2 greg)))
  8452. (cond
  8453. ((eq span 'day)
  8454. (when n
  8455. (setq sd (+ (calendar-absolute-from-gregorian
  8456. (list mg 1 yg))
  8457. n -1))))
  8458. ((or (eq span 'week) (eq span 'fortnight))
  8459. (let* ((nt (calendar-day-of-week
  8460. (calendar-gregorian-from-absolute sd)))
  8461. (d (if org-agenda-start-on-weekday
  8462. (- nt org-agenda-start-on-weekday)
  8463. 0))
  8464. y1)
  8465. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8466. (when n
  8467. (require 'cal-iso)
  8468. (when (> n 99)
  8469. (setq y1 (org-small-year-to-year (/ n 100))
  8470. n (mod n 100)))
  8471. (setq sd
  8472. (calendar-iso-to-absolute
  8473. (list n 1
  8474. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8475. ((eq span 'month)
  8476. (let (y1)
  8477. (when (and n (> n 99))
  8478. (setq y1 (org-small-year-to-year (/ n 100))
  8479. n (mod n 100)))
  8480. (setq sd (calendar-absolute-from-gregorian
  8481. (list (or n mg) 1 (or y1 yg))))))
  8482. ((eq span 'year)
  8483. (setq sd (calendar-absolute-from-gregorian
  8484. (list 1 1 (or n yg))))))
  8485. sd))
  8486. (defun org-agenda-next-date-line (&optional arg)
  8487. "Jump to the next line indicating a date in agenda buffer."
  8488. (interactive "p")
  8489. (org-agenda-check-type t 'agenda)
  8490. (beginning-of-line 1)
  8491. ;; This does not work if user makes date format that starts with a blank
  8492. (when (looking-at-p "^\\S-") (forward-char 1))
  8493. (unless (re-search-forward "^\\S-" nil t arg)
  8494. (backward-char 1)
  8495. (error "No next date after this line in this buffer"))
  8496. (goto-char (match-beginning 0)))
  8497. (defun org-agenda-previous-date-line (&optional arg)
  8498. "Jump to the previous line indicating a date in agenda buffer."
  8499. (interactive "p")
  8500. (org-agenda-check-type t 'agenda)
  8501. (beginning-of-line 1)
  8502. (unless (re-search-backward "^\\S-" nil t arg)
  8503. (error "No previous date before this line in this buffer")))
  8504. ;; Initialize the highlight
  8505. (defvar org-hl (make-overlay 1 1))
  8506. (overlay-put org-hl 'face 'highlight)
  8507. (defun org-highlight (begin end &optional buffer)
  8508. "Highlight a region with overlay."
  8509. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8510. (defun org-unhighlight ()
  8511. "Detach overlay INDEX."
  8512. (delete-overlay org-hl))
  8513. (defun org-unhighlight-once ()
  8514. "Remove the highlight from its position, and this function from the hook."
  8515. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8516. (org-unhighlight))
  8517. (defvar org-agenda-pre-follow-window-conf nil)
  8518. (defun org-agenda-follow-mode ()
  8519. "Toggle follow mode in an agenda buffer."
  8520. (interactive)
  8521. (unless org-agenda-follow-mode
  8522. (setq org-agenda-pre-follow-window-conf
  8523. (current-window-configuration)))
  8524. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8525. (unless org-agenda-follow-mode
  8526. (set-window-configuration org-agenda-pre-follow-window-conf))
  8527. (org-agenda-set-mode-name)
  8528. (org-agenda-do-context-action)
  8529. (message "Follow mode is %s"
  8530. (if org-agenda-follow-mode "on" "off")))
  8531. (defun org-agenda-entry-text-mode (&optional arg)
  8532. "Toggle entry text mode in an agenda buffer."
  8533. (interactive "P")
  8534. (if (or org-agenda-tag-filter
  8535. org-agenda-category-filter
  8536. org-agenda-regexp-filter
  8537. org-agenda-top-headline-filter)
  8538. (user-error "Can't show entry text in filtered views")
  8539. (setq org-agenda-entry-text-mode (or (integerp arg)
  8540. (not org-agenda-entry-text-mode)))
  8541. (org-agenda-entry-text-hide)
  8542. (and org-agenda-entry-text-mode
  8543. (let ((org-agenda-entry-text-maxlines
  8544. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8545. (org-agenda-entry-text-show)))
  8546. (org-agenda-set-mode-name)
  8547. (message "Entry text mode is %s%s"
  8548. (if org-agenda-entry-text-mode "on" "off")
  8549. (if (not org-agenda-entry-text-mode) ""
  8550. (format " (maximum number of lines is %d)"
  8551. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8552. (defun org-agenda-clockreport-mode ()
  8553. "Toggle clocktable mode in an agenda buffer."
  8554. (interactive)
  8555. (org-agenda-check-type t 'agenda)
  8556. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8557. (org-agenda-set-mode-name)
  8558. (org-agenda-redo)
  8559. (message "Clocktable mode is %s"
  8560. (if org-agenda-clockreport-mode "on" "off")))
  8561. (defun org-agenda-log-mode (&optional special)
  8562. "Toggle log mode in an agenda buffer.
  8563. With argument SPECIAL, show all possible log items, not only the ones
  8564. configured in `org-agenda-log-mode-items'.
  8565. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8566. log items, nothing else."
  8567. (interactive "P")
  8568. (org-agenda-check-type t 'agenda)
  8569. (setq org-agenda-show-log
  8570. (cond
  8571. ((equal special '(16)) 'only)
  8572. ((eq special 'clockcheck)
  8573. (if (eq org-agenda-show-log 'clockcheck)
  8574. nil 'clockcheck))
  8575. (special '(closed clock state))
  8576. (t (not org-agenda-show-log))))
  8577. (org-agenda-set-mode-name)
  8578. (org-agenda-redo)
  8579. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8580. (defun org-agenda-archives-mode (&optional with-files)
  8581. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8582. When called with a prefix argument, include all archive files as well."
  8583. (interactive "P")
  8584. (setq org-agenda-archives-mode
  8585. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8586. (with-files t)
  8587. (org-agenda-archives-mode nil)
  8588. (t 'trees)))
  8589. (org-agenda-set-mode-name)
  8590. (org-agenda-redo)
  8591. (message
  8592. "%s"
  8593. (cond
  8594. ((eq org-agenda-archives-mode nil)
  8595. "No archives are included")
  8596. ((eq org-agenda-archives-mode 'trees)
  8597. (format "Trees with :%s: tag are included" org-archive-tag))
  8598. ((eq org-agenda-archives-mode t)
  8599. (format "Trees with :%s: tag and all active archive files are included"
  8600. org-archive-tag)))))
  8601. (defun org-agenda-toggle-diary ()
  8602. "Toggle diary inclusion in an agenda buffer."
  8603. (interactive)
  8604. (org-agenda-check-type t 'agenda)
  8605. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8606. (org-agenda-redo)
  8607. (org-agenda-set-mode-name)
  8608. (message "Diary inclusion turned %s"
  8609. (if org-agenda-include-diary "on" "off")))
  8610. (defun org-agenda-toggle-deadlines ()
  8611. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8612. (interactive)
  8613. (org-agenda-check-type t 'agenda)
  8614. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8615. (org-agenda-redo)
  8616. (org-agenda-set-mode-name)
  8617. (message "Deadlines inclusion turned %s"
  8618. (if org-agenda-include-deadlines "on" "off")))
  8619. (defun org-agenda-toggle-time-grid ()
  8620. "Toggle time grid in an agenda buffer."
  8621. (interactive)
  8622. (org-agenda-check-type t 'agenda)
  8623. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8624. (org-agenda-redo)
  8625. (org-agenda-set-mode-name)
  8626. (message "Time-grid turned %s"
  8627. (if org-agenda-use-time-grid "on" "off")))
  8628. (defun org-agenda-set-mode-name ()
  8629. "Set the mode name to indicate all the small mode settings."
  8630. (setq mode-name
  8631. (list "Org-Agenda"
  8632. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8633. " "
  8634. '(:eval (org-agenda-span-name org-agenda-current-span))
  8635. (if org-agenda-follow-mode " Follow" "")
  8636. (if org-agenda-entry-text-mode " ETxt" "")
  8637. (if org-agenda-include-diary " Diary" "")
  8638. (if org-agenda-include-deadlines " Ddl" "")
  8639. (if org-agenda-use-time-grid " Grid" "")
  8640. (if (and (boundp 'org-habit-show-habits)
  8641. org-habit-show-habits)
  8642. " Habit" "")
  8643. (cond
  8644. ((consp org-agenda-show-log) " LogAll")
  8645. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8646. (org-agenda-show-log " Log")
  8647. (t ""))
  8648. (if (org-agenda-filter-any) " " "")
  8649. (if (or org-agenda-category-filter
  8650. (get 'org-agenda-category-filter :preset-filter))
  8651. '(:eval (propertize
  8652. (concat "["
  8653. (mapconcat
  8654. #'identity
  8655. (append
  8656. (get 'org-agenda-category-filter :preset-filter)
  8657. org-agenda-category-filter)
  8658. "")
  8659. "]")
  8660. 'face 'org-agenda-filter-category
  8661. 'help-echo "Category used in filtering"))
  8662. "")
  8663. (if (or org-agenda-tag-filter
  8664. (get 'org-agenda-tag-filter :preset-filter))
  8665. '(:eval (propertize
  8666. (concat (mapconcat
  8667. #'identity
  8668. (append
  8669. (get 'org-agenda-tag-filter :preset-filter)
  8670. org-agenda-tag-filter)
  8671. ""))
  8672. 'face 'org-agenda-filter-tags
  8673. 'help-echo "Tags used in filtering"))
  8674. "")
  8675. (if (or org-agenda-effort-filter
  8676. (get 'org-agenda-effort-filter :preset-filter))
  8677. '(:eval (propertize
  8678. (concat (mapconcat
  8679. #'identity
  8680. (append
  8681. (get 'org-agenda-effort-filter :preset-filter)
  8682. org-agenda-effort-filter)
  8683. ""))
  8684. 'face 'org-agenda-filter-effort
  8685. 'help-echo "Effort conditions used in filtering"))
  8686. "")
  8687. (if (or org-agenda-regexp-filter
  8688. (get 'org-agenda-regexp-filter :preset-filter))
  8689. '(:eval (propertize
  8690. (concat (mapconcat
  8691. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8692. (append
  8693. (get 'org-agenda-regexp-filter :preset-filter)
  8694. org-agenda-regexp-filter)
  8695. ""))
  8696. 'face 'org-agenda-filter-regexp
  8697. 'help-echo "Regexp used in filtering"))
  8698. "")
  8699. (if org-agenda-archives-mode
  8700. (if (eq org-agenda-archives-mode t)
  8701. " Archives"
  8702. (format " :%s:" org-archive-tag))
  8703. "")
  8704. (if org-agenda-clockreport-mode " Clock" "")))
  8705. (force-mode-line-update))
  8706. (defun org-agenda-update-agenda-type ()
  8707. "Update the agenda type after each command."
  8708. (setq org-agenda-type
  8709. (or (get-text-property (point) 'org-agenda-type)
  8710. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8711. (defun org-agenda-next-line ()
  8712. "Move cursor to the next line, and show if follow mode is active."
  8713. (interactive)
  8714. (call-interactively 'next-line)
  8715. (org-agenda-do-context-action))
  8716. (defun org-agenda-previous-line ()
  8717. "Move cursor to the previous line, and show if follow-mode is active."
  8718. (interactive)
  8719. (call-interactively 'previous-line)
  8720. (org-agenda-do-context-action))
  8721. (defun org-agenda-next-item (n)
  8722. "Move cursor to next agenda item."
  8723. (interactive "p")
  8724. (let ((col (current-column)))
  8725. (dotimes (_ n)
  8726. (when (next-single-property-change (point-at-eol) 'org-marker)
  8727. (move-end-of-line 1)
  8728. (goto-char (next-single-property-change (point) 'org-marker))))
  8729. (org-move-to-column col))
  8730. (org-agenda-do-context-action))
  8731. (defun org-agenda-previous-item (n)
  8732. "Move cursor to next agenda item."
  8733. (interactive "p")
  8734. (dotimes (_ n)
  8735. (let ((col (current-column))
  8736. (goto (save-excursion
  8737. (move-end-of-line 0)
  8738. (previous-single-property-change (point) 'org-marker))))
  8739. (when goto (goto-char goto))
  8740. (org-move-to-column col)))
  8741. (org-agenda-do-context-action))
  8742. (defun org-agenda-do-context-action ()
  8743. "Show outline path and, maybe, follow mode window."
  8744. (let ((m (org-get-at-bol 'org-marker)))
  8745. (when (and (markerp m) (marker-buffer m))
  8746. (and org-agenda-follow-mode
  8747. (if org-agenda-follow-indirect
  8748. (org-agenda-tree-to-indirect-buffer nil)
  8749. (org-agenda-show)))
  8750. (and org-agenda-show-outline-path
  8751. (org-with-point-at m (org-display-outline-path t))))))
  8752. (defun org-agenda-show-tags ()
  8753. "Show the tags applicable to the current item."
  8754. (interactive)
  8755. (let* ((tags (org-get-at-bol 'tags)))
  8756. (if tags
  8757. (message "Tags are :%s:"
  8758. (org-no-properties (mapconcat #'identity tags ":")))
  8759. (message "No tags associated with this line"))))
  8760. (defun org-agenda-goto (&optional highlight)
  8761. "Go to the entry at point in the corresponding Org file."
  8762. (interactive)
  8763. (let* ((marker (or (org-get-at-bol 'org-marker)
  8764. (org-agenda-error)))
  8765. (buffer (marker-buffer marker))
  8766. (pos (marker-position marker)))
  8767. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8768. (switch-to-buffer-other-window buffer)
  8769. (widen)
  8770. (push-mark)
  8771. (goto-char pos)
  8772. (when (derived-mode-p 'org-mode)
  8773. (org-show-context 'agenda)
  8774. (recenter (/ (window-height) 2))
  8775. (org-back-to-heading t)
  8776. (let ((case-fold-search nil))
  8777. (when (re-search-forward org-complex-heading-regexp nil t)
  8778. (goto-char (match-beginning 4)))))
  8779. (run-hooks 'org-agenda-after-show-hook)
  8780. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8781. (defvar org-agenda-after-show-hook nil
  8782. "Normal hook run after an item has been shown from the agenda.
  8783. Point is in the buffer where the item originated.")
  8784. ;; Defined later in org-agenda.el
  8785. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8786. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8787. "Between region BEG and END, call agenda command CMD.
  8788. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8789. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8790. deletes the agenda entry and don't move to the next entry."
  8791. (save-excursion
  8792. (goto-char beg)
  8793. (let ((mend (move-marker (make-marker) end))
  8794. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8795. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8796. org-agenda-loop-over-headlines-in-active-region))
  8797. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8798. (org-get-at-bol 'level))))
  8799. (while (< (point) mend)
  8800. (let ((ov (make-overlay (point) (point-at-eol))))
  8801. (if (not (or all
  8802. (and match (looking-at-p match))
  8803. (eq level (org-get-at-bol 'level))))
  8804. (org-agenda-next-item 1)
  8805. (overlay-put ov 'face 'region)
  8806. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8807. (when (not delete) (org-agenda-next-item 1))
  8808. (delete-overlay ov)))))))
  8809. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8810. ;; kill,set-property,set-effort] commands may loop over agenda
  8811. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8812. ;; use their own mechanisms on active regions.
  8813. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8814. "Maybe loop over agenda entries and perform CMD.
  8815. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8816. (declare (debug t))
  8817. `(if (and (called-interactively-p 'any)
  8818. org-agenda-loop-over-headlines-in-active-region
  8819. (org-region-active-p))
  8820. (org-agenda-do-in-region
  8821. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8822. ,@body))
  8823. (defun org-agenda-kill ()
  8824. "Kill the entry or subtree belonging to the current agenda entry."
  8825. (interactive)
  8826. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8827. (org-agenda-maybe-loop
  8828. #'org-agenda-kill nil nil t
  8829. (let* ((bufname-orig (buffer-name))
  8830. (marker (or (org-get-at-bol 'org-marker)
  8831. (org-agenda-error)))
  8832. (buffer (marker-buffer marker))
  8833. (pos (marker-position marker))
  8834. (type (org-get-at-bol 'type))
  8835. dbeg dend (n 0))
  8836. (org-with-remote-undo buffer
  8837. (with-current-buffer buffer
  8838. (save-excursion
  8839. (goto-char pos)
  8840. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8841. (setq dbeg (progn (org-back-to-heading t) (point))
  8842. dend (org-end-of-subtree t t))
  8843. (setq dbeg (point-at-bol)
  8844. dend (min (point-max) (1+ (point-at-eol)))))
  8845. (goto-char dbeg)
  8846. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8847. (when (or (eq t org-agenda-confirm-kill)
  8848. (and (numberp org-agenda-confirm-kill)
  8849. (> n org-agenda-confirm-kill)))
  8850. (let ((win-conf (current-window-configuration)))
  8851. (unwind-protect
  8852. (and
  8853. (prog2
  8854. (org-agenda-tree-to-indirect-buffer nil)
  8855. (not (y-or-n-p
  8856. (format "Delete entry with %d lines in buffer \"%s\"? "
  8857. n (buffer-name buffer))))
  8858. (kill-buffer org-last-indirect-buffer))
  8859. (error "Abort"))
  8860. (set-window-configuration win-conf))))
  8861. (let ((org-agenda-buffer-name bufname-orig))
  8862. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8863. (with-current-buffer buffer (delete-region dbeg dend))
  8864. (message "Agenda item and source killed")))))
  8865. (defvar org-archive-default-command) ; defined in org-archive.el
  8866. (defun org-agenda-archive-default ()
  8867. "Archive the entry or subtree belonging to the current agenda entry."
  8868. (interactive)
  8869. (require 'org-archive)
  8870. (funcall-interactively
  8871. #'org-agenda-archive-with org-archive-default-command))
  8872. (defun org-agenda-archive-default-with-confirmation ()
  8873. "Archive the entry or subtree belonging to the current agenda entry."
  8874. (interactive)
  8875. (require 'org-archive)
  8876. (funcall-interactively
  8877. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8878. (defun org-agenda-archive ()
  8879. "Archive the entry or subtree belonging to the current agenda entry."
  8880. (interactive)
  8881. (funcall-interactively
  8882. #'org-agenda-archive-with 'org-archive-subtree))
  8883. (defun org-agenda-archive-to-archive-sibling ()
  8884. "Move the entry to the archive sibling."
  8885. (interactive)
  8886. (funcall-interactively
  8887. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8888. (defvar org-archive-from-agenda)
  8889. (defun org-agenda-archive-with (cmd &optional confirm)
  8890. "Move the entry to the archive sibling."
  8891. (interactive)
  8892. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8893. (org-agenda-maybe-loop
  8894. #'org-agenda-archive-with cmd nil t
  8895. (let* ((bufname-orig (buffer-name))
  8896. (marker (or (org-get-at-bol 'org-marker)
  8897. (org-agenda-error)))
  8898. (buffer (marker-buffer marker))
  8899. (pos (marker-position marker)))
  8900. (org-with-remote-undo buffer
  8901. (with-current-buffer buffer
  8902. (if (derived-mode-p 'org-mode)
  8903. (if (and confirm
  8904. (not (y-or-n-p "Archive this subtree or entry? ")))
  8905. (error "Abort")
  8906. (save-window-excursion
  8907. (goto-char pos)
  8908. (let ((org-agenda-buffer-name bufname-orig))
  8909. (org-remove-subtree-entries-from-agenda))
  8910. (org-back-to-heading t)
  8911. (let ((org-archive-from-agenda t))
  8912. (funcall cmd))))
  8913. (error "Archiving works only in Org files")))))))
  8914. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8915. "Remove all lines in the agenda that correspond to a given subtree.
  8916. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8917. If this information is not given, the function uses the tree at point."
  8918. (let ((buf (or buf (current-buffer))) m p)
  8919. (save-excursion
  8920. (unless (and beg end)
  8921. (org-back-to-heading t)
  8922. (setq beg (point))
  8923. (org-end-of-subtree t)
  8924. (setq end (point)))
  8925. (set-buffer (get-buffer org-agenda-buffer-name))
  8926. (save-excursion
  8927. (goto-char (point-max))
  8928. (beginning-of-line 1)
  8929. (while (not (bobp))
  8930. (when (and (setq m (org-get-at-bol 'org-marker))
  8931. (equal buf (marker-buffer m))
  8932. (setq p (marker-position m))
  8933. (>= p beg)
  8934. (< p end))
  8935. (let ((inhibit-read-only t))
  8936. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8937. (beginning-of-line 0))))))
  8938. (defun org-agenda-refile (&optional goto rfloc no-update)
  8939. "Refile the item at point.
  8940. When called with `\\[universal-argument] \\[universal-argument]', \
  8941. go to the location of the last
  8942. refiled item.
  8943. When called with `\\[universal-argument] \\[universal-argument] \
  8944. \\[universal-argument]' prefix or when GOTO is 0, clear
  8945. the refile cache.
  8946. RFLOC can be a refile location obtained in a different way.
  8947. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8948. (interactive "P")
  8949. (cond
  8950. ((member goto '(0 (64)))
  8951. (org-refile-cache-clear))
  8952. ((equal goto '(16))
  8953. (org-refile-goto-last-stored))
  8954. (t
  8955. (let* ((buffer-orig (buffer-name))
  8956. (marker (or (org-get-at-bol 'org-hd-marker)
  8957. (org-agenda-error)))
  8958. (buffer (marker-buffer marker))
  8959. ;; (pos (marker-position marker))
  8960. (rfloc (or rfloc
  8961. (org-refile-get-location
  8962. (if goto "Goto" "Refile to") buffer
  8963. org-refile-allow-creating-parent-nodes))))
  8964. (with-current-buffer buffer
  8965. (org-with-wide-buffer
  8966. (goto-char marker)
  8967. (let ((org-agenda-buffer-name buffer-orig))
  8968. (org-remove-subtree-entries-from-agenda))
  8969. (org-refile goto buffer rfloc))))
  8970. (unless no-update (org-agenda-redo)))))
  8971. (defun org-agenda-open-link (&optional arg)
  8972. "Open the link(s) in the current entry, if any.
  8973. This looks for a link in the displayed line in the agenda.
  8974. It also looks at the text of the entry itself."
  8975. (interactive "P")
  8976. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8977. (org-get-at-bol 'org-marker)))
  8978. (buffer (and marker (marker-buffer marker)))
  8979. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8980. (lkall (and buffer (org-offer-links-in-entry
  8981. buffer marker arg prefix)))
  8982. (lk0 (car lkall))
  8983. (lk (if (stringp lk0) (list lk0) lk0))
  8984. (lkend (cdr lkall))
  8985. trg)
  8986. (cond
  8987. ((and buffer lk)
  8988. (mapcar (lambda(l)
  8989. (with-current-buffer buffer
  8990. (setq trg (and (string-match org-link-bracket-re l)
  8991. (match-string 1 l)))
  8992. (if (or (not trg) (string-match org-link-any-re trg))
  8993. ;; Don't use `org-with-wide-buffer' here as
  8994. ;; opening the link may result in moving the point
  8995. (save-restriction
  8996. (widen)
  8997. (goto-char marker)
  8998. (when (search-forward l nil lkend)
  8999. (goto-char (match-beginning 0))
  9000. (org-open-at-point)))
  9001. ;; This is an internal link, widen the buffer
  9002. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9003. (switch-to-buffer-other-window buffer)
  9004. (widen)
  9005. (goto-char marker)
  9006. (when (search-forward l nil lkend)
  9007. (goto-char (match-beginning 0))
  9008. (org-open-at-point)))))
  9009. lk))
  9010. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9011. (save-excursion
  9012. (beginning-of-line 1)
  9013. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9014. (org-link-open-from-string (match-string 1)))
  9015. (t (message "No link to open here")))))
  9016. (defun org-agenda-copy-local-variable (var)
  9017. "Get a variable from a referenced buffer and install it here."
  9018. (let ((m (org-get-at-bol 'org-marker)))
  9019. (when (and m (buffer-live-p (marker-buffer m)))
  9020. (set (make-local-variable var)
  9021. (with-current-buffer (marker-buffer m)
  9022. (symbol-value var))))))
  9023. (defun org-agenda-switch-to (&optional delete-other-windows)
  9024. "Go to the Org mode file which contains the item at point.
  9025. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9026. displayed Org file fills the frame."
  9027. (interactive)
  9028. (if (and org-return-follows-link
  9029. (not (org-get-at-bol 'org-marker))
  9030. (org-in-regexp org-link-bracket-re))
  9031. (org-link-open-from-string (match-string 0))
  9032. (let* ((marker (or (org-get-at-bol 'org-marker)
  9033. (org-agenda-error)))
  9034. (buffer (marker-buffer marker))
  9035. (pos (marker-position marker)))
  9036. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9037. (pop-to-buffer-same-window buffer)
  9038. (when delete-other-windows (delete-other-windows))
  9039. (widen)
  9040. (goto-char pos)
  9041. (when (derived-mode-p 'org-mode)
  9042. (org-show-context 'agenda)
  9043. (run-hooks 'org-agenda-after-show-hook)))))
  9044. (defun org-agenda-goto-mouse (ev)
  9045. "Go to the Org file which contains the item at the mouse click."
  9046. (interactive "e")
  9047. (mouse-set-point ev)
  9048. (org-agenda-goto))
  9049. (defun org-agenda-show (&optional full-entry)
  9050. "Display the Org file which contains the item at point.
  9051. With prefix argument FULL-ENTRY, make the entire entry visible
  9052. if it was hidden in the outline."
  9053. (interactive "P")
  9054. (let ((win (selected-window)))
  9055. (org-agenda-goto t)
  9056. (when full-entry (org-show-entry))
  9057. (select-window win)))
  9058. (defvar org-agenda-show-window nil)
  9059. (defun org-agenda-show-and-scroll-up (&optional arg)
  9060. "Display the Org file which contains the item at point.
  9061. When called repeatedly, scroll the window that is displaying the buffer.
  9062. With a `\\[universal-argument]' prefix argument, display the item, but \
  9063. fold drawers."
  9064. (interactive "P")
  9065. (let ((win (selected-window)))
  9066. (if (and (window-live-p org-agenda-show-window)
  9067. (eq this-command last-command))
  9068. (progn
  9069. (select-window org-agenda-show-window)
  9070. (ignore-errors (scroll-up)))
  9071. (org-agenda-goto t)
  9072. (org-show-entry)
  9073. (if arg (org-cycle-hide-drawers 'children)
  9074. (org-with-wide-buffer
  9075. (narrow-to-region (org-entry-beginning-position)
  9076. (org-entry-end-position))
  9077. (org-show-all '(drawers))))
  9078. (setq org-agenda-show-window (selected-window)))
  9079. (select-window win)))
  9080. (defun org-agenda-show-scroll-down ()
  9081. "Scroll down the window showing the agenda."
  9082. (interactive)
  9083. (let ((win (selected-window)))
  9084. (when (window-live-p org-agenda-show-window)
  9085. (select-window org-agenda-show-window)
  9086. (ignore-errors (scroll-down))
  9087. (select-window win))))
  9088. (defun org-agenda-show-1 (&optional more)
  9089. "Display the Org file which contains the item at point.
  9090. The prefix arg selects the amount of information to display:
  9091. 0 hide the subtree
  9092. 1 just show the entry according to defaults.
  9093. 2 show the children view
  9094. 3 show the subtree view
  9095. 4 show the entire subtree and any drawers
  9096. With prefix argument FULL-ENTRY, make the entire entry visible
  9097. if it was hidden in the outline."
  9098. (interactive "p")
  9099. (let ((win (selected-window)))
  9100. (org-agenda-goto t)
  9101. (org-back-to-heading)
  9102. (set-window-start (selected-window) (point-at-bol))
  9103. (cond
  9104. ((= more 0)
  9105. (org-flag-subtree t)
  9106. (save-excursion
  9107. (org-back-to-heading)
  9108. (run-hook-with-args 'org-cycle-hook 'folded))
  9109. (message "Remote: FOLDED"))
  9110. ((and (called-interactively-p 'any) (= more 1))
  9111. (message "Remote: show with default settings"))
  9112. ((= more 2)
  9113. (outline-show-entry)
  9114. (org-show-children)
  9115. (save-excursion
  9116. (org-back-to-heading)
  9117. (run-hook-with-args 'org-cycle-hook 'children))
  9118. (message "Remote: CHILDREN"))
  9119. ((= more 3)
  9120. (outline-show-subtree)
  9121. (save-excursion
  9122. (org-back-to-heading)
  9123. (run-hook-with-args 'org-cycle-hook 'subtree))
  9124. (message "Remote: SUBTREE"))
  9125. ((> more 3)
  9126. (outline-show-subtree)
  9127. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9128. (select-window win)))
  9129. (defvar org-agenda-cycle-counter nil)
  9130. (defun org-agenda-cycle-show (&optional n)
  9131. "Show the current entry in another window, with default settings.
  9132. Default settings are taken from `org-show-context-detail'. When
  9133. use repeatedly in immediate succession, the remote entry will
  9134. cycle through visibility
  9135. children -> subtree -> folded
  9136. When called with a numeric prefix arg, that arg will be passed through to
  9137. `org-agenda-show-1'. For the interpretation of that argument, see the
  9138. docstring of `org-agenda-show-1'."
  9139. (interactive "P")
  9140. (if (integerp n)
  9141. (setq org-agenda-cycle-counter n)
  9142. (if (not (eq last-command this-command))
  9143. (setq org-agenda-cycle-counter 1)
  9144. (if (equal org-agenda-cycle-counter 0)
  9145. (setq org-agenda-cycle-counter 2)
  9146. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9147. (when (> org-agenda-cycle-counter 3)
  9148. (setq org-agenda-cycle-counter 0)))))
  9149. (org-agenda-show-1 org-agenda-cycle-counter))
  9150. (defun org-agenda-recenter (arg)
  9151. "Display the Org file which contains the item at point and recenter."
  9152. (interactive "P")
  9153. (let ((win (selected-window)))
  9154. (org-agenda-goto t)
  9155. (recenter arg)
  9156. (select-window win)))
  9157. (defun org-agenda-show-mouse (ev)
  9158. "Display the Org file which contains the item at the mouse click."
  9159. (interactive "e")
  9160. (mouse-set-point ev)
  9161. (org-agenda-show))
  9162. (defun org-agenda-check-no-diary ()
  9163. "Check if the entry is a diary link and abort if yes."
  9164. (when (org-get-at-bol 'org-agenda-diary-link)
  9165. (org-agenda-error)))
  9166. (defun org-agenda-error ()
  9167. "Throw an error when a command is not allowed in the agenda."
  9168. (user-error "Command not allowed in this line"))
  9169. (defun org-agenda-tree-to-indirect-buffer (arg)
  9170. "Show the subtree corresponding to the current entry in an indirect buffer.
  9171. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9172. With a numerical prefix ARG, go up to this level and then take that tree.
  9173. With a negative numeric ARG, go up by this number of levels.
  9174. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9175. i.e. don't use
  9176. the dedicated frame."
  9177. (interactive "P")
  9178. (if current-prefix-arg
  9179. (org-agenda-do-tree-to-indirect-buffer arg)
  9180. (let ((agenda-buffer (buffer-name))
  9181. (agenda-window (selected-window))
  9182. (indirect-window
  9183. (and org-last-indirect-buffer
  9184. (get-buffer-window org-last-indirect-buffer))))
  9185. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9186. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9187. (eq org-indirect-buffer-display 'dedicated-frame))
  9188. (unwind-protect
  9189. (unless (and indirect-window (window-live-p indirect-window))
  9190. (setq indirect-window (split-window agenda-window)))
  9191. (and indirect-window (select-window indirect-window))
  9192. (switch-to-buffer org-last-indirect-buffer :norecord)
  9193. (fit-window-to-buffer indirect-window)))
  9194. (select-window (get-buffer-window agenda-buffer))
  9195. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9196. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9197. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9198. (org-agenda-check-no-diary)
  9199. (let* ((marker (or (org-get-at-bol 'org-marker)
  9200. (org-agenda-error)))
  9201. (buffer (marker-buffer marker))
  9202. (pos (marker-position marker)))
  9203. (with-current-buffer buffer
  9204. (save-excursion
  9205. (goto-char pos)
  9206. (org-tree-to-indirect-buffer arg)))))
  9207. (defvar org-last-heading-marker (make-marker)
  9208. "Marker pointing to the headline that last changed its TODO state
  9209. by a remote command from the agenda.")
  9210. (defun org-agenda-todo-nextset ()
  9211. "Switch TODO entry to next sequence."
  9212. (interactive)
  9213. (org-agenda-todo 'nextset))
  9214. (defun org-agenda-todo-previousset ()
  9215. "Switch TODO entry to previous sequence."
  9216. (interactive)
  9217. (org-agenda-todo 'previousset))
  9218. (defvar org-agenda-headline-snapshot-before-repeat)
  9219. (defun org-agenda-todo (&optional arg)
  9220. "Cycle TODO state of line at point, also in Org file.
  9221. This changes the line at point, all other lines in the agenda referring to
  9222. the same tree node, and the headline of the tree node in the Org file."
  9223. (interactive "P")
  9224. (org-agenda-check-no-diary)
  9225. (org-agenda-maybe-loop
  9226. #'org-agenda-todo arg nil nil
  9227. (let* ((col (current-column))
  9228. (marker (or (org-get-at-bol 'org-marker)
  9229. (org-agenda-error)))
  9230. (buffer (marker-buffer marker))
  9231. (pos (marker-position marker))
  9232. (hdmarker (org-get-at-bol 'org-hd-marker))
  9233. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9234. (inhibit-read-only t)
  9235. org-loop-over-headlines-in-active-region
  9236. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9237. (org-with-remote-undo buffer
  9238. (with-current-buffer buffer
  9239. (widen)
  9240. (goto-char pos)
  9241. (org-show-context 'agenda)
  9242. (let ((current-prefix-arg arg))
  9243. (call-interactively 'org-todo)
  9244. ;; Make sure that log is recorded in current undo.
  9245. (when (and org-log-setup
  9246. (not (eq org-log-note-how 'note)))
  9247. (org-add-log-note)))
  9248. (and (bolp) (forward-char 1))
  9249. (setq newhead (org-get-heading))
  9250. (when (and org-agenda-headline-snapshot-before-repeat
  9251. (not (equal org-agenda-headline-snapshot-before-repeat
  9252. newhead))
  9253. todayp)
  9254. (setq newhead org-agenda-headline-snapshot-before-repeat
  9255. just-one t))
  9256. (save-excursion
  9257. (org-back-to-heading)
  9258. (move-marker org-last-heading-marker (point))))
  9259. (beginning-of-line 1)
  9260. (save-window-excursion
  9261. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9262. (when (bound-and-true-p org-clock-out-when-done)
  9263. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9264. newhead)
  9265. (org-agenda-unmark-clocking-task))
  9266. (org-move-to-column col)
  9267. (org-agenda-mark-clocking-task)))))
  9268. (defun org-agenda-add-note (&optional _arg)
  9269. "Add a time-stamped note to the entry at point."
  9270. (interactive) ;; "P"
  9271. (org-agenda-check-no-diary)
  9272. (let* ((marker (or (org-get-at-bol 'org-marker)
  9273. (org-agenda-error)))
  9274. (buffer (marker-buffer marker))
  9275. (pos (marker-position marker))
  9276. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9277. (inhibit-read-only t))
  9278. (with-current-buffer buffer
  9279. (widen)
  9280. (goto-char pos)
  9281. (org-show-context 'agenda)
  9282. (org-add-note))))
  9283. (defun org-agenda-change-all-lines (newhead hdmarker
  9284. &optional fixface just-this)
  9285. "Change all lines in the agenda buffer which match HDMARKER.
  9286. The new content of the line will be NEWHEAD (as modified by
  9287. `org-agenda-format-item'). HDMARKER is checked with
  9288. `equal' against all `org-hd-marker' text properties in the file.
  9289. If FIXFACE is non-nil, the face of each item is modified according to
  9290. the new TODO state.
  9291. If JUST-THIS is non-nil, change just the current line, not all.
  9292. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9293. (let* ((inhibit-read-only t)
  9294. (line (org-current-line))
  9295. (org-agenda-buffer (current-buffer))
  9296. (thetags (with-current-buffer (marker-buffer hdmarker)
  9297. (org-get-tags hdmarker)))
  9298. props m undone-face done-face finish new dotime level cat tags
  9299. effort effort-minutes) ;; pl
  9300. (save-excursion
  9301. (goto-char (point-max))
  9302. (beginning-of-line 1)
  9303. (while (not finish)
  9304. (setq finish (bobp))
  9305. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9306. (or (not just-this) (= (org-current-line) line))
  9307. (equal m hdmarker))
  9308. (setq props (text-properties-at (point))
  9309. dotime (org-get-at-bol 'dotime)
  9310. cat (org-agenda-get-category)
  9311. level (org-get-at-bol 'level)
  9312. tags thetags
  9313. effort (org-get-at-bol 'effort)
  9314. effort-minutes (org-get-at-bol 'effort-minutes)
  9315. new
  9316. (let ((org-prefix-format-compiled
  9317. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9318. org-prefix-format-compiled))
  9319. (extra (org-get-at-bol 'extra)))
  9320. (with-current-buffer (marker-buffer hdmarker)
  9321. (org-with-wide-buffer
  9322. (org-agenda-format-item extra
  9323. (org-add-props newhead nil
  9324. 'effort effort
  9325. 'effort-minutes effort-minutes)
  9326. level cat tags dotime))))
  9327. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9328. undone-face (org-get-at-bol 'undone-face)
  9329. done-face (org-get-at-bol 'done-face))
  9330. (beginning-of-line 1)
  9331. (cond
  9332. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9333. ((looking-at ".*")
  9334. ;; When replacing the whole line, preserve bulk mark
  9335. ;; overlay, if any.
  9336. (let ((mark (catch :overlay
  9337. (dolist (o (overlays-in (point) (+ 2 (point))))
  9338. (when (eq (overlay-get o 'type)
  9339. 'org-marked-entry-overlay)
  9340. (throw :overlay o))))))
  9341. (replace-match new t t)
  9342. (beginning-of-line)
  9343. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9344. (add-text-properties (point-at-bol) (point-at-eol) props)
  9345. (when fixface
  9346. (add-text-properties
  9347. (point-at-bol) (point-at-eol)
  9348. (list 'face
  9349. (if org-last-todo-state-is-todo
  9350. undone-face done-face))))
  9351. (org-agenda-highlight-todo 'line)
  9352. (beginning-of-line 1))
  9353. (t (error "Line update did not work")))
  9354. (save-restriction
  9355. (narrow-to-region (point-at-bol) (point-at-eol))
  9356. (org-agenda-finalize)))
  9357. (beginning-of-line 0)))))
  9358. (defun org-agenda-align-tags (&optional line)
  9359. "Align all tags in agenda items to `org-agenda-tags-column'.
  9360. When optional argument LINE is non-nil, align tags only on the
  9361. current line."
  9362. (let ((inhibit-read-only t)
  9363. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9364. (- (window-text-width))
  9365. org-agenda-tags-column))
  9366. (end (and line (line-end-position)))
  9367. l c)
  9368. (save-excursion
  9369. (goto-char (if line (line-beginning-position) (point-min)))
  9370. (while (re-search-forward org-tag-group-re end t)
  9371. (add-text-properties
  9372. (match-beginning 1) (match-end 1)
  9373. (list 'face (delq nil (let ((prop (get-text-property
  9374. (match-beginning 1) 'face)))
  9375. (or (listp prop) (setq prop (list prop)))
  9376. (if (memq 'org-tag prop)
  9377. prop
  9378. (cons 'org-tag prop))))))
  9379. (setq l (string-width (match-string 1))
  9380. c (if (< org-agenda-tags-column 0)
  9381. (- (abs org-agenda-tags-column) l)
  9382. org-agenda-tags-column))
  9383. (goto-char (match-beginning 1))
  9384. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9385. (point))
  9386. (insert (org-add-props
  9387. (make-string (max 1 (- c (current-column))) ?\s)
  9388. (plist-put (copy-sequence (text-properties-at (point)))
  9389. 'face nil))))
  9390. (goto-char (point-min))
  9391. (org-font-lock-add-tag-faces (point-max)))))
  9392. (defun org-agenda-priority-up ()
  9393. "Increase the priority of line at point, also in Org file."
  9394. (interactive)
  9395. (org-agenda-priority 'up))
  9396. (defun org-agenda-priority-down ()
  9397. "Decrease the priority of line at point, also in Org file."
  9398. (interactive)
  9399. (org-agenda-priority 'down))
  9400. (defun org-agenda-priority (&optional force-direction)
  9401. "Set the priority of line at point, also in Org file.
  9402. This changes the line at point, all other lines in the agenda
  9403. referring to the same tree node, and the headline of the tree
  9404. node in the Org file.
  9405. Called with one universal prefix arg, show the priority instead
  9406. of setting it.
  9407. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9408. `down', or a character."
  9409. (interactive "P")
  9410. (unless org-priority-enable-commands
  9411. (user-error "Priority commands are disabled"))
  9412. (org-agenda-check-no-diary)
  9413. (let* ((col (current-column))
  9414. (hdmarker (org-get-at-bol 'org-hd-marker))
  9415. (buffer (marker-buffer hdmarker))
  9416. (pos (marker-position hdmarker))
  9417. (inhibit-read-only t)
  9418. newhead)
  9419. (org-with-remote-undo buffer
  9420. (with-current-buffer buffer
  9421. (widen)
  9422. (goto-char pos)
  9423. (org-show-context 'agenda)
  9424. (org-priority force-direction)
  9425. (end-of-line 1)
  9426. (setq newhead (org-get-heading)))
  9427. (org-agenda-change-all-lines newhead hdmarker)
  9428. (org-move-to-column col))))
  9429. ;; FIXME: should fix the tags property of the agenda line.
  9430. (defun org-agenda-set-tags (&optional tag onoff)
  9431. "Set tags for the current headline."
  9432. (interactive)
  9433. (org-agenda-check-no-diary)
  9434. (if (and (org-region-active-p) (called-interactively-p 'any))
  9435. (call-interactively 'org-change-tag-in-region)
  9436. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9437. (org-agenda-error)))
  9438. (buffer (marker-buffer hdmarker))
  9439. (pos (marker-position hdmarker))
  9440. (inhibit-read-only t)
  9441. newhead)
  9442. (org-with-remote-undo buffer
  9443. (with-current-buffer buffer
  9444. (widen)
  9445. (goto-char pos)
  9446. (org-show-context 'agenda)
  9447. (if tag
  9448. (org-toggle-tag tag onoff)
  9449. (call-interactively #'org-set-tags-command))
  9450. (end-of-line 1)
  9451. (setq newhead (org-get-heading)))
  9452. (org-agenda-change-all-lines newhead hdmarker)
  9453. (beginning-of-line 1)))))
  9454. (defun org-agenda-set-property ()
  9455. "Set a property for the current headline."
  9456. (interactive)
  9457. (org-agenda-check-no-diary)
  9458. (org-agenda-maybe-loop
  9459. #'org-agenda-set-property nil nil nil
  9460. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9461. (org-agenda-error)))
  9462. (buffer (marker-buffer hdmarker))
  9463. (pos (marker-position hdmarker))
  9464. (inhibit-read-only t)
  9465. ) ;; newhead
  9466. (org-with-remote-undo buffer
  9467. (with-current-buffer buffer
  9468. (widen)
  9469. (goto-char pos)
  9470. (org-show-context 'agenda)
  9471. (call-interactively 'org-set-property))))))
  9472. (defun org-agenda-set-effort ()
  9473. "Set the effort property for the current headline."
  9474. (interactive)
  9475. (org-agenda-check-no-diary)
  9476. (org-agenda-maybe-loop
  9477. #'org-agenda-set-effort nil nil nil
  9478. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9479. (org-agenda-error)))
  9480. (buffer (marker-buffer hdmarker))
  9481. (pos (marker-position hdmarker))
  9482. (inhibit-read-only t)
  9483. newhead)
  9484. (org-with-remote-undo buffer
  9485. (with-current-buffer buffer
  9486. (widen)
  9487. (goto-char pos)
  9488. (org-show-context 'agenda)
  9489. (call-interactively 'org-set-effort)
  9490. (end-of-line 1)
  9491. (setq newhead (org-get-heading)))
  9492. (org-agenda-change-all-lines newhead hdmarker)))))
  9493. (defun org-agenda-toggle-archive-tag ()
  9494. "Toggle the archive tag for the current entry."
  9495. (interactive)
  9496. (org-agenda-check-no-diary)
  9497. (org-agenda-maybe-loop
  9498. #'org-agenda-toggle-archive-tag nil nil nil
  9499. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9500. (org-agenda-error)))
  9501. (buffer (marker-buffer hdmarker))
  9502. (pos (marker-position hdmarker))
  9503. (inhibit-read-only t)
  9504. newhead)
  9505. (org-with-remote-undo buffer
  9506. (with-current-buffer buffer
  9507. (widen)
  9508. (goto-char pos)
  9509. (org-show-context 'agenda)
  9510. (call-interactively 'org-toggle-archive-tag)
  9511. (end-of-line 1)
  9512. (setq newhead (org-get-heading)))
  9513. (org-agenda-change-all-lines newhead hdmarker)
  9514. (beginning-of-line 1)))))
  9515. (defun org-agenda-do-date-later (arg)
  9516. (interactive "P")
  9517. (cond
  9518. ((or (equal arg '(16))
  9519. (memq last-command
  9520. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9521. (setq this-command 'org-agenda-date-later-minutes)
  9522. (org-agenda-date-later-minutes 1))
  9523. ((or (equal arg '(4))
  9524. (memq last-command
  9525. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9526. (setq this-command 'org-agenda-date-later-hours)
  9527. (org-agenda-date-later-hours 1))
  9528. (t
  9529. (org-agenda-date-later (prefix-numeric-value arg)))))
  9530. (defun org-agenda-do-date-earlier (arg)
  9531. (interactive "P")
  9532. (cond
  9533. ((or (equal arg '(16))
  9534. (memq last-command
  9535. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9536. (setq this-command 'org-agenda-date-earlier-minutes)
  9537. (org-agenda-date-earlier-minutes 1))
  9538. ((or (equal arg '(4))
  9539. (memq last-command
  9540. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9541. (setq this-command 'org-agenda-date-earlier-hours)
  9542. (org-agenda-date-earlier-hours 1))
  9543. (t
  9544. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9545. (defun org-agenda-date-later (arg &optional what)
  9546. "Change the date of this item to ARG day(s) later."
  9547. (interactive "p")
  9548. (org-agenda-check-type t 'agenda)
  9549. (org-agenda-check-no-diary)
  9550. (let* ((marker (or (org-get-at-bol 'org-marker)
  9551. (org-agenda-error)))
  9552. (buffer (marker-buffer marker))
  9553. (pos (marker-position marker))
  9554. cdate today)
  9555. (org-with-remote-undo buffer
  9556. (with-current-buffer buffer
  9557. (widen)
  9558. (goto-char pos)
  9559. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9560. (when (and org-agenda-move-date-from-past-immediately-to-today
  9561. (equal arg 1)
  9562. (or (not what) (eq what 'day))
  9563. (not (save-match-data (org-at-date-range-p))))
  9564. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9565. cdate (calendar-absolute-from-gregorian
  9566. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9567. today (org-today))
  9568. (when (> today cdate)
  9569. ;; immediately shift to today
  9570. (setq arg (- today cdate))))
  9571. (org-timestamp-change arg (or what 'day))
  9572. (when (and (org-at-date-range-p)
  9573. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9574. (let ((end org-last-changed-timestamp))
  9575. (org-timestamp-change arg (or what 'day))
  9576. (setq org-last-changed-timestamp
  9577. (concat org-last-changed-timestamp "--" end)))))
  9578. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9579. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9580. (defun org-agenda-date-earlier (arg &optional what)
  9581. "Change the date of this item to ARG day(s) earlier."
  9582. (interactive "p")
  9583. (org-agenda-date-later (- arg) what))
  9584. (defun org-agenda-date-later-minutes (arg)
  9585. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9586. (interactive "p")
  9587. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9588. (org-agenda-date-later arg 'minute))
  9589. (defun org-agenda-date-earlier-minutes (arg)
  9590. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9591. (interactive "p")
  9592. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9593. (org-agenda-date-earlier arg 'minute))
  9594. (defun org-agenda-date-later-hours (arg)
  9595. "Change the time of this item, in hour steps."
  9596. (interactive "p")
  9597. (org-agenda-date-later arg 'hour))
  9598. (defun org-agenda-date-earlier-hours (arg)
  9599. "Change the time of this item, in hour steps."
  9600. (interactive "p")
  9601. (org-agenda-date-earlier arg 'hour))
  9602. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9603. "Show new date stamp via text properties."
  9604. ;; We use text properties to make this undoable
  9605. (let ((inhibit-read-only t))
  9606. (setq stamp (concat prefix " => " stamp " "))
  9607. (save-excursion
  9608. (goto-char (point-max))
  9609. (while (not (bobp))
  9610. (when (equal marker (org-get-at-bol 'org-marker))
  9611. (remove-text-properties (line-beginning-position)
  9612. (line-end-position)
  9613. '(display nil))
  9614. (org-move-to-column
  9615. (- (if (fboundp 'window-font-width)
  9616. (/ (window-width nil t) (window-font-width))
  9617. ;; Fall back to pre-9.3.3 behavior on Emacs <25.
  9618. (window-width))
  9619. (length stamp))
  9620. t)
  9621. (add-text-properties
  9622. (1- (point)) (point-at-eol)
  9623. (list 'display (org-add-props stamp nil
  9624. 'face '(secondary-selection default))))
  9625. (beginning-of-line 1))
  9626. (beginning-of-line 0)))))
  9627. (defun org-agenda-date-prompt (arg)
  9628. "Change the date of this item. Date is prompted for, with default today.
  9629. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9630. be used to request time specification in the time stamp."
  9631. (interactive "P")
  9632. (org-agenda-check-type t 'agenda)
  9633. (org-agenda-check-no-diary)
  9634. (org-agenda-maybe-loop
  9635. #'org-agenda-date-prompt arg t nil
  9636. (let* ((marker (or (org-get-at-bol 'org-marker)
  9637. (org-agenda-error)))
  9638. (buffer (marker-buffer marker))
  9639. (pos (marker-position marker)))
  9640. (org-with-remote-undo buffer
  9641. (with-current-buffer buffer
  9642. (widen)
  9643. (goto-char pos)
  9644. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9645. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9646. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9647. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9648. (defun org-agenda-schedule (arg &optional time)
  9649. "Schedule the item at point.
  9650. ARG is passed through to `org-schedule'."
  9651. (interactive "P")
  9652. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9653. (org-agenda-check-no-diary)
  9654. (org-agenda-maybe-loop
  9655. #'org-agenda-schedule arg t nil
  9656. (let* ((marker (or (org-get-at-bol 'org-marker)
  9657. (org-agenda-error)))
  9658. ;; (type (marker-insertion-type marker))
  9659. (buffer (marker-buffer marker))
  9660. (pos (marker-position marker))
  9661. ts)
  9662. (set-marker-insertion-type marker t)
  9663. (org-with-remote-undo buffer
  9664. (with-current-buffer buffer
  9665. (widen)
  9666. (goto-char pos)
  9667. (setq ts (org-schedule arg time)))
  9668. (org-agenda-show-new-time marker ts " S"))
  9669. (message "%s" ts))))
  9670. (defun org-agenda-deadline (arg &optional time)
  9671. "Schedule the item at point.
  9672. ARG is passed through to `org-deadline'."
  9673. (interactive "P")
  9674. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9675. (org-agenda-check-no-diary)
  9676. (org-agenda-maybe-loop
  9677. #'org-agenda-deadline arg t nil
  9678. (let* ((marker (or (org-get-at-bol 'org-marker)
  9679. (org-agenda-error)))
  9680. (buffer (marker-buffer marker))
  9681. (pos (marker-position marker))
  9682. ts)
  9683. (org-with-remote-undo buffer
  9684. (with-current-buffer buffer
  9685. (widen)
  9686. (goto-char pos)
  9687. (setq ts (org-deadline arg time)))
  9688. (org-agenda-show-new-time marker ts " D"))
  9689. (message "%s" ts))))
  9690. (defun org-agenda-clock-in (&optional arg)
  9691. "Start the clock on the currently selected item."
  9692. (interactive "P")
  9693. (org-agenda-check-no-diary)
  9694. (if (equal arg '(4))
  9695. (org-clock-in arg)
  9696. (let* ((marker (or (org-get-at-bol 'org-marker)
  9697. (org-agenda-error)))
  9698. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9699. (pos (marker-position marker))
  9700. (col (current-column))
  9701. newhead)
  9702. (org-with-remote-undo (marker-buffer marker)
  9703. (with-current-buffer (marker-buffer marker)
  9704. (widen)
  9705. (goto-char pos)
  9706. (org-show-context 'agenda)
  9707. (org-clock-in arg)
  9708. (setq newhead (org-get-heading)))
  9709. (org-agenda-change-all-lines newhead hdmarker))
  9710. (org-move-to-column col))))
  9711. (defun org-agenda-clock-out ()
  9712. "Stop the currently running clock."
  9713. (interactive)
  9714. (unless (marker-buffer org-clock-marker)
  9715. (user-error "No running clock"))
  9716. (let ((marker (make-marker)) (col (current-column)) newhead)
  9717. (org-with-remote-undo (marker-buffer org-clock-marker)
  9718. (with-current-buffer (marker-buffer org-clock-marker)
  9719. (org-with-wide-buffer
  9720. (goto-char org-clock-marker)
  9721. (org-back-to-heading t)
  9722. (move-marker marker (point))
  9723. (org-clock-out)
  9724. (setq newhead (org-get-heading)))))
  9725. (org-agenda-change-all-lines newhead marker)
  9726. (move-marker marker nil)
  9727. (org-move-to-column col)
  9728. (org-agenda-unmark-clocking-task)))
  9729. (defun org-agenda-clock-cancel (&optional _arg)
  9730. "Cancel the currently running clock."
  9731. (interactive) ;; "P"
  9732. (unless (marker-buffer org-clock-marker)
  9733. (user-error "No running clock"))
  9734. (org-with-remote-undo (marker-buffer org-clock-marker)
  9735. (org-clock-cancel)))
  9736. (defun org-agenda-clock-goto ()
  9737. "Jump to the currently clocked in task within the agenda.
  9738. If the currently clocked in task is not listed in the agenda
  9739. buffer, display it in another window."
  9740. (interactive)
  9741. (let (pos)
  9742. (mapc (lambda (o)
  9743. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9744. (setq pos (overlay-start o))))
  9745. (overlays-in (point-min) (point-max)))
  9746. (cond (pos (goto-char pos))
  9747. ;; If the currently clocked entry is not in the agenda
  9748. ;; buffer, we visit it in another window:
  9749. ((bound-and-true-p org-clock-current-task)
  9750. (org-switch-to-buffer-other-window (org-clock-goto)))
  9751. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9752. (defun org-agenda-diary-entry-in-org-file ()
  9753. "Make a diary entry in the file `org-agenda-diary-file'."
  9754. (let (d1 d2 char (text "") dp1 dp2)
  9755. (if (equal (buffer-name) "*Calendar*")
  9756. (setq d1 (calendar-cursor-to-date t)
  9757. d2 (car calendar-mark-ring))
  9758. (setq dp1 (get-text-property (point-at-bol) 'day))
  9759. (unless dp1 (user-error "No date defined in current line"))
  9760. (setq d1 (calendar-gregorian-from-absolute dp1)
  9761. d2 (and (ignore-errors (mark))
  9762. (save-excursion
  9763. (goto-char (mark))
  9764. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9765. (calendar-gregorian-from-absolute dp2))))
  9766. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9767. (setq char (read-char-exclusive))
  9768. (cond
  9769. ((equal char ?d)
  9770. (setq text (read-string "Day entry: "))
  9771. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9772. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9773. ((equal char ?a)
  9774. (setq d1 (list (car d1) (nth 1 d1)
  9775. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9776. (nth 2 d1))))
  9777. (setq text (read-string "Anniversary (use %d to show years): "))
  9778. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9779. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9780. ((equal char ?b)
  9781. (setq text (read-string "Block entry: "))
  9782. (unless (and d1 d2 (not (equal d1 d2)))
  9783. (user-error "No block of days selected"))
  9784. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9785. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9786. ((equal char ?j)
  9787. (org-switch-to-buffer-other-window
  9788. (find-file-noselect org-agenda-diary-file))
  9789. (require 'org-datetree)
  9790. (org-datetree-find-date-create d1)
  9791. (org-reveal t))
  9792. (t (user-error "Invalid selection character `%c'" char)))))
  9793. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9794. "Where in `org-agenda-diary-file' should new entries be added?
  9795. Valid values:
  9796. date-tree in the date tree, as first child of the date
  9797. date-tree-last in the date tree, as last child of the date
  9798. top-level as top-level entries at the end of the file."
  9799. :group 'org-agenda
  9800. :type '(choice
  9801. (const :tag "first in a date tree" date-tree)
  9802. (const :tag "last in a date tree" date-tree-last)
  9803. (const :tag "as top level at end of file" top-level)))
  9804. (defcustom org-agenda-insert-diary-extract-time nil
  9805. "Non-nil means extract any time specification from the diary entry."
  9806. :group 'org-agenda
  9807. :version "24.1"
  9808. :type 'boolean)
  9809. (defcustom org-agenda-bulk-mark-char ">"
  9810. "A single-character string to be used as the bulk mark."
  9811. :group 'org-agenda
  9812. :version "24.1"
  9813. :type 'string)
  9814. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9815. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9816. If TEXT is not empty, it will become the headline of the new entry, and
  9817. the resulting entry will not be shown. When TEXT is empty, switch to
  9818. `org-agenda-diary-file' and let the user finish the entry there."
  9819. (let ((cw (current-window-configuration)))
  9820. (org-switch-to-buffer-other-window
  9821. (find-file-noselect org-agenda-diary-file))
  9822. (widen)
  9823. (goto-char (point-min))
  9824. (cl-case type
  9825. (anniversary
  9826. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9827. (progn
  9828. (or (org-at-heading-p t)
  9829. (progn
  9830. (outline-next-heading)
  9831. (insert "* Anniversaries\n\n")
  9832. (beginning-of-line -1)))))
  9833. (outline-next-heading)
  9834. (org-back-over-empty-lines)
  9835. (backward-char 1)
  9836. (insert "\n")
  9837. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9838. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9839. (day
  9840. (let ((org-prefix-has-time t)
  9841. (org-agenda-time-leading-zero t)
  9842. fmt time time2)
  9843. (when org-agenda-insert-diary-extract-time
  9844. ;; Use org-agenda-format-item to parse text for a time-range and
  9845. ;; remove it. FIXME: This is a hack, we should refactor
  9846. ;; that function to make time extraction available separately
  9847. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9848. time (get-text-property 0 'time fmt)
  9849. time2 (if (> (length time) 0)
  9850. ;; split-string removes trailing ...... if
  9851. ;; no end time given. First space
  9852. ;; separates time from date.
  9853. (concat " " (car (split-string time "\\.")))
  9854. nil)
  9855. text (get-text-property 0 'txt fmt)))
  9856. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9857. (org-agenda-insert-diary-as-top-level text)
  9858. (require 'org-datetree)
  9859. (org-datetree-find-date-create d1)
  9860. (org-agenda-insert-diary-make-new-entry text))
  9861. (org-insert-time-stamp (org-time-from-absolute
  9862. (calendar-absolute-from-gregorian d1))
  9863. nil nil nil nil time2))
  9864. (end-of-line 0))
  9865. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9866. ;; otherwise the indentation gets confused by the
  9867. ;; special meaning of 'block
  9868. (when (> (calendar-absolute-from-gregorian d1)
  9869. (calendar-absolute-from-gregorian d2))
  9870. (setq d1 (prog1 d2 (setq d2 d1))))
  9871. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9872. (org-agenda-insert-diary-as-top-level text)
  9873. (require 'org-datetree)
  9874. (org-datetree-find-date-create d1)
  9875. (org-agenda-insert-diary-make-new-entry text))
  9876. (org-insert-time-stamp (org-time-from-absolute
  9877. (calendar-absolute-from-gregorian d1)))
  9878. (insert "--")
  9879. (org-insert-time-stamp (org-time-from-absolute
  9880. (calendar-absolute-from-gregorian d2)))
  9881. (end-of-line 0)))
  9882. (if (string-match "\\S-" text)
  9883. (progn
  9884. (set-window-configuration cw)
  9885. (message "%s entry added to %s"
  9886. (capitalize (symbol-name type))
  9887. (abbreviate-file-name org-agenda-diary-file)))
  9888. (org-reveal t)
  9889. (message "Please finish entry here"))))
  9890. (defun org-agenda-insert-diary-as-top-level (text)
  9891. "Make new entry as a top-level entry at the end of the file.
  9892. Add TEXT as headline, and position the cursor in the second line so that
  9893. a timestamp can be added there."
  9894. (widen)
  9895. (goto-char (point-max))
  9896. (unless (bolp) (insert "\n"))
  9897. (org-insert-heading nil t t)
  9898. (insert text)
  9899. (org-end-of-meta-data)
  9900. (unless (bolp) (insert "\n"))
  9901. (when org-adapt-indentation (indent-to-column 2)))
  9902. (defun org-agenda-insert-diary-make-new-entry (text)
  9903. "Make a new entry with TEXT as a child of the current subtree.
  9904. Position the point in the heading's first body line so that
  9905. a timestamp can be added there."
  9906. (cond
  9907. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9908. (end-of-line)
  9909. (org-insert-heading '(4) t)
  9910. (org-do-demote))
  9911. (t
  9912. (outline-next-heading)
  9913. (org-back-over-empty-lines)
  9914. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9915. (org-insert-heading nil t)
  9916. (org-do-demote)))
  9917. (let ((col (current-column)))
  9918. (insert text)
  9919. (org-end-of-meta-data)
  9920. ;; Ensure point is left on a blank line, at proper indentation.
  9921. (unless (bolp) (insert "\n"))
  9922. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9923. (when org-adapt-indentation (indent-to-column col)))
  9924. (org-show-set-visibility 'lineage))
  9925. (defun org-agenda-diary-entry ()
  9926. "Make a diary entry, like the `i' command from the calendar.
  9927. All the standard commands work: block, weekly etc.
  9928. When `org-agenda-diary-file' points to a file,
  9929. `org-agenda-diary-entry-in-org-file' is called instead to create
  9930. entries in that Org file."
  9931. (interactive)
  9932. (if (not (eq org-agenda-diary-file 'diary-file))
  9933. (org-agenda-diary-entry-in-org-file)
  9934. (require 'diary-lib)
  9935. (let* ((char (read-char-exclusive
  9936. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9937. [a]nniversary [b]lock [c]yclic"))
  9938. (cmd (cdr (assoc char
  9939. '((?d . diary-insert-entry)
  9940. (?w . diary-insert-weekly-entry)
  9941. (?m . diary-insert-monthly-entry)
  9942. (?y . diary-insert-yearly-entry)
  9943. (?a . diary-insert-anniversary-entry)
  9944. (?b . diary-insert-block-entry)
  9945. (?c . diary-insert-cyclic-entry)))))
  9946. (oldf (symbol-function 'calendar-cursor-to-date))
  9947. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9948. (point (point))
  9949. (mark (or (mark t) (point))))
  9950. (unless cmd
  9951. (user-error "No command associated with <%c>" char))
  9952. (unless (and (get-text-property point 'day)
  9953. (or (not (equal ?b char))
  9954. (get-text-property mark 'day)))
  9955. (user-error "Don't know which date to use for diary entry"))
  9956. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9957. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9958. (let ((calendar-mark-ring
  9959. (list (calendar-gregorian-from-absolute
  9960. (or (get-text-property mark 'day)
  9961. (get-text-property point 'day))))))
  9962. (unwind-protect
  9963. (progn
  9964. (fset 'calendar-cursor-to-date
  9965. (lambda (&optional _error _dummy)
  9966. (calendar-gregorian-from-absolute
  9967. (get-text-property point 'day))))
  9968. (call-interactively cmd))
  9969. (fset 'calendar-cursor-to-date oldf))))))
  9970. (defun org-agenda-execute-calendar-command (cmd)
  9971. "Execute a calendar command from the agenda with date from cursor."
  9972. (org-agenda-check-type t 'agenda)
  9973. (require 'diary-lib)
  9974. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9975. (user-error "Don't know which date to use for the calendar command"))
  9976. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9977. (point (point))
  9978. (date (calendar-gregorian-from-absolute
  9979. (get-text-property point 'day))))
  9980. ;; the following 2 vars are needed in the calendar
  9981. (org-dlet
  9982. ((displayed-month (car date))
  9983. (displayed-year (nth 2 date)))
  9984. (unwind-protect
  9985. (progn
  9986. (fset 'calendar-cursor-to-date
  9987. (lambda (&optional _error _dummy)
  9988. (calendar-gregorian-from-absolute
  9989. (get-text-property point 'day))))
  9990. (call-interactively cmd))
  9991. (fset 'calendar-cursor-to-date oldf)))))
  9992. (defun org-agenda-phases-of-moon ()
  9993. "Display the phases of the moon for the 3 months around the cursor date."
  9994. (interactive)
  9995. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9996. (defun org-agenda-holidays ()
  9997. "Display the holidays for the 3 months around the cursor date."
  9998. (interactive)
  9999. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10000. (defvar calendar-longitude) ; defined in calendar.el
  10001. (defvar calendar-latitude) ; defined in calendar.el
  10002. (defvar calendar-location-name) ; defined in calendar.el
  10003. (defun org-agenda-sunrise-sunset (arg)
  10004. "Display sunrise and sunset for the cursor date.
  10005. Latitude and longitude can be specified with the variables
  10006. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10007. argument, latitude and longitude will be prompted for."
  10008. (interactive "P")
  10009. (require 'solar)
  10010. (let ((calendar-longitude (if arg nil calendar-longitude))
  10011. (calendar-latitude (if arg nil calendar-latitude))
  10012. (calendar-location-name
  10013. (if arg "the given coordinates" calendar-location-name)))
  10014. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10015. (defun org-agenda-goto-calendar ()
  10016. "Open the Emacs calendar with the date at the cursor."
  10017. (interactive)
  10018. (org-agenda-check-type t 'agenda)
  10019. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10020. (user-error "Don't know which date to open in calendar")))
  10021. (date (calendar-gregorian-from-absolute day))
  10022. (calendar-move-hook nil)
  10023. (calendar-view-holidays-initially-flag nil)
  10024. (calendar-view-diary-initially-flag nil))
  10025. (calendar)
  10026. (calendar-goto-date date)))
  10027. ;;;###autoload
  10028. (defun org-calendar-goto-agenda ()
  10029. "Compute the Org agenda for the calendar date displayed at the cursor.
  10030. This is a command that has to be installed in `calendar-mode-map'."
  10031. (interactive)
  10032. ;; Temporarily disable sticky agenda since user clearly wants to
  10033. ;; refresh view anyway.
  10034. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10035. (org-agenda-sticky nil))
  10036. (org-agenda-list nil (calendar-absolute-from-gregorian
  10037. (calendar-cursor-to-date))
  10038. nil)))
  10039. (defun org-agenda-convert-date ()
  10040. (interactive)
  10041. (org-agenda-check-type t 'agenda)
  10042. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10043. date s)
  10044. (unless day
  10045. (user-error "Don't know which date to convert"))
  10046. (setq date (calendar-gregorian-from-absolute day))
  10047. (setq s (concat
  10048. "Gregorian: " (calendar-date-string date) "\n"
  10049. "ISO: " (calendar-iso-date-string date) "\n"
  10050. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10051. "Julian: " (calendar-julian-date-string date) "\n"
  10052. "Astron. JD: " (calendar-astro-date-string date)
  10053. " (Julian date number at noon UTC)\n"
  10054. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10055. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10056. "French: " (calendar-french-date-string date) "\n"
  10057. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10058. "Mayan: " (calendar-mayan-date-string date) "\n"
  10059. "Coptic: " (calendar-coptic-date-string date) "\n"
  10060. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10061. "Persian: " (calendar-persian-date-string date) "\n"
  10062. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10063. (with-output-to-temp-buffer "*Dates*"
  10064. (princ s))
  10065. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10066. ;;; Bulk commands
  10067. (defun org-agenda-bulk-marked-p ()
  10068. "Non-nil when current entry is marked for bulk action."
  10069. (eq (get-char-property (point-at-bol) 'type)
  10070. 'org-marked-entry-overlay))
  10071. (defun org-agenda-bulk-mark (&optional arg)
  10072. "Mark entries for future bulk action.
  10073. When ARG is nil or one and region is not active then mark the
  10074. entry at point.
  10075. When ARG is nil or one and region is active then mark the entries
  10076. in the region.
  10077. When ARG is greater than one mark ARG lines."
  10078. (interactive "p")
  10079. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10080. (setq arg (count-lines (region-beginning) (region-end)))
  10081. (goto-char (region-beginning))
  10082. (deactivate-mark))
  10083. (dotimes (_ (or arg 1))
  10084. (unless (org-get-at-bol 'org-agenda-diary-link)
  10085. (let* ((m (org-get-at-bol 'org-hd-marker))
  10086. ov)
  10087. (unless (org-agenda-bulk-marked-p)
  10088. (unless m (user-error "Nothing to mark at point"))
  10089. (push m org-agenda-bulk-marked-entries)
  10090. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10091. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10092. (org-get-todo-face "TODO")
  10093. 'evaporate)
  10094. (overlay-put ov 'type 'org-marked-entry-overlay))
  10095. (end-of-line 1)
  10096. (or (ignore-errors
  10097. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10098. (beginning-of-line 2))
  10099. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10100. (beginning-of-line 2)))))
  10101. (message "%d entries marked for bulk action"
  10102. (length org-agenda-bulk-marked-entries)))
  10103. (defun org-agenda-bulk-mark-all ()
  10104. "Mark all entries for future agenda bulk action."
  10105. (interactive)
  10106. (org-agenda-bulk-mark-regexp "."))
  10107. (defun org-agenda-bulk-mark-regexp (regexp)
  10108. "Mark entries matching REGEXP for future agenda bulk action."
  10109. (interactive "sMark entries matching regexp: ")
  10110. (let ((entries-marked 0) txt-at-point)
  10111. (save-excursion
  10112. (goto-char (point-min))
  10113. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10114. (while (and (re-search-forward regexp nil t)
  10115. (setq txt-at-point
  10116. (get-text-property (match-beginning 0) 'txt)))
  10117. (if (get-char-property (point) 'invisible)
  10118. (beginning-of-line 2)
  10119. (when (string-match-p regexp txt-at-point)
  10120. (setq entries-marked (1+ entries-marked))
  10121. (call-interactively 'org-agenda-bulk-mark)))))
  10122. (unless entries-marked
  10123. (message "No entry matching this regexp."))))
  10124. (defun org-agenda-bulk-unmark (&optional arg)
  10125. "Unmark the entry at point for future bulk action."
  10126. (interactive "P")
  10127. (if arg
  10128. (org-agenda-bulk-unmark-all)
  10129. (cond ((org-agenda-bulk-marked-p)
  10130. (org-agenda-bulk-remove-overlays
  10131. (point-at-bol) (+ 2 (point-at-bol)))
  10132. (setq org-agenda-bulk-marked-entries
  10133. (delete (org-get-at-bol 'org-hd-marker)
  10134. org-agenda-bulk-marked-entries))
  10135. (end-of-line 1)
  10136. (or (ignore-errors
  10137. (goto-char (next-single-property-change (point) 'txt)))
  10138. (beginning-of-line 2))
  10139. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10140. (beginning-of-line 2))
  10141. (message "%d entries left marked for bulk action"
  10142. (length org-agenda-bulk-marked-entries)))
  10143. (t (message "No entry to unmark here")))))
  10144. (defun org-agenda-bulk-toggle-all ()
  10145. "Toggle all marks for bulk action."
  10146. (interactive)
  10147. (save-excursion
  10148. (goto-char (point-min))
  10149. (while (ignore-errors
  10150. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10151. (org-agenda-bulk-toggle))))
  10152. (defun org-agenda-bulk-toggle ()
  10153. "Toggle the mark at point for bulk action."
  10154. (interactive)
  10155. (if (org-agenda-bulk-marked-p)
  10156. (org-agenda-bulk-unmark)
  10157. (org-agenda-bulk-mark)))
  10158. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10159. "Remove the mark overlays between BEG and END in the agenda buffer.
  10160. BEG and END default to the buffer limits.
  10161. This only removes the overlays, it does not remove the markers
  10162. from the list in `org-agenda-bulk-marked-entries'."
  10163. (interactive)
  10164. (mapc (lambda (ov)
  10165. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10166. (delete-overlay ov)))
  10167. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10168. (defun org-agenda-bulk-unmark-all ()
  10169. "Remove all marks in the agenda buffer.
  10170. This will remove the markers and the overlays."
  10171. (interactive)
  10172. (if (null org-agenda-bulk-marked-entries)
  10173. (message "No entry to unmark")
  10174. (setq org-agenda-bulk-marked-entries nil)
  10175. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10176. (defcustom org-agenda-persistent-marks nil
  10177. "Non-nil means marked items will stay marked after a bulk action.
  10178. You can toggle this interactively by typing `p' when prompted for a
  10179. bulk action."
  10180. :group 'org-agenda
  10181. :version "24.1"
  10182. :type 'boolean)
  10183. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10184. "Shall some commands act upon headlines in the active region?
  10185. When set to t, some commands will be performed in all headlines
  10186. within the active region.
  10187. When set to `start-level', some commands will be performed in all
  10188. headlines within the active region, provided that these headlines
  10189. are of the same level than the first one.
  10190. When set to a regular expression, those commands will be
  10191. performed on the matching headlines within the active region.
  10192. The list of commands is: `org-agenda-schedule',
  10193. `org-agenda-deadline', `org-agenda-date-prompt',
  10194. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10195. See `org-loop-over-headlines-in-active-region' for the equivalent
  10196. option for Org buffers."
  10197. :type '(choice (const :tag "Don't loop" nil)
  10198. (const :tag "All headlines in active region" t)
  10199. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10200. (regexp :tag "Regular expression matcher"))
  10201. :version "27.1"
  10202. :package-version '(Org . "9.4")
  10203. :group 'org-agenda)
  10204. (defun org-agenda-bulk-action (&optional arg)
  10205. "Execute an remote-editing action on all marked entries.
  10206. The prefix arg is passed through to the command if possible."
  10207. (interactive "P")
  10208. ;; When there is no mark, act on the agenda entry at point.
  10209. (if (not org-agenda-bulk-marked-entries)
  10210. (save-excursion (org-agenda-bulk-mark)))
  10211. (dolist (m org-agenda-bulk-marked-entries)
  10212. (unless (and (markerp m)
  10213. (marker-buffer m)
  10214. (buffer-live-p (marker-buffer m))
  10215. (marker-position m))
  10216. (user-error "Marker %s for bulk command is invalid" m)))
  10217. ;; Prompt for the bulk command.
  10218. (org-unlogged-message
  10219. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10220. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10221. "[S]catter [f]unction "
  10222. (and org-agenda-bulk-custom-functions
  10223. (format " Custom: [%s]"
  10224. (mapconcat (lambda (f) (char-to-string (car f)))
  10225. org-agenda-bulk-custom-functions
  10226. "")))))
  10227. (catch 'exit
  10228. (let* ((org-log-refile (if org-log-refile 'time nil))
  10229. (entries (reverse org-agenda-bulk-marked-entries))
  10230. (org-overriding-default-time
  10231. (and (get-text-property (point) 'org-agenda-date-header)
  10232. (org-get-cursor-date)))
  10233. redo-at-end
  10234. cmd)
  10235. (pcase (read-char-exclusive)
  10236. (?p
  10237. (let ((org-agenda-persistent-marks
  10238. (not org-agenda-persistent-marks)))
  10239. (org-agenda-bulk-action)
  10240. (throw 'exit nil)))
  10241. (?$
  10242. (setq cmd #'org-agenda-archive))
  10243. (?A
  10244. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10245. ((or ?r ?w)
  10246. (let ((refile-location
  10247. (org-refile-get-location
  10248. "Refile to"
  10249. (marker-buffer (car entries))
  10250. org-refile-allow-creating-parent-nodes)))
  10251. (when (nth 3 refile-location)
  10252. (setcar (nthcdr 3 refile-location)
  10253. (move-marker
  10254. (make-marker)
  10255. (nth 3 refile-location)
  10256. (or (get-file-buffer (nth 1 refile-location))
  10257. (find-buffer-visiting (nth 1 refile-location))
  10258. (error "This should not happen")))))
  10259. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10260. (setq redo-at-end t)))
  10261. (?t
  10262. (let ((state (completing-read
  10263. "Todo state: "
  10264. (with-current-buffer (marker-buffer (car entries))
  10265. (mapcar #'list org-todo-keywords-1)))))
  10266. (setq cmd (lambda ()
  10267. (let ((org-inhibit-blocking t)
  10268. (org-inhibit-logging 'note))
  10269. (org-agenda-todo state))))))
  10270. ((and (or ?- ?+) action)
  10271. (let ((tag (completing-read
  10272. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10273. (with-current-buffer (marker-buffer (car entries))
  10274. (delq nil
  10275. (mapcar (lambda (x) (and (stringp (car x)) x))
  10276. org-current-tag-alist))))))
  10277. (setq cmd
  10278. (lambda ()
  10279. (org-agenda-set-tags tag
  10280. (if (eq action ?+) 'on 'off))))))
  10281. ((and (or ?s ?d) c)
  10282. (let* ((schedule? (eq c ?s))
  10283. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10284. (time
  10285. (and (not arg)
  10286. (let ((new (org-read-date
  10287. nil nil nil prompt org-overriding-default-time)))
  10288. ;; A "double plus" answer applies to every
  10289. ;; scheduled time. Do not turn it into
  10290. ;; a fixed date yet.
  10291. (if (string-match-p "\\`[ \t]*\\+\\+"
  10292. org-read-date-final-answer)
  10293. org-read-date-final-answer
  10294. new)))))
  10295. ;; Make sure to not prompt for a note when bulk
  10296. ;; rescheduling/resetting deadline as Org cannot cope with
  10297. ;; simultaneous notes. Besides, it could be annoying
  10298. ;; depending on the number of marked items.
  10299. (setq cmd
  10300. (if schedule?
  10301. (lambda ()
  10302. (let ((org-log-reschedule
  10303. (and org-log-reschedule 'time)))
  10304. (org-agenda-schedule arg time)))
  10305. (lambda ()
  10306. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10307. (org-agenda-deadline arg time)))))))
  10308. (?S
  10309. (unless (org-agenda-check-type nil 'agenda 'todo)
  10310. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10311. (let ((days (read-number
  10312. (format "Scatter tasks across how many %sdays: "
  10313. (if arg "week" ""))
  10314. 7)))
  10315. (setq cmd
  10316. (lambda ()
  10317. (let ((distance (1+ (random days))))
  10318. (when arg
  10319. (let ((dist distance)
  10320. (day-of-week
  10321. (calendar-day-of-week
  10322. (calendar-gregorian-from-absolute (org-today)))))
  10323. (dotimes (_ (1+ dist))
  10324. (while (member day-of-week org-agenda-weekend-days)
  10325. (cl-incf distance)
  10326. (cl-incf day-of-week)
  10327. (when (= day-of-week 7)
  10328. (setq day-of-week 0)))
  10329. (cl-incf day-of-week)
  10330. (when (= day-of-week 7)
  10331. (setq day-of-week 0)))))
  10332. ;; Silently fail when try to replan a sexp entry.
  10333. (ignore-errors
  10334. (let* ((date (calendar-gregorian-from-absolute
  10335. (+ (org-today) distance)))
  10336. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  10337. (nth 2 date))))
  10338. (org-agenda-schedule nil time))))))))
  10339. (?f
  10340. (setq cmd
  10341. (intern
  10342. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10343. (action
  10344. (setq cmd
  10345. (pcase (assoc action org-agenda-bulk-custom-functions)
  10346. (`(,_ ,fn)
  10347. fn)
  10348. (`(,_ ,fn ,arg-fn)
  10349. (apply #'apply-partially fn (funcall arg-fn)))
  10350. (_
  10351. (user-error "Invalid bulk action: %c" action))))
  10352. (setq redo-at-end t)))
  10353. ;; Sort the markers, to make sure that parents are handled
  10354. ;; before children.
  10355. (setq entries (sort entries
  10356. (lambda (a b)
  10357. (cond
  10358. ((eq (marker-buffer a) (marker-buffer b))
  10359. (< (marker-position a) (marker-position b)))
  10360. (t
  10361. (string< (buffer-name (marker-buffer a))
  10362. (buffer-name (marker-buffer b))))))))
  10363. ;; Now loop over all markers and apply CMD.
  10364. (let ((processed 0)
  10365. (skipped 0))
  10366. (dolist (e entries)
  10367. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10368. (if (not pos)
  10369. (progn (message "Skipping removed entry at %s" e)
  10370. (cl-incf skipped))
  10371. (goto-char pos)
  10372. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10373. ;; `post-command-hook' is not run yet. We make sure any
  10374. ;; pending log note is processed.
  10375. (when org-log-setup (org-add-log-note))
  10376. (cl-incf processed))))
  10377. (when redo-at-end (org-agenda-redo))
  10378. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10379. (message "Acted on %d entries%s%s"
  10380. processed
  10381. (if (= skipped 0)
  10382. ""
  10383. (format ", skipped %d (disappeared before their turn)"
  10384. skipped))
  10385. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10386. (defun org-agenda-capture (&optional with-time)
  10387. "Call `org-capture' with the date at point.
  10388. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10389. current HH:MM time."
  10390. (interactive "P")
  10391. (if (not (eq major-mode 'org-agenda-mode))
  10392. (user-error "You cannot do this outside of agenda buffers")
  10393. (let ((org-overriding-default-time
  10394. (org-get-cursor-date (equal with-time 1))))
  10395. (call-interactively 'org-capture))))
  10396. ;;; Dragging agenda lines forward/backward
  10397. (defun org-agenda-reapply-filters ()
  10398. "Re-apply all agenda filters."
  10399. (mapcar
  10400. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10401. `((,org-agenda-tag-filter tag)
  10402. (,org-agenda-category-filter category)
  10403. (,org-agenda-regexp-filter regexp)
  10404. (,org-agenda-effort-filter effort)
  10405. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10406. (,(get 'org-agenda-category-filter :preset-filter) category)
  10407. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10408. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10409. (defun org-agenda-drag-line-forward (arg &optional backward)
  10410. "Drag an agenda line forward by ARG lines.
  10411. When the optional argument `backward' is non-nil, move backward."
  10412. (interactive "p")
  10413. (let ((inhibit-read-only t) lst line)
  10414. (if (or (not (get-text-property (point) 'txt))
  10415. (save-excursion
  10416. (dotimes (_ arg)
  10417. (move-beginning-of-line (if backward 0 2))
  10418. (push (not (get-text-property (point) 'txt)) lst))
  10419. (delq nil lst)))
  10420. (message "Cannot move line forward")
  10421. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10422. (move-beginning-of-line 1)
  10423. (setq line (buffer-substring (point) end))
  10424. (delete-region (point) end)
  10425. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10426. (insert line)
  10427. (org-agenda-reapply-filters)
  10428. (org-agenda-mark-clocking-task)
  10429. (move-beginning-of-line 0)))))
  10430. (defun org-agenda-drag-line-backward (arg)
  10431. "Drag an agenda line backward by ARG lines."
  10432. (interactive "p")
  10433. (org-agenda-drag-line-forward arg t))
  10434. ;;; Flagging notes
  10435. (defun org-agenda-show-the-flagging-note ()
  10436. "Display the flagging note in the other window.
  10437. When called a second time in direct sequence, offer to remove the FLAGGING
  10438. tag and (if present) the flagging note."
  10439. (interactive)
  10440. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10441. (win (selected-window))
  10442. note) ;; heading newhead
  10443. (unless hdmarker
  10444. (user-error "No linked entry at point"))
  10445. (if (and (eq this-command last-command)
  10446. (y-or-n-p "Unflag and remove any flagging note? "))
  10447. (progn
  10448. (org-agenda-remove-flag hdmarker)
  10449. (let ((win (get-buffer-window "*Flagging Note*")))
  10450. (and win (delete-window win)))
  10451. (message "Entry unflagged"))
  10452. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10453. (unless note
  10454. (user-error "No flagging note"))
  10455. (org-kill-new note)
  10456. (org-switch-to-buffer-other-window "*Flagging Note*")
  10457. (erase-buffer)
  10458. (insert note)
  10459. (goto-char (point-min))
  10460. (while (re-search-forward "\\\\n" nil t)
  10461. (replace-match "\n" t t))
  10462. (goto-char (point-min))
  10463. (select-window win)
  10464. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10465. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10466. tag and note")))))
  10467. (defun org-agenda-remove-flag (marker)
  10468. "Remove the FLAGGED tag and any flagging note in the entry."
  10469. (let ((newhead
  10470. (org-with-point-at marker
  10471. (org-toggle-tag "FLAGGED" 'off)
  10472. (org-entry-delete nil "THEFLAGGINGNOTE")
  10473. (org-get-heading))))
  10474. (org-agenda-change-all-lines newhead marker)
  10475. (message "Entry unflagged")))
  10476. (defun org-agenda-get-any-marker (&optional pos)
  10477. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10478. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10479. ;;; Appointment reminders
  10480. (defvar appt-time-msg-list) ; defined in appt.el
  10481. ;;;###autoload
  10482. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10483. "Activate appointments found in `org-agenda-files'.
  10484. With a `\\[universal-argument]' prefix, refresh the list of \
  10485. appointments.
  10486. If FILTER is t, interactively prompt the user for a regular
  10487. expression, and filter out entries that don't match it.
  10488. If FILTER is a string, use this string as a regular expression
  10489. for filtering entries out.
  10490. If FILTER is a function, filter out entries against which
  10491. calling the function returns nil. This function takes one
  10492. argument: an entry from `org-agenda-get-day-entries'.
  10493. FILTER can also be an alist with the car of each cell being
  10494. either `headline' or `category'. For example:
  10495. \\='((headline \"IMPORTANT\")
  10496. (category \"Work\"))
  10497. will only add headlines containing IMPORTANT or headlines
  10498. belonging to the \"Work\" category.
  10499. ARGS are symbols indicating what kind of entries to consider.
  10500. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10501. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10502. and :timestamp entries. See the docstring of `org-diary' for
  10503. details and examples.
  10504. If an entry has a APPT_WARNTIME property, its value will be used
  10505. to override `appt-message-warning-time'."
  10506. (interactive "P")
  10507. (when refresh (setq appt-time-msg-list nil))
  10508. (when (eq filter t)
  10509. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10510. (let* ((cnt 0) ; count added events
  10511. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10512. (org-agenda-new-buffers nil)
  10513. (org-deadline-warning-days 0)
  10514. ;; Do not use `org-today' here because appt only takes
  10515. ;; time and without date as argument, so it may pass wrong
  10516. ;; information otherwise
  10517. (today (org-date-to-gregorian
  10518. (time-to-days nil)))
  10519. (org-agenda-restrict nil)
  10520. (files (org-agenda-files 'unrestricted)) entries file
  10521. (org-agenda-buffer nil))
  10522. ;; Get all entries which may contain an appt
  10523. (org-agenda-prepare-buffers files)
  10524. (while (setq file (pop files))
  10525. (setq entries
  10526. (delq nil
  10527. (append entries
  10528. (apply #'org-agenda-get-day-entries
  10529. file today scope)))))
  10530. ;; Map through entries and find if we should filter them out
  10531. (mapc
  10532. (lambda (x)
  10533. (let* ((evt (org-trim
  10534. (replace-regexp-in-string
  10535. org-link-bracket-re "\\2"
  10536. (or (get-text-property 1 'txt x) ""))))
  10537. (cat (get-text-property (1- (length x)) 'org-category x))
  10538. (tod (get-text-property 1 'time-of-day x))
  10539. (ok (or (null filter)
  10540. (and (stringp filter) (string-match filter evt))
  10541. (and (functionp filter) (funcall filter x))
  10542. (and (listp filter)
  10543. (let ((cat-filter (cadr (assq 'category filter)))
  10544. (evt-filter (cadr (assq 'headline filter))))
  10545. (or (and (stringp cat-filter)
  10546. (string-match cat-filter cat))
  10547. (and (stringp evt-filter)
  10548. (string-match evt-filter evt)))))))
  10549. (wrn (get-text-property 1 'warntime x)))
  10550. ;; FIXME: Shall we remove text-properties for the appt text?
  10551. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10552. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10553. (setq tod (concat "00" (number-to-string tod)))
  10554. (setq tod (when (string-match
  10555. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10556. (concat (match-string 1 tod) ":"
  10557. (match-string 2 tod))))
  10558. (when (appt-add tod evt wrn)
  10559. (setq cnt (1+ cnt))))))
  10560. entries)
  10561. (org-release-buffers org-agenda-new-buffers)
  10562. (if (eq cnt 0)
  10563. (message "No event to add")
  10564. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10565. (defun org-agenda-today-p (date)
  10566. "Non-nil when DATE means today.
  10567. DATE is either a list of the form (month day year) or a number of
  10568. days as returned by `calendar-absolute-from-gregorian' or
  10569. `org-today'. This function considers `org-extend-today-until'
  10570. when defining today."
  10571. (eq (org-today)
  10572. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10573. (defun org-agenda-todo-yesterday (&optional arg)
  10574. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10575. (interactive "P")
  10576. (let* ((org-use-effective-time t)
  10577. (hour (nth 2 (decode-time (org-current-time))))
  10578. (org-extend-today-until (1+ hour)))
  10579. (org-agenda-todo arg)))
  10580. (defun org-agenda-ctrl-c-ctrl-c ()
  10581. "Set tags in agenda buffer."
  10582. (interactive)
  10583. (org-agenda-set-tags))
  10584. (provide 'org-agenda)
  10585. ;;; org-agenda.el ends here