org-agenda.el 394 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2018 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  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 'org)
  43. (require 'org-macs)
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-columns-remove-overlays "org-colview" ())
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-agenda-columns "org-colview" ())
  74. (declare-function org-add-archive-files "org-archive" (files))
  75. (declare-function org-capture "org-capture" (&optional goto keys))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task)
  78. (defvar org-current-tag-alist)
  79. (defvar org-mobile-force-id-on-agenda-items)
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. \\='((ps-print-color-p \\='black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in a temporary buffer before writing the agenda to an export file.
  143. A useful function for this hook is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which is the default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style nil
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header."
  199. :group 'org-agenda-export
  200. :group 'org-export-html
  201. :type '(choice
  202. (const nil)
  203. (string)))
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const timestamp-up) (const timestamp-down)
  216. (const scheduled-up) (const scheduled-down)
  217. (const deadline-up) (const deadline-down)
  218. (const ts-up) (const ts-down)
  219. (const tsia-up) (const tsia-down)
  220. (const category-keep) (const category-up) (const category-down)
  221. (const tag-down) (const tag-up)
  222. (const priority-up) (const priority-down)
  223. (const todo-state-up) (const todo-state-down)
  224. (const effort-up) (const effort-down)
  225. (const habit-up) (const habit-down)
  226. (const alpha-up) (const alpha-down)
  227. (const user-defined-up) (const user-defined-down))
  228. "Sorting choices.")
  229. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  230. ;; the new variable `org-agenda-tag-filter-preset'.
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  233. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  234. "List of types searched for when creating the daily/weekly agenda.
  235. This variable is a list of symbols that controls the types of
  236. items that appear in the daily/weekly agenda. Allowed symbols in this
  237. list are are
  238. :timestamp List items containing a date stamp or date range matching
  239. the selected date. This includes sexp entries in angular
  240. brackets.
  241. :sexp List entries resulting from plain diary-like sexps.
  242. :deadline List deadline due on that date. When the date is today,
  243. also list any deadlines past due, or due within
  244. `org-deadline-warning-days'.
  245. :deadline* Same as above, but only include the deadline if it has an
  246. hour specification as [h]h:mm.
  247. :scheduled List all items which are scheduled for the given date.
  248. The diary for *today* also contains items which were
  249. scheduled earlier and are not yet marked DONE.
  250. :scheduled* Same as above, but only include the scheduled item if it
  251. has an hour specification as [h]h:mm.
  252. By default, all four non-starred types are turned on.
  253. When :scheduled* or :deadline* are included, :schedule or :deadline
  254. will be ignored.
  255. Never set this variable globally using `setq', because then it
  256. will apply to all future agenda commands. Instead, bind it with
  257. `let' to scope it dynamically into the agenda-constructing
  258. command. A good way to set it is through options in
  259. `org-agenda-custom-commands'. For a more flexible (though
  260. somewhat less efficient) way of determining what is included in
  261. the daily/weekly agenda, see `org-agenda-skip-function'.")
  262. (defconst org-agenda-custom-commands-local-options
  263. `(repeat :tag "Local settings for this command. Remember to quote values"
  264. (choice :tag "Setting"
  265. (list :tag "Heading for this block"
  266. (const org-agenda-overriding-header)
  267. (string :tag "Headline"))
  268. (list :tag "Files to be searched"
  269. (const org-agenda-files)
  270. (list
  271. (const :format "" quote)
  272. (repeat (file))))
  273. (list :tag "Sorting strategy"
  274. (const org-agenda-sorting-strategy)
  275. (list
  276. (const :format "" quote)
  277. (repeat
  278. ,org-sorting-choice)))
  279. (list :tag "Prefix format"
  280. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  281. (string))
  282. (list :tag "Number of days in agenda"
  283. (const org-agenda-span)
  284. (list
  285. (const :format "" quote)
  286. (choice (const :tag "Day" day)
  287. (const :tag "Week" week)
  288. (const :tag "Fortnight" fortnight)
  289. (const :tag "Month" month)
  290. (const :tag "Year" year)
  291. (integer :tag "Custom"))))
  292. (list :tag "Fixed starting date"
  293. (const org-agenda-start-day)
  294. (string :value "2007-11-01"))
  295. (list :tag "Start on day of week"
  296. (const org-agenda-start-on-weekday)
  297. (choice :value 1
  298. (const :tag "Today" nil)
  299. (integer :tag "Weekday No.")))
  300. (list :tag "Include data from diary"
  301. (const org-agenda-include-diary)
  302. (boolean))
  303. (list :tag "Deadline Warning days"
  304. (const org-deadline-warning-days)
  305. (integer :value 1))
  306. (list :tag "Category filter preset"
  307. (const org-agenda-category-filter-preset)
  308. (list
  309. (const :format "" quote)
  310. (repeat
  311. (string :tag "+category or -category"))))
  312. (list :tag "Tags filter preset"
  313. (const org-agenda-tag-filter-preset)
  314. (list
  315. (const :format "" quote)
  316. (repeat
  317. (string :tag "+tag or -tag"))))
  318. (list :tag "Effort filter preset"
  319. (const org-agenda-effort-filter-preset)
  320. (list
  321. (const :format "" quote)
  322. (repeat
  323. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  324. (list :tag "Regexp filter preset"
  325. (const org-agenda-regexp-filter-preset)
  326. (list
  327. (const :format "" quote)
  328. (repeat
  329. (string :tag "+regexp or -regexp"))))
  330. (list :tag "Set daily/weekly entry types"
  331. (const org-agenda-entry-types)
  332. (list
  333. (const :format "" quote)
  334. (set :greedy t :value ,org-agenda-entry-types
  335. (const :deadline)
  336. (const :scheduled)
  337. (const :deadline*)
  338. (const :scheduled*)
  339. (const :timestamp)
  340. (const :sexp))))
  341. (list :tag "Standard skipping condition"
  342. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  343. (const org-agenda-skip-function)
  344. (list
  345. (const :format "" quote)
  346. (list
  347. (choice
  348. :tag "Skipping range"
  349. (const :tag "Skip entry" org-agenda-skip-entry-if)
  350. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  351. (repeat :inline t :tag "Conditions for skipping"
  352. (choice
  353. :tag "Condition type"
  354. (list :tag "Regexp matches" :inline t
  355. (const :format "" regexp)
  356. (regexp))
  357. (list :tag "Regexp does not match" :inline t
  358. (const :format "" notregexp)
  359. (regexp))
  360. (list :tag "TODO state is" :inline t
  361. (const todo)
  362. (choice
  363. (const :tag "Any not-done state" todo)
  364. (const :tag "Any done state" done)
  365. (const :tag "Any state" any)
  366. (list :tag "Keyword list"
  367. (const :format "" quote)
  368. (repeat (string :tag "Keyword")))))
  369. (list :tag "TODO state is not" :inline t
  370. (const nottodo)
  371. (choice
  372. (const :tag "Any not-done state" todo)
  373. (const :tag "Any done state" done)
  374. (const :tag "Any state" any)
  375. (list :tag "Keyword list"
  376. (const :format "" quote)
  377. (repeat (string :tag "Keyword")))))
  378. (const :tag "scheduled" scheduled)
  379. (const :tag "not scheduled" notscheduled)
  380. (const :tag "deadline" deadline)
  381. (const :tag "no deadline" notdeadline)
  382. (const :tag "timestamp" timestamp)
  383. (const :tag "no timestamp" nottimestamp))))))
  384. (list :tag "Non-standard skipping condition"
  385. :value (org-agenda-skip-function)
  386. (const org-agenda-skip-function)
  387. (sexp :tag "Function or form (quoted!)"))
  388. (list :tag "Any variable"
  389. (variable :tag "Variable")
  390. (sexp :tag "Value (sexp)"))))
  391. "Selection of examples for agenda command settings.
  392. This will be spliced into the custom type of
  393. `org-agenda-custom-commands'.")
  394. (defcustom org-agenda-custom-commands
  395. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  396. "Custom commands for the agenda.
  397. \\<org-mode-map>
  398. These commands will be offered on the splash screen displayed by the
  399. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  400. (key desc type match settings files)
  401. key The key (one or more characters as a string) to be associated
  402. with the command.
  403. desc A description of the command, when omitted or nil, a default
  404. description is built using MATCH.
  405. type The command type, any of the following symbols:
  406. agenda The daily/weekly agenda.
  407. todo Entries with a specific TODO keyword, in all agenda files.
  408. search Entries containing search words entry or headline.
  409. tags Tags/Property/TODO match in all agenda files.
  410. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  411. todo-tree Sparse tree of specific TODO keyword in *current* file.
  412. tags-tree Sparse tree with all tags matches in *current* file.
  413. occur-tree Occur sparse tree for *current* file.
  414. ... A user-defined function.
  415. match What to search for:
  416. - a single keyword for TODO keyword searches
  417. - a tags match expression for tags searches
  418. - a word search expression for text searches.
  419. - a regular expression for occur searches
  420. For all other commands, this should be the empty string.
  421. settings A list of option settings, similar to that in a let form, so like
  422. this: ((opt1 val1) (opt2 val2) ...). The values will be
  423. evaluated at the moment of execution, so quote them when needed.
  424. files A list of files to write the produced agenda buffer to with
  425. the command `org-store-agenda-views'.
  426. If a file name ends in \".html\", an HTML version of the buffer
  427. is written out. If it ends in \".ps\", a postscript version is
  428. produced. Otherwise, only the plain text is written to the file.
  429. You can also define a set of commands, to create a composite agenda buffer.
  430. In this case, an entry looks like this:
  431. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  432. where
  433. desc A description string to be displayed in the dispatcher menu.
  434. cmd An agenda command, similar to the above. However, tree commands
  435. are not allowed, but instead you can get agenda and global todo list.
  436. So valid commands for a set are:
  437. (agenda \"\" settings)
  438. (alltodo \"\" settings)
  439. (stuck \"\" settings)
  440. (todo \"match\" settings files)
  441. (search \"match\" settings files)
  442. (tags \"match\" settings files)
  443. (tags-todo \"match\" settings files)
  444. Each command can carry a list of options, and another set of options can be
  445. given for the whole set of commands. Individual command options take
  446. precedence over the general options.
  447. When using several characters as key to a command, the first characters
  448. are prefix commands. For the dispatcher to display useful information, you
  449. should provide a description for the prefix, like
  450. (setq org-agenda-custom-commands
  451. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  452. (\"hl\" tags \"+HOME+Lisa\")
  453. (\"hp\" tags \"+HOME+Peter\")
  454. (\"hk\" tags \"+HOME+Kim\")))"
  455. :group 'org-agenda-custom-commands
  456. :type `(repeat
  457. (choice :value ("x" "Describe command here" tags "" nil)
  458. (list :tag "Single command"
  459. (string :tag "Access Key(s) ")
  460. (option (string :tag "Description"))
  461. (choice
  462. (const :tag "Agenda" agenda)
  463. (const :tag "TODO list" alltodo)
  464. (const :tag "Search words" search)
  465. (const :tag "Stuck projects" stuck)
  466. (const :tag "Tags/Property match (all agenda files)" tags)
  467. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  468. (const :tag "TODO keyword search (all agenda files)" todo)
  469. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  470. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  471. (const :tag "Occur tree (current buffer)" occur-tree)
  472. (sexp :tag "Other, user-defined function"))
  473. (string :tag "Match (only for some commands)")
  474. ,org-agenda-custom-commands-local-options
  475. (option (repeat :tag "Export" (file :tag "Export to"))))
  476. (list :tag "Command series, all agenda files"
  477. (string :tag "Access Key(s)")
  478. (string :tag "Description ")
  479. (repeat :tag "Component"
  480. (choice
  481. (list :tag "Agenda"
  482. (const :format "" agenda)
  483. (const :tag "" :format "" "")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "TODO list (all keywords)"
  486. (const :format "" alltodo)
  487. (const :tag "" :format "" "")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Search words"
  490. (const :format "" search)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "Stuck projects"
  494. (const :format "" stuck)
  495. (const :tag "" :format "" "")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "Tags search"
  498. (const :format "" tags)
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)
  501. (list :tag "Tags search, TODO entries only"
  502. (const :format "" tags-todo)
  503. (string :tag "Match")
  504. ,org-agenda-custom-commands-local-options)
  505. (list :tag "TODO keyword search"
  506. (const :format "" todo)
  507. (string :tag "Match")
  508. ,org-agenda-custom-commands-local-options)
  509. (list :tag "Other, user-defined function"
  510. (symbol :tag "function")
  511. (string :tag "Match")
  512. ,org-agenda-custom-commands-local-options)))
  513. (repeat :tag "Settings for entire command set"
  514. (list (variable :tag "Any variable")
  515. (sexp :tag "Value")))
  516. (option (repeat :tag "Export" (file :tag "Export to"))))
  517. (cons :tag "Prefix key documentation"
  518. (string :tag "Access Key(s)")
  519. (string :tag "Description ")))))
  520. (defcustom org-agenda-query-register ?o
  521. "The register holding the current query string.
  522. The purpose of this is that if you construct a query string interactively,
  523. you can then use it to define a custom command."
  524. :group 'org-agenda-custom-commands
  525. :type 'character)
  526. (defcustom org-stuck-projects
  527. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  528. "How to identify stuck projects.
  529. This is a list of four items:
  530. 1. A tags/todo/property matcher string that is used to identify a project.
  531. See the manual for a description of tag and property searches.
  532. The entire tree below a headline matched by this is considered one project.
  533. 2. A list of TODO keywords identifying non-stuck projects.
  534. If the project subtree contains any headline with one of these todo
  535. keywords, the project is considered to be not stuck. If you specify
  536. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  537. 3. A list of tags identifying non-stuck projects.
  538. If the project subtree contains any headline with one of these tags,
  539. the project is considered to be not stuck. If you specify \"*\" as
  540. a tag, any tag will mark the project unstuck. Note that this is about
  541. the explicit presence of a tag somewhere in the subtree, inherited
  542. tags do not count here. If inherited tags make a project not stuck,
  543. use \"-TAG\" in the tags part of the matcher under (1.) above.
  544. 4. An arbitrary regular expression matching non-stuck projects.
  545. If the project turns out to be not stuck, search continues also in the
  546. subtree to see if any of the subtasks have project status.
  547. See also the variable `org-tags-match-list-sublevels' which applies
  548. to projects matched by this search as well.
  549. After defining this variable, you may use `org-agenda-list-stuck-projects'
  550. \(bound to `\\[org-agenda] #') to produce the list."
  551. :group 'org-agenda-custom-commands
  552. :type '(list
  553. (string :tag "Tags/TODO match to identify a project")
  554. (repeat :tag "Projects are *not* stuck if they have an entry with \
  555. TODO keyword any of" (string))
  556. (repeat :tag "Projects are *not* stuck if they have an entry with \
  557. TAG being any of" (string))
  558. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  559. the subtree")))
  560. (defgroup org-agenda-skip nil
  561. "Options concerning skipping parts of agenda files."
  562. :tag "Org Agenda Skip"
  563. :group 'org-agenda)
  564. (defcustom org-agenda-skip-function-global nil
  565. "Function to be called at each match during agenda construction.
  566. If this function returns nil, the current match should not be skipped.
  567. If the function decided to skip an agenda match, is must return the
  568. buffer position from which the search should be continued.
  569. This may also be a Lisp form, which will be evaluated.
  570. This variable will be applied to every agenda match, including
  571. tags/property searches and TODO lists. So try to make the test function
  572. do its checking as efficiently as possible. To implement a skipping
  573. condition just for specific agenda commands, use the variable
  574. `org-agenda-skip-function' which can be set in the options section
  575. of custom agenda commands."
  576. :group 'org-agenda-skip
  577. :type 'sexp)
  578. (defgroup org-agenda-daily/weekly nil
  579. "Options concerning the daily/weekly agenda."
  580. :tag "Org Agenda Daily/Weekly"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-todo-list nil
  583. "Options concerning the global todo list agenda view."
  584. :tag "Org Agenda Todo List"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-match-view nil
  587. "Options concerning the general tags/property/todo match agenda view."
  588. :tag "Org Agenda Match View"
  589. :group 'org-agenda)
  590. (defgroup org-agenda-search-view nil
  591. "Options concerning the search agenda view."
  592. :tag "Org Agenda Search View"
  593. :group 'org-agenda)
  594. (defvar org-agenda-archives-mode nil
  595. "Non-nil means the agenda will include archived items.
  596. If this is the symbol `trees', trees in the selected agenda scope
  597. that are marked with the ARCHIVE tag will be included anyway. When this is
  598. t, also all archive files associated with the current selection of agenda
  599. files will be included.")
  600. (defcustom org-agenda-restriction-lock-highlight-subtree t
  601. "Non-nil means highlight the whole subtree when restriction is active.
  602. Otherwise only highlight the headline. Highlighting the whole subtree is
  603. useful to ensure no edits happen beyond the restricted region."
  604. :group 'org-agenda
  605. :type 'boolean)
  606. (defcustom org-agenda-skip-comment-trees t
  607. "Non-nil means skip trees that start with the COMMENT keyword.
  608. When nil, these trees are also scanned by agenda commands."
  609. :group 'org-agenda-skip
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-list-sublevels t
  612. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  613. When nil, the sublevels of a TODO entry are not checked, resulting in
  614. potentially much shorter TODO lists."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type 'boolean)
  618. (defcustom org-agenda-todo-ignore-with-date nil
  619. "Non-nil means don't show entries with a date in the global todo list.
  620. You can use this if you prefer to mark mere appointments with a TODO keyword,
  621. but don't want them to show up in the TODO list.
  622. When this is set, it also covers deadlines and scheduled items, the settings
  623. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  624. will be ignored.
  625. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  626. :group 'org-agenda-skip
  627. :group 'org-agenda-todo-list
  628. :type 'boolean)
  629. (defcustom org-agenda-todo-ignore-timestamp nil
  630. "Non-nil means don't show entries with a timestamp.
  631. This applies when creating the global todo list.
  632. Valid values are:
  633. past Don't show entries for today or in the past.
  634. future Don't show entries with a timestamp in the future.
  635. The idea behind this is that if it has a future
  636. timestamp, you don't want to think about it until the
  637. date.
  638. all Don't show any entries with a timestamp in the global todo list.
  639. The idea behind this is that by setting a timestamp, you
  640. have already \"taken care\" of this item.
  641. This variable can also have an integer as a value. If positive (N),
  642. todos with a timestamp N or more days in the future will be ignored. If
  643. negative (-N), todos with a timestamp N or more days in the past will be
  644. ignored. If 0, todos with a timestamp either today or in the future will
  645. be ignored. For example, a value of -1 will exclude todos with a
  646. timestamp in the past (yesterday or earlier), while a value of 7 will
  647. exclude todos with a timestamp a week or more in the future.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :version "24.1"
  654. :type '(choice
  655. (const :tag "Ignore future timestamp todos" future)
  656. (const :tag "Ignore past or present timestamp todos" past)
  657. (const :tag "Ignore all timestamp todos" all)
  658. (const :tag "Show timestamp todos" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-scheduled nil
  661. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  662. This applies when creating the global todo list.
  663. Valid values are:
  664. past Don't show entries scheduled today or in the past.
  665. future Don't show entries scheduled in the future.
  666. The idea behind this is that by scheduling it, you don't want to
  667. think about it until the scheduled date.
  668. all Don't show any scheduled entries in the global todo list.
  669. The idea behind this is that by scheduling it, you have already
  670. \"taken care\" of this item.
  671. t Same as `all', for backward compatibility.
  672. This variable can also have an integer as a value. See
  673. `org-agenda-todo-ignore-timestamp' for more details.
  674. See also `org-agenda-todo-ignore-with-date'.
  675. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  676. to make his option also apply to the tags-todo list."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-todo-list
  679. :type '(choice
  680. (const :tag "Ignore future-scheduled todos" future)
  681. (const :tag "Ignore past- or present-scheduled todos" past)
  682. (const :tag "Ignore all scheduled todos" all)
  683. (const :tag "Ignore all scheduled todos (compatibility)" t)
  684. (const :tag "Show scheduled todos" nil)
  685. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  686. (defcustom org-agenda-todo-ignore-deadlines nil
  687. "Non-nil means ignore some deadline TODO items when making TODO list.
  688. There are different motivations for using different values, please think
  689. carefully when configuring this variable.
  690. This applies when creating the global TODO list.
  691. Valid values are:
  692. near Don't show near deadline entries. A deadline is near when it is
  693. closer than `org-deadline-warning-days' days. The idea behind this
  694. is that such items will appear in the agenda anyway.
  695. far Don't show TODO entries where a deadline has been defined, but
  696. is not going to happen anytime soon. This is useful if you want to use
  697. the TODO list to figure out what to do now.
  698. past Don't show entries with a deadline timestamp for today or in the past.
  699. future Don't show entries with a deadline timestamp in the future, not even
  700. when they become `near' ones. Use it with caution.
  701. all Ignore all TODO entries that do have a deadline.
  702. t Same as `near', for backward compatibility.
  703. This variable can also have an integer as a value. See
  704. `org-agenda-todo-ignore-timestamp' for more details.
  705. See also `org-agenda-todo-ignore-with-date'.
  706. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  707. to make his option also apply to the tags-todo list."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Ignore near deadlines" near)
  712. (const :tag "Ignore near deadlines (compatibility)" t)
  713. (const :tag "Ignore far deadlines" far)
  714. (const :tag "Ignore all TODOs with a deadlines" all)
  715. (const :tag "Show all TODOs, even if they have a deadline" nil)
  716. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  717. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  718. "Time unit to use when possibly ignoring an agenda item.
  719. See the docstring of various `org-agenda-todo-ignore-*' options.
  720. The default is to compare time stamps using days. An item is thus
  721. considered to be in the future if it is at least one day after today.
  722. Non-nil means to compare time stamps using seconds. An item is then
  723. considered future if it has a time value later than current time."
  724. :group 'org-agenda-skip
  725. :group 'org-agenda-todo-list
  726. :version "24.4"
  727. :package-version '(Org . "8.0")
  728. :type '(choice
  729. (const :tag "Compare time with days" nil)
  730. (const :tag "Compare time with seconds" t)))
  731. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  732. "Non-nil means honor todo-list ignores options also in tags-todo search.
  733. The variables
  734. `org-agenda-todo-ignore-with-date',
  735. `org-agenda-todo-ignore-timestamp',
  736. `org-agenda-todo-ignore-scheduled',
  737. `org-agenda-todo-ignore-deadlines'
  738. make the global TODO list skip entries that have time stamps of certain
  739. kinds. If this option is set, the same options will also apply for the
  740. tags-todo search, which is the general tags/property matcher
  741. restricted to unfinished TODO entries only."
  742. :group 'org-agenda-skip
  743. :group 'org-agenda-todo-list
  744. :group 'org-agenda-match-view
  745. :type 'boolean)
  746. (defcustom org-agenda-skip-scheduled-if-done nil
  747. "Non-nil means don't show scheduled items in agenda when they are done.
  748. This is relevant for the daily/weekly agenda, not for the TODO list. It
  749. applies only to the actual date of the scheduling. Warnings about an item
  750. with a past scheduling dates are always turned off when the item is DONE."
  751. :group 'org-agenda-skip
  752. :group 'org-agenda-daily/weekly
  753. :type 'boolean)
  754. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  755. "Non-nil means skip scheduling line if same entry shows because of deadline.
  756. In the agenda of today, an entry can show up multiple times
  757. because it is both scheduled and has a nearby deadline, and maybe
  758. a plain time stamp as well.
  759. When this variable is nil, the entry will be shown several times.
  760. When set to t, then only the deadline is shown and the fact that
  761. the entry is scheduled today or was scheduled previously is not
  762. shown.
  763. When set to the symbol `not-today', skip scheduled previously,
  764. but not scheduled today.
  765. When set to the symbol `repeated-after-deadline', skip scheduled
  766. items if they are repeated beyond the current deadline."
  767. :group 'org-agenda-skip
  768. :group 'org-agenda-daily/weekly
  769. :type '(choice
  770. (const :tag "Never" nil)
  771. (const :tag "Always" t)
  772. (const :tag "Not when scheduled today" not-today)
  773. (const :tag "When repeated past deadline" repeated-after-deadline)))
  774. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  775. "Non-nil means skip timestamp line if same entry shows because of deadline.
  776. In the agenda of today, an entry can show up multiple times
  777. because it has both a plain timestamp and has a nearby deadline.
  778. When this variable is t, then only the deadline is shown and the
  779. fact that the entry has a timestamp for or including today is not
  780. shown. When this variable is nil, the entry will be shown
  781. several times."
  782. :group 'org-agenda-skip
  783. :group 'org-agenda-daily/weekly
  784. :version "24.1"
  785. :type '(choice
  786. (const :tag "Never" nil)
  787. (const :tag "Always" t)))
  788. (defcustom org-agenda-skip-deadline-if-done nil
  789. "Non-nil means don't show deadlines when the corresponding item is done.
  790. When nil, the deadline is still shown and should give you a happy feeling.
  791. This is relevant for the daily/weekly agenda. It applies only to the
  792. actual date of the deadline. Warnings about approaching and past-due
  793. deadlines are always turned off when the item is DONE."
  794. :group 'org-agenda-skip
  795. :group 'org-agenda-daily/weekly
  796. :type 'boolean)
  797. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  798. "Non-nil means skip deadline prewarning when entry is also scheduled.
  799. This will apply on all days where a prewarning for the deadline would
  800. be shown, but not at the day when the entry is actually due. On that day,
  801. the deadline will be shown anyway.
  802. This variable may be set to nil, t, the symbol `pre-scheduled',
  803. or a number which will then give the number of days before the actual
  804. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  805. eliminates the deadline prewarning only prior to the scheduled date.
  806. This can be used in a workflow where the first showing of the deadline will
  807. trigger you to schedule it, and then you don't want to be reminded of it
  808. because you will take care of it on the day when scheduled."
  809. :group 'org-agenda-skip
  810. :group 'org-agenda-daily/weekly
  811. :version "24.1"
  812. :type '(choice
  813. (const :tag "Always show prewarning" nil)
  814. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  815. (const :tag "Remove prewarning if entry is scheduled" t)
  816. (integer :tag "Restart prewarning N days before deadline")))
  817. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  818. "Non-nil means skip scheduled delay when entry also has a deadline.
  819. This variable may be set to nil, t, the symbol `post-deadline',
  820. or a number which will then give the number of days after the actual
  821. scheduled date when the delay should expire. The symbol `post-deadline'
  822. eliminates the schedule delay when the date is posterior to the deadline."
  823. :group 'org-agenda-skip
  824. :group 'org-agenda-daily/weekly
  825. :version "24.4"
  826. :package-version '(Org . "8.0")
  827. :type '(choice
  828. (const :tag "Always honor delay" nil)
  829. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  830. (const :tag "Ignore delay if entry has a deadline" t)
  831. (integer :tag "Honor delay up until N days after the scheduled date")))
  832. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  833. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  834. When non-nil, after the search for timestamps has matched once in an
  835. entry, the rest of the entry will not be searched."
  836. :group 'org-agenda-skip
  837. :type 'boolean)
  838. (defcustom org-agenda-skip-timestamp-if-done nil
  839. "Non-nil means don't select item by timestamp or -range if it is DONE."
  840. :group 'org-agenda-skip
  841. :group 'org-agenda-daily/weekly
  842. :type 'boolean)
  843. (defcustom org-agenda-dim-blocked-tasks t
  844. "Non-nil means dim blocked tasks in the agenda display.
  845. This causes some overhead during agenda construction, but if you
  846. have turned on `org-enforce-todo-dependencies',
  847. `org-enforce-todo-checkbox-dependencies', or any other blocking
  848. mechanism, this will create useful feedback in the agenda.
  849. Instead of t, this variable can also have the value `invisible'.
  850. Then blocked tasks will be invisible and only become visible when
  851. they become unblocked. An exemption to this behavior is when a task is
  852. blocked because of unchecked checkboxes below it. Since checkboxes do
  853. not show up in the agenda views, making this task invisible you remove any
  854. trace from agenda views that there is something to do. Therefore, a task
  855. that is blocked because of checkboxes will never be made invisible, it
  856. will only be dimmed."
  857. :group 'org-agenda-daily/weekly
  858. :group 'org-agenda-todo-list
  859. :version "24.3"
  860. :type '(choice
  861. (const :tag "Do not dim" nil)
  862. (const :tag "Dim to a gray face" t)
  863. (const :tag "Make invisible" invisible)))
  864. (defgroup org-agenda-startup nil
  865. "Options concerning initial settings in the Agenda in Org Mode."
  866. :tag "Org Agenda Startup"
  867. :group 'org-agenda)
  868. (defcustom org-agenda-menu-show-matcher t
  869. "Non-nil means show the match string in the agenda dispatcher menu.
  870. When nil, the matcher string is not shown, but is put into the help-echo
  871. property so than moving the mouse over the command shows it.
  872. Setting it to nil is good if matcher strings are very long and/or if
  873. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  874. :group 'org-agenda
  875. :version "24.1"
  876. :type 'boolean)
  877. (defcustom org-agenda-menu-two-columns nil
  878. "Non-nil means, use two columns to show custom commands in the dispatcher.
  879. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  880. to nil."
  881. :group 'org-agenda
  882. :version "24.1"
  883. :type 'boolean)
  884. (defcustom org-agenda-finalize-hook nil
  885. "Hook run just before displaying an agenda buffer.
  886. The buffer is still writable when the hook is called.
  887. You can modify some of the buffer substrings but you should be
  888. extra careful not to modify the text properties of the agenda
  889. headlines as the agenda display heavily relies on them."
  890. :group 'org-agenda-startup
  891. :type 'hook)
  892. (defcustom org-agenda-mouse-1-follows-link nil
  893. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  894. A longer mouse click will still set point. Needs to be set
  895. before org.el is loaded."
  896. :group 'org-agenda-startup
  897. :type 'boolean)
  898. (defcustom org-agenda-start-with-follow-mode nil
  899. "The initial value of follow mode in a newly created agenda window."
  900. :group 'org-agenda-startup
  901. :type 'boolean)
  902. (defcustom org-agenda-follow-indirect nil
  903. "Non-nil means `org-agenda-follow-mode' displays only the
  904. current item's tree, in an indirect buffer."
  905. :group 'org-agenda
  906. :version "24.1"
  907. :type 'boolean)
  908. (defcustom org-agenda-show-outline-path t
  909. "Non-nil means show outline path in echo area after line motion."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-start-with-entry-text-mode nil
  913. "The initial value of entry-text-mode in a newly created agenda window."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-entry-text-maxlines 5
  917. "Number of text lines to be added when `E' is pressed in the agenda.
  918. Note that this variable only used during agenda display. To add entry text
  919. when exporting the agenda, configure the variable
  920. `org-agenda-add-entry-text-maxlines'."
  921. :group 'org-agenda
  922. :type 'integer)
  923. (defcustom org-agenda-entry-text-exclude-regexps nil
  924. "List of regular expressions to clean up entry text.
  925. The complete matches of all regular expressions in this list will be
  926. removed from entry text before it is shown in the agenda."
  927. :group 'org-agenda
  928. :type '(repeat (regexp)))
  929. (defcustom org-agenda-entry-text-leaders " > "
  930. "Text prepended to the entry text in agenda buffers."
  931. :version "24.4"
  932. :package-version '(Org . "8.0")
  933. :group 'org-agenda
  934. :type 'string)
  935. (defvar org-agenda-entry-text-cleanup-hook nil
  936. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  937. This cleanup is done in a temporary buffer, so the function may inspect and
  938. change the entire buffer.
  939. Some default stuff like drawers and scheduling/deadline dates will already
  940. have been removed when this is called, as will any matches for regular
  941. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  942. (defvar org-agenda-include-inactive-timestamps nil
  943. "Non-nil means include inactive time stamps in agenda.
  944. Dynamically scoped.")
  945. (defgroup org-agenda-windows nil
  946. "Options concerning the windows used by the Agenda in Org Mode."
  947. :tag "Org Agenda Windows"
  948. :group 'org-agenda)
  949. (defcustom org-agenda-window-setup 'reorganize-frame
  950. "How the agenda buffer should be displayed.
  951. Possible values for this option are:
  952. current-window Show agenda in the current window, keeping all other windows.
  953. other-window Use `switch-to-buffer-other-window' to display agenda.
  954. only-window Show agenda, deleting all other windows.
  955. reorganize-frame Show only two windows on the current frame, the current
  956. window and the agenda.
  957. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  958. Also, when exiting the agenda, kill that frame.
  959. See also the variable `org-agenda-restore-windows-after-quit'."
  960. :group 'org-agenda-windows
  961. :type '(choice
  962. (const current-window)
  963. (const other-frame)
  964. (const other-window)
  965. (const only-window)
  966. (const reorganize-frame)))
  967. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  968. "The min and max height of the agenda window as a fraction of frame height.
  969. The value of the variable is a cons cell with two numbers between 0 and 1.
  970. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  971. :group 'org-agenda-windows
  972. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  973. (defcustom org-agenda-restore-windows-after-quit nil
  974. "Non-nil means restore window configuration upon exiting agenda.
  975. Before the window configuration is changed for displaying the agenda,
  976. the current status is recorded. When the agenda is exited with
  977. `q' or `x' and this option is set, the old state is restored. If
  978. `org-agenda-window-setup' is `other-frame', the value of this
  979. option will be ignored."
  980. :group 'org-agenda-windows
  981. :type 'boolean)
  982. (defcustom org-agenda-span 'week
  983. "Number of days to include in overview display.
  984. Can be day, week, month, year, or any number of days.
  985. Custom commands can set this variable in the options section."
  986. :group 'org-agenda-daily/weekly
  987. :type '(choice (const :tag "Day" day)
  988. (const :tag "Week" week)
  989. (const :tag "Fortnight" fortnight)
  990. (const :tag "Month" month)
  991. (const :tag "Year" year)
  992. (integer :tag "Custom")))
  993. (defcustom org-agenda-start-on-weekday 1
  994. "Non-nil means start the overview always on the specified weekday.
  995. 0 denotes Sunday, 1 denotes Monday, etc.
  996. When nil, always start on the current day.
  997. Custom commands can set this variable in the options section."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const :tag "Today" nil)
  1000. (integer :tag "Weekday No.")))
  1001. (defcustom org-agenda-show-all-dates t
  1002. "Non-nil means `org-agenda' shows every day in the selected range.
  1003. When nil, only the days which actually have entries are shown."
  1004. :group 'org-agenda-daily/weekly
  1005. :type 'boolean)
  1006. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1007. "Format string for displaying dates in the agenda.
  1008. Used by the daily/weekly agenda. This should be a format string
  1009. understood by `format-time-string', or a function returning the
  1010. formatted date as a string. The function must take a single
  1011. argument, a calendar-style date list like (month day year)."
  1012. :group 'org-agenda-daily/weekly
  1013. :type '(choice
  1014. (string :tag "Format string")
  1015. (function :tag "Function")))
  1016. (defun org-agenda-format-date-aligned (date)
  1017. "Format a DATE string for display in the daily/weekly agenda.
  1018. This function makes sure that dates are aligned for easy reading."
  1019. (require 'cal-iso)
  1020. (let* ((dayname (calendar-day-name date))
  1021. (day (cadr date))
  1022. (day-of-week (calendar-day-of-week date))
  1023. (month (car date))
  1024. (monthname (calendar-month-name month))
  1025. (year (nth 2 date))
  1026. (iso-week (org-days-to-iso-week
  1027. (calendar-absolute-from-gregorian date)))
  1028. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1029. (1- year))
  1030. ((and (= month 12) (<= iso-week 1))
  1031. (1+ year))
  1032. (t year)))
  1033. (weekstring (if (= day-of-week 1)
  1034. (format " W%02d" iso-week)
  1035. "")))
  1036. (format "%-10s %2d %s %4d%s"
  1037. dayname day monthname year weekstring)))
  1038. (defcustom org-agenda-time-leading-zero nil
  1039. "Non-nil means use leading zero for military times in agenda.
  1040. For example, 9:30am would become 09:30 rather than 9:30."
  1041. :group 'org-agenda-daily/weekly
  1042. :version "24.1"
  1043. :type 'boolean)
  1044. (defcustom org-agenda-timegrid-use-ampm nil
  1045. "When set, show AM/PM style timestamps on the timegrid."
  1046. :group 'org-agenda
  1047. :version "24.1"
  1048. :type 'boolean)
  1049. (defun org-agenda-time-of-day-to-ampm (time)
  1050. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1051. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1052. (minute (substring time -2))
  1053. (ampm "am"))
  1054. (cond
  1055. ((equal hour-number 12)
  1056. (setq ampm "pm"))
  1057. ((> hour-number 12)
  1058. (setq ampm "pm")
  1059. (setq hour-number (- hour-number 12))))
  1060. (concat
  1061. (if org-agenda-time-leading-zero
  1062. (format "%02d" hour-number)
  1063. (format "%02s" (number-to-string hour-number)))
  1064. ":" minute ampm)))
  1065. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1066. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1067. (if org-agenda-timegrid-use-ampm
  1068. (org-agenda-time-of-day-to-ampm time)
  1069. time))
  1070. (defcustom org-agenda-weekend-days '(6 0)
  1071. "Which days are weekend?
  1072. These days get the special face `org-agenda-date-weekend' in the agenda."
  1073. :group 'org-agenda-daily/weekly
  1074. :type '(set :greedy t
  1075. (const :tag "Monday" 1)
  1076. (const :tag "Tuesday" 2)
  1077. (const :tag "Wednesday" 3)
  1078. (const :tag "Thursday" 4)
  1079. (const :tag "Friday" 5)
  1080. (const :tag "Saturday" 6)
  1081. (const :tag "Sunday" 0)))
  1082. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1083. "Non-nil means jump to today when moving a past date forward in time.
  1084. When using S-right in the agenda to move a a date forward, and the date
  1085. stamp currently points to the past, the first key press will move it
  1086. to today. WHen nil, just move one day forward even if the date stays
  1087. in the past."
  1088. :group 'org-agenda-daily/weekly
  1089. :version "24.1"
  1090. :type 'boolean)
  1091. (defcustom org-agenda-include-diary nil
  1092. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1093. Custom commands can set this variable in the options section."
  1094. :group 'org-agenda-daily/weekly
  1095. :type 'boolean)
  1096. (defcustom org-agenda-include-deadlines t
  1097. "If non-nil, include entries within their deadline warning period.
  1098. Custom commands can set this variable in the options section."
  1099. :group 'org-agenda-daily/weekly
  1100. :version "24.1"
  1101. :type 'boolean)
  1102. (defcustom org-agenda-show-future-repeats t
  1103. "Non-nil shows repeated entries in the future part of the agenda.
  1104. When set to the symbol `next' only the first future repeat is shown."
  1105. :group 'org-agenda-daily/weekly
  1106. :type '(choice
  1107. (const :tag "Show all repeated entries" t)
  1108. (const :tag "Show next repeated entry" next)
  1109. (const :tag "Do not show repeated entries" nil))
  1110. :version "26.1"
  1111. :package-version '(Org . "9.1")
  1112. :safe #'symbolp)
  1113. (defcustom org-agenda-prefer-last-repeat nil
  1114. "Non-nil sets date for repeated entries to their last repeat.
  1115. When nil, display SCHEDULED and DEADLINE dates at their base
  1116. date, and in today's agenda, as a reminder. Display plain
  1117. time-stamps, on the other hand, at every repeat date in the past
  1118. in addition to the base date.
  1119. When non-nil, show a repeated entry at its latest repeat date,
  1120. possibly being today even if it wasn't marked as done. This
  1121. setting is useful if you do not always mark repeated entries as
  1122. done and, yet, consider that reaching repeat date starts the task
  1123. anew.
  1124. When set to a list of strings, prefer last repeats only for
  1125. entries with these TODO keywords."
  1126. :group 'org-agenda-daily/weekly
  1127. :type '(choice
  1128. (const :tag "Prefer last repeat" t)
  1129. (const :tag "Prefer base date" nil)
  1130. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1131. (string :tag "TODO keyword")))
  1132. :version "26.1"
  1133. :package-version '(Org . "9.1")
  1134. :safe (lambda (x) (or (booleanp x) (consp x))))
  1135. (defcustom org-scheduled-past-days 10000
  1136. "Number of days to continue listing scheduled items not marked DONE.
  1137. When an item is scheduled on a date, it shows up in the agenda on
  1138. this day and will be listed until it is marked done or for the
  1139. number of days given here."
  1140. :group 'org-agenda-daily/weekly
  1141. :type 'integer
  1142. :safe 'integerp)
  1143. (defcustom org-deadline-past-days 10000
  1144. "Number of days to warn about missed deadlines.
  1145. When an item has deadline on a date, it shows up in the agenda on
  1146. this day and will appear as a reminder until it is marked DONE or
  1147. for the number of days given here."
  1148. :group 'org-agenda-daily/weekly
  1149. :type 'integer
  1150. :version "26.1"
  1151. :package-version '(Org . "9.1")
  1152. :safe 'integerp)
  1153. (defcustom org-agenda-log-mode-items '(closed clock)
  1154. "List of items that should be shown in agenda log mode.
  1155. \\<org-agenda-mode-map>\
  1156. This list may contain the following symbols:
  1157. closed Show entries that have been closed on that day.
  1158. clock Show entries that have received clocked time on that day.
  1159. state Show all logged state changes.
  1160. Note that instead of changing this variable, you can also press \
  1161. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1162. the agenda to display all available LOG items temporarily."
  1163. :group 'org-agenda-daily/weekly
  1164. :type '(set :greedy t (const closed) (const clock) (const state)))
  1165. (defcustom org-agenda-clock-consistency-checks
  1166. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1167. :gap-ok-around ("4:00")
  1168. :default-face ((:background "DarkRed") (:foreground "white"))
  1169. :overlap-face nil :gap-face nil :no-end-time-face nil
  1170. :long-face nil :short-face nil)
  1171. "This is a property list, with the following keys:
  1172. :max-duration Mark clocking chunks that are longer than this time.
  1173. This is a time string like \"HH:MM\", or the number
  1174. of minutes as an integer.
  1175. :min-duration Mark clocking chunks that are shorter that this.
  1176. This is a time string like \"HH:MM\", or the number
  1177. of minutes as an integer.
  1178. :max-gap Mark gaps between clocking chunks that are longer than
  1179. this duration. A number of minutes, or a string
  1180. like \"HH:MM\".
  1181. :gap-ok-around List of times during the day which are usually not working
  1182. times. When a gap is detected, but the gap contains any
  1183. of these times, the gap is *not* reported. For example,
  1184. if this is (\"4:00\" \"13:00\") then gaps that contain
  1185. 4:00 in the morning (i.e. the night) and 13:00
  1186. (i.e. a typical lunch time) do not cause a warning.
  1187. You should have at least one time during the night in this
  1188. list, or otherwise the first task each morning will trigger
  1189. a warning because it follows a long gap.
  1190. Furthermore, the following properties can be used to define faces for
  1191. issue display.
  1192. :default-face the default face, if the specific face is undefined
  1193. :overlap-face face for overlapping clocks
  1194. :gap-face face for gaps between clocks
  1195. :no-end-time-face face for incomplete clocks
  1196. :long-face face for clock intervals that are too long
  1197. :short-face face for clock intervals that are too short"
  1198. :group 'org-agenda-daily/weekly
  1199. :group 'org-clock
  1200. :version "24.1"
  1201. :type 'plist)
  1202. (defcustom org-agenda-log-mode-add-notes t
  1203. "Non-nil means add first line of notes to log entries in agenda views.
  1204. If a log item like a state change or a clock entry is associated with
  1205. notes, the first line of these notes will be added to the entry in the
  1206. agenda display."
  1207. :group 'org-agenda-daily/weekly
  1208. :type 'boolean)
  1209. (defcustom org-agenda-start-with-log-mode nil
  1210. "The initial value of log-mode in a newly created agenda window.
  1211. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1212. explanations on the possible values."
  1213. :group 'org-agenda-startup
  1214. :group 'org-agenda-daily/weekly
  1215. :type '(choice (const :tag "Don't show log items" nil)
  1216. (const :tag "Show only log items" only)
  1217. (const :tag "Show all possible log items" clockcheck)
  1218. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1219. (choice (const :tag "Show closed log items" closed)
  1220. (const :tag "Show clocked log items" clock)
  1221. (const :tag "Show all logged state changes" state)))))
  1222. (defcustom org-agenda-start-with-clockreport-mode nil
  1223. "The initial value of clockreport-mode in a newly created agenda window."
  1224. :group 'org-agenda-startup
  1225. :group 'org-agenda-daily/weekly
  1226. :type 'boolean)
  1227. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1228. "Property list with parameters for the clocktable in clockreport mode.
  1229. This is the display mode that shows a clock table in the daily/weekly
  1230. agenda, the properties for this dynamic block can be set here.
  1231. The usual clocktable parameters are allowed here, but you cannot set
  1232. the properties :name, :tstart, :tend, :block, and :scope - these will
  1233. be overwritten to make sure the content accurately reflects the
  1234. current display in the agenda."
  1235. :group 'org-agenda-daily/weekly
  1236. :type 'plist)
  1237. (defcustom org-agenda-search-view-always-boolean nil
  1238. "Non-nil means the search string is interpreted as individual parts.
  1239. The search string for search view can either be interpreted as a phrase,
  1240. or as a list of snippets that define a boolean search for a number of
  1241. strings.
  1242. When this is non-nil, the string will be split on whitespace, and each
  1243. snippet will be searched individually, and all must match in order to
  1244. select an entry. A snippet is then a single string of non-white
  1245. characters, or a string in double quotes, or a regexp in {} braces.
  1246. If a snippet is preceded by \"-\", the snippet must *not* match.
  1247. \"+\" is syntactic sugar for positive selection. Each snippet may
  1248. be found as a full word or a partial word, but see the variable
  1249. `org-agenda-search-view-force-full-words'.
  1250. When this is nil, search will look for the entire search phrase as one,
  1251. with each space character matching any amount of whitespace, including
  1252. line breaks.
  1253. Even when this is nil, you can still switch to Boolean search dynamically
  1254. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1255. is a regexp marked with braces like \"{abc}\", this will also switch to
  1256. boolean search."
  1257. :group 'org-agenda-search-view
  1258. :version "24.1"
  1259. :type 'boolean)
  1260. (defvaralias 'org-agenda-search-view-search-words-only
  1261. 'org-agenda-search-view-always-boolean)
  1262. (defcustom org-agenda-search-view-force-full-words nil
  1263. "Non-nil means, search words must be matches as complete words.
  1264. When nil, they may also match part of a word."
  1265. :group 'org-agenda-search-view
  1266. :version "24.1"
  1267. :type 'boolean)
  1268. (defcustom org-agenda-search-view-max-outline-level 0
  1269. "Maximum outline level to display in search view.
  1270. E.g. when this is set to 1, the search view will only
  1271. show headlines of level 1. When set to 0, the default
  1272. value, don't limit agenda view by outline level."
  1273. :group 'org-agenda-search-view
  1274. :version "26.1"
  1275. :package-version '(Org . "8.3")
  1276. :type 'integer)
  1277. (defgroup org-agenda-time-grid nil
  1278. "Options concerning the time grid in the Org Agenda."
  1279. :tag "Org Agenda Time Grid"
  1280. :group 'org-agenda)
  1281. (defcustom org-agenda-search-headline-for-time t
  1282. "Non-nil means search headline for a time-of-day.
  1283. If the headline contains a time-of-day in one format or another, it will
  1284. be used to sort the entry into the time sequence of items for a day.
  1285. Some people have time stamps in the headline that refer to the creation
  1286. time or so, and then this produces an unwanted side effect. If this is
  1287. the case for your, use this variable to turn off searching the headline
  1288. for a time."
  1289. :group 'org-agenda-time-grid
  1290. :type 'boolean)
  1291. (defcustom org-agenda-use-time-grid t
  1292. "Non-nil means show a time grid in the agenda schedule.
  1293. A time grid is a set of lines for specific times (like every two hours between
  1294. 8:00 and 20:00). The items scheduled for a day at specific times are
  1295. sorted in between these lines.
  1296. For details about when the grid will be shown, and what it will look like, see
  1297. the variable `org-agenda-time-grid'."
  1298. :group 'org-agenda-time-grid
  1299. :type 'boolean)
  1300. (defcustom org-agenda-time-grid
  1301. '((daily today require-timed)
  1302. (800 1000 1200 1400 1600 1800 2000)
  1303. "......"
  1304. "----------------")
  1305. "The settings for time grid for agenda display.
  1306. This is a list of four items. The first item is again a list. It contains
  1307. symbols specifying conditions when the grid should be displayed:
  1308. daily if the agenda shows a single day
  1309. weekly if the agenda shows an entire week
  1310. today show grid on current date, independent of daily/weekly display
  1311. require-timed show grid only if at least one item has a time specification
  1312. remove-match skip grid times already present in an entry
  1313. The second item is a list of integers, indicating the times that
  1314. should have a grid line.
  1315. The third item is a string which will be placed right after the
  1316. times that have a grid line.
  1317. The fourth item is a string placed after the grid times. This
  1318. will align with agenda items"
  1319. :group 'org-agenda-time-grid
  1320. :type
  1321. '(list
  1322. (set :greedy t :tag "Grid Display Options"
  1323. (const :tag "Show grid in single day agenda display" daily)
  1324. (const :tag "Show grid in weekly agenda display" weekly)
  1325. (const :tag "Always show grid for today" today)
  1326. (const :tag "Show grid only if any timed entries are present"
  1327. require-timed)
  1328. (const :tag "Skip grid times already present in an entry"
  1329. remove-match))
  1330. (repeat :tag "Grid Times" (integer :tag "Time"))
  1331. (string :tag "Grid String (after agenda times)")
  1332. (string :tag "Grid String (aligns with agenda items)")))
  1333. (defcustom org-agenda-show-current-time-in-grid t
  1334. "Non-nil means show the current time in the time grid."
  1335. :group 'org-agenda-time-grid
  1336. :version "24.1"
  1337. :type 'boolean)
  1338. (defcustom org-agenda-current-time-string
  1339. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1340. "The string for the current time marker in the agenda."
  1341. :group 'org-agenda-time-grid
  1342. :version "24.1"
  1343. :type 'string)
  1344. (defgroup org-agenda-sorting nil
  1345. "Options concerning sorting in the Org Agenda."
  1346. :tag "Org Agenda Sorting"
  1347. :group 'org-agenda)
  1348. (defcustom org-agenda-sorting-strategy
  1349. '((agenda habit-down time-up priority-down category-keep)
  1350. (todo priority-down category-keep)
  1351. (tags priority-down category-keep)
  1352. (search category-keep))
  1353. "Sorting structure for the agenda items of a single day.
  1354. This is a list of symbols which will be used in sequence to determine
  1355. if an entry should be listed before another entry. The following
  1356. symbols are recognized:
  1357. time-up Put entries with time-of-day indications first, early first
  1358. time-down Put entries with time-of-day indications first, late first
  1359. timestamp-up Sort by any timestamp, early first
  1360. timestamp-down Sort by any timestamp, late first
  1361. scheduled-up Sort by scheduled timestamp, early first
  1362. scheduled-down Sort by scheduled timestamp, late first
  1363. deadline-up Sort by deadline timestamp, early first
  1364. deadline-down Sort by deadline timestamp, late first
  1365. ts-up Sort by active timestamp, early first
  1366. ts-down Sort by active timestamp, late first
  1367. tsia-up Sort by inactive timestamp, early first
  1368. tsia-down Sort by inactive timestamp, late first
  1369. category-keep Keep the default order of categories, corresponding to the
  1370. sequence in `org-agenda-files'.
  1371. category-up Sort alphabetically by category, A-Z.
  1372. category-down Sort alphabetically by category, Z-A.
  1373. tag-up Sort alphabetically by last tag, A-Z.
  1374. tag-down Sort alphabetically by last tag, Z-A.
  1375. priority-up Sort numerically by priority, high priority last.
  1376. priority-down Sort numerically by priority, high priority first.
  1377. todo-state-up Sort by todo state, tasks that are done last.
  1378. todo-state-down Sort by todo state, tasks that are done first.
  1379. effort-up Sort numerically by estimated effort, high effort last.
  1380. effort-down Sort numerically by estimated effort, high effort first.
  1381. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1382. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1383. habit-up Put entries that are habits first
  1384. habit-down Put entries that are habits last
  1385. alpha-up Sort headlines alphabetically
  1386. alpha-down Sort headlines alphabetically, reversed
  1387. The different possibilities will be tried in sequence, and testing stops
  1388. if one comparison returns a \"not-equal\". For example, the default
  1389. '(time-up category-keep priority-down)
  1390. means: Pull out all entries having a specified time of day and sort them,
  1391. in order to make a time schedule for the current day the first thing in the
  1392. agenda listing for the day. Of the entries without a time indication, keep
  1393. the grouped in categories, don't sort the categories, but keep them in
  1394. the sequence given in `org-agenda-files'. Within each category sort by
  1395. priority.
  1396. Leaving out `category-keep' would mean that items will be sorted across
  1397. categories by priority.
  1398. Instead of a single list, this can also be a set of list for specific
  1399. contents, with a context symbol in the car of the list, any of
  1400. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1401. Custom commands can bind this variable in the options section."
  1402. :group 'org-agenda-sorting
  1403. :type `(choice
  1404. (repeat :tag "General" ,org-sorting-choice)
  1405. (list :tag "Individually"
  1406. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1407. (repeat ,org-sorting-choice))
  1408. (cons (const :tag "Strategy for TODO lists" todo)
  1409. (repeat ,org-sorting-choice))
  1410. (cons (const :tag "Strategy for Tags matches" tags)
  1411. (repeat ,org-sorting-choice))
  1412. (cons (const :tag "Strategy for search matches" search)
  1413. (repeat ,org-sorting-choice)))))
  1414. (defcustom org-agenda-cmp-user-defined nil
  1415. "A function to define the comparison `user-defined'.
  1416. This function must receive two arguments, agenda entry a and b.
  1417. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1418. the user comparison, return nil.
  1419. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1420. part of an agenda sorting strategy."
  1421. :group 'org-agenda-sorting
  1422. :type 'symbol)
  1423. (defcustom org-sort-agenda-notime-is-late t
  1424. "Non-nil means items without time are considered late.
  1425. This is only relevant for sorting. When t, items which have no explicit
  1426. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1427. do have a time. When nil, the default time is before 0:00. You can use this
  1428. option to decide if the schedule for today should come before or after timeless
  1429. agenda entries."
  1430. :group 'org-agenda-sorting
  1431. :type 'boolean)
  1432. (defcustom org-sort-agenda-noeffort-is-high t
  1433. "Non-nil means items without effort estimate are sorted as high effort.
  1434. This also applies when filtering an agenda view with respect to the
  1435. < or > effort operator. Then, tasks with no effort defined will be treated
  1436. as tasks with high effort.
  1437. When nil, such items are sorted as 0 minutes effort."
  1438. :group 'org-agenda-sorting
  1439. :type 'boolean)
  1440. (defgroup org-agenda-line-format nil
  1441. "Options concerning the entry prefix in the Org agenda display."
  1442. :tag "Org Agenda Line Format"
  1443. :group 'org-agenda)
  1444. (defcustom org-agenda-prefix-format
  1445. '((agenda . " %i %-12:c%?-12t% s")
  1446. (todo . " %i %-12:c")
  1447. (tags . " %i %-12:c")
  1448. (search . " %i %-12:c"))
  1449. "Format specifications for the prefix of items in the agenda views.
  1450. An alist with five entries, each for the different agenda types. The
  1451. keys of the sublists are `agenda', `todo', `search' and `tags'.
  1452. The values are format strings.
  1453. This format works similar to a printf format, with the following meaning:
  1454. %c the category of the item, \"Diary\" for entries from the diary,
  1455. or as given by the CATEGORY keyword or derived from the file name
  1456. %e the effort required by the item
  1457. %l the level of the item (insert X space(s) if item is of level X)
  1458. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1459. %T the last tag of the item (ignore inherited tags, which come first)
  1460. %t the HH:MM time-of-day specification if one applies to the entry
  1461. %s Scheduling/Deadline information, a short string
  1462. %b show breadcrumbs, i.e., the names of the higher levels
  1463. %(expression) Eval EXPRESSION and replace the control string
  1464. by the result
  1465. All specifiers work basically like the standard `%s' of printf, but may
  1466. contain two additional characters: a question mark just after the `%'
  1467. and a whitespace/punctuation character just before the final letter.
  1468. If the first character after `%' is a question mark, the entire field
  1469. will only be included if the corresponding value applies to the current
  1470. entry. This is useful for fields which should have fixed width when
  1471. present, but zero width when absent. For example, \"%?-12t\" will
  1472. result in a 12 character time field if a time of the day is specified,
  1473. but will completely disappear in entries which do not contain a time.
  1474. If there is punctuation or whitespace character just before the
  1475. final format letter, this character will be appended to the field
  1476. value if the value is not empty. For example, the format
  1477. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1478. the category is empty, no additional colon is inserted.
  1479. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1480. which means:
  1481. - Indent the line with two space characters
  1482. - Give the category a 12 chars wide field, padded with whitespace on
  1483. the right (because of `-'). Append a colon if there is a category
  1484. (because of `:').
  1485. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1486. time, don't put in an empty field, just skip it (because of '?').
  1487. - Finally, put the scheduling information.
  1488. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1489. `org-agenda-remove-tags'.
  1490. Custom commands can set this variable in the options section."
  1491. :type '(choice
  1492. (string :tag "General format")
  1493. (list :greedy t :tag "View dependent"
  1494. (cons (const agenda) (string :tag "Format"))
  1495. (cons (const todo) (string :tag "Format"))
  1496. (cons (const tags) (string :tag "Format"))
  1497. (cons (const search) (string :tag "Format"))))
  1498. :group 'org-agenda-line-format
  1499. :version "26.1"
  1500. :package-version '(Org . "9.1"))
  1501. (defvar org-prefix-format-compiled nil
  1502. "The compiled prefix format and associated variables.
  1503. This is a list where first element is a list of variable bindings, and second
  1504. element is the compiled format expression. See the variable
  1505. `org-agenda-prefix-format'.")
  1506. (defcustom org-agenda-todo-keyword-format "%-1s"
  1507. "Format for the TODO keyword in agenda lines.
  1508. Set this to something like \"%-12s\" if you want all TODO keywords
  1509. to occupy a fixed space in the agenda display."
  1510. :group 'org-agenda-line-format
  1511. :type 'string)
  1512. (defcustom org-agenda-diary-sexp-prefix nil
  1513. "A regexp that matches part of a diary sexp entry
  1514. which should be treated as scheduling/deadline information in
  1515. `org-agenda'.
  1516. For example, you can use this to extract the `diary-remind-message' from
  1517. `diary-remind' entries."
  1518. :group 'org-agenda-line-format
  1519. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1520. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1521. "Text preceding timerange entries in the agenda view.
  1522. This is a list with two strings. The first applies when the range
  1523. is entirely on one day. The second applies if the range spans several days.
  1524. The strings may have two \"%d\" format specifiers which will be filled
  1525. with the sequence number of the days, and the total number of days in the
  1526. range, respectively."
  1527. :group 'org-agenda-line-format
  1528. :type '(list
  1529. (string :tag "Deadline today ")
  1530. (choice :tag "Deadline relative"
  1531. (string :tag "Format string")
  1532. (function))))
  1533. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1534. "Text preceding scheduled items in the agenda view.
  1535. This is a list with two strings. The first applies when the item is
  1536. scheduled on the current day. The second applies when it has been scheduled
  1537. previously, it may contain a %d indicating that this is the nth time that
  1538. this item is scheduled, due to automatic rescheduling of unfinished items
  1539. for the following day. So this number is one larger than the number of days
  1540. that passed since this item was scheduled first."
  1541. :group 'org-agenda-line-format
  1542. :version "24.4"
  1543. :package-version '(Org . "8.0")
  1544. :type '(list
  1545. (string :tag "Scheduled today ")
  1546. (string :tag "Scheduled previously")))
  1547. (defcustom org-agenda-inactive-leader "["
  1548. "Text preceding item pulled into the agenda by inactive time stamps.
  1549. These entries are added to the agenda when pressing \"[\"."
  1550. :group 'org-agenda-line-format
  1551. :version "24.1"
  1552. :type 'string)
  1553. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1554. "Text preceding deadline items in the agenda view.
  1555. This is a list with three strings. The first applies when the item has its
  1556. deadline on the current day. The second applies when the deadline is in the
  1557. future, the third one when it is in the past. The strings may contain %d
  1558. to capture the number of days."
  1559. :group 'org-agenda-line-format
  1560. :version "24.4"
  1561. :package-version '(Org . "8.0")
  1562. :type '(list
  1563. (string :tag "Deadline today ")
  1564. (string :tag "Deadline in the future ")
  1565. (string :tag "Deadline in the past ")))
  1566. (defcustom org-agenda-remove-times-when-in-prefix t
  1567. "Non-nil means remove duplicate time specifications in agenda items.
  1568. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1569. time-of-day specification in a headline or diary entry is extracted and
  1570. placed into the prefix. If this option is non-nil, the original specification
  1571. \(a timestamp or -range, or just a plain time(range) specification like
  1572. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1573. cluttered.
  1574. The option can be t or nil. It may also be the symbol `beg', indicating
  1575. that the time should only be removed when it is located at the beginning of
  1576. the headline/diary entry."
  1577. :group 'org-agenda-line-format
  1578. :type '(choice
  1579. (const :tag "Always" t)
  1580. (const :tag "Never" nil)
  1581. (const :tag "When at beginning of entry" beg)))
  1582. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1583. "Non-nil means remove time ranges specifications in agenda
  1584. items that span on several days."
  1585. :group 'org-agenda-line-format
  1586. :version "24.1"
  1587. :type 'boolean)
  1588. (defcustom org-agenda-default-appointment-duration nil
  1589. "Default duration for appointments that only have a starting time.
  1590. When nil, no duration is specified in such cases.
  1591. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1592. :group 'org-agenda-line-format
  1593. :type '(choice
  1594. (integer :tag "Minutes")
  1595. (const :tag "No default duration")))
  1596. (defcustom org-agenda-show-inherited-tags t
  1597. "Non-nil means show inherited tags in each agenda line.
  1598. When this option is set to `always', it takes precedence over
  1599. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1600. in every agenda.
  1601. When this option is set to t (the default), inherited tags are
  1602. shown when they are available, i.e. when the value of
  1603. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1604. given agenda type.
  1605. This can be set to a list of agenda types in which the agenda
  1606. must display the inherited tags. Available types are `todo',
  1607. `agenda' and `search'.
  1608. When set to nil, never show inherited tags in agenda lines."
  1609. :group 'org-agenda-line-format
  1610. :group 'org-agenda
  1611. :version "24.3"
  1612. :type '(choice
  1613. (const :tag "Show inherited tags when available" t)
  1614. (const :tag "Always show inherited tags" always)
  1615. (repeat :tag "Show inherited tags only in selected agenda types"
  1616. (symbol :tag "Agenda type"))))
  1617. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1618. "List of agenda view types where to use tag inheritance.
  1619. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1620. controlled by `org-use-tag-inheritance'. In other agenda types,
  1621. `org-use-tag-inheritance' is not used for the selection of the
  1622. agenda entries. Still, you may want the agenda to be aware of
  1623. the inherited tags anyway, e.g. for later tag filtering.
  1624. Allowed value are `todo', `search' and `agenda'.
  1625. This variable has no effect if `org-agenda-show-inherited-tags'
  1626. is set to `always'. In that case, the agenda is aware of those
  1627. tags.
  1628. The default value sets tags in every agenda type. Setting this
  1629. option to nil will speed up non-tags agenda view a lot."
  1630. :group 'org-agenda
  1631. :version "26.1"
  1632. :package-version '(Org . "9.1")
  1633. :type '(choice
  1634. (const :tag "Use tag inheritance in all agenda types" t)
  1635. (repeat :tag "Use tag inheritance in selected agenda types"
  1636. (symbol :tag "Agenda type"))))
  1637. (defcustom org-agenda-hide-tags-regexp nil
  1638. "Regular expression used to filter away specific tags in agenda views.
  1639. This means that these tags will be present, but not be shown in the agenda
  1640. line. Secondary filtering will still work on the hidden tags.
  1641. Nil means don't hide any tags."
  1642. :group 'org-agenda-line-format
  1643. :type '(choice
  1644. (const :tag "Hide none" nil)
  1645. (string :tag "Regexp ")))
  1646. (defcustom org-agenda-remove-tags nil
  1647. "Non-nil means remove the tags from the headline copy in the agenda.
  1648. When this is the symbol `prefix', only remove tags when
  1649. `org-agenda-prefix-format' contains a `%T' specifier."
  1650. :group 'org-agenda-line-format
  1651. :type '(choice
  1652. (const :tag "Always" t)
  1653. (const :tag "Never" nil)
  1654. (const :tag "When prefix format contains %T" prefix)))
  1655. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1656. 'org-agenda-remove-tags)
  1657. (defcustom org-agenda-tags-column 'auto
  1658. "Shift tags in agenda items to this column.
  1659. If set to `auto', tags will be automatically aligned to the right
  1660. edge of the window.
  1661. If set to a positive number, tags will be left-aligned to that
  1662. column. If set to a negative number, tags will be right-aligned
  1663. to that column. For example, -80 works well for a normal 80
  1664. character screen."
  1665. :group 'org-agenda-line-format
  1666. :type '(choice
  1667. (const :tag "Automatically align to right edge of window" auto)
  1668. (integer :tag "Specific column" -80))
  1669. :package-version '(Org . "9.1")
  1670. :version "26.1")
  1671. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1672. (defcustom org-agenda-fontify-priorities 'cookies
  1673. "Non-nil means highlight low and high priorities in agenda.
  1674. When t, the highest priority entries are bold, lowest priority italic.
  1675. However, settings in `org-priority-faces' will overrule these faces.
  1676. When this variable is the symbol `cookies', only fontify the
  1677. cookies, not the entire task.
  1678. This may also be an association list of priority faces, whose
  1679. keys are the character values of `org-highest-priority',
  1680. `org-default-priority', and `org-lowest-priority' (the default values
  1681. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1682. color as a string, or a list like `(:background \"Red\")'.
  1683. If it is a color, the variable `org-faces-easy-properties'
  1684. determines if it is a foreground or a background color."
  1685. :group 'org-agenda-line-format
  1686. :type '(choice
  1687. (const :tag "Never" nil)
  1688. (const :tag "Defaults" t)
  1689. (const :tag "Cookies only" cookies)
  1690. (repeat :tag "Specify"
  1691. (list (character :tag "Priority" :value ?A)
  1692. (choice :tag "Face "
  1693. (string :tag "Color")
  1694. (sexp :tag "Face"))))))
  1695. (defcustom org-agenda-day-face-function nil
  1696. "Function called to determine what face should be used to display a day.
  1697. The only argument passed to that function is the day. It should
  1698. returns a face, or nil if does not want to specify a face and let
  1699. the normal rules apply."
  1700. :group 'org-agenda-line-format
  1701. :version "24.1"
  1702. :type '(choice (const nil) (function)))
  1703. (defcustom org-agenda-category-icon-alist nil
  1704. "Alist of category icon to be displayed in agenda views.
  1705. Each entry should have the following format:
  1706. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1707. Where CATEGORY-REGEXP is a regexp matching the categories where
  1708. the icon should be displayed.
  1709. FILE-OR-DATA either a file path or a string containing image data.
  1710. The other fields can be omitted safely if not needed:
  1711. TYPE indicates the image type.
  1712. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1713. image data.
  1714. PROPS are additional image attributes to assign to the image,
  1715. like, e.g. `:ascent center'.
  1716. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1717. If you want to set the display properties yourself, just put a
  1718. list as second element:
  1719. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1720. For example, to display a 16px horizontal space for Emacs
  1721. category, you can use:
  1722. (\"Emacs\" \\='(space . (:width (16))))"
  1723. :group 'org-agenda-line-format
  1724. :version "24.1"
  1725. :type '(alist :key-type (string :tag "Regexp matching category")
  1726. :value-type (choice (list :tag "Icon"
  1727. (string :tag "File or data")
  1728. (symbol :tag "Type")
  1729. (boolean :tag "Data?")
  1730. (repeat :tag "Extra image properties" :inline t symbol))
  1731. (list :tag "Display properties" sexp))))
  1732. (defgroup org-agenda-column-view nil
  1733. "Options concerning column view in the agenda."
  1734. :tag "Org Agenda Column View"
  1735. :group 'org-agenda)
  1736. (defcustom org-agenda-view-columns-initially nil
  1737. "When non-nil, switch to columns view right after creating the agenda."
  1738. :group 'org-agenda-column-view
  1739. :type 'boolean
  1740. :version "26.1"
  1741. :package-version '(Org . "9.0")
  1742. :safe #'booleanp)
  1743. (defcustom org-agenda-columns-show-summaries t
  1744. "Non-nil means show summaries for columns displayed in the agenda view."
  1745. :group 'org-agenda-column-view
  1746. :type 'boolean)
  1747. (defcustom org-agenda-columns-compute-summary-properties t
  1748. "Non-nil means recompute all summary properties before column view.
  1749. When column view in the agenda is listing properties that have a summary
  1750. operator, it can go to all relevant buffers and recompute the summaries
  1751. there. This can mean overhead for the agenda column view, but is necessary
  1752. to have thing up to date.
  1753. As a special case, a CLOCKSUM property also makes sure that the clock
  1754. computations are current."
  1755. :group 'org-agenda-column-view
  1756. :type 'boolean)
  1757. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1758. "Non-nil means the duration of an appointment will add to day effort.
  1759. The property to which appointment durations will be added is the one given
  1760. in the option `org-effort-property'. If an appointment does not have
  1761. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1762. is not set, an appointment without end time will not contribute to the time
  1763. estimate."
  1764. :group 'org-agenda-column-view
  1765. :type 'boolean)
  1766. (defcustom org-agenda-auto-exclude-function nil
  1767. "A function called with a tag to decide if it is filtered on \
  1768. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1769. The sole argument to the function, which is called once for each
  1770. possible tag, is a string giving the name of the tag. The
  1771. function should return either nil if the tag should be included
  1772. as normal, or \"-<TAG>\" to exclude the tag.
  1773. Note that for the purpose of tag filtering, only the lower-case version of
  1774. all tags will be considered, so that this function will only ever see
  1775. the lower-case version of all tags."
  1776. :group 'org-agenda
  1777. :type '(choice (const nil) (function)))
  1778. (defcustom org-agenda-bulk-custom-functions nil
  1779. "Alist of characters and custom functions for bulk actions.
  1780. For example, this value makes those two functions available:
  1781. \\='((?R set-category)
  1782. (?C bulk-cut))
  1783. With selected entries in an agenda buffer, `B R' will call
  1784. the custom function `set-category' on the selected entries.
  1785. Note that functions in this alist don't need to be quoted."
  1786. :type '(alist :key-type character :value-type (group function))
  1787. :version "24.1"
  1788. :group 'org-agenda)
  1789. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1790. "Execute BODY with point at location given by `org-hd-marker' property.
  1791. If STRING is non-nil, the text property will be fetched from position 0
  1792. in that string. If STRING is nil, it will be fetched from the beginning
  1793. of the current line."
  1794. (org-with-gensyms (marker)
  1795. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1796. 'org-hd-marker ,string)))
  1797. (with-current-buffer (marker-buffer ,marker)
  1798. (save-excursion
  1799. (goto-char ,marker)
  1800. ,@body)))))
  1801. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1802. (defun org-add-agenda-custom-command (entry)
  1803. "Replace or add a command in `org-agenda-custom-commands'.
  1804. This is mostly for hacking and trying a new command - once the command
  1805. works you probably want to add it to `org-agenda-custom-commands' for good."
  1806. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1807. (if ass
  1808. (setcdr ass (cdr entry))
  1809. (push entry org-agenda-custom-commands))))
  1810. ;;; Define the org-agenda-mode
  1811. (defvar org-agenda-mode-map (make-sparse-keymap)
  1812. "Keymap for `org-agenda-mode'.")
  1813. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1814. (defvar org-agenda-menu) ; defined later in this file.
  1815. (defvar org-agenda-restrict nil) ; defined later in this file.
  1816. (defvar org-agenda-follow-mode nil)
  1817. (defvar org-agenda-entry-text-mode nil)
  1818. (defvar org-agenda-clockreport-mode nil)
  1819. (defvar org-agenda-show-log nil
  1820. "When non-nil, show the log in the agenda.
  1821. Do not set this directly; instead use
  1822. `org-agenda-start-with-log-mode', which see.")
  1823. (defvar org-agenda-redo-command nil)
  1824. (defvar org-agenda-query-string nil)
  1825. (defvar org-agenda-mode-hook nil
  1826. "Hook run after `org-agenda-mode' is turned on.
  1827. The buffer is still writable when this hook is called.")
  1828. (defvar org-agenda-type nil)
  1829. (defvar org-agenda-force-single-file nil)
  1830. (defvar org-agenda-bulk-marked-entries nil
  1831. "List of markers that refer to marked entries in the agenda.")
  1832. (defvar org-agenda-current-date nil
  1833. "Active date when building the agenda.")
  1834. ;;; Multiple agenda buffers support
  1835. (defcustom org-agenda-sticky nil
  1836. "Non-nil means agenda q key will bury agenda buffers.
  1837. Agenda commands will then show existing buffer instead of generating new ones.
  1838. When nil, `q' will kill the single agenda buffer."
  1839. :group 'org-agenda
  1840. :version "24.3"
  1841. :type 'boolean)
  1842. ;;;###autoload
  1843. (defun org-toggle-sticky-agenda (&optional arg)
  1844. "Toggle `org-agenda-sticky'."
  1845. (interactive "P")
  1846. (let ((new-value (if arg
  1847. (> (prefix-numeric-value arg) 0)
  1848. (not org-agenda-sticky))))
  1849. (if (equal new-value org-agenda-sticky)
  1850. (and (called-interactively-p 'interactive)
  1851. (message "Sticky agenda was already %s"
  1852. (if org-agenda-sticky "enabled" "disabled")))
  1853. (setq org-agenda-sticky new-value)
  1854. (org-agenda-kill-all-agenda-buffers)
  1855. (and (called-interactively-p 'interactive)
  1856. (message "Sticky agenda %s"
  1857. (if org-agenda-sticky "enabled" "disabled"))))))
  1858. (defvar org-agenda-buffer nil
  1859. "Agenda buffer currently being generated.")
  1860. (defvar org-agenda-last-prefix-arg nil)
  1861. (defvar org-agenda-this-buffer-name nil)
  1862. (defvar org-agenda-doing-sticky-redo nil)
  1863. (defvar org-agenda-this-buffer-is-sticky nil)
  1864. (defvar org-agenda-last-indirect-buffer nil
  1865. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1866. (defvar org-agenda-lprops nil)
  1867. (defconst org-agenda-local-vars
  1868. '(org-agenda-this-buffer-name
  1869. org-agenda-undo-list
  1870. org-agenda-pending-undo-list
  1871. org-agenda-follow-mode
  1872. org-agenda-entry-text-mode
  1873. org-agenda-clockreport-mode
  1874. org-agenda-show-log
  1875. org-agenda-redo-command
  1876. org-agenda-query-string
  1877. org-agenda-type
  1878. org-agenda-bulk-marked-entries
  1879. org-agenda-undo-has-started-in
  1880. org-agenda-info
  1881. org-agenda-pre-window-conf
  1882. org-agenda-columns-active
  1883. org-agenda-tag-filter
  1884. org-agenda-category-filter
  1885. org-agenda-top-headline-filter
  1886. org-agenda-regexp-filter
  1887. org-agenda-effort-filter
  1888. org-agenda-markers
  1889. org-agenda-last-search-view-search-was-boolean
  1890. org-agenda-last-indirect-buffer
  1891. org-agenda-filtered-by-category
  1892. org-agenda-filter-form
  1893. org-agenda-cycle-counter
  1894. org-agenda-lprops
  1895. org-agenda-last-prefix-arg)
  1896. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1897. (defun org-agenda-mode ()
  1898. "Mode for time-sorted view on action items in Org files.
  1899. The following commands are available:
  1900. \\{org-agenda-mode-map}"
  1901. (interactive)
  1902. (cond (org-agenda-doing-sticky-redo
  1903. ;; Refreshing sticky agenda-buffer
  1904. ;;
  1905. ;; Preserve the value of `org-agenda-local-vars' variables,
  1906. ;; while letting `kill-all-local-variables' kill the rest
  1907. (let ((save (buffer-local-variables)))
  1908. (kill-all-local-variables)
  1909. (mapc #'make-local-variable org-agenda-local-vars)
  1910. (dolist (elem save)
  1911. (pcase elem
  1912. (`(,var . ,val) ;ignore unbound variables
  1913. (when (and val (memq var org-agenda-local-vars))
  1914. (set var val))))))
  1915. (setq-local org-agenda-this-buffer-is-sticky t))
  1916. (org-agenda-sticky
  1917. ;; Creating a sticky Agenda buffer for the first time
  1918. (kill-all-local-variables)
  1919. (mapc 'make-local-variable org-agenda-local-vars)
  1920. (setq-local org-agenda-this-buffer-is-sticky t))
  1921. (t
  1922. ;; Creating a non-sticky agenda buffer
  1923. (kill-all-local-variables)
  1924. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1925. (setq org-agenda-undo-list nil
  1926. org-agenda-pending-undo-list nil
  1927. org-agenda-bulk-marked-entries nil)
  1928. (setq major-mode 'org-agenda-mode)
  1929. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1930. (setq-local font-lock-global-modes (list 'not major-mode))
  1931. (setq mode-name "Org-Agenda")
  1932. (setq indent-tabs-mode nil)
  1933. (use-local-map org-agenda-mode-map)
  1934. (easy-menu-add org-agenda-menu)
  1935. (if org-startup-truncated (setq truncate-lines t))
  1936. (setq-local line-move-visual nil)
  1937. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1938. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1939. ;; Make sure properties are removed when copying text
  1940. (add-hook 'filter-buffer-substring-functions
  1941. (lambda (fun start end delete)
  1942. (substring-no-properties (funcall fun start end delete)))
  1943. nil t)
  1944. (unless org-agenda-keep-modes
  1945. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1946. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1947. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1948. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1949. (add-to-invisibility-spec '(org-filtered))
  1950. (add-to-invisibility-spec '(org-link))
  1951. (easy-menu-change
  1952. '("Agenda") "Agenda Files"
  1953. (append
  1954. (list
  1955. (vector
  1956. (if (get 'org-agenda-files 'org-restrict)
  1957. "Restricted to single file"
  1958. "Edit File List")
  1959. '(org-edit-agenda-file-list)
  1960. (not (get 'org-agenda-files 'org-restrict)))
  1961. "--")
  1962. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1963. (org-agenda-set-mode-name)
  1964. (apply
  1965. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1966. (list 'org-agenda-mode-hook)))
  1967. (substitute-key-definition 'undo 'org-agenda-undo
  1968. org-agenda-mode-map global-map)
  1969. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1970. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1971. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1972. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1974. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1975. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1976. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1977. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1978. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1979. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1980. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1981. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1982. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1983. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1984. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1985. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1986. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1988. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1989. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1990. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1991. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1992. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1993. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1994. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1995. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1996. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1997. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1998. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1999. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  2001. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  2002. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  2003. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  2004. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  2005. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  2006. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2007. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2008. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2009. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2010. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2011. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2012. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2013. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2014. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2015. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2016. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2017. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2018. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2019. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2022. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2023. (while l (org-defkey org-agenda-mode-map
  2024. (int-to-string (pop l)) 'digit-argument)))
  2025. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2026. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2027. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2028. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2029. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2030. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2031. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2032. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2033. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2034. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2035. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2036. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2038. 'org-clock-modify-effort-estimate)
  2039. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2040. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2041. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2042. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2043. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2044. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2045. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2046. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2047. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2048. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2049. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2050. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2051. (substitute-key-definition 'next-line 'org-agenda-next-line
  2052. org-agenda-mode-map global-map)
  2053. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2054. org-agenda-mode-map global-map)
  2055. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2056. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2057. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2058. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2059. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2060. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2061. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2062. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2063. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2064. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2065. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2066. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2067. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2068. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2069. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2070. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2071. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2072. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2074. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2075. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2076. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2077. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2078. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2079. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2080. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2081. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2082. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2083. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2085. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2086. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2087. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2088. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2089. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2090. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2091. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2092. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2093. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2094. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2095. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2096. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2097. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2099. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2100. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2101. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2102. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2103. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2104. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2105. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2106. (when org-agenda-mouse-1-follows-link
  2107. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2108. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2109. '("Agenda"
  2110. ("Agenda Files")
  2111. "--"
  2112. ("Agenda Dates"
  2113. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2114. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2115. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2116. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2117. "--"
  2118. ("View"
  2119. ["Day View" org-agenda-day-view
  2120. :active (org-agenda-check-type nil 'agenda)
  2121. :style radio :selected (eq org-agenda-current-span 'day)
  2122. :keys "v d (or just d)"]
  2123. ["Week View" org-agenda-week-view
  2124. :active (org-agenda-check-type nil 'agenda)
  2125. :style radio :selected (eq org-agenda-current-span 'week)
  2126. :keys "v w"]
  2127. ["Fortnight View" org-agenda-fortnight-view
  2128. :active (org-agenda-check-type nil 'agenda)
  2129. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2130. :keys "v t"]
  2131. ["Month View" org-agenda-month-view
  2132. :active (org-agenda-check-type nil 'agenda)
  2133. :style radio :selected (eq org-agenda-current-span 'month)
  2134. :keys "v m"]
  2135. ["Year View" org-agenda-year-view
  2136. :active (org-agenda-check-type nil 'agenda)
  2137. :style radio :selected (eq org-agenda-current-span 'year)
  2138. :keys "v y"]
  2139. "--"
  2140. ["Include Diary" org-agenda-toggle-diary
  2141. :style toggle :selected org-agenda-include-diary
  2142. :active (org-agenda-check-type nil 'agenda)]
  2143. ["Include Deadlines" org-agenda-toggle-deadlines
  2144. :style toggle :selected org-agenda-include-deadlines
  2145. :active (org-agenda-check-type nil 'agenda)]
  2146. ["Use Time Grid" org-agenda-toggle-time-grid
  2147. :style toggle :selected org-agenda-use-time-grid
  2148. :active (org-agenda-check-type nil 'agenda)]
  2149. "--"
  2150. ["Show clock report" org-agenda-clockreport-mode
  2151. :style toggle :selected org-agenda-clockreport-mode
  2152. :active (org-agenda-check-type nil 'agenda)]
  2153. ["Show some entry text" org-agenda-entry-text-mode
  2154. :style toggle :selected org-agenda-entry-text-mode
  2155. :active t]
  2156. "--"
  2157. ["Show Logbook entries" org-agenda-log-mode
  2158. :style toggle :selected org-agenda-show-log
  2159. :active (org-agenda-check-type nil 'agenda)
  2160. :keys "v l (or just l)"]
  2161. ["Include archived trees" org-agenda-archives-mode
  2162. :style toggle :selected org-agenda-archives-mode :active t
  2163. :keys "v a"]
  2164. ["Include archive files" (org-agenda-archives-mode t)
  2165. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2166. :keys "v A"]
  2167. "--"
  2168. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2169. ["Write view to file" org-agenda-write t]
  2170. ["Rebuild buffer" org-agenda-redo t]
  2171. ["Save all Org buffers" org-save-all-org-buffers t]
  2172. "--"
  2173. ["Show original entry" org-agenda-show t]
  2174. ["Go To (other window)" org-agenda-goto t]
  2175. ["Go To (this window)" org-agenda-switch-to t]
  2176. ["Capture with cursor date" org-agenda-capture t]
  2177. ["Follow Mode" org-agenda-follow-mode
  2178. :style toggle :selected org-agenda-follow-mode :active t]
  2179. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2180. "--"
  2181. ("TODO"
  2182. ["Cycle TODO" org-agenda-todo t]
  2183. ["Next TODO set" org-agenda-todo-nextset t]
  2184. ["Previous TODO set" org-agenda-todo-previousset t]
  2185. ["Add note" org-agenda-add-note t])
  2186. ("Archive/Refile/Delete"
  2187. ["Archive default" org-agenda-archive-default t]
  2188. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2189. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2190. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2191. ["Archive subtree" org-agenda-archive t]
  2192. "--"
  2193. ["Refile" org-agenda-refile t]
  2194. "--"
  2195. ["Delete subtree" org-agenda-kill t])
  2196. ("Bulk action"
  2197. ["Mark entry" org-agenda-bulk-mark t]
  2198. ["Mark all" org-agenda-bulk-mark-all t]
  2199. ["Unmark entry" org-agenda-bulk-unmark t]
  2200. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2201. ["Toggle mark" org-agenda-bulk-toggle t]
  2202. ["Toggle all" org-agenda-bulk-toggle-all t]
  2203. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2204. ["Act on all marked" org-agenda-bulk-action t]
  2205. "--"
  2206. ("Tags and Properties"
  2207. ["Show all Tags" org-agenda-show-tags t]
  2208. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2209. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2210. "--"
  2211. ["Column View" org-columns t])
  2212. ("Deadline/Schedule"
  2213. ["Schedule" org-agenda-schedule t]
  2214. ["Set Deadline" org-agenda-deadline t]
  2215. "--"
  2216. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2217. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2218. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2219. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2220. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2221. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2222. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2223. ("Clock and Effort"
  2224. ["Clock in" org-agenda-clock-in t]
  2225. ["Clock out" org-agenda-clock-out t]
  2226. ["Clock cancel" org-agenda-clock-cancel t]
  2227. ["Goto running clock" org-clock-goto t]
  2228. "--"
  2229. ["Set Effort" org-agenda-set-effort t]
  2230. ["Change clocked effort" org-clock-modify-effort-estimate
  2231. (org-clock-is-active)])
  2232. ("Priority"
  2233. ["Set Priority" org-agenda-priority t]
  2234. ["Increase Priority" org-agenda-priority-up t]
  2235. ["Decrease Priority" org-agenda-priority-down t]
  2236. ["Show Priority" org-show-priority t])
  2237. ("Calendar/Diary"
  2238. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2239. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2240. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2241. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2242. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2243. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2244. "--"
  2245. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2246. "--"
  2247. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2248. "--"
  2249. ("MobileOrg"
  2250. ["Push Files and Views" org-mobile-push t]
  2251. ["Get Captured and Flagged" org-mobile-pull t]
  2252. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2253. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2254. "--"
  2255. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2256. "--"
  2257. ["Quit" org-agenda-quit t]
  2258. ["Exit and Release Buffers" org-agenda-exit t]
  2259. ))
  2260. ;;; Agenda undo
  2261. (defvar org-agenda-allow-remote-undo t
  2262. "Non-nil means allow remote undo from the agenda buffer.")
  2263. (defvar org-agenda-undo-has-started-in nil
  2264. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2265. (defun org-agenda-undo ()
  2266. "Undo a remote editing step in the agenda.
  2267. This undoes changes both in the agenda buffer and in the remote buffer
  2268. that have been changed along."
  2269. (interactive)
  2270. (or org-agenda-allow-remote-undo
  2271. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2272. (if (not (eq this-command last-command))
  2273. (setq org-agenda-undo-has-started-in nil
  2274. org-agenda-pending-undo-list org-agenda-undo-list))
  2275. (if (not org-agenda-pending-undo-list)
  2276. (user-error "No further undo information"))
  2277. (let* ((entry (pop org-agenda-pending-undo-list))
  2278. buf line cmd rembuf)
  2279. (setq cmd (pop entry) line (pop entry))
  2280. (setq rembuf (nth 2 entry))
  2281. (org-with-remote-undo rembuf
  2282. (while (bufferp (setq buf (pop entry)))
  2283. (if (pop entry)
  2284. (with-current-buffer buf
  2285. (let ((last-undo-buffer buf)
  2286. (inhibit-read-only t))
  2287. (unless (memq buf org-agenda-undo-has-started-in)
  2288. (push buf org-agenda-undo-has-started-in)
  2289. (make-local-variable 'pending-undo-list)
  2290. (undo-start))
  2291. (while (and pending-undo-list
  2292. (listp pending-undo-list)
  2293. (not (car pending-undo-list)))
  2294. (pop pending-undo-list))
  2295. (undo-more 1))))))
  2296. (org-goto-line line)
  2297. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2298. (defun org-verify-change-for-undo (l1 l2)
  2299. "Verify that a real change occurred between the undo lists L1 and L2."
  2300. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2301. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2302. (not (eq l1 l2)))
  2303. ;;; Agenda dispatch
  2304. (defvar org-agenda-restrict-begin (make-marker))
  2305. (defvar org-agenda-restrict-end (make-marker))
  2306. (defvar org-agenda-last-dispatch-buffer nil)
  2307. (defvar org-agenda-overriding-restriction nil)
  2308. (defcustom org-agenda-custom-commands-contexts nil
  2309. "Alist of custom agenda keys and contextual rules.
  2310. For example, if you have a custom agenda command \"p\" and you
  2311. want this command to be accessible only from plain text files,
  2312. use this:
  2313. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2314. Here are the available contexts definitions:
  2315. in-file: command displayed only in matching files
  2316. in-mode: command displayed only in matching modes
  2317. not-in-file: command not displayed in matching files
  2318. not-in-mode: command not displayed in matching modes
  2319. in-buffer: command displayed only in matching buffers
  2320. not-in-buffer: command not displayed in matching buffers
  2321. [function]: a custom function taking no argument
  2322. If you define several checks, the agenda command will be
  2323. accessible if there is at least one valid check.
  2324. You can also bind a key to another agenda custom command
  2325. depending on contextual rules.
  2326. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2327. Here it means: in .txt files, use \"p\" as the key for the
  2328. agenda command otherwise associated with \"q\". (The command
  2329. originally associated with \"q\" is not displayed to avoid
  2330. duplicates.)"
  2331. :version "24.3"
  2332. :group 'org-agenda-custom-commands
  2333. :type '(repeat (list :tag "Rule"
  2334. (string :tag " Agenda key")
  2335. (string :tag "Replace by command")
  2336. (repeat :tag "Available when"
  2337. (choice
  2338. (cons :tag "Condition"
  2339. (choice
  2340. (const :tag "In file" in-file)
  2341. (const :tag "Not in file" not-in-file)
  2342. (const :tag "In buffer" in-buffer)
  2343. (const :tag "Not in buffer" not-in-buffer)
  2344. (const :tag "In mode" in-mode)
  2345. (const :tag "Not in mode" not-in-mode))
  2346. (regexp))
  2347. (function :tag "Custom function"))))))
  2348. (defcustom org-agenda-max-entries nil
  2349. "Maximum number of entries to display in an agenda.
  2350. This can be nil (no limit) or an integer or an alist of agenda
  2351. types with an associated number of entries to display in this
  2352. type."
  2353. :version "24.4"
  2354. :package-version '(Org . "8.0")
  2355. :group 'org-agenda-custom-commands
  2356. :type '(choice (symbol :tag "No limit" nil)
  2357. (integer :tag "Max number of entries")
  2358. (repeat
  2359. (cons (choice :tag "Agenda type"
  2360. (const agenda)
  2361. (const todo)
  2362. (const tags)
  2363. (const search))
  2364. (integer :tag "Max number of entries")))))
  2365. (defcustom org-agenda-max-todos nil
  2366. "Maximum number of TODOs to display in an agenda.
  2367. This can be nil (no limit) or an integer or an alist of agenda
  2368. types with an associated number of entries to display in this
  2369. type."
  2370. :version "24.4"
  2371. :package-version '(Org . "8.0")
  2372. :group 'org-agenda-custom-commands
  2373. :type '(choice (symbol :tag "No limit" nil)
  2374. (integer :tag "Max number of TODOs")
  2375. (repeat
  2376. (cons (choice :tag "Agenda type"
  2377. (const agenda)
  2378. (const todo)
  2379. (const tags)
  2380. (const search))
  2381. (integer :tag "Max number of TODOs")))))
  2382. (defcustom org-agenda-max-tags nil
  2383. "Maximum number of tagged entries to display in an agenda.
  2384. This can be nil (no limit) or an integer or an alist of agenda
  2385. types with an associated number of entries to display in this
  2386. type."
  2387. :version "24.4"
  2388. :package-version '(Org . "8.0")
  2389. :group 'org-agenda-custom-commands
  2390. :type '(choice (symbol :tag "No limit" nil)
  2391. (integer :tag "Max number of tagged entries")
  2392. (repeat
  2393. (cons (choice :tag "Agenda type"
  2394. (const agenda)
  2395. (const todo)
  2396. (const tags)
  2397. (const search))
  2398. (integer :tag "Max number of tagged entries")))))
  2399. (defcustom org-agenda-max-effort nil
  2400. "Maximum cumulated effort duration for the agenda.
  2401. This can be nil (no limit) or a number of minutes (as an integer)
  2402. or an alist of agenda types with an associated number of minutes
  2403. to limit entries to in this type."
  2404. :version "24.4"
  2405. :package-version '(Org . "8.0")
  2406. :group 'org-agenda-custom-commands
  2407. :type '(choice (symbol :tag "No limit" nil)
  2408. (integer :tag "Max number of minutes")
  2409. (repeat
  2410. (cons (choice :tag "Agenda type"
  2411. (const agenda)
  2412. (const todo)
  2413. (const tags)
  2414. (const search))
  2415. (integer :tag "Max number of minutes")))))
  2416. (defvar org-agenda-keep-restricted-file-list nil)
  2417. (defvar org-keys nil)
  2418. (defvar org-match nil)
  2419. ;;;###autoload
  2420. (defun org-agenda (&optional arg org-keys restriction)
  2421. "Dispatch agenda commands to collect entries to the agenda buffer.
  2422. Prompts for a command to execute. Any prefix arg will be passed
  2423. on to the selected command. The default selections are:
  2424. a Call `org-agenda-list' to display the agenda for current day or week.
  2425. t Call `org-todo-list' to display the global todo list.
  2426. T Call `org-todo-list' to display the global todo list, select only
  2427. entries with a specific TODO keyword (the user gets a prompt).
  2428. m Call `org-tags-view' to display headlines with tags matching
  2429. a condition (the user is prompted for the condition).
  2430. M Like `m', but select only TODO entries, no ordinary headlines.
  2431. e Export views to associated files.
  2432. s Search entries for keywords.
  2433. S Search entries for keywords, only with TODO keywords.
  2434. / Multi occur across all agenda files and also files listed
  2435. in `org-agenda-text-search-extra-files'.
  2436. < Restrict agenda commands to buffer, subtree, or region.
  2437. Press several times to get the desired effect.
  2438. > Remove a previous restriction.
  2439. # List \"stuck\" projects.
  2440. ! Configure what \"stuck\" means.
  2441. C Configure custom agenda commands.
  2442. More commands can be added by configuring the variable
  2443. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2444. searches can be pre-defined in this way.
  2445. If the current buffer is in Org mode and visiting a file, you can also
  2446. first press `<' once to indicate that the agenda should be temporarily
  2447. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2448. Pressing `<' twice means to restrict to the current subtree or region
  2449. \(if active)."
  2450. (interactive "P")
  2451. (catch 'exit
  2452. (let* ((prefix-descriptions nil)
  2453. (org-agenda-buffer-name org-agenda-buffer-name)
  2454. (org-agenda-window-setup (if (equal (buffer-name)
  2455. org-agenda-buffer-name)
  2456. 'current-window
  2457. org-agenda-window-setup))
  2458. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2459. (org-agenda-custom-commands
  2460. ;; normalize different versions
  2461. (delq nil
  2462. (mapcar
  2463. (lambda (x)
  2464. (cond ((stringp (cdr x))
  2465. (push x prefix-descriptions)
  2466. nil)
  2467. ((stringp (nth 1 x)) x)
  2468. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2469. (t (cons (car x) (cons "" (cdr x))))))
  2470. org-agenda-custom-commands)))
  2471. (org-agenda-custom-commands
  2472. (org-contextualize-keys
  2473. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2474. (buf (current-buffer))
  2475. (bfn (buffer-file-name (buffer-base-buffer)))
  2476. entry key type org-match lprops ans)
  2477. ;; Turn off restriction unless there is an overriding one,
  2478. (unless org-agenda-overriding-restriction
  2479. (unless org-agenda-keep-restricted-file-list
  2480. ;; There is a request to keep the file list in place
  2481. (put 'org-agenda-files 'org-restrict nil))
  2482. (setq org-agenda-restrict nil)
  2483. (move-marker org-agenda-restrict-begin nil)
  2484. (move-marker org-agenda-restrict-end nil))
  2485. ;; Delete old local properties
  2486. (put 'org-agenda-redo-command 'org-lprops nil)
  2487. ;; Delete previously set last-arguments
  2488. (put 'org-agenda-redo-command 'last-args nil)
  2489. ;; Remember where this call originated
  2490. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2491. (unless org-keys
  2492. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2493. org-keys (car ans)
  2494. restriction (cdr ans)))
  2495. ;; If we have sticky agenda buffers, set a name for the buffer,
  2496. ;; depending on the invoking keys. The user may still set this
  2497. ;; as a command option, which will overwrite what we do here.
  2498. (if org-agenda-sticky
  2499. (setq org-agenda-buffer-name
  2500. (format "*Org Agenda(%s)*" org-keys)))
  2501. ;; Establish the restriction, if any
  2502. (when (and (not org-agenda-overriding-restriction) restriction)
  2503. (put 'org-agenda-files 'org-restrict (list bfn))
  2504. (cond
  2505. ((eq restriction 'region)
  2506. (setq org-agenda-restrict (current-buffer))
  2507. (move-marker org-agenda-restrict-begin (region-beginning))
  2508. (move-marker org-agenda-restrict-end (region-end)))
  2509. ((eq restriction 'subtree)
  2510. (save-excursion
  2511. (setq org-agenda-restrict (current-buffer))
  2512. (org-back-to-heading t)
  2513. (move-marker org-agenda-restrict-begin (point))
  2514. (move-marker org-agenda-restrict-end
  2515. (progn (org-end-of-subtree t)))))))
  2516. ;; For example the todo list should not need it (but does...)
  2517. (cond
  2518. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2519. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2520. (progn
  2521. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2522. lprops (nth 4 entry))
  2523. (if org-agenda-sticky
  2524. (setq org-agenda-buffer-name
  2525. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2526. (format "*Org Agenda(%s)*" org-keys))))
  2527. (put 'org-agenda-redo-command 'org-lprops lprops)
  2528. (cond
  2529. ((eq type 'agenda)
  2530. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2531. ((eq type 'agenda*)
  2532. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2533. ((eq type 'alltodo)
  2534. (org-let lprops '(org-todo-list current-prefix-arg)))
  2535. ((eq type 'search)
  2536. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2537. ((eq type 'stuck)
  2538. (org-let lprops '(org-agenda-list-stuck-projects
  2539. current-prefix-arg)))
  2540. ((eq type 'tags)
  2541. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2542. ((eq type 'tags-todo)
  2543. (org-let lprops '(org-tags-view '(4) org-match)))
  2544. ((eq type 'todo)
  2545. (org-let lprops '(org-todo-list org-match)))
  2546. ((eq type 'tags-tree)
  2547. (org-check-for-org-mode)
  2548. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2549. ((eq type 'todo-tree)
  2550. (org-check-for-org-mode)
  2551. (org-let lprops
  2552. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2553. (regexp-quote org-match) "\\>"))))
  2554. ((eq type 'occur-tree)
  2555. (org-check-for-org-mode)
  2556. (org-let lprops '(org-occur org-match)))
  2557. ((functionp type)
  2558. (org-let lprops '(funcall type org-match)))
  2559. ((fboundp type)
  2560. (org-let lprops '(funcall type org-match)))
  2561. (t (user-error "Invalid custom agenda command type %s" type))))
  2562. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2563. ((equal org-keys "C")
  2564. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2565. (customize-variable 'org-agenda-custom-commands))
  2566. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2567. ((equal org-keys "s") (call-interactively 'org-search-view))
  2568. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2569. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2570. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2571. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2572. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2573. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2574. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2575. (add-hook
  2576. 'post-command-hook
  2577. (lambda ()
  2578. (unless (current-message)
  2579. (let* ((m (org-agenda-get-any-marker))
  2580. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2581. (when note
  2582. (message (concat
  2583. "FLAGGING-NOTE ([?] for more info): "
  2584. (org-add-props
  2585. (replace-regexp-in-string
  2586. "\\\\n" "//"
  2587. (copy-sequence note))
  2588. nil 'face 'org-warning)))))))
  2589. t t))
  2590. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2591. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2592. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2593. (t (user-error "Invalid agenda key"))))))
  2594. (defvar org-agenda-multi)
  2595. (defun org-agenda-append-agenda ()
  2596. "Append another agenda view to the current one.
  2597. This function allows interactive building of block agendas.
  2598. Agenda views are separated by `org-agenda-block-separator'."
  2599. (interactive)
  2600. (unless (derived-mode-p 'org-agenda-mode)
  2601. (user-error "Can only append from within agenda buffer"))
  2602. (let ((org-agenda-multi t))
  2603. (org-agenda)
  2604. (widen)
  2605. (org-agenda-finalize)
  2606. (setq buffer-read-only t)
  2607. (org-agenda-fit-window-to-buffer)))
  2608. (defun org-agenda-normalize-custom-commands (cmds)
  2609. "Normalize custom commands CMDS."
  2610. (delq nil
  2611. (mapcar
  2612. (lambda (x)
  2613. (cond ((stringp (cdr x)) nil)
  2614. ((stringp (nth 1 x)) x)
  2615. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2616. (t (cons (car x) (cons "" (cdr x))))))
  2617. cmds)))
  2618. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2619. "The user interface for selecting an agenda command."
  2620. (catch 'exit
  2621. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2622. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2623. (region-p (org-region-active-p))
  2624. (custom org-agenda-custom-commands)
  2625. (selstring "")
  2626. restriction second-time
  2627. c entry key type match prefixes rmheader header-end custom1 desc
  2628. line lines left right n n1)
  2629. (save-window-excursion
  2630. (delete-other-windows)
  2631. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2632. (erase-buffer)
  2633. (insert (eval-when-compile
  2634. (let ((header
  2635. "Press key for an agenda command:
  2636. -------------------------------- < Buffer, subtree/region restriction
  2637. a Agenda for current week or day > Remove restriction
  2638. t List of all TODO entries e Export agenda views
  2639. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2640. s Search for keywords M Like m, but only TODO entries
  2641. / Multi-occur S Like s, but only TODO entries
  2642. ? Find :FLAGGED: entries C Configure custom agenda commands
  2643. * Toggle sticky agenda views # List stuck projects (!=configure)
  2644. ")
  2645. (start 0))
  2646. (while (string-match
  2647. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2648. header start)
  2649. (setq start (match-end 0))
  2650. (add-text-properties (match-beginning 2) (match-end 2)
  2651. '(face bold) header))
  2652. header)))
  2653. (setq header-end (point-marker))
  2654. (while t
  2655. (setq custom1 custom)
  2656. (when (eq rmheader t)
  2657. (org-goto-line 1)
  2658. (re-search-forward ":" nil t)
  2659. (delete-region (match-end 0) (point-at-eol))
  2660. (forward-char 1)
  2661. (looking-at "-+")
  2662. (delete-region (match-end 0) (point-at-eol))
  2663. (move-marker header-end (match-end 0)))
  2664. (goto-char header-end)
  2665. (delete-region (point) (point-max))
  2666. ;; Produce all the lines that describe custom commands and prefixes
  2667. (setq lines nil)
  2668. (while (setq entry (pop custom1))
  2669. (setq key (car entry) desc (nth 1 entry)
  2670. type (nth 2 entry)
  2671. match (nth 3 entry))
  2672. (if (> (length key) 1)
  2673. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2674. (setq line
  2675. (format
  2676. "%-4s%-14s"
  2677. (org-add-props (copy-sequence key)
  2678. '(face bold))
  2679. (cond
  2680. ((string-match "\\S-" desc) desc)
  2681. ((eq type 'agenda) "Agenda for current week or day")
  2682. ((eq type 'agenda*) "Appointments for current week or day")
  2683. ((eq type 'alltodo) "List of all TODO entries")
  2684. ((eq type 'search) "Word search")
  2685. ((eq type 'stuck) "List of stuck projects")
  2686. ((eq type 'todo) "TODO keyword")
  2687. ((eq type 'tags) "Tags query")
  2688. ((eq type 'tags-todo) "Tags (TODO)")
  2689. ((eq type 'tags-tree) "Tags tree")
  2690. ((eq type 'todo-tree) "TODO kwd tree")
  2691. ((eq type 'occur-tree) "Occur tree")
  2692. ((functionp type) (if (symbolp type)
  2693. (symbol-name type)
  2694. "Lambda expression"))
  2695. (t "???"))))
  2696. (if org-agenda-menu-show-matcher
  2697. (setq line
  2698. (concat line ": "
  2699. (cond
  2700. ((stringp match)
  2701. (setq match (copy-sequence match))
  2702. (org-add-props match nil 'face 'org-warning))
  2703. ((listp type)
  2704. (format "set of %d commands" (length type))))))
  2705. (if (org-string-nw-p match)
  2706. (add-text-properties
  2707. 0 (length line) (list 'help-echo
  2708. (concat "Matcher: " match)) line)))
  2709. (push line lines)))
  2710. (setq lines (nreverse lines))
  2711. (when prefixes
  2712. (mapc (lambda (x)
  2713. (push
  2714. (format "%s %s"
  2715. (org-add-props (char-to-string x)
  2716. nil 'face 'bold)
  2717. (or (cdr (assoc (concat selstring
  2718. (char-to-string x))
  2719. prefix-descriptions))
  2720. "Prefix key"))
  2721. lines))
  2722. prefixes))
  2723. ;; Check if we should display in two columns
  2724. (if org-agenda-menu-two-columns
  2725. (progn
  2726. (setq n (length lines)
  2727. n1 (+ (/ n 2) (mod n 2))
  2728. right (nthcdr n1 lines)
  2729. left (copy-sequence lines))
  2730. (setcdr (nthcdr (1- n1) left) nil))
  2731. (setq left lines right nil))
  2732. (while left
  2733. (insert "\n" (pop left))
  2734. (when right
  2735. (if (< (current-column) 40)
  2736. (move-to-column 40 t)
  2737. (insert " "))
  2738. (insert (pop right))))
  2739. ;; Make the window the right size
  2740. (goto-char (point-min))
  2741. (if second-time
  2742. (if (not (pos-visible-in-window-p (point-max)))
  2743. (org-fit-window-to-buffer))
  2744. (setq second-time t)
  2745. (org-fit-window-to-buffer))
  2746. ;; Ask for selection
  2747. (message "Press key for agenda command%s:"
  2748. (if (or restrict-ok org-agenda-overriding-restriction)
  2749. (if org-agenda-overriding-restriction
  2750. " (restriction lock active)"
  2751. (if restriction
  2752. (format " (restricted to %s)" restriction)
  2753. " (unrestricted)"))
  2754. ""))
  2755. (setq c (read-char-exclusive))
  2756. (message "")
  2757. (cond
  2758. ((assoc (char-to-string c) custom)
  2759. (setq selstring (concat selstring (char-to-string c)))
  2760. (throw 'exit (cons selstring restriction)))
  2761. ((memq c prefixes)
  2762. (setq selstring (concat selstring (char-to-string c))
  2763. prefixes nil
  2764. rmheader (or rmheader t)
  2765. custom (delq nil (mapcar
  2766. (lambda (x)
  2767. (if (or (= (length (car x)) 1)
  2768. (/= (string-to-char (car x)) c))
  2769. nil
  2770. (cons (substring (car x) 1) (cdr x))))
  2771. custom))))
  2772. ((eq c ?*)
  2773. (call-interactively 'org-toggle-sticky-agenda)
  2774. (sit-for 2))
  2775. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2776. (message "Restriction is only possible in Org buffers")
  2777. (ding) (sit-for 1))
  2778. ((eq c ?1)
  2779. (org-agenda-remove-restriction-lock 'noupdate)
  2780. (setq restriction 'buffer))
  2781. ((eq c ?0)
  2782. (org-agenda-remove-restriction-lock 'noupdate)
  2783. (setq restriction (if region-p 'region 'subtree)))
  2784. ((eq c ?<)
  2785. (org-agenda-remove-restriction-lock 'noupdate)
  2786. (setq restriction
  2787. (cond
  2788. ((eq restriction 'buffer)
  2789. (if region-p 'region 'subtree))
  2790. ((memq restriction '(subtree region))
  2791. nil)
  2792. (t 'buffer))))
  2793. ((eq c ?>)
  2794. (org-agenda-remove-restriction-lock 'noupdate)
  2795. (setq restriction nil))
  2796. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2797. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2798. ((and (> (length selstring) 0) (eq c ?\d))
  2799. (delete-window)
  2800. (org-agenda-get-restriction-and-command prefix-descriptions))
  2801. ((equal c ?q) (error "Abort"))
  2802. (t (user-error "Invalid key %c" c))))))))
  2803. (defun org-agenda-fit-window-to-buffer ()
  2804. "Fit the window to the buffer size."
  2805. (and (memq org-agenda-window-setup '(reorganize-frame))
  2806. (fboundp 'fit-window-to-buffer)
  2807. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2808. (= (car org-agenda-window-frame-fractions) 1.0))
  2809. (delete-other-windows)
  2810. (org-fit-window-to-buffer
  2811. nil
  2812. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2813. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2814. (defvar org-cmd nil)
  2815. (defvar org-agenda-overriding-cmd nil)
  2816. (defvar org-agenda-overriding-arguments nil)
  2817. (defvar org-agenda-overriding-cmd-arguments nil)
  2818. (defun org-agenda-run-series (name series)
  2819. "Run agenda NAME as a SERIES of agenda commands."
  2820. (org-let (nth 1 series) '(org-agenda-prepare name))
  2821. ;; We need to reset agenda markers here, because when constructing a
  2822. ;; block agenda, the individual blocks do not do that.
  2823. (org-agenda-reset-markers)
  2824. (let* ((org-agenda-multi t)
  2825. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2826. (cmds (car series))
  2827. (gprops (nth 1 series))
  2828. match ;; The byte compiler incorrectly complains about this. Keep it!
  2829. org-cmd type lprops)
  2830. (while (setq org-cmd (pop cmds))
  2831. (setq type (car org-cmd))
  2832. (setq match (eval (nth 1 org-cmd)))
  2833. (setq lprops (nth 2 org-cmd))
  2834. (let ((org-agenda-overriding-arguments
  2835. (if (eq org-agenda-overriding-cmd org-cmd)
  2836. (or org-agenda-overriding-arguments
  2837. org-agenda-overriding-cmd-arguments))))
  2838. (cond
  2839. ((eq type 'agenda)
  2840. (org-let2 gprops lprops
  2841. '(call-interactively 'org-agenda-list)))
  2842. ((eq type 'agenda*)
  2843. (org-let2 gprops lprops
  2844. '(funcall 'org-agenda-list nil nil t)))
  2845. ((eq type 'alltodo)
  2846. (org-let2 gprops lprops
  2847. '(call-interactively 'org-todo-list)))
  2848. ((eq type 'search)
  2849. (org-let2 gprops lprops
  2850. '(org-search-view current-prefix-arg match nil)))
  2851. ((eq type 'stuck)
  2852. (org-let2 gprops lprops
  2853. '(call-interactively 'org-agenda-list-stuck-projects)))
  2854. ((eq type 'tags)
  2855. (org-let2 gprops lprops
  2856. '(org-tags-view current-prefix-arg match)))
  2857. ((eq type 'tags-todo)
  2858. (org-let2 gprops lprops
  2859. '(org-tags-view '(4) match)))
  2860. ((eq type 'todo)
  2861. (org-let2 gprops lprops
  2862. '(org-todo-list match)))
  2863. ((fboundp type)
  2864. (org-let2 gprops lprops
  2865. '(funcall type match)))
  2866. (t (error "Invalid type in command series")))))
  2867. (widen)
  2868. (let ((inhibit-read-only t))
  2869. (add-text-properties (point-min) (point-max)
  2870. `(org-series t org-series-redo-cmd ,redo)))
  2871. (setq org-agenda-redo-command redo)
  2872. (goto-char (point-min)))
  2873. (org-agenda-fit-window-to-buffer)
  2874. (org-let (nth 1 series) '(org-agenda-finalize)))
  2875. ;;;###autoload
  2876. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2877. "Run an agenda command in batch mode and send the result to STDOUT.
  2878. If CMD-KEY is a string of length 1, it is used as a key in
  2879. `org-agenda-custom-commands' and triggers this command. If it is a
  2880. longer string it is used as a tags/todo match string.
  2881. Parameters are alternating variable names and values that will be bound
  2882. before running the agenda command."
  2883. (org-eval-in-environment (org-make-parameter-alist parameters)
  2884. (let (org-agenda-sticky)
  2885. (if (> (length cmd-key) 1)
  2886. (org-tags-view nil cmd-key)
  2887. (org-agenda nil cmd-key))))
  2888. (set-buffer org-agenda-buffer-name)
  2889. (princ (buffer-string)))
  2890. (defvar org-agenda-info nil)
  2891. ;;;###autoload
  2892. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2893. "Run an agenda command in batch mode and send the result to STDOUT.
  2894. If CMD-KEY is a string of length 1, it is used as a key in
  2895. `org-agenda-custom-commands' and triggers this command. If it is a
  2896. longer string it is used as a tags/todo match string.
  2897. Parameters are alternating variable names and values that will be bound
  2898. before running the agenda command.
  2899. The output gives a line for each selected agenda item. Each
  2900. item is a list of comma-separated values, like this:
  2901. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2902. category The category of the item
  2903. head The headline, without TODO kwd, TAGS and PRIORITY
  2904. type The type of the agenda entry, can be
  2905. todo selected in TODO match
  2906. tagsmatch selected in tags match
  2907. diary imported from diary
  2908. deadline a deadline on given date
  2909. scheduled scheduled on given date
  2910. timestamp entry has timestamp on given date
  2911. closed entry was closed on given date
  2912. upcoming-deadline warning about deadline
  2913. past-scheduled forwarded scheduled item
  2914. block entry has date block including g. date
  2915. todo The todo keyword, if any
  2916. tags All tags including inherited ones, separated by colons
  2917. date The relevant date, like 2007-2-14
  2918. time The time, like 15:00-16:50
  2919. extra Sting with extra planning info
  2920. priority-l The priority letter if any was given
  2921. priority-n The computed numerical priority
  2922. agenda-day The day in the agenda where this is listed"
  2923. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2924. (org-make-parameter-alist parameters))
  2925. (if (> (length cmd-key) 2)
  2926. (org-tags-view nil cmd-key)
  2927. (org-agenda nil cmd-key)))
  2928. (set-buffer org-agenda-buffer-name)
  2929. (let* ((lines (org-split-string (buffer-string) "\n"))
  2930. line)
  2931. (while (setq line (pop lines))
  2932. (catch 'next
  2933. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2934. (setq org-agenda-info
  2935. (org-fix-agenda-info (text-properties-at 0 line)))
  2936. (princ
  2937. (mapconcat 'org-agenda-export-csv-mapper
  2938. '(org-category txt type todo tags date time extra
  2939. priority-letter priority agenda-day)
  2940. ","))
  2941. (princ "\n")))))
  2942. (defun org-fix-agenda-info (props)
  2943. "Make sure all properties on an agenda item have a canonical form.
  2944. This ensures the export commands can easily use it."
  2945. (let (tmp re)
  2946. (when (setq tmp (plist-get props 'tags))
  2947. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2948. (when (setq tmp (plist-get props 'date))
  2949. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2950. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2951. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2952. (setq tmp (calendar-date-string tmp)))
  2953. (setq props (plist-put props 'date tmp)))
  2954. (when (setq tmp (plist-get props 'day))
  2955. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2956. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2957. (setq tmp (calendar-date-string tmp)))
  2958. (setq props (plist-put props 'day tmp))
  2959. (setq props (plist-put props 'agenda-day tmp)))
  2960. (when (setq tmp (plist-get props 'txt))
  2961. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2962. (plist-put props 'priority-letter (match-string 1 tmp))
  2963. (setq tmp (replace-match "" t t tmp)))
  2964. (when (and (setq re (plist-get props 'org-todo-regexp))
  2965. (setq re (concat "\\`\\.*" re " ?"))
  2966. (let ((case-fold-search nil)) (string-match re tmp)))
  2967. (plist-put props 'todo (match-string 1 tmp))
  2968. (setq tmp (replace-match "" t t tmp)))
  2969. (plist-put props 'txt tmp)))
  2970. props)
  2971. (defun org-agenda-export-csv-mapper (prop)
  2972. (let ((res (plist-get org-agenda-info prop)))
  2973. (setq res
  2974. (cond
  2975. ((not res) "")
  2976. ((stringp res) res)
  2977. (t (prin1-to-string res))))
  2978. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2979. ;;;###autoload
  2980. (defun org-store-agenda-views (&rest parameters)
  2981. "Store agenda views."
  2982. (interactive)
  2983. (eval (list 'org-batch-store-agenda-views)))
  2984. ;;;###autoload
  2985. (defmacro org-batch-store-agenda-views (&rest parameters)
  2986. "Run all custom agenda commands that have a file argument."
  2987. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2988. (pop-up-frames nil)
  2989. (dir default-directory)
  2990. (pars (org-make-parameter-alist parameters))
  2991. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2992. (save-window-excursion
  2993. (while cmds
  2994. (setq cmd (pop cmds)
  2995. thiscmdkey (car cmd)
  2996. thiscmdcmd (cdr cmd)
  2997. match (nth 2 thiscmdcmd)
  2998. bufname (if org-agenda-sticky
  2999. (or (and (stringp match)
  3000. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3001. (format "*Org Agenda(%s)*" thiscmdkey))
  3002. org-agenda-buffer-name)
  3003. cmd-or-set (nth 2 cmd)
  3004. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3005. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3006. (if (stringp files) (setq files (list files)))
  3007. (when files
  3008. (org-eval-in-environment (append org-agenda-exporter-settings
  3009. opts pars)
  3010. (org-agenda nil thiscmdkey))
  3011. (set-buffer bufname)
  3012. (while files
  3013. (org-eval-in-environment (append org-agenda-exporter-settings
  3014. opts pars)
  3015. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3016. (and (get-buffer bufname)
  3017. (kill-buffer bufname)))))))
  3018. (defvar org-agenda-current-span nil
  3019. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3020. (defun org-agenda-mark-header-line (pos)
  3021. "Mark the line at POS as an agenda structure header."
  3022. (save-excursion
  3023. (goto-char pos)
  3024. (put-text-property (point-at-bol) (point-at-eol)
  3025. 'org-agenda-structural-header t)
  3026. (when org-agenda-title-append
  3027. (put-text-property (point-at-bol) (point-at-eol)
  3028. 'org-agenda-title-append org-agenda-title-append))))
  3029. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3030. (defvar org-agenda-write-buffer-name "Agenda View")
  3031. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3032. "Write the current buffer (an agenda view) as a file.
  3033. Depending on the extension of the file name, plain text (.txt),
  3034. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3035. If the extension is .ics, translate visible agenda into iCalendar
  3036. format. If the extension is .org, collect all subtrees
  3037. corresponding to the agenda entries and add them in an .org file.
  3038. With prefix argument OPEN, open the new file immediately. If
  3039. NOSETTINGS is given, do not scope the settings of
  3040. `org-agenda-exporter-settings' into the export commands. This is
  3041. used when the settings have already been scoped and we do not
  3042. wish to overrule other, higher priority settings. If
  3043. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3044. the agenda to write."
  3045. (interactive "FWrite agenda to file: \nP")
  3046. (if (or (not (file-writable-p file))
  3047. (and (file-exists-p file)
  3048. (if (called-interactively-p 'any)
  3049. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3050. (user-error "Cannot write agenda to file %s" file))
  3051. (org-let (if nosettings nil org-agenda-exporter-settings)
  3052. '(save-excursion
  3053. (save-window-excursion
  3054. (let ((bs (copy-sequence (buffer-string)))
  3055. (extension (file-name-extension file))
  3056. (default-directory (file-name-directory file))
  3057. beg content)
  3058. (with-temp-buffer
  3059. (rename-buffer org-agenda-write-buffer-name t)
  3060. (set-buffer-modified-p nil)
  3061. (insert bs)
  3062. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3063. (run-hooks 'org-agenda-before-write-hook)
  3064. (cond
  3065. ((bound-and-true-p org-mobile-creating-agendas)
  3066. (org-mobile-write-agenda-for-mobile file))
  3067. ((string= "org" extension)
  3068. (let (content p m message-log-max)
  3069. (goto-char (point-min))
  3070. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3071. (goto-char p)
  3072. (setq m (get-text-property (point) 'org-hd-marker))
  3073. (when m
  3074. (push (save-excursion
  3075. (set-buffer (marker-buffer m))
  3076. (goto-char m)
  3077. (org-copy-subtree 1 nil t t)
  3078. org-subtree-clip)
  3079. content)))
  3080. (find-file file)
  3081. (erase-buffer)
  3082. (dolist (s content) (org-paste-subtree 1 s))
  3083. (write-file file)
  3084. (kill-buffer (current-buffer))
  3085. (message "Org file written to %s" file)))
  3086. ((member extension '("html" "htm"))
  3087. (or (require 'htmlize nil t)
  3088. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3089. (set-buffer (htmlize-buffer (current-buffer)))
  3090. (when org-agenda-export-html-style
  3091. ;; replace <style> section with org-agenda-export-html-style
  3092. (goto-char (point-min))
  3093. (kill-region (- (search-forward "<style") 6)
  3094. (search-forward "</style>"))
  3095. (insert org-agenda-export-html-style))
  3096. (write-file file)
  3097. (kill-buffer (current-buffer))
  3098. (message "HTML written to %s" file))
  3099. ((string= "ps" extension)
  3100. (require 'ps-print)
  3101. (ps-print-buffer-with-faces file)
  3102. (message "Postscript written to %s" file))
  3103. ((string= "pdf" extension)
  3104. (require 'ps-print)
  3105. (ps-print-buffer-with-faces
  3106. (concat (file-name-sans-extension file) ".ps"))
  3107. (call-process "ps2pdf" nil nil nil
  3108. (expand-file-name
  3109. (concat (file-name-sans-extension file) ".ps"))
  3110. (expand-file-name file))
  3111. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3112. (message "PDF written to %s" file))
  3113. ((string= "ics" extension)
  3114. (require 'ox-icalendar)
  3115. (org-icalendar-export-current-agenda (expand-file-name file)))
  3116. (t
  3117. (let ((bs (buffer-string)))
  3118. (find-file file)
  3119. (erase-buffer)
  3120. (insert bs)
  3121. (save-buffer 0)
  3122. (kill-buffer (current-buffer))
  3123. (message "Plain text written to %s" file))))))))
  3124. (set-buffer (or agenda-bufname
  3125. (and (called-interactively-p 'any) (buffer-name))
  3126. org-agenda-buffer-name)))
  3127. (when open (org-open-file file)))
  3128. (defun org-agenda-remove-marked-text (property &optional value)
  3129. "Delete all text marked with VALUE of PROPERTY.
  3130. VALUE defaults to t."
  3131. (let (beg)
  3132. (setq value (or value t))
  3133. (while (setq beg (text-property-any (point-min) (point-max)
  3134. property value))
  3135. (delete-region
  3136. beg (or (next-single-property-change beg property)
  3137. (point-max))))))
  3138. (defun org-agenda-add-entry-text ()
  3139. "Add entry text to agenda lines.
  3140. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3141. entry text following headings shown in the agenda.
  3142. Drawers will be excluded, also the line with scheduling/deadline info."
  3143. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3144. (not (bound-and-true-p org-mobile-creating-agendas)))
  3145. (let (m txt)
  3146. (goto-char (point-min))
  3147. (while (not (eobp))
  3148. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3149. (beginning-of-line 2)
  3150. (setq txt (org-agenda-get-some-entry-text
  3151. m org-agenda-add-entry-text-maxlines " > "))
  3152. (end-of-line 1)
  3153. (if (string-match "\\S-" txt)
  3154. (insert "\n" txt)
  3155. (or (eobp) (forward-char 1))))))))
  3156. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3157. &rest keep)
  3158. "Extract entry text from MARKER, at most N-LINES lines.
  3159. This will ignore drawers etc, just get the text.
  3160. If INDENT is given, prefix every line with this string. If KEEP is
  3161. given, it is a list of symbols, defining stuff that should not be
  3162. removed from the entry content. Currently only `planning' is allowed here."
  3163. (let (txt drawer-re kwd-time-re ind)
  3164. (save-excursion
  3165. (with-current-buffer (marker-buffer marker)
  3166. (if (not (derived-mode-p 'org-mode))
  3167. (setq txt "")
  3168. (org-with-wide-buffer
  3169. (goto-char marker)
  3170. (end-of-line 1)
  3171. (setq txt (buffer-substring
  3172. (min (1+ (point)) (point-max))
  3173. (progn (outline-next-heading) (point)))
  3174. drawer-re org-drawer-regexp
  3175. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3176. ".*\n?"))
  3177. (with-temp-buffer
  3178. (insert txt)
  3179. (when org-agenda-add-entry-text-descriptive-links
  3180. (goto-char (point-min))
  3181. (while (org-activate-links (point-max))
  3182. (add-text-properties (match-beginning 0) (match-end 0)
  3183. '(face org-link))))
  3184. (goto-char (point-min))
  3185. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3186. (set-text-properties (match-beginning 0) (match-end 0)
  3187. nil))
  3188. (goto-char (point-min))
  3189. (while (re-search-forward drawer-re nil t)
  3190. (delete-region
  3191. (match-beginning 0)
  3192. (progn (re-search-forward
  3193. "^[ \t]*:END:.*\n?" nil 'move)
  3194. (point))))
  3195. (unless (member 'planning keep)
  3196. (goto-char (point-min))
  3197. (while (re-search-forward kwd-time-re nil t)
  3198. (replace-match "")))
  3199. (goto-char (point-min))
  3200. (when org-agenda-entry-text-exclude-regexps
  3201. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3202. (while (setq re (pop re-list))
  3203. (goto-char (point-min))
  3204. (while (re-search-forward re nil t)
  3205. (replace-match "")))))
  3206. (goto-char (point-max))
  3207. (skip-chars-backward " \t\n")
  3208. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3209. ;; find and remove min common indentation
  3210. (goto-char (point-min))
  3211. (untabify (point-min) (point-max))
  3212. (setq ind (org-get-indentation))
  3213. (while (not (eobp))
  3214. (unless (looking-at "[ \t]*$")
  3215. (setq ind (min ind (org-get-indentation))))
  3216. (beginning-of-line 2))
  3217. (goto-char (point-min))
  3218. (while (not (eobp))
  3219. (unless (looking-at "[ \t]*$")
  3220. (move-to-column ind)
  3221. (delete-region (point-at-bol) (point)))
  3222. (beginning-of-line 2))
  3223. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3224. (goto-char (point-min))
  3225. (when indent
  3226. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3227. (replace-match indent t t)))
  3228. (goto-char (point-min))
  3229. (while (looking-at "[ \t]*\n") (replace-match ""))
  3230. (goto-char (point-max))
  3231. (when (> (org-current-line)
  3232. n-lines)
  3233. (org-goto-line (1+ n-lines))
  3234. (backward-char 1))
  3235. (setq txt (buffer-substring (point-min) (point))))))))
  3236. txt))
  3237. (defun org-check-for-org-mode ()
  3238. "Make sure current buffer is in Org mode. Error if not."
  3239. (or (derived-mode-p 'org-mode)
  3240. (error "Cannot execute Org agenda command on buffer in %s"
  3241. major-mode)))
  3242. ;;; Agenda prepare and finalize
  3243. (defvar org-agenda-multi nil) ; dynamically scoped
  3244. (defvar org-agenda-pre-window-conf nil)
  3245. (defvar org-agenda-columns-active nil)
  3246. (defvar org-agenda-name nil)
  3247. (defvar org-agenda-tag-filter nil)
  3248. (defvar org-agenda-category-filter nil)
  3249. (defvar org-agenda-regexp-filter nil)
  3250. (defvar org-agenda-effort-filter nil)
  3251. (defvar org-agenda-top-headline-filter nil)
  3252. (defvar org-agenda-tag-filter-preset nil
  3253. "A preset of the tags filter used for secondary agenda filtering.
  3254. This must be a list of strings, each string must be a single tag preceded
  3255. by \"+\" or \"-\".
  3256. This variable should not be set directly, but agenda custom commands can
  3257. bind it in the options section. The preset filter is a global property of
  3258. the entire agenda view. In a block agenda, it will not work reliably to
  3259. define a filter for one of the individual blocks. You need to set it in
  3260. the global options and expect it to be applied to the entire view.")
  3261. (defvar org-agenda-category-filter-preset nil
  3262. "A preset of the category filter used for secondary agenda filtering.
  3263. This must be a list of strings, each string must be a single category
  3264. preceded by \"+\" or \"-\".
  3265. This variable should not be set directly, but agenda custom commands can
  3266. bind it in the options section. The preset filter is a global property of
  3267. the entire agenda view. In a block agenda, it will not work reliably to
  3268. define a filter for one of the individual blocks. You need to set it in
  3269. the global options and expect it to be applied to the entire view.")
  3270. (defvar org-agenda-regexp-filter-preset nil
  3271. "A preset of the regexp filter used for secondary agenda filtering.
  3272. This must be a list of strings, each string must be a single regexp
  3273. preceded by \"+\" or \"-\".
  3274. This variable should not be set directly, but agenda custom commands can
  3275. bind it in the options section. The preset filter is a global property of
  3276. the entire agenda view. In a block agenda, it will not work reliably to
  3277. define a filter for one of the individual blocks. You need to set it in
  3278. the global options and expect it to be applied to the entire view.")
  3279. (defvar org-agenda-effort-filter-preset nil
  3280. "A preset of the effort condition used for secondary agenda filtering.
  3281. This must be a list of strings, each string must be a single regexp
  3282. preceded by \"+\" or \"-\".
  3283. This variable should not be set directly, but agenda custom commands can
  3284. bind it in the options section. The preset filter is a global property of
  3285. the entire agenda view. In a block agenda, it will not work reliably to
  3286. define a filter for one of the individual blocks. You need to set it in
  3287. the global options and expect it to be applied to the entire view.")
  3288. (defun org-agenda-use-sticky-p ()
  3289. "Return non-nil if an agenda buffer named
  3290. `org-agenda-buffer-name' exists and should be shown instead of
  3291. generating a new one."
  3292. (and
  3293. ;; turned off by user
  3294. org-agenda-sticky
  3295. ;; For multi-agenda buffer already exists
  3296. (not org-agenda-multi)
  3297. ;; buffer found
  3298. (get-buffer org-agenda-buffer-name)
  3299. ;; C-u parameter is same as last call
  3300. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3301. (and
  3302. (equal current-prefix-arg
  3303. org-agenda-last-prefix-arg)
  3304. ;; In case user turned stickiness on, while having existing
  3305. ;; Agenda buffer active, don't reuse that buffer, because it
  3306. ;; does not have org variables local
  3307. org-agenda-this-buffer-is-sticky))))
  3308. (defun org-agenda-prepare-window (abuf filter-alist)
  3309. "Setup agenda buffer in the window.
  3310. ABUF is the buffer for the agenda window.
  3311. FILTER-ALIST is an alist of filters we need to apply when
  3312. `org-agenda-persistent-filter' is non-nil."
  3313. (let* ((awin (get-buffer-window abuf)) wconf)
  3314. (cond
  3315. ((equal (current-buffer) abuf) nil)
  3316. (awin (select-window awin))
  3317. ((not (setq wconf (current-window-configuration))))
  3318. ((eq org-agenda-window-setup 'current-window)
  3319. (pop-to-buffer-same-window abuf))
  3320. ((eq org-agenda-window-setup 'other-window)
  3321. (org-switch-to-buffer-other-window abuf))
  3322. ((eq org-agenda-window-setup 'other-frame)
  3323. (switch-to-buffer-other-frame abuf))
  3324. ((eq org-agenda-window-setup 'only-window)
  3325. (delete-other-windows)
  3326. (pop-to-buffer-same-window abuf))
  3327. ((eq org-agenda-window-setup 'reorganize-frame)
  3328. (delete-other-windows)
  3329. (org-switch-to-buffer-other-window abuf)))
  3330. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3331. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3332. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3333. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3334. ;; Additional test in case agenda is invoked from within agenda
  3335. ;; buffer via elisp link.
  3336. (unless (equal (current-buffer) abuf)
  3337. (pop-to-buffer-same-window abuf))
  3338. (setq org-agenda-pre-window-conf
  3339. (or wconf org-agenda-pre-window-conf))))
  3340. (defun org-agenda-prepare (&optional name)
  3341. (let ((filter-alist (if org-agenda-persistent-filter
  3342. (with-current-buffer
  3343. (get-buffer-create org-agenda-buffer-name)
  3344. (list `(tag . ,org-agenda-tag-filter)
  3345. `(re . ,org-agenda-regexp-filter)
  3346. `(effort . ,org-agenda-effort-filter)
  3347. `(cat . ,org-agenda-category-filter))))))
  3348. (if (org-agenda-use-sticky-p)
  3349. (progn
  3350. (put 'org-agenda-tag-filter :preset-filter nil)
  3351. (put 'org-agenda-category-filter :preset-filter nil)
  3352. (put 'org-agenda-regexp-filter :preset-filter nil)
  3353. ;; Popup existing buffer
  3354. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3355. filter-alist)
  3356. (message "Sticky Agenda buffer, use `r' to refresh")
  3357. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3358. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3359. (setq org-todo-keywords-for-agenda nil)
  3360. (put 'org-agenda-tag-filter :preset-filter
  3361. org-agenda-tag-filter-preset)
  3362. (put 'org-agenda-category-filter :preset-filter
  3363. org-agenda-category-filter-preset)
  3364. (put 'org-agenda-regexp-filter :preset-filter
  3365. org-agenda-regexp-filter-preset)
  3366. (put 'org-agenda-effort-filter :preset-filter
  3367. org-agenda-effort-filter-preset)
  3368. (if org-agenda-multi
  3369. (progn
  3370. (setq buffer-read-only nil)
  3371. (goto-char (point-max))
  3372. (unless (or (bobp) org-agenda-compact-blocks
  3373. (not org-agenda-block-separator))
  3374. (insert "\n"
  3375. (if (stringp org-agenda-block-separator)
  3376. org-agenda-block-separator
  3377. (make-string (window-width) org-agenda-block-separator))
  3378. "\n"))
  3379. (narrow-to-region (point) (point-max)))
  3380. (setq org-done-keywords-for-agenda nil)
  3381. ;; Setting any org variables that are in org-agenda-local-vars
  3382. ;; list need to be done after the prepare call
  3383. (org-agenda-prepare-window
  3384. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3385. (setq buffer-read-only nil)
  3386. (org-agenda-reset-markers)
  3387. (let ((inhibit-read-only t)) (erase-buffer))
  3388. (org-agenda-mode)
  3389. (setq org-agenda-buffer (current-buffer))
  3390. (setq org-agenda-contributing-files nil)
  3391. (setq org-agenda-columns-active nil)
  3392. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3393. (setq org-todo-keywords-for-agenda
  3394. (org-uniquify org-todo-keywords-for-agenda))
  3395. (setq org-done-keywords-for-agenda
  3396. (org-uniquify org-done-keywords-for-agenda))
  3397. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3398. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3399. ;; Don't set these until we know we're in the agenda buffer,
  3400. ;; and we know they're valid.
  3401. (setq org-agenda-lprops (or org-agenda-lprops
  3402. (get 'org-agenda-redo-command 'org-lprops)))
  3403. (and name (not org-agenda-name)
  3404. (setq-local org-agenda-name name)))
  3405. (setq buffer-read-only nil))))
  3406. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3407. (defun org-agenda-finalize ()
  3408. "Finishing touch for the agenda buffer, called just before displaying it."
  3409. (unless org-agenda-multi
  3410. (save-excursion
  3411. (let ((inhibit-read-only t))
  3412. (goto-char (point-min))
  3413. (save-excursion
  3414. (while (org-activate-links (point-max))
  3415. (add-text-properties (match-beginning 0) (match-end 0)
  3416. '(face org-link))))
  3417. (unless (eq org-agenda-remove-tags t)
  3418. (org-agenda-align-tags))
  3419. (unless org-agenda-with-colors
  3420. (remove-text-properties (point-min) (point-max) '(face nil)))
  3421. (if (and (boundp 'org-agenda-overriding-columns-format)
  3422. org-agenda-overriding-columns-format)
  3423. (setq-local org-agenda-overriding-columns-format
  3424. org-agenda-overriding-columns-format))
  3425. (if (and (boundp 'org-agenda-view-columns-initially)
  3426. org-agenda-view-columns-initially)
  3427. (org-agenda-columns))
  3428. (when org-agenda-fontify-priorities
  3429. (org-agenda-fontify-priorities))
  3430. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3431. (org-agenda-dim-blocked-tasks))
  3432. (org-agenda-mark-clocking-task)
  3433. (when org-agenda-entry-text-mode
  3434. (org-agenda-entry-text-hide)
  3435. (org-agenda-entry-text-show))
  3436. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3437. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3438. (org-habit-insert-consistency-graphs))
  3439. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3440. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3441. (and (listp org-agenda-show-inherited-tags)
  3442. (memq org-agenda-type org-agenda-show-inherited-tags))
  3443. (and (eq org-agenda-show-inherited-tags t)
  3444. (or (eq org-agenda-use-tag-inheritance t)
  3445. (and (listp org-agenda-use-tag-inheritance)
  3446. (not (memq org-agenda-type
  3447. org-agenda-use-tag-inheritance))))))
  3448. (let (mrk)
  3449. (save-excursion
  3450. (goto-char (point-min))
  3451. (while (equal (forward-line) 0)
  3452. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3453. (put-text-property (point-at-bol) (point-at-eol)
  3454. 'tags (org-with-point-at mrk
  3455. (delete-dups
  3456. (mapcar 'downcase (org-get-tags-at))))))))))
  3457. (run-hooks 'org-agenda-finalize-hook)
  3458. (when org-agenda-top-headline-filter
  3459. (org-agenda-filter-top-headline-apply
  3460. org-agenda-top-headline-filter))
  3461. (when org-agenda-tag-filter
  3462. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3463. (when (get 'org-agenda-tag-filter :preset-filter)
  3464. (org-agenda-filter-apply
  3465. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3466. (when org-agenda-category-filter
  3467. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3468. (when (get 'org-agenda-category-filter :preset-filter)
  3469. (org-agenda-filter-apply
  3470. (get 'org-agenda-category-filter :preset-filter) 'category))
  3471. (when org-agenda-regexp-filter
  3472. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3473. (when (get 'org-agenda-regexp-filter :preset-filter)
  3474. (org-agenda-filter-apply
  3475. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3476. (when org-agenda-effort-filter
  3477. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3478. (when (get 'org-agenda-effort-filter :preset-filter)
  3479. (org-agenda-filter-apply
  3480. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3481. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3482. (defun org-agenda-mark-clocking-task ()
  3483. "Mark the current clock entry in the agenda if it is present."
  3484. ;; We need to widen when `org-agenda-finalize' is called from
  3485. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3486. (when (bound-and-true-p org-clock-current-task)
  3487. (save-restriction
  3488. (widen)
  3489. (org-agenda-unmark-clocking-task)
  3490. (when (marker-buffer org-clock-hd-marker)
  3491. (save-excursion
  3492. (goto-char (point-min))
  3493. (let (s ov)
  3494. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3495. (goto-char s)
  3496. (when (equal (org-get-at-bol 'org-hd-marker)
  3497. org-clock-hd-marker)
  3498. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3499. (overlay-put ov 'type 'org-agenda-clocking)
  3500. (overlay-put ov 'face 'org-agenda-clocking)
  3501. (overlay-put ov 'help-echo
  3502. "The clock is running in this item")))))))))
  3503. (defun org-agenda-unmark-clocking-task ()
  3504. "Unmark the current clocking task."
  3505. (mapc (lambda (o)
  3506. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3507. (delete-overlay o)))
  3508. (overlays-in (point-min) (point-max))))
  3509. (defun org-agenda-fontify-priorities ()
  3510. "Make highest priority lines bold, and lowest italic."
  3511. (interactive)
  3512. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3513. (delete-overlay o)))
  3514. (overlays-in (point-min) (point-max)))
  3515. (save-excursion
  3516. (let (b e p ov h l)
  3517. (goto-char (point-min))
  3518. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3519. (setq h (or (get-char-property (point) 'org-highest-priority)
  3520. org-highest-priority)
  3521. l (or (get-char-property (point) 'org-lowest-priority)
  3522. org-lowest-priority)
  3523. p (string-to-char (match-string 1))
  3524. b (match-beginning 0)
  3525. e (if (eq org-agenda-fontify-priorities 'cookies)
  3526. (match-end 0)
  3527. (point-at-eol))
  3528. ov (make-overlay b e))
  3529. (overlay-put
  3530. ov 'face
  3531. (let ((special-face
  3532. (cond ((org-face-from-face-or-color
  3533. 'priority 'org-priority
  3534. (cdr (assoc p org-priority-faces))))
  3535. ((and (listp org-agenda-fontify-priorities)
  3536. (org-face-from-face-or-color
  3537. 'priority 'org-priority
  3538. (cdr (assoc p org-agenda-fontify-priorities)))))
  3539. ((equal p l) 'italic)
  3540. ((equal p h) 'bold))))
  3541. (if special-face (list special-face 'org-priority) 'org-priority)))
  3542. (overlay-put ov 'org-type 'org-priority)))))
  3543. (defvar org-depend-tag-blocked)
  3544. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3545. "Dim currently blocked TODOs in the agenda display.
  3546. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3547. dimming them."
  3548. (interactive "P")
  3549. (when (called-interactively-p 'interactive)
  3550. (message "Dim or hide blocked tasks..."))
  3551. (dolist (o (overlays-in (point-min) (point-max)))
  3552. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3553. (delete-overlay o)))
  3554. (save-excursion
  3555. (let ((inhibit-read-only t))
  3556. (goto-char (point-min))
  3557. (while (let ((pos (text-property-not-all
  3558. (point) (point-max) 'org-todo-blocked nil)))
  3559. (when pos (goto-char pos)))
  3560. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3561. (ov (make-overlay (if invisible
  3562. (line-end-position 0)
  3563. (line-beginning-position))
  3564. (line-end-position))))
  3565. (if invisible
  3566. (overlay-put ov 'invisible t)
  3567. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3568. (overlay-put ov 'org-type 'org-blocked-todo))
  3569. (forward-line))))
  3570. (when (called-interactively-p 'interactive)
  3571. (message "Dim or hide blocked tasks...done")))
  3572. (defun org-agenda--mark-blocked-entry (entry)
  3573. "For ENTRY a string with the text property `org-hd-marker', if
  3574. the header at `org-hd-marker' is blocked according to
  3575. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3576. 'invisible and the header is not blocked by checkboxes, set the
  3577. text property `org-todo-blocked' to 'invisible, otherwise set it
  3578. to t."
  3579. (when (get-text-property 0 'todo-state entry)
  3580. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3581. (org-blocked-by-checkboxes nil)
  3582. ;; Necessary so that `org-entry-blocked-p' does not change
  3583. ;; the buffer.
  3584. (org-depend-tag-blocked nil))
  3585. (when entry-marker
  3586. (let ((blocked
  3587. (with-current-buffer (marker-buffer entry-marker)
  3588. (save-excursion
  3589. (goto-char entry-marker)
  3590. (org-entry-blocked-p)))))
  3591. (when blocked
  3592. (let ((really-invisible
  3593. (and (not org-blocked-by-checkboxes)
  3594. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3595. (put-text-property
  3596. 0 (length entry) 'org-todo-blocked
  3597. (if really-invisible 'invisible t)
  3598. entry)))))))
  3599. entry)
  3600. (defvar org-agenda-skip-function nil
  3601. "Function to be called at each match during agenda construction.
  3602. If this function returns nil, the current match should not be skipped.
  3603. Otherwise, the function must return a position from where the search
  3604. should be continued.
  3605. This may also be a Lisp form, it will be evaluated.
  3606. Never set this variable using `setq' or so, because then it will apply
  3607. to all future agenda commands. If you do want a global skipping condition,
  3608. use the option `org-agenda-skip-function-global' instead.
  3609. The correct usage for `org-agenda-skip-function' is to bind it with
  3610. `let' to scope it dynamically into the agenda-constructing command.
  3611. A good way to set it is through options in `org-agenda-custom-commands'.")
  3612. (defun org-agenda-skip ()
  3613. "Throw to `:skip' in places that should be skipped.
  3614. Also moves point to the end of the skipped region, so that search can
  3615. continue from there."
  3616. (let ((p (point-at-bol)) to)
  3617. (when (or
  3618. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3619. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3620. (get-text-property p :org-archived)
  3621. (org-end-of-subtree t))
  3622. (and org-agenda-skip-comment-trees
  3623. (get-text-property p :org-comment)
  3624. (org-end-of-subtree t))
  3625. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3626. (org-agenda-skip-eval org-agenda-skip-function)))
  3627. (goto-char to))
  3628. (org-in-src-block-p t))
  3629. (throw :skip t))))
  3630. (defun org-agenda-skip-eval (form)
  3631. "If FORM is a function or a list, call (or eval) it and return the result.
  3632. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3633. and match data are returned to the previous state no matter what these
  3634. functions do."
  3635. (let (fp)
  3636. (and form
  3637. (or (setq fp (functionp form))
  3638. (consp form))
  3639. (save-excursion
  3640. (save-match-data
  3641. (if fp
  3642. (funcall form)
  3643. (eval form)))))))
  3644. (defvar org-agenda-markers nil
  3645. "List of all currently active markers created by `org-agenda'.")
  3646. (defvar org-agenda-last-marker-time (float-time)
  3647. "Creation time of the last agenda marker.")
  3648. (defun org-agenda-new-marker (&optional pos)
  3649. "Return a new agenda marker.
  3650. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3651. these markers and resets them when they are no longer in use."
  3652. (let ((m (copy-marker (or pos (point)) t)))
  3653. (setq org-agenda-last-marker-time (float-time))
  3654. (if org-agenda-buffer
  3655. (with-current-buffer org-agenda-buffer
  3656. (push m org-agenda-markers))
  3657. (push m org-agenda-markers))
  3658. m))
  3659. (defun org-agenda-reset-markers ()
  3660. "Reset markers created by `org-agenda'."
  3661. (while org-agenda-markers
  3662. (move-marker (pop org-agenda-markers) nil)))
  3663. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3664. "Save relative positions of markers in region.
  3665. This check for agenda markers in all agenda buffers currently active."
  3666. (dolist (buf (buffer-list))
  3667. (with-current-buffer buf
  3668. (when (eq major-mode 'org-agenda-mode)
  3669. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3670. org-agenda-markers)))))
  3671. ;;; Entry text mode
  3672. (defun org-agenda-entry-text-show-here ()
  3673. "Add some text from the entry as context to the current line."
  3674. (let (m txt o)
  3675. (setq m (org-get-at-bol 'org-hd-marker))
  3676. (unless (marker-buffer m)
  3677. (error "No marker points to an entry here"))
  3678. (setq txt (concat "\n" (org-no-properties
  3679. (org-agenda-get-some-entry-text
  3680. m org-agenda-entry-text-maxlines
  3681. org-agenda-entry-text-leaders))))
  3682. (when (string-match "\\S-" txt)
  3683. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3684. (overlay-put o 'evaporate t)
  3685. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3686. (overlay-put o 'after-string txt))))
  3687. (defun org-agenda-entry-text-show ()
  3688. "Add entry context for all agenda lines."
  3689. (interactive)
  3690. (save-excursion
  3691. (goto-char (point-max))
  3692. (beginning-of-line 1)
  3693. (while (not (bobp))
  3694. (when (org-get-at-bol 'org-hd-marker)
  3695. (org-agenda-entry-text-show-here))
  3696. (beginning-of-line 0))))
  3697. (defun org-agenda-entry-text-hide ()
  3698. "Remove any shown entry context."
  3699. (delq nil
  3700. (mapcar (lambda (o)
  3701. (if (eq (overlay-get o 'org-overlay-type)
  3702. 'agenda-entry-content)
  3703. (progn (delete-overlay o) t)))
  3704. (overlays-in (point-min) (point-max)))))
  3705. (defun org-agenda-get-day-face (date)
  3706. "Return the face DATE should be displayed with."
  3707. (cond ((and (functionp org-agenda-day-face-function)
  3708. (funcall org-agenda-day-face-function date)))
  3709. ((org-agenda-today-p date) 'org-agenda-date-today)
  3710. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3711. 'org-agenda-date-weekend)
  3712. (t 'org-agenda-date)))
  3713. (defvar org-agenda-show-log-scoped)
  3714. ;;; Agenda Daily/Weekly
  3715. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3716. "Start day for the agenda view.
  3717. Custom commands can set this variable in the options section.
  3718. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3719. input allowed when reading a date through the Org calendar.
  3720. See the docstring of `org-read-date' for details.")
  3721. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3722. (defvar org-arg-loc nil) ; local variable
  3723. (defvar org-agenda-buffer-tmp-name nil)
  3724. ;;;###autoload
  3725. (defun org-agenda-list (&optional arg start-day span with-hour)
  3726. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3727. The view will be for the current day or week, but from the overview buffer
  3728. you will be able to go to other days/weeks.
  3729. With a numeric prefix argument in an interactive call, the agenda will
  3730. span ARG days. Lisp programs should instead specify SPAN to change
  3731. the number of days. SPAN defaults to `org-agenda-span'.
  3732. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3733. given in `org-agenda-start-on-weekday'.
  3734. When WITH-HOUR is non-nil, only include scheduled and deadline
  3735. items if they have an hour specification like [h]h:mm."
  3736. (interactive "P")
  3737. (if org-agenda-overriding-arguments
  3738. (setq arg (car org-agenda-overriding-arguments)
  3739. start-day (nth 1 org-agenda-overriding-arguments)
  3740. span (nth 2 org-agenda-overriding-arguments)))
  3741. (if (and (integerp arg) (> arg 0))
  3742. (setq span arg arg nil))
  3743. (catch 'exit
  3744. (setq org-agenda-buffer-name
  3745. (or org-agenda-buffer-tmp-name
  3746. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3747. (if org-agenda-sticky
  3748. (cond ((and org-keys (stringp org-match))
  3749. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3750. (org-keys
  3751. (format "*Org Agenda(%s)*" org-keys))
  3752. (t "*Org Agenda(a)*")))
  3753. "*Org Agenda*"))
  3754. (org-agenda-prepare "Day/Week")
  3755. (setq start-day (or start-day org-agenda-start-day))
  3756. (if (stringp start-day)
  3757. ;; Convert to an absolute day number
  3758. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3759. (org-compile-prefix-format 'agenda)
  3760. (org-set-sorting-strategy 'agenda)
  3761. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3762. (today (org-today))
  3763. (sd (or start-day today))
  3764. (ndays (org-agenda-span-to-ndays span sd))
  3765. (org-agenda-start-on-weekday
  3766. (if (or (eq ndays 7) (eq ndays 14))
  3767. org-agenda-start-on-weekday))
  3768. (thefiles (org-agenda-files nil 'ifmode))
  3769. (files thefiles)
  3770. (start (if (or (null org-agenda-start-on-weekday)
  3771. (< ndays 7))
  3772. sd
  3773. (let* ((nt (calendar-day-of-week
  3774. (calendar-gregorian-from-absolute sd)))
  3775. (n1 org-agenda-start-on-weekday)
  3776. (d (- nt n1)))
  3777. (- sd (+ (if (< d 0) 7 0) d)))))
  3778. (day-numbers (list start))
  3779. (day-cnt 0)
  3780. (inhibit-redisplay (not debug-on-error))
  3781. (org-agenda-show-log-scoped org-agenda-show-log)
  3782. s e rtn rtnall file date d start-pos end-pos todayp
  3783. clocktable-start clocktable-end filter)
  3784. (setq org-agenda-redo-command
  3785. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3786. (dotimes (n (1- ndays))
  3787. (push (1+ (car day-numbers)) day-numbers))
  3788. (setq day-numbers (nreverse day-numbers))
  3789. (setq clocktable-start (car day-numbers)
  3790. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3791. (setq-local org-starting-day (car day-numbers))
  3792. (setq-local org-arg-loc arg)
  3793. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3794. (unless org-agenda-compact-blocks
  3795. (let* ((d1 (car day-numbers))
  3796. (d2 (org-last day-numbers))
  3797. (w1 (org-days-to-iso-week d1))
  3798. (w2 (org-days-to-iso-week d2)))
  3799. (setq s (point))
  3800. (if org-agenda-overriding-header
  3801. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3802. nil 'face 'org-agenda-structure) "\n")
  3803. (insert (org-agenda-span-name span)
  3804. "-agenda"
  3805. (if (< (- d2 d1) 350)
  3806. (if (= w1 w2)
  3807. (format " (W%02d)" w1)
  3808. (format " (W%02d-W%02d)" w1 w2))
  3809. "")
  3810. ":\n")))
  3811. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3812. 'org-date-line t))
  3813. (org-agenda-mark-header-line s))
  3814. (while (setq d (pop day-numbers))
  3815. (setq date (calendar-gregorian-from-absolute d)
  3816. s (point))
  3817. (if (or (setq todayp (= d today))
  3818. (and (not start-pos) (= d sd)))
  3819. (setq start-pos (point))
  3820. (if (and start-pos (not end-pos))
  3821. (setq end-pos (point))))
  3822. (setq files thefiles
  3823. rtnall nil)
  3824. (while (setq file (pop files))
  3825. (catch 'nextfile
  3826. (org-check-agenda-file file)
  3827. (let ((org-agenda-entry-types org-agenda-entry-types))
  3828. ;; Starred types override non-starred equivalents
  3829. (when (member :deadline* org-agenda-entry-types)
  3830. (setq org-agenda-entry-types
  3831. (delq :deadline org-agenda-entry-types)))
  3832. (when (member :scheduled* org-agenda-entry-types)
  3833. (setq org-agenda-entry-types
  3834. (delq :scheduled org-agenda-entry-types)))
  3835. ;; Honor with-hour
  3836. (when with-hour
  3837. (when (member :deadline org-agenda-entry-types)
  3838. (setq org-agenda-entry-types
  3839. (delq :deadline org-agenda-entry-types))
  3840. (push :deadline* org-agenda-entry-types))
  3841. (when (member :scheduled org-agenda-entry-types)
  3842. (setq org-agenda-entry-types
  3843. (delq :scheduled org-agenda-entry-types))
  3844. (push :scheduled* org-agenda-entry-types)))
  3845. (unless org-agenda-include-deadlines
  3846. (setq org-agenda-entry-types
  3847. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3848. (cond
  3849. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3850. (setq rtn (org-agenda-get-day-entries
  3851. file date :closed)))
  3852. (org-agenda-show-log-scoped
  3853. (setq rtn (apply 'org-agenda-get-day-entries
  3854. file date
  3855. (append '(:closed) org-agenda-entry-types))))
  3856. (t
  3857. (setq rtn (apply 'org-agenda-get-day-entries
  3858. file date
  3859. org-agenda-entry-types)))))
  3860. (setq rtnall (append rtnall rtn)))) ;; all entries
  3861. (if org-agenda-include-diary
  3862. (let ((org-agenda-search-headline-for-time t))
  3863. (require 'diary-lib)
  3864. (setq rtn (org-get-entries-from-diary date))
  3865. (setq rtnall (append rtnall rtn))))
  3866. (if (or rtnall org-agenda-show-all-dates)
  3867. (progn
  3868. (setq day-cnt (1+ day-cnt))
  3869. (insert
  3870. (if (stringp org-agenda-format-date)
  3871. (format-time-string org-agenda-format-date
  3872. (org-time-from-absolute date))
  3873. (funcall org-agenda-format-date date))
  3874. "\n")
  3875. (put-text-property s (1- (point)) 'face
  3876. (org-agenda-get-day-face date))
  3877. (put-text-property s (1- (point)) 'org-date-line t)
  3878. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3879. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3880. (when todayp
  3881. (put-text-property s (1- (point)) 'org-today t))
  3882. (setq rtnall
  3883. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3884. (if rtnall (insert ;; all entries
  3885. (org-agenda-finalize-entries rtnall 'agenda)
  3886. "\n"))
  3887. (put-text-property s (1- (point)) 'day d)
  3888. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3889. (when (and org-agenda-clockreport-mode clocktable-start)
  3890. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3891. ;; the above line is to ensure the restricted range!
  3892. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3893. tbl)
  3894. (setq p (org-plist-delete p :block))
  3895. (setq p (plist-put p :tstart clocktable-start))
  3896. (setq p (plist-put p :tend clocktable-end))
  3897. (setq p (plist-put p :scope 'agenda))
  3898. (setq tbl (apply 'org-clock-get-clocktable p))
  3899. (insert tbl)))
  3900. (goto-char (point-min))
  3901. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3902. (unless (and (pos-visible-in-window-p (point-min))
  3903. (pos-visible-in-window-p (point-max)))
  3904. (goto-char (1- (point-max)))
  3905. (recenter -1)
  3906. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3907. (progn
  3908. (goto-char (or start-pos 1))
  3909. (recenter 1))))
  3910. (goto-char (or start-pos 1))
  3911. (add-text-properties (point-min) (point-max)
  3912. `(org-agenda-type agenda
  3913. org-last-args (,arg ,start-day ,span)
  3914. org-redo-cmd ,org-agenda-redo-command
  3915. org-series-cmd ,org-cmd))
  3916. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3917. (org-agenda-show-clocking-issues))
  3918. (org-agenda-finalize)
  3919. (setq buffer-read-only t)
  3920. (message ""))))
  3921. (defun org-agenda-ndays-to-span (n)
  3922. "Return a span symbol for a span of N days, or N if none matches."
  3923. (cond ((symbolp n) n)
  3924. ((= n 1) 'day)
  3925. ((= n 7) 'week)
  3926. ((= n 14) 'fortnight)
  3927. (t n)))
  3928. (defun org-agenda-span-to-ndays (span &optional start-day)
  3929. "Return ndays from SPAN, possibly starting at START-DAY.
  3930. START-DAY is an absolute time value."
  3931. (cond ((numberp span) span)
  3932. ((eq span 'day) 1)
  3933. ((eq span 'week) 7)
  3934. ((eq span 'fortnight) 14)
  3935. ((eq span 'month)
  3936. (let ((date (calendar-gregorian-from-absolute start-day)))
  3937. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3938. ((eq span 'year)
  3939. (let ((date (calendar-gregorian-from-absolute start-day)))
  3940. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3941. (defun org-agenda-span-name (span)
  3942. "Return a SPAN name."
  3943. (if (null span)
  3944. ""
  3945. (if (symbolp span)
  3946. (capitalize (symbol-name span))
  3947. (format "%d days" span))))
  3948. ;;; Agenda word search
  3949. (defvar org-agenda-search-history nil)
  3950. (defvar org-search-syntax-table nil
  3951. "Special syntax table for Org search.
  3952. In this table, we have single quotes not as word constituents, to
  3953. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3954. (defvar org-mode-syntax-table) ; From org.el
  3955. (defun org-search-syntax-table ()
  3956. (unless org-search-syntax-table
  3957. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3958. (modify-syntax-entry ?' "." org-search-syntax-table)
  3959. (modify-syntax-entry ?` "." org-search-syntax-table))
  3960. org-search-syntax-table)
  3961. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3962. ;;;###autoload
  3963. (defun org-search-view (&optional todo-only string edit-at)
  3964. "Show all entries that contain a phrase or words or regular expressions.
  3965. With optional prefix argument TODO-ONLY, only consider entries that are
  3966. TODO entries. The argument STRING can be used to pass a default search
  3967. string into this function. If EDIT-AT is non-nil, it means that the
  3968. user should get a chance to edit this string, with cursor at position
  3969. EDIT-AT.
  3970. The search string can be viewed either as a phrase that should be found as
  3971. is, or it can be broken into a number of snippets, each of which must match
  3972. in a Boolean way to select an entry. The default depends on the variable
  3973. `org-agenda-search-view-always-boolean'.
  3974. Even if this is turned off (the default) you can always switch to
  3975. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3976. The default is a direct search of the whole phrase, where each space in
  3977. the search string can expand to an arbitrary amount of whitespace,
  3978. including newlines.
  3979. If using a Boolean search, the search string is split on whitespace and
  3980. each snippet is searched separately, with logical AND to select an entry.
  3981. Words prefixed with a minus must *not* occur in the entry. Words without
  3982. a prefix or prefixed with a plus must occur in the entry. Matching is
  3983. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3984. match whole words, not parts of a word) if
  3985. `org-agenda-search-view-force-full-words' is set (default is nil).
  3986. Boolean search snippets enclosed by curly braces are interpreted as
  3987. regular expressions that must or (when preceded with \"-\") must not
  3988. match in the entry. Snippets enclosed into double quotes will be taken
  3989. as a whole, to include whitespace.
  3990. - If the search string starts with an asterisk, search only in headlines.
  3991. - If (possibly after the leading star) the search string starts with an
  3992. exclamation mark, this also means to look at TODO entries only, an effect
  3993. that can also be achieved with a prefix argument.
  3994. - If (possibly after star and exclamation mark) the search string starts
  3995. with a colon, this will mean that the (non-regexp) snippets of the
  3996. Boolean search must match as full words.
  3997. This command searches the agenda files, and in addition the files
  3998. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  3999. is active."
  4000. (interactive "P")
  4001. (if org-agenda-overriding-arguments
  4002. (setq todo-only (car org-agenda-overriding-arguments)
  4003. string (nth 1 org-agenda-overriding-arguments)
  4004. edit-at (nth 2 org-agenda-overriding-arguments)))
  4005. (let* ((props (list 'face nil
  4006. 'done-face 'org-agenda-done
  4007. 'org-not-done-regexp org-not-done-regexp
  4008. 'org-todo-regexp org-todo-regexp
  4009. 'org-complex-heading-regexp org-complex-heading-regexp
  4010. 'mouse-face 'highlight
  4011. 'help-echo (format "mouse-2 or RET jump to location")))
  4012. (full-words org-agenda-search-view-force-full-words)
  4013. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4014. regexp rtn rtnall files file pos inherited-tags
  4015. marker category level tags c neg re boolean
  4016. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4017. (unless (and (not edit-at)
  4018. (stringp string)
  4019. (string-match "\\S-" string))
  4020. (setq string (read-string
  4021. (if org-agenda-search-view-always-boolean
  4022. "[+-]Word/{Regexp} ...: "
  4023. "Phrase or [+-]Word/{Regexp} ...: ")
  4024. (cond
  4025. ((integerp edit-at) (cons string edit-at))
  4026. (edit-at string))
  4027. 'org-agenda-search-history)))
  4028. (catch 'exit
  4029. (if org-agenda-sticky
  4030. (setq org-agenda-buffer-name
  4031. (if (stringp string)
  4032. (format "*Org Agenda(%s:%s)*"
  4033. (or org-keys (or (and todo-only "S") "s")) string)
  4034. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4035. (org-agenda-prepare "SEARCH")
  4036. (org-compile-prefix-format 'search)
  4037. (org-set-sorting-strategy 'search)
  4038. (setq org-agenda-redo-command
  4039. (list 'org-search-view (if todo-only t nil)
  4040. (list 'if 'current-prefix-arg nil string)))
  4041. (setq org-agenda-query-string string)
  4042. (if (equal (string-to-char string) ?*)
  4043. (setq hdl-only t
  4044. words (substring string 1))
  4045. (setq words string))
  4046. (when (equal (string-to-char words) ?!)
  4047. (setq todo-only t
  4048. words (substring words 1)))
  4049. (when (equal (string-to-char words) ?:)
  4050. (setq full-words t
  4051. words (substring words 1)))
  4052. (if (or org-agenda-search-view-always-boolean
  4053. (member (string-to-char words) '(?- ?+ ?\{)))
  4054. (setq boolean t))
  4055. (setq words (split-string words))
  4056. (let (www w)
  4057. (while (setq w (pop words))
  4058. (while (and (string-match "\\\\\\'" w) words)
  4059. (setq w (concat (substring w 0 -1) " " (pop words))))
  4060. (push w www))
  4061. (setq words (nreverse www) www nil)
  4062. (while (setq w (pop words))
  4063. (when (and (string-match "\\`[-+]?{" w)
  4064. (not (string-match "}\\'" w)))
  4065. (while (and words (not (string-match "}\\'" (car words))))
  4066. (setq w (concat w " " (pop words))))
  4067. (setq w (concat w " " (pop words))))
  4068. (push w www))
  4069. (setq words (nreverse www)))
  4070. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4071. (when boolean
  4072. (let (wds w)
  4073. (while (setq w (pop words))
  4074. (if (or (equal (substring w 0 1) "\"")
  4075. (and (> (length w) 1)
  4076. (member (substring w 0 1) '("+" "-"))
  4077. (equal (substring w 1 2) "\"")))
  4078. (while (and words (not (equal (substring w -1) "\"")))
  4079. (setq w (concat w " " (pop words)))))
  4080. (and (string-match "\\`\\([-+]?\\)\"" w)
  4081. (setq w (replace-match "\\1" nil nil w)))
  4082. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4083. (push w wds))
  4084. (setq words (nreverse wds))))
  4085. (if boolean
  4086. (mapc (lambda (w)
  4087. (setq c (string-to-char w))
  4088. (if (equal c ?-)
  4089. (setq neg t w (substring w 1))
  4090. (if (equal c ?+)
  4091. (setq neg nil w (substring w 1))
  4092. (setq neg nil)))
  4093. (if (string-match "\\`{.*}\\'" w)
  4094. (setq re (substring w 1 -1))
  4095. (if full-words
  4096. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4097. (setq re (regexp-quote (downcase w)))))
  4098. (if neg (push re regexps-) (push re regexps+)))
  4099. words)
  4100. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4101. regexps+))
  4102. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4103. (if (not regexps+)
  4104. (setq regexp org-outline-regexp-bol)
  4105. (setq regexp (pop regexps+))
  4106. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4107. regexp))))
  4108. (setq files (org-agenda-files nil 'ifmode))
  4109. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4110. ;; restriction.
  4111. (unless (get 'org-agenda-files 'org-restrict)
  4112. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4113. (pop org-agenda-text-search-extra-files)
  4114. (setq files (org-add-archive-files files))))
  4115. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4116. ;; non-existent ones.
  4117. (setq files (cl-remove-duplicates
  4118. (append files org-agenda-text-search-extra-files)
  4119. :test (lambda (a b)
  4120. (and (file-exists-p a)
  4121. (file-exists-p b)
  4122. (file-equal-p a b))))
  4123. rtnall nil)
  4124. (while (setq file (pop files))
  4125. (setq ee nil)
  4126. (catch 'nextfile
  4127. (org-check-agenda-file file)
  4128. (setq buffer (if (file-exists-p file)
  4129. (org-get-agenda-file-buffer file)
  4130. (error "No such file %s" file)))
  4131. (if (not buffer)
  4132. ;; If file does not exist, make sure an error message is sent
  4133. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4134. file))))
  4135. (with-current-buffer buffer
  4136. (with-syntax-table (org-search-syntax-table)
  4137. (unless (derived-mode-p 'org-mode)
  4138. (error "Agenda file %s is not in Org mode" file))
  4139. (let ((case-fold-search t))
  4140. (save-excursion
  4141. (save-restriction
  4142. (if (eq buffer org-agenda-restrict)
  4143. (narrow-to-region org-agenda-restrict-begin
  4144. org-agenda-restrict-end)
  4145. (widen))
  4146. (goto-char (point-min))
  4147. (unless (or (org-at-heading-p)
  4148. (outline-next-heading))
  4149. (throw 'nextfile t))
  4150. (goto-char (max (point-min) (1- (point))))
  4151. (while (re-search-forward regexp nil t)
  4152. (org-back-to-heading t)
  4153. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4154. (> (org-reduced-level (org-outline-level))
  4155. org-agenda-search-view-max-outline-level)
  4156. (forward-line -1)
  4157. (org-back-to-heading t)))
  4158. (skip-chars-forward "* ")
  4159. (setq beg (point-at-bol)
  4160. beg1 (point)
  4161. end (progn
  4162. (outline-next-heading)
  4163. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4164. (> (org-reduced-level (org-outline-level))
  4165. org-agenda-search-view-max-outline-level)
  4166. (forward-line 1)
  4167. (outline-next-heading)))
  4168. (point)))
  4169. (catch :skip
  4170. (goto-char beg)
  4171. (org-agenda-skip)
  4172. (setq str (buffer-substring-no-properties
  4173. (point-at-bol)
  4174. (if hdl-only (point-at-eol) end)))
  4175. (mapc (lambda (wr) (when (string-match wr str)
  4176. (goto-char (1- end))
  4177. (throw :skip t)))
  4178. regexps-)
  4179. (mapc (lambda (wr) (unless (string-match wr str)
  4180. (goto-char (1- end))
  4181. (throw :skip t)))
  4182. (if todo-only
  4183. (cons (concat "^\\*+[ \t]+"
  4184. org-not-done-regexp)
  4185. regexps+)
  4186. regexps+))
  4187. (goto-char beg)
  4188. (setq marker (org-agenda-new-marker (point))
  4189. category (org-get-category)
  4190. level (make-string (org-reduced-level (org-outline-level)) ? )
  4191. inherited-tags
  4192. (or (eq org-agenda-show-inherited-tags 'always)
  4193. (and (listp org-agenda-show-inherited-tags)
  4194. (memq 'todo org-agenda-show-inherited-tags))
  4195. (and (eq org-agenda-show-inherited-tags t)
  4196. (or (eq org-agenda-use-tag-inheritance t)
  4197. (memq 'todo org-agenda-use-tag-inheritance))))
  4198. tags (org-get-tags-at nil (not inherited-tags))
  4199. txt (org-agenda-format-item
  4200. ""
  4201. (buffer-substring-no-properties
  4202. beg1 (point-at-eol))
  4203. level category tags t))
  4204. (org-add-props txt props
  4205. 'org-marker marker 'org-hd-marker marker
  4206. 'org-todo-regexp org-todo-regexp
  4207. 'level level
  4208. 'org-complex-heading-regexp org-complex-heading-regexp
  4209. 'priority 1000
  4210. 'type "search")
  4211. (push txt ee)
  4212. (goto-char (1- end))))))))))
  4213. (setq rtn (nreverse ee))
  4214. (setq rtnall (append rtnall rtn)))
  4215. (if org-agenda-overriding-header
  4216. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4217. nil 'face 'org-agenda-structure) "\n")
  4218. (insert "Search words: ")
  4219. (add-text-properties (point-min) (1- (point))
  4220. (list 'face 'org-agenda-structure))
  4221. (setq pos (point))
  4222. (insert string "\n")
  4223. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4224. (setq pos (point))
  4225. (unless org-agenda-multi
  4226. (insert (substitute-command-keys "\
  4227. Press `\\[org-agenda-manipulate-query-add]', \
  4228. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4229. `\\[org-agenda-manipulate-query-add-re]', \
  4230. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4231. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4232. (add-text-properties pos (1- (point))
  4233. (list 'face 'org-agenda-structure))))
  4234. (org-agenda-mark-header-line (point-min))
  4235. (when rtnall
  4236. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4237. (goto-char (point-min))
  4238. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4239. (add-text-properties (point-min) (point-max)
  4240. `(org-agenda-type search
  4241. org-last-args (,todo-only ,string ,edit-at)
  4242. org-redo-cmd ,org-agenda-redo-command
  4243. org-series-cmd ,org-cmd))
  4244. (org-agenda-finalize)
  4245. (setq buffer-read-only t))))
  4246. ;;; Agenda TODO list
  4247. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4248. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4249. (concat
  4250. (if (or (equal keywords "ALL") (not keywords))
  4251. (propertize "ALL" 'face 'warning)
  4252. (mapconcat
  4253. (lambda (kw)
  4254. (propertize kw 'face (org-get-todo-face kw)))
  4255. (org-split-string keywords "|")
  4256. "|"))
  4257. "\n"))
  4258. (defvar org-select-this-todo-keyword nil)
  4259. (defvar org-last-arg nil)
  4260. ;;;###autoload
  4261. (defun org-todo-list (&optional arg)
  4262. "Show all (not done) TODO entries from all agenda file in a single list.
  4263. The prefix arg can be used to select a specific TODO keyword and limit
  4264. the list to these. When using `\\[universal-argument]', you will be prompted
  4265. for a keyword. A numeric prefix directly selects the Nth keyword in
  4266. `org-todo-keywords-1'."
  4267. (interactive "P")
  4268. (if org-agenda-overriding-arguments
  4269. (setq arg org-agenda-overriding-arguments))
  4270. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4271. (let* ((today (org-today))
  4272. (date (calendar-gregorian-from-absolute today))
  4273. (kwds org-todo-keywords-for-agenda)
  4274. (completion-ignore-case t)
  4275. (org-select-this-todo-keyword
  4276. (if (stringp arg) arg
  4277. (and arg (integerp arg) (> arg 0)
  4278. (nth (1- arg) kwds))))
  4279. rtn rtnall files file pos)
  4280. (when (equal arg '(4))
  4281. (setq org-select-this-todo-keyword
  4282. (completing-read "Keyword (or KWD1|K2D2|...): "
  4283. (mapcar #'list kwds) nil nil)))
  4284. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4285. (catch 'exit
  4286. (if org-agenda-sticky
  4287. (setq org-agenda-buffer-name
  4288. (if (stringp org-select-this-todo-keyword)
  4289. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4290. org-select-this-todo-keyword)
  4291. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4292. (org-agenda-prepare "TODO")
  4293. (org-compile-prefix-format 'todo)
  4294. (org-set-sorting-strategy 'todo)
  4295. (setq org-agenda-redo-command
  4296. `(org-todo-list (or (and (numberp current-prefix-arg)
  4297. current-prefix-arg)
  4298. ,org-select-this-todo-keyword
  4299. current-prefix-arg ,arg)))
  4300. (setq files (org-agenda-files nil 'ifmode)
  4301. rtnall nil)
  4302. (while (setq file (pop files))
  4303. (catch 'nextfile
  4304. (org-check-agenda-file file)
  4305. (setq rtn (org-agenda-get-day-entries file date :todo))
  4306. (setq rtnall (append rtnall rtn))))
  4307. (if org-agenda-overriding-header
  4308. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4309. nil 'face 'org-agenda-structure) "\n")
  4310. (insert "Global list of TODO items of type: ")
  4311. (add-text-properties (point-min) (1- (point))
  4312. (list 'face 'org-agenda-structure
  4313. 'short-heading
  4314. (concat "ToDo: "
  4315. (or org-select-this-todo-keyword "ALL"))))
  4316. (org-agenda-mark-header-line (point-min))
  4317. (insert (org-agenda-propertize-selected-todo-keywords
  4318. org-select-this-todo-keyword))
  4319. (setq pos (point))
  4320. (unless org-agenda-multi
  4321. (insert (substitute-command-keys "Available with \
  4322. `N \\[org-agenda-redo]': (0)[ALL]"))
  4323. (let ((n 0) s)
  4324. (mapc (lambda (x)
  4325. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4326. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4327. (insert "\n "))
  4328. (insert " " s))
  4329. kwds))
  4330. (insert "\n"))
  4331. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4332. (org-agenda-mark-header-line (point-min))
  4333. (when rtnall
  4334. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4335. (goto-char (point-min))
  4336. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4337. (add-text-properties (point-min) (point-max)
  4338. `(org-agenda-type todo
  4339. org-last-args ,arg
  4340. org-redo-cmd ,org-agenda-redo-command
  4341. org-series-cmd ,org-cmd))
  4342. (org-agenda-finalize)
  4343. (setq buffer-read-only t))))
  4344. ;;; Agenda tags match
  4345. ;;;###autoload
  4346. (defun org-tags-view (&optional todo-only match)
  4347. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4348. The prefix arg TODO-ONLY limits the search to TODO entries."
  4349. (interactive "P")
  4350. (if org-agenda-overriding-arguments
  4351. (setq todo-only (car org-agenda-overriding-arguments)
  4352. match (nth 1 org-agenda-overriding-arguments)))
  4353. (let* ((org-tags-match-list-sublevels
  4354. org-tags-match-list-sublevels)
  4355. (completion-ignore-case t)
  4356. (org--matcher-tags-todo-only todo-only)
  4357. rtn rtnall files file pos matcher
  4358. buffer)
  4359. (when (and (stringp match) (not (string-match "\\S-" match)))
  4360. (setq match nil))
  4361. (catch 'exit
  4362. (if org-agenda-sticky
  4363. (setq org-agenda-buffer-name
  4364. (if (stringp match)
  4365. (format "*Org Agenda(%s:%s)*"
  4366. (or org-keys (or (and todo-only "M") "m")) match)
  4367. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4368. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4369. ;; expanding tags within `org-make-tags-matcher'
  4370. (org-agenda-prepare (concat "TAGS " match))
  4371. (setq matcher (org-make-tags-matcher match)
  4372. match (car matcher)
  4373. matcher (cdr matcher))
  4374. (org-compile-prefix-format 'tags)
  4375. (org-set-sorting-strategy 'tags)
  4376. (setq org-agenda-query-string match)
  4377. (setq org-agenda-redo-command
  4378. (list 'org-tags-view
  4379. `(quote ,org--matcher-tags-todo-only)
  4380. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4381. (setq files (org-agenda-files nil 'ifmode)
  4382. rtnall nil)
  4383. (while (setq file (pop files))
  4384. (catch 'nextfile
  4385. (org-check-agenda-file file)
  4386. (setq buffer (if (file-exists-p file)
  4387. (org-get-agenda-file-buffer file)
  4388. (error "No such file %s" file)))
  4389. (if (not buffer)
  4390. ;; If file does not exist, error message to agenda
  4391. (setq rtn (list
  4392. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4393. rtnall (append rtnall rtn))
  4394. (with-current-buffer buffer
  4395. (unless (derived-mode-p 'org-mode)
  4396. (error "Agenda file %s is not in Org mode" file))
  4397. (save-excursion
  4398. (save-restriction
  4399. (if (eq buffer org-agenda-restrict)
  4400. (narrow-to-region org-agenda-restrict-begin
  4401. org-agenda-restrict-end)
  4402. (widen))
  4403. (setq rtn (org-scan-tags 'agenda
  4404. matcher
  4405. org--matcher-tags-todo-only))
  4406. (setq rtnall (append rtnall rtn))))))))
  4407. (if org-agenda-overriding-header
  4408. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4409. nil 'face 'org-agenda-structure) "\n")
  4410. (insert "Headlines with TAGS match: ")
  4411. (add-text-properties (point-min) (1- (point))
  4412. (list 'face 'org-agenda-structure
  4413. 'short-heading
  4414. (concat "Match: " match)))
  4415. (setq pos (point))
  4416. (insert match "\n")
  4417. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4418. (setq pos (point))
  4419. (unless org-agenda-multi
  4420. (insert (substitute-command-keys
  4421. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4422. to search again with new search string\n")))
  4423. (add-text-properties pos (1- (point))
  4424. (list 'face 'org-agenda-structure)))
  4425. (org-agenda-mark-header-line (point-min))
  4426. (when rtnall
  4427. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4428. (goto-char (point-min))
  4429. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4430. (add-text-properties
  4431. (point-min) (point-max)
  4432. `(org-agenda-type tags
  4433. org-last-args (,org--matcher-tags-todo-only ,match)
  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 Finding stuck projects
  4439. (defvar org-agenda-skip-regexp nil
  4440. "Regular expression used in skipping subtrees for the agenda.
  4441. This is basically a temporary global variable that can be set and then
  4442. used by user-defined selections using `org-agenda-skip-function'.")
  4443. (defvar org-agenda-overriding-header nil
  4444. "When set during agenda, todo and tags searches it replaces the header.
  4445. This variable should not be set directly, but custom commands can bind it
  4446. in the options section.")
  4447. (defun org-agenda-skip-entry-if (&rest conditions)
  4448. "Skip entry if any of CONDITIONS is true.
  4449. See `org-agenda-skip-if' for details."
  4450. (org-agenda-skip-if nil conditions))
  4451. (defun org-agenda-skip-subtree-if (&rest conditions)
  4452. "Skip subtree if any of CONDITIONS is true.
  4453. See `org-agenda-skip-if' for details."
  4454. (org-agenda-skip-if t conditions))
  4455. (defun org-agenda-skip-if (subtree conditions)
  4456. "Checks current entity for CONDITIONS.
  4457. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4458. the entry (i.e. the text before the next heading) is checked.
  4459. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4460. from different tests. Valid conditions are:
  4461. scheduled Check if there is a scheduled cookie
  4462. notscheduled Check if there is no scheduled cookie
  4463. deadline Check if there is a deadline
  4464. notdeadline Check if there is no deadline
  4465. timestamp Check if there is a timestamp (also deadline or scheduled)
  4466. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4467. regexp Check if regexp matches
  4468. notregexp Check if regexp does not match.
  4469. todo Check if TODO keyword matches
  4470. nottodo Check if TODO keyword does not match
  4471. The regexp is taken from the conditions list, it must come right after
  4472. the `regexp' or `notregexp' element.
  4473. `todo' and `nottodo' accept as an argument a list of todo
  4474. keywords, which may include \"*\" to match any todo keyword.
  4475. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4476. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4477. Instead of a list, a keyword class may be given. For example:
  4478. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4479. would skip entries that haven't been marked with any of \"DONE\"
  4480. keywords. Possible classes are: `todo', `done', `any'.
  4481. If any of these conditions is met, this function returns the end point of
  4482. the entity, causing the search to continue from there. This is a function
  4483. that can be put into `org-agenda-skip-function' for the duration of a command."
  4484. (org-back-to-heading t)
  4485. (let* ((beg (point))
  4486. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4487. (org-entry-end-position)))
  4488. (planning-end (if subtree end (line-end-position 2)))
  4489. m)
  4490. (and
  4491. (or (and (memq 'scheduled conditions)
  4492. (re-search-forward org-scheduled-time-regexp planning-end t))
  4493. (and (memq 'notscheduled conditions)
  4494. (not
  4495. (save-excursion
  4496. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4497. (and (memq 'deadline conditions)
  4498. (re-search-forward org-deadline-time-regexp planning-end t))
  4499. (and (memq 'notdeadline conditions)
  4500. (not
  4501. (save-excursion
  4502. (re-search-forward org-deadline-time-regexp planning-end t))))
  4503. (and (memq 'timestamp conditions)
  4504. (re-search-forward org-ts-regexp end t))
  4505. (and (memq 'nottimestamp conditions)
  4506. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4507. (and (setq m (memq 'regexp conditions))
  4508. (stringp (nth 1 m))
  4509. (re-search-forward (nth 1 m) end t))
  4510. (and (setq m (memq 'notregexp conditions))
  4511. (stringp (nth 1 m))
  4512. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4513. (and (or
  4514. (setq m (memq 'nottodo conditions))
  4515. (setq m (memq 'todo-unblocked conditions))
  4516. (setq m (memq 'nottodo-unblocked conditions))
  4517. (setq m (memq 'todo conditions)))
  4518. (org-agenda-skip-if-todo m end)))
  4519. end)))
  4520. (defun org-agenda-skip-if-todo (args end)
  4521. "Helper function for `org-agenda-skip-if', do not use it directly.
  4522. ARGS is a list with first element either `todo', `nottodo',
  4523. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4524. a list of TODO keywords, or a state symbol `todo' or `done' or
  4525. `any'."
  4526. (let ((todo-re
  4527. (concat "^\\*+[ \t]+"
  4528. (regexp-opt
  4529. (pcase args
  4530. (`(,_ todo)
  4531. (org-delete-all org-done-keywords
  4532. (copy-sequence org-todo-keywords-1)))
  4533. (`(,_ done) org-done-keywords)
  4534. (`(,_ any) org-todo-keywords-1)
  4535. (`(,_ ,(pred atom))
  4536. (error "Invalid TODO class or type: %S" args))
  4537. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4538. (`(,_ ,todo-list) todo-list))
  4539. 'words))))
  4540. (pcase args
  4541. (`(todo . ,_)
  4542. (let (case-fold-search) (re-search-forward todo-re end t)))
  4543. (`(nottodo . ,_)
  4544. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4545. (`(todo-unblocked . ,_)
  4546. (catch :unblocked
  4547. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4548. (when (org-entry-blocked-p) (throw :unblocked t)))
  4549. nil))
  4550. (`(nottodo-unblocked . ,_)
  4551. (catch :unblocked
  4552. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4553. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4554. t))
  4555. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4556. ;;;###autoload
  4557. (defun org-agenda-list-stuck-projects (&rest ignore)
  4558. "Create agenda view for projects that are stuck.
  4559. Stuck projects are project that have no next actions. For the definitions
  4560. of what a project is and how to check if it stuck, customize the variable
  4561. `org-stuck-projects'."
  4562. (interactive)
  4563. (let* ((org-agenda-overriding-header
  4564. (or org-agenda-overriding-header "List of stuck projects: "))
  4565. (matcher (nth 0 org-stuck-projects))
  4566. (todo (nth 1 org-stuck-projects))
  4567. (tags (nth 2 org-stuck-projects))
  4568. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4569. (todo-wds
  4570. (if (not (member "*" todo)) todo
  4571. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4572. (org-delete-all org-done-keywords-for-agenda
  4573. (copy-sequence org-todo-keywords-for-agenda))))
  4574. (todo-re (and todo
  4575. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4576. (mapconcat #'identity todo-wds "\\|"))))
  4577. (tags-re (cond ((null tags) nil)
  4578. ((member "*" tags)
  4579. (eval-when-compile
  4580. (concat org-outline-regexp-bol
  4581. ".*:[[:alnum:]_@#%]+:[ \t]*$")))
  4582. (tags (concat org-outline-regexp-bol
  4583. ".*:\\("
  4584. (mapconcat #'identity tags "\\|")
  4585. "\\):[[:alnum:]_@#%:]*[ \t]*$"))
  4586. (t nil)))
  4587. (re-list (delq nil (list todo-re tags-re gen-re)))
  4588. (skip-re
  4589. (if (null re-list)
  4590. (error "Missing information to identify unstuck projects")
  4591. (mapconcat #'identity re-list "\\|")))
  4592. (org-agenda-skip-function
  4593. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4594. ;; in the subtree.
  4595. `(lambda ()
  4596. (and (save-excursion
  4597. (let ((case-fold-search nil))
  4598. (re-search-forward
  4599. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4600. (progn (outline-next-heading) (point))))))
  4601. (org-tags-view nil matcher)
  4602. (setq org-agenda-buffer-name (buffer-name))
  4603. (with-current-buffer org-agenda-buffer-name
  4604. (setq org-agenda-redo-command
  4605. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4606. (let ((inhibit-read-only t))
  4607. (add-text-properties
  4608. (point-min) (point-max)
  4609. `(org-redo-cmd ,org-agenda-redo-command))))))
  4610. ;;; Diary integration
  4611. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4612. (defvar diary-list-entries-hook)
  4613. (defvar diary-time-regexp)
  4614. (defun org-get-entries-from-diary (date)
  4615. "Get the (Emacs Calendar) diary entries for DATE."
  4616. (require 'diary-lib)
  4617. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4618. (diary-display-function 'diary-fancy-display)
  4619. (pop-up-frames nil)
  4620. (diary-list-entries-hook
  4621. (cons 'org-diary-default-entry diary-list-entries-hook))
  4622. (diary-file-name-prefix nil) ; turn this feature off
  4623. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4624. entries
  4625. (org-disable-agenda-to-diary t))
  4626. (save-excursion
  4627. (save-window-excursion
  4628. (funcall (if (fboundp 'diary-list-entries)
  4629. 'diary-list-entries 'list-diary-entries)
  4630. date 1)))
  4631. (if (not (get-buffer diary-fancy-buffer))
  4632. (setq entries nil)
  4633. (with-current-buffer diary-fancy-buffer
  4634. (setq buffer-read-only nil)
  4635. (if (zerop (buffer-size))
  4636. ;; No entries
  4637. (setq entries nil)
  4638. ;; Omit the date and other unnecessary stuff
  4639. (org-agenda-cleanup-fancy-diary)
  4640. ;; Add prefix to each line and extend the text properties
  4641. (if (zerop (buffer-size))
  4642. (setq entries nil)
  4643. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4644. (setq entries
  4645. (with-temp-buffer
  4646. (insert entries) (goto-char (point-min))
  4647. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4648. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4649. (replace-match (concat "; " (match-string 1)))))
  4650. (buffer-string)))))
  4651. (set-buffer-modified-p nil)
  4652. (kill-buffer diary-fancy-buffer)))
  4653. (when entries
  4654. (setq entries (org-split-string entries "\n"))
  4655. (setq entries
  4656. (mapcar
  4657. (lambda (x)
  4658. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4659. ;; Extend the text properties to the beginning of the line
  4660. (org-add-props x (text-properties-at (1- (length x)) x)
  4661. 'type "diary" 'date date 'face 'org-agenda-diary))
  4662. entries)))))
  4663. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4664. "Hook run when the fancy diary buffer is cleaned up.")
  4665. (defun org-agenda-cleanup-fancy-diary ()
  4666. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4667. This gets rid of the date, the underline under the date, and the
  4668. dummy entry installed by Org mode to ensure non-empty diary for
  4669. each date. It also removes lines that contain only whitespace."
  4670. (goto-char (point-min))
  4671. (if (looking-at ".*?:[ \t]*")
  4672. (progn
  4673. (replace-match "")
  4674. (re-search-forward "\n=+$" nil t)
  4675. (replace-match "")
  4676. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4677. (re-search-forward "\n=+$" nil t)
  4678. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4679. (goto-char (point-min))
  4680. (while (re-search-forward "^ +\n" nil t)
  4681. (replace-match ""))
  4682. (goto-char (point-min))
  4683. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4684. (replace-match ""))
  4685. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4686. ;; Make sure entries from the diary have the right text properties.
  4687. (eval-after-load "diary-lib"
  4688. '(if (boundp 'diary-modify-entry-list-string-function)
  4689. ;; We can rely on the hook, nothing to do
  4690. nil
  4691. ;; Hook not available, must use advice to make this work
  4692. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4693. "Make the position visible."
  4694. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4695. (stringp string)
  4696. buffer-file-name)
  4697. (setq string (org-modify-diary-entry-string string))))))
  4698. (defun org-modify-diary-entry-string (string)
  4699. "Add text properties to string, allowing Org to act on it."
  4700. (org-add-props string nil
  4701. 'mouse-face 'highlight
  4702. 'help-echo (if buffer-file-name
  4703. (format "mouse-2 or RET jump to diary file %s"
  4704. (abbreviate-file-name buffer-file-name))
  4705. "")
  4706. 'org-agenda-diary-link t
  4707. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4708. (defun org-diary-default-entry ()
  4709. "Add a dummy entry to the diary.
  4710. Needed to avoid empty dates which mess up holiday display."
  4711. ;; Catch the error if dealing with the new add-to-diary-alist
  4712. (when org-disable-agenda-to-diary
  4713. (condition-case nil
  4714. (org-add-to-diary-list original-date "Org mode dummy" "")
  4715. (error
  4716. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4717. (defun org-add-to-diary-list (&rest args)
  4718. (if (fboundp 'diary-add-to-list)
  4719. (apply 'diary-add-to-list args)
  4720. (apply 'add-to-diary-list args)))
  4721. (defvar org-diary-last-run-time nil)
  4722. ;;;###autoload
  4723. (defun org-diary (&rest args)
  4724. "Return diary information from org files.
  4725. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4726. It accesses org files and extracts information from those files to be
  4727. listed in the diary. The function accepts arguments specifying what
  4728. items should be listed. For a list of arguments allowed here, see the
  4729. variable `org-agenda-entry-types'.
  4730. The call in the diary file should look like this:
  4731. &%%(org-diary) ~/path/to/some/orgfile.org
  4732. Use a separate line for each org file to check. Or, if you omit the file name,
  4733. all files listed in `org-agenda-files' will be checked automatically:
  4734. &%%(org-diary)
  4735. If you don't give any arguments (as in the example above), the default value
  4736. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4737. So the example above may also be written as
  4738. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4739. The function expects the lisp variables `entry' and `date' to be provided
  4740. by the caller, because this is how the calendar works. Don't use this
  4741. function from a program - use `org-agenda-get-day-entries' instead."
  4742. (when (> (- (float-time)
  4743. org-agenda-last-marker-time)
  4744. 5)
  4745. ;; I am not sure if this works with sticky agendas, because the marker
  4746. ;; list is then no longer a global variable.
  4747. (org-agenda-reset-markers))
  4748. (org-compile-prefix-format 'agenda)
  4749. (org-set-sorting-strategy 'agenda)
  4750. (setq args (or args org-agenda-entry-types))
  4751. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4752. (list entry)
  4753. (org-agenda-files t)))
  4754. (time (float-time))
  4755. file rtn results)
  4756. (when (or (not org-diary-last-run-time)
  4757. (> (- time
  4758. org-diary-last-run-time)
  4759. 3))
  4760. (org-agenda-prepare-buffers files))
  4761. (setq org-diary-last-run-time time)
  4762. ;; If this is called during org-agenda, don't return any entries to
  4763. ;; the calendar. Org Agenda will list these entries itself.
  4764. (if org-disable-agenda-to-diary (setq files nil))
  4765. (while (setq file (pop files))
  4766. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4767. (setq results (append results rtn)))
  4768. (when results
  4769. (setq results
  4770. (mapcar (lambda (i) (replace-regexp-in-string
  4771. org-bracket-link-regexp "\\3" i)) results))
  4772. (concat (org-agenda-finalize-entries results) "\n"))))
  4773. ;;; Agenda entry finders
  4774. (defun org-agenda--timestamp-to-absolute (&rest args)
  4775. "Call `org-time-string-to-absolute' with ARGS.
  4776. However, throw `:skip' whenever an error is raised."
  4777. (condition-case e
  4778. (apply #'org-time-string-to-absolute args)
  4779. (org-diary-sexp-no-match (throw :skip nil))
  4780. (error
  4781. (message "%s; Skipping entry" (error-message-string e))
  4782. (throw :skip nil))))
  4783. (defun org-agenda-get-day-entries (file date &rest args)
  4784. "Does the work for `org-diary' and `org-agenda'.
  4785. FILE is the path to a file to be checked for entries. DATE is date like
  4786. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4787. which kind of entries should be extracted. For details about these, see
  4788. the documentation of `org-diary'."
  4789. (let* ((org-startup-folded nil)
  4790. (org-startup-align-all-tables nil)
  4791. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4792. (error "No such file %s" file))))
  4793. (if (not buffer)
  4794. ;; If file does not exist, signal it in diary nonetheless.
  4795. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4796. (with-current-buffer buffer
  4797. (unless (derived-mode-p 'org-mode)
  4798. (error "Agenda file %s is not in Org mode" file))
  4799. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4800. (setf org-agenda-current-date date)
  4801. (save-excursion
  4802. (save-restriction
  4803. (if (eq buffer org-agenda-restrict)
  4804. (narrow-to-region org-agenda-restrict-begin
  4805. org-agenda-restrict-end)
  4806. (widen))
  4807. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4808. ;; first in order to populate DEADLINES before passing it.
  4809. ;;
  4810. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4811. ;; guarding us from modifying `org-agenda-entry-types'.
  4812. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4813. (when (and (memq :scheduled args) (memq :scheduled* args))
  4814. (setf args (delq :scheduled* args)))
  4815. (cond
  4816. ((memq :deadline args)
  4817. (setf args (cons :deadline
  4818. (delq :deadline (delq :deadline* args)))))
  4819. ((memq :deadline* args)
  4820. (setf args (cons :deadline* (delq :deadline* args)))))
  4821. ;; Collect list of headlines. Return them flattened.
  4822. (let ((case-fold-search nil) results deadlines)
  4823. (dolist (arg args (apply #'nconc (nreverse results)))
  4824. (pcase arg
  4825. ((and :todo (guard (org-agenda-today-p date)))
  4826. (push (org-agenda-get-todos) results))
  4827. (:timestamp
  4828. (push (org-agenda-get-blocks) results)
  4829. (push (org-agenda-get-timestamps deadlines) results))
  4830. (:sexp
  4831. (push (org-agenda-get-sexps) results))
  4832. (:scheduled
  4833. (push (org-agenda-get-scheduled deadlines) results))
  4834. (:scheduled*
  4835. (push (org-agenda-get-scheduled deadlines t) results))
  4836. (:closed
  4837. (push (org-agenda-get-progress) results))
  4838. (:deadline
  4839. (setf deadlines (org-agenda-get-deadlines))
  4840. (push deadlines results))
  4841. (:deadline*
  4842. (setf deadlines (org-agenda-get-deadlines t))
  4843. (push deadlines results)))))))))))
  4844. (defsubst org-em (x y list)
  4845. "Is X or Y a member of LIST?"
  4846. (or (memq x list) (memq y list)))
  4847. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4848. (defvar org-agenda-sorting-strategy-selected nil)
  4849. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4850. "Retrieve timestamp information for sorting agenda views.
  4851. Given a point or marker POM, returns a cons cell of the timestamp
  4852. and the timestamp type relevant for the sorting strategy in
  4853. `org-agenda-sorting-strategy-selected'."
  4854. (let (ts ts-date-type)
  4855. (save-match-data
  4856. (cond ((org-em 'scheduled-up 'scheduled-down
  4857. org-agenda-sorting-strategy-selected)
  4858. (setq ts (org-entry-get pom "SCHEDULED")
  4859. ts-date-type " scheduled"))
  4860. ((org-em 'deadline-up 'deadline-down
  4861. org-agenda-sorting-strategy-selected)
  4862. (setq ts (org-entry-get pom "DEADLINE")
  4863. ts-date-type " deadline"))
  4864. ((org-em 'ts-up 'ts-down
  4865. org-agenda-sorting-strategy-selected)
  4866. (setq ts (org-entry-get pom "TIMESTAMP")
  4867. ts-date-type " timestamp"))
  4868. ((org-em 'tsia-up 'tsia-down
  4869. org-agenda-sorting-strategy-selected)
  4870. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4871. ts-date-type " timestamp_ia"))
  4872. ((org-em 'timestamp-up 'timestamp-down
  4873. org-agenda-sorting-strategy-selected)
  4874. (setq ts (or (org-entry-get pom "SCHEDULED")
  4875. (org-entry-get pom "DEADLINE")
  4876. (org-entry-get pom "TIMESTAMP")
  4877. (org-entry-get pom "TIMESTAMP_IA"))
  4878. ts-date-type ""))
  4879. (t (setq ts-date-type "")))
  4880. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4881. ts-date-type))))
  4882. (defun org-agenda-get-todos ()
  4883. "Return the TODO information for agenda display."
  4884. (let* ((props (list 'face nil
  4885. 'done-face 'org-agenda-done
  4886. 'org-not-done-regexp org-not-done-regexp
  4887. 'org-todo-regexp org-todo-regexp
  4888. 'org-complex-heading-regexp org-complex-heading-regexp
  4889. 'mouse-face 'highlight
  4890. 'help-echo
  4891. (format "mouse-2 or RET jump to org file %s"
  4892. (abbreviate-file-name buffer-file-name))))
  4893. (case-fold-search nil)
  4894. (regexp (format org-heading-keyword-regexp-format
  4895. (cond
  4896. ((and org-select-this-todo-keyword
  4897. (equal org-select-this-todo-keyword "*"))
  4898. org-todo-regexp)
  4899. (org-select-this-todo-keyword
  4900. (concat "\\("
  4901. (mapconcat 'identity
  4902. (org-split-string
  4903. org-select-this-todo-keyword
  4904. "|")
  4905. "\\|") "\\)"))
  4906. (t org-not-done-regexp))))
  4907. marker priority category level tags todo-state
  4908. ts-date ts-date-type ts-date-pair
  4909. ee txt beg end inherited-tags todo-state-end-pos)
  4910. (goto-char (point-min))
  4911. (while (re-search-forward regexp nil t)
  4912. (catch :skip
  4913. (save-match-data
  4914. (beginning-of-line)
  4915. (org-agenda-skip)
  4916. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4917. (unless (and (setq todo-state (org-get-todo-state))
  4918. (setq todo-state-end-pos (match-end 2)))
  4919. (goto-char end)
  4920. (throw :skip nil))
  4921. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4922. (goto-char (1+ beg))
  4923. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4924. (throw :skip nil)))
  4925. (goto-char (match-beginning 2))
  4926. (setq marker (org-agenda-new-marker (match-beginning 0))
  4927. category (org-get-category)
  4928. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4929. ts-date (car ts-date-pair)
  4930. ts-date-type (cdr ts-date-pair)
  4931. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4932. inherited-tags
  4933. (or (eq org-agenda-show-inherited-tags 'always)
  4934. (and (listp org-agenda-show-inherited-tags)
  4935. (memq 'todo org-agenda-show-inherited-tags))
  4936. (and (eq org-agenda-show-inherited-tags t)
  4937. (or (eq org-agenda-use-tag-inheritance t)
  4938. (memq 'todo org-agenda-use-tag-inheritance))))
  4939. tags (org-get-tags-at nil (not inherited-tags))
  4940. level (make-string (org-reduced-level (org-outline-level)) ? )
  4941. txt (org-agenda-format-item "" txt level category tags t)
  4942. priority (1+ (org-get-priority txt)))
  4943. (org-add-props txt props
  4944. 'org-marker marker 'org-hd-marker marker
  4945. 'priority priority
  4946. 'level level
  4947. 'ts-date ts-date
  4948. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4949. (push txt ee)
  4950. (if org-agenda-todo-list-sublevels
  4951. (goto-char todo-state-end-pos)
  4952. (org-end-of-subtree 'invisible))))
  4953. (nreverse ee)))
  4954. (defun org-agenda-todo-custom-ignore-p (time n)
  4955. "Check whether timestamp is farther away than n number of days.
  4956. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4957. `org-agenda-todo-ignore-scheduled' or
  4958. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4959. (let ((days (org-time-stamp-to-now
  4960. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4961. (if (>= n 0)
  4962. (>= days n)
  4963. (<= days n))))
  4964. ;;;###autoload
  4965. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4966. (&optional end)
  4967. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4968. (when (or org-agenda-todo-ignore-with-date
  4969. org-agenda-todo-ignore-scheduled
  4970. org-agenda-todo-ignore-deadlines
  4971. org-agenda-todo-ignore-timestamp)
  4972. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4973. (save-excursion
  4974. (or (and org-agenda-todo-ignore-with-date
  4975. (re-search-forward org-ts-regexp end t))
  4976. (and org-agenda-todo-ignore-scheduled
  4977. (re-search-forward org-scheduled-time-regexp end t)
  4978. (cond
  4979. ((eq org-agenda-todo-ignore-scheduled 'future)
  4980. (> (org-time-stamp-to-now
  4981. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4982. ((eq org-agenda-todo-ignore-scheduled 'past)
  4983. (<= (org-time-stamp-to-now
  4984. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4985. ((numberp org-agenda-todo-ignore-scheduled)
  4986. (org-agenda-todo-custom-ignore-p
  4987. (match-string 1) org-agenda-todo-ignore-scheduled))
  4988. (t)))
  4989. (and org-agenda-todo-ignore-deadlines
  4990. (re-search-forward org-deadline-time-regexp end t)
  4991. (cond
  4992. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4993. ((eq org-agenda-todo-ignore-deadlines 'far)
  4994. (not (org-deadline-close-p (match-string 1))))
  4995. ((eq org-agenda-todo-ignore-deadlines 'future)
  4996. (> (org-time-stamp-to-now
  4997. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4998. ((eq org-agenda-todo-ignore-deadlines 'past)
  4999. (<= (org-time-stamp-to-now
  5000. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5001. ((numberp org-agenda-todo-ignore-deadlines)
  5002. (org-agenda-todo-custom-ignore-p
  5003. (match-string 1) org-agenda-todo-ignore-deadlines))
  5004. (t (org-deadline-close-p (match-string 1)))))
  5005. (and org-agenda-todo-ignore-timestamp
  5006. (let ((buffer (current-buffer))
  5007. (regexp
  5008. (concat
  5009. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5010. (start (point)))
  5011. ;; Copy current buffer into a temporary one
  5012. (with-temp-buffer
  5013. (insert-buffer-substring buffer start end)
  5014. (goto-char (point-min))
  5015. ;; Delete SCHEDULED and DEADLINE items
  5016. (while (re-search-forward regexp end t)
  5017. (delete-region (match-beginning 0) (match-end 0)))
  5018. (goto-char (point-min))
  5019. ;; No search for timestamp left
  5020. (when (re-search-forward org-ts-regexp nil t)
  5021. (cond
  5022. ((eq org-agenda-todo-ignore-timestamp 'future)
  5023. (> (org-time-stamp-to-now
  5024. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5025. ((eq org-agenda-todo-ignore-timestamp 'past)
  5026. (<= (org-time-stamp-to-now
  5027. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5028. ((numberp org-agenda-todo-ignore-timestamp)
  5029. (org-agenda-todo-custom-ignore-p
  5030. (match-string 1) org-agenda-todo-ignore-timestamp))
  5031. (t))))))))))
  5032. (defun org-agenda-get-timestamps (&optional deadlines)
  5033. "Return the date stamp information for agenda display.
  5034. Optional argument DEADLINES is a list of deadline items to be
  5035. displayed in agenda view."
  5036. (let* ((props (list 'face 'org-agenda-calendar-event
  5037. 'org-not-done-regexp org-not-done-regexp
  5038. 'org-todo-regexp org-todo-regexp
  5039. 'org-complex-heading-regexp org-complex-heading-regexp
  5040. 'mouse-face 'highlight
  5041. 'help-echo
  5042. (format "mouse-2 or RET jump to Org file %s"
  5043. (abbreviate-file-name buffer-file-name))))
  5044. (current (calendar-absolute-from-gregorian date))
  5045. (today (org-today))
  5046. (deadline-position-alist
  5047. (mapcar (lambda (d)
  5048. (let ((m (get-text-property 0 'org-hd-marker d)))
  5049. (and m (marker-position m))))
  5050. deadlines))
  5051. ;; Match time-stamps set to current date, time-stamps with
  5052. ;; a repeater, and S-exp time-stamps.
  5053. (regexp
  5054. (concat
  5055. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5056. (regexp-quote
  5057. (substring
  5058. (format-time-string
  5059. (car org-time-stamp-formats)
  5060. (apply #'encode-time ; DATE bound by calendar
  5061. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5062. 1 11))
  5063. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5064. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5065. timestamp-items)
  5066. (goto-char (point-min))
  5067. (while (re-search-forward regexp nil t)
  5068. ;; Skip date ranges, scheduled and deadlines, which are handled
  5069. ;; specially. Also skip time-stamps before first headline as
  5070. ;; there would be no entry to add to the agenda. Eventually,
  5071. ;; ignore clock entries.
  5072. (catch :skip
  5073. (save-match-data
  5074. (when (or (org-at-date-range-p)
  5075. (org-at-planning-p)
  5076. (org-before-first-heading-p)
  5077. (and org-agenda-include-inactive-timestamps
  5078. (org-at-clock-log-p)))
  5079. (throw :skip nil))
  5080. (org-agenda-skip))
  5081. (let* ((pos (match-beginning 0))
  5082. (repeat (match-string 1))
  5083. (sexp-entry (match-string 3))
  5084. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5085. (save-excursion
  5086. (goto-char pos)
  5087. (looking-at org-ts-regexp-both)
  5088. (match-string 0))))
  5089. (todo-state (org-get-todo-state))
  5090. (warntime (get-text-property (point) 'org-appt-warntime))
  5091. (done? (member todo-state org-done-keywords)))
  5092. ;; Possibly skip done tasks.
  5093. (when (and done? org-agenda-skip-timestamp-if-done)
  5094. (throw :skip t))
  5095. ;; S-exp entry doesn't match current day: skip it.
  5096. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5097. (throw :skip nil))
  5098. (when repeat
  5099. (let* ((past
  5100. ;; A repeating time stamp is shown at its base
  5101. ;; date and every repeated date up to TODAY. If
  5102. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5103. ;; however, only the last repeat before today
  5104. ;; (inclusive) is shown.
  5105. (org-agenda--timestamp-to-absolute
  5106. repeat
  5107. (if (or (> current today)
  5108. (eq org-agenda-prefer-last-repeat t)
  5109. (member todo-state org-agenda-prefer-last-repeat))
  5110. today
  5111. current)
  5112. 'past (current-buffer) pos))
  5113. (future
  5114. ;; Display every repeated date past TODAY
  5115. ;; (exclusive) unless
  5116. ;; `org-agenda-show-future-repeats' is nil. If
  5117. ;; this variable is set to `next', only display
  5118. ;; the first repeated date after TODAY
  5119. ;; (exclusive).
  5120. (cond
  5121. ((<= current today) past)
  5122. ((not org-agenda-show-future-repeats) past)
  5123. (t
  5124. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5125. (1+ today)
  5126. current)))
  5127. (org-agenda--timestamp-to-absolute
  5128. repeat base 'future (current-buffer) pos))))))
  5129. (when (and (/= current past) (/= current future))
  5130. (throw :skip nil))))
  5131. (save-excursion
  5132. (re-search-backward org-outline-regexp-bol nil t)
  5133. ;; Possibly skip time-stamp when a deadline is set.
  5134. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5135. (assq (point) deadline-position-alist))
  5136. (throw :skip nil))
  5137. (let* ((category (org-get-category pos))
  5138. (inherited-tags
  5139. (or (eq org-agenda-show-inherited-tags 'always)
  5140. (and (consp org-agenda-show-inherited-tags)
  5141. (memq 'agenda org-agenda-show-inherited-tags))
  5142. (and (eq org-agenda-show-inherited-tags t)
  5143. (or (eq org-agenda-use-tag-inheritance t)
  5144. (memq 'agenda
  5145. org-agenda-use-tag-inheritance)))))
  5146. (tags (org-get-tags-at nil (not inherited-tags)))
  5147. (level (make-string (org-reduced-level (org-outline-level))
  5148. ?\s))
  5149. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5150. (match-string 1)))
  5151. (inactive? (= (char-after pos) ?\[))
  5152. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5153. (item
  5154. (org-agenda-format-item
  5155. (and inactive? org-agenda-inactive-leader)
  5156. head level category tags time-stamp org-ts-regexp habit?)))
  5157. (org-add-props item props
  5158. 'priority (if habit?
  5159. (org-habit-get-priority (org-habit-parse-todo))
  5160. (org-get-priority item))
  5161. 'org-marker (org-agenda-new-marker pos)
  5162. 'org-hd-marker (org-agenda-new-marker)
  5163. 'date date
  5164. 'level level
  5165. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5166. current)
  5167. 'todo-state todo-state
  5168. 'warntime warntime
  5169. 'type "timestamp")
  5170. (push item timestamp-items))))
  5171. (when org-agenda-skip-additional-timestamps-same-entry
  5172. (outline-next-heading))))
  5173. (nreverse timestamp-items)))
  5174. (defun org-agenda-get-sexps ()
  5175. "Return the sexp information for agenda display."
  5176. (require 'diary-lib)
  5177. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5178. 'mouse-face 'highlight
  5179. 'help-echo
  5180. (format "mouse-2 or RET jump to org file %s"
  5181. (abbreviate-file-name buffer-file-name))))
  5182. (regexp "^&?%%(")
  5183. marker category extra level ee txt tags entry
  5184. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5185. (goto-char (point-min))
  5186. (while (re-search-forward regexp nil t)
  5187. (catch :skip
  5188. (org-agenda-skip)
  5189. (setq beg (match-beginning 0))
  5190. (goto-char (1- (match-end 0)))
  5191. (setq b (point))
  5192. (forward-sexp 1)
  5193. (setq sexp (buffer-substring b (point)))
  5194. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5195. (org-trim (match-string 1))
  5196. ""))
  5197. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5198. (when result
  5199. (setq marker (org-agenda-new-marker beg)
  5200. level (make-string (org-reduced-level (org-outline-level)) ? )
  5201. category (org-get-category beg)
  5202. inherited-tags
  5203. (or (eq org-agenda-show-inherited-tags 'always)
  5204. (and (listp org-agenda-show-inherited-tags)
  5205. (memq 'agenda org-agenda-show-inherited-tags))
  5206. (and (eq org-agenda-show-inherited-tags t)
  5207. (or (eq org-agenda-use-tag-inheritance t)
  5208. (memq 'agenda org-agenda-use-tag-inheritance))))
  5209. tags (org-get-tags-at nil (not inherited-tags))
  5210. todo-state (org-get-todo-state)
  5211. warntime (get-text-property (point) 'org-appt-warntime)
  5212. extra nil)
  5213. (dolist (r (if (stringp result)
  5214. (list result)
  5215. result)) ;; we expect a list here
  5216. (when (and org-agenda-diary-sexp-prefix
  5217. (string-match org-agenda-diary-sexp-prefix r))
  5218. (setq extra (match-string 0 r)
  5219. r (replace-match "" nil nil r)))
  5220. (if (string-match "\\S-" r)
  5221. (setq txt r)
  5222. (setq txt "SEXP entry returned empty string"))
  5223. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5224. (org-add-props txt props 'org-marker marker
  5225. 'date date 'todo-state todo-state
  5226. 'level level 'type "sexp" 'warntime warntime)
  5227. (push txt ee)))))
  5228. (nreverse ee)))
  5229. ;; Calendar sanity: define some functions that are independent of
  5230. ;; `calendar-date-style'.
  5231. (defun org-anniversary (year month day &optional mark)
  5232. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5233. (with-no-warnings
  5234. (let ((calendar-date-style 'iso))
  5235. (diary-anniversary year month day mark))))
  5236. (defun org-cyclic (N year month day &optional mark)
  5237. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5238. (with-no-warnings
  5239. (let ((calendar-date-style 'iso))
  5240. (diary-cyclic N year month day mark))))
  5241. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5242. "Like `diary-block', but with fixed (ISO) order of arguments."
  5243. (with-no-warnings
  5244. (let ((calendar-date-style 'iso))
  5245. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5246. (defun org-date (year month day &optional mark)
  5247. "Like `diary-date', but with fixed (ISO) order of arguments."
  5248. (with-no-warnings
  5249. (let ((calendar-date-style 'iso))
  5250. (diary-date year month day mark))))
  5251. ;; Define the `org-class' function
  5252. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5253. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5254. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5255. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5256. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5257. `holidays', then any date that is known by the Emacs calendar to be a
  5258. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5259. then those holidays will be skipped."
  5260. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5261. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5262. (d (calendar-absolute-from-gregorian date))
  5263. (h (when skip-weeks (calendar-check-holidays date))))
  5264. (and
  5265. (<= date1 d)
  5266. (<= d date2)
  5267. (= (calendar-day-of-week date) dayname)
  5268. (or (not skip-weeks)
  5269. (progn
  5270. (require 'cal-iso)
  5271. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5272. (not (or (and h (memq 'holidays skip-weeks))
  5273. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5274. entry)))
  5275. (defalias 'org-get-closed 'org-agenda-get-progress)
  5276. (defun org-agenda-get-progress ()
  5277. "Return the logged TODO entries for agenda display."
  5278. (let* ((props (list 'mouse-face 'highlight
  5279. 'org-not-done-regexp org-not-done-regexp
  5280. 'org-todo-regexp org-todo-regexp
  5281. 'org-complex-heading-regexp org-complex-heading-regexp
  5282. 'help-echo
  5283. (format "mouse-2 or RET jump to org file %s"
  5284. (abbreviate-file-name buffer-file-name))))
  5285. (items (if (consp org-agenda-show-log-scoped)
  5286. org-agenda-show-log-scoped
  5287. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5288. '(clock)
  5289. org-agenda-log-mode-items)))
  5290. (parts
  5291. (delq nil
  5292. (list
  5293. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5294. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5295. (if (memq 'state items)
  5296. (format "- State \"%s\".*?" org-todo-regexp)))))
  5297. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5298. (error "`org-agenda-log-mode-items' is empty")))
  5299. (regexp (concat
  5300. "\\(" parts-re "\\)"
  5301. " *\\["
  5302. (regexp-quote
  5303. (substring
  5304. (format-time-string
  5305. (car org-time-stamp-formats)
  5306. (apply 'encode-time ; DATE bound by calendar
  5307. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5308. 1 11))))
  5309. (org-agenda-search-headline-for-time nil)
  5310. marker hdmarker priority category level tags closedp
  5311. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5312. (goto-char (point-min))
  5313. (while (re-search-forward regexp nil t)
  5314. (catch :skip
  5315. (org-agenda-skip)
  5316. (setq marker (org-agenda-new-marker (match-beginning 0))
  5317. closedp (equal (match-string 1) org-closed-string)
  5318. statep (equal (string-to-char (match-string 1)) ?-)
  5319. clockp (not (or closedp statep))
  5320. state (and statep (match-string 2))
  5321. category (org-get-category (match-beginning 0))
  5322. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5323. (when (string-match "\\]" timestr)
  5324. ;; substring should only run to end of time stamp
  5325. (setq rest (substring timestr (match-end 0))
  5326. timestr (substring timestr 0 (match-end 0)))
  5327. (if (and (not closedp) (not statep)
  5328. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5329. rest))
  5330. (progn (setq timestr (concat (substring timestr 0 -1)
  5331. "-" (match-string 1 rest) "]"))
  5332. (setq clocked (match-string 2 rest)))
  5333. (setq clocked "-")))
  5334. (save-excursion
  5335. (setq extra
  5336. (cond
  5337. ((not org-agenda-log-mode-add-notes) nil)
  5338. (statep
  5339. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5340. (match-string 1)))
  5341. (clockp
  5342. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5343. (match-string 1)))))
  5344. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5345. (throw :skip nil)
  5346. (goto-char (match-beginning 0))
  5347. (setq hdmarker (org-agenda-new-marker)
  5348. inherited-tags
  5349. (or (eq org-agenda-show-inherited-tags 'always)
  5350. (and (listp org-agenda-show-inherited-tags)
  5351. (memq 'todo org-agenda-show-inherited-tags))
  5352. (and (eq org-agenda-show-inherited-tags t)
  5353. (or (eq org-agenda-use-tag-inheritance t)
  5354. (memq 'todo org-agenda-use-tag-inheritance))))
  5355. tags (org-get-tags-at nil (not inherited-tags))
  5356. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5357. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5358. (setq txt (match-string 1))
  5359. (when extra
  5360. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5361. (setq txt (concat (substring txt 0 (match-beginning 1))
  5362. " - " extra " " (match-string 2 txt)))
  5363. (setq txt (concat txt " - " extra))))
  5364. (setq txt (org-agenda-format-item
  5365. (cond
  5366. (closedp "Closed: ")
  5367. (statep (concat "State: (" state ")"))
  5368. (t (concat "Clocked: (" clocked ")")))
  5369. txt level category tags timestr)))
  5370. (setq priority 100000)
  5371. (org-add-props txt props
  5372. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5373. 'priority priority 'level level
  5374. 'type "closed" 'date date
  5375. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5376. (push txt ee))
  5377. (goto-char (point-at-eol))))
  5378. (nreverse ee)))
  5379. (defun org-agenda-show-clocking-issues ()
  5380. "Add overlays, showing issues with clocking.
  5381. See also the user option `org-agenda-clock-consistency-checks'."
  5382. (interactive)
  5383. (let* ((pl org-agenda-clock-consistency-checks)
  5384. (re (concat "^[ \t]*"
  5385. org-clock-string
  5386. "[ \t]+"
  5387. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5388. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5389. (tlstart 0.)
  5390. (tlend 0.)
  5391. (maxtime (org-duration-to-minutes
  5392. (or (plist-get pl :max-duration) "24:00")))
  5393. (mintime (org-duration-to-minutes
  5394. (or (plist-get pl :min-duration) 0)))
  5395. (maxgap (org-duration-to-minutes
  5396. ;; default 30:00 means never complain
  5397. (or (plist-get pl :max-gap) "30:00")))
  5398. (gapok (mapcar #'org-duration-to-minutes
  5399. (plist-get pl :gap-ok-around)))
  5400. (def-face (or (plist-get pl :default-face)
  5401. '((:background "DarkRed") (:foreground "white"))))
  5402. issue face m te ts dt ov)
  5403. (goto-char (point-min))
  5404. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5405. (setq issue nil face def-face)
  5406. (catch 'next
  5407. (setq m (org-get-at-bol 'org-marker)
  5408. te nil ts nil)
  5409. (unless (and m (markerp m))
  5410. (setq issue "No valid clock line") (throw 'next t))
  5411. (org-with-point-at m
  5412. (save-excursion
  5413. (goto-char (point-at-bol))
  5414. (unless (looking-at re)
  5415. (error "No valid Clock line")
  5416. (throw 'next t))
  5417. (unless (match-end 3)
  5418. (setq issue "No end time"
  5419. face (or (plist-get pl :no-end-time-face) face))
  5420. (throw 'next t))
  5421. (setq ts (match-string 1)
  5422. te (match-string 3)
  5423. ts (float-time
  5424. (apply #'encode-time (org-parse-time-string ts)))
  5425. te (float-time
  5426. (apply #'encode-time (org-parse-time-string te)))
  5427. dt (- te ts))))
  5428. (cond
  5429. ((> dt (* 60 maxtime))
  5430. ;; a very long clocking chunk
  5431. (setq issue (format "Clocking interval is very long: %s"
  5432. (org-duration-from-minutes (floor (/ dt 60.))))
  5433. face (or (plist-get pl :long-face) face)))
  5434. ((< dt (* 60 mintime))
  5435. ;; a very short clocking chunk
  5436. (setq issue (format "Clocking interval is very short: %s"
  5437. (org-duration-from-minutes (floor (/ dt 60.))))
  5438. face (or (plist-get pl :short-face) face)))
  5439. ((and (> tlend 0) (< ts tlend))
  5440. ;; Two clock entries are overlapping
  5441. (setq issue (format "Clocking overlap: %d minutes"
  5442. (/ (- tlend ts) 60))
  5443. face (or (plist-get pl :overlap-face) face)))
  5444. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5445. ;; There is a gap, lets see if we need to report it
  5446. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5447. (setq issue (format "Clocking gap: %d minutes"
  5448. (/ (- ts tlend) 60))
  5449. face (or (plist-get pl :gap-face) face))))
  5450. (t nil)))
  5451. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5452. (when issue
  5453. ;; OK, there was some issue, add an overlay to show the issue
  5454. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5455. (overlay-put ov 'before-string
  5456. (concat
  5457. (org-add-props
  5458. (format "%-43s" (concat " " issue))
  5459. nil
  5460. 'face face)
  5461. "\n"))
  5462. (overlay-put ov 'evaporate t)))))
  5463. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5464. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5465. (catch 'exit
  5466. (unless ok-list
  5467. ;; there are no OK times for gaps...
  5468. (throw 'exit nil))
  5469. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5470. ;; This is more than 24 hours, so it is OK.
  5471. ;; because we have at least one OK time, that must be in the
  5472. ;; 24 hour interval.
  5473. (throw 'exit t))
  5474. ;; We have a shorter gap.
  5475. ;; Now we have to get the minute of the day when these times are
  5476. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5477. (t2dec (decode-time (seconds-to-time t2)))
  5478. ;; compute the minute on the day
  5479. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5480. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5481. (when (< min2 min1)
  5482. ;; if min2 is smaller than min1, this means it is on the next day.
  5483. ;; Wrap it to after midnight.
  5484. (setq min2 (+ min2 1440)))
  5485. ;; Now check if any of the OK times is in the gap
  5486. (mapc (lambda (x)
  5487. ;; Wrap the time to after midnight if necessary
  5488. (if (< x min1) (setq x (+ x 1440)))
  5489. ;; Check if in interval
  5490. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5491. ok-list)
  5492. ;; Nope, this gap is not OK
  5493. nil)))
  5494. (defun org-agenda-get-deadlines (&optional with-hour)
  5495. "Return the deadline information for agenda display.
  5496. When WITH-HOUR is non-nil, only return deadlines with an hour
  5497. specification like [h]h:mm."
  5498. (let* ((props (list 'mouse-face 'highlight
  5499. 'org-not-done-regexp org-not-done-regexp
  5500. 'org-todo-regexp org-todo-regexp
  5501. 'org-complex-heading-regexp org-complex-heading-regexp
  5502. 'help-echo
  5503. (format "mouse-2 or RET jump to org file %s"
  5504. (abbreviate-file-name buffer-file-name))))
  5505. (regexp (if with-hour
  5506. org-deadline-time-hour-regexp
  5507. org-deadline-time-regexp))
  5508. (today (org-today))
  5509. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5510. (current (calendar-absolute-from-gregorian date))
  5511. deadline-items)
  5512. (goto-char (point-min))
  5513. (while (re-search-forward regexp nil t)
  5514. (catch :skip
  5515. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5516. (org-agenda-skip)
  5517. (let* ((s (match-string 1))
  5518. (pos (1- (match-beginning 1)))
  5519. (todo-state (save-match-data (org-get-todo-state)))
  5520. (done? (member todo-state org-done-keywords))
  5521. (sexp? (string-prefix-p "%%" s))
  5522. ;; DEADLINE is the deadline date for the entry. It is
  5523. ;; either the base date or the last repeat, according
  5524. ;; to `org-agenda-prefer-last-repeat'.
  5525. (deadline
  5526. (cond
  5527. (sexp? (org-agenda--timestamp-to-absolute s current))
  5528. ((or (eq org-agenda-prefer-last-repeat t)
  5529. (member todo-state org-agenda-prefer-last-repeat))
  5530. (org-agenda--timestamp-to-absolute
  5531. s today 'past (current-buffer) pos))
  5532. (t (org-agenda--timestamp-to-absolute s))))
  5533. ;; REPEAT is the future repeat closest from CURRENT,
  5534. ;; according to `org-agenda-show-future-repeats'. If
  5535. ;; the latter is nil, or if the time stamp has no
  5536. ;; repeat part, default to DEADLINE.
  5537. (repeat
  5538. (cond
  5539. (sexp? deadline)
  5540. ((<= current today) deadline)
  5541. ((not org-agenda-show-future-repeats) deadline)
  5542. (t
  5543. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5544. (1+ today)
  5545. current)))
  5546. (org-agenda--timestamp-to-absolute
  5547. s base 'future (current-buffer) pos)))))
  5548. (diff (- deadline current))
  5549. (suppress-prewarning
  5550. (let ((scheduled
  5551. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5552. (org-entry-get nil "SCHEDULED"))))
  5553. (cond
  5554. ((not scheduled) nil)
  5555. ;; The current item has a scheduled date, so
  5556. ;; evaluate its prewarning lead time.
  5557. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5558. ;; Use global prewarning-restart lead time.
  5559. org-agenda-skip-deadline-prewarning-if-scheduled)
  5560. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5561. 'pre-scheduled)
  5562. ;; Set pre-warning to no earlier than SCHEDULED.
  5563. (min (- deadline
  5564. (org-agenda--timestamp-to-absolute scheduled))
  5565. org-deadline-warning-days))
  5566. ;; Set pre-warning to deadline.
  5567. (t 0))))
  5568. (wdays (if suppress-prewarning
  5569. (let ((org-deadline-warning-days suppress-prewarning))
  5570. (org-get-wdays s))
  5571. (org-get-wdays s))))
  5572. (cond
  5573. ;; Only display deadlines at their base date, at future
  5574. ;; repeat occurrences or in today agenda.
  5575. ((= current deadline) nil)
  5576. ((= current repeat) nil)
  5577. ((not today?) (throw :skip nil))
  5578. ;; Upcoming deadline: display within warning period WDAYS.
  5579. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5580. ;; Overdue deadline: warn about it for
  5581. ;; `org-deadline-past-days' duration.
  5582. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5583. ;; Possibly skip done tasks.
  5584. (when (and done?
  5585. (or org-agenda-skip-deadline-if-done
  5586. (/= deadline current)))
  5587. (throw :skip nil))
  5588. (save-excursion
  5589. (re-search-backward "^\\*+[ \t]+" nil t)
  5590. (goto-char (match-end 0))
  5591. (let* ((category (org-get-category))
  5592. (level (make-string (org-reduced-level (org-outline-level))
  5593. ?\s))
  5594. (head (buffer-substring (point) (line-end-position)))
  5595. (inherited-tags
  5596. (or (eq org-agenda-show-inherited-tags 'always)
  5597. (and (listp org-agenda-show-inherited-tags)
  5598. (memq 'agenda org-agenda-show-inherited-tags))
  5599. (and (eq org-agenda-show-inherited-tags t)
  5600. (or (eq org-agenda-use-tag-inheritance t)
  5601. (memq 'agenda
  5602. org-agenda-use-tag-inheritance)))))
  5603. (tags (org-get-tags-at nil (not inherited-tags)))
  5604. (time
  5605. (cond
  5606. ;; No time of day designation if it is only
  5607. ;; a reminder.
  5608. ((and (/= current deadline) (/= current repeat)) nil)
  5609. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5610. (concat (substring s (match-beginning 1)) " "))
  5611. (t 'time)))
  5612. (item
  5613. (org-agenda-format-item
  5614. ;; Insert appropriate suffixes before deadlines.
  5615. ;; Those only apply to today agenda.
  5616. (pcase-let ((`(,now ,future ,past)
  5617. org-agenda-deadline-leaders))
  5618. (cond
  5619. ((and today? (< deadline today)) (format past (- diff)))
  5620. ((and today? (> deadline today)) (format future diff))
  5621. (t now)))
  5622. head level category tags time))
  5623. (face (org-agenda-deadline-face
  5624. (- 1 (/ (float diff) (max wdays 1)))))
  5625. (upcoming? (and today? (> deadline today)))
  5626. (warntime (get-text-property (point) 'org-appt-warntime)))
  5627. (org-add-props item props
  5628. 'org-marker (org-agenda-new-marker pos)
  5629. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5630. 'warntime warntime
  5631. 'level level
  5632. 'ts-date deadline
  5633. 'priority
  5634. ;; Adjust priority to today reminders about deadlines.
  5635. ;; Overdue deadlines get the highest priority
  5636. ;; increase, then imminent deadlines and eventually
  5637. ;; more distant deadlines.
  5638. (let ((adjust (if today? (- diff) 0)))
  5639. (+ adjust (org-get-priority item)))
  5640. 'todo-state todo-state
  5641. 'type (if upcoming? "upcoming-deadline" "deadline")
  5642. 'date (if upcoming? date deadline)
  5643. 'face (if done? 'org-agenda-done face)
  5644. 'undone-face face
  5645. 'done-face 'org-agenda-done)
  5646. (push item deadline-items))))))
  5647. (nreverse deadline-items)))
  5648. (defun org-agenda-deadline-face (fraction)
  5649. "Return the face to displaying a deadline item.
  5650. FRACTION is what fraction of the head-warning time has passed."
  5651. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5652. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5653. "Return the scheduled information for agenda display.
  5654. Optional argument DEADLINES is a list of deadline items to be
  5655. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5656. scheduled items with an hour specification like [h]h:mm."
  5657. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5658. 'org-todo-regexp org-todo-regexp
  5659. 'org-complex-heading-regexp org-complex-heading-regexp
  5660. 'done-face 'org-agenda-done
  5661. 'mouse-face 'highlight
  5662. 'help-echo
  5663. (format "mouse-2 or RET jump to Org file %s"
  5664. (abbreviate-file-name buffer-file-name))))
  5665. (regexp (if with-hour
  5666. org-scheduled-time-hour-regexp
  5667. org-scheduled-time-regexp))
  5668. (today (org-today))
  5669. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5670. (current (calendar-absolute-from-gregorian date))
  5671. (deadline-pos
  5672. (mapcar (lambda (d)
  5673. (let ((m (get-text-property 0 'org-hd-marker d)))
  5674. (and m (marker-position m))))
  5675. deadlines))
  5676. scheduled-items)
  5677. (goto-char (point-min))
  5678. (while (re-search-forward regexp nil t)
  5679. (catch :skip
  5680. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5681. (org-agenda-skip)
  5682. (let* ((s (match-string 1))
  5683. (pos (1- (match-beginning 1)))
  5684. (todo-state (save-match-data (org-get-todo-state)))
  5685. (donep (member todo-state org-done-keywords))
  5686. (sexp? (string-prefix-p "%%" s))
  5687. ;; SCHEDULE is the scheduled date for the entry. It is
  5688. ;; either the bare date or the last repeat, according
  5689. ;; to `org-agenda-prefer-last-repeat'.
  5690. (schedule
  5691. (cond
  5692. (sexp? (org-agenda--timestamp-to-absolute s current))
  5693. ((or (eq org-agenda-prefer-last-repeat t)
  5694. (member todo-state org-agenda-prefer-last-repeat))
  5695. (org-agenda--timestamp-to-absolute
  5696. s today 'past (current-buffer) pos))
  5697. (t (org-agenda--timestamp-to-absolute s))))
  5698. ;; REPEAT is the future repeat closest from CURRENT,
  5699. ;; according to `org-agenda-show-future-repeats'. If
  5700. ;; the latter is nil, or if the time stamp has no
  5701. ;; repeat part, default to SCHEDULE.
  5702. (repeat
  5703. (cond
  5704. (sexp? schedule)
  5705. ((<= current today) schedule)
  5706. ((not org-agenda-show-future-repeats) schedule)
  5707. (t
  5708. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5709. (1+ today)
  5710. current)))
  5711. (org-agenda--timestamp-to-absolute
  5712. s base 'future (current-buffer) pos)))))
  5713. (diff (- current schedule))
  5714. (warntime (get-text-property (point) 'org-appt-warntime))
  5715. (pastschedp (< schedule today))
  5716. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5717. (suppress-delay
  5718. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5719. (org-entry-get nil "DEADLINE"))))
  5720. (cond
  5721. ((not deadline) nil)
  5722. ;; The current item has a deadline date, so
  5723. ;; evaluate its delay time.
  5724. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5725. ;; Use global delay time.
  5726. (- org-agenda-skip-scheduled-delay-if-deadline))
  5727. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5728. 'post-deadline)
  5729. ;; Set delay to no later than DEADLINE.
  5730. (min (- schedule
  5731. (org-agenda--timestamp-to-absolute deadline))
  5732. org-scheduled-delay-days))
  5733. (t 0))))
  5734. (ddays
  5735. (cond
  5736. ;; Nullify delay when a repeater triggered already
  5737. ;; and the delay is of the form --Xd.
  5738. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5739. (> current schedule))
  5740. 0)
  5741. (suppress-delay
  5742. (let ((org-scheduled-delay-days suppress-delay))
  5743. (org-get-wdays s t t)))
  5744. (t (org-get-wdays s t)))))
  5745. ;; Display scheduled items at base date (SCHEDULE), today if
  5746. ;; scheduled before the current date, and at any repeat past
  5747. ;; today. However, skip delayed items and items that have
  5748. ;; been displayed for more than `org-scheduled-past-days'.
  5749. (unless (and todayp
  5750. habitp
  5751. (bound-and-true-p org-habit-show-all-today))
  5752. (when (or (and (> ddays 0) (< diff ddays))
  5753. (> diff org-scheduled-past-days)
  5754. (> schedule current)
  5755. (and (/= current schedule)
  5756. (/= current today)
  5757. (/= current repeat)))
  5758. (throw :skip nil)))
  5759. ;; Possibly skip done tasks.
  5760. (when (and donep
  5761. (or org-agenda-skip-scheduled-if-done
  5762. (/= schedule current)))
  5763. (throw :skip nil))
  5764. ;; Skip entry if it already appears as a deadline, per
  5765. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5766. ;; doesn't apply to habits.
  5767. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5768. ((guard
  5769. (or (not (memq (line-beginning-position 0) deadline-pos))
  5770. habitp))
  5771. nil)
  5772. (`repeated-after-deadline
  5773. (let ((deadline (time-to-days
  5774. (org-get-deadline-time (point)))))
  5775. (and (<= schedule deadline) (> current deadline))))
  5776. (`not-today pastschedp)
  5777. (`t t)
  5778. (_ nil))
  5779. (throw :skip nil))
  5780. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5781. ;; only show them for today. Also skip done habits.
  5782. (when (and habitp
  5783. (or donep
  5784. (not (bound-and-true-p org-habit-show-habits))
  5785. (and (not todayp)
  5786. (bound-and-true-p
  5787. org-habit-show-habits-only-for-today))))
  5788. (throw :skip nil))
  5789. (save-excursion
  5790. (re-search-backward "^\\*+[ \t]+" nil t)
  5791. (goto-char (match-end 0))
  5792. (let* ((category (org-get-category))
  5793. (inherited-tags
  5794. (or (eq org-agenda-show-inherited-tags 'always)
  5795. (and (listp org-agenda-show-inherited-tags)
  5796. (memq 'agenda org-agenda-show-inherited-tags))
  5797. (and (eq org-agenda-show-inherited-tags t)
  5798. (or (eq org-agenda-use-tag-inheritance t)
  5799. (memq 'agenda
  5800. org-agenda-use-tag-inheritance)))))
  5801. (tags (org-get-tags-at nil (not inherited-tags)))
  5802. (level (make-string (org-reduced-level (org-outline-level))
  5803. ?\s))
  5804. (head (buffer-substring (point) (line-end-position)))
  5805. (time
  5806. (cond
  5807. ;; No time of day designation if it is only
  5808. ;; a reminder.
  5809. ((and (/= current schedule) (/= current repeat)) nil)
  5810. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5811. (concat (substring s (match-beginning 1)) " "))
  5812. (t 'time)))
  5813. (item
  5814. (org-agenda-format-item
  5815. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5816. ;; Show a reminder of a past scheduled today.
  5817. (if (and todayp pastschedp)
  5818. (format past diff)
  5819. first))
  5820. head level category tags time nil habitp))
  5821. (face (cond ((and (not habitp) pastschedp)
  5822. 'org-scheduled-previously)
  5823. (todayp 'org-scheduled-today)
  5824. (t 'org-scheduled)))
  5825. (habitp (and habitp (org-habit-parse-todo))))
  5826. (org-add-props item props
  5827. 'undone-face face
  5828. 'face (if donep 'org-agenda-done face)
  5829. 'org-marker (org-agenda-new-marker pos)
  5830. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5831. 'type (if pastschedp "past-scheduled" "scheduled")
  5832. 'date (if pastschedp schedule date)
  5833. 'ts-date schedule
  5834. 'warntime warntime
  5835. 'level level
  5836. 'priority (if habitp (org-habit-get-priority habitp)
  5837. (+ 99 diff (org-get-priority item)))
  5838. 'org-habit-p habitp
  5839. 'todo-state todo-state)
  5840. (push item scheduled-items))))))
  5841. (nreverse scheduled-items)))
  5842. (defun org-agenda-get-blocks ()
  5843. "Return the date-range information for agenda display."
  5844. (let* ((props (list 'face nil
  5845. 'org-not-done-regexp org-not-done-regexp
  5846. 'org-todo-regexp org-todo-regexp
  5847. 'org-complex-heading-regexp org-complex-heading-regexp
  5848. 'mouse-face 'highlight
  5849. 'help-echo
  5850. (format "mouse-2 or RET jump to org file %s"
  5851. (abbreviate-file-name buffer-file-name))))
  5852. (regexp org-tr-regexp)
  5853. (d0 (calendar-absolute-from-gregorian date))
  5854. marker hdmarker ee txt d1 d2 s1 s2 category
  5855. level todo-state tags pos head donep inherited-tags)
  5856. (goto-char (point-min))
  5857. (while (re-search-forward regexp nil t)
  5858. (catch :skip
  5859. (org-agenda-skip)
  5860. (setq pos (point))
  5861. (let ((start-time (match-string 1))
  5862. (end-time (match-string 2)))
  5863. (setq s1 (match-string 1)
  5864. s2 (match-string 2)
  5865. d1 (time-to-days
  5866. (condition-case err
  5867. (org-time-string-to-time s1)
  5868. (error
  5869. (error
  5870. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5871. s1
  5872. pos
  5873. (current-buffer)
  5874. (error-message-string err)))))
  5875. d2 (time-to-days
  5876. (condition-case err
  5877. (org-time-string-to-time s2)
  5878. (error
  5879. (error
  5880. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5881. s2
  5882. pos
  5883. (current-buffer)
  5884. (error-message-string err))))))
  5885. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5886. ;; Only allow days between the limits, because the normal
  5887. ;; date stamps will catch the limits.
  5888. (save-excursion
  5889. (setq todo-state (org-get-todo-state))
  5890. (setq donep (member todo-state org-done-keywords))
  5891. (if (and donep org-agenda-skip-timestamp-if-done)
  5892. (throw :skip t))
  5893. (setq marker (org-agenda-new-marker (point))
  5894. category (org-get-category))
  5895. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5896. (throw :skip nil)
  5897. (goto-char (match-beginning 0))
  5898. (setq hdmarker (org-agenda-new-marker (point))
  5899. inherited-tags
  5900. (or (eq org-agenda-show-inherited-tags 'always)
  5901. (and (listp org-agenda-show-inherited-tags)
  5902. (memq 'agenda org-agenda-show-inherited-tags))
  5903. (and (eq org-agenda-show-inherited-tags t)
  5904. (or (eq org-agenda-use-tag-inheritance t)
  5905. (memq 'agenda org-agenda-use-tag-inheritance))))
  5906. tags (org-get-tags-at nil (not inherited-tags)))
  5907. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5908. (looking-at "\\*+[ \t]+\\(.*\\)")
  5909. (setq head (match-string 1))
  5910. (let ((remove-re
  5911. (if org-agenda-remove-timeranges-from-blocks
  5912. (concat
  5913. "<" (regexp-quote s1) ".*?>"
  5914. "--"
  5915. "<" (regexp-quote s2) ".*?>")
  5916. nil)))
  5917. (setq txt (org-agenda-format-item
  5918. (format
  5919. (nth (if (= d1 d2) 0 1)
  5920. org-agenda-timerange-leaders)
  5921. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5922. head level category tags
  5923. (cond ((and (= d1 d0) (= d2 d0))
  5924. (concat "<" start-time ">--<" end-time ">"))
  5925. ((= d1 d0)
  5926. (concat "<" start-time ">"))
  5927. ((= d2 d0)
  5928. (concat "<" end-time ">")))
  5929. remove-re))))
  5930. (org-add-props txt props
  5931. 'org-marker marker 'org-hd-marker hdmarker
  5932. 'type "block" 'date date
  5933. 'level level
  5934. 'todo-state todo-state
  5935. 'priority (org-get-priority txt))
  5936. (push txt ee))))
  5937. (goto-char pos)))
  5938. ;; Sort the entries by expiration date.
  5939. (nreverse ee)))
  5940. ;;; Agenda presentation and sorting
  5941. (defvar org-prefix-has-time nil
  5942. "A flag, set by `org-compile-prefix-format'.
  5943. The flag is set if the currently compiled format contains a `%t'.")
  5944. (defvar org-prefix-has-tag nil
  5945. "A flag, set by `org-compile-prefix-format'.
  5946. The flag is set if the currently compiled format contains a `%T'.")
  5947. (defvar org-prefix-has-effort nil
  5948. "A flag, set by `org-compile-prefix-format'.
  5949. The flag is set if the currently compiled format contains a `%e'.")
  5950. (defvar org-prefix-has-breadcrumbs nil
  5951. "A flag, set by `org-compile-prefix-format'.
  5952. The flag is set if the currently compiled format contains a `%b'.")
  5953. (defvar org-prefix-category-length nil
  5954. "Used by `org-compile-prefix-format' to remember the category field width.")
  5955. (defvar org-prefix-category-max-length nil
  5956. "Used by `org-compile-prefix-format' to remember the category field width.")
  5957. (defun org-agenda-get-category-icon (category)
  5958. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5959. (cl-dolist (entry org-agenda-category-icon-alist)
  5960. (when (string-match-p (car entry) category)
  5961. (if (listp (cadr entry))
  5962. (cl-return (cadr entry))
  5963. (cl-return (apply #'create-image (cdr entry)))))))
  5964. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5965. remove-re habitp)
  5966. "Format TXT to be inserted into the agenda buffer.
  5967. In particular, add the prefix and corresponding text properties.
  5968. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5969. LEVEL may be a string to replace the `%l' specifier.
  5970. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5971. category taken from local variable or file name. It will replace the `%c'
  5972. specifier in the format.
  5973. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5974. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5975. When DOTIME is a string, this string is searched for a time before TXT is.
  5976. TAGS can be the tags of the headline.
  5977. Any match of REMOVE-RE will be removed from TXT."
  5978. ;; We keep the org-prefix-* variable values along with a compiled
  5979. ;; formatter, so that multiple agendas existing at the same time do
  5980. ;; not step on each other toes.
  5981. ;;
  5982. ;; It was inconvenient to make these variables buffer local in
  5983. ;; Agenda buffers, because this function expects to be called with
  5984. ;; the buffer where item comes from being current, and not agenda
  5985. ;; buffer
  5986. (let* ((bindings (car org-prefix-format-compiled))
  5987. (formatter (cadr org-prefix-format-compiled)))
  5988. (cl-loop for (var value) in bindings
  5989. do (set var value))
  5990. (save-match-data
  5991. ;; Diary entries sometimes have extra whitespace at the beginning
  5992. (setq txt (org-trim txt))
  5993. ;; Fix the tags part in txt
  5994. (setq txt (org-agenda-fix-displayed-tags
  5995. txt tags
  5996. org-agenda-show-inherited-tags
  5997. org-agenda-hide-tags-regexp))
  5998. (let* ((category (or category
  5999. (if buffer-file-name
  6000. (file-name-sans-extension
  6001. (file-name-nondirectory buffer-file-name))
  6002. "")))
  6003. (category-icon (org-agenda-get-category-icon category))
  6004. (category-icon (if category-icon
  6005. (propertize " " 'display category-icon)
  6006. ""))
  6007. (effort (and (not (string= txt ""))
  6008. (get-text-property 1 'effort txt)))
  6009. ;; time, tag, effort are needed for the eval of the prefix format
  6010. (tag (if tags (nth (1- (length tags)) tags) ""))
  6011. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6012. time
  6013. (ts (if dotime (concat
  6014. (if (stringp dotime) dotime "")
  6015. (and org-agenda-search-headline-for-time txt))))
  6016. (time-of-day (and dotime (org-get-time-of-day ts)))
  6017. stamp plain s0 s1 s2 rtn srp l
  6018. duration breadcrumbs)
  6019. (and (derived-mode-p 'org-mode) buffer-file-name
  6020. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6021. (when (and dotime time-of-day)
  6022. ;; Extract starting and ending time and move them to prefix
  6023. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6024. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6025. (setq s0 (match-string 0 ts)
  6026. srp (and stamp (match-end 3))
  6027. s1 (match-string (if plain 1 2) ts)
  6028. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6029. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6030. ;; them, we might want to remove them there to avoid duplication.
  6031. ;; The user can turn this off with a variable.
  6032. (if (and org-prefix-has-time
  6033. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6034. (string-match (concat (regexp-quote s0) " *") txt)
  6035. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6036. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6037. (= (match-beginning 0) 0)
  6038. t))
  6039. (setq txt (replace-match "" nil nil txt))))
  6040. ;; Normalize the time(s) to 24 hour
  6041. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6042. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6043. ;; Try to set s2 if s1 and
  6044. ;; `org-agenda-default-appointment-duration' are set
  6045. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6046. (setq s2
  6047. (org-duration-from-minutes
  6048. (+ (org-duration-to-minutes s1 t)
  6049. org-agenda-default-appointment-duration)
  6050. nil t)))
  6051. ;; Compute the duration
  6052. (when s2
  6053. (setq duration (- (org-duration-to-minutes s2)
  6054. (org-duration-to-minutes s1)))))
  6055. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6056. ;; Tags are in the string
  6057. (if (or (eq org-agenda-remove-tags t)
  6058. (and org-agenda-remove-tags
  6059. org-prefix-has-tag))
  6060. (setq txt (replace-match "" t t txt))
  6061. (setq txt (replace-match
  6062. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6063. (match-string 2 txt))
  6064. t t txt))))
  6065. (when remove-re
  6066. (while (string-match remove-re txt)
  6067. (setq txt (replace-match "" t t txt))))
  6068. ;; Set org-heading property on `txt' to mark the start of the
  6069. ;; heading.
  6070. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6071. ;; Prepare the variables needed in the eval of the compiled format
  6072. (if org-prefix-has-breadcrumbs
  6073. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6074. (let ((s (org-display-outline-path nil nil "->" t)))
  6075. (if (eq "" s) "" (concat s "->"))))))
  6076. (setq time (cond (s2 (concat
  6077. (org-agenda-time-of-day-to-ampm-maybe s1)
  6078. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6079. (if org-agenda-timegrid-use-ampm " ")))
  6080. (s1 (concat
  6081. (org-agenda-time-of-day-to-ampm-maybe s1)
  6082. (if org-agenda-timegrid-use-ampm
  6083. (concat time-grid-trailing-characters " ")
  6084. time-grid-trailing-characters)))
  6085. (t ""))
  6086. extra (or (and (not habitp) extra) "")
  6087. category (if (symbolp category) (symbol-name category) category)
  6088. level (or level ""))
  6089. (if (string-match org-bracket-link-regexp category)
  6090. (progn
  6091. (setq l (if (match-end 3)
  6092. (- (match-end 3) (match-beginning 3))
  6093. (- (match-end 1) (match-beginning 1))))
  6094. (when (< l (or org-prefix-category-length 0))
  6095. (setq category (copy-sequence category))
  6096. (org-add-props category nil
  6097. 'extra-space (make-string
  6098. (- org-prefix-category-length l 1) ?\ ))))
  6099. (if (and org-prefix-category-max-length
  6100. (>= (length category) org-prefix-category-max-length))
  6101. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6102. ;; Evaluate the compiled format
  6103. (setq rtn (concat (eval formatter) txt))
  6104. ;; And finally add the text properties
  6105. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6106. (org-add-props rtn nil
  6107. 'org-category category
  6108. 'tags (mapcar 'org-downcase-keep-props tags)
  6109. 'org-highest-priority org-highest-priority
  6110. 'org-lowest-priority org-lowest-priority
  6111. 'time-of-day time-of-day
  6112. 'duration duration
  6113. 'breadcrumbs breadcrumbs
  6114. 'txt txt
  6115. 'level level
  6116. 'time time
  6117. 'extra extra
  6118. 'format org-prefix-format-compiled
  6119. 'dotime dotime)))))
  6120. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6121. "Remove tags string from TXT, and add a modified list of tags.
  6122. The modified list may contain inherited tags, and tags matched by
  6123. `org-agenda-hide-tags-regexp' will be removed."
  6124. (when (or add-inherited hide-re)
  6125. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6126. (setq txt (substring txt 0 (match-beginning 0))))
  6127. (setq tags
  6128. (delq nil
  6129. (mapcar (lambda (tg)
  6130. (if (or (and hide-re (string-match hide-re tg))
  6131. (and (not add-inherited)
  6132. (get-text-property 0 'inherited tg)))
  6133. nil
  6134. tg))
  6135. tags)))
  6136. (when tags
  6137. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6138. i)
  6139. (setq txt (concat txt " :"
  6140. (mapconcat
  6141. (lambda (x)
  6142. (setq i (get-text-property 0 'inherited x))
  6143. (if (and have-i (not i))
  6144. (progn
  6145. (setq have-i nil)
  6146. (concat ":" x))
  6147. x))
  6148. tags ":")
  6149. (if have-i "::" ":"))))))
  6150. txt)
  6151. (defun org-downcase-keep-props (s)
  6152. (let ((props (text-properties-at 0 s)))
  6153. (setq s (downcase s))
  6154. (add-text-properties 0 (length s) props s)
  6155. s))
  6156. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6157. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6158. "Add a time-grid for agenda items which need it.
  6159. LIST is the list of agenda items formatted by `org-agenda-list'.
  6160. NDAYS is the span of the current agenda view.
  6161. TODAYP is t when the current agenda view is on today."
  6162. (catch 'exit
  6163. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6164. ((and todayp (member 'today (car org-agenda-time-grid))))
  6165. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6166. ((member 'weekly (car org-agenda-time-grid)))
  6167. (t (throw 'exit list)))
  6168. (let* ((have (delq nil (mapcar
  6169. (lambda (x) (get-text-property 1 'time-of-day x))
  6170. list)))
  6171. (string (nth 3 org-agenda-time-grid))
  6172. (gridtimes (nth 1 org-agenda-time-grid))
  6173. (req (car org-agenda-time-grid))
  6174. (remove (member 'remove-match req))
  6175. new time)
  6176. (if (and (member 'require-timed req) (not have))
  6177. ;; don't show empty grid
  6178. (throw 'exit list))
  6179. (while (setq time (pop gridtimes))
  6180. (unless (and remove (member time have))
  6181. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6182. (push (org-agenda-format-item
  6183. nil string nil "" nil
  6184. (concat (substring time 0 -2) ":" (substring time -2)))
  6185. new)
  6186. (put-text-property
  6187. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6188. (when (and todayp org-agenda-show-current-time-in-grid)
  6189. (push (org-agenda-format-item
  6190. nil org-agenda-current-time-string nil "" nil
  6191. (format-time-string "%H:%M "))
  6192. new)
  6193. (put-text-property
  6194. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6195. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6196. (append new list)
  6197. (append list new)))))
  6198. (defun org-compile-prefix-format (key)
  6199. "Compile the prefix format into a Lisp form that can be evaluated.
  6200. The resulting form and associated variable bindings is returned
  6201. and stored in the variable `org-prefix-format-compiled'."
  6202. (setq org-prefix-has-time nil
  6203. org-prefix-has-tag nil
  6204. org-prefix-category-length nil
  6205. org-prefix-has-effort nil
  6206. org-prefix-has-breadcrumbs nil)
  6207. (let ((s (cond
  6208. ((stringp org-agenda-prefix-format)
  6209. org-agenda-prefix-format)
  6210. ((assq key org-agenda-prefix-format)
  6211. (cdr (assq key org-agenda-prefix-format)))
  6212. (t " %-12:c%?-12t% s")))
  6213. (start 0)
  6214. varform vars var e c f opt)
  6215. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6216. s start)
  6217. (setq var (or (cdr (assoc (match-string 4 s)
  6218. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6219. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6220. 'eval)
  6221. c (or (match-string 3 s) "")
  6222. opt (match-beginning 1)
  6223. start (1+ (match-beginning 0)))
  6224. (if (eq var 'time) (setq org-prefix-has-time t))
  6225. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6226. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6227. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6228. (setq f (concat "%" (match-string 2 s) "s"))
  6229. (when (eq var 'category)
  6230. (setq org-prefix-category-length
  6231. (floor (abs (string-to-number (match-string 2 s)))))
  6232. (setq org-prefix-category-max-length
  6233. (let ((x (match-string 2 s)))
  6234. (save-match-data
  6235. (if (string-match "\\.[0-9]+" x)
  6236. (string-to-number (substring (match-string 0 x) 1)))))))
  6237. (if (eq var 'eval)
  6238. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6239. (if opt
  6240. (setq varform
  6241. `(if (or (equal "" ,var) (equal nil ,var))
  6242. ""
  6243. (format ,f (concat ,var ,c))))
  6244. (setq varform
  6245. `(format ,f (if (or (equal ,var "")
  6246. (equal ,var nil)) ""
  6247. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6248. (setq s (replace-match "%s" t nil s))
  6249. (push varform vars))
  6250. (setq vars (nreverse vars))
  6251. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6252. (setq org-prefix-format-compiled
  6253. (list
  6254. `((org-prefix-has-time ,org-prefix-has-time)
  6255. (org-prefix-has-tag ,org-prefix-has-tag)
  6256. (org-prefix-category-length ,org-prefix-category-length)
  6257. (org-prefix-has-effort ,org-prefix-has-effort)
  6258. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6259. `(format ,s ,@vars))))))
  6260. (defun org-set-sorting-strategy (key)
  6261. (if (symbolp (car org-agenda-sorting-strategy))
  6262. ;; the old format
  6263. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6264. (setq org-agenda-sorting-strategy-selected
  6265. (or (cdr (assq key org-agenda-sorting-strategy))
  6266. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6267. '(time-up category-keep priority-down)))))
  6268. (defun org-get-time-of-day (s &optional string mod24)
  6269. "Check string S for a time of day.
  6270. If found, return it as a military time number between 0 and 2400.
  6271. If not found, return nil.
  6272. The optional STRING argument forces conversion into a 5 character wide string
  6273. HH:MM."
  6274. (save-match-data
  6275. (when
  6276. (and
  6277. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6278. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6279. (not (eq (get-text-property 1 'face s) 'org-link)))
  6280. (let* ((h (string-to-number (match-string 1 s)))
  6281. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6282. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6283. (am-p (equal ampm "am"))
  6284. (h1 (cond ((not ampm) h)
  6285. ((= h 12) (if am-p 0 12))
  6286. (t (+ h (if am-p 0 12)))))
  6287. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6288. (mod h1 24) h1))
  6289. (t0 (+ (* 100 h2) m))
  6290. (t1 (concat (if (>= h1 24) "+" " ")
  6291. (if (and org-agenda-time-leading-zero
  6292. (< t0 1000)) "0" "")
  6293. (if (< t0 100) "0" "")
  6294. (if (< t0 10) "0" "")
  6295. (int-to-string t0))))
  6296. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6297. (defvar org-agenda-before-sorting-filter-function nil
  6298. "Function to be applied to agenda items prior to sorting.
  6299. Prior to sorting also means just before they are inserted into the agenda.
  6300. To aid sorting, you may revisit the original entries and add more text
  6301. properties which will later be used by the sorting functions.
  6302. The function should take a string argument, an agenda line.
  6303. It has access to the text properties in that line, which contain among
  6304. other things, the property `org-hd-marker' that points to the entry
  6305. where the line comes from. Note that not all lines going into the agenda
  6306. have this property, only most.
  6307. The function should return the modified string. It is probably best
  6308. to ONLY change text properties.
  6309. You can also use this function as a filter, by returning nil for lines
  6310. you don't want to have in the agenda at all. For this application, you
  6311. could bind the variable in the options section of a custom command.")
  6312. (defun org-agenda-finalize-entries (list &optional type)
  6313. "Sort, limit and concatenate the LIST of agenda items.
  6314. The optional argument TYPE tells the agenda type."
  6315. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6316. (cdr (assoc type org-agenda-max-effort)))
  6317. (t org-agenda-max-effort)))
  6318. (max-todo (cond ((listp org-agenda-max-todos)
  6319. (cdr (assoc type org-agenda-max-todos)))
  6320. (t org-agenda-max-todos)))
  6321. (max-tags (cond ((listp org-agenda-max-tags)
  6322. (cdr (assoc type org-agenda-max-tags)))
  6323. (t org-agenda-max-tags)))
  6324. (max-entries (cond ((listp org-agenda-max-entries)
  6325. (cdr (assoc type org-agenda-max-entries)))
  6326. (t org-agenda-max-entries))))
  6327. (when org-agenda-before-sorting-filter-function
  6328. (setq list
  6329. (delq nil
  6330. (mapcar
  6331. org-agenda-before-sorting-filter-function list))))
  6332. (setq list (mapcar 'org-agenda-highlight-todo list)
  6333. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6334. (when max-effort
  6335. (setq list (org-agenda-limit-entries
  6336. list 'effort-minutes max-effort
  6337. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6338. 32767 -1))))))
  6339. (when max-todo
  6340. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6341. (when max-tags
  6342. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6343. (when max-entries
  6344. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6345. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6346. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6347. (mapconcat 'identity list "\n")))
  6348. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6349. "Limit the number of agenda entries."
  6350. (let ((include (and limit (< limit 0))))
  6351. (if limit
  6352. (let ((fun (or fn (lambda (p) (if p 1))))
  6353. (lim 0))
  6354. (delq nil
  6355. (mapcar
  6356. (lambda (e)
  6357. (let ((pval (funcall
  6358. fun (get-text-property (1- (length e))
  6359. prop e))))
  6360. (if pval (setq lim (+ lim pval)))
  6361. (cond ((and pval (<= lim (abs limit))) e)
  6362. ((and include (not pval)) e))))
  6363. list)))
  6364. list)))
  6365. (defun org-agenda-limit-interactively (remove)
  6366. "In agenda, interactively limit entries to various maximums."
  6367. (interactive "P")
  6368. (if remove
  6369. (progn (setq org-agenda-max-entries nil
  6370. org-agenda-max-todos nil
  6371. org-agenda-max-tags nil
  6372. org-agenda-max-effort nil)
  6373. (org-agenda-redo))
  6374. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6375. (msg (cond ((= max ?E) "How many minutes? ")
  6376. ((= max ?e) "How many entries? ")
  6377. ((= max ?t) "How many TODO entries? ")
  6378. ((= max ?T) "How many tagged entries? ")
  6379. (t (user-error "Wrong input"))))
  6380. (num (string-to-number (read-from-minibuffer msg))))
  6381. (cond ((equal max ?e)
  6382. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6383. ((equal max ?t)
  6384. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6385. ((equal max ?T)
  6386. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6387. ((equal max ?E)
  6388. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6389. (org-agenda-fit-window-to-buffer))
  6390. (defun org-agenda-highlight-todo (x)
  6391. (let ((org-done-keywords org-done-keywords-for-agenda)
  6392. (case-fold-search nil)
  6393. re)
  6394. (if (eq x 'line)
  6395. (save-excursion
  6396. (beginning-of-line 1)
  6397. (setq re (org-get-at-bol 'org-todo-regexp))
  6398. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6399. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6400. (add-text-properties (match-beginning 0) (match-end 1)
  6401. (list 'face (org-get-todo-face 1)))
  6402. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6403. (delete-region (match-beginning 1) (1- (match-end 0)))
  6404. (goto-char (match-beginning 1))
  6405. (insert (format org-agenda-todo-keyword-format s)))))
  6406. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6407. (setq re (get-text-property 0 'org-todo-regexp x))
  6408. (when (and re
  6409. ;; Test `pl' because if there's no heading content,
  6410. ;; there's no point matching to highlight. Note
  6411. ;; that if we didn't test `pl' first, and there
  6412. ;; happened to be no keyword from `org-todo-regexp'
  6413. ;; on this heading line, then the `equal' comparison
  6414. ;; afterwards would spuriously succeed in the case
  6415. ;; where `pl' is nil -- causing an args-out-of-range
  6416. ;; error when we try to add text properties to text
  6417. ;; that isn't there.
  6418. pl
  6419. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6420. x pl) pl))
  6421. (add-text-properties
  6422. (or (match-end 1) (match-end 0)) (match-end 0)
  6423. (list 'face (org-get-todo-face (match-string 2 x)))
  6424. x)
  6425. (when (match-end 1)
  6426. (setq x
  6427. (concat
  6428. (substring x 0 (match-end 1))
  6429. (format org-agenda-todo-keyword-format
  6430. (match-string 2 x))
  6431. ;; Remove `display' property as the icon could leak
  6432. ;; on the white space.
  6433. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6434. 'display))
  6435. (substring x (match-end 3)))))))
  6436. x)))
  6437. (defsubst org-cmp-values (a b property)
  6438. "Compare the numeric value of text PROPERTY for string A and B."
  6439. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6440. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6441. (cond ((> pa pb) +1)
  6442. ((< pa pb) -1))))
  6443. (defsubst org-cmp-effort (a b)
  6444. "Compare the effort values of string A and B."
  6445. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6446. ;; `effort-minutes' property is not directly accessible from
  6447. ;; the strings, but is stored as a property in `txt'.
  6448. (ea (or (get-text-property
  6449. 0 'effort-minutes (get-text-property 0 'txt a))
  6450. def))
  6451. (eb (or (get-text-property
  6452. 0 'effort-minutes (get-text-property 0 'txt b))
  6453. def)))
  6454. (cond ((> ea eb) +1)
  6455. ((< ea eb) -1))))
  6456. (defsubst org-cmp-category (a b)
  6457. "Compare the string values of categories of strings A and B."
  6458. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6459. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6460. (cond ((string-lessp ca cb) -1)
  6461. ((string-lessp cb ca) +1))))
  6462. (defsubst org-cmp-todo-state (a b)
  6463. "Compare the todo states of strings A and B."
  6464. (let* ((ma (or (get-text-property 1 'org-marker a)
  6465. (get-text-property 1 'org-hd-marker a)))
  6466. (mb (or (get-text-property 1 'org-marker b)
  6467. (get-text-property 1 'org-hd-marker b)))
  6468. (fa (and ma (marker-buffer ma)))
  6469. (fb (and mb (marker-buffer mb)))
  6470. (todo-kwds
  6471. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6472. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6473. (ta (or (get-text-property 1 'todo-state a) ""))
  6474. (tb (or (get-text-property 1 'todo-state b) ""))
  6475. (la (- (length (member ta todo-kwds))))
  6476. (lb (- (length (member tb todo-kwds))))
  6477. (donepa (member ta org-done-keywords-for-agenda))
  6478. (donepb (member tb org-done-keywords-for-agenda)))
  6479. (cond ((and donepa (not donepb)) -1)
  6480. ((and (not donepa) donepb) +1)
  6481. ((< la lb) -1)
  6482. ((< lb la) +1))))
  6483. (defsubst org-cmp-alpha (a b)
  6484. "Compare the headlines, alphabetically."
  6485. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6486. (plb (text-property-any 0 (length b) 'org-heading t b))
  6487. (ta (and pla (substring a pla)))
  6488. (tb (and plb (substring b plb)))
  6489. (case-fold-search nil))
  6490. (when pla
  6491. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6492. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6493. (setq ta (substring ta (match-end 0))))
  6494. (setq ta (downcase ta)))
  6495. (when plb
  6496. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6497. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6498. (setq tb (substring tb (match-end 0))))
  6499. (setq tb (downcase tb)))
  6500. (cond ((not ta) +1)
  6501. ((not tb) -1)
  6502. ((string-lessp ta tb) -1)
  6503. ((string-lessp tb ta) +1))))
  6504. (defsubst org-cmp-tag (a b)
  6505. "Compare the string values of the first tags of A and B."
  6506. (let ((ta (car (last (get-text-property 1 'tags a))))
  6507. (tb (car (last (get-text-property 1 'tags b)))))
  6508. (cond ((not ta) +1)
  6509. ((not tb) -1)
  6510. ((string-lessp ta tb) -1)
  6511. ((string-lessp tb ta) +1))))
  6512. (defsubst org-cmp-time (a b)
  6513. "Compare the time-of-day values of strings A and B."
  6514. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6515. (ta (or (get-text-property 1 'time-of-day a) def))
  6516. (tb (or (get-text-property 1 'time-of-day b) def)))
  6517. (cond ((< ta tb) -1)
  6518. ((< tb ta) +1))))
  6519. (defsubst org-cmp-ts (a b type)
  6520. "Compare the timestamps values of entries A and B.
  6521. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6522. \"timestamp_ia\", compare within each of these type. When TYPE
  6523. is the empty string, compare all timestamps without respect of
  6524. their type."
  6525. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6526. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6527. (get-text-property 1 'ts-date a))
  6528. def))
  6529. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6530. (get-text-property 1 'ts-date b))
  6531. def)))
  6532. (cond ((< ta tb) -1)
  6533. ((< tb ta) +1))))
  6534. (defsubst org-cmp-habit-p (a b)
  6535. "Compare the todo states of strings A and B."
  6536. (let ((ha (get-text-property 1 'org-habit-p a))
  6537. (hb (get-text-property 1 'org-habit-p b)))
  6538. (cond ((and ha (not hb)) -1)
  6539. ((and (not ha) hb) +1))))
  6540. (defun org-entries-lessp (a b)
  6541. "Predicate for sorting agenda entries."
  6542. ;; The following variables will be used when the form is evaluated.
  6543. ;; So even though the compiler complains, keep them.
  6544. (let* ((ss org-agenda-sorting-strategy-selected)
  6545. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6546. (org-cmp-ts a b "")))
  6547. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6548. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6549. (org-cmp-ts a b "scheduled")))
  6550. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6551. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6552. (org-cmp-ts a b "deadline")))
  6553. (deadline-down (if deadline-up (- deadline-up) nil))
  6554. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6555. (org-cmp-ts a b "timestamp_ia")))
  6556. (tsia-down (if tsia-up (- tsia-up) nil))
  6557. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6558. (org-cmp-ts a b "timestamp")))
  6559. (ts-down (if ts-up (- ts-up) nil))
  6560. (time-up (and (org-em 'time-up 'time-down ss)
  6561. (org-cmp-time a b)))
  6562. (time-down (if time-up (- time-up) nil))
  6563. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6564. (org-cmp-values a b 'org-stats)))
  6565. (stats-down (if stats-up (- stats-up) nil))
  6566. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6567. (org-cmp-values a b 'priority)))
  6568. (priority-down (if priority-up (- priority-up) nil))
  6569. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6570. (org-cmp-effort a b)))
  6571. (effort-down (if effort-up (- effort-up) nil))
  6572. (category-up (and (or (org-em 'category-up 'category-down ss)
  6573. (memq 'category-keep ss))
  6574. (org-cmp-category a b)))
  6575. (category-down (if category-up (- category-up) nil))
  6576. (category-keep (if category-up +1 nil))
  6577. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6578. (org-cmp-tag a b)))
  6579. (tag-down (if tag-up (- tag-up) nil))
  6580. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6581. (org-cmp-todo-state a b)))
  6582. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6583. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6584. (org-cmp-habit-p a b)))
  6585. (habit-down (if habit-up (- habit-up) nil))
  6586. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6587. (org-cmp-alpha a b)))
  6588. (alpha-down (if alpha-up (- alpha-up) nil))
  6589. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6590. user-defined-up user-defined-down)
  6591. (if (and need-user-cmp org-agenda-cmp-user-defined
  6592. (functionp org-agenda-cmp-user-defined))
  6593. (setq user-defined-up
  6594. (funcall org-agenda-cmp-user-defined a b)
  6595. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6596. (cdr (assoc
  6597. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6598. '((-1 . t) (1 . nil) (nil . nil))))))
  6599. ;;; Agenda restriction lock
  6600. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6601. "Overlay to mark the headline to which agenda commands are restricted.")
  6602. (overlay-put org-agenda-restriction-lock-overlay
  6603. 'face 'org-agenda-restriction-lock)
  6604. (overlay-put org-agenda-restriction-lock-overlay
  6605. 'help-echo "Agendas are currently limited to this subtree.")
  6606. (delete-overlay org-agenda-restriction-lock-overlay)
  6607. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6608. "Set the restriction lock to the agenda item at point from within the agenda.
  6609. When called with a `\\[universal-argument]' prefix, restrict to
  6610. the file which contains the item.
  6611. Argument ARG is the prefix argument."
  6612. (interactive "P")
  6613. (unless (derived-mode-p 'org-agenda-mode)
  6614. (user-error "Not in an Org agenda buffer"))
  6615. (let* ((marker (or (org-get-at-bol 'org-marker)
  6616. (org-agenda-error)))
  6617. (buffer (marker-buffer marker))
  6618. (pos (marker-position marker)))
  6619. (with-current-buffer buffer
  6620. (goto-char pos)
  6621. (org-agenda-set-restriction-lock arg))))
  6622. ;;;###autoload
  6623. (defun org-agenda-set-restriction-lock (&optional type)
  6624. "Set restriction lock for agenda, to current subtree or file.
  6625. Restriction will be the file if TYPE is `file', or if type is the
  6626. universal prefix \\='(4), or if the cursor is before the first headline
  6627. in the file. Otherwise, restriction will be to the current subtree."
  6628. (interactive "P")
  6629. (org-agenda-remove-restriction-lock 'noupdate)
  6630. (and (equal type '(4)) (setq type 'file))
  6631. (setq type (cond
  6632. (type type)
  6633. ((org-at-heading-p) 'subtree)
  6634. ((condition-case nil (org-back-to-heading t) (error nil))
  6635. 'subtree)
  6636. (t 'file)))
  6637. (if (eq type 'subtree)
  6638. (progn
  6639. (setq org-agenda-restrict (current-buffer))
  6640. (setq org-agenda-overriding-restriction 'subtree)
  6641. (put 'org-agenda-files 'org-restrict
  6642. (list (buffer-file-name (buffer-base-buffer))))
  6643. (org-back-to-heading t)
  6644. (move-overlay org-agenda-restriction-lock-overlay
  6645. (point)
  6646. (if org-agenda-restriction-lock-highlight-subtree
  6647. (save-excursion (org-end-of-subtree t t) (point))
  6648. (point-at-eol)))
  6649. (move-marker org-agenda-restrict-begin (point))
  6650. (move-marker org-agenda-restrict-end
  6651. (save-excursion (org-end-of-subtree t t)))
  6652. (message "Locking agenda restriction to subtree"))
  6653. (put 'org-agenda-files 'org-restrict
  6654. (list (buffer-file-name (buffer-base-buffer))))
  6655. (setq org-agenda-restrict nil)
  6656. (setq org-agenda-overriding-restriction 'file)
  6657. (move-marker org-agenda-restrict-begin nil)
  6658. (move-marker org-agenda-restrict-end nil)
  6659. (message "Locking agenda restriction to file"))
  6660. (setq current-prefix-arg nil)
  6661. (org-agenda-maybe-redo))
  6662. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6663. "Remove the agenda restriction lock."
  6664. (interactive "P")
  6665. (delete-overlay org-agenda-restriction-lock-overlay)
  6666. (delete-overlay org-speedbar-restriction-lock-overlay)
  6667. (setq org-agenda-overriding-restriction nil)
  6668. (setq org-agenda-restrict nil)
  6669. (put 'org-agenda-files 'org-restrict nil)
  6670. (move-marker org-agenda-restrict-begin nil)
  6671. (move-marker org-agenda-restrict-end nil)
  6672. (setq current-prefix-arg nil)
  6673. (message "Agenda restriction lock removed")
  6674. (or noupdate (org-agenda-maybe-redo)))
  6675. (defun org-agenda-maybe-redo ()
  6676. "If there is any window showing the agenda view, update it."
  6677. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6678. org-agenda-buffer-name)
  6679. t))
  6680. (w0 (selected-window)))
  6681. (when w
  6682. (select-window w)
  6683. (org-agenda-redo)
  6684. (select-window w0)
  6685. (if org-agenda-overriding-restriction
  6686. (message "Agenda view shifted to new %s restriction"
  6687. org-agenda-overriding-restriction)
  6688. (message "Agenda restriction lock removed")))))
  6689. ;;; Agenda commands
  6690. (defun org-agenda-check-type (error &rest types)
  6691. "Check if agenda buffer is of allowed type.
  6692. If ERROR is non-nil, throw an error, otherwise just return nil.
  6693. Allowed types are `agenda' `todo' `tags' `search'."
  6694. (cond ((not org-agenda-type)
  6695. (error "No Org agenda currently displayed"))
  6696. ((memq org-agenda-type types) t)
  6697. (error
  6698. (error "Not allowed in %s-type agenda buffers" org-agenda-type))
  6699. (t nil)))
  6700. (defun org-agenda-Quit ()
  6701. "Exit the agenda, killing the agenda buffer.
  6702. Like `org-agenda-quit', but kill the buffer even when
  6703. `org-agenda-sticky' is non-nil."
  6704. (interactive)
  6705. (org-agenda--quit))
  6706. (defun org-agenda-quit ()
  6707. "Exit the agenda.
  6708. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6709. instead of killing it.
  6710. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6711. the pre-agenda window configuration.
  6712. When column view is active, exit column view instead of the
  6713. agenda."
  6714. (interactive)
  6715. (org-agenda--quit org-agenda-sticky))
  6716. (defun org-agenda--quit (&optional bury)
  6717. (if org-agenda-columns-active
  6718. (org-columns-quit)
  6719. (let ((wconf org-agenda-pre-window-conf)
  6720. (buf (current-buffer))
  6721. (org-agenda-last-indirect-window
  6722. (and (eq org-indirect-buffer-display 'other-window)
  6723. org-agenda-last-indirect-buffer
  6724. (get-buffer-window org-agenda-last-indirect-buffer))))
  6725. (cond
  6726. ((eq org-agenda-window-setup 'other-frame)
  6727. (delete-frame))
  6728. ((and org-agenda-restore-windows-after-quit
  6729. wconf)
  6730. ;; Maybe restore the pre-agenda window configuration. Reset
  6731. ;; `org-agenda-pre-window-conf' before running
  6732. ;; `set-window-configuration', which loses the current buffer.
  6733. (setq org-agenda-pre-window-conf nil)
  6734. (set-window-configuration wconf))
  6735. (t
  6736. (when org-agenda-last-indirect-window
  6737. (delete-window org-agenda-last-indirect-window))
  6738. (and (not (eq org-agenda-window-setup 'current-window))
  6739. (not (one-window-p))
  6740. (delete-window))))
  6741. (if bury
  6742. ;; Set the agenda buffer as the current buffer instead of
  6743. ;; passing it as an argument to `bury-buffer' so that
  6744. ;; `bury-buffer' removes it from the window.
  6745. (with-current-buffer buf
  6746. (bury-buffer))
  6747. (kill-buffer buf)
  6748. (setq org-agenda-archives-mode nil
  6749. org-agenda-buffer nil)))))
  6750. (defun org-agenda-exit ()
  6751. "Exit the agenda, killing Org buffers loaded by the agenda.
  6752. Like `org-agenda-Quit', but kill any buffers that were created by
  6753. the agenda. Org buffers visited directly by the user will not be
  6754. touched. Also, exit the agenda even if it is in column view."
  6755. (interactive)
  6756. (when org-agenda-columns-active
  6757. (org-columns-quit))
  6758. (org-release-buffers org-agenda-new-buffers)
  6759. (setq org-agenda-new-buffers nil)
  6760. (org-agenda-Quit))
  6761. (defun org-agenda-kill-all-agenda-buffers ()
  6762. "Kill all buffers in `org-agenda-mode'.
  6763. This is used when toggling sticky agendas."
  6764. (interactive)
  6765. (let (blist)
  6766. (dolist (buf (buffer-list))
  6767. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6768. (push buf blist)))
  6769. (mapc 'kill-buffer blist)))
  6770. (defun org-agenda-execute (arg)
  6771. "Execute another agenda command, keeping same window.
  6772. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6773. in the agenda."
  6774. (interactive "P")
  6775. (let ((org-agenda-window-setup 'current-window))
  6776. (org-agenda arg)))
  6777. (defun org-agenda-redo (&optional all)
  6778. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6779. (interactive "P")
  6780. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6781. (cpa (unless (eq all t) current-prefix-arg))
  6782. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6783. (org-agenda-sticky nil)
  6784. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6785. org-agenda-buffer-name))
  6786. (org-agenda-keep-modes t)
  6787. (tag-filter org-agenda-tag-filter)
  6788. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6789. (top-hl-filter org-agenda-top-headline-filter)
  6790. (cat-filter org-agenda-category-filter)
  6791. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6792. (re-filter org-agenda-regexp-filter)
  6793. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6794. (effort-filter org-agenda-effort-filter)
  6795. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6796. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6797. (cols org-agenda-columns-active)
  6798. (line (org-current-line))
  6799. (window-line (- line (org-current-line (window-start))))
  6800. (lprops org-agenda-lprops)
  6801. (redo-cmd (get-text-property p 'org-redo-cmd))
  6802. (last-args (get-text-property p 'org-last-args))
  6803. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6804. (org-agenda-overriding-cmd-arguments
  6805. (unless (eq all t)
  6806. (cond ((listp last-args)
  6807. (cons (or cpa (car last-args)) (cdr last-args)))
  6808. ((stringp last-args)
  6809. last-args))))
  6810. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6811. (put 'org-agenda-tag-filter :preset-filter nil)
  6812. (put 'org-agenda-category-filter :preset-filter nil)
  6813. (put 'org-agenda-regexp-filter :preset-filter nil)
  6814. (put 'org-agenda-effort-filter :preset-filter nil)
  6815. (and cols (org-columns-quit))
  6816. (message "Rebuilding agenda buffer...")
  6817. (if series-redo-cmd
  6818. (eval series-redo-cmd)
  6819. (org-let lprops redo-cmd))
  6820. (setq org-agenda-undo-list nil
  6821. org-agenda-pending-undo-list nil
  6822. org-agenda-tag-filter tag-filter
  6823. org-agenda-category-filter cat-filter
  6824. org-agenda-regexp-filter re-filter
  6825. org-agenda-effort-filter effort-filter
  6826. org-agenda-top-headline-filter top-hl-filter)
  6827. (message "Rebuilding agenda buffer...done")
  6828. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6829. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6830. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6831. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6832. (let ((tag (or tag-filter tag-preset))
  6833. (cat (or cat-filter cat-preset))
  6834. (effort (or effort-filter effort-preset))
  6835. (re (or re-filter re-preset)))
  6836. (when tag (org-agenda-filter-apply tag 'tag t))
  6837. (when cat (org-agenda-filter-apply cat 'category))
  6838. (when effort (org-agenda-filter-apply effort 'effort))
  6839. (when re (org-agenda-filter-apply re 'regexp)))
  6840. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6841. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6842. (org-goto-line line)
  6843. (recenter window-line)))
  6844. (defun org-agenda-redo-all (&optional exhaustive)
  6845. "Rebuild all agenda views in the current buffer.
  6846. With a prefix argument, do so in all agenda buffers."
  6847. (interactive "P")
  6848. (if exhaustive
  6849. (dolist (buffer (buffer-list))
  6850. (with-current-buffer buffer
  6851. (when (derived-mode-p 'org-agenda-mode)
  6852. (org-agenda-redo t))))
  6853. (org-agenda-redo t)))
  6854. (defvar org-global-tags-completion-table nil)
  6855. (defvar org-agenda-filter-form nil)
  6856. (defvar org-agenda-filtered-by-category nil)
  6857. (defun org-agenda-filter-by-category (strip)
  6858. "Filter lines in the agenda buffer that have a specific category.
  6859. The category is that of the current line.
  6860. Without prefix argument, keep only the lines of that category.
  6861. With a prefix argument, exclude the lines of that category.
  6862. "
  6863. (interactive "P")
  6864. (if (and org-agenda-filtered-by-category
  6865. org-agenda-category-filter)
  6866. (org-agenda-filter-show-all-cat)
  6867. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6868. (cond
  6869. ((and cat strip)
  6870. (org-agenda-filter-apply
  6871. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6872. (cat
  6873. (org-agenda-filter-apply
  6874. (setq org-agenda-category-filter
  6875. (list (concat "+" cat))) 'category))
  6876. (t (error "No category at point"))))))
  6877. (defun org-find-top-headline (&optional pos)
  6878. "Find the topmost parent headline and return it.
  6879. POS when non-nil is the marker or buffer position to start the
  6880. search from."
  6881. (save-excursion
  6882. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6883. (when pos (goto-char pos))
  6884. ;; Skip up to the topmost parent.
  6885. (while (org-up-heading-safe))
  6886. (ignore-errors (nth 4 (org-heading-components))))))
  6887. (defvar org-agenda-filtered-by-top-headline nil)
  6888. (defun org-agenda-filter-by-top-headline (strip)
  6889. "Keep only those lines that are descendants from the same top headline.
  6890. The top headline is that of the current line."
  6891. (interactive "P")
  6892. (if org-agenda-filtered-by-top-headline
  6893. (progn
  6894. (setq org-agenda-filtered-by-top-headline nil
  6895. org-agenda-top-headline-filter nil)
  6896. (org-agenda-filter-show-all-top-filter))
  6897. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6898. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6899. (error "No top-level headline at point")))))
  6900. (defvar org-agenda-regexp-filter nil)
  6901. (defun org-agenda-filter-by-regexp (strip)
  6902. "Filter agenda entries by a regular expression.
  6903. Regexp filters are cumulative.
  6904. With no prefix argument, keep entries matching the regexp.
  6905. With one prefix argument, filter out entries matching the regexp.
  6906. With two prefix arguments, remove the regexp filters."
  6907. (interactive "P")
  6908. (if (not (equal strip '(16)))
  6909. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6910. (read-from-minibuffer
  6911. (if (equal strip '(4))
  6912. "Filter out entries matching regexp: "
  6913. "Narrow to entries matching regexp: ")))))
  6914. (push flt org-agenda-regexp-filter)
  6915. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6916. (org-agenda-filter-show-all-re)
  6917. (message "Regexp filter removed")))
  6918. (defvar org-agenda-effort-filter nil)
  6919. (defun org-agenda-filter-by-effort (strip)
  6920. "Filter agenda entries by effort.
  6921. With no prefix argument, keep entries matching the effort condition.
  6922. With one prefix argument, filter out entries matching the condition.
  6923. With two prefix arguments, remove the effort filters."
  6924. (interactive "P")
  6925. (cond
  6926. ((member strip '(nil 4))
  6927. (let* ((efforts (split-string
  6928. (or (cdr (assoc (concat org-effort-property "_ALL")
  6929. org-global-properties))
  6930. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6931. ;; XXX: the following handles only up to 10 different
  6932. ;; effort values.
  6933. (allowed-keys (if (null efforts) nil
  6934. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6935. (number-sequence 1 (length efforts)))))
  6936. (op nil))
  6937. (while (not (memq op '(?< ?> ?=)))
  6938. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6939. ;; Select appropriate duration. Ignore non-digit characters.
  6940. (let ((prompt
  6941. (apply #'format
  6942. (concat "Effort %c "
  6943. (mapconcat (lambda (s) (concat "[%d]" s))
  6944. efforts
  6945. " "))
  6946. op allowed-keys))
  6947. (eff -1))
  6948. (while (not (memq eff allowed-keys))
  6949. (message prompt)
  6950. (setq eff (- (read-char-exclusive) 48)))
  6951. (setq org-agenda-effort-filter
  6952. (list (concat (if strip "-" "+")
  6953. (char-to-string op)
  6954. ;; Numbering is 1 2 3 ... 9 0, but we want
  6955. ;; 0 1 2 ... 8 9.
  6956. (nth (mod (1- eff) 10) efforts)))))
  6957. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6958. (t (org-agenda-filter-show-all-effort)
  6959. (message "Effort filter removed"))))
  6960. (defun org-agenda-filter-remove-all ()
  6961. "Remove all filters from the current agenda buffer."
  6962. (interactive)
  6963. (when org-agenda-tag-filter
  6964. (org-agenda-filter-show-all-tag))
  6965. (when org-agenda-category-filter
  6966. (org-agenda-filter-show-all-cat))
  6967. (when org-agenda-regexp-filter
  6968. (org-agenda-filter-show-all-re))
  6969. (when org-agenda-top-headline-filter
  6970. (org-agenda-filter-show-all-top-filter))
  6971. (when org-agenda-effort-filter
  6972. (org-agenda-filter-show-all-effort))
  6973. (org-agenda-finalize))
  6974. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6975. "Keep only those lines in the agenda buffer that have a specific tag.
  6976. The tag is selected with its fast selection letter, as configured.
  6977. With a `\\[universal-argument]' prefix, exclude the agenda search.
  6978. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  6979. i.e. don't
  6980. filter on all its group members.
  6981. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  6982. should be used to exclude the search - the interactive user can
  6983. also press `-' or `+' to switch between filtering and excluding."
  6984. (interactive "P")
  6985. (let* ((alist org-tag-alist-for-agenda)
  6986. (tag-chars (mapconcat
  6987. (lambda (x) (if (and (not (symbolp (car x)))
  6988. (cdr x))
  6989. (char-to-string (cdr x))
  6990. ""))
  6991. org-tag-alist-for-agenda ""))
  6992. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  6993. (string-to-list tag-chars)))
  6994. (exclude (or exclude (equal arg '(4))))
  6995. (expand (not (equal arg '(16))))
  6996. (inhibit-read-only t)
  6997. (current org-agenda-tag-filter)
  6998. a n tag)
  6999. (unless char
  7000. (while (not (memq char valid-char-list))
  7001. (message
  7002. "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7003. (if exclude "Exclude" "Filter")
  7004. tag-chars
  7005. (if org-agenda-auto-exclude-function "[RET], " "")
  7006. (if expand "" ", no grouptag expand"))
  7007. (setq char (read-char-exclusive))
  7008. ;; Excluding or filtering down
  7009. (cond ((eq char ?-) (setq exclude t))
  7010. ((eq char ?+) (setq exclude nil)))))
  7011. (when (eq char ?\t)
  7012. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7013. (setq-local org-global-tags-completion-table
  7014. (org-global-tags-completion-table)))
  7015. (let ((completion-ignore-case t))
  7016. (setq tag (completing-read
  7017. "Tag: " org-global-tags-completion-table nil t))))
  7018. (cond
  7019. ((eq char ?\r)
  7020. (org-agenda-filter-show-all-tag)
  7021. (when org-agenda-auto-exclude-function
  7022. (setq org-agenda-tag-filter nil)
  7023. (dolist (tag (org-agenda-get-represented-tags))
  7024. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7025. (if modifier
  7026. (push modifier org-agenda-tag-filter))))
  7027. (if (not (null org-agenda-tag-filter))
  7028. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7029. ((eq char ?/)
  7030. (org-agenda-filter-show-all-tag)
  7031. (when (get 'org-agenda-tag-filter :preset-filter)
  7032. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7033. ((eq char ?.)
  7034. (setq org-agenda-tag-filter
  7035. (mapcar (lambda(tag) (concat "+" tag))
  7036. (org-get-at-bol 'tags)))
  7037. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7038. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7039. ((or (eq char ?\s)
  7040. (setq a (rassoc char alist))
  7041. (and tag (setq a (cons tag nil))))
  7042. (org-agenda-filter-show-all-tag)
  7043. (setq tag (car a))
  7044. (setq org-agenda-tag-filter
  7045. (cons (concat (if exclude "-" "+") tag)
  7046. current))
  7047. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7048. (t (error "Invalid tag selection character %c" char)))))
  7049. (defun org-agenda-get-represented-tags ()
  7050. "Get a list of all tags currently represented in the agenda."
  7051. (let (p tags)
  7052. (save-excursion
  7053. (goto-char (point-min))
  7054. (while (setq p (next-single-property-change (point) 'tags))
  7055. (goto-char p)
  7056. (mapc (lambda (x) (add-to-list 'tags x))
  7057. (get-text-property (point) 'tags))))
  7058. tags))
  7059. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7060. "Create the form that tests a line for agenda filter. Optional
  7061. argument EXPAND can be used for the TYPE tag and will expand the
  7062. tags in the FILTER if any of the tags in FILTER are grouptags."
  7063. (let (f f1)
  7064. (cond
  7065. ;; Tag filter
  7066. ((eq type 'tag)
  7067. (setq filter
  7068. (delete-dups
  7069. (append (get 'org-agenda-tag-filter :preset-filter)
  7070. filter)))
  7071. (dolist (x filter)
  7072. (let ((op (string-to-char x)))
  7073. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7074. (setq x (list x)))
  7075. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7076. (push f1 f))))
  7077. ;; Category filter
  7078. ((eq type 'category)
  7079. (setq filter
  7080. (delete-dups
  7081. (append (get 'org-agenda-category-filter :preset-filter)
  7082. filter)))
  7083. (dolist (x filter)
  7084. (if (equal "-" (substring x 0 1))
  7085. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7086. (setq f1 (list 'equal (substring x 1) 'cat)))
  7087. (push f1 f)))
  7088. ;; Regexp filter
  7089. ((eq type 'regexp)
  7090. (setq filter
  7091. (delete-dups
  7092. (append (get 'org-agenda-regexp-filter :preset-filter)
  7093. filter)))
  7094. (dolist (x filter)
  7095. (if (equal "-" (substring x 0 1))
  7096. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7097. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7098. (push f1 f)))
  7099. ;; Effort filter
  7100. ((eq type 'effort)
  7101. (setq filter
  7102. (delete-dups
  7103. (append (get 'org-agenda-effort-filter :preset-filter)
  7104. filter)))
  7105. (dolist (x filter)
  7106. (push (org-agenda-filter-effort-form x) f))))
  7107. (cons 'and (nreverse f))))
  7108. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7109. "Return a form associated to tag-expression TAGS.
  7110. Build a form testing a line for agenda filter for
  7111. tag-expressions. OP is an operator of type CHAR that allows the
  7112. function to set the right switches in the returned form."
  7113. (let (form)
  7114. ;; Any of the expressions can match if OP is +, all must match if
  7115. ;; the operator is -.
  7116. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7117. (let* ((tag (substring x 1))
  7118. (f (cond
  7119. ((string= "" tag) '(not tags))
  7120. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7121. ;; TAG is a regexp.
  7122. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7123. (t (list 'member (downcase tag) 'tags)))))
  7124. (push (if (eq op ?-) (list 'not f) f) form)))))
  7125. (defun org-agenda-filter-effort-form (e)
  7126. "Return the form to compare the effort of the current line with what E says.
  7127. E looks like \"+<2:25\"."
  7128. (let (op)
  7129. (setq e (substring e 1))
  7130. (setq op (string-to-char e) e (substring e 1))
  7131. (setq op (cond ((equal op ?<) '<=)
  7132. ((equal op ?>) '>=)
  7133. ((equal op ??) op)
  7134. (t '=)))
  7135. (list 'org-agenda-compare-effort (list 'quote op)
  7136. (org-duration-to-minutes e))))
  7137. (defun org-agenda-compare-effort (op value)
  7138. "Compare the effort of the current line with VALUE, using OP.
  7139. If the line does not have an effort defined, return nil."
  7140. ;; `effort-minutes' property cannot be extracted directly from
  7141. ;; current line but is stored as a property in `txt'.
  7142. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7143. (funcall op
  7144. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7145. value)))
  7146. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7147. "Expand group tags in FILTER for the agenda.
  7148. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7149. (if org-group-tags
  7150. (let ((case-fold-search t) rtn)
  7151. (mapc
  7152. (lambda (f)
  7153. (let (f0 dir)
  7154. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7155. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7156. (setq dir (if no-operator "" "+") f0 f))
  7157. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7158. (org-tags-expand f0 t t))
  7159. rtn))))
  7160. filter)
  7161. (reverse rtn))
  7162. filter))
  7163. (defun org-agenda-filter-apply (filter type &optional expand)
  7164. "Set FILTER as the new agenda filter and apply it. Optional
  7165. argument EXPAND can be used for the TYPE tag and will expand the
  7166. tags in the FILTER if any of the tags in FILTER are grouptags."
  7167. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7168. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7169. (let (tags cat txt)
  7170. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7171. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7172. ;; category is used as the filter:
  7173. (setq org-agenda-filtered-by-category
  7174. (and (eq type 'category)
  7175. (not (equal (substring (car filter) 0 1) "-"))))
  7176. (org-agenda-set-mode-name)
  7177. (save-excursion
  7178. (goto-char (point-min))
  7179. (while (not (eobp))
  7180. (if (org-get-at-bol 'org-marker)
  7181. (progn
  7182. (setq tags (org-get-at-bol 'tags)
  7183. cat (org-get-at-eol 'org-category 1)
  7184. txt (org-get-at-bol 'txt))
  7185. (if (not (eval org-agenda-filter-form))
  7186. (org-agenda-filter-hide-line type))
  7187. (beginning-of-line 2))
  7188. (beginning-of-line 2))))
  7189. (if (get-char-property (point) 'invisible)
  7190. (ignore-errors (org-agenda-previous-line)))))
  7191. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7192. "Filter by top headline HL."
  7193. (org-agenda-set-mode-name)
  7194. (save-excursion
  7195. (goto-char (point-min))
  7196. (while (not (eobp))
  7197. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7198. (tophl (and pos (org-find-top-headline pos))))
  7199. (if (and tophl (funcall (if negative 'identity 'not)
  7200. (string= hl tophl)))
  7201. (org-agenda-filter-hide-line 'top-headline)))
  7202. (beginning-of-line 2)))
  7203. (if (get-char-property (point) 'invisible)
  7204. (org-agenda-previous-line))
  7205. (setq org-agenda-top-headline-filter hl
  7206. org-agenda-filtered-by-top-headline t))
  7207. (defun org-agenda-filter-hide-line (type)
  7208. "Hide lines with TYPE in the agenda buffer."
  7209. (let* ((b (max (point-min) (1- (point-at-bol))))
  7210. (e (point-at-eol)))
  7211. (let ((inhibit-read-only t))
  7212. (add-text-properties
  7213. b e `(invisible org-filtered org-filter-type ,type)))))
  7214. (defun org-agenda-remove-filter (type)
  7215. (interactive)
  7216. "Remove filter of type TYPE from the agenda buffer."
  7217. (save-excursion
  7218. (goto-char (point-min))
  7219. (let ((inhibit-read-only t) pos)
  7220. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7221. (goto-char pos)
  7222. (remove-text-properties
  7223. (point) (next-single-property-change (point) 'org-filter-type)
  7224. `(invisible org-filtered org-filter-type ,type))))
  7225. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7226. (setq org-agenda-filter-form nil)
  7227. (org-agenda-set-mode-name)
  7228. (org-agenda-finalize)))
  7229. (defun org-agenda-filter-show-all-tag nil
  7230. (org-agenda-remove-filter 'tag))
  7231. (defun org-agenda-filter-show-all-re nil
  7232. (org-agenda-remove-filter 'regexp))
  7233. (defun org-agenda-filter-show-all-effort nil
  7234. (org-agenda-remove-filter 'effort))
  7235. (defun org-agenda-filter-show-all-cat nil
  7236. (org-agenda-remove-filter 'category))
  7237. (defun org-agenda-filter-show-all-top-filter nil
  7238. (org-agenda-remove-filter 'top-headline))
  7239. (defun org-agenda-manipulate-query-add ()
  7240. "Manipulate the query by adding a search term with positive selection.
  7241. Positive selection means the term must be matched for selection of an entry."
  7242. (interactive)
  7243. (org-agenda-manipulate-query ?\[))
  7244. (defun org-agenda-manipulate-query-subtract ()
  7245. "Manipulate the query by adding a search term with negative selection.
  7246. Negative selection means term must not be matched for selection of an entry."
  7247. (interactive)
  7248. (org-agenda-manipulate-query ?\]))
  7249. (defun org-agenda-manipulate-query-add-re ()
  7250. "Manipulate the query by adding a search regexp with positive selection.
  7251. Positive selection means the regexp must match for selection of an entry."
  7252. (interactive)
  7253. (org-agenda-manipulate-query ?\{))
  7254. (defun org-agenda-manipulate-query-subtract-re ()
  7255. "Manipulate the query by adding a search regexp with negative selection.
  7256. Negative selection means regexp must not match for selection of an entry."
  7257. (interactive)
  7258. (org-agenda-manipulate-query ?\}))
  7259. (defun org-agenda-manipulate-query (char)
  7260. (cond
  7261. ((eq org-agenda-type 'agenda)
  7262. (let ((org-agenda-include-inactive-timestamps t))
  7263. (org-agenda-redo))
  7264. (message "Display now includes inactive timestamps as well"))
  7265. ((eq org-agenda-type 'search)
  7266. (org-add-to-string
  7267. 'org-agenda-query-string
  7268. (if org-agenda-last-search-view-search-was-boolean
  7269. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7270. (?\{ . " +{}") (?\} . " -{}"))))
  7271. " "))
  7272. (setq org-agenda-redo-command
  7273. (list 'org-search-view
  7274. (car (get-text-property (min (1- (point-max)) (point))
  7275. 'org-last-args))
  7276. org-agenda-query-string
  7277. (+ (length org-agenda-query-string)
  7278. (if (member char '(?\{ ?\})) 0 1))))
  7279. (set-register org-agenda-query-register org-agenda-query-string)
  7280. (let ((org-agenda-overriding-arguments
  7281. (cdr org-agenda-redo-command)))
  7282. (org-agenda-redo)))
  7283. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7284. org-agenda-type))))
  7285. (defun org-add-to-string (var string)
  7286. (set var (concat (symbol-value var) string)))
  7287. (defun org-agenda-goto-date (span)
  7288. "Jump to DATE in agenda."
  7289. (interactive "P")
  7290. (let* ((org-read-date-prefer-future
  7291. (eval org-agenda-jump-prefer-future))
  7292. (date (org-read-date))
  7293. (day (time-to-days (org-time-string-to-time date)))
  7294. (org-agenda-sticky-orig org-agenda-sticky)
  7295. (org-agenda-buffer-tmp-name (buffer-name))
  7296. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7297. (0-arg (or current-prefix-arg (car args)))
  7298. (2-arg (nth 2 args))
  7299. (with-hour-p (nth 4 org-agenda-redo-command))
  7300. (newcmd (list 'org-agenda-list 0-arg date
  7301. (org-agenda-span-to-ndays
  7302. 2-arg (org-time-string-to-absolute date))
  7303. with-hour-p))
  7304. (newargs (cdr newcmd))
  7305. (inhibit-read-only t)
  7306. org-agenda-sticky)
  7307. (if (not (org-agenda-check-type t 'agenda))
  7308. (error "Not available in non-agenda views")
  7309. (add-text-properties (point-min) (point-max)
  7310. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7311. (org-agenda-redo)
  7312. (goto-char (point-min))
  7313. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7314. (save-excursion (move-beginning-of-line 2) (eobp))))
  7315. (move-beginning-of-line 2))
  7316. (setq org-agenda-sticky org-agenda-sticky-orig
  7317. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7318. (defun org-agenda-goto-today ()
  7319. "Go to today."
  7320. (interactive)
  7321. (org-agenda-check-type t 'agenda)
  7322. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7323. (curspan (nth 2 args))
  7324. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7325. (cond
  7326. (tdpos (goto-char tdpos))
  7327. ((eq org-agenda-type 'agenda)
  7328. (let* ((sd (org-agenda-compute-starting-span
  7329. (org-today) (or curspan org-agenda-span)))
  7330. (org-agenda-overriding-arguments args))
  7331. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7332. (org-agenda-redo)
  7333. (org-agenda-find-same-or-today-or-agenda)))
  7334. (t (error "Cannot find today")))))
  7335. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7336. (goto-char
  7337. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7338. (text-property-any (point-min) (point-max) 'org-today t)
  7339. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7340. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7341. (org-agenda-backward-block))
  7342. (point-min))))
  7343. (defun org-agenda-backward-block ()
  7344. "Move backward by one agenda block."
  7345. (interactive)
  7346. (org-agenda-forward-block 'backward))
  7347. (defun org-agenda-forward-block (&optional backward)
  7348. "Move forward by one agenda block.
  7349. When optional argument BACKWARD is set, go backward"
  7350. (interactive)
  7351. (cond ((not (derived-mode-p 'org-agenda-mode))
  7352. (user-error
  7353. "Cannot execute this command outside of org-agenda-mode buffers"))
  7354. ((looking-at (if backward "\\`" "\\'"))
  7355. (message "Already at the %s block" (if backward "first" "last")))
  7356. (t (let ((pos (prog1 (point)
  7357. (ignore-errors (if backward (backward-char 1)
  7358. (move-end-of-line 1)))))
  7359. (f (if backward
  7360. 'previous-single-property-change
  7361. 'next-single-property-change))
  7362. moved dest)
  7363. (while (and (setq dest (funcall
  7364. f (point) 'org-agenda-structural-header))
  7365. (not (get-text-property
  7366. (point) 'org-agenda-structural-header)))
  7367. (setq moved t)
  7368. (goto-char dest))
  7369. (if moved (move-beginning-of-line 1)
  7370. (goto-char (if backward (point-min) (point-max)))
  7371. (move-beginning-of-line 1)
  7372. (message "No %s block" (if backward "previous" "further")))))))
  7373. (defun org-agenda-later (arg)
  7374. "Go forward in time by the current span.
  7375. With prefix ARG, go forward that many times the current span."
  7376. (interactive "p")
  7377. (org-agenda-check-type t 'agenda)
  7378. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7379. (span (or (nth 2 args) org-agenda-current-span))
  7380. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7381. (greg (calendar-gregorian-from-absolute sd))
  7382. (cnt (org-get-at-bol 'org-day-cnt))
  7383. greg2)
  7384. (cond
  7385. ((numberp span)
  7386. (setq sd (+ (* span arg) sd)))
  7387. ((eq span 'day)
  7388. (setq sd (+ arg sd)))
  7389. ((eq span 'week)
  7390. (setq sd (+ (* 7 arg) sd)))
  7391. ((eq span 'fortnight)
  7392. (setq sd (+ (* 14 arg) sd)))
  7393. ((eq span 'month)
  7394. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7395. sd (calendar-absolute-from-gregorian greg2))
  7396. (setcar greg2 (1+ (car greg2))))
  7397. ((eq span 'year)
  7398. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7399. sd (calendar-absolute-from-gregorian greg2))
  7400. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7401. (t
  7402. (setq sd (+ (* span arg) sd))))
  7403. (let ((org-agenda-overriding-cmd
  7404. ;; `cmd' may have been set by `org-agenda-run-series' which
  7405. ;; uses `org-agenda-overriding-cmd' to decide whether
  7406. ;; overriding is allowed for `cmd'
  7407. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7408. (org-agenda-overriding-arguments
  7409. (list (car args) sd span)))
  7410. (org-agenda-redo)
  7411. (org-agenda-find-same-or-today-or-agenda cnt))))
  7412. (defun org-agenda-earlier (arg)
  7413. "Go backward in time by the current span.
  7414. With prefix ARG, go backward that many times the current span."
  7415. (interactive "p")
  7416. (org-agenda-later (- arg)))
  7417. (defun org-agenda-view-mode-dispatch ()
  7418. "Call one of the view mode commands."
  7419. (interactive)
  7420. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7421. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7422. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7423. (pcase (read-char-exclusive)
  7424. (?\ (call-interactively 'org-agenda-reset-view))
  7425. (?d (call-interactively 'org-agenda-day-view))
  7426. (?w (call-interactively 'org-agenda-week-view))
  7427. (?t (call-interactively 'org-agenda-fortnight-view))
  7428. (?m (call-interactively 'org-agenda-month-view))
  7429. (?y (call-interactively 'org-agenda-year-view))
  7430. (?l (call-interactively 'org-agenda-log-mode))
  7431. (?L (org-agenda-log-mode '(4)))
  7432. (?c (org-agenda-log-mode 'clockcheck))
  7433. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7434. (?a (call-interactively 'org-agenda-archives-mode))
  7435. (?A (org-agenda-archives-mode 'files))
  7436. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7437. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7438. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7439. (?D (call-interactively 'org-agenda-toggle-diary))
  7440. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7441. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7442. (org-agenda-check-type t 'agenda)
  7443. (org-agenda-redo))
  7444. (message "Display now includes inactive timestamps as well"))
  7445. (?q (message "Abort"))
  7446. (key (user-error "Invalid key: %s" key))))
  7447. (defun org-agenda-reset-view ()
  7448. "Switch to default view for agenda."
  7449. (interactive)
  7450. (org-agenda-change-time-span org-agenda-span))
  7451. (defun org-agenda-day-view (&optional day-of-month)
  7452. "Switch to daily view for agenda.
  7453. With argument DAY-OF-MONTH, switch to that day of the month."
  7454. (interactive "P")
  7455. (org-agenda-change-time-span 'day day-of-month))
  7456. (defun org-agenda-week-view (&optional iso-week)
  7457. "Switch to weekly view for agenda.
  7458. With argument ISO-WEEK, switch to the corresponding ISO week.
  7459. If ISO-WEEK has more then 2 digits, only the last two encode
  7460. the week. Any digits before this encode a year. So 200712
  7461. means week 12 of year 2007. Years ranging from 70 years ago
  7462. to 30 years in the future can also be written as 2-digit years."
  7463. (interactive "P")
  7464. (org-agenda-change-time-span 'week iso-week))
  7465. (defun org-agenda-fortnight-view (&optional iso-week)
  7466. "Switch to fortnightly view for agenda.
  7467. With argument ISO-WEEK, switch to the corresponding ISO week.
  7468. If ISO-WEEK has more then 2 digits, only the last two encode
  7469. the week. Any digits before this encode a year. So 200712
  7470. means week 12 of year 2007. Years ranging from 70 years ago
  7471. to 30 years in the future can also be written as 2-digit years."
  7472. (interactive "P")
  7473. (org-agenda-change-time-span 'fortnight iso-week))
  7474. (defun org-agenda-month-view (&optional month)
  7475. "Switch to monthly view for agenda.
  7476. With argument MONTH, switch to that month. If MONTH has more
  7477. then 2 digits, only the last two encode the month. Any digits
  7478. before this encode a year. So 200712 means December year 2007.
  7479. Years ranging from 70 years ago to 30 years in the future can
  7480. also be written as 2-digit years."
  7481. (interactive "P")
  7482. (org-agenda-change-time-span 'month month))
  7483. (defun org-agenda-year-view (&optional year)
  7484. "Switch to yearly view for agenda.
  7485. With argument YEAR, switch to that year. Years ranging from 70
  7486. years ago to 30 years in the future can also be written as
  7487. 2-digit years."
  7488. (interactive "P")
  7489. (when year
  7490. (setq year (org-small-year-to-year year)))
  7491. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7492. (org-agenda-change-time-span 'year year)
  7493. (error "Abort")))
  7494. (defun org-agenda-change-time-span (span &optional n)
  7495. "Change the agenda view to SPAN.
  7496. SPAN may be `day', `week', `fortnight', `month', `year'."
  7497. (org-agenda-check-type t 'agenda)
  7498. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7499. (curspan (nth 2 args)))
  7500. (if (and (not n) (equal curspan span))
  7501. (error "Viewing span is already \"%s\"" span))
  7502. (let* ((sd (or (org-get-at-bol 'day)
  7503. (nth 1 args)
  7504. org-starting-day))
  7505. (sd (org-agenda-compute-starting-span sd span n))
  7506. (org-agenda-overriding-cmd
  7507. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7508. (org-agenda-overriding-arguments
  7509. (list (car args) sd span)))
  7510. (org-agenda-redo)
  7511. (org-agenda-find-same-or-today-or-agenda))
  7512. (org-agenda-set-mode-name)
  7513. (message "Switched to %s view" span)))
  7514. (defun org-agenda-compute-starting-span (sd span &optional n)
  7515. "Compute starting date for agenda.
  7516. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7517. is a cons cell with the starting date and the number of days,
  7518. so that the date SD will be in that range."
  7519. (let* ((greg (calendar-gregorian-from-absolute sd))
  7520. (dg (nth 1 greg))
  7521. (mg (car greg))
  7522. (yg (nth 2 greg)))
  7523. (cond
  7524. ((eq span 'day)
  7525. (when n
  7526. (setq sd (+ (calendar-absolute-from-gregorian
  7527. (list mg 1 yg))
  7528. n -1))))
  7529. ((or (eq span 'week) (eq span 'fortnight))
  7530. (let* ((nt (calendar-day-of-week
  7531. (calendar-gregorian-from-absolute sd)))
  7532. (d (if org-agenda-start-on-weekday
  7533. (- nt org-agenda-start-on-weekday)
  7534. 0))
  7535. y1)
  7536. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7537. (when n
  7538. (require 'cal-iso)
  7539. (when (> n 99)
  7540. (setq y1 (org-small-year-to-year (/ n 100))
  7541. n (mod n 100)))
  7542. (setq sd
  7543. (calendar-iso-to-absolute
  7544. (list n 1
  7545. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7546. ((eq span 'month)
  7547. (let (y1)
  7548. (when (and n (> n 99))
  7549. (setq y1 (org-small-year-to-year (/ n 100))
  7550. n (mod n 100)))
  7551. (setq sd (calendar-absolute-from-gregorian
  7552. (list (or n mg) 1 (or y1 yg))))))
  7553. ((eq span 'year)
  7554. (setq sd (calendar-absolute-from-gregorian
  7555. (list 1 1 (or n yg))))))
  7556. sd))
  7557. (defun org-agenda-next-date-line (&optional arg)
  7558. "Jump to the next line indicating a date in agenda buffer."
  7559. (interactive "p")
  7560. (org-agenda-check-type t 'agenda)
  7561. (beginning-of-line 1)
  7562. ;; This does not work if user makes date format that starts with a blank
  7563. (if (looking-at "^\\S-") (forward-char 1))
  7564. (if (not (re-search-forward "^\\S-" nil t arg))
  7565. (progn
  7566. (backward-char 1)
  7567. (error "No next date after this line in this buffer")))
  7568. (goto-char (match-beginning 0)))
  7569. (defun org-agenda-previous-date-line (&optional arg)
  7570. "Jump to the previous line indicating a date in agenda buffer."
  7571. (interactive "p")
  7572. (org-agenda-check-type t 'agenda)
  7573. (beginning-of-line 1)
  7574. (if (not (re-search-backward "^\\S-" nil t arg))
  7575. (error "No previous date before this line in this buffer")))
  7576. ;; Initialize the highlight
  7577. (defvar org-hl (make-overlay 1 1))
  7578. (overlay-put org-hl 'face 'highlight)
  7579. (defun org-highlight (begin end &optional buffer)
  7580. "Highlight a region with overlay."
  7581. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7582. (defun org-unhighlight ()
  7583. "Detach overlay INDEX."
  7584. (delete-overlay org-hl))
  7585. (defun org-unhighlight-once ()
  7586. "Remove the highlight from its position, and this function from the hook."
  7587. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7588. (org-unhighlight))
  7589. (defvar org-agenda-pre-follow-window-conf nil)
  7590. (defun org-agenda-follow-mode ()
  7591. "Toggle follow mode in an agenda buffer."
  7592. (interactive)
  7593. (unless org-agenda-follow-mode
  7594. (setq org-agenda-pre-follow-window-conf
  7595. (current-window-configuration)))
  7596. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7597. (unless org-agenda-follow-mode
  7598. (set-window-configuration org-agenda-pre-follow-window-conf))
  7599. (org-agenda-set-mode-name)
  7600. (org-agenda-do-context-action)
  7601. (message "Follow mode is %s"
  7602. (if org-agenda-follow-mode "on" "off")))
  7603. (defun org-agenda-entry-text-mode (&optional arg)
  7604. "Toggle entry text mode in an agenda buffer."
  7605. (interactive "P")
  7606. (if (or org-agenda-tag-filter
  7607. org-agenda-category-filter
  7608. org-agenda-regexp-filter
  7609. org-agenda-top-headline-filter)
  7610. (user-error "Can't show entry text in filtered views")
  7611. (setq org-agenda-entry-text-mode (or (integerp arg)
  7612. (not org-agenda-entry-text-mode)))
  7613. (org-agenda-entry-text-hide)
  7614. (and org-agenda-entry-text-mode
  7615. (let ((org-agenda-entry-text-maxlines
  7616. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7617. (org-agenda-entry-text-show)))
  7618. (org-agenda-set-mode-name)
  7619. (message "Entry text mode is %s%s"
  7620. (if org-agenda-entry-text-mode "on" "off")
  7621. (if (not org-agenda-entry-text-mode) ""
  7622. (format " (maximum number of lines is %d)"
  7623. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7624. (defun org-agenda-clockreport-mode ()
  7625. "Toggle clocktable mode in an agenda buffer."
  7626. (interactive)
  7627. (org-agenda-check-type t 'agenda)
  7628. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7629. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7630. (org-agenda-set-mode-name)
  7631. (org-agenda-redo)
  7632. (message "Clocktable mode is %s"
  7633. (if org-agenda-clockreport-mode "on" "off")))
  7634. (defun org-agenda-log-mode (&optional special)
  7635. "Toggle log mode in an agenda buffer.
  7636. With argument SPECIAL, show all possible log items, not only the ones
  7637. configured in `org-agenda-log-mode-items'.
  7638. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7639. log items, nothing else."
  7640. (interactive "P")
  7641. (org-agenda-check-type t 'agenda)
  7642. (setq org-agenda-show-log
  7643. (cond
  7644. ((equal special '(16)) 'only)
  7645. ((eq special 'clockcheck)
  7646. (if (eq org-agenda-show-log 'clockcheck)
  7647. nil 'clockcheck))
  7648. (special '(closed clock state))
  7649. (t (not org-agenda-show-log))))
  7650. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7651. (org-agenda-set-mode-name)
  7652. (org-agenda-redo)
  7653. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7654. (defun org-agenda-archives-mode (&optional with-files)
  7655. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7656. When called with a prefix argument, include all archive files as well."
  7657. (interactive "P")
  7658. (setq org-agenda-archives-mode
  7659. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7660. (org-agenda-set-mode-name)
  7661. (org-agenda-redo)
  7662. (message
  7663. "%s"
  7664. (cond
  7665. ((eq org-agenda-archives-mode nil)
  7666. "No archives are included")
  7667. ((eq org-agenda-archives-mode 'trees)
  7668. (format "Trees with :%s: tag are included" org-archive-tag))
  7669. ((eq org-agenda-archives-mode t)
  7670. (format "Trees with :%s: tag and all active archive files are included"
  7671. org-archive-tag)))))
  7672. (defun org-agenda-toggle-diary ()
  7673. "Toggle diary inclusion in an agenda buffer."
  7674. (interactive)
  7675. (org-agenda-check-type t 'agenda)
  7676. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7677. (org-agenda-redo)
  7678. (org-agenda-set-mode-name)
  7679. (message "Diary inclusion turned %s"
  7680. (if org-agenda-include-diary "on" "off")))
  7681. (defun org-agenda-toggle-deadlines ()
  7682. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7683. (interactive)
  7684. (org-agenda-check-type t 'agenda)
  7685. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7686. (org-agenda-redo)
  7687. (org-agenda-set-mode-name)
  7688. (message "Deadlines inclusion turned %s"
  7689. (if org-agenda-include-deadlines "on" "off")))
  7690. (defun org-agenda-toggle-time-grid ()
  7691. "Toggle time grid in an agenda buffer."
  7692. (interactive)
  7693. (org-agenda-check-type t 'agenda)
  7694. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7695. (org-agenda-redo)
  7696. (org-agenda-set-mode-name)
  7697. (message "Time-grid turned %s"
  7698. (if org-agenda-use-time-grid "on" "off")))
  7699. (defun org-agenda-set-mode-name ()
  7700. "Set the mode name to indicate all the small mode settings."
  7701. (setq mode-name
  7702. (list "Org-Agenda"
  7703. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7704. " "
  7705. '(:eval (org-agenda-span-name org-agenda-current-span))
  7706. (if org-agenda-follow-mode " Follow" "")
  7707. (if org-agenda-entry-text-mode " ETxt" "")
  7708. (if org-agenda-include-diary " Diary" "")
  7709. (if org-agenda-include-deadlines " Ddl" "")
  7710. (if org-agenda-use-time-grid " Grid" "")
  7711. (if (and (boundp 'org-habit-show-habits)
  7712. org-habit-show-habits) " Habit" "")
  7713. (cond
  7714. ((consp org-agenda-show-log) " LogAll")
  7715. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7716. (org-agenda-show-log " Log")
  7717. (t ""))
  7718. (if (or org-agenda-category-filter
  7719. (get 'org-agenda-category-filter :preset-filter))
  7720. '(:eval (propertize
  7721. (concat " <"
  7722. (mapconcat
  7723. 'identity
  7724. (append
  7725. (get 'org-agenda-category-filter :preset-filter)
  7726. org-agenda-category-filter)
  7727. "")
  7728. ">")
  7729. 'face 'org-agenda-filter-category
  7730. 'help-echo "Category used in filtering")) "")
  7731. (if (or org-agenda-tag-filter
  7732. (get 'org-agenda-tag-filter :preset-filter))
  7733. '(:eval (propertize
  7734. (concat " {"
  7735. (mapconcat
  7736. 'identity
  7737. (append
  7738. (get 'org-agenda-tag-filter :preset-filter)
  7739. org-agenda-tag-filter)
  7740. "")
  7741. "}")
  7742. 'face 'org-agenda-filter-tags
  7743. 'help-echo "Tags used in filtering")) "")
  7744. (if (or org-agenda-effort-filter
  7745. (get 'org-agenda-effort-filter :preset-filter))
  7746. '(:eval (propertize
  7747. (concat " {"
  7748. (mapconcat
  7749. 'identity
  7750. (append
  7751. (get 'org-agenda-effort-filter :preset-filter)
  7752. org-agenda-effort-filter)
  7753. "")
  7754. "}")
  7755. 'face 'org-agenda-filter-effort
  7756. 'help-echo "Effort conditions used in filtering")) "")
  7757. (if (or org-agenda-regexp-filter
  7758. (get 'org-agenda-regexp-filter :preset-filter))
  7759. '(:eval (propertize
  7760. (concat " ["
  7761. (mapconcat
  7762. 'identity
  7763. (append
  7764. (get 'org-agenda-regexp-filter :preset-filter)
  7765. org-agenda-regexp-filter)
  7766. "")
  7767. "]")
  7768. 'face 'org-agenda-filter-regexp
  7769. 'help-echo "Regexp used in filtering")) "")
  7770. (if org-agenda-archives-mode
  7771. (if (eq org-agenda-archives-mode t)
  7772. " Archives"
  7773. (format " :%s:" org-archive-tag))
  7774. "")
  7775. (if org-agenda-clockreport-mode " Clock" "")))
  7776. (force-mode-line-update))
  7777. (defun org-agenda-update-agenda-type ()
  7778. "Update the agenda type after each command."
  7779. (setq org-agenda-type
  7780. (or (get-text-property (point) 'org-agenda-type)
  7781. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7782. (defun org-agenda-next-line ()
  7783. "Move cursor to the next line, and show if follow mode is active."
  7784. (interactive)
  7785. (call-interactively 'next-line)
  7786. (org-agenda-do-context-action))
  7787. (defun org-agenda-previous-line ()
  7788. "Move cursor to the previous line, and show if follow-mode is active."
  7789. (interactive)
  7790. (call-interactively 'previous-line)
  7791. (org-agenda-do-context-action))
  7792. (defun org-agenda-next-item (n)
  7793. "Move cursor to next agenda item."
  7794. (interactive "p")
  7795. (let ((col (current-column)))
  7796. (dotimes (c n)
  7797. (when (next-single-property-change (point-at-eol) 'org-marker)
  7798. (move-end-of-line 1)
  7799. (goto-char (next-single-property-change (point) 'org-marker))))
  7800. (org-move-to-column col))
  7801. (org-agenda-do-context-action))
  7802. (defun org-agenda-previous-item (n)
  7803. "Move cursor to next agenda item."
  7804. (interactive "p")
  7805. (dotimes (c n)
  7806. (let ((col (current-column))
  7807. (goto (save-excursion
  7808. (move-end-of-line 0)
  7809. (previous-single-property-change (point) 'org-marker))))
  7810. (if goto (goto-char goto))
  7811. (org-move-to-column col)))
  7812. (org-agenda-do-context-action))
  7813. (defun org-agenda-do-context-action ()
  7814. "Show outline path and, maybe, follow mode window."
  7815. (let ((m (org-get-at-bol 'org-marker)))
  7816. (when (and (markerp m) (marker-buffer m))
  7817. (and org-agenda-follow-mode
  7818. (if org-agenda-follow-indirect
  7819. (org-agenda-tree-to-indirect-buffer nil)
  7820. (org-agenda-show)))
  7821. (and org-agenda-show-outline-path
  7822. (org-with-point-at m (org-display-outline-path t))))))
  7823. (defun org-agenda-show-tags ()
  7824. "Show the tags applicable to the current item."
  7825. (interactive)
  7826. (let* ((tags (org-get-at-bol 'tags)))
  7827. (if tags
  7828. (message "Tags are :%s:"
  7829. (org-no-properties (mapconcat 'identity tags ":")))
  7830. (message "No tags associated with this line"))))
  7831. (defun org-agenda-goto (&optional highlight)
  7832. "Go to the entry at point in the corresponding Org file."
  7833. (interactive)
  7834. (let* ((marker (or (org-get-at-bol 'org-marker)
  7835. (org-agenda-error)))
  7836. (buffer (marker-buffer marker))
  7837. (pos (marker-position marker)))
  7838. (switch-to-buffer-other-window buffer)
  7839. (widen)
  7840. (push-mark)
  7841. (goto-char pos)
  7842. (when (derived-mode-p 'org-mode)
  7843. (org-show-context 'agenda)
  7844. (recenter (/ (window-height) 2))
  7845. (org-back-to-heading t)
  7846. (let ((case-fold-search nil))
  7847. (when (re-search-forward org-complex-heading-regexp nil t)
  7848. (goto-char (match-beginning 4)))))
  7849. (run-hooks 'org-agenda-after-show-hook)
  7850. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7851. (defvar org-agenda-after-show-hook nil
  7852. "Normal hook run after an item has been shown from the agenda.
  7853. Point is in the buffer where the item originated.")
  7854. (defun org-agenda-kill ()
  7855. "Kill the entry or subtree belonging to the current agenda entry."
  7856. (interactive)
  7857. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7858. (let* ((bufname-orig (buffer-name))
  7859. (marker (or (org-get-at-bol 'org-marker)
  7860. (org-agenda-error)))
  7861. (buffer (marker-buffer marker))
  7862. (pos (marker-position marker))
  7863. (type (org-get-at-bol 'type))
  7864. dbeg dend (n 0) conf)
  7865. (org-with-remote-undo buffer
  7866. (with-current-buffer buffer
  7867. (save-excursion
  7868. (goto-char pos)
  7869. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7870. (setq dbeg (progn (org-back-to-heading t) (point))
  7871. dend (org-end-of-subtree t t))
  7872. (setq dbeg (point-at-bol)
  7873. dend (min (point-max) (1+ (point-at-eol)))))
  7874. (goto-char dbeg)
  7875. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7876. (setq conf (or (eq t org-agenda-confirm-kill)
  7877. (and (numberp org-agenda-confirm-kill)
  7878. (> n org-agenda-confirm-kill))))
  7879. (and conf
  7880. (not (y-or-n-p
  7881. (format "Delete entry with %d lines in buffer \"%s\"? "
  7882. n (buffer-name buffer))))
  7883. (error "Abort"))
  7884. (let ((org-agenda-buffer-name bufname-orig))
  7885. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7886. (with-current-buffer buffer (delete-region dbeg dend))
  7887. (message "Agenda item and source killed"))))
  7888. (defvar org-archive-default-command) ; defined in org-archive.el
  7889. (defun org-agenda-archive-default ()
  7890. "Archive the entry or subtree belonging to the current agenda entry."
  7891. (interactive)
  7892. (require 'org-archive)
  7893. (org-agenda-archive-with org-archive-default-command))
  7894. (defun org-agenda-archive-default-with-confirmation ()
  7895. "Archive the entry or subtree belonging to the current agenda entry."
  7896. (interactive)
  7897. (require 'org-archive)
  7898. (org-agenda-archive-with org-archive-default-command 'confirm))
  7899. (defun org-agenda-archive ()
  7900. "Archive the entry or subtree belonging to the current agenda entry."
  7901. (interactive)
  7902. (org-agenda-archive-with 'org-archive-subtree))
  7903. (defun org-agenda-archive-to-archive-sibling ()
  7904. "Move the entry to the archive sibling."
  7905. (interactive)
  7906. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7907. (defun org-agenda-archive-with (cmd &optional confirm)
  7908. "Move the entry to the archive sibling."
  7909. (interactive)
  7910. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7911. (let* ((bufname-orig (buffer-name))
  7912. (marker (or (org-get-at-bol 'org-marker)
  7913. (org-agenda-error)))
  7914. (buffer (marker-buffer marker))
  7915. (pos (marker-position marker)))
  7916. (org-with-remote-undo buffer
  7917. (with-current-buffer buffer
  7918. (if (derived-mode-p 'org-mode)
  7919. (if (and confirm
  7920. (not (y-or-n-p "Archive this subtree or entry? ")))
  7921. (error "Abort")
  7922. (save-window-excursion
  7923. (goto-char pos)
  7924. (let ((org-agenda-buffer-name bufname-orig))
  7925. (org-remove-subtree-entries-from-agenda))
  7926. (org-back-to-heading t)
  7927. (funcall cmd)))
  7928. (error "Archiving works only in Org files"))))))
  7929. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7930. "Remove all lines in the agenda that correspond to a given subtree.
  7931. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7932. If this information is not given, the function uses the tree at point."
  7933. (let ((buf (or buf (current-buffer))) m p)
  7934. (save-excursion
  7935. (unless (and beg end)
  7936. (org-back-to-heading t)
  7937. (setq beg (point))
  7938. (org-end-of-subtree t)
  7939. (setq end (point)))
  7940. (set-buffer (get-buffer org-agenda-buffer-name))
  7941. (save-excursion
  7942. (goto-char (point-max))
  7943. (beginning-of-line 1)
  7944. (while (not (bobp))
  7945. (when (and (setq m (org-get-at-bol 'org-marker))
  7946. (equal buf (marker-buffer m))
  7947. (setq p (marker-position m))
  7948. (>= p beg)
  7949. (< p end))
  7950. (let ((inhibit-read-only t))
  7951. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7952. (beginning-of-line 0))))))
  7953. (defun org-agenda-refile (&optional goto rfloc no-update)
  7954. "Refile the item at point.
  7955. When called with `\\[universal-argument] \\[universal-argument]', \
  7956. go to the location of the last
  7957. refiled item.
  7958. When called with `\\[universal-argument] \\[universal-argument] \
  7959. \\[universal-argument]' prefix or when GOTO is 0, clear
  7960. the refile cache.
  7961. RFLOC can be a refile location obtained in a different way.
  7962. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7963. (interactive "P")
  7964. (cond
  7965. ((member goto '(0 (64)))
  7966. (org-refile-cache-clear))
  7967. ((equal goto '(16))
  7968. (org-refile-goto-last-stored))
  7969. (t
  7970. (let* ((buffer-orig (buffer-name))
  7971. (marker (or (org-get-at-bol 'org-hd-marker)
  7972. (org-agenda-error)))
  7973. (buffer (marker-buffer marker))
  7974. (pos (marker-position marker))
  7975. (rfloc (or rfloc
  7976. (org-refile-get-location
  7977. (if goto "Goto" "Refile to") buffer
  7978. org-refile-allow-creating-parent-nodes))))
  7979. (with-current-buffer buffer
  7980. (org-with-wide-buffer
  7981. (goto-char marker)
  7982. (let ((org-agenda-buffer-name buffer-orig))
  7983. (org-remove-subtree-entries-from-agenda))
  7984. (org-refile goto buffer rfloc))))
  7985. (unless no-update (org-agenda-redo)))))
  7986. (defun org-agenda-open-link (&optional arg)
  7987. "Open the link(s) in the current entry, if any.
  7988. This looks for a link in the displayed line in the agenda.
  7989. It also looks at the text of the entry itself."
  7990. (interactive "P")
  7991. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7992. (org-get-at-bol 'org-marker)))
  7993. (buffer (and marker (marker-buffer marker)))
  7994. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7995. (lkall (and buffer (org-offer-links-in-entry
  7996. buffer marker arg prefix)))
  7997. (lk0 (car lkall))
  7998. (lk (if (stringp lk0) (list lk0) lk0))
  7999. (lkend (cdr lkall))
  8000. trg)
  8001. (cond
  8002. ((and buffer lk)
  8003. (mapcar (lambda(l)
  8004. (with-current-buffer buffer
  8005. (setq trg (and (string-match org-bracket-link-regexp l)
  8006. (match-string 1 l)))
  8007. (if (or (not trg) (string-match org-any-link-re trg))
  8008. (org-with-wide-buffer
  8009. (goto-char marker)
  8010. (when (search-forward l nil lkend)
  8011. (goto-char (match-beginning 0))
  8012. (org-open-at-point)))
  8013. ;; This is an internal link, widen the buffer
  8014. (switch-to-buffer-other-window buffer)
  8015. (widen)
  8016. (goto-char marker)
  8017. (when (search-forward l nil lkend)
  8018. (goto-char (match-beginning 0))
  8019. (org-open-at-point)))))
  8020. lk))
  8021. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8022. (save-excursion
  8023. (beginning-of-line 1)
  8024. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8025. (org-open-link-from-string (match-string 1)))
  8026. (t (message "No link to open here")))))
  8027. (defun org-agenda-copy-local-variable (var)
  8028. "Get a variable from a referenced buffer and install it here."
  8029. (let ((m (org-get-at-bol 'org-marker)))
  8030. (when (and m (buffer-live-p (marker-buffer m)))
  8031. (set (make-local-variable var)
  8032. (with-current-buffer (marker-buffer m)
  8033. (symbol-value var))))))
  8034. (defun org-agenda-switch-to (&optional delete-other-windows)
  8035. "Go to the Org mode file which contains the item at point.
  8036. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8037. displayed Org file fills the frame."
  8038. (interactive)
  8039. (if (and org-return-follows-link
  8040. (not (org-get-at-bol 'org-marker))
  8041. (org-in-regexp org-bracket-link-regexp))
  8042. (org-open-link-from-string (match-string 0))
  8043. (let* ((marker (or (org-get-at-bol 'org-marker)
  8044. (org-agenda-error)))
  8045. (buffer (marker-buffer marker))
  8046. (pos (marker-position marker)))
  8047. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8048. (pop-to-buffer-same-window buffer)
  8049. (when delete-other-windows (delete-other-windows))
  8050. (widen)
  8051. (goto-char pos)
  8052. (when (derived-mode-p 'org-mode)
  8053. (org-show-context 'agenda)
  8054. (run-hooks 'org-agenda-after-show-hook)))))
  8055. (defun org-agenda-goto-mouse (ev)
  8056. "Go to the Org file which contains the item at the mouse click."
  8057. (interactive "e")
  8058. (mouse-set-point ev)
  8059. (org-agenda-goto))
  8060. (defun org-agenda-show (&optional full-entry)
  8061. "Display the Org file which contains the item at point.
  8062. With prefix argument FULL-ENTRY, make the entire entry visible
  8063. if it was hidden in the outline."
  8064. (interactive "P")
  8065. (let ((win (selected-window)))
  8066. (org-agenda-goto t)
  8067. (when full-entry (org-show-entry))
  8068. (select-window win)))
  8069. (defvar org-agenda-show-window nil)
  8070. (defun org-agenda-show-and-scroll-up (&optional arg)
  8071. "Display the Org file which contains the item at point.
  8072. When called repeatedly, scroll the window that is displaying the buffer.
  8073. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  8074. `outline-show-subtree'
  8075. to display the item, so that drawers and logbooks stay folded."
  8076. (interactive "P")
  8077. (let ((win (selected-window)))
  8078. (if (and (window-live-p org-agenda-show-window)
  8079. (eq this-command last-command))
  8080. (progn
  8081. (select-window org-agenda-show-window)
  8082. (ignore-errors (scroll-up)))
  8083. (org-agenda-goto t)
  8084. (if arg (org-show-entry) (outline-show-subtree))
  8085. (setq org-agenda-show-window (selected-window)))
  8086. (select-window win)))
  8087. (defun org-agenda-show-scroll-down ()
  8088. "Scroll down the window showing the agenda."
  8089. (interactive)
  8090. (let ((win (selected-window)))
  8091. (when (window-live-p org-agenda-show-window)
  8092. (select-window org-agenda-show-window)
  8093. (ignore-errors (scroll-down))
  8094. (select-window win))))
  8095. (defun org-agenda-show-1 (&optional more)
  8096. "Display the Org file which contains the item at point.
  8097. The prefix arg selects the amount of information to display:
  8098. 0 hide the subtree
  8099. 1 just show the entry according to defaults.
  8100. 2 show the children view
  8101. 3 show the subtree view
  8102. 4 show the entire subtree and any LOGBOOK drawers
  8103. 5 show the entire subtree and any drawers
  8104. With prefix argument FULL-ENTRY, make the entire entry visible
  8105. if it was hidden in the outline."
  8106. (interactive "p")
  8107. (let ((win (selected-window)))
  8108. (org-agenda-goto t)
  8109. (org-back-to-heading)
  8110. (set-window-start (selected-window) (point-at-bol))
  8111. (cond
  8112. ((= more 0)
  8113. (outline-hide-subtree)
  8114. (save-excursion
  8115. (org-back-to-heading)
  8116. (run-hook-with-args 'org-cycle-hook 'folded))
  8117. (message "Remote: FOLDED"))
  8118. ((and (called-interactively-p 'any) (= more 1))
  8119. (message "Remote: show with default settings"))
  8120. ((= more 2)
  8121. (outline-show-entry)
  8122. (org-show-children)
  8123. (save-excursion
  8124. (org-back-to-heading)
  8125. (run-hook-with-args 'org-cycle-hook 'children))
  8126. (message "Remote: CHILDREN"))
  8127. ((= more 3)
  8128. (outline-show-subtree)
  8129. (save-excursion
  8130. (org-back-to-heading)
  8131. (run-hook-with-args 'org-cycle-hook 'subtree))
  8132. (message "Remote: SUBTREE"))
  8133. ((= more 4)
  8134. (outline-show-subtree)
  8135. (save-excursion
  8136. (org-back-to-heading)
  8137. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8138. (message "Remote: SUBTREE AND LOGBOOK"))
  8139. ((> more 4)
  8140. (outline-show-subtree)
  8141. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8142. (select-window win)))
  8143. (defvar org-agenda-cycle-counter nil)
  8144. (defun org-agenda-cycle-show (&optional n)
  8145. "Show the current entry in another window, with default settings.
  8146. Default settings are taken from `org-show-context-detail'. When
  8147. use repeatedly in immediate succession, the remote entry will
  8148. cycle through visibility
  8149. children -> subtree -> folded
  8150. When called with a numeric prefix arg, that arg will be passed through to
  8151. `org-agenda-show-1'. For the interpretation of that argument, see the
  8152. docstring of `org-agenda-show-1'."
  8153. (interactive "P")
  8154. (if (integerp n)
  8155. (setq org-agenda-cycle-counter n)
  8156. (if (not (eq last-command this-command))
  8157. (setq org-agenda-cycle-counter 1)
  8158. (if (equal org-agenda-cycle-counter 0)
  8159. (setq org-agenda-cycle-counter 2)
  8160. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8161. (if (> org-agenda-cycle-counter 3)
  8162. (setq org-agenda-cycle-counter 0)))))
  8163. (org-agenda-show-1 org-agenda-cycle-counter))
  8164. (defun org-agenda-recenter (arg)
  8165. "Display the Org file which contains the item at point and recenter."
  8166. (interactive "P")
  8167. (let ((win (selected-window)))
  8168. (org-agenda-goto t)
  8169. (recenter arg)
  8170. (select-window win)))
  8171. (defun org-agenda-show-mouse (ev)
  8172. "Display the Org file which contains the item at the mouse click."
  8173. (interactive "e")
  8174. (mouse-set-point ev)
  8175. (org-agenda-show))
  8176. (defun org-agenda-check-no-diary ()
  8177. "Check if the entry is a diary link and abort if yes."
  8178. (if (org-get-at-bol 'org-agenda-diary-link)
  8179. (org-agenda-error)))
  8180. (defun org-agenda-error ()
  8181. "Throw an error when a command is not allowed in the agenda."
  8182. (user-error "Command not allowed in this line"))
  8183. (defun org-agenda-tree-to-indirect-buffer (arg)
  8184. "Show the subtree corresponding to the current entry in an indirect buffer.
  8185. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8186. With a numerical prefix ARG, go up to this level and then take that tree.
  8187. With a negative numeric ARG, go up by this number of levels.
  8188. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8189. i.e. don't use
  8190. the dedicated frame."
  8191. (interactive "P")
  8192. (if current-prefix-arg
  8193. (org-agenda-do-tree-to-indirect-buffer arg)
  8194. (let ((agenda-buffer (buffer-name))
  8195. (agenda-window (selected-window))
  8196. (indirect-window
  8197. (and org-last-indirect-buffer
  8198. (get-buffer-window org-last-indirect-buffer))))
  8199. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8200. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8201. (eq org-indirect-buffer-display 'dedicated-frame))
  8202. (unwind-protect
  8203. (unless (and indirect-window (window-live-p indirect-window))
  8204. (setq indirect-window (split-window agenda-window)))
  8205. (and indirect-window (select-window indirect-window))
  8206. (switch-to-buffer org-last-indirect-buffer :norecord)
  8207. (fit-window-to-buffer indirect-window)))
  8208. (select-window (get-buffer-window agenda-buffer))
  8209. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8210. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8211. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8212. (org-agenda-check-no-diary)
  8213. (let* ((marker (or (org-get-at-bol 'org-marker)
  8214. (org-agenda-error)))
  8215. (buffer (marker-buffer marker))
  8216. (pos (marker-position marker)))
  8217. (with-current-buffer buffer
  8218. (save-excursion
  8219. (goto-char pos)
  8220. (funcall 'org-tree-to-indirect-buffer arg)))))
  8221. (defvar org-last-heading-marker (make-marker)
  8222. "Marker pointing to the headline that last changed its TODO state
  8223. by a remote command from the agenda.")
  8224. (defun org-agenda-todo-nextset ()
  8225. "Switch TODO entry to next sequence."
  8226. (interactive)
  8227. (org-agenda-todo 'nextset))
  8228. (defun org-agenda-todo-previousset ()
  8229. "Switch TODO entry to previous sequence."
  8230. (interactive)
  8231. (org-agenda-todo 'previousset))
  8232. (defun org-agenda-todo (&optional arg)
  8233. "Cycle TODO state of line at point, also in Org file.
  8234. This changes the line at point, all other lines in the agenda referring to
  8235. the same tree node, and the headline of the tree node in the Org file."
  8236. (interactive "P")
  8237. (org-agenda-check-no-diary)
  8238. (let* ((col (current-column))
  8239. (marker (or (org-get-at-bol 'org-marker)
  8240. (org-agenda-error)))
  8241. (buffer (marker-buffer marker))
  8242. (pos (marker-position marker))
  8243. (hdmarker (org-get-at-bol 'org-hd-marker))
  8244. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8245. (inhibit-read-only t)
  8246. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8247. (org-with-remote-undo buffer
  8248. (with-current-buffer buffer
  8249. (widen)
  8250. (goto-char pos)
  8251. (org-show-context 'agenda)
  8252. (let ((current-prefix-arg arg))
  8253. (call-interactively 'org-todo))
  8254. (and (bolp) (forward-char 1))
  8255. (setq newhead (org-get-heading))
  8256. (when (and (bound-and-true-p
  8257. org-agenda-headline-snapshot-before-repeat)
  8258. (not (equal org-agenda-headline-snapshot-before-repeat
  8259. newhead))
  8260. todayp)
  8261. (setq newhead org-agenda-headline-snapshot-before-repeat
  8262. just-one t))
  8263. (save-excursion
  8264. (org-back-to-heading)
  8265. (move-marker org-last-heading-marker (point))))
  8266. (beginning-of-line 1)
  8267. (save-window-excursion
  8268. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8269. (when (bound-and-true-p org-clock-out-when-done)
  8270. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8271. newhead)
  8272. (org-agenda-unmark-clocking-task))
  8273. (org-move-to-column col)
  8274. (org-agenda-mark-clocking-task))))
  8275. (defun org-agenda-add-note (&optional arg)
  8276. "Add a time-stamped note to the entry at point."
  8277. (interactive "P")
  8278. (org-agenda-check-no-diary)
  8279. (let* ((marker (or (org-get-at-bol 'org-marker)
  8280. (org-agenda-error)))
  8281. (buffer (marker-buffer marker))
  8282. (pos (marker-position marker))
  8283. (hdmarker (org-get-at-bol 'org-hd-marker))
  8284. (inhibit-read-only t))
  8285. (with-current-buffer buffer
  8286. (widen)
  8287. (goto-char pos)
  8288. (org-show-context 'agenda)
  8289. (org-add-note))))
  8290. (defun org-agenda-change-all-lines (newhead hdmarker
  8291. &optional fixface just-this)
  8292. "Change all lines in the agenda buffer which match HDMARKER.
  8293. The new content of the line will be NEWHEAD (as modified by
  8294. `org-agenda-format-item'). HDMARKER is checked with
  8295. `equal' against all `org-hd-marker' text properties in the file.
  8296. If FIXFACE is non-nil, the face of each item is modified according to
  8297. the new TODO state.
  8298. If JUST-THIS is non-nil, change just the current line, not all.
  8299. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8300. (let* ((inhibit-read-only t)
  8301. (line (org-current-line))
  8302. (org-agenda-buffer (current-buffer))
  8303. (thetags (with-current-buffer (marker-buffer hdmarker)
  8304. (org-with-wide-buffer
  8305. (goto-char hdmarker)
  8306. (org-get-tags-at))))
  8307. props m pl undone-face done-face finish new dotime level cat tags)
  8308. (save-excursion
  8309. (goto-char (point-max))
  8310. (beginning-of-line 1)
  8311. (while (not finish)
  8312. (setq finish (bobp))
  8313. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8314. (or (not just-this) (= (org-current-line) line))
  8315. (equal m hdmarker))
  8316. (setq props (text-properties-at (point))
  8317. dotime (org-get-at-bol 'dotime)
  8318. cat (org-get-at-eol 'org-category 1)
  8319. level (org-get-at-bol 'level)
  8320. tags thetags
  8321. new
  8322. (let ((org-prefix-format-compiled
  8323. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8324. org-prefix-format-compiled))
  8325. (extra (org-get-at-bol 'extra)))
  8326. (with-current-buffer (marker-buffer hdmarker)
  8327. (org-with-wide-buffer
  8328. (org-agenda-format-item extra newhead level cat tags dotime))))
  8329. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8330. undone-face (org-get-at-bol 'undone-face)
  8331. done-face (org-get-at-bol 'done-face))
  8332. (beginning-of-line 1)
  8333. (cond
  8334. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8335. ((looking-at ".*")
  8336. ;; When replacing the whole line, preserve bulk mark
  8337. ;; overlay, if any.
  8338. (let ((mark (catch :overlay
  8339. (dolist (o (overlays-in (point) (+ 2 (point))))
  8340. (when (eq (overlay-get o 'type)
  8341. 'org-marked-entry-overlay)
  8342. (throw :overlay o))))))
  8343. (replace-match new t t)
  8344. (beginning-of-line)
  8345. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8346. (add-text-properties (point-at-bol) (point-at-eol) props)
  8347. (when fixface
  8348. (add-text-properties
  8349. (point-at-bol) (point-at-eol)
  8350. (list 'face
  8351. (if org-last-todo-state-is-todo
  8352. undone-face done-face))))
  8353. (org-agenda-highlight-todo 'line)
  8354. (beginning-of-line 1))
  8355. (t (error "Line update did not work")))
  8356. (save-restriction
  8357. (narrow-to-region (point-at-bol) (point-at-eol))
  8358. (org-agenda-finalize)))
  8359. (beginning-of-line 0)))))
  8360. (defun org-agenda-align-tags (&optional line)
  8361. "Align all tags in agenda items to `org-agenda-tags-column'."
  8362. (let ((inhibit-read-only t)
  8363. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8364. (- (window-text-width))
  8365. org-agenda-tags-column))
  8366. l c)
  8367. (save-excursion
  8368. (goto-char (if line (point-at-bol) (point-min)))
  8369. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8370. (if line (point-at-eol) nil) t)
  8371. (add-text-properties
  8372. (match-beginning 2) (match-end 2)
  8373. (list 'face (delq nil (let ((prop (get-text-property
  8374. (match-beginning 2) 'face)))
  8375. (or (listp prop) (setq prop (list prop)))
  8376. (if (memq 'org-tag prop)
  8377. prop
  8378. (cons 'org-tag prop))))))
  8379. (setq l (- (match-end 2) (match-beginning 2))
  8380. c (if (< org-agenda-tags-column 0)
  8381. (- (abs org-agenda-tags-column) l)
  8382. org-agenda-tags-column))
  8383. (delete-region (match-beginning 1) (match-end 1))
  8384. (goto-char (match-beginning 1))
  8385. (insert (org-add-props
  8386. (make-string (max 1 (- c (current-column))) ?\ )
  8387. (plist-put (copy-sequence (text-properties-at (point)))
  8388. 'face nil))))
  8389. (goto-char (point-min))
  8390. (org-font-lock-add-tag-faces (point-max)))))
  8391. (defun org-agenda-priority-up ()
  8392. "Increase the priority of line at point, also in Org file."
  8393. (interactive)
  8394. (org-agenda-priority 'up))
  8395. (defun org-agenda-priority-down ()
  8396. "Decrease the priority of line at point, also in Org file."
  8397. (interactive)
  8398. (org-agenda-priority 'down))
  8399. (defun org-agenda-priority (&optional force-direction)
  8400. "Set the priority of line at point, also in Org file.
  8401. This changes the line at point, all other lines in the agenda referring to
  8402. the same tree node, and the headline of the tree node in the Org file.
  8403. Called with a universal prefix arg, show the priority instead of setting it."
  8404. (interactive "P")
  8405. (if (equal force-direction '(4))
  8406. (org-show-priority)
  8407. (unless org-enable-priority-commands
  8408. (error "Priority commands are disabled"))
  8409. (org-agenda-check-no-diary)
  8410. (let* ((col (current-column))
  8411. (marker (or (org-get-at-bol 'org-marker)
  8412. (org-agenda-error)))
  8413. (hdmarker (org-get-at-bol 'org-hd-marker))
  8414. (buffer (marker-buffer hdmarker))
  8415. (pos (marker-position hdmarker))
  8416. (inhibit-read-only t)
  8417. newhead)
  8418. (org-with-remote-undo buffer
  8419. (with-current-buffer buffer
  8420. (widen)
  8421. (goto-char pos)
  8422. (org-show-context 'agenda)
  8423. (funcall 'org-priority force-direction)
  8424. (end-of-line 1)
  8425. (setq newhead (org-get-heading)))
  8426. (org-agenda-change-all-lines newhead hdmarker)
  8427. (org-move-to-column col)))))
  8428. ;; FIXME: should fix the tags property of the agenda line.
  8429. (defun org-agenda-set-tags (&optional tag onoff)
  8430. "Set tags for the current headline."
  8431. (interactive)
  8432. (org-agenda-check-no-diary)
  8433. (if (and (org-region-active-p) (called-interactively-p 'any))
  8434. (call-interactively 'org-change-tag-in-region)
  8435. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8436. (org-agenda-error)))
  8437. (buffer (marker-buffer hdmarker))
  8438. (pos (marker-position hdmarker))
  8439. (inhibit-read-only t)
  8440. newhead)
  8441. (org-with-remote-undo buffer
  8442. (with-current-buffer buffer
  8443. (widen)
  8444. (goto-char pos)
  8445. (org-show-context 'agenda)
  8446. (if tag
  8447. (org-toggle-tag tag onoff)
  8448. (call-interactively 'org-set-tags))
  8449. (end-of-line 1)
  8450. (setq newhead (org-get-heading)))
  8451. (org-agenda-change-all-lines newhead hdmarker)
  8452. (beginning-of-line 1)))))
  8453. (defun org-agenda-set-property ()
  8454. "Set a property for the current headline."
  8455. (interactive)
  8456. (org-agenda-check-no-diary)
  8457. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8458. (org-agenda-error)))
  8459. (buffer (marker-buffer hdmarker))
  8460. (pos (marker-position hdmarker))
  8461. (inhibit-read-only t)
  8462. newhead)
  8463. (org-with-remote-undo buffer
  8464. (with-current-buffer buffer
  8465. (widen)
  8466. (goto-char pos)
  8467. (org-show-context 'agenda)
  8468. (call-interactively 'org-set-property)))))
  8469. (defun org-agenda-set-effort ()
  8470. "Set the effort property for the current headline."
  8471. (interactive)
  8472. (org-agenda-check-no-diary)
  8473. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8474. (org-agenda-error)))
  8475. (buffer (marker-buffer hdmarker))
  8476. (pos (marker-position hdmarker))
  8477. (inhibit-read-only t)
  8478. newhead)
  8479. (org-with-remote-undo buffer
  8480. (with-current-buffer buffer
  8481. (widen)
  8482. (goto-char pos)
  8483. (org-show-context 'agenda)
  8484. (call-interactively 'org-set-effort)
  8485. (end-of-line 1)
  8486. (setq newhead (org-get-heading)))
  8487. (org-agenda-change-all-lines newhead hdmarker))))
  8488. (defun org-agenda-toggle-archive-tag ()
  8489. "Toggle the archive tag for the current entry."
  8490. (interactive)
  8491. (org-agenda-check-no-diary)
  8492. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8493. (org-agenda-error)))
  8494. (buffer (marker-buffer hdmarker))
  8495. (pos (marker-position hdmarker))
  8496. (inhibit-read-only t)
  8497. newhead)
  8498. (org-with-remote-undo buffer
  8499. (with-current-buffer buffer
  8500. (widen)
  8501. (goto-char pos)
  8502. (org-show-context 'agenda)
  8503. (call-interactively 'org-toggle-archive-tag)
  8504. (end-of-line 1)
  8505. (setq newhead (org-get-heading)))
  8506. (org-agenda-change-all-lines newhead hdmarker)
  8507. (beginning-of-line 1))))
  8508. (defun org-agenda-do-date-later (arg)
  8509. (interactive "P")
  8510. (cond
  8511. ((or (equal arg '(16))
  8512. (memq last-command
  8513. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8514. (setq this-command 'org-agenda-date-later-minutes)
  8515. (org-agenda-date-later-minutes 1))
  8516. ((or (equal arg '(4))
  8517. (memq last-command
  8518. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8519. (setq this-command 'org-agenda-date-later-hours)
  8520. (org-agenda-date-later-hours 1))
  8521. (t
  8522. (org-agenda-date-later (prefix-numeric-value arg)))))
  8523. (defun org-agenda-do-date-earlier (arg)
  8524. (interactive "P")
  8525. (cond
  8526. ((or (equal arg '(16))
  8527. (memq last-command
  8528. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8529. (setq this-command 'org-agenda-date-earlier-minutes)
  8530. (org-agenda-date-earlier-minutes 1))
  8531. ((or (equal arg '(4))
  8532. (memq last-command
  8533. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8534. (setq this-command 'org-agenda-date-earlier-hours)
  8535. (org-agenda-date-earlier-hours 1))
  8536. (t
  8537. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8538. (defun org-agenda-date-later (arg &optional what)
  8539. "Change the date of this item to ARG day(s) later."
  8540. (interactive "p")
  8541. (org-agenda-check-type t 'agenda)
  8542. (org-agenda-check-no-diary)
  8543. (let* ((marker (or (org-get-at-bol 'org-marker)
  8544. (org-agenda-error)))
  8545. (buffer (marker-buffer marker))
  8546. (pos (marker-position marker))
  8547. cdate today)
  8548. (org-with-remote-undo buffer
  8549. (with-current-buffer buffer
  8550. (widen)
  8551. (goto-char pos)
  8552. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8553. (when (and org-agenda-move-date-from-past-immediately-to-today
  8554. (equal arg 1)
  8555. (or (not what) (eq what 'day))
  8556. (not (save-match-data (org-at-date-range-p))))
  8557. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8558. cdate (calendar-absolute-from-gregorian
  8559. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8560. today (org-today))
  8561. (if (> today cdate)
  8562. ;; immediately shift to today
  8563. (setq arg (- today cdate))))
  8564. (org-timestamp-change arg (or what 'day))
  8565. (when (and (org-at-date-range-p)
  8566. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8567. (let ((end org-last-changed-timestamp))
  8568. (org-timestamp-change arg (or what 'day))
  8569. (setq org-last-changed-timestamp
  8570. (concat org-last-changed-timestamp "--" end)))))
  8571. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8572. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8573. (defun org-agenda-date-earlier (arg &optional what)
  8574. "Change the date of this item to ARG day(s) earlier."
  8575. (interactive "p")
  8576. (org-agenda-date-later (- arg) what))
  8577. (defun org-agenda-date-later-minutes (arg)
  8578. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8579. (interactive "p")
  8580. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8581. (org-agenda-date-later arg 'minute))
  8582. (defun org-agenda-date-earlier-minutes (arg)
  8583. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8584. (interactive "p")
  8585. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8586. (org-agenda-date-earlier arg 'minute))
  8587. (defun org-agenda-date-later-hours (arg)
  8588. "Change the time of this item, in hour steps."
  8589. (interactive "p")
  8590. (org-agenda-date-later arg 'hour))
  8591. (defun org-agenda-date-earlier-hours (arg)
  8592. "Change the time of this item, in hour steps."
  8593. (interactive "p")
  8594. (org-agenda-date-earlier arg 'hour))
  8595. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8596. "Show new date stamp via text properties."
  8597. ;; We use text properties to make this undoable
  8598. (let ((inhibit-read-only t))
  8599. (setq stamp (concat prefix " => " stamp " "))
  8600. (save-excursion
  8601. (goto-char (point-max))
  8602. (while (not (bobp))
  8603. (when (equal marker (org-get-at-bol 'org-marker))
  8604. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8605. (org-move-to-column (- (window-width) (length stamp)) t)
  8606. (add-text-properties
  8607. (1- (point)) (point-at-eol)
  8608. (list 'display (org-add-props stamp nil
  8609. 'face '(secondary-selection default))))
  8610. (beginning-of-line 1))
  8611. (beginning-of-line 0)))))
  8612. (defun org-agenda-date-prompt (arg)
  8613. "Change the date of this item. Date is prompted for, with default today.
  8614. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8615. be used to request time specification in the time stamp."
  8616. (interactive "P")
  8617. (org-agenda-check-type t 'agenda)
  8618. (org-agenda-check-no-diary)
  8619. (let* ((marker (or (org-get-at-bol 'org-marker)
  8620. (org-agenda-error)))
  8621. (buffer (marker-buffer marker))
  8622. (pos (marker-position marker)))
  8623. (org-with-remote-undo buffer
  8624. (with-current-buffer buffer
  8625. (widen)
  8626. (goto-char pos)
  8627. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8628. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8629. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8630. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8631. (defun org-agenda-schedule (arg &optional time)
  8632. "Schedule the item at point.
  8633. ARG is passed through to `org-schedule'."
  8634. (interactive "P")
  8635. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8636. (org-agenda-check-no-diary)
  8637. (let* ((marker (or (org-get-at-