org-agenda.el 390 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2017 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'org)
  43. (require 'org-macs)
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-columns-remove-overlays "org-colview" ())
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-agenda-columns "org-colview" ())
  74. (declare-function org-add-archive-files "org-archive" (files))
  75. (declare-function org-capture "org-capture" (&optional goto keys))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task)
  78. (defvar org-current-tag-alist)
  79. (defvar org-mobile-force-id-on-agenda-items)
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. \\='((ps-print-color-p \\='black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in a temporary buffer before writing the agenda to an export file.
  143. A useful function for this hook is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which is the default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style nil
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header."
  199. :group 'org-agenda-export
  200. :group 'org-export-html
  201. :type '(choice
  202. (const nil)
  203. (string)))
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const timestamp-up) (const timestamp-down)
  216. (const scheduled-up) (const scheduled-down)
  217. (const deadline-up) (const deadline-down)
  218. (const ts-up) (const ts-down)
  219. (const tsia-up) (const tsia-down)
  220. (const category-keep) (const category-up) (const category-down)
  221. (const tag-down) (const tag-up)
  222. (const priority-up) (const priority-down)
  223. (const todo-state-up) (const todo-state-down)
  224. (const effort-up) (const effort-down)
  225. (const habit-up) (const habit-down)
  226. (const alpha-up) (const alpha-down)
  227. (const user-defined-up) (const user-defined-down))
  228. "Sorting choices.")
  229. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  230. ;; the new variable `org-agenda-tag-filter-preset'.
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  233. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  234. "List of types searched for when creating the daily/weekly agenda.
  235. This variable is a list of symbols that controls the types of
  236. items that appear in the daily/weekly agenda. Allowed symbols in this
  237. list are are
  238. :timestamp List items containing a date stamp or date range matching
  239. the selected date. This includes sexp entries in angular
  240. brackets.
  241. :sexp List entries resulting from plain diary-like sexps.
  242. :deadline List deadline due on that date. When the date is today,
  243. also list any deadlines past due, or due within
  244. `org-deadline-warning-days'. `:deadline' must appear before
  245. `:scheduled' if the setting of
  246. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  247. any effect.
  248. :deadline* Same as above, but only include the deadline if it has an
  249. hour specification as [h]h:mm.
  250. :scheduled List all items which are scheduled for the given date.
  251. The diary for *today* also contains items which were
  252. scheduled earlier and are not yet marked DONE.
  253. :scheduled* Same as above, but only include the scheduled item if it
  254. has an hour specification as [h]h:mm.
  255. By default, all four non-starred types are turned on.
  256. When :scheduled* or :deadline* are included, :schedule or :deadline
  257. will be ignored.
  258. Never set this variable globally using `setq', because then it
  259. will apply to all future agenda commands. Instead, bind it with
  260. `let' to scope it dynamically into the agenda-constructing
  261. command. A good way to set it is through options in
  262. `org-agenda-custom-commands'. For a more flexible (though
  263. somewhat less efficient) way of determining what is included in
  264. the daily/weekly agenda, see `org-agenda-skip-function'.")
  265. (defconst org-agenda-custom-commands-local-options
  266. `(repeat :tag "Local settings for this command. Remember to quote values"
  267. (choice :tag "Setting"
  268. (list :tag "Heading for this block"
  269. (const org-agenda-overriding-header)
  270. (string :tag "Headline"))
  271. (list :tag "Files to be searched"
  272. (const org-agenda-files)
  273. (list
  274. (const :format "" quote)
  275. (repeat (file))))
  276. (list :tag "Sorting strategy"
  277. (const org-agenda-sorting-strategy)
  278. (list
  279. (const :format "" quote)
  280. (repeat
  281. ,org-sorting-choice)))
  282. (list :tag "Prefix format"
  283. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  284. (string))
  285. (list :tag "Number of days in agenda"
  286. (const org-agenda-span)
  287. (choice (const :tag "Day" day)
  288. (const :tag "Week" week)
  289. (const :tag "Fortnight" fortnight)
  290. (const :tag "Month" month)
  291. (const :tag "Year" year)
  292. (integer :tag "Custom")))
  293. (list :tag "Fixed starting date"
  294. (const org-agenda-start-day)
  295. (string :value "2007-11-01"))
  296. (list :tag "Start on day of week"
  297. (const org-agenda-start-on-weekday)
  298. (choice :value 1
  299. (const :tag "Today" nil)
  300. (integer :tag "Weekday No.")))
  301. (list :tag "Include data from diary"
  302. (const org-agenda-include-diary)
  303. (boolean))
  304. (list :tag "Deadline Warning days"
  305. (const org-deadline-warning-days)
  306. (integer :value 1))
  307. (list :tag "Category filter preset"
  308. (const org-agenda-category-filter-preset)
  309. (list
  310. (const :format "" quote)
  311. (repeat
  312. (string :tag "+category or -category"))))
  313. (list :tag "Tags filter preset"
  314. (const org-agenda-tag-filter-preset)
  315. (list
  316. (const :format "" quote)
  317. (repeat
  318. (string :tag "+tag or -tag"))))
  319. (list :tag "Effort filter preset"
  320. (const org-agenda-effort-filter-preset)
  321. (list
  322. (const :format "" quote)
  323. (repeat
  324. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  325. (list :tag "Regexp filter preset"
  326. (const org-agenda-regexp-filter-preset)
  327. (list
  328. (const :format "" quote)
  329. (repeat
  330. (string :tag "+regexp or -regexp"))))
  331. (list :tag "Set daily/weekly entry types"
  332. (const org-agenda-entry-types)
  333. (list
  334. (const :format "" quote)
  335. (set :greedy t :value ,org-agenda-entry-types
  336. (const :deadline)
  337. (const :scheduled)
  338. (const :deadline*)
  339. (const :scheduled*)
  340. (const :timestamp)
  341. (const :sexp))))
  342. (list :tag "Standard skipping condition"
  343. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  344. (const org-agenda-skip-function)
  345. (list
  346. (const :format "" quote)
  347. (list
  348. (choice
  349. :tag "Skipping range"
  350. (const :tag "Skip entry" org-agenda-skip-entry-if)
  351. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  352. (repeat :inline t :tag "Conditions for skipping"
  353. (choice
  354. :tag "Condition type"
  355. (list :tag "Regexp matches" :inline t
  356. (const :format "" 'regexp)
  357. (regexp))
  358. (list :tag "Regexp does not match" :inline t
  359. (const :format "" 'notregexp)
  360. (regexp))
  361. (list :tag "TODO state is" :inline t
  362. (const 'todo)
  363. (choice
  364. (const :tag "Any not-done state" 'todo)
  365. (const :tag "Any done state" 'done)
  366. (const :tag "Any state" 'any)
  367. (list :tag "Keyword list"
  368. (const :format "" quote)
  369. (repeat (string :tag "Keyword")))))
  370. (list :tag "TODO state is not" :inline t
  371. (const 'nottodo)
  372. (choice
  373. (const :tag "Any not-done state" 'todo)
  374. (const :tag "Any done state" 'done)
  375. (const :tag "Any state" 'any)
  376. (list :tag "Keyword list"
  377. (const :format "" quote)
  378. (repeat (string :tag "Keyword")))))
  379. (const :tag "scheduled" 'scheduled)
  380. (const :tag "not scheduled" 'notscheduled)
  381. (const :tag "deadline" 'deadline)
  382. (const :tag "no deadline" 'notdeadline)
  383. (const :tag "timestamp" 'timestamp)
  384. (const :tag "no timestamp" 'nottimestamp))))))
  385. (list :tag "Non-standard skipping condition"
  386. :value (org-agenda-skip-function)
  387. (const org-agenda-skip-function)
  388. (sexp :tag "Function or form (quoted!)"))
  389. (list :tag "Any variable"
  390. (variable :tag "Variable")
  391. (sexp :tag "Value (sexp)"))))
  392. "Selection of examples for agenda command settings.
  393. This will be spliced into the custom type of
  394. `org-agenda-custom-commands'.")
  395. (defcustom org-agenda-custom-commands
  396. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  397. "Custom commands for the agenda.
  398. \\<org-mode-map>
  399. These commands will be offered on the splash screen displayed by the
  400. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  401. (key desc type match settings files)
  402. key The key (one or more characters as a string) to be associated
  403. with the command.
  404. desc A description of the command, when omitted or nil, a default
  405. description is built using MATCH.
  406. type The command type, any of the following symbols:
  407. agenda The daily/weekly agenda.
  408. todo Entries with a specific TODO keyword, in all agenda files.
  409. search Entries containing search words entry or headline.
  410. tags Tags/Property/TODO match in all agenda files.
  411. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  412. todo-tree Sparse tree of specific TODO keyword in *current* file.
  413. tags-tree Sparse tree with all tags matches in *current* file.
  414. occur-tree Occur sparse tree for *current* file.
  415. ... A user-defined function.
  416. match What to search for:
  417. - a single keyword for TODO keyword searches
  418. - a tags match expression for tags searches
  419. - a word search expression for text searches.
  420. - a regular expression for occur searches
  421. For all other commands, this should be the empty string.
  422. settings A list of option settings, similar to that in a let form, so like
  423. this: ((opt1 val1) (opt2 val2) ...). The values will be
  424. evaluated at the moment of execution, so quote them when needed.
  425. files A list of files to write the produced agenda buffer to with
  426. the command `org-store-agenda-views'.
  427. If a file name ends in \".html\", an HTML version of the buffer
  428. is written out. If it ends in \".ps\", a postscript version is
  429. produced. Otherwise, only the plain text is written to the file.
  430. You can also define a set of commands, to create a composite agenda buffer.
  431. In this case, an entry looks like this:
  432. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  433. where
  434. desc A description string to be displayed in the dispatcher menu.
  435. cmd An agenda command, similar to the above. However, tree commands
  436. are not allowed, but instead you can get agenda and global todo list.
  437. So valid commands for a set are:
  438. (agenda \"\" settings)
  439. (alltodo \"\" settings)
  440. (stuck \"\" settings)
  441. (todo \"match\" settings files)
  442. (search \"match\" settings files)
  443. (tags \"match\" settings files)
  444. (tags-todo \"match\" settings files)
  445. Each command can carry a list of options, and another set of options can be
  446. given for the whole set of commands. Individual command options take
  447. precedence over the general options.
  448. When using several characters as key to a command, the first characters
  449. are prefix commands. For the dispatcher to display useful information, you
  450. should provide a description for the prefix, like
  451. (setq org-agenda-custom-commands
  452. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  453. (\"hl\" tags \"+HOME+Lisa\")
  454. (\"hp\" tags \"+HOME+Peter\")
  455. (\"hk\" tags \"+HOME+Kim\")))"
  456. :group 'org-agenda-custom-commands
  457. :type `(repeat
  458. (choice :value ("x" "Describe command here" tags "" nil)
  459. (list :tag "Single command"
  460. (string :tag "Access Key(s) ")
  461. (option (string :tag "Description"))
  462. (choice
  463. (const :tag "Agenda" agenda)
  464. (const :tag "TODO list" alltodo)
  465. (const :tag "Search words" search)
  466. (const :tag "Stuck projects" stuck)
  467. (const :tag "Tags/Property match (all agenda files)" tags)
  468. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  469. (const :tag "TODO keyword search (all agenda files)" todo)
  470. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  471. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  472. (const :tag "Occur tree (current buffer)" occur-tree)
  473. (sexp :tag "Other, user-defined function"))
  474. (string :tag "Match (only for some commands)")
  475. ,org-agenda-custom-commands-local-options
  476. (option (repeat :tag "Export" (file :tag "Export to"))))
  477. (list :tag "Command series, all agenda files"
  478. (string :tag "Access Key(s)")
  479. (string :tag "Description ")
  480. (repeat :tag "Component"
  481. (choice
  482. (list :tag "Agenda"
  483. (const :format "" agenda)
  484. (const :tag "" :format "" "")
  485. ,org-agenda-custom-commands-local-options)
  486. (list :tag "TODO list (all keywords)"
  487. (const :format "" alltodo)
  488. (const :tag "" :format "" "")
  489. ,org-agenda-custom-commands-local-options)
  490. (list :tag "Search words"
  491. (const :format "" search)
  492. (string :tag "Match")
  493. ,org-agenda-custom-commands-local-options)
  494. (list :tag "Stuck projects"
  495. (const :format "" stuck)
  496. (const :tag "" :format "" "")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "Tags search"
  499. (const :format "" tags)
  500. (string :tag "Match")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Tags search, TODO entries only"
  503. (const :format "" tags-todo)
  504. (string :tag "Match")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "TODO keyword search"
  507. (const :format "" todo)
  508. (string :tag "Match")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "Other, user-defined function"
  511. (symbol :tag "function")
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)))
  514. (repeat :tag "Settings for entire command set"
  515. (list (variable :tag "Any variable")
  516. (sexp :tag "Value")))
  517. (option (repeat :tag "Export" (file :tag "Export to"))))
  518. (cons :tag "Prefix key documentation"
  519. (string :tag "Access Key(s)")
  520. (string :tag "Description ")))))
  521. (defcustom org-agenda-query-register ?o
  522. "The register holding the current query string.
  523. The purpose of this is that if you construct a query string interactively,
  524. you can then use it to define a custom command."
  525. :group 'org-agenda-custom-commands
  526. :type 'character)
  527. (defcustom org-stuck-projects
  528. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  529. "How to identify stuck projects.
  530. This is a list of four items:
  531. 1. A tags/todo/property matcher string that is used to identify a project.
  532. See the manual for a description of tag and property searches.
  533. The entire tree below a headline matched by this is considered one project.
  534. 2. A list of TODO keywords identifying non-stuck projects.
  535. If the project subtree contains any headline with one of these todo
  536. keywords, the project is considered to be not stuck. If you specify
  537. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  538. 3. A list of tags identifying non-stuck projects.
  539. If the project subtree contains any headline with one of these tags,
  540. the project is considered to be not stuck. If you specify \"*\" as
  541. a tag, any tag will mark the project unstuck. Note that this is about
  542. the explicit presence of a tag somewhere in the subtree, inherited
  543. tags do not count here. If inherited tags make a project not stuck,
  544. use \"-TAG\" in the tags part of the matcher under (1.) above.
  545. 4. An arbitrary regular expression matching non-stuck projects.
  546. If the project turns out to be not stuck, search continues also in the
  547. subtree to see if any of the subtasks have project status.
  548. See also the variable `org-tags-match-list-sublevels' which applies
  549. to projects matched by this search as well.
  550. After defining this variable, you may use `\\[org-agenda-list-stuck-projects]'
  551. \(bound to `C-c a #') to produce the list."
  552. :group 'org-agenda-custom-commands
  553. :type '(list
  554. (string :tag "Tags/TODO match to identify a project")
  555. (repeat :tag "Projects are *not* stuck if they have an entry with \
  556. TODO keyword any of" (string))
  557. (repeat :tag "Projects are *not* stuck if they have an entry with \
  558. TAG being any of" (string))
  559. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  560. the subtree")))
  561. (defgroup org-agenda-skip nil
  562. "Options concerning skipping parts of agenda files."
  563. :tag "Org Agenda Skip"
  564. :group 'org-agenda)
  565. (defcustom org-agenda-skip-function-global nil
  566. "Function to be called at each match during agenda construction.
  567. If this function returns nil, the current match should not be skipped.
  568. If the function decided to skip an agenda match, is must return the
  569. buffer position from which the search should be continued.
  570. This may also be a Lisp form, which will be evaluated.
  571. This variable will be applied to every agenda match, including
  572. tags/property searches and TODO lists. So try to make the test function
  573. do its checking as efficiently as possible. To implement a skipping
  574. condition just for specific agenda commands, use the variable
  575. `org-agenda-skip-function' which can be set in the options section
  576. of custom agenda commands."
  577. :group 'org-agenda-skip
  578. :type 'sexp)
  579. (defgroup org-agenda-daily/weekly nil
  580. "Options concerning the daily/weekly agenda."
  581. :tag "Org Agenda Daily/Weekly"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-todo-list nil
  584. "Options concerning the global todo list agenda view."
  585. :tag "Org Agenda Todo List"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-match-view nil
  588. "Options concerning the general tags/property/todo match agenda view."
  589. :tag "Org Agenda Match View"
  590. :group 'org-agenda)
  591. (defgroup org-agenda-search-view nil
  592. "Options concerning the search agenda view."
  593. :tag "Org Agenda Search View"
  594. :group 'org-agenda)
  595. (defvar org-agenda-archives-mode nil
  596. "Non-nil means the agenda will include archived items.
  597. If this is the symbol `trees', trees in the selected agenda scope
  598. that are marked with the ARCHIVE tag will be included anyway. When this is
  599. t, also all archive files associated with the current selection of agenda
  600. files will be included.")
  601. (defcustom org-agenda-restriction-lock-highlight-subtree t
  602. "Non-nil means highlight the whole subtree when restriction is active.
  603. Otherwise only highlight the headline. Highlighting the whole subtree is
  604. useful to ensure no edits happen beyond the restricted region."
  605. :group 'org-agenda
  606. :type 'boolean)
  607. (defcustom org-agenda-skip-comment-trees t
  608. "Non-nil means skip trees that start with the COMMENT keyword.
  609. When nil, these trees are also scanned by agenda commands."
  610. :group 'org-agenda-skip
  611. :type 'boolean)
  612. (defcustom org-agenda-todo-list-sublevels t
  613. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  614. When nil, the sublevels of a TODO entry are not checked, resulting in
  615. potentially much shorter TODO lists."
  616. :group 'org-agenda-skip
  617. :group 'org-agenda-todo-list
  618. :type 'boolean)
  619. (defcustom org-agenda-todo-ignore-with-date nil
  620. "Non-nil means don't show entries with a date in the global todo list.
  621. You can use this if you prefer to mark mere appointments with a TODO keyword,
  622. but don't want them to show up in the TODO list.
  623. When this is set, it also covers deadlines and scheduled items, the settings
  624. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  625. will be ignored.
  626. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  627. :group 'org-agenda-skip
  628. :group 'org-agenda-todo-list
  629. :type 'boolean)
  630. (defcustom org-agenda-todo-ignore-timestamp nil
  631. "Non-nil means don't show entries with a timestamp.
  632. This applies when creating the global todo list.
  633. Valid values are:
  634. past Don't show entries for today or in the past.
  635. future Don't show entries with a timestamp in the future.
  636. The idea behind this is that if it has a future
  637. timestamp, you don't want to think about it until the
  638. date.
  639. all Don't show any entries with a timestamp in the global todo list.
  640. The idea behind this is that by setting a timestamp, you
  641. have already \"taken care\" of this item.
  642. This variable can also have an integer as a value. If positive (N),
  643. todos with a timestamp N or more days in the future will be ignored. If
  644. negative (-N), todos with a timestamp N or more days in the past will be
  645. ignored. If 0, todos with a timestamp either today or in the future will
  646. be ignored. For example, a value of -1 will exclude todos with a
  647. timestamp in the past (yesterday or earlier), while a value of 7 will
  648. exclude todos with a timestamp a week or more in the future.
  649. See also `org-agenda-todo-ignore-with-date'.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  651. to make his option also apply to the tags-todo list."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :version "24.1"
  655. :type '(choice
  656. (const :tag "Ignore future timestamp todos" future)
  657. (const :tag "Ignore past or present timestamp todos" past)
  658. (const :tag "Ignore all timestamp todos" all)
  659. (const :tag "Show timestamp todos" nil)
  660. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  661. (defcustom org-agenda-todo-ignore-scheduled nil
  662. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  663. This applies when creating the global todo list.
  664. Valid values are:
  665. past Don't show entries scheduled today or in the past.
  666. future Don't show entries scheduled in the future.
  667. The idea behind this is that by scheduling it, you don't want to
  668. think about it until the scheduled date.
  669. all Don't show any scheduled entries in the global todo list.
  670. The idea behind this is that by scheduling it, you have already
  671. \"taken care\" of this item.
  672. t Same as `all', for backward compatibility.
  673. This variable can also have an integer as a value. See
  674. `org-agenda-todo-ignore-timestamp' for more details.
  675. See also `org-agenda-todo-ignore-with-date'.
  676. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  677. to make his option also apply to the tags-todo list."
  678. :group 'org-agenda-skip
  679. :group 'org-agenda-todo-list
  680. :type '(choice
  681. (const :tag "Ignore future-scheduled todos" future)
  682. (const :tag "Ignore past- or present-scheduled todos" past)
  683. (const :tag "Ignore all scheduled todos" all)
  684. (const :tag "Ignore all scheduled todos (compatibility)" t)
  685. (const :tag "Show scheduled todos" nil)
  686. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  687. (defcustom org-agenda-todo-ignore-deadlines nil
  688. "Non-nil means ignore some deadline TODO items when making TODO list.
  689. There are different motivations for using different values, please think
  690. carefully when configuring this variable.
  691. This applies when creating the global TODO list.
  692. Valid values are:
  693. near Don't show near deadline entries. A deadline is near when it is
  694. closer than `org-deadline-warning-days' days. The idea behind this
  695. is that such items will appear in the agenda anyway.
  696. far Don't show TODO entries where a deadline has been defined, but
  697. is not going to happen anytime soon. This is useful if you want to use
  698. the TODO list to figure out what to do now.
  699. past Don't show entries with a deadline timestamp for today or in the past.
  700. future Don't show entries with a deadline timestamp in the future, not even
  701. when they become `near' ones. Use it with caution.
  702. all Ignore all TODO entries that do have a deadline.
  703. t Same as `near', for backward compatibility.
  704. This variable can also have an integer as a value. See
  705. `org-agenda-todo-ignore-timestamp' for more details.
  706. See also `org-agenda-todo-ignore-with-date'.
  707. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  708. to make his option also apply to the tags-todo list."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-todo-list
  711. :type '(choice
  712. (const :tag "Ignore near deadlines" near)
  713. (const :tag "Ignore near deadlines (compatibility)" t)
  714. (const :tag "Ignore far deadlines" far)
  715. (const :tag "Ignore all TODOs with a deadlines" all)
  716. (const :tag "Show all TODOs, even if they have a deadline" nil)
  717. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  718. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  719. "Time unit to use when possibly ignoring an agenda item.
  720. See the docstring of various `org-agenda-todo-ignore-*' options.
  721. The default is to compare time stamps using days. An item is thus
  722. considered to be in the future if it is at least one day after today.
  723. Non-nil means to compare time stamps using seconds. An item is then
  724. considered future if it has a time value later than current time."
  725. :group 'org-agenda-skip
  726. :group 'org-agenda-todo-list
  727. :version "24.4"
  728. :package-version '(Org . "8.0")
  729. :type '(choice
  730. (const :tag "Compare time with days" nil)
  731. (const :tag "Compare time with seconds" t)))
  732. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  733. "Non-nil means honor todo-list ignores options also in tags-todo search.
  734. The variables
  735. `org-agenda-todo-ignore-with-date',
  736. `org-agenda-todo-ignore-timestamp',
  737. `org-agenda-todo-ignore-scheduled',
  738. `org-agenda-todo-ignore-deadlines'
  739. make the global TODO list skip entries that have time stamps of certain
  740. kinds. If this option is set, the same options will also apply for the
  741. tags-todo search, which is the general tags/property matcher
  742. restricted to unfinished TODO entries only."
  743. :group 'org-agenda-skip
  744. :group 'org-agenda-todo-list
  745. :group 'org-agenda-match-view
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-scheduled-if-done nil
  748. "Non-nil means don't show scheduled items in agenda when they are done.
  749. This is relevant for the daily/weekly agenda, not for the TODO list. It
  750. applies only to the actual date of the scheduling. Warnings about an item
  751. with a past scheduling dates are always turned off when the item is DONE."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  756. "Non-nil means skip scheduling line if same entry shows because of deadline.
  757. In the agenda of today, an entry can show up multiple times
  758. because it is both scheduled and has a nearby deadline, and maybe
  759. a plain time stamp as well.
  760. When this variable is nil, the entry will be shown several times.
  761. When set to t, then only the deadline is shown and the fact that
  762. the entry is scheduled today or was scheduled previously is not
  763. shown.
  764. When set to the symbol `not-today', skip scheduled previously,
  765. but not scheduled today.
  766. When set to the symbol `repeated-after-deadline', skip scheduled
  767. items if they are repeated beyond the current deadline."
  768. :group 'org-agenda-skip
  769. :group 'org-agenda-daily/weekly
  770. :type '(choice
  771. (const :tag "Never" nil)
  772. (const :tag "Always" t)
  773. (const :tag "Not when scheduled today" not-today)
  774. (const :tag "When repeated past deadline" repeated-after-deadline)))
  775. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  776. "Non-nil means skip timestamp line if same entry shows because of deadline.
  777. In the agenda of today, an entry can show up multiple times
  778. because it has both a plain timestamp and has a nearby deadline.
  779. When this variable is t, then only the deadline is shown and the
  780. fact that the entry has a timestamp for or including today is not
  781. shown. When this variable is nil, the entry will be shown
  782. several times."
  783. :group 'org-agenda-skip
  784. :group 'org-agenda-daily/weekly
  785. :version "24.1"
  786. :type '(choice
  787. (const :tag "Never" nil)
  788. (const :tag "Always" t)))
  789. (defcustom org-agenda-skip-deadline-if-done nil
  790. "Non-nil means don't show deadlines when the corresponding item is done.
  791. When nil, the deadline is still shown and should give you a happy feeling.
  792. This is relevant for the daily/weekly agenda. It applies only to the
  793. actual date of the deadline. Warnings about approaching and past-due
  794. deadlines are always turned off when the item is DONE."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  799. "Non-nil means skip deadline prewarning when entry is also scheduled.
  800. This will apply on all days where a prewarning for the deadline would
  801. be shown, but not at the day when the entry is actually due. On that day,
  802. the deadline will be shown anyway.
  803. This variable may be set to nil, t, the symbol `pre-scheduled',
  804. or a number which will then give the number of days before the actual
  805. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  806. eliminates the deadline prewarning only prior to the scheduled date.
  807. This can be used in a workflow where the first showing of the deadline will
  808. trigger you to schedule it, and then you don't want to be reminded of it
  809. because you will take care of it on the day when scheduled."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Always show prewarning" nil)
  815. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  816. (const :tag "Remove prewarning if entry is scheduled" t)
  817. (integer :tag "Restart prewarning N days before deadline")))
  818. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  819. "Non-nil means skip scheduled delay when entry also has a deadline.
  820. This variable may be set to nil, t, the symbol `post-deadline',
  821. or a number which will then give the number of days after the actual
  822. scheduled date when the delay should expire. The symbol `post-deadline'
  823. eliminates the schedule delay when the date is posterior to the deadline."
  824. :group 'org-agenda-skip
  825. :group 'org-agenda-daily/weekly
  826. :version "24.4"
  827. :package-version '(Org . "8.0")
  828. :type '(choice
  829. (const :tag "Always honor delay" nil)
  830. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  831. (const :tag "Ignore delay if entry has a deadline" t)
  832. (integer :tag "Honor delay up until N days after the scheduled date")))
  833. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  834. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  835. When non-nil, after the search for timestamps has matched once in an
  836. entry, the rest of the entry will not be searched."
  837. :group 'org-agenda-skip
  838. :type 'boolean)
  839. (defcustom org-agenda-skip-timestamp-if-done nil
  840. "Non-nil means don't select item by timestamp or -range if it is DONE."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :type 'boolean)
  844. (defcustom org-agenda-dim-blocked-tasks t
  845. "Non-nil means dim blocked tasks in the agenda display.
  846. This causes some overhead during agenda construction, but if you
  847. have turned on `org-enforce-todo-dependencies',
  848. `org-enforce-todo-checkbox-dependencies', or any other blocking
  849. mechanism, this will create useful feedback in the agenda.
  850. Instead of t, this variable can also have the value `invisible'.
  851. Then blocked tasks will be invisible and only become visible when
  852. they become unblocked. An exemption to this behavior is when a task is
  853. blocked because of unchecked checkboxes below it. Since checkboxes do
  854. not show up in the agenda views, making this task invisible you remove any
  855. trace from agenda views that there is something to do. Therefore, a task
  856. that is blocked because of checkboxes will never be made invisible, it
  857. will only be dimmed."
  858. :group 'org-agenda-daily/weekly
  859. :group 'org-agenda-todo-list
  860. :version "24.3"
  861. :type '(choice
  862. (const :tag "Do not dim" nil)
  863. (const :tag "Dim to a gray face" t)
  864. (const :tag "Make invisible" invisible)))
  865. (defgroup org-agenda-startup nil
  866. "Options concerning initial settings in the Agenda in Org Mode."
  867. :tag "Org Agenda Startup"
  868. :group 'org-agenda)
  869. (defcustom org-agenda-menu-show-matcher t
  870. "Non-nil means show the match string in the agenda dispatcher menu.
  871. When nil, the matcher string is not shown, but is put into the help-echo
  872. property so than moving the mouse over the command shows it.
  873. Setting it to nil is good if matcher strings are very long and/or if
  874. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  875. :group 'org-agenda
  876. :version "24.1"
  877. :type 'boolean)
  878. (defcustom org-agenda-menu-two-columns nil
  879. "Non-nil means, use two columns to show custom commands in the dispatcher.
  880. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  881. to nil."
  882. :group 'org-agenda
  883. :version "24.1"
  884. :type 'boolean)
  885. (defcustom org-agenda-finalize-hook nil
  886. "Hook run just before displaying an agenda buffer.
  887. The buffer is still writable when the hook is called.
  888. You can modify some of the buffer substrings but you should be
  889. extra careful not to modify the text properties of the agenda
  890. headlines as the agenda display heavily relies on them."
  891. :group 'org-agenda-startup
  892. :type 'hook)
  893. (defcustom org-agenda-mouse-1-follows-link nil
  894. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  895. A longer mouse click will still set point. Needs to be set
  896. before org.el is loaded."
  897. :group 'org-agenda-startup
  898. :type 'boolean)
  899. (defcustom org-agenda-start-with-follow-mode nil
  900. "The initial value of follow mode in a newly created agenda window."
  901. :group 'org-agenda-startup
  902. :type 'boolean)
  903. (defcustom org-agenda-follow-indirect nil
  904. "Non-nil means `org-agenda-follow-mode' displays only the
  905. current item's tree, in an indirect buffer."
  906. :group 'org-agenda
  907. :version "24.1"
  908. :type 'boolean)
  909. (defcustom org-agenda-show-outline-path t
  910. "Non-nil means show outline path in echo area after line motion."
  911. :group 'org-agenda-startup
  912. :type 'boolean)
  913. (defcustom org-agenda-start-with-entry-text-mode nil
  914. "The initial value of entry-text-mode in a newly created agenda window."
  915. :group 'org-agenda-startup
  916. :type 'boolean)
  917. (defcustom org-agenda-entry-text-maxlines 5
  918. "Number of text lines to be added when `E' is pressed in the agenda.
  919. Note that this variable only used during agenda display. To add entry text
  920. when exporting the agenda, configure the variable
  921. `org-agenda-add-entry-text-maxlines'."
  922. :group 'org-agenda
  923. :type 'integer)
  924. (defcustom org-agenda-entry-text-exclude-regexps nil
  925. "List of regular expressions to clean up entry text.
  926. The complete matches of all regular expressions in this list will be
  927. removed from entry text before it is shown in the agenda."
  928. :group 'org-agenda
  929. :type '(repeat (regexp)))
  930. (defcustom org-agenda-entry-text-leaders " > "
  931. "Text prepended to the entry text in agenda buffers."
  932. :version "24.4"
  933. :package-version '(Org . "8.0")
  934. :group 'org-agenda
  935. :type 'string)
  936. (defvar org-agenda-entry-text-cleanup-hook nil
  937. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  938. This cleanup is done in a temporary buffer, so the function may inspect and
  939. change the entire buffer.
  940. Some default stuff like drawers and scheduling/deadline dates will already
  941. have been removed when this is called, as will any matches for regular
  942. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  943. (defvar org-agenda-include-inactive-timestamps nil
  944. "Non-nil means include inactive time stamps in agenda and timeline.
  945. Dynamically scoped.")
  946. (defgroup org-agenda-windows nil
  947. "Options concerning the windows used by the Agenda in Org Mode."
  948. :tag "Org Agenda Windows"
  949. :group 'org-agenda)
  950. (defcustom org-agenda-window-setup 'reorganize-frame
  951. "How the agenda buffer should be displayed.
  952. Possible values for this option are:
  953. current-window Show agenda in the current window, keeping all other windows.
  954. other-window Use `switch-to-buffer-other-window' to display agenda.
  955. only-window Show agenda, deleting all other windows.
  956. reorganize-frame Show only two windows on the current frame, the current
  957. window and the agenda.
  958. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  959. Also, when exiting the agenda, kill that frame.
  960. See also the variable `org-agenda-restore-windows-after-quit'."
  961. :group 'org-agenda-windows
  962. :type '(choice
  963. (const current-window)
  964. (const other-frame)
  965. (const other-window)
  966. (const only-window)
  967. (const reorganize-frame)))
  968. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  969. "The min and max height of the agenda window as a fraction of frame height.
  970. The value of the variable is a cons cell with two numbers between 0 and 1.
  971. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  972. :group 'org-agenda-windows
  973. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  974. (defcustom org-agenda-restore-windows-after-quit nil
  975. "Non-nil means restore window configuration upon exiting agenda.
  976. Before the window configuration is changed for displaying the agenda,
  977. the current status is recorded. When the agenda is exited with
  978. `q' or `x' and this option is set, the old state is restored. If
  979. `org-agenda-window-setup' is `other-frame', the value of this
  980. option will be ignored."
  981. :group 'org-agenda-windows
  982. :type 'boolean)
  983. (defcustom org-agenda-span 'week
  984. "Number of days to include in overview display.
  985. Can be day, week, month, year, or any number of days.
  986. Custom commands can set this variable in the options section."
  987. :group 'org-agenda-daily/weekly
  988. :type '(choice (const :tag "Day" day)
  989. (const :tag "Week" week)
  990. (const :tag "Fortnight" fortnight)
  991. (const :tag "Month" month)
  992. (const :tag "Year" year)
  993. (integer :tag "Custom")))
  994. (defcustom org-agenda-start-on-weekday 1
  995. "Non-nil means start the overview always on the specified weekday.
  996. 0 denotes Sunday, 1 denotes Monday, etc.
  997. When nil, always start on the current day.
  998. Custom commands can set this variable in the options section."
  999. :group 'org-agenda-daily/weekly
  1000. :type '(choice (const :tag "Today" nil)
  1001. (integer :tag "Weekday No.")))
  1002. (defcustom org-agenda-show-all-dates t
  1003. "Non-nil means `org-agenda' shows every day in the selected range.
  1004. When nil, only the days which actually have entries are shown."
  1005. :group 'org-agenda-daily/weekly
  1006. :type 'boolean)
  1007. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1008. "Format string for displaying dates in the agenda.
  1009. Used by the daily/weekly agenda and by the timeline. This should be
  1010. a format string understood by `format-time-string', or a function returning
  1011. the formatted date as a string. The function must take a single argument,
  1012. a calendar-style date list like (month day year)."
  1013. :group 'org-agenda-daily/weekly
  1014. :type '(choice
  1015. (string :tag "Format string")
  1016. (function :tag "Function")))
  1017. (defun org-agenda-format-date-aligned (date)
  1018. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1019. This function makes sure that dates are aligned for easy reading."
  1020. (require 'cal-iso)
  1021. (let* ((dayname (calendar-day-name date))
  1022. (day (cadr date))
  1023. (day-of-week (calendar-day-of-week date))
  1024. (month (car date))
  1025. (monthname (calendar-month-name month))
  1026. (year (nth 2 date))
  1027. (iso-week (org-days-to-iso-week
  1028. (calendar-absolute-from-gregorian date)))
  1029. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1030. (1- year))
  1031. ((and (= month 12) (<= iso-week 1))
  1032. (1+ year))
  1033. (t year)))
  1034. (weekstring (if (= day-of-week 1)
  1035. (format " W%02d" iso-week)
  1036. "")))
  1037. (format "%-10s %2d %s %4d%s"
  1038. dayname day monthname year weekstring)))
  1039. (defcustom org-agenda-time-leading-zero nil
  1040. "Non-nil means use leading zero for military times in agenda.
  1041. For example, 9:30am would become 09:30 rather than 9:30."
  1042. :group 'org-agenda-daily/weekly
  1043. :version "24.1"
  1044. :type 'boolean)
  1045. (defcustom org-agenda-timegrid-use-ampm nil
  1046. "When set, show AM/PM style timestamps on the timegrid."
  1047. :group 'org-agenda
  1048. :version "24.1"
  1049. :type 'boolean)
  1050. (defun org-agenda-time-of-day-to-ampm (time)
  1051. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1052. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1053. (minute (substring time -2))
  1054. (ampm "am"))
  1055. (cond
  1056. ((equal hour-number 12)
  1057. (setq ampm "pm"))
  1058. ((> hour-number 12)
  1059. (setq ampm "pm")
  1060. (setq hour-number (- hour-number 12))))
  1061. (concat
  1062. (if org-agenda-time-leading-zero
  1063. (format "%02d" hour-number)
  1064. (format "%02s" (number-to-string hour-number)))
  1065. ":" minute ampm)))
  1066. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1067. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1068. (if org-agenda-timegrid-use-ampm
  1069. (org-agenda-time-of-day-to-ampm time)
  1070. time))
  1071. (defcustom org-agenda-weekend-days '(6 0)
  1072. "Which days are weekend?
  1073. These days get the special face `org-agenda-date-weekend' in the agenda
  1074. and timeline buffers."
  1075. :group 'org-agenda-daily/weekly
  1076. :type '(set :greedy t
  1077. (const :tag "Monday" 1)
  1078. (const :tag "Tuesday" 2)
  1079. (const :tag "Wednesday" 3)
  1080. (const :tag "Thursday" 4)
  1081. (const :tag "Friday" 5)
  1082. (const :tag "Saturday" 6)
  1083. (const :tag "Sunday" 0)))
  1084. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1085. "Non-nil means jump to today when moving a past date forward in time.
  1086. When using S-right in the agenda to move a a date forward, and the date
  1087. stamp currently points to the past, the first key press will move it
  1088. to today. WHen nil, just move one day forward even if the date stays
  1089. in the past."
  1090. :group 'org-agenda-daily/weekly
  1091. :version "24.1"
  1092. :type 'boolean)
  1093. (defcustom org-agenda-include-diary nil
  1094. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1095. Custom commands can set this variable in the options section."
  1096. :group 'org-agenda-daily/weekly
  1097. :type 'boolean)
  1098. (defcustom org-agenda-include-deadlines t
  1099. "If non-nil, include entries within their deadline warning period.
  1100. Custom commands can set this variable in the options section."
  1101. :group 'org-agenda-daily/weekly
  1102. :version "24.1"
  1103. :type 'boolean)
  1104. (defcustom org-agenda-show-future-repeats t
  1105. "Non-nil shows repeated entries in the future part of the agenda.
  1106. When set to the symbol `next' only the first future repeat is shown."
  1107. :group 'org-agenda-daily/weekly
  1108. :type '(choice
  1109. (const :tag "Show all repeated entries" t)
  1110. (const :tag "Show next repeated entry" next)
  1111. (const :tag "Do not show repeated entries" nil))
  1112. :version "26.1"
  1113. :package-version '(Org . "9.1")
  1114. :safe #'symbolp)
  1115. (defcustom org-agenda-prefer-last-repeat nil
  1116. "Non-nil sets date for repeated entries to their last repeat.
  1117. When nil, display SCHEDULED and DEADLINE dates at their base
  1118. date, and in today's agenda, as a reminder. Display plain
  1119. time-stamps, on the other hand, at every repeat date in the past
  1120. in addition to the base date.
  1121. When non-nil, show a repeated entry at its latest repeat date,
  1122. possibly being today even if it wasn't marked as done. This
  1123. setting is useful if you do not always mark repeated entries as
  1124. done and, yet, consider that reaching repeat date starts the task
  1125. anew.
  1126. When set to a list of strings, prefer last repeats only for
  1127. entries with these TODO keywords."
  1128. :group 'org-agenda-daily/weekly
  1129. :type '(choice
  1130. (const :tag "Prefer last repeat" t)
  1131. (const :tag "Prefer base date" nil)
  1132. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1133. (string :tag "TODO keyword")))
  1134. :version "26.1"
  1135. :package-version '(Org . "9.1")
  1136. :safe (lambda (x) (or (booleanp x) (consp x))))
  1137. (defcustom org-scheduled-past-days 10000
  1138. "Number of days to continue listing scheduled items not marked DONE.
  1139. When an item is scheduled on a date, it shows up in the agenda on
  1140. this day and will be listed until it is marked done or for the
  1141. number of days given here."
  1142. :group 'org-agenda-daily/weekly
  1143. :type 'integer)
  1144. (defcustom org-agenda-log-mode-items '(closed clock)
  1145. "List of items that should be shown in agenda log mode.
  1146. \\<org-agenda-mode-map>\
  1147. This list may contain the following symbols:
  1148. closed Show entries that have been closed on that day.
  1149. clock Show entries that have received clocked time on that day.
  1150. state Show all logged state changes.
  1151. Note that instead of changing this variable, you can also press \
  1152. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1153. the agenda to display all available LOG items temporarily."
  1154. :group 'org-agenda-daily/weekly
  1155. :type '(set :greedy t (const closed) (const clock) (const state)))
  1156. (defcustom org-agenda-clock-consistency-checks
  1157. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1158. :gap-ok-around ("4:00")
  1159. :default-face ((:background "DarkRed") (:foreground "white"))
  1160. :overlap-face nil :gap-face nil :no-end-time-face nil
  1161. :long-face nil :short-face nil)
  1162. "This is a property list, with the following keys:
  1163. :max-duration Mark clocking chunks that are longer than this time.
  1164. This is a time string like \"HH:MM\", or the number
  1165. of minutes as an integer.
  1166. :min-duration Mark clocking chunks that are shorter that this.
  1167. This is a time string like \"HH:MM\", or the number
  1168. of minutes as an integer.
  1169. :max-gap Mark gaps between clocking chunks that are longer than
  1170. this duration. A number of minutes, or a string
  1171. like \"HH:MM\".
  1172. :gap-ok-around List of times during the day which are usually not working
  1173. times. When a gap is detected, but the gap contains any
  1174. of these times, the gap is *not* reported. For example,
  1175. if this is (\"4:00\" \"13:00\") then gaps that contain
  1176. 4:00 in the morning (i.e. the night) and 13:00
  1177. (i.e. a typical lunch time) do not cause a warning.
  1178. You should have at least one time during the night in this
  1179. list, or otherwise the first task each morning will trigger
  1180. a warning because it follows a long gap.
  1181. Furthermore, the following properties can be used to define faces for
  1182. issue display.
  1183. :default-face the default face, if the specific face is undefined
  1184. :overlap-face face for overlapping clocks
  1185. :gap-face face for gaps between clocks
  1186. :no-end-time-face face for incomplete clocks
  1187. :long-face face for clock intervals that are too long
  1188. :short-face face for clock intervals that are too short"
  1189. :group 'org-agenda-daily/weekly
  1190. :group 'org-clock
  1191. :version "24.1"
  1192. :type 'plist)
  1193. (defcustom org-agenda-log-mode-add-notes t
  1194. "Non-nil means add first line of notes to log entries in agenda views.
  1195. If a log item like a state change or a clock entry is associated with
  1196. notes, the first line of these notes will be added to the entry in the
  1197. agenda display."
  1198. :group 'org-agenda-daily/weekly
  1199. :type 'boolean)
  1200. (defcustom org-agenda-start-with-log-mode nil
  1201. "The initial value of log-mode in a newly created agenda window.
  1202. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1203. explanations on the possible values."
  1204. :group 'org-agenda-startup
  1205. :group 'org-agenda-daily/weekly
  1206. :type '(choice (const :tag "Don't show log items" nil)
  1207. (const :tag "Show only log items" only)
  1208. (const :tag "Show all possible log items" clockcheck)
  1209. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1210. (choice (const :tag "Show closed log items" closed)
  1211. (const :tag "Show clocked log items" clock)
  1212. (const :tag "Show all logged state changes" state)))))
  1213. (defcustom org-agenda-start-with-clockreport-mode nil
  1214. "The initial value of clockreport-mode in a newly created agenda window."
  1215. :group 'org-agenda-startup
  1216. :group 'org-agenda-daily/weekly
  1217. :type 'boolean)
  1218. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1219. "Property list with parameters for the clocktable in clockreport mode.
  1220. This is the display mode that shows a clock table in the daily/weekly
  1221. agenda, the properties for this dynamic block can be set here.
  1222. The usual clocktable parameters are allowed here, but you cannot set
  1223. the properties :name, :tstart, :tend, :block, and :scope - these will
  1224. be overwritten to make sure the content accurately reflects the
  1225. current display in the agenda."
  1226. :group 'org-agenda-daily/weekly
  1227. :type 'plist)
  1228. (defcustom org-agenda-search-view-always-boolean nil
  1229. "Non-nil means the search string is interpreted as individual parts.
  1230. The search string for search view can either be interpreted as a phrase,
  1231. or as a list of snippets that define a boolean search for a number of
  1232. strings.
  1233. When this is non-nil, the string will be split on whitespace, and each
  1234. snippet will be searched individually, and all must match in order to
  1235. select an entry. A snippet is then a single string of non-white
  1236. characters, or a string in double quotes, or a regexp in {} braces.
  1237. If a snippet is preceded by \"-\", the snippet must *not* match.
  1238. \"+\" is syntactic sugar for positive selection. Each snippet may
  1239. be found as a full word or a partial word, but see the variable
  1240. `org-agenda-search-view-force-full-words'.
  1241. When this is nil, search will look for the entire search phrase as one,
  1242. with each space character matching any amount of whitespace, including
  1243. line breaks.
  1244. Even when this is nil, you can still switch to Boolean search dynamically
  1245. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1246. is a regexp marked with braces like \"{abc}\", this will also switch to
  1247. boolean search."
  1248. :group 'org-agenda-search-view
  1249. :version "24.1"
  1250. :type 'boolean)
  1251. (defvaralias 'org-agenda-search-view-search-words-only
  1252. 'org-agenda-search-view-always-boolean)
  1253. (defcustom org-agenda-search-view-force-full-words nil
  1254. "Non-nil means, search words must be matches as complete words.
  1255. When nil, they may also match part of a word."
  1256. :group 'org-agenda-search-view
  1257. :version "24.1"
  1258. :type 'boolean)
  1259. (defcustom org-agenda-search-view-max-outline-level 0
  1260. "Maximum outline level to display in search view.
  1261. E.g. when this is set to 1, the search view will only
  1262. show headlines of level 1. When set to 0, the default
  1263. value, don't limit agenda view by outline level."
  1264. :group 'org-agenda-search-view
  1265. :version "24.4"
  1266. :package-version '(Org . "8.3")
  1267. :type 'integer)
  1268. (defgroup org-agenda-time-grid nil
  1269. "Options concerning the time grid in the Org Agenda."
  1270. :tag "Org Agenda Time Grid"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-search-headline-for-time t
  1273. "Non-nil means search headline for a time-of-day.
  1274. If the headline contains a time-of-day in one format or another, it will
  1275. be used to sort the entry into the time sequence of items for a day.
  1276. Some people have time stamps in the headline that refer to the creation
  1277. time or so, and then this produces an unwanted side effect. If this is
  1278. the case for your, use this variable to turn off searching the headline
  1279. for a time."
  1280. :group 'org-agenda-time-grid
  1281. :type 'boolean)
  1282. (defcustom org-agenda-use-time-grid t
  1283. "Non-nil means show a time grid in the agenda schedule.
  1284. A time grid is a set of lines for specific times (like every two hours between
  1285. 8:00 and 20:00). The items scheduled for a day at specific times are
  1286. sorted in between these lines.
  1287. For details about when the grid will be shown, and what it will look like, see
  1288. the variable `org-agenda-time-grid'."
  1289. :group 'org-agenda-time-grid
  1290. :type 'boolean)
  1291. (defcustom org-agenda-time-grid
  1292. '((daily today require-timed)
  1293. "----------------"
  1294. (800 1000 1200 1400 1600 1800 2000))
  1295. "The settings for time grid for agenda display.
  1296. This is a list of three items. The first item is again a list. It contains
  1297. symbols specifying conditions when the grid should be displayed:
  1298. daily if the agenda shows a single day
  1299. weekly if the agenda shows an entire week
  1300. today show grid on current date, independent of daily/weekly display
  1301. require-timed show grid only if at least one item has a time specification
  1302. remove-match skip grid times already present in an entry
  1303. The second item is a string which will be placed behind the grid time.
  1304. The third item is a list of integers, indicating the times that should have
  1305. a grid line."
  1306. :group 'org-agenda-time-grid
  1307. :type
  1308. '(list
  1309. (set :greedy t :tag "Grid Display Options"
  1310. (const :tag "Show grid in single day agenda display" daily)
  1311. (const :tag "Show grid in weekly agenda display" weekly)
  1312. (const :tag "Always show grid for today" today)
  1313. (const :tag "Show grid only if any timed entries are present"
  1314. require-timed)
  1315. (const :tag "Skip grid times already present in an entry"
  1316. remove-match))
  1317. (string :tag "Grid String")
  1318. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1319. (defcustom org-agenda-show-current-time-in-grid t
  1320. "Non-nil means show the current time in the time grid."
  1321. :group 'org-agenda-time-grid
  1322. :version "24.1"
  1323. :type 'boolean)
  1324. (defcustom org-agenda-current-time-string
  1325. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1326. "The string for the current time marker in the agenda."
  1327. :group 'org-agenda-time-grid
  1328. :version "24.1"
  1329. :type 'string)
  1330. (defgroup org-agenda-sorting nil
  1331. "Options concerning sorting in the Org Agenda."
  1332. :tag "Org Agenda Sorting"
  1333. :group 'org-agenda)
  1334. (defcustom org-agenda-sorting-strategy
  1335. '((agenda habit-down time-up priority-down category-keep)
  1336. (todo priority-down category-keep)
  1337. (tags priority-down category-keep)
  1338. (search category-keep))
  1339. "Sorting structure for the agenda items of a single day.
  1340. This is a list of symbols which will be used in sequence to determine
  1341. if an entry should be listed before another entry. The following
  1342. symbols are recognized:
  1343. time-up Put entries with time-of-day indications first, early first
  1344. time-down Put entries with time-of-day indications first, late first
  1345. timestamp-up Sort by any timestamp, early first
  1346. timestamp-down Sort by any timestamp, late first
  1347. scheduled-up Sort by scheduled timestamp, early first
  1348. scheduled-down Sort by scheduled timestamp, late first
  1349. deadline-up Sort by deadline timestamp, early first
  1350. deadline-down Sort by deadline timestamp, late first
  1351. ts-up Sort by active timestamp, early first
  1352. ts-down Sort by active timestamp, late first
  1353. tsia-up Sort by inactive timestamp, early first
  1354. tsia-down Sort by inactive timestamp, late first
  1355. category-keep Keep the default order of categories, corresponding to the
  1356. sequence in `org-agenda-files'.
  1357. category-up Sort alphabetically by category, A-Z.
  1358. category-down Sort alphabetically by category, Z-A.
  1359. tag-up Sort alphabetically by last tag, A-Z.
  1360. tag-down Sort alphabetically by last tag, Z-A.
  1361. priority-up Sort numerically by priority, high priority last.
  1362. priority-down Sort numerically by priority, high priority first.
  1363. todo-state-up Sort by todo state, tasks that are done last.
  1364. todo-state-down Sort by todo state, tasks that are done first.
  1365. effort-up Sort numerically by estimated effort, high effort last.
  1366. effort-down Sort numerically by estimated effort, high effort first.
  1367. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1368. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1369. habit-up Put entries that are habits first
  1370. habit-down Put entries that are habits last
  1371. alpha-up Sort headlines alphabetically
  1372. alpha-down Sort headlines alphabetically, reversed
  1373. The different possibilities will be tried in sequence, and testing stops
  1374. if one comparison returns a \"not-equal\". For example, the default
  1375. '(time-up category-keep priority-down)
  1376. means: Pull out all entries having a specified time of day and sort them,
  1377. in order to make a time schedule for the current day the first thing in the
  1378. agenda listing for the day. Of the entries without a time indication, keep
  1379. the grouped in categories, don't sort the categories, but keep them in
  1380. the sequence given in `org-agenda-files'. Within each category sort by
  1381. priority.
  1382. Leaving out `category-keep' would mean that items will be sorted across
  1383. categories by priority.
  1384. Instead of a single list, this can also be a set of list for specific
  1385. contents, with a context symbol in the car of the list, any of
  1386. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1387. Custom commands can bind this variable in the options section."
  1388. :group 'org-agenda-sorting
  1389. :type `(choice
  1390. (repeat :tag "General" ,org-sorting-choice)
  1391. (list :tag "Individually"
  1392. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1393. (repeat ,org-sorting-choice))
  1394. (cons (const :tag "Strategy for TODO lists" todo)
  1395. (repeat ,org-sorting-choice))
  1396. (cons (const :tag "Strategy for Tags matches" tags)
  1397. (repeat ,org-sorting-choice))
  1398. (cons (const :tag "Strategy for search matches" search)
  1399. (repeat ,org-sorting-choice)))))
  1400. (defcustom org-agenda-cmp-user-defined nil
  1401. "A function to define the comparison `user-defined'.
  1402. This function must receive two arguments, agenda entry a and b.
  1403. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1404. the user comparison, return nil.
  1405. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1406. part of an agenda sorting strategy."
  1407. :group 'org-agenda-sorting
  1408. :type 'symbol)
  1409. (defcustom org-sort-agenda-notime-is-late t
  1410. "Non-nil means items without time are considered late.
  1411. This is only relevant for sorting. When t, items which have no explicit
  1412. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1413. do have a time. When nil, the default time is before 0:00. You can use this
  1414. option to decide if the schedule for today should come before or after timeless
  1415. agenda entries."
  1416. :group 'org-agenda-sorting
  1417. :type 'boolean)
  1418. (defcustom org-sort-agenda-noeffort-is-high t
  1419. "Non-nil means items without effort estimate are sorted as high effort.
  1420. This also applies when filtering an agenda view with respect to the
  1421. < or > effort operator. Then, tasks with no effort defined will be treated
  1422. as tasks with high effort.
  1423. When nil, such items are sorted as 0 minutes effort."
  1424. :group 'org-agenda-sorting
  1425. :type 'boolean)
  1426. (defgroup org-agenda-line-format nil
  1427. "Options concerning the entry prefix in the Org agenda display."
  1428. :tag "Org Agenda Line Format"
  1429. :group 'org-agenda)
  1430. (defcustom org-agenda-prefix-format
  1431. '((agenda . " %i %-12:c%?-12t% s")
  1432. (timeline . " % s")
  1433. (todo . " %i %-12:c")
  1434. (tags . " %i %-12:c")
  1435. (search . " %i %-12:c"))
  1436. "Format specifications for the prefix of items in the agenda views.
  1437. An alist with five entries, each for the different agenda types. The
  1438. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1439. The values are format strings.
  1440. This format works similar to a printf format, with the following meaning:
  1441. %c the category of the item, \"Diary\" for entries from the diary,
  1442. or as given by the CATEGORY keyword or derived from the file name
  1443. %e the effort required by the item
  1444. %l the level of the item (insert X space(s) if item is of level X)
  1445. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1446. %T the last tag of the item (ignore inherited tags, which come first)
  1447. %t the HH:MM time-of-day specification if one applies to the entry
  1448. %s Scheduling/Deadline information, a short string
  1449. %b show breadcrumbs, i.e., the names of the higher levels
  1450. %(expression) Eval EXPRESSION and replace the control string
  1451. by the result
  1452. All specifiers work basically like the standard `%s' of printf, but may
  1453. contain two additional characters: a question mark just after the `%'
  1454. and a whitespace/punctuation character just before the final letter.
  1455. If the first character after `%' is a question mark, the entire field
  1456. will only be included if the corresponding value applies to the current
  1457. entry. This is useful for fields which should have fixed width when
  1458. present, but zero width when absent. For example, \"%?-12t\" will
  1459. result in a 12 character time field if a time of the day is specified,
  1460. but will completely disappear in entries which do not contain a time.
  1461. If there is punctuation or whitespace character just before the
  1462. final format letter, this character will be appended to the field
  1463. value if the value is not empty. For example, the format
  1464. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1465. the category is empty, no additional colon is inserted.
  1466. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1467. which means:
  1468. - Indent the line with two space characters
  1469. - Give the category a 12 chars wide field, padded with whitespace on
  1470. the right (because of `-'). Append a colon if there is a category
  1471. (because of `:').
  1472. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1473. time, don't put in an empty field, just skip it (because of '?').
  1474. - Finally, put the scheduling information.
  1475. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1476. `org-agenda-remove-tags'.
  1477. Custom commands can set this variable in the options section."
  1478. :type '(choice
  1479. (string :tag "General format")
  1480. (list :greedy t :tag "View dependent"
  1481. (cons (const agenda) (string :tag "Format"))
  1482. (cons (const timeline) (string :tag "Format"))
  1483. (cons (const todo) (string :tag "Format"))
  1484. (cons (const tags) (string :tag "Format"))
  1485. (cons (const search) (string :tag "Format"))))
  1486. :group 'org-agenda-line-format)
  1487. (defvar org-prefix-format-compiled nil
  1488. "The compiled prefix format and associated variables.
  1489. This is a list where first element is a list of variable bindings, and second
  1490. element is the compiled format expression. See the variable
  1491. `org-agenda-prefix-format'.")
  1492. (defcustom org-agenda-todo-keyword-format "%-1s"
  1493. "Format for the TODO keyword in agenda lines.
  1494. Set this to something like \"%-12s\" if you want all TODO keywords
  1495. to occupy a fixed space in the agenda display."
  1496. :group 'org-agenda-line-format
  1497. :type 'string)
  1498. (defcustom org-agenda-diary-sexp-prefix nil
  1499. "A regexp that matches part of a diary sexp entry
  1500. which should be treated as scheduling/deadline information in
  1501. `org-agenda'.
  1502. For example, you can use this to extract the `diary-remind-message' from
  1503. `diary-remind' entries."
  1504. :group 'org-agenda-line-format
  1505. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1506. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1507. "Text preceding timerange entries in the agenda view.
  1508. This is a list with two strings. The first applies when the range
  1509. is entirely on one day. The second applies if the range spans several days.
  1510. The strings may have two \"%d\" format specifiers which will be filled
  1511. with the sequence number of the days, and the total number of days in the
  1512. range, respectively."
  1513. :group 'org-agenda-line-format
  1514. :type '(list
  1515. (string :tag "Deadline today ")
  1516. (choice :tag "Deadline relative"
  1517. (string :tag "Format string")
  1518. (function))))
  1519. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1520. "Text preceding scheduled items in the agenda view.
  1521. This is a list with two strings. The first applies when the item is
  1522. scheduled on the current day. The second applies when it has been scheduled
  1523. previously, it may contain a %d indicating that this is the nth time that
  1524. this item is scheduled, due to automatic rescheduling of unfinished items
  1525. for the following day. So this number is one larger than the number of days
  1526. that passed since this item was scheduled first."
  1527. :group 'org-agenda-line-format
  1528. :version "24.4"
  1529. :package-version '(Org . "8.0")
  1530. :type '(list
  1531. (string :tag "Scheduled today ")
  1532. (string :tag "Scheduled previously")))
  1533. (defcustom org-agenda-inactive-leader "["
  1534. "Text preceding item pulled into the agenda by inactive time stamps.
  1535. These entries are added to the agenda when pressing \"[\"."
  1536. :group 'org-agenda-line-format
  1537. :version "24.1"
  1538. :type 'string)
  1539. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1540. "Text preceding deadline items in the agenda view.
  1541. This is a list with three strings. The first applies when the item has its
  1542. deadline on the current day. The second applies when the deadline is in the
  1543. future, the third one when it is in the past. The strings may contain %d
  1544. to capture the number of days."
  1545. :group 'org-agenda-line-format
  1546. :version "24.4"
  1547. :package-version '(Org . "8.0")
  1548. :type '(list
  1549. (string :tag "Deadline today ")
  1550. (string :tag "Deadline in the future ")
  1551. (string :tag "Deadline in the past ")))
  1552. (defcustom org-agenda-remove-times-when-in-prefix t
  1553. "Non-nil means remove duplicate time specifications in agenda items.
  1554. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1555. time-of-day specification in a headline or diary entry is extracted and
  1556. placed into the prefix. If this option is non-nil, the original specification
  1557. \(a timestamp or -range, or just a plain time(range) specification like
  1558. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1559. cluttered.
  1560. The option can be t or nil. It may also be the symbol `beg', indicating
  1561. that the time should only be removed when it is located at the beginning of
  1562. the headline/diary entry."
  1563. :group 'org-agenda-line-format
  1564. :type '(choice
  1565. (const :tag "Always" t)
  1566. (const :tag "Never" nil)
  1567. (const :tag "When at beginning of entry" beg)))
  1568. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1569. "Non-nil means remove time ranges specifications in agenda
  1570. items that span on several days."
  1571. :group 'org-agenda-line-format
  1572. :version "24.1"
  1573. :type 'boolean)
  1574. (defcustom org-agenda-default-appointment-duration nil
  1575. "Default duration for appointments that only have a starting time.
  1576. When nil, no duration is specified in such cases.
  1577. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1578. :group 'org-agenda-line-format
  1579. :type '(choice
  1580. (integer :tag "Minutes")
  1581. (const :tag "No default duration")))
  1582. (defcustom org-agenda-show-inherited-tags t
  1583. "Non-nil means show inherited tags in each agenda line.
  1584. When this option is set to `always', it take precedences over
  1585. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1586. in every agenda.
  1587. When this option is set to t (the default), inherited tags are
  1588. shown when they are available, i.e. when the value of
  1589. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1590. given agenda type.
  1591. This can be set to a list of agenda types in which the agenda
  1592. must display the inherited tags. Available types are `todo',
  1593. `agenda', `search' and `timeline'.
  1594. When set to nil, never show inherited tags in agenda lines."
  1595. :group 'org-agenda-line-format
  1596. :group 'org-agenda
  1597. :version "24.3"
  1598. :type '(choice
  1599. (const :tag "Show inherited tags when available" t)
  1600. (const :tag "Always show inherited tags" always)
  1601. (repeat :tag "Show inherited tags only in selected agenda types"
  1602. (symbol :tag "Agenda type"))))
  1603. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1604. "List of agenda view types where to use tag inheritance.
  1605. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1606. controlled by `org-use-tag-inheritance'. In other agenda types,
  1607. `org-use-tag-inheritance' is not used for the selection of the
  1608. agenda entries. Still, you may want the agenda to be aware of
  1609. the inherited tags anyway, e.g. for later tag filtering.
  1610. Allowed value are `todo', `search', `timeline' and `agenda'.
  1611. This variable has no effect if `org-agenda-show-inherited-tags'
  1612. is set to `always'. In that case, the agenda is aware of those
  1613. tags.
  1614. The default value sets tags in every agenda type. Setting this
  1615. option to nil will speed up non-tags agenda view a lot."
  1616. :group 'org-agenda
  1617. :version "24.3"
  1618. :type '(choice
  1619. (const :tag "Use tag inheritance in all agenda types" t)
  1620. (repeat :tag "Use tag inheritance in selected agenda types"
  1621. (symbol :tag "Agenda type"))))
  1622. (defcustom org-agenda-hide-tags-regexp nil
  1623. "Regular expression used to filter away specific tags in agenda views.
  1624. This means that these tags will be present, but not be shown in the agenda
  1625. line. Secondary filtering will still work on the hidden tags.
  1626. Nil means don't hide any tags."
  1627. :group 'org-agenda-line-format
  1628. :type '(choice
  1629. (const :tag "Hide none" nil)
  1630. (string :tag "Regexp ")))
  1631. (defcustom org-agenda-remove-tags nil
  1632. "Non-nil means remove the tags from the headline copy in the agenda.
  1633. When this is the symbol `prefix', only remove tags when
  1634. `org-agenda-prefix-format' contains a `%T' specifier."
  1635. :group 'org-agenda-line-format
  1636. :type '(choice
  1637. (const :tag "Always" t)
  1638. (const :tag "Never" nil)
  1639. (const :tag "When prefix format contains %T" prefix)))
  1640. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1641. 'org-agenda-remove-tags)
  1642. (defcustom org-agenda-tags-column -80
  1643. "Shift tags in agenda items to this column.
  1644. If this number is positive, it specifies the column. If it is negative,
  1645. it means that the tags should be flushright to that column. For example,
  1646. -80 works well for a normal 80 character screen."
  1647. :group 'org-agenda-line-format
  1648. :type 'integer)
  1649. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1650. (defcustom org-agenda-fontify-priorities 'cookies
  1651. "Non-nil means highlight low and high priorities in agenda.
  1652. When t, the highest priority entries are bold, lowest priority italic.
  1653. However, settings in `org-priority-faces' will overrule these faces.
  1654. When this variable is the symbol `cookies', only fontify the
  1655. cookies, not the entire task.
  1656. This may also be an association list of priority faces, whose
  1657. keys are the character values of `org-highest-priority',
  1658. `org-default-priority', and `org-lowest-priority' (the default values
  1659. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1660. color as a string, or a list like `(:background \"Red\")'.
  1661. If it is a color, the variable `org-faces-easy-properties'
  1662. determines if it is a foreground or a background color."
  1663. :group 'org-agenda-line-format
  1664. :type '(choice
  1665. (const :tag "Never" nil)
  1666. (const :tag "Defaults" t)
  1667. (const :tag "Cookies only" cookies)
  1668. (repeat :tag "Specify"
  1669. (list (character :tag "Priority" :value ?A)
  1670. (choice :tag "Face "
  1671. (string :tag "Color")
  1672. (sexp :tag "Face"))))))
  1673. (defcustom org-agenda-day-face-function nil
  1674. "Function called to determine what face should be used to display a day.
  1675. The only argument passed to that function is the day. It should
  1676. returns a face, or nil if does not want to specify a face and let
  1677. the normal rules apply."
  1678. :group 'org-agenda-line-format
  1679. :version "24.1"
  1680. :type '(choice (const nil) (function)))
  1681. (defcustom org-agenda-category-icon-alist nil
  1682. "Alist of category icon to be displayed in agenda views.
  1683. Each entry should have the following format:
  1684. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1685. Where CATEGORY-REGEXP is a regexp matching the categories where
  1686. the icon should be displayed.
  1687. FILE-OR-DATA either a file path or a string containing image data.
  1688. The other fields can be omitted safely if not needed:
  1689. TYPE indicates the image type.
  1690. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1691. image data.
  1692. PROPS are additional image attributes to assign to the image,
  1693. like, e.g. `:ascent center'.
  1694. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1695. If you want to set the display properties yourself, just put a
  1696. list as second element:
  1697. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1698. For example, to display a 16px horizontal space for Emacs
  1699. category, you can use:
  1700. (\"Emacs\" \\='(space . (:width (16))))"
  1701. :group 'org-agenda-line-format
  1702. :version "24.1"
  1703. :type '(alist :key-type (string :tag "Regexp matching category")
  1704. :value-type (choice (list :tag "Icon"
  1705. (string :tag "File or data")
  1706. (symbol :tag "Type")
  1707. (boolean :tag "Data?")
  1708. (repeat :tag "Extra image properties" :inline t symbol))
  1709. (list :tag "Display properties" sexp))))
  1710. (defgroup org-agenda-column-view nil
  1711. "Options concerning column view in the agenda."
  1712. :tag "Org Agenda Column View"
  1713. :group 'org-agenda)
  1714. (defcustom org-agenda-view-columns-initially nil
  1715. "When non-nil, switch to columns view right after creating the agenda."
  1716. :group 'org-agenda-column-view
  1717. :type 'boolean
  1718. :version "26.1"
  1719. :package-version '(Org . "9.0")
  1720. :safe #'booleanp)
  1721. (defcustom org-agenda-columns-show-summaries t
  1722. "Non-nil means show summaries for columns displayed in the agenda view."
  1723. :group 'org-agenda-column-view
  1724. :type 'boolean)
  1725. (defcustom org-agenda-columns-compute-summary-properties t
  1726. "Non-nil means recompute all summary properties before column view.
  1727. When column view in the agenda is listing properties that have a summary
  1728. operator, it can go to all relevant buffers and recompute the summaries
  1729. there. This can mean overhead for the agenda column view, but is necessary
  1730. to have thing up to date.
  1731. As a special case, a CLOCKSUM property also makes sure that the clock
  1732. computations are current."
  1733. :group 'org-agenda-column-view
  1734. :type 'boolean)
  1735. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1736. "Non-nil means the duration of an appointment will add to day effort.
  1737. The property to which appointment durations will be added is the one given
  1738. in the option `org-effort-property'. If an appointment does not have
  1739. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1740. is not set, an appointment without end time will not contribute to the time
  1741. estimate."
  1742. :group 'org-agenda-column-view
  1743. :type 'boolean)
  1744. (defcustom org-agenda-auto-exclude-function nil
  1745. "A function called with a tag to decide if it is filtered on \
  1746. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1747. The sole argument to the function, which is called once for each
  1748. possible tag, is a string giving the name of the tag. The
  1749. function should return either nil if the tag should be included
  1750. as normal, or \"-<TAG>\" to exclude the tag.
  1751. Note that for the purpose of tag filtering, only the lower-case version of
  1752. all tags will be considered, so that this function will only ever see
  1753. the lower-case version of all tags."
  1754. :group 'org-agenda
  1755. :type '(choice (const nil) (function)))
  1756. (defcustom org-agenda-bulk-custom-functions nil
  1757. "Alist of characters and custom functions for bulk actions.
  1758. For example, this value makes those two functions available:
  1759. \\='((?R set-category)
  1760. (?C bulk-cut))
  1761. With selected entries in an agenda buffer, `B R' will call
  1762. the custom function `set-category' on the selected entries.
  1763. Note that functions in this alist don't need to be quoted."
  1764. :type '(alist :key-type character :value-type (group function))
  1765. :version "24.1"
  1766. :group 'org-agenda)
  1767. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1768. "Execute BODY with point at location given by `org-hd-marker' property.
  1769. If STRING is non-nil, the text property will be fetched from position 0
  1770. in that string. If STRING is nil, it will be fetched from the beginning
  1771. of the current line."
  1772. (org-with-gensyms (marker)
  1773. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1774. 'org-hd-marker ,string)))
  1775. (with-current-buffer (marker-buffer ,marker)
  1776. (save-excursion
  1777. (goto-char ,marker)
  1778. ,@body)))))
  1779. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1780. (defun org-add-agenda-custom-command (entry)
  1781. "Replace or add a command in `org-agenda-custom-commands'.
  1782. This is mostly for hacking and trying a new command - once the command
  1783. works you probably want to add it to `org-agenda-custom-commands' for good."
  1784. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1785. (if ass
  1786. (setcdr ass (cdr entry))
  1787. (push entry org-agenda-custom-commands))))
  1788. ;;; Define the org-agenda-mode
  1789. (defvar org-agenda-mode-map (make-sparse-keymap)
  1790. "Keymap for `org-agenda-mode'.")
  1791. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1792. (defvar org-agenda-menu) ; defined later in this file.
  1793. (defvar org-agenda-restrict nil) ; defined later in this file.
  1794. (defvar org-agenda-follow-mode nil)
  1795. (defvar org-agenda-entry-text-mode nil)
  1796. (defvar org-agenda-clockreport-mode nil)
  1797. (defvar org-agenda-show-log nil)
  1798. (defvar org-agenda-redo-command nil)
  1799. (defvar org-agenda-query-string nil)
  1800. (defvar org-agenda-mode-hook nil
  1801. "Hook run after `org-agenda-mode' is turned on.
  1802. The buffer is still writable when this hook is called.")
  1803. (defvar org-agenda-type nil)
  1804. (defvar org-agenda-force-single-file nil)
  1805. (defvar org-agenda-bulk-marked-entries nil
  1806. "List of markers that refer to marked entries in the agenda.")
  1807. (defvar org-agenda-current-date nil
  1808. "Active date when building the agenda.")
  1809. ;;; Multiple agenda buffers support
  1810. (defcustom org-agenda-sticky nil
  1811. "Non-nil means agenda q key will bury agenda buffers.
  1812. Agenda commands will then show existing buffer instead of generating new ones.
  1813. When nil, `q' will kill the single agenda buffer."
  1814. :group 'org-agenda
  1815. :version "24.3"
  1816. :type 'boolean)
  1817. ;;;###autoload
  1818. (defun org-toggle-sticky-agenda (&optional arg)
  1819. "Toggle `org-agenda-sticky'."
  1820. (interactive "P")
  1821. (let ((new-value (if arg
  1822. (> (prefix-numeric-value arg) 0)
  1823. (not org-agenda-sticky))))
  1824. (if (equal new-value org-agenda-sticky)
  1825. (and (called-interactively-p 'interactive)
  1826. (message "Sticky agenda was already %s"
  1827. (if org-agenda-sticky "enabled" "disabled")))
  1828. (setq org-agenda-sticky new-value)
  1829. (org-agenda-kill-all-agenda-buffers)
  1830. (and (called-interactively-p 'interactive)
  1831. (message "Sticky agenda %s"
  1832. (if org-agenda-sticky "enabled" "disabled"))))))
  1833. (defvar org-agenda-buffer nil
  1834. "Agenda buffer currently being generated.")
  1835. (defvar org-agenda-last-prefix-arg nil)
  1836. (defvar org-agenda-this-buffer-name nil)
  1837. (defvar org-agenda-doing-sticky-redo nil)
  1838. (defvar org-agenda-this-buffer-is-sticky nil)
  1839. (defvar org-agenda-last-indirect-buffer nil
  1840. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1841. (defconst org-agenda-local-vars
  1842. '(org-agenda-this-buffer-name
  1843. org-agenda-undo-list
  1844. org-agenda-pending-undo-list
  1845. org-agenda-follow-mode
  1846. org-agenda-entry-text-mode
  1847. org-agenda-clockreport-mode
  1848. org-agenda-show-log
  1849. org-agenda-redo-command
  1850. org-agenda-query-string
  1851. org-agenda-type
  1852. org-agenda-bulk-marked-entries
  1853. org-agenda-undo-has-started-in
  1854. org-agenda-info
  1855. org-agenda-pre-window-conf
  1856. org-agenda-columns-active
  1857. org-agenda-tag-filter
  1858. org-agenda-category-filter
  1859. org-agenda-top-headline-filter
  1860. org-agenda-regexp-filter
  1861. org-agenda-effort-filter
  1862. org-agenda-markers
  1863. org-agenda-last-search-view-search-was-boolean
  1864. org-agenda-last-indirect-buffer
  1865. org-agenda-filtered-by-category
  1866. org-agenda-filter-form
  1867. org-agenda-cycle-counter
  1868. org-agenda-last-prefix-arg)
  1869. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1870. (defun org-agenda-mode ()
  1871. "Mode for time-sorted view on action items in Org files.
  1872. The following commands are available:
  1873. \\{org-agenda-mode-map}"
  1874. (interactive)
  1875. (cond (org-agenda-doing-sticky-redo
  1876. ;; Refreshing sticky agenda-buffer
  1877. ;;
  1878. ;; Preserve the value of `org-agenda-local-vars' variables,
  1879. ;; while letting `kill-all-local-variables' kill the rest
  1880. (let ((save (buffer-local-variables)))
  1881. (kill-all-local-variables)
  1882. (mapc 'make-local-variable org-agenda-local-vars)
  1883. (dolist (elem save)
  1884. (let ((var (car elem))
  1885. (val (cdr elem)))
  1886. (when (and val
  1887. (member var org-agenda-local-vars))
  1888. (set var val)))))
  1889. (setq-local org-agenda-this-buffer-is-sticky t))
  1890. (org-agenda-sticky
  1891. ;; Creating a sticky Agenda buffer for the first time
  1892. (kill-all-local-variables)
  1893. (mapc 'make-local-variable org-agenda-local-vars)
  1894. (setq-local org-agenda-this-buffer-is-sticky t))
  1895. (t
  1896. ;; Creating a non-sticky agenda buffer
  1897. (kill-all-local-variables)
  1898. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1899. (setq org-agenda-undo-list nil
  1900. org-agenda-pending-undo-list nil
  1901. org-agenda-bulk-marked-entries nil)
  1902. (setq major-mode 'org-agenda-mode)
  1903. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1904. (setq-local font-lock-global-modes (list 'not major-mode))
  1905. (setq mode-name "Org-Agenda")
  1906. (setq indent-tabs-mode nil)
  1907. (use-local-map org-agenda-mode-map)
  1908. (easy-menu-add org-agenda-menu)
  1909. (if org-startup-truncated (setq truncate-lines t))
  1910. (setq-local line-move-visual nil)
  1911. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1912. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1913. ;; Make sure properties are removed when copying text
  1914. (add-hook 'filter-buffer-substring-functions
  1915. (lambda (fun start end delete)
  1916. (substring-no-properties (funcall fun start end delete)))
  1917. nil t)
  1918. (unless org-agenda-keep-modes
  1919. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1920. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1921. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1922. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1923. (add-to-invisibility-spec '(org-filtered))
  1924. (add-to-invisibility-spec '(org-link))
  1925. (easy-menu-change
  1926. '("Agenda") "Agenda Files"
  1927. (append
  1928. (list
  1929. (vector
  1930. (if (get 'org-agenda-files 'org-restrict)
  1931. "Restricted to single file"
  1932. "Edit File List")
  1933. '(org-edit-agenda-file-list)
  1934. (not (get 'org-agenda-files 'org-restrict)))
  1935. "--")
  1936. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1937. (org-agenda-set-mode-name)
  1938. (apply
  1939. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1940. (list 'org-agenda-mode-hook)))
  1941. (substitute-key-definition 'undo 'org-agenda-undo
  1942. org-agenda-mode-map global-map)
  1943. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1944. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1945. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1946. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1947. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1948. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1949. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1950. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1951. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1952. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1953. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1954. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1955. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1956. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1957. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1958. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1959. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1960. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1963. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1964. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1965. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1966. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1967. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1968. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1969. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1970. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1971. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1972. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1973. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1974. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1975. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1976. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1977. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1978. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1979. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1980. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1981. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1982. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1983. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1984. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1985. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1986. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1988. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1989. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1990. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1991. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1992. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1993. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1994. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1995. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1996. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1997. (while l (org-defkey org-agenda-mode-map
  1998. (int-to-string (pop l)) 'digit-argument)))
  1999. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2000. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2001. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2002. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2003. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2004. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2005. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2006. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2007. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2008. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  2009. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2010. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2011. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2012. 'org-clock-modify-effort-estimate)
  2013. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2014. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2015. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2016. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2017. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2018. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2019. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2020. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2021. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2022. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2023. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2024. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2025. (substitute-key-definition 'next-line 'org-agenda-next-line
  2026. org-agenda-mode-map global-map)
  2027. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2028. org-agenda-mode-map global-map)
  2029. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2030. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2031. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2032. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2033. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2034. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2035. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2036. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2037. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2038. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2039. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2040. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2041. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2042. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2043. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2044. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2045. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2046. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2048. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2049. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2050. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2051. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2052. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2053. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2054. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2055. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2056. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2057. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2058. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2059. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2060. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2061. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2062. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2063. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2064. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2065. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2066. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2067. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2068. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2069. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2070. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2071. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2072. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2074. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2075. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2076. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2077. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2078. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2079. (when org-agenda-mouse-1-follows-link
  2080. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2081. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2082. '("Agenda"
  2083. ("Agenda Files")
  2084. "--"
  2085. ("Agenda Dates"
  2086. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2087. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2088. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2089. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2090. "--"
  2091. ("View"
  2092. ["Day View" org-agenda-day-view
  2093. :active (org-agenda-check-type nil 'agenda)
  2094. :style radio :selected (eq org-agenda-current-span 'day)
  2095. :keys "v d (or just d)"]
  2096. ["Week View" org-agenda-week-view
  2097. :active (org-agenda-check-type nil 'agenda)
  2098. :style radio :selected (eq org-agenda-current-span 'week)
  2099. :keys "v w"]
  2100. ["Fortnight View" org-agenda-fortnight-view
  2101. :active (org-agenda-check-type nil 'agenda)
  2102. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2103. :keys "v t"]
  2104. ["Month View" org-agenda-month-view
  2105. :active (org-agenda-check-type nil 'agenda)
  2106. :style radio :selected (eq org-agenda-current-span 'month)
  2107. :keys "v m"]
  2108. ["Year View" org-agenda-year-view
  2109. :active (org-agenda-check-type nil 'agenda)
  2110. :style radio :selected (eq org-agenda-current-span 'year)
  2111. :keys "v y"]
  2112. "--"
  2113. ["Include Diary" org-agenda-toggle-diary
  2114. :style toggle :selected org-agenda-include-diary
  2115. :active (org-agenda-check-type nil 'agenda)]
  2116. ["Include Deadlines" org-agenda-toggle-deadlines
  2117. :style toggle :selected org-agenda-include-deadlines
  2118. :active (org-agenda-check-type nil 'agenda)]
  2119. ["Use Time Grid" org-agenda-toggle-time-grid
  2120. :style toggle :selected org-agenda-use-time-grid
  2121. :active (org-agenda-check-type nil 'agenda)]
  2122. "--"
  2123. ["Show clock report" org-agenda-clockreport-mode
  2124. :style toggle :selected org-agenda-clockreport-mode
  2125. :active (org-agenda-check-type nil 'agenda)]
  2126. ["Show some entry text" org-agenda-entry-text-mode
  2127. :style toggle :selected org-agenda-entry-text-mode
  2128. :active t]
  2129. "--"
  2130. ["Show Logbook entries" org-agenda-log-mode
  2131. :style toggle :selected org-agenda-show-log
  2132. :active (org-agenda-check-type nil 'agenda 'timeline)
  2133. :keys "v l (or just l)"]
  2134. ["Include archived trees" org-agenda-archives-mode
  2135. :style toggle :selected org-agenda-archives-mode :active t
  2136. :keys "v a"]
  2137. ["Include archive files" (org-agenda-archives-mode t)
  2138. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2139. :keys "v A"]
  2140. "--"
  2141. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2142. ["Write view to file" org-agenda-write t]
  2143. ["Rebuild buffer" org-agenda-redo t]
  2144. ["Save all Org buffers" org-save-all-org-buffers t]
  2145. "--"
  2146. ["Show original entry" org-agenda-show t]
  2147. ["Go To (other window)" org-agenda-goto t]
  2148. ["Go To (this window)" org-agenda-switch-to t]
  2149. ["Capture with cursor date" org-agenda-capture t]
  2150. ["Follow Mode" org-agenda-follow-mode
  2151. :style toggle :selected org-agenda-follow-mode :active t]
  2152. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2153. "--"
  2154. ("TODO"
  2155. ["Cycle TODO" org-agenda-todo t]
  2156. ["Next TODO set" org-agenda-todo-nextset t]
  2157. ["Previous TODO set" org-agenda-todo-previousset t]
  2158. ["Add note" org-agenda-add-note t])
  2159. ("Archive/Refile/Delete"
  2160. ["Archive default" org-agenda-archive-default t]
  2161. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2162. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2163. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2164. ["Archive subtree" org-agenda-archive t]
  2165. "--"
  2166. ["Refile" org-agenda-refile t]
  2167. "--"
  2168. ["Delete subtree" org-agenda-kill t])
  2169. ("Bulk action"
  2170. ["Mark entry" org-agenda-bulk-mark t]
  2171. ["Mark all" org-agenda-bulk-mark-all t]
  2172. ["Unmark entry" org-agenda-bulk-unmark t]
  2173. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2174. ["Toggle mark" org-agenda-bulk-toggle t]
  2175. ["Toggle all" org-agenda-bulk-toggle-all t]
  2176. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2177. ["Act on all marked" org-agenda-bulk-action t]
  2178. "--"
  2179. ("Tags and Properties"
  2180. ["Show all Tags" org-agenda-show-tags t]
  2181. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2182. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2183. "--"
  2184. ["Column View" org-columns t])
  2185. ("Deadline/Schedule"
  2186. ["Schedule" org-agenda-schedule t]
  2187. ["Set Deadline" org-agenda-deadline t]
  2188. "--"
  2189. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2190. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2191. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2192. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2193. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2194. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2195. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2196. ("Clock and Effort"
  2197. ["Clock in" org-agenda-clock-in t]
  2198. ["Clock out" org-agenda-clock-out t]
  2199. ["Clock cancel" org-agenda-clock-cancel t]
  2200. ["Goto running clock" org-clock-goto t]
  2201. "--"
  2202. ["Set Effort" org-agenda-set-effort t]
  2203. ["Change clocked effort" org-clock-modify-effort-estimate
  2204. (org-clock-is-active)])
  2205. ("Priority"
  2206. ["Set Priority" org-agenda-priority t]
  2207. ["Increase Priority" org-agenda-priority-up t]
  2208. ["Decrease Priority" org-agenda-priority-down t]
  2209. ["Show Priority" org-show-priority t])
  2210. ("Calendar/Diary"
  2211. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2212. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2213. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2214. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2215. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2216. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2217. "--"
  2218. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2219. "--"
  2220. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2221. "--"
  2222. ("MobileOrg"
  2223. ["Push Files and Views" org-mobile-push t]
  2224. ["Get Captured and Flagged" org-mobile-pull t]
  2225. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2226. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2227. "--"
  2228. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2229. "--"
  2230. ["Quit" org-agenda-quit t]
  2231. ["Exit and Release Buffers" org-agenda-exit t]
  2232. ))
  2233. ;;; Agenda undo
  2234. (defvar org-agenda-allow-remote-undo t
  2235. "Non-nil means allow remote undo from the agenda buffer.")
  2236. (defvar org-agenda-undo-has-started-in nil
  2237. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2238. (defun org-agenda-undo ()
  2239. "Undo a remote editing step in the agenda.
  2240. This undoes changes both in the agenda buffer and in the remote buffer
  2241. that have been changed along."
  2242. (interactive)
  2243. (or org-agenda-allow-remote-undo
  2244. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2245. (if (not (eq this-command last-command))
  2246. (setq org-agenda-undo-has-started-in nil
  2247. org-agenda-pending-undo-list org-agenda-undo-list))
  2248. (if (not org-agenda-pending-undo-list)
  2249. (user-error "No further undo information"))
  2250. (let* ((entry (pop org-agenda-pending-undo-list))
  2251. buf line cmd rembuf)
  2252. (setq cmd (pop entry) line (pop entry))
  2253. (setq rembuf (nth 2 entry))
  2254. (org-with-remote-undo rembuf
  2255. (while (bufferp (setq buf (pop entry)))
  2256. (if (pop entry)
  2257. (with-current-buffer buf
  2258. (let ((last-undo-buffer buf)
  2259. (inhibit-read-only t))
  2260. (unless (memq buf org-agenda-undo-has-started-in)
  2261. (push buf org-agenda-undo-has-started-in)
  2262. (make-local-variable 'pending-undo-list)
  2263. (undo-start))
  2264. (while (and pending-undo-list
  2265. (listp pending-undo-list)
  2266. (not (car pending-undo-list)))
  2267. (pop pending-undo-list))
  2268. (undo-more 1))))))
  2269. (org-goto-line line)
  2270. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2271. (defun org-verify-change-for-undo (l1 l2)
  2272. "Verify that a real change occurred between the undo lists L1 and L2."
  2273. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2274. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2275. (not (eq l1 l2)))
  2276. ;;; Agenda dispatch
  2277. (defvar org-agenda-restrict-begin (make-marker))
  2278. (defvar org-agenda-restrict-end (make-marker))
  2279. (defvar org-agenda-last-dispatch-buffer nil)
  2280. (defvar org-agenda-overriding-restriction nil)
  2281. (defcustom org-agenda-custom-commands-contexts nil
  2282. "Alist of custom agenda keys and contextual rules.
  2283. For example, if you have a custom agenda command \"p\" and you
  2284. want this command to be accessible only from plain text files,
  2285. use this:
  2286. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2287. Here are the available contexts definitions:
  2288. in-file: command displayed only in matching files
  2289. in-mode: command displayed only in matching modes
  2290. not-in-file: command not displayed in matching files
  2291. not-in-mode: command not displayed in matching modes
  2292. in-buffer: command displayed only in matching buffers
  2293. not-in-buffer: command not displayed in matching buffers
  2294. [function]: a custom function taking no argument
  2295. If you define several checks, the agenda command will be
  2296. accessible if there is at least one valid check.
  2297. You can also bind a key to another agenda custom command
  2298. depending on contextual rules.
  2299. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2300. Here it means: in .txt files, use \"p\" as the key for the
  2301. agenda command otherwise associated with \"q\". (The command
  2302. originally associated with \"q\" is not displayed to avoid
  2303. duplicates.)"
  2304. :version "24.3"
  2305. :group 'org-agenda-custom-commands
  2306. :type '(repeat (list :tag "Rule"
  2307. (string :tag " Agenda key")
  2308. (string :tag "Replace by command")
  2309. (repeat :tag "Available when"
  2310. (choice
  2311. (cons :tag "Condition"
  2312. (choice
  2313. (const :tag "In file" in-file)
  2314. (const :tag "Not in file" not-in-file)
  2315. (const :tag "In buffer" in-buffer)
  2316. (const :tag "Not in buffer" not-in-buffer)
  2317. (const :tag "In mode" in-mode)
  2318. (const :tag "Not in mode" not-in-mode))
  2319. (regexp))
  2320. (function :tag "Custom function"))))))
  2321. (defcustom org-agenda-max-entries nil
  2322. "Maximum number of entries to display in an agenda.
  2323. This can be nil (no limit) or an integer or an alist of agenda
  2324. types with an associated number of entries to display in this
  2325. type."
  2326. :version "24.4"
  2327. :package-version '(Org . "8.0")
  2328. :group 'org-agenda-custom-commands
  2329. :type '(choice (symbol :tag "No limit" nil)
  2330. (integer :tag "Max number of entries")
  2331. (repeat
  2332. (cons (choice :tag "Agenda type"
  2333. (const agenda)
  2334. (const todo)
  2335. (const tags)
  2336. (const search)
  2337. (const timeline))
  2338. (integer :tag "Max number of entries")))))
  2339. (defcustom org-agenda-max-todos nil
  2340. "Maximum number of TODOs to display in an agenda.
  2341. This can be nil (no limit) or an integer or an alist of agenda
  2342. types with an associated number of entries to display in this
  2343. type."
  2344. :version "24.4"
  2345. :package-version '(Org . "8.0")
  2346. :group 'org-agenda-custom-commands
  2347. :type '(choice (symbol :tag "No limit" nil)
  2348. (integer :tag "Max number of TODOs")
  2349. (repeat
  2350. (cons (choice :tag "Agenda type"
  2351. (const agenda)
  2352. (const todo)
  2353. (const tags)
  2354. (const search)
  2355. (const timeline))
  2356. (integer :tag "Max number of TODOs")))))
  2357. (defcustom org-agenda-max-tags nil
  2358. "Maximum number of tagged entries to display in an agenda.
  2359. This can be nil (no limit) or an integer or an alist of agenda
  2360. types with an associated number of entries to display in this
  2361. type."
  2362. :version "24.4"
  2363. :package-version '(Org . "8.0")
  2364. :group 'org-agenda-custom-commands
  2365. :type '(choice (symbol :tag "No limit" nil)
  2366. (integer :tag "Max number of tagged entries")
  2367. (repeat
  2368. (cons (choice :tag "Agenda type"
  2369. (const agenda)
  2370. (const todo)
  2371. (const tags)
  2372. (const search)
  2373. (const timeline))
  2374. (integer :tag "Max number of tagged entries")))))
  2375. (defcustom org-agenda-max-effort nil
  2376. "Maximum cumulated effort duration for the agenda.
  2377. This can be nil (no limit) or a number of minutes (as an integer)
  2378. or an alist of agenda types with an associated number of minutes
  2379. to limit entries to in this type."
  2380. :version "24.4"
  2381. :package-version '(Org . "8.0")
  2382. :group 'org-agenda-custom-commands
  2383. :type '(choice (symbol :tag "No limit" nil)
  2384. (integer :tag "Max number of minutes")
  2385. (repeat
  2386. (cons (choice :tag "Agenda type"
  2387. (const agenda)
  2388. (const todo)
  2389. (const tags)
  2390. (const search)
  2391. (const timeline))
  2392. (integer :tag "Max number of minutes")))))
  2393. (defvar org-agenda-keep-restricted-file-list nil)
  2394. (defvar org-keys nil)
  2395. (defvar org-match nil)
  2396. ;;;###autoload
  2397. (defun org-agenda (&optional arg org-keys restriction)
  2398. "Dispatch agenda commands to collect entries to the agenda buffer.
  2399. Prompts for a command to execute. Any prefix arg will be passed
  2400. on to the selected command. The default selections are:
  2401. a Call `org-agenda-list' to display the agenda for current day or week.
  2402. t Call `org-todo-list' to display the global todo list.
  2403. T Call `org-todo-list' to display the global todo list, select only
  2404. entries with a specific TODO keyword (the user gets a prompt).
  2405. m Call `org-tags-view' to display headlines with tags matching
  2406. a condition (the user is prompted for the condition).
  2407. M Like `m', but select only TODO entries, no ordinary headlines.
  2408. e Export views to associated files.
  2409. s Search entries for keywords.
  2410. S Search entries for keywords, only with TODO keywords.
  2411. / Multi occur across all agenda files and also files listed
  2412. in `org-agenda-text-search-extra-files'.
  2413. < Restrict agenda commands to buffer, subtree, or region.
  2414. Press several times to get the desired effect.
  2415. > Remove a previous restriction.
  2416. # List \"stuck\" projects.
  2417. ! Configure what \"stuck\" means.
  2418. C Configure custom agenda commands.
  2419. More commands can be added by configuring the variable
  2420. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2421. searches can be pre-defined in this way.
  2422. If the current buffer is in Org mode and visiting a file, you can also
  2423. first press `<' once to indicate that the agenda should be temporarily
  2424. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2425. Pressing `<' twice means to restrict to the current subtree or region
  2426. \(if active)."
  2427. (interactive "P")
  2428. (catch 'exit
  2429. (let* ((prefix-descriptions nil)
  2430. (org-agenda-buffer-name org-agenda-buffer-name)
  2431. (org-agenda-window-setup (if (equal (buffer-name)
  2432. org-agenda-buffer-name)
  2433. 'current-window
  2434. org-agenda-window-setup))
  2435. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2436. (org-agenda-custom-commands
  2437. ;; normalize different versions
  2438. (delq nil
  2439. (mapcar
  2440. (lambda (x)
  2441. (cond ((stringp (cdr x))
  2442. (push x prefix-descriptions)
  2443. nil)
  2444. ((stringp (nth 1 x)) x)
  2445. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2446. (t (cons (car x) (cons "" (cdr x))))))
  2447. org-agenda-custom-commands)))
  2448. (org-agenda-custom-commands
  2449. (org-contextualize-keys
  2450. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2451. (buf (current-buffer))
  2452. (bfn (buffer-file-name (buffer-base-buffer)))
  2453. entry key type org-match lprops ans)
  2454. ;; Turn off restriction unless there is an overriding one,
  2455. (unless org-agenda-overriding-restriction
  2456. (unless org-agenda-keep-restricted-file-list
  2457. ;; There is a request to keep the file list in place
  2458. (put 'org-agenda-files 'org-restrict nil))
  2459. (setq org-agenda-restrict nil)
  2460. (move-marker org-agenda-restrict-begin nil)
  2461. (move-marker org-agenda-restrict-end nil))
  2462. ;; Delete old local properties
  2463. (put 'org-agenda-redo-command 'org-lprops nil)
  2464. ;; Delete previously set last-arguments
  2465. (put 'org-agenda-redo-command 'last-args nil)
  2466. ;; Remember where this call originated
  2467. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2468. (unless org-keys
  2469. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2470. org-keys (car ans)
  2471. restriction (cdr ans)))
  2472. ;; If we have sticky agenda buffers, set a name for the buffer,
  2473. ;; depending on the invoking keys. The user may still set this
  2474. ;; as a command option, which will overwrite what we do here.
  2475. (if org-agenda-sticky
  2476. (setq org-agenda-buffer-name
  2477. (format "*Org Agenda(%s)*" org-keys)))
  2478. ;; Establish the restriction, if any
  2479. (when (and (not org-agenda-overriding-restriction) restriction)
  2480. (put 'org-agenda-files 'org-restrict (list bfn))
  2481. (cond
  2482. ((eq restriction 'region)
  2483. (setq org-agenda-restrict (current-buffer))
  2484. (move-marker org-agenda-restrict-begin (region-beginning))
  2485. (move-marker org-agenda-restrict-end (region-end)))
  2486. ((eq restriction 'subtree)
  2487. (save-excursion
  2488. (setq org-agenda-restrict (current-buffer))
  2489. (org-back-to-heading t)
  2490. (move-marker org-agenda-restrict-begin (point))
  2491. (move-marker org-agenda-restrict-end
  2492. (progn (org-end-of-subtree t)))))))
  2493. ;; For example the todo list should not need it (but does...)
  2494. (cond
  2495. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2496. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2497. (progn
  2498. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2499. lprops (nth 4 entry))
  2500. (if org-agenda-sticky
  2501. (setq org-agenda-buffer-name
  2502. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2503. (format "*Org Agenda(%s)*" org-keys))))
  2504. (put 'org-agenda-redo-command 'org-lprops lprops)
  2505. (cond
  2506. ((eq type 'agenda)
  2507. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2508. ((eq type 'agenda*)
  2509. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2510. ((eq type 'alltodo)
  2511. (org-let lprops '(org-todo-list current-prefix-arg)))
  2512. ((eq type 'search)
  2513. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2514. ((eq type 'stuck)
  2515. (org-let lprops '(org-agenda-list-stuck-projects
  2516. current-prefix-arg)))
  2517. ((eq type 'tags)
  2518. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2519. ((eq type 'tags-todo)
  2520. (org-let lprops '(org-tags-view '(4) org-match)))
  2521. ((eq type 'todo)
  2522. (org-let lprops '(org-todo-list org-match)))
  2523. ((eq type 'tags-tree)
  2524. (org-check-for-org-mode)
  2525. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2526. ((eq type 'todo-tree)
  2527. (org-check-for-org-mode)
  2528. (org-let lprops
  2529. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2530. (regexp-quote org-match) "\\>"))))
  2531. ((eq type 'occur-tree)
  2532. (org-check-for-org-mode)
  2533. (org-let lprops '(org-occur org-match)))
  2534. ((functionp type)
  2535. (org-let lprops '(funcall type org-match)))
  2536. ((fboundp type)
  2537. (org-let lprops '(funcall type org-match)))
  2538. (t (user-error "Invalid custom agenda command type %s" type))))
  2539. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2540. ((equal org-keys "C")
  2541. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2542. (customize-variable 'org-agenda-custom-commands))
  2543. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2544. ((equal org-keys "s") (call-interactively 'org-search-view))
  2545. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2546. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2547. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2548. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2549. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2550. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2551. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2552. (add-hook
  2553. 'post-command-hook
  2554. (lambda ()
  2555. (unless (current-message)
  2556. (let* ((m (org-agenda-get-any-marker))
  2557. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2558. (when note
  2559. (message (concat
  2560. "FLAGGING-NOTE ([?] for more info): "
  2561. (org-add-props
  2562. (replace-regexp-in-string
  2563. "\\\\n" "//"
  2564. (copy-sequence note))
  2565. nil 'face 'org-warning)))))))
  2566. t t))
  2567. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2568. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2569. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2570. (t (user-error "Invalid agenda key"))))))
  2571. (defvar org-agenda-multi)
  2572. (defun org-agenda-append-agenda ()
  2573. "Append another agenda view to the current one.
  2574. This function allows interactive building of block agendas.
  2575. Agenda views are separated by `org-agenda-block-separator'."
  2576. (interactive)
  2577. (unless (derived-mode-p 'org-agenda-mode)
  2578. (user-error "Can only append from within agenda buffer"))
  2579. (let ((org-agenda-multi t))
  2580. (org-agenda)
  2581. (widen)
  2582. (org-agenda-finalize)
  2583. (setq buffer-read-only t)
  2584. (org-agenda-fit-window-to-buffer)))
  2585. (defun org-agenda-normalize-custom-commands (cmds)
  2586. "Normalize custom commands CMDS."
  2587. (delq nil
  2588. (mapcar
  2589. (lambda (x)
  2590. (cond ((stringp (cdr x)) nil)
  2591. ((stringp (nth 1 x)) x)
  2592. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2593. (t (cons (car x) (cons "" (cdr x))))))
  2594. cmds)))
  2595. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2596. "The user interface for selecting an agenda command."
  2597. (catch 'exit
  2598. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2599. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2600. (region-p (org-region-active-p))
  2601. (custom org-agenda-custom-commands)
  2602. (selstring "")
  2603. restriction second-time
  2604. c entry key type match prefixes rmheader header-end custom1 desc
  2605. line lines left right n n1)
  2606. (save-window-excursion
  2607. (delete-other-windows)
  2608. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2609. (erase-buffer)
  2610. (insert (eval-when-compile
  2611. (let ((header
  2612. "Press key for an agenda command:
  2613. -------------------------------- < Buffer, subtree/region restriction
  2614. a Agenda for current week or day > Remove restriction
  2615. t List of all TODO entries e Export agenda views
  2616. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2617. s Search for keywords M Like m, but only TODO entries
  2618. / Multi-occur S Like s, but only TODO entries
  2619. ? Find :FLAGGED: entries C Configure custom agenda commands
  2620. * Toggle sticky agenda views # List stuck projects (!=configure)
  2621. ")
  2622. (start 0))
  2623. (while (string-match
  2624. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2625. header start)
  2626. (setq start (match-end 0))
  2627. (add-text-properties (match-beginning 2) (match-end 2)
  2628. '(face bold) header))
  2629. header)))
  2630. (setq header-end (point-marker))
  2631. (while t
  2632. (setq custom1 custom)
  2633. (when (eq rmheader t)
  2634. (org-goto-line 1)
  2635. (re-search-forward ":" nil t)
  2636. (delete-region (match-end 0) (point-at-eol))
  2637. (forward-char 1)
  2638. (looking-at "-+")
  2639. (delete-region (match-end 0) (point-at-eol))
  2640. (move-marker header-end (match-end 0)))
  2641. (goto-char header-end)
  2642. (delete-region (point) (point-max))
  2643. ;; Produce all the lines that describe custom commands and prefixes
  2644. (setq lines nil)
  2645. (while (setq entry (pop custom1))
  2646. (setq key (car entry) desc (nth 1 entry)
  2647. type (nth 2 entry)
  2648. match (nth 3 entry))
  2649. (if (> (length key) 1)
  2650. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2651. (setq line
  2652. (format
  2653. "%-4s%-14s"
  2654. (org-add-props (copy-sequence key)
  2655. '(face bold))
  2656. (cond
  2657. ((string-match "\\S-" desc) desc)
  2658. ((eq type 'agenda) "Agenda for current week or day")
  2659. ((eq type 'agenda*) "Appointments for current week or day")
  2660. ((eq type 'alltodo) "List of all TODO entries")
  2661. ((eq type 'search) "Word search")
  2662. ((eq type 'stuck) "List of stuck projects")
  2663. ((eq type 'todo) "TODO keyword")
  2664. ((eq type 'tags) "Tags query")
  2665. ((eq type 'tags-todo) "Tags (TODO)")
  2666. ((eq type 'tags-tree) "Tags tree")
  2667. ((eq type 'todo-tree) "TODO kwd tree")
  2668. ((eq type 'occur-tree) "Occur tree")
  2669. ((functionp type) (if (symbolp type)
  2670. (symbol-name type)
  2671. "Lambda expression"))
  2672. (t "???"))))
  2673. (if org-agenda-menu-show-matcher
  2674. (setq line
  2675. (concat line ": "
  2676. (cond
  2677. ((stringp match)
  2678. (setq match (copy-sequence match))
  2679. (org-add-props match nil 'face 'org-warning))
  2680. ((listp type)
  2681. (format "set of %d commands" (length type))))))
  2682. (if (org-string-nw-p match)
  2683. (add-text-properties
  2684. 0 (length line) (list 'help-echo
  2685. (concat "Matcher: " match)) line)))
  2686. (push line lines)))
  2687. (setq lines (nreverse lines))
  2688. (when prefixes
  2689. (mapc (lambda (x)
  2690. (push
  2691. (format "%s %s"
  2692. (org-add-props (char-to-string x)
  2693. nil 'face 'bold)
  2694. (or (cdr (assoc (concat selstring
  2695. (char-to-string x))
  2696. prefix-descriptions))
  2697. "Prefix key"))
  2698. lines))
  2699. prefixes))
  2700. ;; Check if we should display in two columns
  2701. (if org-agenda-menu-two-columns
  2702. (progn
  2703. (setq n (length lines)
  2704. n1 (+ (/ n 2) (mod n 2))
  2705. right (nthcdr n1 lines)
  2706. left (copy-sequence lines))
  2707. (setcdr (nthcdr (1- n1) left) nil))
  2708. (setq left lines right nil))
  2709. (while left
  2710. (insert "\n" (pop left))
  2711. (when right
  2712. (if (< (current-column) 40)
  2713. (move-to-column 40 t)
  2714. (insert " "))
  2715. (insert (pop right))))
  2716. ;; Make the window the right size
  2717. (goto-char (point-min))
  2718. (if second-time
  2719. (if (not (pos-visible-in-window-p (point-max)))
  2720. (org-fit-window-to-buffer))
  2721. (setq second-time t)
  2722. (org-fit-window-to-buffer))
  2723. ;; Ask for selection
  2724. (message "Press key for agenda command%s:"
  2725. (if (or restrict-ok org-agenda-overriding-restriction)
  2726. (if org-agenda-overriding-restriction
  2727. " (restriction lock active)"
  2728. (if restriction
  2729. (format " (restricted to %s)" restriction)
  2730. " (unrestricted)"))
  2731. ""))
  2732. (setq c (read-char-exclusive))
  2733. (message "")
  2734. (cond
  2735. ((assoc (char-to-string c) custom)
  2736. (setq selstring (concat selstring (char-to-string c)))
  2737. (throw 'exit (cons selstring restriction)))
  2738. ((memq c prefixes)
  2739. (setq selstring (concat selstring (char-to-string c))
  2740. prefixes nil
  2741. rmheader (or rmheader t)
  2742. custom (delq nil (mapcar
  2743. (lambda (x)
  2744. (if (or (= (length (car x)) 1)
  2745. (/= (string-to-char (car x)) c))
  2746. nil
  2747. (cons (substring (car x) 1) (cdr x))))
  2748. custom))))
  2749. ((eq c ?*)
  2750. (call-interactively 'org-toggle-sticky-agenda)
  2751. (sit-for 2))
  2752. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2753. (message "Restriction is only possible in Org buffers")
  2754. (ding) (sit-for 1))
  2755. ((eq c ?1)
  2756. (org-agenda-remove-restriction-lock 'noupdate)
  2757. (setq restriction 'buffer))
  2758. ((eq c ?0)
  2759. (org-agenda-remove-restriction-lock 'noupdate)
  2760. (setq restriction (if region-p 'region 'subtree)))
  2761. ((eq c ?<)
  2762. (org-agenda-remove-restriction-lock 'noupdate)
  2763. (setq restriction
  2764. (cond
  2765. ((eq restriction 'buffer)
  2766. (if region-p 'region 'subtree))
  2767. ((memq restriction '(subtree region))
  2768. nil)
  2769. (t 'buffer))))
  2770. ((eq c ?>)
  2771. (org-agenda-remove-restriction-lock 'noupdate)
  2772. (setq restriction nil))
  2773. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2774. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2775. ((and (> (length selstring) 0) (eq c ?\d))
  2776. (delete-window)
  2777. (org-agenda-get-restriction-and-command prefix-descriptions))
  2778. ((equal c ?q) (error "Abort"))
  2779. (t (user-error "Invalid key %c" c))))))))
  2780. (defun org-agenda-fit-window-to-buffer ()
  2781. "Fit the window to the buffer size."
  2782. (and (memq org-agenda-window-setup '(reorganize-frame))
  2783. (fboundp 'fit-window-to-buffer)
  2784. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2785. (= (car org-agenda-window-frame-fractions) 1.0))
  2786. (delete-other-windows)
  2787. (org-fit-window-to-buffer
  2788. nil
  2789. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2790. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2791. (defvar org-cmd nil)
  2792. (defvar org-agenda-overriding-cmd nil)
  2793. (defvar org-agenda-overriding-arguments nil)
  2794. (defvar org-agenda-overriding-cmd-arguments nil)
  2795. (defun org-agenda-run-series (name series)
  2796. "Run agenda NAME as a SERIES of agenda commands."
  2797. (org-let (nth 1 series) '(org-agenda-prepare name))
  2798. ;; We need to reset agenda markers here, because when constructing a
  2799. ;; block agenda, the individual blocks do not do that.
  2800. (org-agenda-reset-markers)
  2801. (let* ((org-agenda-multi t)
  2802. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2803. (cmds (car series))
  2804. (gprops (nth 1 series))
  2805. match ;; The byte compiler incorrectly complains about this. Keep it!
  2806. org-cmd type lprops)
  2807. (while (setq org-cmd (pop cmds))
  2808. (setq type (car org-cmd))
  2809. (setq match (eval (nth 1 org-cmd)))
  2810. (setq lprops (nth 2 org-cmd))
  2811. (let ((org-agenda-overriding-arguments
  2812. (if (eq org-agenda-overriding-cmd org-cmd)
  2813. (or org-agenda-overriding-arguments
  2814. org-agenda-overriding-cmd-arguments))))
  2815. (cond
  2816. ((eq type 'agenda)
  2817. (org-let2 gprops lprops
  2818. '(call-interactively 'org-agenda-list)))
  2819. ((eq type 'agenda*)
  2820. (org-let2 gprops lprops
  2821. '(funcall 'org-agenda-list nil nil t)))
  2822. ((eq type 'alltodo)
  2823. (org-let2 gprops lprops
  2824. '(call-interactively 'org-todo-list)))
  2825. ((eq type 'search)
  2826. (org-let2 gprops lprops
  2827. '(org-search-view current-prefix-arg match nil)))
  2828. ((eq type 'stuck)
  2829. (org-let2 gprops lprops
  2830. '(call-interactively 'org-agenda-list-stuck-projects)))
  2831. ((eq type 'tags)
  2832. (org-let2 gprops lprops
  2833. '(org-tags-view current-prefix-arg match)))
  2834. ((eq type 'tags-todo)
  2835. (org-let2 gprops lprops
  2836. '(org-tags-view '(4) match)))
  2837. ((eq type 'todo)
  2838. (org-let2 gprops lprops
  2839. '(org-todo-list match)))
  2840. ((fboundp type)
  2841. (org-let2 gprops lprops
  2842. '(funcall type match)))
  2843. (t (error "Invalid type in command series")))))
  2844. (widen)
  2845. (let ((inhibit-read-only t))
  2846. (add-text-properties (point-min) (point-max)
  2847. `(org-series t org-series-redo-cmd ,redo)))
  2848. (setq org-agenda-redo-command redo)
  2849. (goto-char (point-min)))
  2850. (org-agenda-fit-window-to-buffer)
  2851. (org-let (nth 1 series) '(org-agenda-finalize)))
  2852. ;;;###autoload
  2853. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2854. "Run an agenda command in batch mode and send the result to STDOUT.
  2855. If CMD-KEY is a string of length 1, it is used as a key in
  2856. `org-agenda-custom-commands' and triggers this command. If it is a
  2857. longer string it is used as a tags/todo match string.
  2858. Parameters are alternating variable names and values that will be bound
  2859. before running the agenda command."
  2860. (org-eval-in-environment (org-make-parameter-alist parameters)
  2861. (let (org-agenda-sticky)
  2862. (if (> (length cmd-key) 1)
  2863. (org-tags-view nil cmd-key)
  2864. (org-agenda nil cmd-key))))
  2865. (set-buffer org-agenda-buffer-name)
  2866. (princ (buffer-string)))
  2867. (defvar org-agenda-info nil)
  2868. ;;;###autoload
  2869. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2870. "Run an agenda command in batch mode and send the result to STDOUT.
  2871. If CMD-KEY is a string of length 1, it is used as a key in
  2872. `org-agenda-custom-commands' and triggers this command. If it is a
  2873. longer string it is used as a tags/todo match string.
  2874. Parameters are alternating variable names and values that will be bound
  2875. before running the agenda command.
  2876. The output gives a line for each selected agenda item. Each
  2877. item is a list of comma-separated values, like this:
  2878. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2879. category The category of the item
  2880. head The headline, without TODO kwd, TAGS and PRIORITY
  2881. type The type of the agenda entry, can be
  2882. todo selected in TODO match
  2883. tagsmatch selected in tags match
  2884. diary imported from diary
  2885. deadline a deadline on given date
  2886. scheduled scheduled on given date
  2887. timestamp entry has timestamp on given date
  2888. closed entry was closed on given date
  2889. upcoming-deadline warning about deadline
  2890. past-scheduled forwarded scheduled item
  2891. block entry has date block including g. date
  2892. todo The todo keyword, if any
  2893. tags All tags including inherited ones, separated by colons
  2894. date The relevant date, like 2007-2-14
  2895. time The time, like 15:00-16:50
  2896. extra Sting with extra planning info
  2897. priority-l The priority letter if any was given
  2898. priority-n The computed numerical priority
  2899. agenda-day The day in the agenda where this is listed"
  2900. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2901. (org-make-parameter-alist parameters))
  2902. (if (> (length cmd-key) 2)
  2903. (org-tags-view nil cmd-key)
  2904. (org-agenda nil cmd-key)))
  2905. (set-buffer org-agenda-buffer-name)
  2906. (let* ((lines (org-split-string (buffer-string) "\n"))
  2907. line)
  2908. (while (setq line (pop lines))
  2909. (catch 'next
  2910. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2911. (setq org-agenda-info
  2912. (org-fix-agenda-info (text-properties-at 0 line)))
  2913. (princ
  2914. (mapconcat 'org-agenda-export-csv-mapper
  2915. '(org-category txt type todo tags date time extra
  2916. priority-letter priority agenda-day)
  2917. ","))
  2918. (princ "\n")))))
  2919. (defun org-fix-agenda-info (props)
  2920. "Make sure all properties on an agenda item have a canonical form.
  2921. This ensures the export commands can easily use it."
  2922. (let (tmp re)
  2923. (when (setq tmp (plist-get props 'tags))
  2924. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2925. (when (setq tmp (plist-get props 'date))
  2926. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2927. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2928. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2929. (setq tmp (calendar-date-string tmp)))
  2930. (setq props (plist-put props 'date tmp)))
  2931. (when (setq tmp (plist-get props 'day))
  2932. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2933. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2934. (setq tmp (calendar-date-string tmp)))
  2935. (setq props (plist-put props 'day tmp))
  2936. (setq props (plist-put props 'agenda-day tmp)))
  2937. (when (setq tmp (plist-get props 'txt))
  2938. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2939. (plist-put props 'priority-letter (match-string 1 tmp))
  2940. (setq tmp (replace-match "" t t tmp)))
  2941. (when (and (setq re (plist-get props 'org-todo-regexp))
  2942. (setq re (concat "\\`\\.*" re " ?"))
  2943. (let ((case-fold-search nil)) (string-match re tmp)))
  2944. (plist-put props 'todo (match-string 1 tmp))
  2945. (setq tmp (replace-match "" t t tmp)))
  2946. (plist-put props 'txt tmp)))
  2947. props)
  2948. (defun org-agenda-export-csv-mapper (prop)
  2949. (let ((res (plist-get org-agenda-info prop)))
  2950. (setq res
  2951. (cond
  2952. ((not res) "")
  2953. ((stringp res) res)
  2954. (t (prin1-to-string res))))
  2955. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2956. ;;;###autoload
  2957. (defun org-store-agenda-views (&rest parameters)
  2958. "Store agenda views."
  2959. (interactive)
  2960. (eval (list 'org-batch-store-agenda-views)))
  2961. ;;;###autoload
  2962. (defmacro org-batch-store-agenda-views (&rest parameters)
  2963. "Run all custom agenda commands that have a file argument."
  2964. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2965. (pop-up-frames nil)
  2966. (dir default-directory)
  2967. (pars (org-make-parameter-alist parameters))
  2968. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2969. (save-window-excursion
  2970. (while cmds
  2971. (setq cmd (pop cmds)
  2972. thiscmdkey (car cmd)
  2973. thiscmdcmd (cdr cmd)
  2974. match (nth 2 thiscmdcmd)
  2975. bufname (if org-agenda-sticky
  2976. (or (and (stringp match)
  2977. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2978. (format "*Org Agenda(%s)*" thiscmdkey))
  2979. org-agenda-buffer-name)
  2980. cmd-or-set (nth 2 cmd)
  2981. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2982. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2983. (if (stringp files) (setq files (list files)))
  2984. (when files
  2985. (org-eval-in-environment (append org-agenda-exporter-settings
  2986. opts pars)
  2987. (org-agenda nil thiscmdkey))
  2988. (set-buffer bufname)
  2989. (while files
  2990. (org-eval-in-environment (append org-agenda-exporter-settings
  2991. opts pars)
  2992. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2993. (and (get-buffer bufname)
  2994. (kill-buffer bufname)))))))
  2995. (defvar org-agenda-current-span nil
  2996. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2997. (defun org-agenda-mark-header-line (pos)
  2998. "Mark the line at POS as an agenda structure header."
  2999. (save-excursion
  3000. (goto-char pos)
  3001. (put-text-property (point-at-bol) (point-at-eol)
  3002. 'org-agenda-structural-header t)
  3003. (when org-agenda-title-append
  3004. (put-text-property (point-at-bol) (point-at-eol)
  3005. 'org-agenda-title-append org-agenda-title-append))))
  3006. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3007. (defvar org-agenda-write-buffer-name "Agenda View")
  3008. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3009. "Write the current buffer (an agenda view) as a file.
  3010. Depending on the extension of the file name, plain text (.txt),
  3011. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3012. If the extension is .ics, translate visible agenda into iCalendar
  3013. format. If the extension is .org, collect all subtrees
  3014. corresponding to the agenda entries and add them in an .org file.
  3015. With prefix argument OPEN, open the new file immediately. If
  3016. NOSETTINGS is given, do not scope the settings of
  3017. `org-agenda-exporter-settings' into the export commands. This is
  3018. used when the settings have already been scoped and we do not
  3019. wish to overrule other, higher priority settings. If
  3020. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3021. the agenda to write."
  3022. (interactive "FWrite agenda to file: \nP")
  3023. (if (or (not (file-writable-p file))
  3024. (and (file-exists-p file)
  3025. (if (called-interactively-p 'any)
  3026. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3027. (user-error "Cannot write agenda to file %s" file))
  3028. (org-let (if nosettings nil org-agenda-exporter-settings)
  3029. '(save-excursion
  3030. (save-window-excursion
  3031. (let ((bs (copy-sequence (buffer-string)))
  3032. (extension (file-name-extension file))
  3033. beg content)
  3034. (with-temp-buffer
  3035. (rename-buffer org-agenda-write-buffer-name t)
  3036. (set-buffer-modified-p nil)
  3037. (insert bs)
  3038. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3039. (run-hooks 'org-agenda-before-write-hook)
  3040. (cond
  3041. ((bound-and-true-p org-mobile-creating-agendas)
  3042. (org-mobile-write-agenda-for-mobile file))
  3043. ((string= "org" extension)
  3044. (let (content p m message-log-max)
  3045. (goto-char (point-min))
  3046. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3047. (goto-char p)
  3048. (setq m (get-text-property (point) 'org-hd-marker))
  3049. (when m
  3050. (push (save-excursion
  3051. (set-buffer (marker-buffer m))
  3052. (goto-char m)
  3053. (org-copy-subtree 1 nil t t)
  3054. org-subtree-clip)
  3055. content)))
  3056. (find-file file)
  3057. (erase-buffer)
  3058. (dolist (s content) (org-paste-subtree 1 s))
  3059. (write-file file)
  3060. (kill-buffer (current-buffer))
  3061. (message "Org file written to %s" file)))
  3062. ((member extension '("html" "htm"))
  3063. (require 'htmlize)
  3064. (set-buffer (htmlize-buffer (current-buffer)))
  3065. (when org-agenda-export-html-style
  3066. ;; replace <style> section with org-agenda-export-html-style
  3067. (goto-char (point-min))
  3068. (kill-region (- (search-forward "<style") 6)
  3069. (search-forward "</style>"))
  3070. (insert org-agenda-export-html-style))
  3071. (write-file file)
  3072. (kill-buffer (current-buffer))
  3073. (message "HTML written to %s" file))
  3074. ((string= "ps" extension)
  3075. (require 'ps-print)
  3076. (ps-print-buffer-with-faces file)
  3077. (message "Postscript written to %s" file))
  3078. ((string= "pdf" extension)
  3079. (require 'ps-print)
  3080. (ps-print-buffer-with-faces
  3081. (concat (file-name-sans-extension file) ".ps"))
  3082. (call-process "ps2pdf" nil nil nil
  3083. (expand-file-name
  3084. (concat (file-name-sans-extension file) ".ps"))
  3085. (expand-file-name file))
  3086. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3087. (message "PDF written to %s" file))
  3088. ((string= "ics" extension)
  3089. (require 'ox-icalendar)
  3090. (org-icalendar-export-current-agenda (expand-file-name file)))
  3091. (t
  3092. (let ((bs (buffer-string)))
  3093. (find-file file)
  3094. (erase-buffer)
  3095. (insert bs)
  3096. (save-buffer 0)
  3097. (kill-buffer (current-buffer))
  3098. (message "Plain text written to %s" file))))))))
  3099. (set-buffer (or agenda-bufname
  3100. (and (called-interactively-p 'any) (buffer-name))
  3101. org-agenda-buffer-name)))
  3102. (when open (org-open-file file)))
  3103. (defun org-agenda-remove-marked-text (property &optional value)
  3104. "Delete all text marked with VALUE of PROPERTY.
  3105. VALUE defaults to t."
  3106. (let (beg)
  3107. (setq value (or value t))
  3108. (while (setq beg (text-property-any (point-min) (point-max)
  3109. property value))
  3110. (delete-region
  3111. beg (or (next-single-property-change beg property)
  3112. (point-max))))))
  3113. (defun org-agenda-add-entry-text ()
  3114. "Add entry text to agenda lines.
  3115. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3116. entry text following headings shown in the agenda.
  3117. Drawers will be excluded, also the line with scheduling/deadline info."
  3118. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3119. (not (bound-and-true-p org-mobile-creating-agendas)))
  3120. (let (m txt)
  3121. (goto-char (point-min))
  3122. (while (not (eobp))
  3123. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3124. (beginning-of-line 2)
  3125. (setq txt (org-agenda-get-some-entry-text
  3126. m org-agenda-add-entry-text-maxlines " > "))
  3127. (end-of-line 1)
  3128. (if (string-match "\\S-" txt)
  3129. (insert "\n" txt)
  3130. (or (eobp) (forward-char 1))))))))
  3131. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3132. &rest keep)
  3133. "Extract entry text from MARKER, at most N-LINES lines.
  3134. This will ignore drawers etc, just get the text.
  3135. If INDENT is given, prefix every line with this string. If KEEP is
  3136. given, it is a list of symbols, defining stuff that should not be
  3137. removed from the entry content. Currently only `planning' is allowed here."
  3138. (let (txt drawer-re kwd-time-re ind)
  3139. (save-excursion
  3140. (with-current-buffer (marker-buffer marker)
  3141. (if (not (derived-mode-p 'org-mode))
  3142. (setq txt "")
  3143. (org-with-wide-buffer
  3144. (goto-char marker)
  3145. (end-of-line 1)
  3146. (setq txt (buffer-substring
  3147. (min (1+ (point)) (point-max))
  3148. (progn (outline-next-heading) (point)))
  3149. drawer-re org-drawer-regexp
  3150. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3151. ".*\n?"))
  3152. (with-temp-buffer
  3153. (insert txt)
  3154. (when org-agenda-add-entry-text-descriptive-links
  3155. (goto-char (point-min))
  3156. (while (org-activate-bracket-links (point-max))
  3157. (add-text-properties (match-beginning 0) (match-end 0)
  3158. '(face org-link))))
  3159. (goto-char (point-min))
  3160. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3161. (set-text-properties (match-beginning 0) (match-end 0)
  3162. nil))
  3163. (goto-char (point-min))
  3164. (while (re-search-forward drawer-re nil t)
  3165. (delete-region
  3166. (match-beginning 0)
  3167. (progn (re-search-forward
  3168. "^[ \t]*:END:.*\n?" nil 'move)
  3169. (point))))
  3170. (unless (member 'planning keep)
  3171. (goto-char (point-min))
  3172. (while (re-search-forward kwd-time-re nil t)
  3173. (replace-match "")))
  3174. (goto-char (point-min))
  3175. (when org-agenda-entry-text-exclude-regexps
  3176. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3177. (while (setq re (pop re-list))
  3178. (goto-char (point-min))
  3179. (while (re-search-forward re nil t)
  3180. (replace-match "")))))
  3181. (goto-char (point-max))
  3182. (skip-chars-backward " \t\n")
  3183. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3184. ;; find and remove min common indentation
  3185. (goto-char (point-min))
  3186. (untabify (point-min) (point-max))
  3187. (setq ind (org-get-indentation))
  3188. (while (not (eobp))
  3189. (unless (looking-at "[ \t]*$")
  3190. (setq ind (min ind (org-get-indentation))))
  3191. (beginning-of-line 2))
  3192. (goto-char (point-min))
  3193. (while (not (eobp))
  3194. (unless (looking-at "[ \t]*$")
  3195. (move-to-column ind)
  3196. (delete-region (point-at-bol) (point)))
  3197. (beginning-of-line 2))
  3198. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3199. (goto-char (point-min))
  3200. (when indent
  3201. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3202. (replace-match indent t t)))
  3203. (goto-char (point-min))
  3204. (while (looking-at "[ \t]*\n") (replace-match ""))
  3205. (goto-char (point-max))
  3206. (when (> (org-current-line)
  3207. n-lines)
  3208. (org-goto-line (1+ n-lines))
  3209. (backward-char 1))
  3210. (setq txt (buffer-substring (point-min) (point))))))))
  3211. txt))
  3212. (defun org-check-for-org-mode ()
  3213. "Make sure current buffer is in org-mode. Error if not."
  3214. (or (derived-mode-p 'org-mode)
  3215. (error "Cannot execute Org agenda command on buffer in %s"
  3216. major-mode)))
  3217. ;;; Agenda prepare and finalize
  3218. (defvar org-agenda-multi nil) ; dynamically scoped
  3219. (defvar org-agenda-pre-window-conf nil)
  3220. (defvar org-agenda-columns-active nil)
  3221. (defvar org-agenda-name nil)
  3222. (defvar org-agenda-tag-filter nil)
  3223. (defvar org-agenda-category-filter nil)
  3224. (defvar org-agenda-regexp-filter nil)
  3225. (defvar org-agenda-effort-filter nil)
  3226. (defvar org-agenda-top-headline-filter nil)
  3227. (defvar org-agenda-tag-filter-preset nil
  3228. "A preset of the tags filter used for secondary agenda filtering.
  3229. This must be a list of strings, each string must be a single tag preceded
  3230. by \"+\" or \"-\".
  3231. This variable should not be set directly, but agenda custom commands can
  3232. bind it in the options section. The preset filter is a global property of
  3233. the entire agenda view. In a block agenda, it will not work reliably to
  3234. define a filter for one of the individual blocks. You need to set it in
  3235. the global options and expect it to be applied to the entire view.")
  3236. (defvar org-agenda-category-filter-preset nil
  3237. "A preset of the category filter used for secondary agenda filtering.
  3238. This must be a list of strings, each string must be a single category
  3239. preceded by \"+\" or \"-\".
  3240. This variable should not be set directly, but agenda custom commands can
  3241. bind it in the options section. The preset filter is a global property of
  3242. the entire agenda view. In a block agenda, it will not work reliably to
  3243. define a filter for one of the individual blocks. You need to set it in
  3244. the global options and expect it to be applied to the entire view.")
  3245. (defvar org-agenda-regexp-filter-preset nil
  3246. "A preset of the regexp filter used for secondary agenda filtering.
  3247. This must be a list of strings, each string must be a single regexp
  3248. preceded by \"+\" or \"-\".
  3249. This variable should not be set directly, but agenda custom commands can
  3250. bind it in the options section. The preset filter is a global property of
  3251. the entire agenda view. In a block agenda, it will not work reliably to
  3252. define a filter for one of the individual blocks. You need to set it in
  3253. the global options and expect it to be applied to the entire view.")
  3254. (defvar org-agenda-effort-filter-preset nil
  3255. "A preset of the effort condition used for secondary agenda filtering.
  3256. This must be a list of strings, each string must be a single regexp
  3257. preceded by \"+\" or \"-\".
  3258. This variable should not be set directly, but agenda custom commands can
  3259. bind it in the options section. The preset filter is a global property of
  3260. the entire agenda view. In a block agenda, it will not work reliably to
  3261. define a filter for one of the individual blocks. You need to set it in
  3262. the global options and expect it to be applied to the entire view.")
  3263. (defun org-agenda-use-sticky-p ()
  3264. "Return non-nil if an agenda buffer named
  3265. `org-agenda-buffer-name' exists and should be shown instead of
  3266. generating a new one."
  3267. (and
  3268. ;; turned off by user
  3269. org-agenda-sticky
  3270. ;; For multi-agenda buffer already exists
  3271. (not org-agenda-multi)
  3272. ;; buffer found
  3273. (get-buffer org-agenda-buffer-name)
  3274. ;; C-u parameter is same as last call
  3275. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3276. (and
  3277. (equal current-prefix-arg
  3278. org-agenda-last-prefix-arg)
  3279. ;; In case user turned stickiness on, while having existing
  3280. ;; Agenda buffer active, don't reuse that buffer, because it
  3281. ;; does not have org variables local
  3282. org-agenda-this-buffer-is-sticky))))
  3283. (defun org-agenda-prepare-window (abuf filter-alist)
  3284. "Setup agenda buffer in the window.
  3285. ABUF is the buffer for the agenda window.
  3286. FILTER-ALIST is an alist of filters we need to apply when
  3287. `org-agenda-persistent-filter' is non-nil."
  3288. (let* ((awin (get-buffer-window abuf)) wconf)
  3289. (cond
  3290. ((equal (current-buffer) abuf) nil)
  3291. (awin (select-window awin))
  3292. ((not (setq wconf (current-window-configuration))))
  3293. ((eq org-agenda-window-setup 'current-window)
  3294. (pop-to-buffer-same-window abuf))
  3295. ((eq org-agenda-window-setup 'other-window)
  3296. (org-switch-to-buffer-other-window abuf))
  3297. ((eq org-agenda-window-setup 'other-frame)
  3298. (switch-to-buffer-other-frame abuf))
  3299. ((eq org-agenda-window-setup 'only-window)
  3300. (delete-other-windows)
  3301. (pop-to-buffer-same-window abuf))
  3302. ((eq org-agenda-window-setup 'reorganize-frame)
  3303. (delete-other-windows)
  3304. (org-switch-to-buffer-other-window abuf)))
  3305. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3306. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3307. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3308. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3309. ;; Additional test in case agenda is invoked from within agenda
  3310. ;; buffer via elisp link.
  3311. (unless (equal (current-buffer) abuf)
  3312. (pop-to-buffer-same-window abuf))
  3313. (setq org-agenda-pre-window-conf
  3314. (or wconf org-agenda-pre-window-conf))))
  3315. (defun org-agenda-prepare (&optional name)
  3316. (let ((filter-alist (if org-agenda-persistent-filter
  3317. (with-current-buffer
  3318. (get-buffer-create org-agenda-buffer-name)
  3319. (list `(tag . ,org-agenda-tag-filter)
  3320. `(re . ,org-agenda-regexp-filter)
  3321. `(effort . ,org-agenda-effort-filter)
  3322. `(cat . ,org-agenda-category-filter))))))
  3323. (if (org-agenda-use-sticky-p)
  3324. (progn
  3325. (put 'org-agenda-tag-filter :preset-filter nil)
  3326. (put 'org-agenda-category-filter :preset-filter nil)
  3327. (put 'org-agenda-regexp-filter :preset-filter nil)
  3328. ;; Popup existing buffer
  3329. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3330. filter-alist)
  3331. (message "Sticky Agenda buffer, use `r' to refresh")
  3332. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3333. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3334. (setq org-todo-keywords-for-agenda nil)
  3335. (put 'org-agenda-tag-filter :preset-filter
  3336. org-agenda-tag-filter-preset)
  3337. (put 'org-agenda-category-filter :preset-filter
  3338. org-agenda-category-filter-preset)
  3339. (put 'org-agenda-regexp-filter :preset-filter
  3340. org-agenda-regexp-filter-preset)
  3341. (put 'org-agenda-effort-filter :preset-filter
  3342. org-agenda-effort-filter-preset)
  3343. (if org-agenda-multi
  3344. (progn
  3345. (setq buffer-read-only nil)
  3346. (goto-char (point-max))
  3347. (unless (or (bobp) org-agenda-compact-blocks
  3348. (not org-agenda-block-separator))
  3349. (insert "\n"
  3350. (if (stringp org-agenda-block-separator)
  3351. org-agenda-block-separator
  3352. (make-string (window-width) org-agenda-block-separator))
  3353. "\n"))
  3354. (narrow-to-region (point) (point-max)))
  3355. (setq org-done-keywords-for-agenda nil)
  3356. ;; Setting any org variables that are in org-agenda-local-vars
  3357. ;; list need to be done after the prepare call
  3358. (org-agenda-prepare-window
  3359. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3360. (setq buffer-read-only nil)
  3361. (org-agenda-reset-markers)
  3362. (let ((inhibit-read-only t)) (erase-buffer))
  3363. (org-agenda-mode)
  3364. (setq org-agenda-buffer (current-buffer))
  3365. (setq org-agenda-contributing-files nil)
  3366. (setq org-agenda-columns-active nil)
  3367. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3368. (setq org-todo-keywords-for-agenda
  3369. (org-uniquify org-todo-keywords-for-agenda))
  3370. (setq org-done-keywords-for-agenda
  3371. (org-uniquify org-done-keywords-for-agenda))
  3372. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3373. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3374. (and name (not org-agenda-name)
  3375. (setq-local org-agenda-name name)))
  3376. (setq buffer-read-only nil))))
  3377. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3378. (defun org-agenda-finalize ()
  3379. "Finishing touch for the agenda buffer, called just before displaying it."
  3380. (unless org-agenda-multi
  3381. (save-excursion
  3382. (let ((inhibit-read-only t))
  3383. (goto-char (point-min))
  3384. (save-excursion
  3385. (while (org-activate-bracket-links (point-max))
  3386. (add-text-properties (match-beginning 0) (match-end 0)
  3387. '(face org-link))))
  3388. (save-excursion
  3389. (while (org-activate-plain-links (point-max))
  3390. (add-text-properties (match-beginning 0) (match-end 0)
  3391. '(face org-link))))
  3392. (unless (eq org-agenda-remove-tags t)
  3393. (org-agenda-align-tags))
  3394. (unless org-agenda-with-colors
  3395. (remove-text-properties (point-min) (point-max) '(face nil)))
  3396. (if (and (boundp 'org-agenda-overriding-columns-format)
  3397. org-agenda-overriding-columns-format)
  3398. (setq-local org-agenda-overriding-columns-format
  3399. org-agenda-overriding-columns-format))
  3400. (if (and (boundp 'org-agenda-view-columns-initially)
  3401. org-agenda-view-columns-initially)
  3402. (org-agenda-columns))
  3403. (when org-agenda-fontify-priorities
  3404. (org-agenda-fontify-priorities))
  3405. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3406. (org-agenda-dim-blocked-tasks))
  3407. (org-agenda-mark-clocking-task)
  3408. (when org-agenda-entry-text-mode
  3409. (org-agenda-entry-text-hide)
  3410. (org-agenda-entry-text-show))
  3411. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3412. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3413. (org-habit-insert-consistency-graphs))
  3414. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3415. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3416. (and (listp org-agenda-show-inherited-tags)
  3417. (memq org-agenda-type org-agenda-show-inherited-tags))
  3418. (and (eq org-agenda-show-inherited-tags t)
  3419. (or (eq org-agenda-use-tag-inheritance t)
  3420. (and (listp org-agenda-use-tag-inheritance)
  3421. (not (memq org-agenda-type
  3422. org-agenda-use-tag-inheritance))))))
  3423. (let (mrk)
  3424. (save-excursion
  3425. (goto-char (point-min))
  3426. (while (equal (forward-line) 0)
  3427. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3428. (put-text-property (point-at-bol) (point-at-eol)
  3429. 'tags (org-with-point-at mrk
  3430. (delete-dups
  3431. (mapcar 'downcase (org-get-tags-at))))))))))
  3432. (run-hooks 'org-agenda-finalize-hook)
  3433. (when org-agenda-top-headline-filter
  3434. (org-agenda-filter-top-headline-apply
  3435. org-agenda-top-headline-filter))
  3436. (when org-agenda-tag-filter
  3437. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3438. (when (get 'org-agenda-tag-filter :preset-filter)
  3439. (org-agenda-filter-apply
  3440. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3441. (when org-agenda-category-filter
  3442. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3443. (when (get 'org-agenda-category-filter :preset-filter)
  3444. (org-agenda-filter-apply
  3445. (get 'org-agenda-category-filter :preset-filter) 'category))
  3446. (when org-agenda-regexp-filter
  3447. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3448. (when (get 'org-agenda-regexp-filter :preset-filter)
  3449. (org-agenda-filter-apply
  3450. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3451. (when org-agenda-effort-filter
  3452. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3453. (when (get 'org-agenda-effort-filter :preset-filter)
  3454. (org-agenda-filter-apply
  3455. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3456. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3457. (defun org-agenda-mark-clocking-task ()
  3458. "Mark the current clock entry in the agenda if it is present."
  3459. ;; We need to widen when `org-agenda-finalize' is called from
  3460. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3461. (when (bound-and-true-p org-clock-current-task)
  3462. (save-restriction
  3463. (widen)
  3464. (org-agenda-unmark-clocking-task)
  3465. (when (marker-buffer org-clock-hd-marker)
  3466. (save-excursion
  3467. (goto-char (point-min))
  3468. (let (s ov)
  3469. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3470. (goto-char s)
  3471. (when (equal (org-get-at-bol 'org-hd-marker)
  3472. org-clock-hd-marker)
  3473. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3474. (overlay-put ov 'type 'org-agenda-clocking)
  3475. (overlay-put ov 'face 'org-agenda-clocking)
  3476. (overlay-put ov 'help-echo
  3477. "The clock is running in this item")))))))))
  3478. (defun org-agenda-unmark-clocking-task ()
  3479. "Unmark the current clocking task."
  3480. (mapc (lambda (o)
  3481. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3482. (delete-overlay o)))
  3483. (overlays-in (point-min) (point-max))))
  3484. (defun org-agenda-fontify-priorities ()
  3485. "Make highest priority lines bold, and lowest italic."
  3486. (interactive)
  3487. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3488. (delete-overlay o)))
  3489. (overlays-in (point-min) (point-max)))
  3490. (save-excursion
  3491. (let (b e p ov h l)
  3492. (goto-char (point-min))
  3493. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3494. (setq h (or (get-char-property (point) 'org-highest-priority)
  3495. org-highest-priority)
  3496. l (or (get-char-property (point) 'org-lowest-priority)
  3497. org-lowest-priority)
  3498. p (string-to-char (match-string 1))
  3499. b (match-beginning 0)
  3500. e (if (eq org-agenda-fontify-priorities 'cookies)
  3501. (match-end 0)
  3502. (point-at-eol))
  3503. ov (make-overlay b e))
  3504. (overlay-put
  3505. ov 'face
  3506. (let ((special-face
  3507. (cond ((org-face-from-face-or-color
  3508. 'priority 'org-priority
  3509. (cdr (assoc p org-priority-faces))))
  3510. ((and (listp org-agenda-fontify-priorities)
  3511. (org-face-from-face-or-color
  3512. 'priority 'org-priority
  3513. (cdr (assoc p org-agenda-fontify-priorities)))))
  3514. ((equal p l) 'italic)
  3515. ((equal p h) 'bold))))
  3516. (if special-face (list special-face 'org-priority) 'org-priority)))
  3517. (overlay-put ov 'org-type 'org-priority)))))
  3518. (defvar org-depend-tag-blocked)
  3519. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3520. "Dim currently blocked TODOs in the agenda display.
  3521. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3522. dimming them."
  3523. (interactive "P")
  3524. (when (called-interactively-p 'interactive)
  3525. (message "Dim or hide blocked tasks..."))
  3526. (dolist (o (overlays-in (point-min) (point-max)))
  3527. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3528. (delete-overlay o)))
  3529. (save-excursion
  3530. (let ((inhibit-read-only t)
  3531. (org-depend-tag-blocked nil)
  3532. org-blocked-by-checkboxes)
  3533. (goto-char (point-min))
  3534. (while (let ((pos (text-property-not-all
  3535. (point) (point-max) 'todo-state nil)))
  3536. (when pos (goto-char pos)))
  3537. (setq org-blocked-by-checkboxes nil)
  3538. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3539. (when (and (markerp marker)
  3540. (with-current-buffer (marker-buffer marker)
  3541. (save-excursion (goto-char marker)
  3542. (org-entry-blocked-p))))
  3543. ;; Entries blocked by checkboxes cannot be made invisible.
  3544. ;; See `org-agenda-dim-blocked-tasks' for details.
  3545. (let* ((really-invisible
  3546. (and (not org-blocked-by-checkboxes)
  3547. (or invisible (eq org-agenda-dim-blocked-tasks
  3548. 'invisible))))
  3549. (ov (make-overlay (if really-invisible (line-end-position 0)
  3550. (line-beginning-position))
  3551. (line-end-position))))
  3552. (if really-invisible (overlay-put ov 'invisible t)
  3553. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3554. (overlay-put ov 'org-type 'org-blocked-todo))))
  3555. (forward-line))))
  3556. (when (called-interactively-p 'interactive)
  3557. (message "Dim or hide blocked tasks...done")))
  3558. (defvar org-agenda-skip-function nil
  3559. "Function to be called at each match during agenda construction.
  3560. If this function returns nil, the current match should not be skipped.
  3561. Otherwise, the function must return a position from where the search
  3562. should be continued.
  3563. This may also be a Lisp form, it will be evaluated.
  3564. Never set this variable using `setq' or so, because then it will apply
  3565. to all future agenda commands. If you do want a global skipping condition,
  3566. use the option `org-agenda-skip-function-global' instead.
  3567. The correct usage for `org-agenda-skip-function' is to bind it with
  3568. `let' to scope it dynamically into the agenda-constructing command.
  3569. A good way to set it is through options in `org-agenda-custom-commands'.")
  3570. (defun org-agenda-skip ()
  3571. "Throw to `:skip' in places that should be skipped.
  3572. Also moves point to the end of the skipped region, so that search can
  3573. continue from there."
  3574. (let ((p (point-at-bol)) to)
  3575. (when (or
  3576. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3577. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3578. (get-text-property p :org-archived)
  3579. (org-end-of-subtree t))
  3580. (and org-agenda-skip-comment-trees
  3581. (get-text-property p :org-comment)
  3582. (org-end-of-subtree t))
  3583. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3584. (org-agenda-skip-eval org-agenda-skip-function)))
  3585. (goto-char to))
  3586. (org-in-src-block-p t))
  3587. (throw :skip t))))
  3588. (defun org-agenda-skip-eval (form)
  3589. "If FORM is a function or a list, call (or eval) it and return the result.
  3590. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3591. and match data are returned to the previous state no matter what these
  3592. functions do."
  3593. (let (fp)
  3594. (and form
  3595. (or (setq fp (functionp form))
  3596. (consp form))
  3597. (save-excursion
  3598. (save-match-data
  3599. (if fp
  3600. (funcall form)
  3601. (eval form)))))))
  3602. (defvar org-agenda-markers nil
  3603. "List of all currently active markers created by `org-agenda'.")
  3604. (defvar org-agenda-last-marker-time (float-time)
  3605. "Creation time of the last agenda marker.")
  3606. (defun org-agenda-new-marker (&optional pos)
  3607. "Return a new agenda marker.
  3608. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3609. these markers and resets them when they are no longer in use."
  3610. (let ((m (copy-marker (or pos (point)) t)))
  3611. (setq org-agenda-last-marker-time (float-time))
  3612. (if org-agenda-buffer
  3613. (with-current-buffer org-agenda-buffer
  3614. (push m org-agenda-markers))
  3615. (push m org-agenda-markers))
  3616. m))
  3617. (defun org-agenda-reset-markers ()
  3618. "Reset markers created by `org-agenda'."
  3619. (while org-agenda-markers
  3620. (move-marker (pop org-agenda-markers) nil)))
  3621. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3622. "Save relative positions of markers in region.
  3623. This check for agenda markers in all agenda buffers currently active."
  3624. (dolist (buf (buffer-list))
  3625. (with-current-buffer buf
  3626. (when (eq major-mode 'org-agenda-mode)
  3627. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3628. org-agenda-markers)))))
  3629. ;;; Entry text mode
  3630. (defun org-agenda-entry-text-show-here ()
  3631. "Add some text from the entry as context to the current line."
  3632. (let (m txt o)
  3633. (setq m (org-get-at-bol 'org-hd-marker))
  3634. (unless (marker-buffer m)
  3635. (error "No marker points to an entry here"))
  3636. (setq txt (concat "\n" (org-no-properties
  3637. (org-agenda-get-some-entry-text
  3638. m org-agenda-entry-text-maxlines
  3639. org-agenda-entry-text-leaders))))
  3640. (when (string-match "\\S-" txt)
  3641. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3642. (overlay-put o 'evaporate t)
  3643. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3644. (overlay-put o 'after-string txt))))
  3645. (defun org-agenda-entry-text-show ()
  3646. "Add entry context for all agenda lines."
  3647. (interactive)
  3648. (save-excursion
  3649. (goto-char (point-max))
  3650. (beginning-of-line 1)
  3651. (while (not (bobp))
  3652. (when (org-get-at-bol 'org-hd-marker)
  3653. (org-agenda-entry-text-show-here))
  3654. (beginning-of-line 0))))
  3655. (defun org-agenda-entry-text-hide ()
  3656. "Remove any shown entry context."
  3657. (delq nil
  3658. (mapcar (lambda (o)
  3659. (if (eq (overlay-get o 'org-overlay-type)
  3660. 'agenda-entry-content)
  3661. (progn (delete-overlay o) t)))
  3662. (overlays-in (point-min) (point-max)))))
  3663. (defun org-agenda-get-day-face (date)
  3664. "Return the face DATE should be displayed with."
  3665. (cond ((and (functionp org-agenda-day-face-function)
  3666. (funcall org-agenda-day-face-function date)))
  3667. ((org-agenda-today-p date) 'org-agenda-date-today)
  3668. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3669. 'org-agenda-date-weekend)
  3670. (t 'org-agenda-date)))
  3671. (defvar org-agenda-show-log-scoped)
  3672. ;;; Agenda Daily/Weekly
  3673. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3674. "Start day for the agenda view.
  3675. Custom commands can set this variable in the options section.
  3676. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3677. input allowed when reading a date through the Org calendar.
  3678. See the docstring of `org-read-date' for details.")
  3679. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3680. (defvar org-arg-loc nil) ; local variable
  3681. (defvar org-agenda-buffer-tmp-name nil)
  3682. ;;;###autoload
  3683. (defun org-agenda-list (&optional arg start-day span with-hour)
  3684. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3685. The view will be for the current day or week, but from the overview buffer
  3686. you will be able to go to other days/weeks.
  3687. With a numeric prefix argument in an interactive call, the agenda will
  3688. span ARG days. Lisp programs should instead specify SPAN to change
  3689. the number of days. SPAN defaults to `org-agenda-span'.
  3690. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3691. given in `org-agenda-start-on-weekday'.
  3692. When WITH-HOUR is non-nil, only include scheduled and deadline
  3693. items if they have an hour specification like [h]h:mm."
  3694. (interactive "P")
  3695. (if org-agenda-overriding-arguments
  3696. (setq arg (car org-agenda-overriding-arguments)
  3697. start-day (nth 1 org-agenda-overriding-arguments)
  3698. span (nth 2 org-agenda-overriding-arguments)))
  3699. (if (and (integerp arg) (> arg 0))
  3700. (setq span arg arg nil))
  3701. (catch 'exit
  3702. (setq org-agenda-buffer-name
  3703. (or org-agenda-buffer-tmp-name
  3704. (if org-agenda-sticky
  3705. (cond ((and org-keys (stringp org-match))
  3706. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3707. (org-keys
  3708. (format "*Org Agenda(%s)*" org-keys))
  3709. (t "*Org Agenda(a)*")))
  3710. org-agenda-buffer-name))
  3711. (org-agenda-prepare "Day/Week")
  3712. (setq start-day (or start-day org-agenda-start-day))
  3713. (if (stringp start-day)
  3714. ;; Convert to an absolute day number
  3715. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3716. (org-compile-prefix-format 'agenda)
  3717. (org-set-sorting-strategy 'agenda)
  3718. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3719. (today (org-today))
  3720. (sd (or start-day today))
  3721. (ndays (org-agenda-span-to-ndays span sd))
  3722. (org-agenda-start-on-weekday
  3723. (if (or (eq ndays 7) (eq ndays 14))
  3724. org-agenda-start-on-weekday))
  3725. (thefiles (org-agenda-files nil 'ifmode))
  3726. (files thefiles)
  3727. (start (if (or (null org-agenda-start-on-weekday)
  3728. (< ndays 7))
  3729. sd
  3730. (let* ((nt (calendar-day-of-week
  3731. (calendar-gregorian-from-absolute sd)))
  3732. (n1 org-agenda-start-on-weekday)
  3733. (d (- nt n1)))
  3734. (- sd (+ (if (< d 0) 7 0) d)))))
  3735. (day-numbers (list start))
  3736. (day-cnt 0)
  3737. (inhibit-redisplay (not debug-on-error))
  3738. (org-agenda-show-log-scoped org-agenda-show-log)
  3739. s e rtn rtnall file date d start-pos end-pos todayp
  3740. clocktable-start clocktable-end filter)
  3741. (setq org-agenda-redo-command
  3742. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3743. (dotimes (n (1- ndays))
  3744. (push (1+ (car day-numbers)) day-numbers))
  3745. (setq day-numbers (nreverse day-numbers))
  3746. (setq clocktable-start (car day-numbers)
  3747. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3748. (setq-local org-starting-day (car day-numbers))
  3749. (setq-local org-arg-loc arg)
  3750. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3751. (unless org-agenda-compact-blocks
  3752. (let* ((d1 (car day-numbers))
  3753. (d2 (org-last day-numbers))
  3754. (w1 (org-days-to-iso-week d1))
  3755. (w2 (org-days-to-iso-week d2)))
  3756. (setq s (point))
  3757. (if org-agenda-overriding-header
  3758. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3759. nil 'face 'org-agenda-structure) "\n")
  3760. (insert (org-agenda-span-name span)
  3761. "-agenda"
  3762. (if (< (- d2 d1) 350)
  3763. (if (= w1 w2)
  3764. (format " (W%02d)" w1)
  3765. (format " (W%02d-W%02d)" w1 w2))
  3766. "")
  3767. ":\n")))
  3768. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3769. 'org-date-line t))
  3770. (org-agenda-mark-header-line s))
  3771. (while (setq d (pop day-numbers))
  3772. (setq date (calendar-gregorian-from-absolute d)
  3773. s (point))
  3774. (if (or (setq todayp (= d today))
  3775. (and (not start-pos) (= d sd)))
  3776. (setq start-pos (point))
  3777. (if (and start-pos (not end-pos))
  3778. (setq end-pos (point))))
  3779. (setq files thefiles
  3780. rtnall nil)
  3781. (while (setq file (pop files))
  3782. (catch 'nextfile
  3783. (org-check-agenda-file file)
  3784. (let ((org-agenda-entry-types org-agenda-entry-types))
  3785. ;; Starred types override non-starred equivalents
  3786. (when (member :deadline* org-agenda-entry-types)
  3787. (setq org-agenda-entry-types
  3788. (delq :deadline org-agenda-entry-types)))
  3789. (when (member :scheduled* org-agenda-entry-types)
  3790. (setq org-agenda-entry-types
  3791. (delq :scheduled org-agenda-entry-types)))
  3792. ;; Honor with-hour
  3793. (when with-hour
  3794. (when (member :deadline org-agenda-entry-types)
  3795. (setq org-agenda-entry-types
  3796. (delq :deadline org-agenda-entry-types))
  3797. (push :deadline* org-agenda-entry-types))
  3798. (when (member :scheduled org-agenda-entry-types)
  3799. (setq org-agenda-entry-types
  3800. (delq :scheduled org-agenda-entry-types))
  3801. (push :scheduled* org-agenda-entry-types)))
  3802. (unless org-agenda-include-deadlines
  3803. (setq org-agenda-entry-types
  3804. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3805. (cond
  3806. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3807. (setq rtn (org-agenda-get-day-entries
  3808. file date :closed)))
  3809. (org-agenda-show-log-scoped
  3810. (setq rtn (apply 'org-agenda-get-day-entries
  3811. file date
  3812. (append '(:closed) org-agenda-entry-types))))
  3813. (t
  3814. (setq rtn (apply 'org-agenda-get-day-entries
  3815. file date
  3816. org-agenda-entry-types)))))
  3817. (setq rtnall (append rtnall rtn)))) ;; all entries
  3818. (if org-agenda-include-diary
  3819. (let ((org-agenda-search-headline-for-time t))
  3820. (require 'diary-lib)
  3821. (setq rtn (org-get-entries-from-diary date))
  3822. (setq rtnall (append rtnall rtn))))
  3823. (if (or rtnall org-agenda-show-all-dates)
  3824. (progn
  3825. (setq day-cnt (1+ day-cnt))
  3826. (insert
  3827. (if (stringp org-agenda-format-date)
  3828. (format-time-string org-agenda-format-date
  3829. (org-time-from-absolute date))
  3830. (funcall org-agenda-format-date date))
  3831. "\n")
  3832. (put-text-property s (1- (point)) 'face
  3833. (org-agenda-get-day-face date))
  3834. (put-text-property s (1- (point)) 'org-date-line t)
  3835. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3836. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3837. (when todayp
  3838. (put-text-property s (1- (point)) 'org-today t))
  3839. (setq rtnall
  3840. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3841. (if rtnall (insert ;; all entries
  3842. (org-agenda-finalize-entries rtnall 'agenda)
  3843. "\n"))
  3844. (put-text-property s (1- (point)) 'day d)
  3845. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3846. (when (and org-agenda-clockreport-mode clocktable-start)
  3847. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3848. ;; the above line is to ensure the restricted range!
  3849. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3850. tbl)
  3851. (setq p (org-plist-delete p :block))
  3852. (setq p (plist-put p :tstart clocktable-start))
  3853. (setq p (plist-put p :tend clocktable-end))
  3854. (setq p (plist-put p :scope 'agenda))
  3855. (setq tbl (apply 'org-clock-get-clocktable p))
  3856. (insert tbl)))
  3857. (goto-char (point-min))
  3858. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3859. (unless (and (pos-visible-in-window-p (point-min))
  3860. (pos-visible-in-window-p (point-max)))
  3861. (goto-char (1- (point-max)))
  3862. (recenter -1)
  3863. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3864. (progn
  3865. (goto-char (or start-pos 1))
  3866. (recenter 1))))
  3867. (goto-char (or start-pos 1))
  3868. (add-text-properties (point-min) (point-max)
  3869. `(org-agenda-type agenda
  3870. org-last-args (,arg ,start-day ,span)
  3871. org-redo-cmd ,org-agenda-redo-command
  3872. org-series-cmd ,org-cmd))
  3873. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3874. (org-agenda-show-clocking-issues))
  3875. (org-agenda-finalize)
  3876. (setq buffer-read-only t)
  3877. (message ""))))
  3878. (defun org-agenda-ndays-to-span (n)
  3879. "Return a span symbol for a span of N days, or N if none matches."
  3880. (cond ((symbolp n) n)
  3881. ((= n 1) 'day)
  3882. ((= n 7) 'week)
  3883. ((= n 14) 'fortnight)
  3884. (t n)))
  3885. (defun org-agenda-span-to-ndays (span &optional start-day)
  3886. "Return ndays from SPAN, possibly starting at START-DAY.
  3887. START-DAY is an absolute time value."
  3888. (cond ((numberp span) span)
  3889. ((eq span 'day) 1)
  3890. ((eq span 'week) 7)
  3891. ((eq span 'fortnight) 14)
  3892. ((eq span 'month)
  3893. (let ((date (calendar-gregorian-from-absolute start-day)))
  3894. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3895. ((eq span 'year)
  3896. (let ((date (calendar-gregorian-from-absolute start-day)))
  3897. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3898. (defun org-agenda-span-name (span)
  3899. "Return a SPAN name."
  3900. (if (null span)
  3901. ""
  3902. (if (symbolp span)
  3903. (capitalize (symbol-name span))
  3904. (format "%d days" span))))
  3905. ;;; Agenda word search
  3906. (defvar org-agenda-search-history nil)
  3907. (defvar org-search-syntax-table nil
  3908. "Special syntax table for Org search.
  3909. In this table, we have single quotes not as word constituents, to
  3910. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3911. (defvar org-mode-syntax-table) ; From org.el
  3912. (defun org-search-syntax-table ()
  3913. (unless org-search-syntax-table
  3914. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3915. (modify-syntax-entry ?' "." org-search-syntax-table)
  3916. (modify-syntax-entry ?` "." org-search-syntax-table))
  3917. org-search-syntax-table)
  3918. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3919. ;;;###autoload
  3920. (defun org-search-view (&optional todo-only string edit-at)
  3921. "Show all entries that contain a phrase or words or regular expressions.
  3922. With optional prefix argument TODO-ONLY, only consider entries that are
  3923. TODO entries. The argument STRING can be used to pass a default search
  3924. string into this function. If EDIT-AT is non-nil, it means that the
  3925. user should get a chance to edit this string, with cursor at position
  3926. EDIT-AT.
  3927. The search string can be viewed either as a phrase that should be found as
  3928. is, or it can be broken into a number of snippets, each of which must match
  3929. in a Boolean way to select an entry. The default depends on the variable
  3930. `org-agenda-search-view-always-boolean'.
  3931. Even if this is turned off (the default) you can always switch to
  3932. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3933. The default is a direct search of the whole phrase, where each space in
  3934. the search string can expand to an arbitrary amount of whitespace,
  3935. including newlines.
  3936. If using a Boolean search, the search string is split on whitespace and
  3937. each snippet is searched separately, with logical AND to select an entry.
  3938. Words prefixed with a minus must *not* occur in the entry. Words without
  3939. a prefix or prefixed with a plus must occur in the entry. Matching is
  3940. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3941. match whole words, not parts of a word) if
  3942. `org-agenda-search-view-force-full-words' is set (default is nil).
  3943. Boolean search snippets enclosed by curly braces are interpreted as
  3944. regular expressions that must or (when preceded with \"-\") must not
  3945. match in the entry. Snippets enclosed into double quotes will be taken
  3946. as a whole, to include whitespace.
  3947. - If the search string starts with an asterisk, search only in headlines.
  3948. - If (possibly after the leading star) the search string starts with an
  3949. exclamation mark, this also means to look at TODO entries only, an effect
  3950. that can also be achieved with a prefix argument.
  3951. - If (possibly after star and exclamation mark) the search string starts
  3952. with a colon, this will mean that the (non-regexp) snippets of the
  3953. Boolean search must match as full words.
  3954. This command searches the agenda files, and in addition the files listed
  3955. in `org-agenda-text-search-extra-files'."
  3956. (interactive "P")
  3957. (if org-agenda-overriding-arguments
  3958. (setq todo-only (car org-agenda-overriding-arguments)
  3959. string (nth 1 org-agenda-overriding-arguments)
  3960. edit-at (nth 2 org-agenda-overriding-arguments)))
  3961. (let* ((props (list 'face nil
  3962. 'done-face 'org-agenda-done
  3963. 'org-not-done-regexp org-not-done-regexp
  3964. 'org-todo-regexp org-todo-regexp
  3965. 'org-complex-heading-regexp org-complex-heading-regexp
  3966. 'mouse-face 'highlight
  3967. 'help-echo (format "mouse-2 or RET jump to location")))
  3968. (full-words org-agenda-search-view-force-full-words)
  3969. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3970. regexp rtn rtnall files file pos inherited-tags
  3971. marker category level tags c neg re boolean
  3972. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3973. (unless (and (not edit-at)
  3974. (stringp string)
  3975. (string-match "\\S-" string))
  3976. (setq string (read-string
  3977. (if org-agenda-search-view-always-boolean
  3978. "[+-]Word/{Regexp} ...: "
  3979. "Phrase or [+-]Word/{Regexp} ...: ")
  3980. (cond
  3981. ((integerp edit-at) (cons string edit-at))
  3982. (edit-at string))
  3983. 'org-agenda-search-history)))
  3984. (catch 'exit
  3985. (if org-agenda-sticky
  3986. (setq org-agenda-buffer-name
  3987. (if (stringp string)
  3988. (format "*Org Agenda(%s:%s)*"
  3989. (or org-keys (or (and todo-only "S") "s")) string)
  3990. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3991. (org-agenda-prepare "SEARCH")
  3992. (org-compile-prefix-format 'search)
  3993. (org-set-sorting-strategy 'search)
  3994. (setq org-agenda-redo-command
  3995. (list 'org-search-view (if todo-only t nil)
  3996. (list 'if 'current-prefix-arg nil string)))
  3997. (setq org-agenda-query-string string)
  3998. (if (equal (string-to-char string) ?*)
  3999. (setq hdl-only t
  4000. words (substring string 1))
  4001. (setq words string))
  4002. (when (equal (string-to-char words) ?!)
  4003. (setq todo-only t
  4004. words (substring words 1)))
  4005. (when (equal (string-to-char words) ?:)
  4006. (setq full-words t
  4007. words (substring words 1)))
  4008. (if (or org-agenda-search-view-always-boolean
  4009. (member (string-to-char words) '(?- ?+ ?\{)))
  4010. (setq boolean t))
  4011. (setq words (org-split-string words))
  4012. (let (www w)
  4013. (while (setq w (pop words))
  4014. (while (and (string-match "\\\\\\'" w) words)
  4015. (setq w (concat (substring w 0 -1) " " (pop words))))
  4016. (push w www))
  4017. (setq words (nreverse www) www nil)
  4018. (while (setq w (pop words))
  4019. (when (and (string-match "\\`[-+]?{" w)
  4020. (not (string-match "}\\'" w)))
  4021. (while (and words (not (string-match "}\\'" (car words))))
  4022. (setq w (concat w " " (pop words))))
  4023. (setq w (concat w " " (pop words))))
  4024. (push w www))
  4025. (setq words (nreverse www)))
  4026. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4027. (when boolean
  4028. (let (wds w)
  4029. (while (setq w (pop words))
  4030. (if (or (equal (substring w 0 1) "\"")
  4031. (and (> (length w) 1)
  4032. (member (substring w 0 1) '("+" "-"))
  4033. (equal (substring w 1 2) "\"")))
  4034. (while (and words (not (equal (substring w -1) "\"")))
  4035. (setq w (concat w " " (pop words)))))
  4036. (and (string-match "\\`\\([-+]?\\)\"" w)
  4037. (setq w (replace-match "\\1" nil nil w)))
  4038. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4039. (push w wds))
  4040. (setq words (nreverse wds))))
  4041. (if boolean
  4042. (mapc (lambda (w)
  4043. (setq c (string-to-char w))
  4044. (if (equal c ?-)
  4045. (setq neg t w (substring w 1))
  4046. (if (equal c ?+)
  4047. (setq neg nil w (substring w 1))
  4048. (setq neg nil)))
  4049. (if (string-match "\\`{.*}\\'" w)
  4050. (setq re (substring w 1 -1))
  4051. (if full-words
  4052. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4053. (setq re (regexp-quote (downcase w)))))
  4054. (if neg (push re regexps-) (push re regexps+)))
  4055. words)
  4056. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4057. regexps+))
  4058. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4059. (if (not regexps+)
  4060. (setq regexp org-outline-regexp-bol)
  4061. (setq regexp (pop regexps+))
  4062. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4063. regexp))))
  4064. (setq files (org-agenda-files nil 'ifmode))
  4065. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4066. (pop org-agenda-text-search-extra-files)
  4067. (setq files (org-add-archive-files files)))
  4068. (setq files (append files org-agenda-text-search-extra-files)
  4069. rtnall nil)
  4070. (while (setq file (pop files))
  4071. (setq ee nil)
  4072. (catch 'nextfile
  4073. (org-check-agenda-file file)
  4074. (setq buffer (if (file-exists-p file)
  4075. (org-get-agenda-file-buffer file)
  4076. (error "No such file %s" file)))
  4077. (if (not buffer)
  4078. ;; If file does not exist, make sure an error message is sent
  4079. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4080. file))))
  4081. (with-current-buffer buffer
  4082. (with-syntax-table (org-search-syntax-table)
  4083. (unless (derived-mode-p 'org-mode)
  4084. (error "Agenda file %s is not in `org-mode'" file))
  4085. (let ((case-fold-search t))
  4086. (save-excursion
  4087. (save-restriction
  4088. (if (eq buffer org-agenda-restrict)
  4089. (narrow-to-region org-agenda-restrict-begin
  4090. org-agenda-restrict-end)
  4091. (widen))
  4092. (goto-char (point-min))
  4093. (unless (or (org-at-heading-p)
  4094. (outline-next-heading))
  4095. (throw 'nextfile t))
  4096. (goto-char (max (point-min) (1- (point))))
  4097. (while (re-search-forward regexp nil t)
  4098. (org-back-to-heading t)
  4099. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4100. (> (org-reduced-level (org-outline-level))
  4101. org-agenda-search-view-max-outline-level)
  4102. (forward-line -1)
  4103. (org-back-to-heading t)))
  4104. (skip-chars-forward "* ")
  4105. (setq beg (point-at-bol)
  4106. beg1 (point)
  4107. end (progn
  4108. (outline-next-heading)
  4109. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4110. (> (org-reduced-level (org-outline-level))
  4111. org-agenda-search-view-max-outline-level)
  4112. (forward-line 1)
  4113. (outline-next-heading)))
  4114. (point)))
  4115. (catch :skip
  4116. (goto-char beg)
  4117. (org-agenda-skip)
  4118. (setq str (buffer-substring-no-properties
  4119. (point-at-bol)
  4120. (if hdl-only (point-at-eol) end)))
  4121. (mapc (lambda (wr) (when (string-match wr str)
  4122. (goto-char (1- end))
  4123. (throw :skip t)))
  4124. regexps-)
  4125. (mapc (lambda (wr) (unless (string-match wr str)
  4126. (goto-char (1- end))
  4127. (throw :skip t)))
  4128. (if todo-only
  4129. (cons (concat "^\\*+[ \t]+"
  4130. org-not-done-regexp)
  4131. regexps+)
  4132. regexps+))
  4133. (goto-char beg)
  4134. (setq marker (org-agenda-new-marker (point))
  4135. category (org-get-category)
  4136. level (make-string (org-reduced-level (org-outline-level)) ? )
  4137. inherited-tags
  4138. (or (eq org-agenda-show-inherited-tags 'always)
  4139. (and (listp org-agenda-show-inherited-tags)
  4140. (memq 'todo org-agenda-show-inherited-tags))
  4141. (and (eq org-agenda-show-inherited-tags t)
  4142. (or (eq org-agenda-use-tag-inheritance t)
  4143. (memq 'todo org-agenda-use-tag-inheritance))))
  4144. tags (org-get-tags-at nil (not inherited-tags))
  4145. txt (org-agenda-format-item
  4146. ""
  4147. (buffer-substring-no-properties
  4148. beg1 (point-at-eol))
  4149. level category tags t))
  4150. (org-add-props txt props
  4151. 'org-marker marker 'org-hd-marker marker
  4152. 'org-todo-regexp org-todo-regexp
  4153. 'level level
  4154. 'org-complex-heading-regexp org-complex-heading-regexp
  4155. 'priority 1000
  4156. 'type "search")
  4157. (push txt ee)
  4158. (goto-char (1- end))))))))))
  4159. (setq rtn (nreverse ee))
  4160. (setq rtnall (append rtnall rtn)))
  4161. (if org-agenda-overriding-header
  4162. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4163. nil 'face 'org-agenda-structure) "\n")
  4164. (insert "Search words: ")
  4165. (add-text-properties (point-min) (1- (point))
  4166. (list 'face 'org-agenda-structure))
  4167. (setq pos (point))
  4168. (insert string "\n")
  4169. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4170. (setq pos (point))
  4171. (unless org-agenda-multi
  4172. (insert (substitute-command-keys "\
  4173. Press `\\[org-agenda-manipulate-query-add]', \
  4174. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4175. `\\[org-agenda-manipulate-query-add-re]', \
  4176. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4177. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4178. (add-text-properties pos (1- (point))
  4179. (list 'face 'org-agenda-structure))))
  4180. (org-agenda-mark-header-line (point-min))
  4181. (when rtnall
  4182. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4183. (goto-char (point-min))
  4184. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4185. (add-text-properties (point-min) (point-max)
  4186. `(org-agenda-type search
  4187. org-last-args (,todo-only ,string ,edit-at)
  4188. org-redo-cmd ,org-agenda-redo-command
  4189. org-series-cmd ,org-cmd))
  4190. (org-agenda-finalize)
  4191. (setq buffer-read-only t))))
  4192. ;;; Agenda TODO list
  4193. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4194. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4195. (concat
  4196. (if (or (equal keywords "ALL") (not keywords))
  4197. (propertize "ALL" 'face 'warning)
  4198. (mapconcat
  4199. (lambda (kw)
  4200. (propertize kw 'face (org-get-todo-face kw)))
  4201. (org-split-string keywords "|")
  4202. "|"))
  4203. "\n"))
  4204. (defvar org-select-this-todo-keyword nil)
  4205. (defvar org-last-arg nil)
  4206. ;;;###autoload
  4207. (defun org-todo-list (&optional arg)
  4208. "Show all (not done) TODO entries from all agenda file in a single list.
  4209. The prefix arg can be used to select a specific TODO keyword and limit
  4210. the list to these. When using `\\[universal-argument]', you will be prompted
  4211. for a keyword. A numeric prefix directly selects the Nth keyword in
  4212. `org-todo-keywords-1'."
  4213. (interactive "P")
  4214. (if org-agenda-overriding-arguments
  4215. (setq arg org-agenda-overriding-arguments))
  4216. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4217. (let* ((today (org-today))
  4218. (date (calendar-gregorian-from-absolute today))
  4219. (kwds org-todo-keywords-for-agenda)
  4220. (completion-ignore-case t)
  4221. (org-select-this-todo-keyword
  4222. (if (stringp arg) arg
  4223. (and arg (integerp arg) (> arg 0)
  4224. (nth (1- arg) kwds))))
  4225. rtn rtnall files file pos)
  4226. (when (equal arg '(4))
  4227. (setq org-select-this-todo-keyword
  4228. (completing-read "Keyword (or KWD1|K2D2|...): "
  4229. (mapcar #'list kwds) nil nil)))
  4230. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4231. (catch 'exit
  4232. (if org-agenda-sticky
  4233. (setq org-agenda-buffer-name
  4234. (if (stringp org-select-this-todo-keyword)
  4235. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4236. org-select-this-todo-keyword)
  4237. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4238. (org-agenda-prepare "TODO")
  4239. (org-compile-prefix-format 'todo)
  4240. (org-set-sorting-strategy 'todo)
  4241. (setq org-agenda-redo-command
  4242. `(org-todo-list (or (and (numberp current-prefix-arg)
  4243. current-prefix-arg)
  4244. ,org-select-this-todo-keyword
  4245. current-prefix-arg ,arg)))
  4246. (setq files (org-agenda-files nil 'ifmode)
  4247. rtnall nil)
  4248. (while (setq file (pop files))
  4249. (catch 'nextfile
  4250. (org-check-agenda-file file)
  4251. (setq rtn (org-agenda-get-day-entries file date :todo))
  4252. (setq rtnall (append rtnall rtn))))
  4253. (if org-agenda-overriding-header
  4254. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4255. nil 'face 'org-agenda-structure) "\n")
  4256. (insert "Global list of TODO items of type: ")
  4257. (add-text-properties (point-min) (1- (point))
  4258. (list 'face 'org-agenda-structure
  4259. 'short-heading
  4260. (concat "ToDo: "
  4261. (or org-select-this-todo-keyword "ALL"))))
  4262. (org-agenda-mark-header-line (point-min))
  4263. (insert (org-agenda-propertize-selected-todo-keywords
  4264. org-select-this-todo-keyword))
  4265. (setq pos (point))
  4266. (unless org-agenda-multi
  4267. (insert (substitute-command-keys "Available with \
  4268. `N \\[org-agenda-redo]': (0)[ALL]"))
  4269. (let ((n 0) s)
  4270. (mapc (lambda (x)
  4271. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4272. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4273. (insert "\n "))
  4274. (insert " " s))
  4275. kwds))
  4276. (insert "\n"))
  4277. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4278. (org-agenda-mark-header-line (point-min))
  4279. (when rtnall
  4280. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4281. (goto-char (point-min))
  4282. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4283. (add-text-properties (point-min) (point-max)
  4284. `(org-agenda-type todo
  4285. org-last-args ,arg
  4286. org-redo-cmd ,org-agenda-redo-command
  4287. org-series-cmd ,org-cmd))
  4288. (org-agenda-finalize)
  4289. (setq buffer-read-only t))))
  4290. ;;; Agenda tags match
  4291. ;;;###autoload
  4292. (defun org-tags-view (&optional todo-only match)
  4293. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4294. The prefix arg TODO-ONLY limits the search to TODO entries."
  4295. (interactive "P")
  4296. (if org-agenda-overriding-arguments
  4297. (setq todo-only (car org-agenda-overriding-arguments)
  4298. match (nth 1 org-agenda-overriding-arguments)))
  4299. (let* ((org-tags-match-list-sublevels
  4300. org-tags-match-list-sublevels)
  4301. (completion-ignore-case t)
  4302. rtn rtnall files file pos matcher
  4303. buffer)
  4304. (when (and (stringp match) (not (string-match "\\S-" match)))
  4305. (setq match nil))
  4306. (catch 'exit
  4307. (if org-agenda-sticky
  4308. (setq org-agenda-buffer-name
  4309. (if (stringp match)
  4310. (format "*Org Agenda(%s:%s)*"
  4311. (or org-keys (or (and todo-only "M") "m")) match)
  4312. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4313. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4314. ;; expanding tags within `org-make-tags-matcher'
  4315. (org-agenda-prepare (concat "TAGS " match))
  4316. (setq org--matcher-tags-todo-only todo-only
  4317. matcher (org-make-tags-matcher match)
  4318. match (car matcher)
  4319. matcher (cdr matcher))
  4320. (org-compile-prefix-format 'tags)
  4321. (org-set-sorting-strategy 'tags)
  4322. (setq org-agenda-query-string match)
  4323. (setq org-agenda-redo-command
  4324. (list 'org-tags-view
  4325. `(quote ,org--matcher-tags-todo-only)
  4326. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4327. (setq files (org-agenda-files nil 'ifmode)
  4328. rtnall nil)
  4329. (while (setq file (pop files))
  4330. (catch 'nextfile
  4331. (org-check-agenda-file file)
  4332. (setq buffer (if (file-exists-p file)
  4333. (org-get-agenda-file-buffer file)
  4334. (error "No such file %s" file)))
  4335. (if (not buffer)
  4336. ;; If file does not exist, error message to agenda
  4337. (setq rtn (list
  4338. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4339. rtnall (append rtnall rtn))
  4340. (with-current-buffer buffer
  4341. (unless (derived-mode-p 'org-mode)
  4342. (error "Agenda file %s is not in `org-mode'" file))
  4343. (save-excursion
  4344. (save-restriction
  4345. (if (eq buffer org-agenda-restrict)
  4346. (narrow-to-region org-agenda-restrict-begin
  4347. org-agenda-restrict-end)
  4348. (widen))
  4349. (setq rtn (org-scan-tags 'agenda
  4350. matcher
  4351. org--matcher-tags-todo-only))
  4352. (setq rtnall (append rtnall rtn))))))))
  4353. (if org-agenda-overriding-header
  4354. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4355. nil 'face 'org-agenda-structure) "\n")
  4356. (insert "Headlines with TAGS match: ")
  4357. (add-text-properties (point-min) (1- (point))
  4358. (list 'face 'org-agenda-structure
  4359. 'short-heading
  4360. (concat "Match: " match)))
  4361. (setq pos (point))
  4362. (insert match "\n")
  4363. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4364. (setq pos (point))
  4365. (unless org-agenda-multi
  4366. (insert (substitute-command-keys
  4367. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4368. to search again with new search string\n")))
  4369. (add-text-properties pos (1- (point))
  4370. (list 'face 'org-agenda-structure)))
  4371. (org-agenda-mark-header-line (point-min))
  4372. (when rtnall
  4373. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4374. (goto-char (point-min))
  4375. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4376. (add-text-properties
  4377. (point-min) (point-max)
  4378. `(org-agenda-type tags
  4379. org-last-args (,org--matcher-tags-todo-only ,match)
  4380. org-redo-cmd ,org-agenda-redo-command
  4381. org-series-cmd ,org-cmd))
  4382. (org-agenda-finalize)
  4383. (setq buffer-read-only t))))
  4384. ;;; Agenda Finding stuck projects
  4385. (defvar org-agenda-skip-regexp nil
  4386. "Regular expression used in skipping subtrees for the agenda.
  4387. This is basically a temporary global variable that can be set and then
  4388. used by user-defined selections using `org-agenda-skip-function'.")
  4389. (defvar org-agenda-overriding-header nil
  4390. "When set during agenda, todo and tags searches it replaces the header.
  4391. This variable should not be set directly, but custom commands can bind it
  4392. in the options section.")
  4393. (defun org-agenda-skip-entry-if (&rest conditions)
  4394. "Skip entry if any of CONDITIONS is true.
  4395. See `org-agenda-skip-if' for details."
  4396. (org-agenda-skip-if nil conditions))
  4397. (defun org-agenda-skip-subtree-if (&rest conditions)
  4398. "Skip subtree if any of CONDITIONS is true.
  4399. See `org-agenda-skip-if' for details."
  4400. (org-agenda-skip-if t conditions))
  4401. (defun org-agenda-skip-if (subtree conditions)
  4402. "Checks current entity for CONDITIONS.
  4403. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4404. the entry (i.e. the text before the next heading) is checked.
  4405. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4406. from different tests. Valid conditions are:
  4407. scheduled Check if there is a scheduled cookie
  4408. notscheduled Check if there is no scheduled cookie
  4409. deadline Check if there is a deadline
  4410. notdeadline Check if there is no deadline
  4411. timestamp Check if there is a timestamp (also deadline or scheduled)
  4412. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4413. regexp Check if regexp matches
  4414. notregexp Check if regexp does not match.
  4415. todo Check if TODO keyword matches
  4416. nottodo Check if TODO keyword does not match
  4417. The regexp is taken from the conditions list, it must come right after
  4418. the `regexp' or `notregexp' element.
  4419. `todo' and `nottodo' accept as an argument a list of todo
  4420. keywords, which may include \"*\" to match any todo keyword.
  4421. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4422. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4423. Instead of a list, a keyword class may be given. For example:
  4424. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4425. would skip entries that haven't been marked with any of \"DONE\"
  4426. keywords. Possible classes are: `todo', `done', `any'.
  4427. If any of these conditions is met, this function returns the end point of
  4428. the entity, causing the search to continue from there. This is a function
  4429. that can be put into `org-agenda-skip-function' for the duration of a command."
  4430. (let (beg end m)
  4431. (org-back-to-heading t)
  4432. (setq beg (point)
  4433. end (if subtree
  4434. (progn (org-end-of-subtree t) (point))
  4435. (progn (outline-next-heading) (1- (point)))))
  4436. (goto-char beg)
  4437. (and
  4438. (or
  4439. (and (memq 'scheduled conditions)
  4440. (re-search-forward org-scheduled-time-regexp end t))
  4441. (and (memq 'notscheduled conditions)
  4442. (not (re-search-forward org-scheduled-time-regexp end t)))
  4443. (and (memq 'deadline conditions)
  4444. (re-search-forward org-deadline-time-regexp end t))
  4445. (and (memq 'notdeadline conditions)
  4446. (not (re-search-forward org-deadline-time-regexp end t)))
  4447. (and (memq 'timestamp conditions)
  4448. (re-search-forward org-ts-regexp end t))
  4449. (and (memq 'nottimestamp conditions)
  4450. (not (re-search-forward org-ts-regexp end t)))
  4451. (and (setq m (memq 'regexp conditions))
  4452. (stringp (nth 1 m))
  4453. (re-search-forward (nth 1 m) end t))
  4454. (and (setq m (memq 'notregexp conditions))
  4455. (stringp (nth 1 m))
  4456. (not (re-search-forward (nth 1 m) end t)))
  4457. (and (or
  4458. (setq m (memq 'nottodo conditions))
  4459. (setq m (memq 'todo-unblocked conditions))
  4460. (setq m (memq 'nottodo-unblocked conditions))
  4461. (setq m (memq 'todo conditions)))
  4462. (org-agenda-skip-if-todo m end)))
  4463. end)))
  4464. (defun org-agenda-skip-if-todo (args end)
  4465. "Helper function for `org-agenda-skip-if', do not use it directly.
  4466. ARGS is a list with first element either `todo', `nottodo',
  4467. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4468. a list of TODO keywords, or a state symbol `todo' or `done' or
  4469. `any'."
  4470. (let ((kw (car args))
  4471. (arg (cadr args))
  4472. todo-wds todo-re)
  4473. (setq todo-wds
  4474. (org-uniquify
  4475. (cond
  4476. ((listp arg) ;; list of keywords
  4477. (if (member "*" arg)
  4478. (mapcar 'substring-no-properties org-todo-keywords-1)
  4479. arg))
  4480. ((symbolp arg) ;; keyword class name
  4481. (cond
  4482. ((eq arg 'todo)
  4483. (org-delete-all org-done-keywords
  4484. (mapcar 'substring-no-properties
  4485. org-todo-keywords-1)))
  4486. ((eq arg 'done) org-done-keywords)
  4487. ((eq arg 'any)
  4488. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4489. (setq todo-re
  4490. (concat "^\\*+[ \t]+\\<\\("
  4491. (mapconcat 'identity todo-wds "\\|")
  4492. "\\)\\>"))
  4493. (cond
  4494. ((eq kw 'todo) (re-search-forward todo-re end t))
  4495. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4496. ((eq kw 'todo-unblocked)
  4497. (catch 'unblocked
  4498. (while (re-search-forward todo-re end t)
  4499. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4500. nil))
  4501. ((eq kw 'nottodo-unblocked)
  4502. (catch 'unblocked
  4503. (while (re-search-forward todo-re end t)
  4504. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4505. t))
  4506. )))
  4507. ;;;###autoload
  4508. (defun org-agenda-list-stuck-projects (&rest ignore)
  4509. "Create agenda view for projects that are stuck.
  4510. Stuck projects are project that have no next actions. For the definitions
  4511. of what a project is and how to check if it stuck, customize the variable
  4512. `org-stuck-projects'."
  4513. (interactive)
  4514. (let* ((org-agenda-overriding-header
  4515. (or org-agenda-overriding-header "List of stuck projects: "))
  4516. (matcher (nth 0 org-stuck-projects))
  4517. (todo (nth 1 org-stuck-projects))
  4518. (tags (nth 2 org-stuck-projects))
  4519. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4520. (todo-wds
  4521. (if (not (member "*" todo)) todo
  4522. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4523. (org-delete-all org-done-keywords-for-agenda
  4524. (copy-sequence org-todo-keywords-for-agenda))))
  4525. (todo-re (and todo
  4526. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4527. (mapconcat #'identity todo-wds "\\|"))))
  4528. (tags-re (cond ((null tags) nil)
  4529. ((member "*" tags)
  4530. (eval-when-compile
  4531. (concat org-outline-regexp-bol
  4532. ".*:[[:alnum:]_@#%]+:[ \t]*$")))
  4533. (tags (concat org-outline-regexp-bol
  4534. ".*:\\("
  4535. (mapconcat #'identity tags "\\|")
  4536. "\\):[[:alnum:]_@#%:]*[ \t]*$"))
  4537. (t nil)))
  4538. (re-list (delq nil (list todo-re tags-re gen-re)))
  4539. (skip-re
  4540. (if (null re-list)
  4541. (error "Missing information to identify unstuck projects")
  4542. (mapconcat #'identity re-list "\\|")))
  4543. (org-agenda-skip-function
  4544. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4545. ;; in the subtree.
  4546. `(lambda ()
  4547. (and (save-excursion
  4548. (let ((case-fold-search nil))
  4549. (re-search-forward
  4550. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4551. (progn (outline-next-heading) (point))))))
  4552. (org-tags-view nil matcher)
  4553. (setq org-agenda-buffer-name (buffer-name))
  4554. (with-current-buffer org-agenda-buffer-name
  4555. (setq org-agenda-redo-command
  4556. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4557. ;;; Diary integration
  4558. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4559. (defvar diary-list-entries-hook)
  4560. (defvar diary-time-regexp)
  4561. (defun org-get-entries-from-diary (date)
  4562. "Get the (Emacs Calendar) diary entries for DATE."
  4563. (require 'diary-lib)
  4564. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4565. (diary-display-function 'diary-fancy-display)
  4566. (pop-up-frames nil)
  4567. (diary-list-entries-hook
  4568. (cons 'org-diary-default-entry diary-list-entries-hook))
  4569. (diary-file-name-prefix nil) ; turn this feature off
  4570. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4571. entries
  4572. (org-disable-agenda-to-diary t))
  4573. (save-excursion
  4574. (save-window-excursion
  4575. (funcall (if (fboundp 'diary-list-entries)
  4576. 'diary-list-entries 'list-diary-entries)
  4577. date 1)))
  4578. (if (not (get-buffer diary-fancy-buffer))
  4579. (setq entries nil)
  4580. (with-current-buffer diary-fancy-buffer
  4581. (setq buffer-read-only nil)
  4582. (if (zerop (buffer-size))
  4583. ;; No entries
  4584. (setq entries nil)
  4585. ;; Omit the date and other unnecessary stuff
  4586. (org-agenda-cleanup-fancy-diary)
  4587. ;; Add prefix to each line and extend the text properties
  4588. (if (zerop (buffer-size))
  4589. (setq entries nil)
  4590. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4591. (setq entries
  4592. (with-temp-buffer
  4593. (insert entries) (goto-char (point-min))
  4594. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4595. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4596. (replace-match (concat "; " (match-string 1)))))
  4597. (buffer-string)))))
  4598. (set-buffer-modified-p nil)
  4599. (kill-buffer diary-fancy-buffer)))
  4600. (when entries
  4601. (setq entries (org-split-string entries "\n"))
  4602. (setq entries
  4603. (mapcar
  4604. (lambda (x)
  4605. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4606. ;; Extend the text properties to the beginning of the line
  4607. (org-add-props x (text-properties-at (1- (length x)) x)
  4608. 'type "diary" 'date date 'face 'org-agenda-diary))
  4609. entries)))))
  4610. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4611. "Hook run when the fancy diary buffer is cleaned up.")
  4612. (defun org-agenda-cleanup-fancy-diary ()
  4613. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4614. This gets rid of the date, the underline under the date, and
  4615. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4616. date. It also removes lines that contain only whitespace."
  4617. (goto-char (point-min))
  4618. (if (looking-at ".*?:[ \t]*")
  4619. (progn
  4620. (replace-match "")
  4621. (re-search-forward "\n=+$" nil t)
  4622. (replace-match "")
  4623. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4624. (re-search-forward "\n=+$" nil t)
  4625. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4626. (goto-char (point-min))
  4627. (while (re-search-forward "^ +\n" nil t)
  4628. (replace-match ""))
  4629. (goto-char (point-min))
  4630. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4631. (replace-match ""))
  4632. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4633. ;; Make sure entries from the diary have the right text properties.
  4634. (eval-after-load "diary-lib"
  4635. '(if (boundp 'diary-modify-entry-list-string-function)
  4636. ;; We can rely on the hook, nothing to do
  4637. nil
  4638. ;; Hook not available, must use advice to make this work
  4639. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4640. "Make the position visible."
  4641. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4642. (stringp string)
  4643. buffer-file-name)
  4644. (setq string (org-modify-diary-entry-string string))))))
  4645. (defun org-modify-diary-entry-string (string)
  4646. "Add text properties to string, allowing Org to act on it."
  4647. (org-add-props string nil
  4648. 'mouse-face 'highlight
  4649. 'help-echo (if buffer-file-name
  4650. (format "mouse-2 or RET jump to diary file %s"
  4651. (abbreviate-file-name buffer-file-name))
  4652. "")
  4653. 'org-agenda-diary-link t
  4654. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4655. (defun org-diary-default-entry ()
  4656. "Add a dummy entry to the diary.
  4657. Needed to avoid empty dates which mess up holiday display."
  4658. ;; Catch the error if dealing with the new add-to-diary-alist
  4659. (when org-disable-agenda-to-diary
  4660. (condition-case nil
  4661. (org-add-to-diary-list original-date "Org mode dummy" "")
  4662. (error
  4663. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4664. (defun org-add-to-diary-list (&rest args)
  4665. (if (fboundp 'diary-add-to-list)
  4666. (apply 'diary-add-to-list args)
  4667. (apply 'add-to-diary-list args)))
  4668. (defvar org-diary-last-run-time nil)
  4669. ;;;###autoload
  4670. (defun org-diary (&rest args)
  4671. "Return diary information from org files.
  4672. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4673. It accesses org files and extracts information from those files to be
  4674. listed in the diary. The function accepts arguments specifying what
  4675. items should be listed. For a list of arguments allowed here, see the
  4676. variable `org-agenda-entry-types'.
  4677. The call in the diary file should look like this:
  4678. &%%(org-diary) ~/path/to/some/orgfile.org
  4679. Use a separate line for each org file to check. Or, if you omit the file name,
  4680. all files listed in `org-agenda-files' will be checked automatically:
  4681. &%%(org-diary)
  4682. If you don't give any arguments (as in the example above), the default value
  4683. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4684. So the example above may also be written as
  4685. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4686. The function expects the lisp variables `entry' and `date' to be provided
  4687. by the caller, because this is how the calendar works. Don't use this
  4688. function from a program - use `org-agenda-get-day-entries' instead."
  4689. (when (> (- (float-time)
  4690. org-agenda-last-marker-time)
  4691. 5)
  4692. ;; I am not sure if this works with sticky agendas, because the marker
  4693. ;; list is then no longer a global variable.
  4694. (org-agenda-reset-markers))
  4695. (org-compile-prefix-format 'agenda)
  4696. (org-set-sorting-strategy 'agenda)
  4697. (setq args (or args org-agenda-entry-types))
  4698. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4699. (list entry)
  4700. (org-agenda-files t)))
  4701. (time (float-time))
  4702. file rtn results)
  4703. (when (or (not org-diary-last-run-time)
  4704. (> (- time
  4705. org-diary-last-run-time)
  4706. 3))
  4707. (org-agenda-prepare-buffers files))
  4708. (setq org-diary-last-run-time time)
  4709. ;; If this is called during org-agenda, don't return any entries to
  4710. ;; the calendar. Org Agenda will list these entries itself.
  4711. (if org-disable-agenda-to-diary (setq files nil))
  4712. (while (setq file (pop files))
  4713. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4714. (setq results (append results rtn)))
  4715. (when results
  4716. (setq results
  4717. (mapcar (lambda (i) (replace-regexp-in-string
  4718. org-bracket-link-regexp "\\3" i)) results))
  4719. (concat (org-agenda-finalize-entries results) "\n"))))
  4720. ;;; Agenda entry finders
  4721. (defun org-agenda--timestamp-to-absolute (&rest args)
  4722. "Call `org-time-string-to-absolute' with ARGS.
  4723. However, throw `:skip' whenever an error is raised."
  4724. (condition-case e
  4725. (apply #'org-time-string-to-absolute args)
  4726. (org-diary-sexp-no-match (throw :skip nil))
  4727. (error
  4728. (message "%s; Skipping entry" (error-message-string e))
  4729. (throw :skip nil))))
  4730. (defun org-agenda-get-day-entries (file date &rest args)
  4731. "Does the work for `org-diary' and `org-agenda'.
  4732. FILE is the path to a file to be checked for entries. DATE is date like
  4733. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4734. which kind of entries should be extracted. For details about these, see
  4735. the documentation of `org-diary'."
  4736. (let* ((org-startup-folded nil)
  4737. (org-startup-align-all-tables nil)
  4738. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4739. (error "No such file %s" file))))
  4740. (if (not buffer)
  4741. ;; If file does not exist, signal it in diary nonetheless.
  4742. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4743. (with-current-buffer buffer
  4744. (unless (derived-mode-p 'org-mode)
  4745. (error "Agenda file %s is not in `org-mode'" file))
  4746. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4747. (setf org-agenda-current-date date)
  4748. (save-excursion
  4749. (save-restriction
  4750. (if (eq buffer org-agenda-restrict)
  4751. (narrow-to-region org-agenda-restrict-begin
  4752. org-agenda-restrict-end)
  4753. (widen))
  4754. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4755. ;; first in order to populate DEADLINES before passing it.
  4756. ;;
  4757. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4758. ;; guarding us from modifying `org-agenda-entry-types'.
  4759. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4760. (when (and (memq :scheduled args) (memq :scheduled* args))
  4761. (setf args (delq :scheduled* args)))
  4762. (cond
  4763. ((memq :deadline args)
  4764. (setf args (cons :deadline
  4765. (delq :deadline (delq :deadline* args)))))
  4766. ((memq :deadline* args)
  4767. (setf args (cons :deadline* (delq :deadline* args)))))
  4768. ;; Collect list of headlines. Return them flattened.
  4769. (let ((case-fold-search nil) results deadlines)
  4770. (dolist (arg args (apply #'nconc (nreverse results)))
  4771. (pcase arg
  4772. ((and :todo (guard (org-agenda-today-p date)))
  4773. (push (org-agenda-get-todos) results))
  4774. (:timestamp
  4775. (push (org-agenda-get-blocks) results)
  4776. (push (org-agenda-get-timestamps deadlines) results))
  4777. (:sexp
  4778. (push (org-agenda-get-sexps) results))
  4779. (:scheduled
  4780. (push (org-agenda-get-scheduled deadlines) results))
  4781. (:scheduled*
  4782. (push (org-agenda-get-scheduled deadlines t) results))
  4783. (:closed
  4784. (push (org-agenda-get-progress) results))
  4785. (:deadline
  4786. (setf deadlines (org-agenda-get-deadlines))
  4787. (push deadlines results))
  4788. (:deadline*
  4789. (setf deadlines (org-agenda-get-deadlines t))
  4790. (push deadlines results)))))))))))
  4791. (defsubst org-em (x y list)
  4792. "Is X or Y a member of LIST?"
  4793. (or (memq x list) (memq y list)))
  4794. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4795. (defvar org-agenda-sorting-strategy-selected nil)
  4796. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4797. "Retrieve timestamp information for sorting agenda views.
  4798. Given a point or marker POM, returns a cons cell of the timestamp
  4799. and the timestamp type relevant for the sorting strategy in
  4800. `org-agenda-sorting-strategy-selected'."
  4801. (let (ts ts-date-type)
  4802. (save-match-data
  4803. (cond ((org-em 'scheduled-up 'scheduled-down
  4804. org-agenda-sorting-strategy-selected)
  4805. (setq ts (org-entry-get pom "SCHEDULED")
  4806. ts-date-type " scheduled"))
  4807. ((org-em 'deadline-up 'deadline-down
  4808. org-agenda-sorting-strategy-selected)
  4809. (setq ts (org-entry-get pom "DEADLINE")
  4810. ts-date-type " deadline"))
  4811. ((org-em 'ts-up 'ts-down
  4812. org-agenda-sorting-strategy-selected)
  4813. (setq ts (org-entry-get pom "TIMESTAMP")
  4814. ts-date-type " timestamp"))
  4815. ((org-em 'tsia-up 'tsia-down
  4816. org-agenda-sorting-strategy-selected)
  4817. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4818. ts-date-type " timestamp_ia"))
  4819. ((org-em 'timestamp-up 'timestamp-down
  4820. org-agenda-sorting-strategy-selected)
  4821. (setq ts (or (org-entry-get pom "SCHEDULED")
  4822. (org-entry-get pom "DEADLINE")
  4823. (org-entry-get pom "TIMESTAMP")
  4824. (org-entry-get pom "TIMESTAMP_IA"))
  4825. ts-date-type ""))
  4826. (t (setq ts-date-type "")))
  4827. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4828. ts-date-type))))
  4829. (defun org-agenda-get-todos ()
  4830. "Return the TODO information for agenda display."
  4831. (let* ((props (list 'face nil
  4832. 'done-face 'org-agenda-done
  4833. 'org-not-done-regexp org-not-done-regexp
  4834. 'org-todo-regexp org-todo-regexp
  4835. 'org-complex-heading-regexp org-complex-heading-regexp
  4836. 'mouse-face 'highlight
  4837. 'help-echo
  4838. (format "mouse-2 or RET jump to org file %s"
  4839. (abbreviate-file-name buffer-file-name))))
  4840. (case-fold-search nil)
  4841. (regexp (format org-heading-keyword-regexp-format
  4842. (cond
  4843. ((and org-select-this-todo-keyword
  4844. (equal org-select-this-todo-keyword "*"))
  4845. org-todo-regexp)
  4846. (org-select-this-todo-keyword
  4847. (concat "\\("
  4848. (mapconcat 'identity
  4849. (org-split-string
  4850. org-select-this-todo-keyword
  4851. "|")
  4852. "\\|") "\\)"))
  4853. (t org-not-done-regexp))))
  4854. marker priority category level tags todo-state
  4855. ts-date ts-date-type ts-date-pair
  4856. ee txt beg end inherited-tags todo-state-end-pos)
  4857. (goto-char (point-min))
  4858. (while (re-search-forward regexp nil t)
  4859. (catch :skip
  4860. (save-match-data
  4861. (beginning-of-line)
  4862. (org-agenda-skip)
  4863. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4864. (unless (and (setq todo-state (org-get-todo-state))
  4865. (setq todo-state-end-pos (match-end 2)))
  4866. (goto-char end)
  4867. (throw :skip nil))
  4868. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4869. (goto-char (1+ beg))
  4870. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4871. (throw :skip nil)))
  4872. (goto-char (match-beginning 2))
  4873. (setq marker (org-agenda-new-marker (match-beginning 0))
  4874. category (org-get-category)
  4875. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4876. ts-date (car ts-date-pair)
  4877. ts-date-type (cdr ts-date-pair)
  4878. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4879. inherited-tags
  4880. (or (eq org-agenda-show-inherited-tags 'always)
  4881. (and (listp org-agenda-show-inherited-tags)
  4882. (memq 'todo org-agenda-show-inherited-tags))
  4883. (and (eq org-agenda-show-inherited-tags t)
  4884. (or (eq org-agenda-use-tag-inheritance t)
  4885. (memq 'todo org-agenda-use-tag-inheritance))))
  4886. tags (org-get-tags-at nil (not inherited-tags))
  4887. level (make-string (org-reduced-level (org-outline-level)) ? )
  4888. txt (org-agenda-format-item "" txt level category tags t)
  4889. priority (1+ (org-get-priority txt)))
  4890. (org-add-props txt props
  4891. 'org-marker marker 'org-hd-marker marker
  4892. 'priority priority
  4893. 'level level
  4894. 'ts-date ts-date
  4895. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4896. (push txt ee)
  4897. (if org-agenda-todo-list-sublevels
  4898. (goto-char todo-state-end-pos)
  4899. (org-end-of-subtree 'invisible))))
  4900. (nreverse ee)))
  4901. (defun org-agenda-todo-custom-ignore-p (time n)
  4902. "Check whether timestamp is farther away than n number of days.
  4903. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4904. `org-agenda-todo-ignore-scheduled' or
  4905. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4906. (let ((days (org-time-stamp-to-now
  4907. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4908. (if (>= n 0)
  4909. (>= days n)
  4910. (<= days n))))
  4911. ;;;###autoload
  4912. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4913. (&optional end)
  4914. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4915. (when (or org-agenda-todo-ignore-with-date
  4916. org-agenda-todo-ignore-scheduled
  4917. org-agenda-todo-ignore-deadlines
  4918. org-agenda-todo-ignore-timestamp)
  4919. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4920. (save-excursion
  4921. (or (and org-agenda-todo-ignore-with-date
  4922. (re-search-forward org-ts-regexp end t))
  4923. (and org-agenda-todo-ignore-scheduled
  4924. (re-search-forward org-scheduled-time-regexp end t)
  4925. (cond
  4926. ((eq org-agenda-todo-ignore-scheduled 'future)
  4927. (> (org-time-stamp-to-now
  4928. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4929. ((eq org-agenda-todo-ignore-scheduled 'past)
  4930. (<= (org-time-stamp-to-now
  4931. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4932. ((numberp org-agenda-todo-ignore-scheduled)
  4933. (org-agenda-todo-custom-ignore-p
  4934. (match-string 1) org-agenda-todo-ignore-scheduled))
  4935. (t)))
  4936. (and org-agenda-todo-ignore-deadlines
  4937. (re-search-forward org-deadline-time-regexp end t)
  4938. (cond
  4939. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4940. ((eq org-agenda-todo-ignore-deadlines 'far)
  4941. (not (org-deadline-close-p (match-string 1))))
  4942. ((eq org-agenda-todo-ignore-deadlines 'future)
  4943. (> (org-time-stamp-to-now
  4944. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4945. ((eq org-agenda-todo-ignore-deadlines 'past)
  4946. (<= (org-time-stamp-to-now
  4947. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4948. ((numberp org-agenda-todo-ignore-deadlines)
  4949. (org-agenda-todo-custom-ignore-p
  4950. (match-string 1) org-agenda-todo-ignore-deadlines))
  4951. (t (org-deadline-close-p (match-string 1)))))
  4952. (and org-agenda-todo-ignore-timestamp
  4953. (let ((buffer (current-buffer))
  4954. (regexp
  4955. (concat
  4956. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4957. (start (point)))
  4958. ;; Copy current buffer into a temporary one
  4959. (with-temp-buffer
  4960. (insert-buffer-substring buffer start end)
  4961. (goto-char (point-min))
  4962. ;; Delete SCHEDULED and DEADLINE items
  4963. (while (re-search-forward regexp end t)
  4964. (delete-region (match-beginning 0) (match-end 0)))
  4965. (goto-char (point-min))
  4966. ;; No search for timestamp left
  4967. (when (re-search-forward org-ts-regexp nil t)
  4968. (cond
  4969. ((eq org-agenda-todo-ignore-timestamp 'future)
  4970. (> (org-time-stamp-to-now
  4971. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4972. ((eq org-agenda-todo-ignore-timestamp 'past)
  4973. (<= (org-time-stamp-to-now
  4974. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4975. ((numberp org-agenda-todo-ignore-timestamp)
  4976. (org-agenda-todo-custom-ignore-p
  4977. (match-string 1) org-agenda-todo-ignore-timestamp))
  4978. (t))))))))))
  4979. (defun org-agenda-get-timestamps (&optional deadlines)
  4980. "Return the date stamp information for agenda display.
  4981. Optional argument DEADLINES is a list of deadline items to be
  4982. displayed in agenda view."
  4983. (let* ((props (list 'face 'org-agenda-calendar-event
  4984. 'org-not-done-regexp org-not-done-regexp
  4985. 'org-todo-regexp org-todo-regexp
  4986. 'org-complex-heading-regexp org-complex-heading-regexp
  4987. 'mouse-face 'highlight
  4988. 'help-echo
  4989. (format "mouse-2 or RET jump to Org file %s"
  4990. (abbreviate-file-name buffer-file-name))))
  4991. (current (calendar-absolute-from-gregorian date))
  4992. (today (org-today))
  4993. (deadline-position-alist
  4994. (mapcar (lambda (d)
  4995. (let ((m (get-text-property 0 'org-hd-marker d)))
  4996. (and m (marker-position m))))
  4997. deadlines))
  4998. ;; Match time-stamps set to current date, time-stamps with
  4999. ;; a repeater, and S-exp time-stamps.
  5000. (regexp
  5001. (concat
  5002. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5003. (regexp-quote
  5004. (substring
  5005. (format-time-string
  5006. (car org-time-stamp-formats)
  5007. (apply #'encode-time ; DATE bound by calendar
  5008. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5009. 1 11))
  5010. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5011. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5012. timestamp-items)
  5013. (goto-char (point-min))
  5014. (while (re-search-forward regexp nil t)
  5015. ;; Skip date ranges, scheduled and deadlines, which are handled
  5016. ;; specially. Also skip time-stamps before first headline as
  5017. ;; there would be no entry to add to the agenda. Eventually,
  5018. ;; ignore clock entries.
  5019. (catch :skip
  5020. (save-match-data
  5021. (when (or (org-at-date-range-p)
  5022. (org-at-planning-p)
  5023. (org-before-first-heading-p)
  5024. (and org-agenda-include-inactive-timestamps
  5025. (org-at-clock-log-p)))
  5026. (throw :skip nil))
  5027. (org-agenda-skip))
  5028. (let* ((pos (match-beginning 0))
  5029. (repeat (match-string 1))
  5030. (sexp-entry (match-string 3))
  5031. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5032. (save-excursion
  5033. (goto-char pos)
  5034. (looking-at org-ts-regexp-both)
  5035. (match-string 0))))
  5036. (todo-state (org-get-todo-state))
  5037. (warntime (get-text-property (point) 'org-appt-warntime))
  5038. (done? (member todo-state org-done-keywords)))
  5039. ;; Possibly skip done tasks.
  5040. (when (and done? org-agenda-skip-timestamp-if-done)
  5041. (throw :skip t))
  5042. ;; S-exp entry doesn't match current day: skip it.
  5043. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5044. (throw :skip nil))
  5045. (when repeat
  5046. (let* ((past
  5047. ;; A repeating time stamp is shown at its base
  5048. ;; date and every repeated date up to TODAY. If
  5049. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5050. ;; however, only the last repeat before today
  5051. ;; (inclusive) is shown.
  5052. (org-agenda--timestamp-to-absolute
  5053. repeat
  5054. (if (or (> current today)
  5055. (eq org-agenda-prefer-last-repeat t)
  5056. (member todo-state org-agenda-prefer-last-repeat))
  5057. today
  5058. current)
  5059. 'past (current-buffer) pos))
  5060. (future
  5061. ;; Display every repeated date past TODAY
  5062. ;; (exclusive) unless
  5063. ;; `org-agenda-show-future-repeats' is nil. If
  5064. ;; this variable is set to `next', only display
  5065. ;; the first repeated date after TODAY
  5066. ;; (exclusive).
  5067. (cond
  5068. ((<= current today) past)
  5069. ((not org-agenda-show-future-repeats) past)
  5070. (t
  5071. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5072. (1+ today)
  5073. current)))
  5074. (org-agenda--timestamp-to-absolute
  5075. repeat base 'future (current-buffer) pos))))))
  5076. (when (and (/= current past) (/= current future))
  5077. (throw :skip nil))))
  5078. (save-excursion
  5079. (re-search-backward org-outline-regexp-bol nil t)
  5080. ;; Possibly skip time-stamp when a deadline is set.
  5081. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5082. (assq (point) deadline-position-alist))
  5083. (throw :skip nil))
  5084. (let* ((category (org-get-category pos))
  5085. (inherited-tags
  5086. (or (eq org-agenda-show-inherited-tags 'always)
  5087. (and (consp org-agenda-show-inherited-tags)
  5088. (memq 'agenda org-agenda-show-inherited-tags))
  5089. (and (eq org-agenda-show-inherited-tags t)
  5090. (or (eq org-agenda-use-tag-inheritance t)
  5091. (memq 'agenda
  5092. org-agenda-use-tag-inheritance)))))
  5093. (tags (org-get-tags-at nil (not inherited-tags)))
  5094. (level (make-string (org-reduced-level (org-outline-level))
  5095. ?\s))
  5096. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5097. (match-string 1)))
  5098. (inactive? (= (char-after pos) ?\[))
  5099. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5100. (item
  5101. (org-agenda-format-item
  5102. (and inactive? org-agenda-inactive-leader)
  5103. head level category tags time-stamp org-ts-regexp habit?)))
  5104. (org-add-props item props
  5105. 'priority (if habit?
  5106. (org-habit-get-priority (org-habit-parse-todo))
  5107. (org-get-priority item))
  5108. 'org-marker (org-agenda-new-marker pos)
  5109. 'org-hd-marker (org-agenda-new-marker)
  5110. 'date date
  5111. 'level level
  5112. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5113. current)
  5114. 'todo-state todo-state
  5115. 'warntime warntime
  5116. 'type "timestamp")
  5117. (push item timestamp-items))))
  5118. (when org-agenda-skip-additional-timestamps-same-entry
  5119. (outline-next-heading))))
  5120. (nreverse timestamp-items)))
  5121. (defun org-agenda-get-sexps ()
  5122. "Return the sexp information for agenda display."
  5123. (require 'diary-lib)
  5124. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5125. 'mouse-face 'highlight
  5126. 'help-echo
  5127. (format "mouse-2 or RET jump to org file %s"
  5128. (abbreviate-file-name buffer-file-name))))
  5129. (regexp "^&?%%(")
  5130. marker category extra level ee txt tags entry
  5131. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5132. (goto-char (point-min))
  5133. (while (re-search-forward regexp nil t)
  5134. (catch :skip
  5135. (org-agenda-skip)
  5136. (setq beg (match-beginning 0))
  5137. (goto-char (1- (match-end 0)))
  5138. (setq b (point))
  5139. (forward-sexp 1)
  5140. (setq sexp (buffer-substring b (point)))
  5141. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5142. (org-trim (match-string 1))
  5143. ""))
  5144. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5145. (when result
  5146. (setq marker (org-agenda-new-marker beg)
  5147. level (make-string (org-reduced-level (org-outline-level)) ? )
  5148. category (org-get-category beg)
  5149. inherited-tags
  5150. (or (eq org-agenda-show-inherited-tags 'always)
  5151. (and (listp org-agenda-show-inherited-tags)
  5152. (memq 'agenda org-agenda-show-inherited-tags))
  5153. (and (eq org-agenda-show-inherited-tags t)
  5154. (or (eq org-agenda-use-tag-inheritance t)
  5155. (memq 'agenda org-agenda-use-tag-inheritance))))
  5156. tags (org-get-tags-at nil (not inherited-tags))
  5157. todo-state (org-get-todo-state)
  5158. warntime (get-text-property (point) 'org-appt-warntime)
  5159. extra nil)
  5160. (dolist (r (if (stringp result)
  5161. (list result)
  5162. result)) ;; we expect a list here
  5163. (when (and org-agenda-diary-sexp-prefix
  5164. (string-match org-agenda-diary-sexp-prefix r))
  5165. (setq extra (match-string 0 r)
  5166. r (replace-match "" nil nil r)))
  5167. (if (string-match "\\S-" r)
  5168. (setq txt r)
  5169. (setq txt "SEXP entry returned empty string"))
  5170. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5171. (org-add-props txt props 'org-marker marker
  5172. 'date date 'todo-state todo-state
  5173. 'level level 'type "sexp" 'warntime warntime)
  5174. (push txt ee)))))
  5175. (nreverse ee)))
  5176. ;; Calendar sanity: define some functions that are independent of
  5177. ;; `calendar-date-style'.
  5178. (defun org-anniversary (year month day &optional mark)
  5179. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5180. (with-no-warnings
  5181. (let ((calendar-date-style 'iso))
  5182. (diary-anniversary year month day mark))))
  5183. (defun org-cyclic (N year month day &optional mark)
  5184. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5185. (with-no-warnings
  5186. (let ((calendar-date-style 'iso))
  5187. (diary-cyclic N year month day mark))))
  5188. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5189. "Like `diary-block', but with fixed (ISO) order of arguments."
  5190. (with-no-warnings
  5191. (let ((calendar-date-style 'iso))
  5192. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5193. (defun org-date (year month day &optional mark)
  5194. "Like `diary-date', but with fixed (ISO) order of arguments."
  5195. (with-no-warnings
  5196. (let ((calendar-date-style 'iso))
  5197. (diary-date year month day mark))))
  5198. ;; Define the `org-class' function
  5199. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5200. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5201. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5202. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5203. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5204. `holidays', then any date that is known by the Emacs calendar to be a
  5205. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5206. then those holidays will be skipped."
  5207. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5208. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5209. (d (calendar-absolute-from-gregorian date))
  5210. (h (when skip-weeks (calendar-check-holidays date))))
  5211. (and
  5212. (<= date1 d)
  5213. (<= d date2)
  5214. (= (calendar-day-of-week date) dayname)
  5215. (or (not skip-weeks)
  5216. (progn
  5217. (require 'cal-iso)
  5218. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5219. (not (or (and h (memq 'holidays skip-weeks))
  5220. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5221. entry)))
  5222. (defalias 'org-get-closed 'org-agenda-get-progress)
  5223. (defun org-agenda-get-progress ()
  5224. "Return the logged TODO entries for agenda display."
  5225. (let* ((props (list 'mouse-face 'highlight
  5226. 'org-not-done-regexp org-not-done-regexp
  5227. 'org-todo-regexp org-todo-regexp
  5228. 'org-complex-heading-regexp org-complex-heading-regexp
  5229. 'help-echo
  5230. (format "mouse-2 or RET jump to org file %s"
  5231. (abbreviate-file-name buffer-file-name))))
  5232. (items (if (consp org-agenda-show-log-scoped)
  5233. org-agenda-show-log-scoped
  5234. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5235. '(clock)
  5236. org-agenda-log-mode-items)))
  5237. (parts
  5238. (delq nil
  5239. (list
  5240. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5241. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5242. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5243. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5244. (error "`org-agenda-log-mode-items' is empty")))
  5245. (regexp (concat
  5246. "\\(" parts-re "\\)"
  5247. " *\\["
  5248. (regexp-quote
  5249. (substring
  5250. (format-time-string
  5251. (car org-time-stamp-formats)
  5252. (apply 'encode-time ; DATE bound by calendar
  5253. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5254. 1 11))))
  5255. (org-agenda-search-headline-for-time nil)
  5256. marker hdmarker priority category level tags closedp
  5257. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5258. (goto-char (point-min))
  5259. (while (re-search-forward regexp nil t)
  5260. (catch :skip
  5261. (org-agenda-skip)
  5262. (setq marker (org-agenda-new-marker (match-beginning 0))
  5263. closedp (equal (match-string 1) org-closed-string)
  5264. statep (equal (string-to-char (match-string 1)) ?-)
  5265. clockp (not (or closedp statep))
  5266. state (and statep (match-string 2))
  5267. category (org-get-category (match-beginning 0))
  5268. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5269. (when (string-match "\\]" timestr)
  5270. ;; substring should only run to end of time stamp
  5271. (setq rest (substring timestr (match-end 0))
  5272. timestr (substring timestr 0 (match-end 0)))
  5273. (if (and (not closedp) (not statep)
  5274. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5275. rest))
  5276. (progn (setq timestr (concat (substring timestr 0 -1)
  5277. "-" (match-string 1 rest) "]"))
  5278. (setq clocked (match-string 2 rest)))
  5279. (setq clocked "-")))
  5280. (save-excursion
  5281. (setq extra
  5282. (cond
  5283. ((not org-agenda-log-mode-add-notes) nil)
  5284. (statep
  5285. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5286. (match-string 1)))
  5287. (clockp
  5288. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5289. (match-string 1)))))
  5290. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5291. (throw :skip nil)
  5292. (goto-char (match-beginning 0))
  5293. (setq hdmarker (org-agenda-new-marker)
  5294. inherited-tags
  5295. (or (eq org-agenda-show-inherited-tags 'always)
  5296. (and (listp org-agenda-show-inherited-tags)
  5297. (memq 'todo org-agenda-show-inherited-tags))
  5298. (and (eq org-agenda-show-inherited-tags t)
  5299. (or (eq org-agenda-use-tag-inheritance t)
  5300. (memq 'todo org-agenda-use-tag-inheritance))))
  5301. tags (org-get-tags-at nil (not inherited-tags))
  5302. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5303. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5304. (setq txt (match-string 1))
  5305. (when extra
  5306. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5307. (setq txt (concat (substring txt 0 (match-beginning 1))
  5308. " - " extra " " (match-string 2 txt)))
  5309. (setq txt (concat txt " - " extra))))
  5310. (setq txt (org-agenda-format-item
  5311. (cond
  5312. (closedp "Closed: ")
  5313. (statep (concat "State: (" state ")"))
  5314. (t (concat "Clocked: (" clocked ")")))
  5315. txt level category tags timestr)))
  5316. (setq priority 100000)
  5317. (org-add-props txt props
  5318. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5319. 'priority priority 'level level
  5320. 'type "closed" 'date date
  5321. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5322. (push txt ee))
  5323. (goto-char (point-at-eol))))
  5324. (nreverse ee)))
  5325. (defun org-agenda-show-clocking-issues ()
  5326. "Add overlays, showing issues with clocking.
  5327. See also the user option `org-agenda-clock-consistency-checks'."
  5328. (interactive)
  5329. (let* ((pl org-agenda-clock-consistency-checks)
  5330. (re (concat "^[ \t]*"
  5331. org-clock-string
  5332. "[ \t]+"
  5333. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5334. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5335. (tlstart 0.)
  5336. (tlend 0.)
  5337. (maxtime (org-duration-to-minutes
  5338. (or (plist-get pl :max-duration) "24:00")))
  5339. (mintime (org-duration-to-minutes
  5340. (or (plist-get pl :min-duration) 0)))
  5341. (maxgap (org-duration-to-minutes
  5342. ;; default 30:00 means never complain
  5343. (or (plist-get pl :max-gap) "30:00")))
  5344. (gapok (mapcar #'org-duration-to-minutes
  5345. (plist-get pl :gap-ok-around)))
  5346. (def-face (or (plist-get pl :default-face)
  5347. '((:background "DarkRed") (:foreground "white"))))
  5348. issue face m te ts dt ov)
  5349. (goto-char (point-min))
  5350. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5351. (setq issue nil face def-face)
  5352. (catch 'next
  5353. (setq m (org-get-at-bol 'org-marker)
  5354. te nil ts nil)
  5355. (unless (and m (markerp m))
  5356. (setq issue "No valid clock line") (throw 'next t))
  5357. (org-with-point-at m
  5358. (save-excursion
  5359. (goto-char (point-at-bol))
  5360. (unless (looking-at re)
  5361. (error "No valid Clock line")
  5362. (throw 'next t))
  5363. (unless (match-end 3)
  5364. (setq issue "No end time"
  5365. face (or (plist-get pl :no-end-time-face) face))
  5366. (throw 'next t))
  5367. (setq ts (match-string 1)
  5368. te (match-string 3)
  5369. ts (float-time
  5370. (apply #'encode-time (org-parse-time-string ts)))
  5371. te (float-time
  5372. (apply #'encode-time (org-parse-time-string te)))
  5373. dt (- te ts))))
  5374. (cond
  5375. ((> dt (* 60 maxtime))
  5376. ;; a very long clocking chunk
  5377. (setq issue (format "Clocking interval is very long: %s"
  5378. (org-duration-from-minutes (floor (/ dt 60.))))
  5379. face (or (plist-get pl :long-face) face)))
  5380. ((< dt (* 60 mintime))
  5381. ;; a very short clocking chunk
  5382. (setq issue (format "Clocking interval is very short: %s"
  5383. (org-duration-from-minutes (floor (/ dt 60.))))
  5384. face (or (plist-get pl :short-face) face)))
  5385. ((and (> tlend 0) (< ts tlend))
  5386. ;; Two clock entries are overlapping
  5387. (setq issue (format "Clocking overlap: %d minutes"
  5388. (/ (- tlend ts) 60))
  5389. face (or (plist-get pl :overlap-face) face)))
  5390. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5391. ;; There is a gap, lets see if we need to report it
  5392. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5393. (setq issue (format "Clocking gap: %d minutes"
  5394. (/ (- ts tlend) 60))
  5395. face (or (plist-get pl :gap-face) face))))
  5396. (t nil)))
  5397. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5398. (when issue
  5399. ;; OK, there was some issue, add an overlay to show the issue
  5400. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5401. (overlay-put ov 'before-string
  5402. (concat
  5403. (org-add-props
  5404. (format "%-43s" (concat " " issue))
  5405. nil
  5406. 'face face)
  5407. "\n"))
  5408. (overlay-put ov 'evaporate t)))))
  5409. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5410. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5411. (catch 'exit
  5412. (unless ok-list
  5413. ;; there are no OK times for gaps...
  5414. (throw 'exit nil))
  5415. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5416. ;; This is more than 24 hours, so it is OK.
  5417. ;; because we have at least one OK time, that must be in the
  5418. ;; 24 hour interval.
  5419. (throw 'exit t))
  5420. ;; We have a shorter gap.
  5421. ;; Now we have to get the minute of the day when these times are
  5422. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5423. (t2dec (decode-time (seconds-to-time t2)))
  5424. ;; compute the minute on the day
  5425. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5426. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5427. (when (< min2 min1)
  5428. ;; if min2 is smaller than min1, this means it is on the next day.
  5429. ;; Wrap it to after midnight.
  5430. (setq min2 (+ min2 1440)))
  5431. ;; Now check if any of the OK times is in the gap
  5432. (mapc (lambda (x)
  5433. ;; Wrap the time to after midnight if necessary
  5434. (if (< x min1) (setq x (+ x 1440)))
  5435. ;; Check if in interval
  5436. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5437. ok-list)
  5438. ;; Nope, this gap is not OK
  5439. nil)))
  5440. (defun org-agenda-get-deadlines (&optional with-hour)
  5441. "Return the deadline information for agenda display.
  5442. When WITH-HOUR is non-nil, only return deadlines with an hour
  5443. specification like [h]h:mm."
  5444. (let* ((props (list 'mouse-face 'highlight
  5445. 'org-not-done-regexp org-not-done-regexp
  5446. 'org-todo-regexp org-todo-regexp
  5447. 'org-complex-heading-regexp org-complex-heading-regexp
  5448. 'help-echo
  5449. (format "mouse-2 or RET jump to org file %s"
  5450. (abbreviate-file-name buffer-file-name))))
  5451. (regexp (if with-hour
  5452. org-deadline-time-hour-regexp
  5453. org-deadline-time-regexp))
  5454. (today (org-today))
  5455. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5456. (current (calendar-absolute-from-gregorian date))
  5457. deadline-items)
  5458. (goto-char (point-min))
  5459. (while (re-search-forward regexp nil t)
  5460. (catch :skip
  5461. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5462. (org-agenda-skip)
  5463. (let* ((s (match-string 1))
  5464. (pos (1- (match-beginning 1)))
  5465. (todo-state (save-match-data (org-get-todo-state)))
  5466. (done? (member todo-state org-done-keywords))
  5467. (sexp? (string-prefix-p "%%" s))
  5468. ;; DEADLINE is the deadline date for the entry. It is
  5469. ;; either the base date or the last repeat, according
  5470. ;; to `org-agenda-prefer-last-repeat'.
  5471. (deadline
  5472. (cond
  5473. (sexp? (org-agenda--timestamp-to-absolute s current))
  5474. ((or (eq org-agenda-prefer-last-repeat t)
  5475. (member todo-state org-agenda-prefer-last-repeat))
  5476. (org-agenda--timestamp-to-absolute
  5477. s today 'past (current-buffer) pos))
  5478. (t (org-agenda--timestamp-to-absolute s))))
  5479. ;; REPEAT is the future repeat closest from CURRENT,
  5480. ;; according to `org-agenda-show-future-repeats'. If
  5481. ;; the latter is nil, or if the time stamp has no
  5482. ;; repeat part, default to DEADLINE.
  5483. (repeat
  5484. (cond
  5485. (sexp? deadline)
  5486. ((<= current today) deadline)
  5487. ((not org-agenda-show-future-repeats) deadline)
  5488. (t
  5489. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5490. (1+ today)
  5491. current)))
  5492. (org-agenda--timestamp-to-absolute
  5493. s base 'future (current-buffer) pos)))))
  5494. (diff (- deadline current))
  5495. (suppress-prewarning
  5496. (let ((scheduled
  5497. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5498. (org-entry-get nil "SCHEDULED"))))
  5499. (cond
  5500. ((not scheduled) nil)
  5501. ;; The current item has a scheduled date, so
  5502. ;; evaluate its prewarning lead time.
  5503. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5504. ;; Use global prewarning-restart lead time.
  5505. org-agenda-skip-deadline-prewarning-if-scheduled)
  5506. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5507. 'pre-scheduled)
  5508. ;; Set pre-warning to no earlier than SCHEDULED.
  5509. (min (- deadline
  5510. (org-agenda--timestamp-to-absolute scheduled))
  5511. org-deadline-warning-days))
  5512. ;; Set pre-warning to deadline.
  5513. (t 0))))
  5514. (wdays (if suppress-prewarning
  5515. (let ((org-deadline-warning-days suppress-prewarning))
  5516. (org-get-wdays s))
  5517. (org-get-wdays s))))
  5518. ;; Display deadlines items at base date (DEADLINE), today,
  5519. ;; if deadline is overdue or if the expiration of the
  5520. ;; upcoming deadline is within WDAYS warning time. Also,
  5521. ;; show any repeat past today.
  5522. (when (or (and (/= current deadline)
  5523. (/= current today)
  5524. (/= current repeat))
  5525. (and today?
  5526. (> deadline current)
  5527. (> diff wdays)))
  5528. (throw :skip nil))
  5529. ;; Possibly skip done tasks.
  5530. (when (and done?
  5531. (or org-agenda-skip-deadline-if-done
  5532. (/= deadline current)))
  5533. (throw :skip nil))
  5534. (save-excursion
  5535. (re-search-backward "^\\*+[ \t]+" nil t)
  5536. (goto-char (match-end 0))
  5537. (let* ((category (org-get-category))
  5538. (level (make-string (org-reduced-level (org-outline-level))
  5539. ?\s))
  5540. (head (buffer-substring (point) (line-end-position)))
  5541. (inherited-tags
  5542. (or (eq org-agenda-show-inherited-tags 'always)
  5543. (and (listp org-agenda-show-inherited-tags)
  5544. (memq 'agenda org-agenda-show-inherited-tags))
  5545. (and (eq org-agenda-show-inherited-tags t)
  5546. (or (eq org-agenda-use-tag-inheritance t)
  5547. (memq 'agenda
  5548. org-agenda-use-tag-inheritance)))))
  5549. (tags (org-get-tags-at nil (not inherited-tags)))
  5550. (time
  5551. (cond
  5552. ;; No time of day designation if it is only
  5553. ;; a reminder.
  5554. ((and (/= current deadline) (/= current repeat)) nil)
  5555. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5556. (concat (substring s (match-beginning 1)) " "))
  5557. (t 'time)))
  5558. (item
  5559. (org-agenda-format-item
  5560. ;; Insert appropriate suffixes before deadlines.
  5561. ;; Those only apply to today agenda.
  5562. (pcase-let ((`(,now ,future ,past)
  5563. org-agenda-deadline-leaders))
  5564. (cond
  5565. ((and today? (< deadline today)) (format past (- diff)))
  5566. ((and today? (> deadline today)) (format future diff))
  5567. (t now)))
  5568. head level category tags time))
  5569. (face (org-agenda-deadline-face
  5570. (- 1 (/ (float diff) (max wdays 1)))))
  5571. (upcoming? (and today? (> deadline today)))
  5572. (warntime (get-text-property (point) 'org-appt-warntime)))
  5573. (org-add-props item props
  5574. 'org-marker (org-agenda-new-marker pos)
  5575. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5576. 'warntime warntime
  5577. 'level level
  5578. 'ts-date deadline
  5579. 'priority
  5580. ;; Adjust priority to today reminders about deadlines.
  5581. ;; Overdue deadlines get the highest priority
  5582. ;; increase, then imminent deadlines and eventually
  5583. ;; more distant deadlines.
  5584. (let ((adjust (if today? (- diff) 0)))
  5585. (+ adjust (org-get-priority item)))
  5586. 'todo-state todo-state
  5587. 'type (if upcoming? "upcoming-deadline" "deadline")
  5588. 'date (if upcoming? date deadline)
  5589. 'face (if done? 'org-agenda-done face)
  5590. 'undone-face face
  5591. 'done-face 'org-agenda-done)
  5592. (push item deadline-items))))))
  5593. (nreverse deadline-items)))
  5594. (defun org-agenda-deadline-face (fraction)
  5595. "Return the face to displaying a deadline item.
  5596. FRACTION is what fraction of the head-warning time has passed."
  5597. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5598. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5599. "Return the scheduled information for agenda display.
  5600. Optional argument DEADLINES is a list of deadline items to be
  5601. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5602. scheduled items with an hour specification like [h]h:mm."
  5603. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5604. 'org-todo-regexp org-todo-regexp
  5605. 'org-complex-heading-regexp org-complex-heading-regexp
  5606. 'done-face 'org-agenda-done
  5607. 'mouse-face 'highlight
  5608. 'help-echo
  5609. (format "mouse-2 or RET jump to Org file %s"
  5610. (abbreviate-file-name buffer-file-name))))
  5611. (regexp (if with-hour
  5612. org-scheduled-time-hour-regexp
  5613. org-scheduled-time-regexp))
  5614. (today (org-today))
  5615. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5616. (current (calendar-absolute-from-gregorian date))
  5617. (deadline-pos
  5618. (mapcar (lambda (d)
  5619. (let ((m (get-text-property 0 'org-hd-marker d)))
  5620. (and m (marker-position m))))
  5621. deadlines))
  5622. scheduled-items)
  5623. (goto-char (point-min))
  5624. (while (re-search-forward regexp nil t)
  5625. (catch :skip
  5626. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5627. (org-agenda-skip)
  5628. (let* ((s (match-string 1))
  5629. (pos (1- (match-beginning 1)))
  5630. (todo-state (save-match-data (org-get-todo-state)))
  5631. (donep (member todo-state org-done-keywords))
  5632. (sexp? (string-prefix-p "%%" s))
  5633. ;; SCHEDULE is the scheduled date for the entry. It is
  5634. ;; either the bare date or the last repeat, according
  5635. ;; to `org-agenda-prefer-last-repeat'.
  5636. (schedule
  5637. (cond
  5638. (sexp? (org-agenda--timestamp-to-absolute s current))
  5639. ((or (eq org-agenda-prefer-last-repeat t)
  5640. (member todo-state org-agenda-prefer-last-repeat))
  5641. (org-agenda--timestamp-to-absolute
  5642. s today 'past (current-buffer) pos))
  5643. (t (org-agenda--timestamp-to-absolute s))))
  5644. ;; REPEAT is the future repeat closest from CURRENT,
  5645. ;; according to `org-agenda-show-future-repeats'. If
  5646. ;; the latter is nil, or if the time stamp has no
  5647. ;; repeat part, default to SCHEDULE.
  5648. (repeat
  5649. (cond
  5650. (sexp? schedule)
  5651. ((<= current today) schedule)
  5652. ((not org-agenda-show-future-repeats) schedule)
  5653. (t
  5654. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5655. (1+ today)
  5656. current)))
  5657. (org-agenda--timestamp-to-absolute
  5658. s base 'future (current-buffer) pos)))))
  5659. (diff (- current schedule))
  5660. (warntime (get-text-property (point) 'org-appt-warntime))
  5661. (pastschedp (< schedule today))
  5662. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5663. (suppress-delay
  5664. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5665. (org-entry-get nil "DEADLINE"))))
  5666. (cond
  5667. ((not deadline) nil)
  5668. ;; The current item has a deadline date, so
  5669. ;; evaluate its delay time.
  5670. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5671. ;; Use global delay time.
  5672. (- org-agenda-skip-scheduled-delay-if-deadline))
  5673. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5674. 'post-deadline)
  5675. ;; Set delay to no later than DEADLINE.
  5676. (min (- schedule
  5677. (org-agenda--timestamp-to-absolute deadline))
  5678. org-scheduled-delay-days))
  5679. (t 0))))
  5680. (ddays
  5681. (cond
  5682. ;; Nullify delay when a repeater triggered already
  5683. ;; and the delay is of the form --Xd.
  5684. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5685. (> current schedule))
  5686. 0)
  5687. (suppress-delay
  5688. (let ((org-scheduled-delay-days suppress-delay))
  5689. (org-get-wdays s t t)))
  5690. (t (org-get-wdays s t)))))
  5691. ;; Display scheduled items at base date (SCHEDULE), today if
  5692. ;; scheduled before the current date, and at any repeat past
  5693. ;; today. However, skip delayed items and items that have
  5694. ;; been displayed for more than `org-scheduled-past-days'.
  5695. (unless (and todayp
  5696. habitp
  5697. (bound-and-true-p org-habit-show-all-today))
  5698. (when (or (and (> ddays 0) (< diff ddays))
  5699. (> diff org-scheduled-past-days)
  5700. (> schedule current)
  5701. (and (/= current schedule)
  5702. (/= current today)
  5703. (/= current repeat)))
  5704. (throw :skip nil)))
  5705. ;; Possibly skip done tasks.
  5706. (when (and donep
  5707. (or org-agenda-skip-scheduled-if-done
  5708. (/= schedule current)))
  5709. (throw :skip nil))
  5710. ;; Skip entry if it already appears as a deadline, per
  5711. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5712. ;; doesn't apply to habits.
  5713. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5714. ((guard
  5715. (or (not (memq (line-beginning-position 0) deadline-pos))
  5716. habitp))
  5717. nil)
  5718. (`repeated-after-deadline
  5719. (let ((deadline (time-to-days
  5720. (org-get-deadline-time (point)))))
  5721. (and (<= schedule deadline) (> current deadline))))
  5722. (`not-today pastschedp)
  5723. (`t t)
  5724. (_ nil))
  5725. (throw :skip nil))
  5726. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5727. ;; only show them for today. Also skip done habits.
  5728. (when (and habitp
  5729. (or donep
  5730. (not (bound-and-true-p org-habit-show-habits))
  5731. (and (not todayp)
  5732. (bound-and-true-p
  5733. org-habit-show-habits-only-for-today))))
  5734. (throw :skip nil))
  5735. (save-excursion
  5736. (re-search-backward "^\\*+[ \t]+" nil t)
  5737. (goto-char (match-end 0))
  5738. (let* ((category (org-get-category))
  5739. (inherited-tags
  5740. (or (eq org-agenda-show-inherited-tags 'always)
  5741. (and (listp org-agenda-show-inherited-tags)
  5742. (memq 'agenda org-agenda-show-inherited-tags))
  5743. (and (eq org-agenda-show-inherited-tags t)
  5744. (or (eq org-agenda-use-tag-inheritance t)
  5745. (memq 'agenda
  5746. org-agenda-use-tag-inheritance)))))
  5747. (tags (org-get-tags-at nil (not inherited-tags)))
  5748. (level (make-string (org-reduced-level (org-outline-level))
  5749. ?\s))
  5750. (head (buffer-substring (point) (line-end-position)))
  5751. (time
  5752. (cond
  5753. ;; No time of day designation if it is only
  5754. ;; a reminder.
  5755. ((and (/= current schedule) (/= current repeat)) nil)
  5756. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5757. (concat (substring s (match-beginning 1)) " "))
  5758. (t 'time)))
  5759. (item
  5760. (org-agenda-format-item
  5761. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5762. ;; Show a reminder of a past scheduled today.
  5763. (if (and todayp pastschedp)
  5764. (format past (1+ diff))
  5765. first))
  5766. head level category tags time nil habitp))
  5767. (face (cond ((and (not habitp) pastschedp)
  5768. 'org-scheduled-previously)
  5769. (todayp 'org-scheduled-today)
  5770. (t 'org-scheduled)))
  5771. (habitp (and habitp (org-habit-parse-todo))))
  5772. (org-add-props item props
  5773. 'undone-face face
  5774. 'face (if donep 'org-agenda-done face)
  5775. 'org-marker (org-agenda-new-marker pos)
  5776. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5777. 'type (if pastschedp "past-scheduled" "scheduled")
  5778. 'date (if pastschedp schedule date)
  5779. 'ts-date schedule
  5780. 'warntime warntime
  5781. 'level level
  5782. 'priority (if habitp (org-habit-get-priority habitp)
  5783. (+ 99 diff (org-get-priority item)))
  5784. 'org-habit-p habitp
  5785. 'todo-state todo-state)
  5786. (push item scheduled-items))))))
  5787. (nreverse scheduled-items)))
  5788. (defun org-agenda-get-blocks ()
  5789. "Return the date-range information for agenda display."
  5790. (let* ((props (list 'face nil
  5791. 'org-not-done-regexp org-not-done-regexp
  5792. 'org-todo-regexp org-todo-regexp
  5793. 'org-complex-heading-regexp org-complex-heading-regexp
  5794. 'mouse-face 'highlight
  5795. 'help-echo
  5796. (format "mouse-2 or RET jump to org file %s"
  5797. (abbreviate-file-name buffer-file-name))))
  5798. (regexp org-tr-regexp)
  5799. (d0 (calendar-absolute-from-gregorian date))
  5800. marker hdmarker ee txt d1 d2 s1 s2 category
  5801. level todo-state tags pos head donep inherited-tags)
  5802. (goto-char (point-min))
  5803. (while (re-search-forward regexp nil t)
  5804. (catch :skip
  5805. (org-agenda-skip)
  5806. (setq pos (point))
  5807. (let ((start-time (match-string 1))
  5808. (end-time (match-string 2)))
  5809. (setq s1 (match-string 1)
  5810. s2 (match-string 2)
  5811. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5812. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5813. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5814. ;; Only allow days between the limits, because the normal
  5815. ;; date stamps will catch the limits.
  5816. (save-excursion
  5817. (setq todo-state (org-get-todo-state))
  5818. (setq donep (member todo-state org-done-keywords))
  5819. (if (and donep org-agenda-skip-timestamp-if-done)
  5820. (throw :skip t))
  5821. (setq marker (org-agenda-new-marker (point))
  5822. category (org-get-category))
  5823. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5824. (throw :skip nil)
  5825. (goto-char (match-beginning 0))
  5826. (setq hdmarker (org-agenda-new-marker (point))
  5827. inherited-tags
  5828. (or (eq org-agenda-show-inherited-tags 'always)
  5829. (and (listp org-agenda-show-inherited-tags)
  5830. (memq 'agenda org-agenda-show-inherited-tags))
  5831. (and (eq org-agenda-show-inherited-tags t)
  5832. (or (eq org-agenda-use-tag-inheritance t)
  5833. (memq 'agenda org-agenda-use-tag-inheritance))))
  5834. tags (org-get-tags-at nil (not inherited-tags)))
  5835. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5836. (looking-at "\\*+[ \t]+\\(.*\\)")
  5837. (setq head (match-string 1))
  5838. (let ((remove-re
  5839. (if org-agenda-remove-timeranges-from-blocks
  5840. (concat
  5841. "<" (regexp-quote s1) ".*?>"
  5842. "--"
  5843. "<" (regexp-quote s2) ".*?>")
  5844. nil)))
  5845. (setq txt (org-agenda-format-item
  5846. (format
  5847. (nth (if (= d1 d2) 0 1)
  5848. org-agenda-timerange-leaders)
  5849. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5850. head level category tags
  5851. (cond ((and (= d1 d0) (= d2 d0))
  5852. (concat "<" start-time ">--<" end-time ">"))
  5853. ((= d1 d0)
  5854. (concat "<" start-time ">"))
  5855. ((= d2 d0)
  5856. (concat "<" end-time ">")))
  5857. remove-re))))
  5858. (org-add-props txt props
  5859. 'org-marker marker 'org-hd-marker hdmarker
  5860. 'type "block" 'date date
  5861. 'level level
  5862. 'todo-state todo-state
  5863. 'priority (org-get-priority txt))
  5864. (push txt ee))))
  5865. (goto-char pos)))
  5866. ;; Sort the entries by expiration date.
  5867. (nreverse ee)))
  5868. ;;; Agenda presentation and sorting
  5869. (defvar org-prefix-has-time nil
  5870. "A flag, set by `org-compile-prefix-format'.
  5871. The flag is set if the currently compiled format contains a `%t'.")
  5872. (defvar org-prefix-has-tag nil
  5873. "A flag, set by `org-compile-prefix-format'.
  5874. The flag is set if the currently compiled format contains a `%T'.")
  5875. (defvar org-prefix-has-effort nil
  5876. "A flag, set by `org-compile-prefix-format'.
  5877. The flag is set if the currently compiled format contains a `%e'.")
  5878. (defvar org-prefix-has-breadcrumbs nil
  5879. "A flag, set by `org-compile-prefix-format'.
  5880. The flag is set if the currently compiled format contains a `%b'.")
  5881. (defvar org-prefix-category-length nil
  5882. "Used by `org-compile-prefix-format' to remember the category field width.")
  5883. (defvar org-prefix-category-max-length nil
  5884. "Used by `org-compile-prefix-format' to remember the category field width.")
  5885. (defun org-agenda-get-category-icon (category)
  5886. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5887. (cl-dolist (entry org-agenda-category-icon-alist)
  5888. (when (string-match-p (car entry) category)
  5889. (if (listp (cadr entry))
  5890. (cl-return (cadr entry))
  5891. (cl-return (apply #'create-image (cdr entry)))))))
  5892. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5893. remove-re habitp)
  5894. "Format TXT to be inserted into the agenda buffer.
  5895. In particular, add the prefix and corresponding text properties.
  5896. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5897. LEVEL may be a string to replace the `%l' specifier.
  5898. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5899. category taken from local variable or file name. It will replace the `%c'
  5900. specifier in the format.
  5901. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5902. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5903. When DOTIME is a string, this string is searched for a time before TXT is.
  5904. TAGS can be the tags of the headline.
  5905. Any match of REMOVE-RE will be removed from TXT."
  5906. ;; We keep the org-prefix-* variable values along with a compiled
  5907. ;; formatter, so that multiple agendas existing at the same time do
  5908. ;; not step on each other toes.
  5909. ;;
  5910. ;; It was inconvenient to make these variables buffer local in
  5911. ;; Agenda buffers, because this function expects to be called with
  5912. ;; the buffer where item comes from being current, and not agenda
  5913. ;; buffer
  5914. (let* ((bindings (car org-prefix-format-compiled))
  5915. (formatter (cadr org-prefix-format-compiled)))
  5916. (cl-loop for (var value) in bindings
  5917. do (set var value))
  5918. (save-match-data
  5919. ;; Diary entries sometimes have extra whitespace at the beginning
  5920. (setq txt (org-trim txt))
  5921. ;; Fix the tags part in txt
  5922. (setq txt (org-agenda-fix-displayed-tags
  5923. txt tags
  5924. org-agenda-show-inherited-tags
  5925. org-agenda-hide-tags-regexp))
  5926. (let* ((category (or category
  5927. (if buffer-file-name
  5928. (file-name-sans-extension
  5929. (file-name-nondirectory buffer-file-name))
  5930. "")))
  5931. (category-icon (org-agenda-get-category-icon category))
  5932. (category-icon (if category-icon
  5933. (propertize " " 'display category-icon)
  5934. ""))
  5935. (effort (and (not (string= txt ""))
  5936. (get-text-property 1 'effort txt)))
  5937. ;; time, tag, effort are needed for the eval of the prefix format
  5938. (tag (if tags (nth (1- (length tags)) tags) ""))
  5939. time
  5940. (ts (if dotime (concat
  5941. (if (stringp dotime) dotime "")
  5942. (and org-agenda-search-headline-for-time txt))))
  5943. (time-of-day (and dotime (org-get-time-of-day ts)))
  5944. stamp plain s0 s1 s2 rtn srp l
  5945. duration breadcrumbs)
  5946. (and (derived-mode-p 'org-mode) buffer-file-name
  5947. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5948. (when (and dotime time-of-day)
  5949. ;; Extract starting and ending time and move them to prefix
  5950. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5951. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5952. (setq s0 (match-string 0 ts)
  5953. srp (and stamp (match-end 3))
  5954. s1 (match-string (if plain 1 2) ts)
  5955. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5956. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5957. ;; them, we might want to remove them there to avoid duplication.
  5958. ;; The user can turn this off with a variable.
  5959. (if (and org-prefix-has-time
  5960. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5961. (string-match (concat (regexp-quote s0) " *") txt)
  5962. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5963. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5964. (= (match-beginning 0) 0)
  5965. t))
  5966. (setq txt (replace-match "" nil nil txt))))
  5967. ;; Normalize the time(s) to 24 hour
  5968. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5969. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5970. ;; Try to set s2 if s1 and
  5971. ;; `org-agenda-default-appointment-duration' are set
  5972. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5973. (setq s2
  5974. (org-duration-from-minutes
  5975. (+ (org-duration-to-minutes s1 t)
  5976. org-agenda-default-appointment-duration)
  5977. nil t)))
  5978. ;; Compute the duration
  5979. (when s2
  5980. (setq duration (- (org-duration-to-minutes s2)
  5981. (org-duration-to-minutes s1)))))
  5982. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  5983. ;; Tags are in the string
  5984. (if (or (eq org-agenda-remove-tags t)
  5985. (and org-agenda-remove-tags
  5986. org-prefix-has-tag))
  5987. (setq txt (replace-match "" t t txt))
  5988. (setq txt (replace-match
  5989. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5990. (match-string 2 txt))
  5991. t t txt))))
  5992. (when remove-re
  5993. (while (string-match remove-re txt)
  5994. (setq txt (replace-match "" t t txt))))
  5995. ;; Set org-heading property on `txt' to mark the start of the
  5996. ;; heading.
  5997. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5998. ;; Prepare the variables needed in the eval of the compiled format
  5999. (if org-prefix-has-breadcrumbs
  6000. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6001. (let ((s (org-display-outline-path nil nil "->" t)))
  6002. (if (eq "" s) "" (concat s "->"))))))
  6003. (setq time (cond (s2 (concat
  6004. (org-agenda-time-of-day-to-ampm-maybe s1)
  6005. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6006. (if org-agenda-timegrid-use-ampm " ")))
  6007. (s1 (concat
  6008. (org-agenda-time-of-day-to-ampm-maybe s1)
  6009. (if org-agenda-timegrid-use-ampm
  6010. "........ "
  6011. "......")))
  6012. (t ""))
  6013. extra (or (and (not habitp) extra) "")
  6014. category (if (symbolp category) (symbol-name category) category)
  6015. level (or level ""))
  6016. (if (string-match org-bracket-link-regexp category)
  6017. (progn
  6018. (setq l (if (match-end 3)
  6019. (- (match-end 3) (match-beginning 3))
  6020. (- (match-end 1) (match-beginning 1))))
  6021. (when (< l (or org-prefix-category-length 0))
  6022. (setq category (copy-sequence category))
  6023. (org-add-props category nil
  6024. 'extra-space (make-string
  6025. (- org-prefix-category-length l 1) ?\ ))))
  6026. (if (and org-prefix-category-max-length
  6027. (>= (length category) org-prefix-category-max-length))
  6028. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6029. ;; Evaluate the compiled format
  6030. (setq rtn (concat (eval formatter) txt))
  6031. ;; And finally add the text properties
  6032. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6033. (org-add-props rtn nil
  6034. 'org-category category
  6035. 'tags (mapcar 'org-downcase-keep-props tags)
  6036. 'org-highest-priority org-highest-priority
  6037. 'org-lowest-priority org-lowest-priority
  6038. 'time-of-day time-of-day
  6039. 'duration duration
  6040. 'breadcrumbs breadcrumbs
  6041. 'txt txt
  6042. 'level level
  6043. 'time time
  6044. 'extra extra
  6045. 'format org-prefix-format-compiled
  6046. 'dotime dotime)))))
  6047. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6048. "Remove tags string from TXT, and add a modified list of tags.
  6049. The modified list may contain inherited tags, and tags matched by
  6050. `org-agenda-hide-tags-regexp' will be removed."
  6051. (when (or add-inherited hide-re)
  6052. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6053. (setq txt (substring txt 0 (match-beginning 0))))
  6054. (setq tags
  6055. (delq nil
  6056. (mapcar (lambda (tg)
  6057. (if (or (and hide-re (string-match hide-re tg))
  6058. (and (not add-inherited)
  6059. (get-text-property 0 'inherited tg)))
  6060. nil
  6061. tg))
  6062. tags)))
  6063. (when tags
  6064. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6065. i)
  6066. (setq txt (concat txt " :"
  6067. (mapconcat
  6068. (lambda (x)
  6069. (setq i (get-text-property 0 'inherited x))
  6070. (if (and have-i (not i))
  6071. (progn
  6072. (setq have-i nil)
  6073. (concat ":" x))
  6074. x))
  6075. tags ":")
  6076. (if have-i "::" ":"))))))
  6077. txt)
  6078. (defun org-downcase-keep-props (s)
  6079. (let ((props (text-properties-at 0 s)))
  6080. (setq s (downcase s))
  6081. (add-text-properties 0 (length s) props s)
  6082. s))
  6083. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6084. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6085. "Add a time-grid for agenda items which need it.
  6086. LIST is the list of agenda items formatted by `org-agenda-list'.
  6087. NDAYS is the span of the current agenda view.
  6088. TODAYP is t when the current agenda view is on today."
  6089. (catch 'exit
  6090. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6091. ((and todayp (member 'today (car org-agenda-time-grid))))
  6092. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6093. ((member 'weekly (car org-agenda-time-grid)))
  6094. (t (throw 'exit list)))
  6095. (let* ((have (delq nil (mapcar
  6096. (lambda (x) (get-text-property 1 'time-of-day x))
  6097. list)))
  6098. (string (nth 1 org-agenda-time-grid))
  6099. (gridtimes (nth 2 org-agenda-time-grid))
  6100. (req (car org-agenda-time-grid))
  6101. (remove (member 'remove-match req))
  6102. new time)
  6103. (if (and (member 'require-timed req) (not have))
  6104. ;; don't show empty grid
  6105. (throw 'exit list))
  6106. (while (setq time (pop gridtimes))
  6107. (unless (and remove (member time have))
  6108. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6109. (push (org-agenda-format-item
  6110. nil string nil "" nil
  6111. (concat (substring time 0 -2) ":" (substring time -2)))
  6112. new)
  6113. (put-text-property
  6114. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6115. (when (and todayp org-agenda-show-current-time-in-grid)
  6116. (push (org-agenda-format-item
  6117. nil org-agenda-current-time-string nil "" nil
  6118. (format-time-string "%H:%M "))
  6119. new)
  6120. (put-text-property
  6121. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6122. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6123. (append new list)
  6124. (append list new)))))
  6125. (defun org-compile-prefix-format (key)
  6126. "Compile the prefix format into a Lisp form that can be evaluated.
  6127. The resulting form and associated variable bindings is returned
  6128. and stored in the variable `org-prefix-format-compiled'."
  6129. (setq org-prefix-has-time nil
  6130. org-prefix-has-tag nil
  6131. org-prefix-category-length nil
  6132. org-prefix-has-effort nil
  6133. org-prefix-has-breadcrumbs nil)
  6134. (let ((s (cond
  6135. ((stringp org-agenda-prefix-format)
  6136. org-agenda-prefix-format)
  6137. ((assq key org-agenda-prefix-format)
  6138. (cdr (assq key org-agenda-prefix-format)))
  6139. (t " %-12:c%?-12t% s")))
  6140. (start 0)
  6141. varform vars var e c f opt)
  6142. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6143. s start)
  6144. (setq var (or (cdr (assoc (match-string 4 s)
  6145. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6146. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6147. 'eval)
  6148. c (or (match-string 3 s) "")
  6149. opt (match-beginning 1)
  6150. start (1+ (match-beginning 0)))
  6151. (if (eq var 'time) (setq org-prefix-has-time t))
  6152. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6153. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6154. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6155. (setq f (concat "%" (match-string 2 s) "s"))
  6156. (when (eq var 'category)
  6157. (setq org-prefix-category-length
  6158. (floor (abs (string-to-number (match-string 2 s)))))
  6159. (setq org-prefix-category-max-length
  6160. (let ((x (match-string 2 s)))
  6161. (save-match-data
  6162. (if (string-match "\\.[0-9]+" x)
  6163. (string-to-number (substring (match-string 0 x) 1)))))))
  6164. (if (eq var 'eval)
  6165. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6166. (if opt
  6167. (setq varform
  6168. `(if (or (equal "" ,var) (equal nil ,var))
  6169. ""
  6170. (format ,f (concat ,var ,c))))
  6171. (setq varform
  6172. `(format ,f (if (or (equal ,var "")
  6173. (equal ,var nil)) ""
  6174. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6175. (setq s (replace-match "%s" t nil s))
  6176. (push varform vars))
  6177. (setq vars (nreverse vars))
  6178. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6179. (setq org-prefix-format-compiled
  6180. (list
  6181. `((org-prefix-has-time ,org-prefix-has-time)
  6182. (org-prefix-has-tag ,org-prefix-has-tag)
  6183. (org-prefix-category-length ,org-prefix-category-length)
  6184. (org-prefix-has-effort ,org-prefix-has-effort)
  6185. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6186. `(format ,s ,@vars))))))
  6187. (defun org-set-sorting-strategy (key)
  6188. (if (symbolp (car org-agenda-sorting-strategy))
  6189. ;; the old format
  6190. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6191. (setq org-agenda-sorting-strategy-selected
  6192. (or (cdr (assq key org-agenda-sorting-strategy))
  6193. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6194. '(time-up category-keep priority-down)))))
  6195. (defun org-get-time-of-day (s &optional string mod24)
  6196. "Check string S for a time of day.
  6197. If found, return it as a military time number between 0 and 2400.
  6198. If not found, return nil.
  6199. The optional STRING argument forces conversion into a 5 character wide string
  6200. HH:MM."
  6201. (save-match-data
  6202. (when
  6203. (and
  6204. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6205. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6206. (not (eq (get-text-property 1 'face s) 'org-link)))
  6207. (let* ((h (string-to-number (match-string 1 s)))
  6208. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6209. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6210. (am-p (equal ampm "am"))
  6211. (h1 (cond ((not ampm) h)
  6212. ((= h 12) (if am-p 0 12))
  6213. (t (+ h (if am-p 0 12)))))
  6214. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6215. (mod h1 24) h1))
  6216. (t0 (+ (* 100 h2) m))
  6217. (t1 (concat (if (>= h1 24) "+" " ")
  6218. (if (and org-agenda-time-leading-zero
  6219. (< t0 1000)) "0" "")
  6220. (if (< t0 100) "0" "")
  6221. (if (< t0 10) "0" "")
  6222. (int-to-string t0))))
  6223. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6224. (defvar org-agenda-before-sorting-filter-function nil
  6225. "Function to be applied to agenda items prior to sorting.
  6226. Prior to sorting also means just before they are inserted into the agenda.
  6227. To aid sorting, you may revisit the original entries and add more text
  6228. properties which will later be used by the sorting functions.
  6229. The function should take a string argument, an agenda line.
  6230. It has access to the text properties in that line, which contain among
  6231. other things, the property `org-hd-marker' that points to the entry
  6232. where the line comes from. Note that not all lines going into the agenda
  6233. have this property, only most.
  6234. The function should return the modified string. It is probably best
  6235. to ONLY change text properties.
  6236. You can also use this function as a filter, by returning nil for lines
  6237. you don't want to have in the agenda at all. For this application, you
  6238. could bind the variable in the options section of a custom command.")
  6239. (defun org-agenda-finalize-entries (list &optional type)
  6240. "Sort, limit and concatenate the LIST of agenda items.
  6241. The optional argument TYPE tells the agenda type."
  6242. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6243. (cdr (assoc type org-agenda-max-effort)))
  6244. (t org-agenda-max-effort)))
  6245. (max-todo (cond ((listp org-agenda-max-todos)
  6246. (cdr (assoc type org-agenda-max-todos)))
  6247. (t org-agenda-max-todos)))
  6248. (max-tags (cond ((listp org-agenda-max-tags)
  6249. (cdr (assoc type org-agenda-max-tags)))
  6250. (t org-agenda-max-tags)))
  6251. (max-entries (cond ((listp org-agenda-max-entries)
  6252. (cdr (assoc type org-agenda-max-entries)))
  6253. (t org-agenda-max-entries))))
  6254. (when org-agenda-before-sorting-filter-function
  6255. (setq list
  6256. (delq nil
  6257. (mapcar
  6258. org-agenda-before-sorting-filter-function list))))
  6259. (setq list (mapcar 'org-agenda-highlight-todo list)
  6260. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6261. (when max-effort
  6262. (setq list (org-agenda-limit-entries
  6263. list 'effort-minutes max-effort
  6264. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6265. 32767 -1))))))
  6266. (when max-todo
  6267. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6268. (when max-tags
  6269. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6270. (when max-entries
  6271. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6272. (mapconcat 'identity list "\n")))
  6273. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6274. "Limit the number of agenda entries."
  6275. (let ((include (and limit (< limit 0))))
  6276. (if limit
  6277. (let ((fun (or fn (lambda (p) (if p 1))))
  6278. (lim 0))
  6279. (delq nil
  6280. (mapcar
  6281. (lambda (e)
  6282. (let ((pval (funcall
  6283. fun (get-text-property (1- (length e))
  6284. prop e))))
  6285. (if pval (setq lim (+ lim pval)))
  6286. (cond ((and pval (<= lim (abs limit))) e)
  6287. ((and include (not pval)) e))))
  6288. list)))
  6289. list)))
  6290. (defun org-agenda-limit-interactively (remove)
  6291. "In agenda, interactively limit entries to various maximums."
  6292. (interactive "P")
  6293. (if remove
  6294. (progn (setq org-agenda-max-entries nil
  6295. org-agenda-max-todos nil
  6296. org-agenda-max-tags nil
  6297. org-agenda-max-effort nil)
  6298. (org-agenda-redo))
  6299. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6300. (msg (cond ((= max ?E) "How many minutes? ")
  6301. ((= max ?e) "How many entries? ")
  6302. ((= max ?t) "How many TODO entries? ")
  6303. ((= max ?T) "How many tagged entries? ")
  6304. (t (user-error "Wrong input"))))
  6305. (num (string-to-number (read-from-minibuffer msg))))
  6306. (cond ((equal max ?e)
  6307. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6308. ((equal max ?t)
  6309. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6310. ((equal max ?T)
  6311. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6312. ((equal max ?E)
  6313. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6314. (org-agenda-fit-window-to-buffer))
  6315. (defun org-agenda-highlight-todo (x)
  6316. (let ((org-done-keywords org-done-keywords-for-agenda)
  6317. (case-fold-search nil)
  6318. re)
  6319. (if (eq x 'line)
  6320. (save-excursion
  6321. (beginning-of-line 1)
  6322. (setq re (org-get-at-bol 'org-todo-regexp))
  6323. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6324. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6325. (add-text-properties (match-beginning 0) (match-end 1)
  6326. (list 'face (org-get-todo-face 1)))
  6327. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6328. (delete-region (match-beginning 1) (1- (match-end 0)))
  6329. (goto-char (match-beginning 1))
  6330. (insert (format org-agenda-todo-keyword-format s)))))
  6331. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6332. (setq re (get-text-property 0 'org-todo-regexp x))
  6333. (when (and re
  6334. ;; Test `pl' because if there's no heading content,
  6335. ;; there's no point matching to highlight. Note
  6336. ;; that if we didn't test `pl' first, and there
  6337. ;; happened to be no keyword from `org-todo-regexp'
  6338. ;; on this heading line, then the `equal' comparison
  6339. ;; afterwards would spuriously succeed in the case
  6340. ;; where `pl' is nil -- causing an args-out-of-range
  6341. ;; error when we try to add text properties to text
  6342. ;; that isn't there.
  6343. pl
  6344. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6345. x pl) pl))
  6346. (add-text-properties
  6347. (or (match-end 1) (match-end 0)) (match-end 0)
  6348. (list 'face (org-get-todo-face (match-string 2 x)))
  6349. x)
  6350. (when (match-end 1)
  6351. (setq x (concat (substring x 0 (match-end 1))
  6352. (format org-agenda-todo-keyword-format
  6353. (match-string 2 x))
  6354. (org-add-props " " (text-properties-at 0 x))
  6355. (substring x (match-end 3)))))))
  6356. x)))
  6357. (defsubst org-cmp-values (a b property)
  6358. "Compare the numeric value of text PROPERTY for string A and B."
  6359. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6360. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6361. (cond ((> pa pb) +1)
  6362. ((< pa pb) -1))))
  6363. (defsubst org-cmp-effort (a b)
  6364. "Compare the effort values of string A and B."
  6365. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6366. ;; `effort-minutes' property is not directly accessible from
  6367. ;; the strings, but is stored as a property in `txt'.
  6368. (ea (or (get-text-property
  6369. 0 'effort-minutes (get-text-property 0 'txt a))
  6370. def))
  6371. (eb (or (get-text-property
  6372. 0 'effort-minutes (get-text-property 0 'txt b))
  6373. def)))
  6374. (cond ((> ea eb) +1)
  6375. ((< ea eb) -1))))
  6376. (defsubst org-cmp-category (a b)
  6377. "Compare the string values of categories of strings A and B."
  6378. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6379. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6380. (cond ((string-lessp ca cb) -1)
  6381. ((string-lessp cb ca) +1))))
  6382. (defsubst org-cmp-todo-state (a b)
  6383. "Compare the todo states of strings A and B."
  6384. (let* ((ma (or (get-text-property 1 'org-marker a)
  6385. (get-text-property 1 'org-hd-marker a)))
  6386. (mb (or (get-text-property 1 'org-marker b)
  6387. (get-text-property 1 'org-hd-marker b)))
  6388. (fa (and ma (marker-buffer ma)))
  6389. (fb (and mb (marker-buffer mb)))
  6390. (todo-kwds
  6391. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6392. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6393. (ta (or (get-text-property 1 'todo-state a) ""))
  6394. (tb (or (get-text-property 1 'todo-state b) ""))
  6395. (la (- (length (member ta todo-kwds))))
  6396. (lb (- (length (member tb todo-kwds))))
  6397. (donepa (member ta org-done-keywords-for-agenda))
  6398. (donepb (member tb org-done-keywords-for-agenda)))
  6399. (cond ((and donepa (not donepb)) -1)
  6400. ((and (not donepa) donepb) +1)
  6401. ((< la lb) -1)
  6402. ((< lb la) +1))))
  6403. (defsubst org-cmp-alpha (a b)
  6404. "Compare the headlines, alphabetically."
  6405. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6406. (plb (text-property-any 0 (length b) 'org-heading t b))
  6407. (ta (and pla (substring a pla)))
  6408. (tb (and plb (substring b plb)))
  6409. (case-fold-search nil))
  6410. (when pla
  6411. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6412. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6413. (setq ta (substring ta (match-end 0))))
  6414. (setq ta (downcase ta)))
  6415. (when plb
  6416. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6417. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6418. (setq tb (substring tb (match-end 0))))
  6419. (setq tb (downcase tb)))
  6420. (cond ((not ta) +1)
  6421. ((not tb) -1)
  6422. ((string-lessp ta tb) -1)
  6423. ((string-lessp tb ta) +1))))
  6424. (defsubst org-cmp-tag (a b)
  6425. "Compare the string values of the first tags of A and B."
  6426. (let ((ta (car (last (get-text-property 1 'tags a))))
  6427. (tb (car (last (get-text-property 1 'tags b)))))
  6428. (cond ((not ta) +1)
  6429. ((not tb) -1)
  6430. ((string-lessp ta tb) -1)
  6431. ((string-lessp tb ta) +1))))
  6432. (defsubst org-cmp-time (a b)
  6433. "Compare the time-of-day values of strings A and B."
  6434. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6435. (ta (or (get-text-property 1 'time-of-day a) def))
  6436. (tb (or (get-text-property 1 'time-of-day b) def)))
  6437. (cond ((< ta tb) -1)
  6438. ((< tb ta) +1))))
  6439. (defsubst org-cmp-ts (a b type)
  6440. "Compare the timestamps values of entries A and B.
  6441. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6442. \"timestamp_ia\", compare within each of these type. When TYPE
  6443. is the empty string, compare all timestamps without respect of
  6444. their type."
  6445. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6446. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6447. (get-text-property 1 'ts-date a))
  6448. def))
  6449. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6450. (get-text-property 1 'ts-date b))
  6451. def)))
  6452. (cond ((< ta tb) -1)
  6453. ((< tb ta) +1))))
  6454. (defsubst org-cmp-habit-p (a b)
  6455. "Compare the todo states of strings A and B."
  6456. (let ((ha (get-text-property 1 'org-habit-p a))
  6457. (hb (get-text-property 1 'org-habit-p b)))
  6458. (cond ((and ha (not hb)) -1)
  6459. ((and (not ha) hb) +1))))
  6460. (defun org-entries-lessp (a b)
  6461. "Predicate for sorting agenda entries."
  6462. ;; The following variables will be used when the form is evaluated.
  6463. ;; So even though the compiler complains, keep them.
  6464. (let* ((ss org-agenda-sorting-strategy-selected)
  6465. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6466. (org-cmp-ts a b "")))
  6467. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6468. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6469. (org-cmp-ts a b "scheduled")))
  6470. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6471. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6472. (org-cmp-ts a b "deadline")))
  6473. (deadline-down (if deadline-up (- deadline-up) nil))
  6474. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6475. (org-cmp-ts a b "timestamp_ia")))
  6476. (tsia-down (if tsia-up (- tsia-up) nil))
  6477. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6478. (org-cmp-ts a b "timestamp")))
  6479. (ts-down (if ts-up (- ts-up) nil))
  6480. (time-up (and (org-em 'time-up 'time-down ss)
  6481. (org-cmp-time a b)))
  6482. (time-down (if time-up (- time-up) nil))
  6483. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6484. (org-cmp-values a b 'org-stats)))
  6485. (stats-down (if stats-up (- stats-up) nil))
  6486. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6487. (org-cmp-values a b 'priority)))
  6488. (priority-down (if priority-up (- priority-up) nil))
  6489. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6490. (org-cmp-effort a b)))
  6491. (effort-down (if effort-up (- effort-up) nil))
  6492. (category-up (and (or (org-em 'category-up 'category-down ss)
  6493. (memq 'category-keep ss))
  6494. (org-cmp-category a b)))
  6495. (category-down (if category-up (- category-up) nil))
  6496. (category-keep (if category-up +1 nil))
  6497. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6498. (org-cmp-tag a b)))
  6499. (tag-down (if tag-up (- tag-up) nil))
  6500. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6501. (org-cmp-todo-state a b)))
  6502. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6503. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6504. (org-cmp-habit-p a b)))
  6505. (habit-down (if habit-up (- habit-up) nil))
  6506. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6507. (org-cmp-alpha a b)))
  6508. (alpha-down (if alpha-up (- alpha-up) nil))
  6509. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6510. user-defined-up user-defined-down)
  6511. (if (and need-user-cmp org-agenda-cmp-user-defined
  6512. (functionp org-agenda-cmp-user-defined))
  6513. (setq user-defined-up
  6514. (funcall org-agenda-cmp-user-defined a b)
  6515. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6516. (cdr (assoc
  6517. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6518. '((-1 . t) (1 . nil) (nil . nil))))))
  6519. ;;; Agenda restriction lock
  6520. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6521. "Overlay to mark the headline to which agenda commands are restricted.")
  6522. (overlay-put org-agenda-restriction-lock-overlay
  6523. 'face 'org-agenda-restriction-lock)
  6524. (overlay-put org-agenda-restriction-lock-overlay
  6525. 'help-echo "Agendas are currently limited to this subtree.")
  6526. (delete-overlay org-agenda-restriction-lock-overlay)
  6527. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6528. "Set the restriction lock to the agenda item at point from within the agenda.
  6529. When called with a `\\[universal-argument]' prefix, restrict to
  6530. the file which contains the item.
  6531. Argument ARG is the prefix argument."
  6532. (interactive "P")
  6533. (unless (derived-mode-p 'org-agenda-mode)
  6534. (user-error "Not in an Org agenda buffer"))
  6535. (let* ((marker (or (org-get-at-bol 'org-marker)
  6536. (org-agenda-error)))
  6537. (buffer (marker-buffer marker))
  6538. (pos (marker-position marker)))
  6539. (with-current-buffer buffer
  6540. (goto-char pos)
  6541. (org-agenda-set-restriction-lock arg))))
  6542. ;;;###autoload
  6543. (defun org-agenda-set-restriction-lock (&optional type)
  6544. "Set restriction lock for agenda, to current subtree or file.
  6545. Restriction will be the file if TYPE is `file', or if type is the
  6546. universal prefix \\='(4), or if the cursor is before the first headline
  6547. in the file. Otherwise, restriction will be to the current subtree."
  6548. (interactive "P")
  6549. (org-agenda-remove-restriction-lock 'noupdate)
  6550. (and (equal type '(4)) (setq type 'file))
  6551. (setq type (cond
  6552. (type type)
  6553. ((org-at-heading-p) 'subtree)
  6554. ((condition-case nil (org-back-to-heading t) (error nil))
  6555. 'subtree)
  6556. (t 'file)))
  6557. (if (eq type 'subtree)
  6558. (progn
  6559. (setq org-agenda-restrict (current-buffer))
  6560. (setq org-agenda-overriding-restriction 'subtree)
  6561. (put 'org-agenda-files 'org-restrict
  6562. (list (buffer-file-name (buffer-base-buffer))))
  6563. (org-back-to-heading t)
  6564. (move-overlay org-agenda-restriction-lock-overlay
  6565. (point)
  6566. (if org-agenda-restriction-lock-highlight-subtree
  6567. (save-excursion (org-end-of-subtree t t) (point))
  6568. (point-at-eol)))
  6569. (move-marker org-agenda-restrict-begin (point))
  6570. (move-marker org-agenda-restrict-end
  6571. (save-excursion (org-end-of-subtree t t)))
  6572. (message "Locking agenda restriction to subtree"))
  6573. (put 'org-agenda-files 'org-restrict
  6574. (list (buffer-file-name (buffer-base-buffer))))
  6575. (setq org-agenda-restrict nil)
  6576. (setq org-agenda-overriding-restriction 'file)
  6577. (move-marker org-agenda-restrict-begin nil)
  6578. (move-marker org-agenda-restrict-end nil)
  6579. (message "Locking agenda restriction to file"))
  6580. (setq current-prefix-arg nil)
  6581. (org-agenda-maybe-redo))
  6582. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6583. "Remove the agenda restriction lock."
  6584. (interactive "P")
  6585. (delete-overlay org-agenda-restriction-lock-overlay)
  6586. (delete-overlay org-speedbar-restriction-lock-overlay)
  6587. (setq org-agenda-overriding-restriction nil)
  6588. (setq org-agenda-restrict nil)
  6589. (put 'org-agenda-files 'org-restrict nil)
  6590. (move-marker org-agenda-restrict-begin nil)
  6591. (move-marker org-agenda-restrict-end nil)
  6592. (setq current-prefix-arg nil)
  6593. (message "Agenda restriction lock removed")
  6594. (or noupdate (org-agenda-maybe-redo)))
  6595. (defun org-agenda-maybe-redo ()
  6596. "If there is any window showing the agenda view, update it."
  6597. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6598. org-agenda-buffer-name)
  6599. t))
  6600. (w0 (selected-window)))
  6601. (when w
  6602. (select-window w)
  6603. (org-agenda-redo)
  6604. (select-window w0)
  6605. (if org-agenda-overriding-restriction
  6606. (message "Agenda view shifted to new %s restriction"
  6607. org-agenda-overriding-restriction)
  6608. (message "Agenda restriction lock removed")))))
  6609. ;;; Agenda commands
  6610. (defun org-agenda-check-type (error &rest types)
  6611. "Check if agenda buffer is of allowed type.
  6612. If ERROR is non-nil, throw an error, otherwise just return nil.
  6613. Allowed types are `agenda' `timeline' `todo' `tags' `search'."
  6614. (if (not org-agenda-type)
  6615. (error "No Org agenda currently displayed")
  6616. (if (memq org-agenda-type types)
  6617. t
  6618. (if error
  6619. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6620. nil))))
  6621. (defun org-agenda-Quit ()
  6622. "Exit the agenda, killing the agenda buffer.
  6623. Like `org-agenda-quit', but kill the buffer even when
  6624. `org-agenda-sticky' is non-nil."
  6625. (interactive)
  6626. (org-agenda--quit))
  6627. (defun org-agenda-quit ()
  6628. "Exit the agenda.
  6629. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6630. instead of killing it.
  6631. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6632. the pre-agenda window configuration.
  6633. When column view is active, exit column view instead of the
  6634. agenda."
  6635. (interactive)
  6636. (org-agenda--quit org-agenda-sticky))
  6637. (defun org-agenda--quit (&optional bury)
  6638. (if org-agenda-columns-active
  6639. (org-columns-quit)
  6640. (let ((wconf org-agenda-pre-window-conf)
  6641. (buf (current-buffer))
  6642. (org-agenda-last-indirect-window
  6643. (and (eq org-indirect-buffer-display 'other-window)
  6644. org-agenda-last-indirect-buffer
  6645. (get-buffer-window org-agenda-last-indirect-buffer))))
  6646. (cond
  6647. ((eq org-agenda-window-setup 'other-frame)
  6648. (delete-frame))
  6649. ((and org-agenda-restore-windows-after-quit
  6650. wconf)
  6651. ;; Maybe restore the pre-agenda window configuration. Reset
  6652. ;; `org-agenda-pre-window-conf' before running
  6653. ;; `set-window-configuration', which loses the current buffer.
  6654. (setq org-agenda-pre-window-conf nil)
  6655. (set-window-configuration wconf))
  6656. (t
  6657. (when org-agenda-last-indirect-window
  6658. (delete-window org-agenda-last-indirect-window))
  6659. (and (not (eq org-agenda-window-setup 'current-window))
  6660. (not (one-window-p))
  6661. (delete-window))))
  6662. (if bury
  6663. ;; Set the agenda buffer as the current buffer instead of
  6664. ;; passing it as an argument to `bury-buffer' so that
  6665. ;; `bury-buffer' removes it from the window.
  6666. (with-current-buffer buf
  6667. (bury-buffer))
  6668. (kill-buffer buf)
  6669. (setq org-agenda-archives-mode nil
  6670. org-agenda-buffer nil)))))
  6671. (defun org-agenda-exit ()
  6672. "Exit the agenda, killing Org buffers loaded by the agenda.
  6673. Like `org-agenda-Quit', but kill any buffers that were created by
  6674. the agenda. Org buffers visited directly by the user will not be
  6675. touched. Also, exit the agenda even if it is in column view."
  6676. (interactive)
  6677. (when org-agenda-columns-active
  6678. (org-columns-quit))
  6679. (org-release-buffers org-agenda-new-buffers)
  6680. (setq org-agenda-new-buffers nil)
  6681. (org-agenda-Quit))
  6682. (defun org-agenda-kill-all-agenda-buffers ()
  6683. "Kill all buffers in `org-agenda-mode'.
  6684. This is used when toggling sticky agendas."
  6685. (interactive)
  6686. (let (blist)
  6687. (dolist (buf (buffer-list))
  6688. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6689. (push buf blist)))
  6690. (mapc 'kill-buffer blist)))
  6691. (defun org-agenda-execute (arg)
  6692. "Execute another agenda command, keeping same window.
  6693. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6694. in the agenda."
  6695. (interactive "P")
  6696. (let ((org-agenda-window-setup 'current-window))
  6697. (org-agenda arg)))
  6698. (defun org-agenda-redo (&optional all)
  6699. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6700. (interactive "P")
  6701. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6702. (cpa (unless (eq all t) current-prefix-arg))
  6703. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6704. (org-agenda-sticky nil)
  6705. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6706. org-agenda-buffer-name))
  6707. (org-agenda-keep-modes t)
  6708. (tag-filter org-agenda-tag-filter)
  6709. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6710. (top-hl-filter org-agenda-top-headline-filter)
  6711. (cat-filter org-agenda-category-filter)
  6712. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6713. (re-filter org-agenda-regexp-filter)
  6714. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6715. (effort-filter org-agenda-effort-filter)
  6716. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6717. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6718. (cols org-agenda-columns-active)
  6719. (line (org-current-line))
  6720. (window-line (- line (org-current-line (window-start))))
  6721. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6722. (redo-cmd (get-text-property p 'org-redo-cmd))
  6723. (last-args (get-text-property p 'org-last-args))
  6724. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6725. (org-agenda-overriding-cmd-arguments
  6726. (unless (eq all t)
  6727. (cond ((listp last-args)
  6728. (cons (or cpa (car last-args)) (cdr last-args)))
  6729. ((stringp last-args)
  6730. last-args))))
  6731. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6732. (put 'org-agenda-tag-filter :preset-filter nil)
  6733. (put 'org-agenda-category-filter :preset-filter nil)
  6734. (put 'org-agenda-regexp-filter :preset-filter nil)
  6735. (put 'org-agenda-effort-filter :preset-filter nil)
  6736. (and cols (org-columns-quit))
  6737. (message "Rebuilding agenda buffer...")
  6738. (if series-redo-cmd
  6739. (eval series-redo-cmd)
  6740. (org-let lprops redo-cmd))
  6741. (setq org-agenda-undo-list nil
  6742. org-agenda-pending-undo-list nil
  6743. org-agenda-tag-filter tag-filter
  6744. org-agenda-category-filter cat-filter
  6745. org-agenda-regexp-filter re-filter
  6746. org-agenda-effort-filter effort-filter
  6747. org-agenda-top-headline-filter top-hl-filter)
  6748. (message "Rebuilding agenda buffer...done")
  6749. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6750. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6751. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6752. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6753. (let ((tag (or tag-filter tag-preset))
  6754. (cat (or cat-filter cat-preset))
  6755. (effort (or effort-filter effort-preset))
  6756. (re (or re-filter re-preset)))
  6757. (when tag (org-agenda-filter-apply tag 'tag t))
  6758. (when cat (org-agenda-filter-apply cat 'category))
  6759. (when effort (org-agenda-filter-apply effort 'effort))
  6760. (when re (org-agenda-filter-apply re 'regexp)))
  6761. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6762. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6763. (org-goto-line line)
  6764. (recenter window-line)))
  6765. (defvar org-global-tags-completion-table nil)
  6766. (defvar org-agenda-filter-form nil)
  6767. (defvar org-agenda-filtered-by-category nil)
  6768. (defun org-agenda-filter-by-category (strip)
  6769. "Filter lines in the agenda buffer that have a specific category.
  6770. The category is that of the current line.
  6771. Without prefix argument, keep only the lines of that category.
  6772. With a prefix argument, exclude the lines of that category.
  6773. "
  6774. (interactive "P")
  6775. (if (and org-agenda-filtered-by-category
  6776. org-agenda-category-filter)
  6777. (org-agenda-filter-show-all-cat)
  6778. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6779. (cond
  6780. ((and cat strip)
  6781. (org-agenda-filter-apply
  6782. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6783. (cat
  6784. (org-agenda-filter-apply
  6785. (setq org-agenda-category-filter
  6786. (list (concat "+" cat))) 'category))
  6787. (t (error "No category at point"))))))
  6788. (defun org-find-top-headline (&optional pos)
  6789. "Find the topmost parent headline and return it."
  6790. (save-excursion
  6791. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6792. (if pos (goto-char pos))
  6793. ;; Skip up to the topmost parent
  6794. (while (ignore-errors (outline-up-heading 1) t))
  6795. (ignore-errors
  6796. (nth 4 (org-heading-components))))))
  6797. (defvar org-agenda-filtered-by-top-headline nil)
  6798. (defun org-agenda-filter-by-top-headline (strip)
  6799. "Keep only those lines that are descendants from the same top headline.
  6800. The top headline is that of the current line."
  6801. (interactive "P")
  6802. (if org-agenda-filtered-by-top-headline
  6803. (progn
  6804. (setq org-agenda-filtered-by-top-headline nil
  6805. org-agenda-top-headline-filter nil)
  6806. (org-agenda-filter-show-all-top-filter))
  6807. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6808. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6809. (error "No top-level headline at point")))))
  6810. (defvar org-agenda-regexp-filter nil)
  6811. (defun org-agenda-filter-by-regexp (strip)
  6812. "Filter agenda entries by a regular expression.
  6813. Regexp filters are cumulative.
  6814. With no prefix argument, keep entries matching the regexp.
  6815. With one prefix argument, filter out entries matching the regexp.
  6816. With two prefix arguments, remove the regexp filters."
  6817. (interactive "P")
  6818. (if (not (equal strip '(16)))
  6819. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6820. (read-from-minibuffer
  6821. (if (equal strip '(4))
  6822. "Filter out entries matching regexp: "
  6823. "Narrow to entries matching regexp: ")))))
  6824. (push flt org-agenda-regexp-filter)
  6825. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6826. (org-agenda-filter-show-all-re)
  6827. (message "Regexp filter removed")))
  6828. (defvar org-agenda-effort-filter nil)
  6829. (defun org-agenda-filter-by-effort (strip)
  6830. "Filter agenda entries by effort.
  6831. With no prefix argument, keep entries matching the effort condition.
  6832. With one prefix argument, filter out entries matching the condition.
  6833. With two prefix arguments, remove the effort filters."
  6834. (interactive "P")
  6835. (cond
  6836. ((member strip '(nil 4))
  6837. (let* ((efforts (split-string
  6838. (or (cdr (assoc (concat org-effort-property "_ALL")
  6839. org-global-properties))
  6840. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6841. ;; XXX: the following handles only up to 10 different
  6842. ;; effort values.
  6843. (allowed-keys (if (null efforts) nil
  6844. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6845. (number-sequence 1 (length efforts)))))
  6846. (op nil))
  6847. (while (not (memq op '(?< ?> ?=)))
  6848. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6849. ;; Select appropriate duration. Ignore non-digit characters.
  6850. (let ((prompt
  6851. (apply #'format
  6852. (concat "Effort %c "
  6853. (mapconcat (lambda (s) (concat "[%d]" s))
  6854. efforts
  6855. " "))
  6856. op allowed-keys))
  6857. (eff -1))
  6858. (while (not (memq eff allowed-keys))
  6859. (message prompt)
  6860. (setq eff (- (read-char-exclusive) 48)))
  6861. (setq org-agenda-effort-filter
  6862. (list (concat (if strip "-" "+")
  6863. (char-to-string op)
  6864. ;; Numbering is 1 2 3 ... 9 0, but we want
  6865. ;; 0 1 2 ... 8 9.
  6866. (nth (mod (1- eff) 10) efforts)))))
  6867. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6868. (t (org-agenda-filter-show-all-effort)
  6869. (message "Effort filter removed"))))
  6870. (defun org-agenda-filter-remove-all ()
  6871. "Remove all filters from the current agenda buffer."
  6872. (interactive)
  6873. (when org-agenda-tag-filter
  6874. (org-agenda-filter-show-all-tag))
  6875. (when org-agenda-category-filter
  6876. (org-agenda-filter-show-all-cat))
  6877. (when org-agenda-regexp-filter
  6878. (org-agenda-filter-show-all-re))
  6879. (when org-agenda-top-headline-filter
  6880. (org-agenda-filter-show-all-top-filter))
  6881. (when org-agenda-effort-filter
  6882. (org-agenda-filter-show-all-effort))
  6883. (org-agenda-finalize))
  6884. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6885. "Keep only those lines in the agenda buffer that have a specific tag.
  6886. The tag is selected with its fast selection letter, as configured.
  6887. With a `\\[universal-argument]' prefix, exclude the agenda search.
  6888. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  6889. i.e. don't
  6890. filter on all its group members.
  6891. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  6892. should be used to exclude the search - the interactive user can
  6893. also press `-' or `+' to switch between filtering and excluding."
  6894. (interactive "P")
  6895. (let* ((alist org-tag-alist-for-agenda)
  6896. (tag-chars (mapconcat
  6897. (lambda (x) (if (and (not (symbolp (car x)))
  6898. (cdr x))
  6899. (char-to-string (cdr x))
  6900. ""))
  6901. org-tag-alist-for-agenda ""))
  6902. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  6903. (string-to-list tag-chars)))
  6904. (exclude (or exclude (equal arg '(4))))
  6905. (expand (not (equal arg '(16))))
  6906. (inhibit-read-only t)
  6907. (current org-agenda-tag-filter)
  6908. a n tag)
  6909. (unless char
  6910. (while (not (memq char valid-char-list))
  6911. (message
  6912. "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  6913. (if exclude "Exclude" "Filter") tag-chars
  6914. (if org-agenda-auto-exclude-function "[RET], " "")
  6915. (if expand "" ", no grouptag expand"))
  6916. (setq char (read-char-exclusive))
  6917. ;; Excluding or filtering down
  6918. (cond ((eq char ?-) (setq exclude t))
  6919. ((eq char ?+) (setq exclude nil)))))
  6920. (when (eq char ?\t)
  6921. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6922. (setq-local org-global-tags-completion-table
  6923. (org-global-tags-completion-table)))
  6924. (let ((completion-ignore-case t))
  6925. (setq tag (completing-read
  6926. "Tag: " org-global-tags-completion-table))))
  6927. (cond
  6928. ((eq char ?\r)
  6929. (org-agenda-filter-show-all-tag)
  6930. (when org-agenda-auto-exclude-function
  6931. (setq org-agenda-tag-filter nil)
  6932. (dolist (tag (org-agenda-get-represented-tags))
  6933. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6934. (if modifier
  6935. (push modifier org-agenda-tag-filter))))
  6936. (if (not (null org-agenda-tag-filter))
  6937. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  6938. ((eq char ?/)
  6939. (org-agenda-filter-show-all-tag)
  6940. (when (get 'org-agenda-tag-filter :preset-filter)
  6941. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  6942. ((eq char ?.)
  6943. (setq org-agenda-tag-filter
  6944. (mapcar (lambda(tag) (concat "+" tag))
  6945. (org-get-at-bol 'tags)))
  6946. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  6947. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  6948. ((or (eq char ?\s)
  6949. (setq a (rassoc char alist))
  6950. (and tag (setq a (cons tag nil))))
  6951. (org-agenda-filter-show-all-tag)
  6952. (setq tag (car a))
  6953. (setq org-agenda-tag-filter
  6954. (cons (concat (if exclude "-" "+") tag)
  6955. current))
  6956. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  6957. (t (error "Invalid tag selection character %c" char)))))
  6958. (defun org-agenda-get-represented-tags ()
  6959. "Get a list of all tags currently represented in the agenda."
  6960. (let (p tags)
  6961. (save-excursion
  6962. (goto-char (point-min))
  6963. (while (setq p (next-single-property-change (point) 'tags))
  6964. (goto-char p)
  6965. (mapc (lambda (x) (add-to-list 'tags x))
  6966. (get-text-property (point) 'tags))))
  6967. tags))
  6968. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  6969. "Create the form that tests a line for agenda filter. Optional
  6970. argument EXPAND can be used for the TYPE tag and will expand the
  6971. tags in the FILTER if any of the tags in FILTER are grouptags."
  6972. (let (f f1)
  6973. (cond
  6974. ;; Tag filter
  6975. ((eq type 'tag)
  6976. (setq filter
  6977. (delete-dups
  6978. (append (get 'org-agenda-tag-filter :preset-filter)
  6979. filter)))
  6980. (dolist (x filter)
  6981. (let ((op (string-to-char x)))
  6982. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  6983. (setq x (list x)))
  6984. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  6985. (push f1 f))))
  6986. ;; Category filter
  6987. ((eq type 'category)
  6988. (setq filter
  6989. (delete-dups
  6990. (append (get 'org-agenda-category-filter :preset-filter)
  6991. filter)))
  6992. (dolist (x filter)
  6993. (if (equal "-" (substring x 0 1))
  6994. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6995. (setq f1 (list 'equal (substring x 1) 'cat)))
  6996. (push f1 f)))
  6997. ;; Regexp filter
  6998. ((eq type 'regexp)
  6999. (setq filter
  7000. (delete-dups
  7001. (append (get 'org-agenda-regexp-filter :preset-filter)
  7002. filter)))
  7003. (dolist (x filter)
  7004. (if (equal "-" (substring x 0 1))
  7005. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7006. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7007. (push f1 f)))
  7008. ;; Effort filter
  7009. ((eq type 'effort)
  7010. (setq filter
  7011. (delete-dups
  7012. (append (get 'org-agenda-effort-filter :preset-filter)
  7013. filter)))
  7014. (dolist (x filter)
  7015. (push (org-agenda-filter-effort-form x) f))))
  7016. (cons 'and (nreverse f))))
  7017. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7018. "Return a form associated to tag-expression TAGS.
  7019. Build a form testing a line for agenda filter for
  7020. tag-expressions. OP is an operator of type CHAR that allows the
  7021. function to set the right switches in the returned form."
  7022. (let (form)
  7023. ;; Any of the expressions can match if OP is +, all must match if
  7024. ;; the operator is -.
  7025. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7026. (let* ((tag (substring x 1))
  7027. (f (cond
  7028. ((string= "" tag) '(not tags))
  7029. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7030. ;; TAG is a regexp.
  7031. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7032. (t (list 'member (downcase tag) 'tags)))))
  7033. (push (if (eq op ?-) (list 'not f) f) form)))))
  7034. (defun org-agenda-filter-effort-form (e)
  7035. "Return the form to compare the effort of the current line with what E says.
  7036. E looks like \"+<2:25\"."
  7037. (let (op)
  7038. (setq e (substring e 1))
  7039. (setq op (string-to-char e) e (substring e 1))
  7040. (setq op (cond ((equal op ?<) '<=)
  7041. ((equal op ?>) '>=)
  7042. ((equal op ??) op)
  7043. (t '=)))
  7044. (list 'org-agenda-compare-effort (list 'quote op)
  7045. (org-duration-to-minutes e))))
  7046. (defun org-agenda-compare-effort (op value)
  7047. "Compare the effort of the current line with VALUE, using OP.
  7048. If the line does not have an effort defined, return nil."
  7049. ;; `effort-minutes' property cannot be extracted directly from
  7050. ;; current line but is stored as a property in `txt'.
  7051. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7052. (funcall op
  7053. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7054. value)))
  7055. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7056. "Expand group tags in FILTER for the agenda.
  7057. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7058. (if org-group-tags
  7059. (let ((case-fold-search t) rtn)
  7060. (mapc
  7061. (lambda (f)
  7062. (let (f0 dir)
  7063. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7064. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7065. (setq dir (if no-operator "" "+") f0 f))
  7066. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7067. (org-tags-expand f0 t t))
  7068. rtn))))
  7069. filter)
  7070. (reverse rtn))
  7071. filter))
  7072. (defun org-agenda-filter-apply (filter type &optional expand)
  7073. "Set FILTER as the new agenda filter and apply it. Optional
  7074. argument EXPAND can be used for the TYPE tag and will expand the
  7075. tags in the FILTER if any of the tags in FILTER are grouptags."
  7076. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7077. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7078. (let (tags cat txt)
  7079. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7080. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7081. ;; category is used as the filter:
  7082. (setq org-agenda-filtered-by-category
  7083. (and (eq type 'category)
  7084. (not (equal (substring (car filter) 0 1) "-"))))
  7085. (org-agenda-set-mode-name)
  7086. (save-excursion
  7087. (goto-char (point-min))
  7088. (while (not (eobp))
  7089. (if (org-get-at-bol 'org-marker)
  7090. (progn
  7091. (setq tags (org-get-at-bol 'tags)
  7092. cat (org-get-at-eol 'org-category 1)
  7093. txt (org-get-at-bol 'txt))
  7094. (if (not (eval org-agenda-filter-form))
  7095. (org-agenda-filter-hide-line type))
  7096. (beginning-of-line 2))
  7097. (beginning-of-line 2))))
  7098. (if (get-char-property (point) 'invisible)
  7099. (ignore-errors (org-agenda-previous-line)))))
  7100. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7101. "Filter by top headline HL."
  7102. (org-agenda-set-mode-name)
  7103. (save-excursion
  7104. (goto-char (point-min))
  7105. (while (not (eobp))
  7106. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7107. (tophl (and pos (org-find-top-headline pos))))
  7108. (if (and tophl (funcall (if negative 'identity 'not)
  7109. (string= hl tophl)))
  7110. (org-agenda-filter-hide-line 'top-headline)))
  7111. (beginning-of-line 2)))
  7112. (if (get-char-property (point) 'invisible)
  7113. (org-agenda-previous-line))
  7114. (setq org-agenda-top-headline-filter hl
  7115. org-agenda-filtered-by-top-headline t))
  7116. (defun org-agenda-filter-hide-line (type)
  7117. "Hide lines with TYPE in the agenda buffer."
  7118. (let* ((b (max (point-min) (1- (point-at-bol))))
  7119. (e (point-at-eol)))
  7120. (let ((inhibit-read-only t))
  7121. (add-text-properties
  7122. b e `(invisible org-filtered org-filter-type ,type)))))
  7123. (defun org-agenda-remove-filter (type)
  7124. (interactive)
  7125. "Remove filter of type TYPE from the agenda buffer."
  7126. (save-excursion
  7127. (goto-char (point-min))
  7128. (let ((inhibit-read-only t) pos)
  7129. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7130. (goto-char pos)
  7131. (remove-text-properties
  7132. (point) (next-single-property-change (point) 'org-filter-type)
  7133. `(invisible org-filtered org-filter-type ,type))))
  7134. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7135. (setq org-agenda-filter-form nil)
  7136. (org-agenda-set-mode-name)
  7137. (org-agenda-finalize)))
  7138. (defun org-agenda-filter-show-all-tag nil
  7139. (org-agenda-remove-filter 'tag))
  7140. (defun org-agenda-filter-show-all-re nil
  7141. (org-agenda-remove-filter 'regexp))
  7142. (defun org-agenda-filter-show-all-effort nil
  7143. (org-agenda-remove-filter 'effort))
  7144. (defun org-agenda-filter-show-all-cat nil
  7145. (org-agenda-remove-filter 'category))
  7146. (defun org-agenda-filter-show-all-top-filter nil
  7147. (org-agenda-remove-filter 'top-headline))
  7148. (defun org-agenda-manipulate-query-add ()
  7149. "Manipulate the query by adding a search term with positive selection.
  7150. Positive selection means the term must be matched for selection of an entry."
  7151. (interactive)
  7152. (org-agenda-manipulate-query ?\[))
  7153. (defun org-agenda-manipulate-query-subtract ()
  7154. "Manipulate the query by adding a search term with negative selection.
  7155. Negative selection means term must not be matched for selection of an entry."
  7156. (interactive)
  7157. (org-agenda-manipulate-query ?\]))
  7158. (defun org-agenda-manipulate-query-add-re ()
  7159. "Manipulate the query by adding a search regexp with positive selection.
  7160. Positive selection means the regexp must match for selection of an entry."
  7161. (interactive)
  7162. (org-agenda-manipulate-query ?\{))
  7163. (defun org-agenda-manipulate-query-subtract-re ()
  7164. "Manipulate the query by adding a search regexp with negative selection.
  7165. Negative selection means regexp must not match for selection of an entry."
  7166. (interactive)
  7167. (org-agenda-manipulate-query ?\}))
  7168. (defun org-agenda-manipulate-query (char)
  7169. (cond
  7170. ((memq org-agenda-type '(timeline agenda))
  7171. (let ((org-agenda-include-inactive-timestamps t))
  7172. (org-agenda-redo))
  7173. (message "Display now includes inactive timestamps as well"))
  7174. ((eq org-agenda-type 'search)
  7175. (org-add-to-string
  7176. 'org-agenda-query-string
  7177. (if org-agenda-last-search-view-search-was-boolean
  7178. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7179. (?\{ . " +{}") (?\} . " -{}"))))
  7180. " "))
  7181. (setq org-agenda-redo-command
  7182. (list 'org-search-view
  7183. (car (get-text-property (min (1- (point-max)) (point))
  7184. 'org-last-args))
  7185. org-agenda-query-string
  7186. (+ (length org-agenda-query-string)
  7187. (if (member char '(?\{ ?\})) 0 1))))
  7188. (set-register org-agenda-query-register org-agenda-query-string)
  7189. (let ((org-agenda-overriding-arguments
  7190. (cdr org-agenda-redo-command)))
  7191. (org-agenda-redo)))
  7192. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7193. org-agenda-type))))
  7194. (defun org-add-to-string (var string)
  7195. (set var (concat (symbol-value var) string)))
  7196. (defun org-agenda-goto-date (span)
  7197. "Jump to DATE in agenda."
  7198. (interactive "P")
  7199. (let* ((org-read-date-prefer-future
  7200. (eval org-agenda-jump-prefer-future))
  7201. (date (org-read-date))
  7202. (day (time-to-days (org-time-string-to-time date)))
  7203. (org-agenda-sticky-orig org-agenda-sticky)
  7204. (org-agenda-buffer-tmp-name (buffer-name))
  7205. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7206. (0-arg (or current-prefix-arg (car args)))
  7207. (2-arg (nth 2 args))
  7208. (with-hour-p (nth 4 org-agenda-redo-command))
  7209. (newcmd (list 'org-agenda-list 0-arg date
  7210. (org-agenda-span-to-ndays
  7211. 2-arg (org-time-string-to-absolute date))
  7212. with-hour-p))
  7213. (newargs (cdr newcmd))
  7214. (inhibit-read-only t)
  7215. org-agenda-sticky)
  7216. (if (not (org-agenda-check-type t 'agenda))
  7217. (error "Not available in non-agenda views")
  7218. (add-text-properties (point-min) (point-max)
  7219. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7220. (org-agenda-redo)
  7221. (goto-char (point-min))
  7222. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7223. (save-excursion (move-beginning-of-line 2) (eobp))))
  7224. (move-beginning-of-line 2))
  7225. (setq org-agenda-sticky org-agenda-sticky-orig
  7226. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7227. (defun org-agenda-goto-today ()
  7228. "Go to today."
  7229. (interactive)
  7230. (org-agenda-check-type t 'timeline 'agenda)
  7231. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7232. (curspan (nth 2 args))
  7233. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7234. (cond
  7235. (tdpos (goto-char tdpos))
  7236. ((eq org-agenda-type 'agenda)
  7237. (let* ((sd (org-agenda-compute-starting-span
  7238. (org-today) (or curspan org-agenda-span)))
  7239. (org-agenda-overriding-arguments args))
  7240. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7241. (org-agenda-redo)
  7242. (org-agenda-find-same-or-today-or-agenda)))
  7243. (t (error "Cannot find today")))))
  7244. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7245. (goto-char
  7246. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7247. (text-property-any (point-min) (point-max) 'org-today t)
  7248. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7249. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7250. (org-agenda-backward-block))
  7251. (point-min))))
  7252. (defun org-agenda-backward-block ()
  7253. "Move backward by one agenda block."
  7254. (interactive)
  7255. (org-agenda-forward-block 'backward))
  7256. (defun org-agenda-forward-block (&optional backward)
  7257. "Move forward by one agenda block.
  7258. When optional argument BACKWARD is set, go backward"
  7259. (interactive)
  7260. (cond ((not (derived-mode-p 'org-agenda-mode))
  7261. (user-error
  7262. "Cannot execute this command outside of org-agenda-mode buffers"))
  7263. ((looking-at (if backward "\\`" "\\'"))
  7264. (message "Already at the %s block" (if backward "first" "last")))
  7265. (t (let ((pos (prog1 (point)
  7266. (ignore-errors (if backward (backward-char 1)
  7267. (move-end-of-line 1)))))
  7268. (f (if backward
  7269. 'previous-single-property-change
  7270. 'next-single-property-change))
  7271. moved dest)
  7272. (while (and (setq dest (funcall
  7273. f (point) 'org-agenda-structural-header))
  7274. (not (get-text-property
  7275. (point) 'org-agenda-structural-header)))
  7276. (setq moved t)
  7277. (goto-char dest))
  7278. (if moved (move-beginning-of-line 1)
  7279. (goto-char (if backward (point-min) (point-max)))
  7280. (move-beginning-of-line 1)
  7281. (message "No %s block" (if backward "previous" "further")))))))
  7282. (defun org-agenda-later (arg)
  7283. "Go forward in time by the current span.
  7284. With prefix ARG, go forward that many times the current span."
  7285. (interactive "p")
  7286. (org-agenda-check-type t 'agenda)
  7287. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7288. (span (or (nth 2 args) org-agenda-current-span))
  7289. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7290. (greg (calendar-gregorian-from-absolute sd))
  7291. (cnt (org-get-at-bol 'org-day-cnt))
  7292. greg2)
  7293. (cond
  7294. ((numberp span)
  7295. (setq sd (+ (* span arg) sd)))
  7296. ((eq span 'day)
  7297. (setq sd (+ arg sd)))
  7298. ((eq span 'week)
  7299. (setq sd (+ (* 7 arg) sd)))
  7300. ((eq span 'fortnight)
  7301. (setq sd (+ (* 14 arg) sd)))
  7302. ((eq span 'month)
  7303. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7304. sd (calendar-absolute-from-gregorian greg2))
  7305. (setcar greg2 (1+ (car greg2))))
  7306. ((eq span 'year)
  7307. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7308. sd (calendar-absolute-from-gregorian greg2))
  7309. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7310. (t
  7311. (setq sd (+ (* span arg) sd))))
  7312. (let ((org-agenda-overriding-cmd
  7313. ;; `cmd' may have been set by `org-agenda-run-series' which
  7314. ;; uses `org-agenda-overriding-cmd' to decide whether
  7315. ;; overriding is allowed for `cmd'
  7316. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7317. (org-agenda-overriding-arguments
  7318. (list (car args) sd span)))
  7319. (org-agenda-redo)
  7320. (org-agenda-find-same-or-today-or-agenda cnt))))
  7321. (defun org-agenda-earlier (arg)
  7322. "Go backward in time by the current span.
  7323. With prefix ARG, go backward that many times the current span."
  7324. (interactive "p")
  7325. (org-agenda-later (- arg)))
  7326. (defun org-agenda-view-mode-dispatch ()
  7327. "Call one of the view mode commands."
  7328. (interactive)
  7329. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7330. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7331. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7332. (pcase (read-char-exclusive)
  7333. (?\ (call-interactively 'org-agenda-reset-view))
  7334. (?d (call-interactively 'org-agenda-day-view))
  7335. (?w (call-interactively 'org-agenda-week-view))
  7336. (?t (call-interactively 'org-agenda-fortnight-view))
  7337. (?m (call-interactively 'org-agenda-month-view))
  7338. (?y (call-interactively 'org-agenda-year-view))
  7339. (?l (call-interactively 'org-agenda-log-mode))
  7340. (?L (org-agenda-log-mode '(4)))
  7341. (?c (org-agenda-log-mode 'clockcheck))
  7342. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7343. (?a (call-interactively 'org-agenda-archives-mode))
  7344. (?A (org-agenda-archives-mode 'files))
  7345. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7346. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7347. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7348. (?D (call-interactively 'org-agenda-toggle-diary))
  7349. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7350. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7351. (org-agenda-check-type t 'timeline 'agenda)
  7352. (org-agenda-redo))
  7353. (message "Display now includes inactive timestamps as well"))
  7354. (?q (message "Abort"))
  7355. (key (user-error "Invalid key: %s" key))))
  7356. (defun org-agenda-reset-view ()
  7357. "Switch to default view for agenda."
  7358. (interactive)
  7359. (org-agenda-change-time-span org-agenda-span))
  7360. (defun org-agenda-day-view (&optional day-of-month)
  7361. "Switch to daily view for agenda.
  7362. With argument DAY-OF-MONTH, switch to that day of the month."
  7363. (interactive "P")
  7364. (org-agenda-change-time-span 'day day-of-month))
  7365. (defun org-agenda-week-view (&optional iso-week)
  7366. "Switch to weekly view for agenda.
  7367. With argument ISO-WEEK, switch to the corresponding ISO week.
  7368. If ISO-WEEK has more then 2 digits, only the last two encode
  7369. the week. Any digits before this encode a year. So 200712
  7370. means week 12 of year 2007. Years ranging from 70 years ago
  7371. to 30 years in the future can also be written as 2-digit years."
  7372. (interactive "P")
  7373. (org-agenda-change-time-span 'week iso-week))
  7374. (defun org-agenda-fortnight-view (&optional iso-week)
  7375. "Switch to fortnightly view for agenda.
  7376. With argument ISO-WEEK, switch to the corresponding ISO week.
  7377. If ISO-WEEK has more then 2 digits, only the last two encode
  7378. the week. Any digits before this encode a year. So 200712
  7379. means week 12 of year 2007. Years ranging from 70 years ago
  7380. to 30 years in the future can also be written as 2-digit years."
  7381. (interactive "P")
  7382. (org-agenda-change-time-span 'fortnight iso-week))
  7383. (defun org-agenda-month-view (&optional month)
  7384. "Switch to monthly view for agenda.
  7385. With argument MONTH, switch to that month. If MONTH has more
  7386. then 2 digits, only the last two encode the month. Any digits
  7387. before this encode a year. So 200712 means December year 2007.
  7388. Years ranging from 70 years ago to 30 years in the future can
  7389. also be written as 2-digit years."
  7390. (interactive "P")
  7391. (org-agenda-change-time-span 'month month))
  7392. (defun org-agenda-year-view (&optional year)
  7393. "Switch to yearly view for agenda.
  7394. With argument YEAR, switch to that year. Years ranging from 70
  7395. years ago to 30 years in the future can also be written as
  7396. 2-digit years."
  7397. (interactive "P")
  7398. (when year
  7399. (setq year (org-small-year-to-year year)))
  7400. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7401. (org-agenda-change-time-span 'year year)
  7402. (error "Abort")))
  7403. (defun org-agenda-change-time-span (span &optional n)
  7404. "Change the agenda view to SPAN.
  7405. SPAN may be `day', `week', `fortnight', `month', `year'."
  7406. (org-agenda-check-type t 'agenda)
  7407. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7408. (curspan (nth 2 args)))
  7409. (if (and (not n) (equal curspan span))
  7410. (error "Viewing span is already \"%s\"" span))
  7411. (let* ((sd (or (org-get-at-bol 'day)
  7412. (nth 1 args)
  7413. org-starting-day))
  7414. (sd (org-agenda-compute-starting-span sd span n))
  7415. (org-agenda-overriding-cmd
  7416. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7417. (org-agenda-overriding-arguments
  7418. (list (car args) sd span)))
  7419. (org-agenda-redo)
  7420. (org-agenda-find-same-or-today-or-agenda))
  7421. (org-agenda-set-mode-name)
  7422. (message "Switched to %s view" span)))
  7423. (defun org-agenda-compute-starting-span (sd span &optional n)
  7424. "Compute starting date for agenda.
  7425. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7426. is a cons cell with the starting date and the number of days,
  7427. so that the date SD will be in that range."
  7428. (let* ((greg (calendar-gregorian-from-absolute sd))
  7429. (dg (nth 1 greg))
  7430. (mg (car greg))
  7431. (yg (nth 2 greg)))
  7432. (cond
  7433. ((eq span 'day)
  7434. (when n
  7435. (setq sd (+ (calendar-absolute-from-gregorian
  7436. (list mg 1 yg))
  7437. n -1))))
  7438. ((or (eq span 'week) (eq span 'fortnight))
  7439. (let* ((nt (calendar-day-of-week
  7440. (calendar-gregorian-from-absolute sd)))
  7441. (d (if org-agenda-start-on-weekday
  7442. (- nt org-agenda-start-on-weekday)
  7443. 0))
  7444. y1)
  7445. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7446. (when n
  7447. (require 'cal-iso)
  7448. (when (> n 99)
  7449. (setq y1 (org-small-year-to-year (/ n 100))
  7450. n (mod n 100)))
  7451. (setq sd
  7452. (calendar-iso-to-absolute
  7453. (list n 1
  7454. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7455. ((eq span 'month)
  7456. (let (y1)
  7457. (when (and n (> n 99))
  7458. (setq y1 (org-small-year-to-year (/ n 100))
  7459. n (mod n 100)))
  7460. (setq sd (calendar-absolute-from-gregorian
  7461. (list (or n mg) 1 (or y1 yg))))))
  7462. ((eq span 'year)
  7463. (setq sd (calendar-absolute-from-gregorian
  7464. (list 1 1 (or n yg))))))
  7465. sd))
  7466. (defun org-agenda-next-date-line (&optional arg)
  7467. "Jump to the next line indicating a date in agenda buffer."
  7468. (interactive "p")
  7469. (org-agenda-check-type t 'agenda 'timeline)
  7470. (beginning-of-line 1)
  7471. ;; This does not work if user makes date format that starts with a blank
  7472. (if (looking-at "^\\S-") (forward-char 1))
  7473. (if (not (re-search-forward "^\\S-" nil t arg))
  7474. (progn
  7475. (backward-char 1)
  7476. (error "No next date after this line in this buffer")))
  7477. (goto-char (match-beginning 0)))
  7478. (defun org-agenda-previous-date-line (&optional arg)
  7479. "Jump to the previous line indicating a date in agenda buffer."
  7480. (interactive "p")
  7481. (org-agenda-check-type t 'agenda 'timeline)
  7482. (beginning-of-line 1)
  7483. (if (not (re-search-backward "^\\S-" nil t arg))
  7484. (error "No previous date before this line in this buffer")))
  7485. ;; Initialize the highlight
  7486. (defvar org-hl (make-overlay 1 1))
  7487. (overlay-put org-hl 'face 'highlight)
  7488. (defun org-highlight (begin end &optional buffer)
  7489. "Highlight a region with overlay."
  7490. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7491. (defun org-unhighlight ()
  7492. "Detach overlay INDEX."
  7493. (delete-overlay org-hl))
  7494. (defun org-unhighlight-once ()
  7495. "Remove the highlight from its position, and this function from the hook."
  7496. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7497. (org-unhighlight))
  7498. (defvar org-agenda-pre-follow-window-conf nil)
  7499. (defun org-agenda-follow-mode ()
  7500. "Toggle follow mode in an agenda buffer."
  7501. (interactive)
  7502. (unless org-agenda-follow-mode
  7503. (setq org-agenda-pre-follow-window-conf
  7504. (current-window-configuration)))
  7505. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7506. (unless org-agenda-follow-mode
  7507. (set-window-configuration org-agenda-pre-follow-window-conf))
  7508. (org-agenda-set-mode-name)
  7509. (org-agenda-do-context-action)
  7510. (message "Follow mode is %s"
  7511. (if org-agenda-follow-mode "on" "off")))
  7512. (defun org-agenda-entry-text-mode (&optional arg)
  7513. "Toggle entry text mode in an agenda buffer."
  7514. (interactive "P")
  7515. (if (or org-agenda-tag-filter
  7516. org-agenda-category-filter
  7517. org-agenda-regexp-filter
  7518. org-agenda-top-headline-filter)
  7519. (user-error "Can't show entry text in filtered views")
  7520. (setq org-agenda-entry-text-mode (or (integerp arg)
  7521. (not org-agenda-entry-text-mode)))
  7522. (org-agenda-entry-text-hide)
  7523. (and org-agenda-entry-text-mode
  7524. (let ((org-agenda-entry-text-maxlines
  7525. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7526. (org-agenda-entry-text-show)))
  7527. (org-agenda-set-mode-name)
  7528. (message "Entry text mode is %s%s"
  7529. (if org-agenda-entry-text-mode "on" "off")
  7530. (if (not org-agenda-entry-text-mode) ""
  7531. (format " (maximum number of lines is %d)"
  7532. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7533. (defun org-agenda-clockreport-mode ()
  7534. "Toggle clocktable mode in an agenda buffer."
  7535. (interactive)
  7536. (org-agenda-check-type t 'agenda)
  7537. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7538. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7539. (org-agenda-set-mode-name)
  7540. (org-agenda-redo)
  7541. (message "Clocktable mode is %s"
  7542. (if org-agenda-clockreport-mode "on" "off")))
  7543. (defun org-agenda-log-mode (&optional special)
  7544. "Toggle log mode in an agenda buffer.
  7545. With argument SPECIAL, show all possible log items, not only the ones
  7546. configured in `org-agenda-log-mode-items'.
  7547. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7548. log items, nothing else."
  7549. (interactive "P")
  7550. (org-agenda-check-type t 'agenda 'timeline)
  7551. (setq org-agenda-show-log
  7552. (cond
  7553. ((equal special '(16)) 'only)
  7554. ((eq special 'clockcheck)
  7555. (if (eq org-agenda-show-log 'clockcheck)
  7556. nil 'clockcheck))
  7557. (special '(closed clock state))
  7558. (t (not org-agenda-show-log))))
  7559. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7560. (org-agenda-set-mode-name)
  7561. (org-agenda-redo)
  7562. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7563. (defun org-agenda-archives-mode (&optional with-files)
  7564. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7565. When called with a prefix argument, include all archive files as well."
  7566. (interactive "P")
  7567. (setq org-agenda-archives-mode
  7568. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7569. (org-agenda-set-mode-name)
  7570. (org-agenda-redo)
  7571. (message
  7572. "%s"
  7573. (cond
  7574. ((eq org-agenda-archives-mode nil)
  7575. "No archives are included")
  7576. ((eq org-agenda-archives-mode 'trees)
  7577. (format "Trees with :%s: tag are included" org-archive-tag))
  7578. ((eq org-agenda-archives-mode t)
  7579. (format "Trees with :%s: tag and all active archive files are included"
  7580. org-archive-tag)))))
  7581. (defun org-agenda-toggle-diary ()
  7582. "Toggle diary inclusion in an agenda buffer."
  7583. (interactive)
  7584. (org-agenda-check-type t 'agenda)
  7585. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7586. (org-agenda-redo)
  7587. (org-agenda-set-mode-name)
  7588. (message "Diary inclusion turned %s"
  7589. (if org-agenda-include-diary "on" "off")))
  7590. (defun org-agenda-toggle-deadlines ()
  7591. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7592. (interactive)
  7593. (org-agenda-check-type t 'agenda)
  7594. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7595. (org-agenda-redo)
  7596. (org-agenda-set-mode-name)
  7597. (message "Deadlines inclusion turned %s"
  7598. (if org-agenda-include-deadlines "on" "off")))
  7599. (defun org-agenda-toggle-time-grid ()
  7600. "Toggle time grid in an agenda buffer."
  7601. (interactive)
  7602. (org-agenda-check-type t 'agenda)
  7603. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7604. (org-agenda-redo)
  7605. (org-agenda-set-mode-name)
  7606. (message "Time-grid turned %s"
  7607. (if org-agenda-use-time-grid "on" "off")))
  7608. (defun org-agenda-set-mode-name ()
  7609. "Set the mode name to indicate all the small mode settings."
  7610. (setq mode-name
  7611. (list "Org-Agenda"
  7612. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7613. " "
  7614. '(:eval (org-agenda-span-name org-agenda-current-span))
  7615. (if org-agenda-follow-mode " Follow" "")
  7616. (if org-agenda-entry-text-mode " ETxt" "")
  7617. (if org-agenda-include-diary " Diary" "")
  7618. (if org-agenda-include-deadlines " Ddl" "")
  7619. (if org-agenda-use-time-grid " Grid" "")
  7620. (if (and (boundp 'org-habit-show-habits)
  7621. org-habit-show-habits) " Habit" "")
  7622. (cond
  7623. ((consp org-agenda-show-log) " LogAll")
  7624. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7625. (org-agenda-show-log " Log")
  7626. (t ""))
  7627. (if (or org-agenda-category-filter
  7628. (get 'org-agenda-category-filter :preset-filter))
  7629. '(:eval (propertize
  7630. (concat " <"
  7631. (mapconcat
  7632. 'identity
  7633. (append
  7634. (get 'org-agenda-category-filter :preset-filter)
  7635. org-agenda-category-filter)
  7636. "")
  7637. ">")
  7638. 'face 'org-agenda-filter-category
  7639. 'help-echo "Category used in filtering")) "")
  7640. (if (or org-agenda-tag-filter
  7641. (get 'org-agenda-tag-filter :preset-filter))
  7642. '(:eval (propertize
  7643. (concat " {"
  7644. (mapconcat
  7645. 'identity
  7646. (append
  7647. (get 'org-agenda-tag-filter :preset-filter)
  7648. org-agenda-tag-filter)
  7649. "")
  7650. "}")
  7651. 'face 'org-agenda-filter-tags
  7652. 'help-echo "Tags used in filtering")) "")
  7653. (if (or org-agenda-effort-filter
  7654. (get 'org-agenda-effort-filter :preset-filter))
  7655. '(:eval (propertize
  7656. (concat " {"
  7657. (mapconcat
  7658. 'identity
  7659. (append
  7660. (get 'org-agenda-effort-filter :preset-filter)
  7661. org-agenda-effort-filter)
  7662. "")
  7663. "}")
  7664. 'face 'org-agenda-filter-effort
  7665. 'help-echo "Effort conditions used in filtering")) "")
  7666. (if (or org-agenda-regexp-filter
  7667. (get 'org-agenda-regexp-filter :preset-filter))
  7668. '(:eval (propertize
  7669. (concat " ["
  7670. (mapconcat
  7671. 'identity
  7672. (append
  7673. (get 'org-agenda-regexp-filter :preset-filter)
  7674. org-agenda-regexp-filter)
  7675. "")
  7676. "]")
  7677. 'face 'org-agenda-filter-regexp
  7678. 'help-echo "Regexp used in filtering")) "")
  7679. (if org-agenda-archives-mode
  7680. (if (eq org-agenda-archives-mode t)
  7681. " Archives"
  7682. (format " :%s:" org-archive-tag))
  7683. "")
  7684. (if org-agenda-clockreport-mode " Clock" "")))
  7685. (force-mode-line-update))
  7686. (defun org-agenda-update-agenda-type ()
  7687. "Update the agenda type after each command."
  7688. (setq org-agenda-type
  7689. (or (get-text-property (point) 'org-agenda-type)
  7690. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7691. (defun org-agenda-next-line ()
  7692. "Move cursor to the next line, and show if follow mode is active."
  7693. (interactive)
  7694. (call-interactively 'next-line)
  7695. (org-agenda-do-context-action))
  7696. (defun org-agenda-previous-line ()
  7697. "Move cursor to the previous line, and show if follow-mode is active."
  7698. (interactive)
  7699. (call-interactively 'previous-line)
  7700. (org-agenda-do-context-action))
  7701. (defun org-agenda-next-item (n)
  7702. "Move cursor to next agenda item."
  7703. (interactive "p")
  7704. (let ((col (current-column)))
  7705. (dotimes (c n)
  7706. (when (next-single-property-change (point-at-eol) 'org-marker)
  7707. (move-end-of-line 1)
  7708. (goto-char (next-single-property-change (point) 'org-marker))))
  7709. (org-move-to-column col))
  7710. (org-agenda-do-context-action))
  7711. (defun org-agenda-previous-item (n)
  7712. "Move cursor to next agenda item."
  7713. (interactive "p")
  7714. (dotimes (c n)
  7715. (let ((col (current-column))
  7716. (goto (save-excursion
  7717. (move-end-of-line 0)
  7718. (previous-single-property-change (point) 'org-marker))))
  7719. (if goto (goto-char goto))
  7720. (org-move-to-column col)))
  7721. (org-agenda-do-context-action))
  7722. (defun org-agenda-do-context-action ()
  7723. "Show outline path and, maybe, follow mode window."
  7724. (let ((m (org-get-at-bol 'org-marker)))
  7725. (when (and (markerp m) (marker-buffer m))
  7726. (and org-agenda-follow-mode
  7727. (if org-agenda-follow-indirect
  7728. (org-agenda-tree-to-indirect-buffer nil)
  7729. (org-agenda-show)))
  7730. (and org-agenda-show-outline-path
  7731. (org-with-point-at m (org-display-outline-path t))))))
  7732. (defun org-agenda-show-tags ()
  7733. "Show the tags applicable to the current item."
  7734. (interactive)
  7735. (let* ((tags (org-get-at-bol 'tags)))
  7736. (if tags
  7737. (message "Tags are :%s:"
  7738. (org-no-properties (mapconcat 'identity tags ":")))
  7739. (message "No tags associated with this line"))))
  7740. (defun org-agenda-goto (&optional highlight)
  7741. "Go to the entry at point in the corresponding Org file."
  7742. (interactive)
  7743. (let* ((marker (or (org-get-at-bol 'org-marker)
  7744. (org-agenda-error)))
  7745. (buffer (marker-buffer marker))
  7746. (pos (marker-position marker)))
  7747. (switch-to-buffer-other-window buffer)
  7748. (widen)
  7749. (push-mark)
  7750. (goto-char pos)
  7751. (when (derived-mode-p 'org-mode)
  7752. (org-show-context 'agenda)
  7753. (recenter (/ (window-height) 2))
  7754. (org-back-to-heading t)
  7755. (let ((case-fold-search nil))
  7756. (when (re-search-forward org-complex-heading-regexp nil t)
  7757. (goto-char (match-beginning 4)))))
  7758. (run-hooks 'org-agenda-after-show-hook)
  7759. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7760. (defvar org-agenda-after-show-hook nil
  7761. "Normal hook run after an item has been shown from the agenda.
  7762. Point is in the buffer where the item originated.")
  7763. (defun org-agenda-kill ()
  7764. "Kill the entry or subtree belonging to the current agenda entry."
  7765. (interactive)
  7766. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7767. (let* ((bufname-orig (buffer-name))
  7768. (marker (or (org-get-at-bol 'org-marker)
  7769. (org-agenda-error)))
  7770. (buffer (marker-buffer marker))
  7771. (pos (marker-position marker))
  7772. (type (org-get-at-bol 'type))
  7773. dbeg dend (n 0) conf)
  7774. (org-with-remote-undo buffer
  7775. (with-current-buffer buffer
  7776. (save-excursion
  7777. (goto-char pos)
  7778. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7779. (setq dbeg (progn (org-back-to-heading t) (point))
  7780. dend (org-end-of-subtree t t))
  7781. (setq dbeg (point-at-bol)
  7782. dend (min (point-max) (1+ (point-at-eol)))))
  7783. (goto-char dbeg)
  7784. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7785. (setq conf (or (eq t org-agenda-confirm-kill)
  7786. (and (numberp org-agenda-confirm-kill)
  7787. (> n org-agenda-confirm-kill))))
  7788. (and conf
  7789. (not (y-or-n-p
  7790. (format "Delete entry with %d lines in buffer \"%s\"? "
  7791. n (buffer-name buffer))))
  7792. (error "Abort"))
  7793. (let ((org-agenda-buffer-name bufname-orig))
  7794. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7795. (with-current-buffer buffer (delete-region dbeg dend))
  7796. (message "Agenda item and source killed"))))
  7797. (defvar org-archive-default-command) ; defined in org-archive.el
  7798. (defun org-agenda-archive-default ()
  7799. "Archive the entry or subtree belonging to the current agenda entry."
  7800. (interactive)
  7801. (require 'org-archive)
  7802. (org-agenda-archive-with org-archive-default-command))
  7803. (defun org-agenda-archive-default-with-confirmation ()
  7804. "Archive the entry or subtree belonging to the current agenda entry."
  7805. (interactive)
  7806. (require 'org-archive)
  7807. (org-agenda-archive-with org-archive-default-command 'confirm))
  7808. (defun org-agenda-archive ()
  7809. "Archive the entry or subtree belonging to the current agenda entry."
  7810. (interactive)
  7811. (org-agenda-archive-with 'org-archive-subtree))
  7812. (defun org-agenda-archive-to-archive-sibling ()
  7813. "Move the entry to the archive sibling."
  7814. (interactive)
  7815. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7816. (defun org-agenda-archive-with (cmd &optional confirm)
  7817. "Move the entry to the archive sibling."
  7818. (interactive)
  7819. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7820. (let* ((bufname-orig (buffer-name))
  7821. (marker (or (org-get-at-bol 'org-marker)
  7822. (org-agenda-error)))
  7823. (buffer (marker-buffer marker))
  7824. (pos (marker-position marker)))
  7825. (org-with-remote-undo buffer
  7826. (with-current-buffer buffer
  7827. (if (derived-mode-p 'org-mode)
  7828. (if (and confirm
  7829. (not (y-or-n-p "Archive this subtree or entry? ")))
  7830. (error "Abort")
  7831. (save-window-excursion
  7832. (goto-char pos)
  7833. (let ((org-agenda-buffer-name bufname-orig))
  7834. (org-remove-subtree-entries-from-agenda))
  7835. (org-back-to-heading t)
  7836. (funcall cmd)))
  7837. (error "Archiving works only in Org files"))))))
  7838. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7839. "Remove all lines in the agenda that correspond to a given subtree.
  7840. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7841. If this information is not given, the function uses the tree at point."
  7842. (let ((buf (or buf (current-buffer))) m p)
  7843. (save-excursion
  7844. (unless (and beg end)
  7845. (org-back-to-heading t)
  7846. (setq beg (point))
  7847. (org-end-of-subtree t)
  7848. (setq end (point)))
  7849. (set-buffer (get-buffer org-agenda-buffer-name))
  7850. (save-excursion
  7851. (goto-char (point-max))
  7852. (beginning-of-line 1)
  7853. (while (not (bobp))
  7854. (when (and (setq m (org-get-at-bol 'org-marker))
  7855. (equal buf (marker-buffer m))
  7856. (setq p (marker-position m))
  7857. (>= p beg)
  7858. (< p end))
  7859. (let ((inhibit-read-only t))
  7860. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7861. (beginning-of-line 0))))))
  7862. (defun org-agenda-refile (&optional goto rfloc no-update)
  7863. "Refile the item at point.
  7864. When called with `\\[universal-argument] \\[universal-argument]', \
  7865. go to the location of the last
  7866. refiled item.
  7867. When called with `\\[universal-argument] \\[universal-argument] \
  7868. \\[universal-argument]' prefix or when GOTO is 0, clear
  7869. the refile cache.
  7870. RFLOC can be a refile location obtained in a different way.
  7871. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7872. (interactive "P")
  7873. (cond
  7874. ((member goto '(0 (64)))
  7875. (org-refile-cache-clear))
  7876. ((equal goto '(16))
  7877. (org-refile-goto-last-stored))
  7878. (t
  7879. (let* ((buffer-orig (buffer-name))
  7880. (marker (or (org-get-at-bol 'org-hd-marker)
  7881. (org-agenda-error)))
  7882. (buffer (marker-buffer marker))
  7883. (pos (marker-position marker))
  7884. (rfloc (or rfloc
  7885. (org-refile-get-location
  7886. (if goto "Goto" "Refile to") buffer
  7887. org-refile-allow-creating-parent-nodes))))
  7888. (with-current-buffer buffer
  7889. (org-with-wide-buffer
  7890. (goto-char marker)
  7891. (let ((org-agenda-buffer-name buffer-orig))
  7892. (org-remove-subtree-entries-from-agenda))
  7893. (org-refile goto buffer rfloc))))
  7894. (unless no-update (org-agenda-redo)))))
  7895. (defun org-agenda-open-link (&optional arg)
  7896. "Open the link(s) in the current entry, if any.
  7897. This looks for a link in the displayed line in the agenda.
  7898. It also looks at the text of the entry itself."
  7899. (interactive "P")
  7900. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7901. (org-get-at-bol 'org-marker)))
  7902. (buffer (and marker (marker-buffer marker)))
  7903. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7904. (lkall (and buffer (org-offer-links-in-entry
  7905. buffer marker arg prefix)))
  7906. (lk0 (car lkall))
  7907. (lk (if (stringp lk0) (list lk0) lk0))
  7908. (lkend (cdr lkall))
  7909. trg)
  7910. (cond
  7911. ((and buffer lk)
  7912. (mapcar (lambda(l)
  7913. (with-current-buffer buffer
  7914. (setq trg (and (string-match org-bracket-link-regexp l)
  7915. (match-string 1 l)))
  7916. (if (or (not trg) (string-match org-any-link-re trg))
  7917. (org-with-wide-buffer
  7918. (goto-char marker)
  7919. (when (search-forward l nil lkend)
  7920. (goto-char (match-beginning 0))
  7921. (org-open-at-point)))
  7922. ;; This is an internal link, widen the buffer
  7923. (switch-to-buffer-other-window buffer)
  7924. (widen)
  7925. (goto-char marker)
  7926. (when (search-forward l nil lkend)
  7927. (goto-char (match-beginning 0))
  7928. (org-open-at-point)))))
  7929. lk))
  7930. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7931. (save-excursion
  7932. (beginning-of-line 1)
  7933. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7934. (org-open-link-from-string (match-string 1)))
  7935. (t (message "No link to open here")))))
  7936. (defun org-agenda-copy-local-variable (var)
  7937. "Get a variable from a referenced buffer and install it here."
  7938. (let ((m (org-get-at-bol 'org-marker)))
  7939. (when (and m (buffer-live-p (marker-buffer m)))
  7940. (set (make-local-variable var)
  7941. (with-current-buffer (marker-buffer m)
  7942. (symbol-value var))))))
  7943. (defun org-agenda-switch-to (&optional delete-other-windows)
  7944. "Go to the Org mode file which contains the item at point.
  7945. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  7946. displayed Org file fills the frame."
  7947. (interactive)
  7948. (if (and org-return-follows-link
  7949. (not (org-get-at-bol 'org-marker))
  7950. (org-in-regexp org-bracket-link-regexp))
  7951. (org-open-link-from-string (match-string 0))
  7952. (let* ((marker (or (org-get-at-bol 'org-marker)
  7953. (org-agenda-error)))
  7954. (buffer (marker-buffer marker))
  7955. (pos (marker-position marker)))
  7956. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  7957. (pop-to-buffer-same-window buffer)
  7958. (when delete-other-windows (delete-other-windows))
  7959. (widen)
  7960. (goto-char pos)
  7961. (when (derived-mode-p 'org-mode)
  7962. (org-show-context 'agenda)
  7963. (run-hooks 'org-agenda-after-show-hook)))))
  7964. (defun org-agenda-goto-mouse (ev)
  7965. "Go to the Org file which contains the item at the mouse click."
  7966. (interactive "e")
  7967. (mouse-set-point ev)
  7968. (org-agenda-goto))
  7969. (defun org-agenda-show (&optional full-entry)
  7970. "Display the Org file which contains the item at point.
  7971. With prefix argument FULL-ENTRY, make the entire entry visible
  7972. if it was hidden in the outline."
  7973. (interactive "P")
  7974. (let ((win (selected-window)))
  7975. (org-agenda-goto t)
  7976. (when full-entry (org-show-entry))
  7977. (select-window win)))
  7978. (defvar org-agenda-show-window nil)
  7979. (defun org-agenda-show-and-scroll-up (&optional arg)
  7980. "Display the Org file which contains the item at point.
  7981. When called repeatedly, scroll the window that is displaying the buffer.
  7982. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  7983. `outline-show-subtree'
  7984. to display the item, so that drawers and logbooks stay folded."
  7985. (interactive "P")
  7986. (let ((win (selected-window)))
  7987. (if (and (window-live-p org-agenda-show-window)
  7988. (eq this-command last-command))
  7989. (progn
  7990. (select-window org-agenda-show-window)
  7991. (ignore-errors (scroll-up)))
  7992. (org-agenda-goto t)
  7993. (if arg (org-show-entry) (outline-show-subtree))
  7994. (setq org-agenda-show-window (selected-window)))
  7995. (select-window win)))
  7996. (defun org-agenda-show-scroll-down ()
  7997. "Scroll down the window showing the agenda."
  7998. (interactive)
  7999. (let ((win (selected-window)))
  8000. (when (window-live-p org-agenda-show-window)
  8001. (select-window org-agenda-show-window)
  8002. (ignore-errors (scroll-down))
  8003. (select-window win))))
  8004. (defun org-agenda-show-1 (&optional more)
  8005. "Display the Org file which contains the item at point.
  8006. The prefix arg selects the amount of information to display:
  8007. 0 hide the subtree
  8008. 1 just show the entry according to defaults.
  8009. 2 show the children view
  8010. 3 show the subtree view
  8011. 4 show the entire subtree and any LOGBOOK drawers
  8012. 5 show the entire subtree and any drawers
  8013. With prefix argument FULL-ENTRY, make the entire entry visible
  8014. if it was hidden in the outline."
  8015. (interactive "p")
  8016. (let ((win (selected-window)))
  8017. (org-agenda-goto t)
  8018. (org-back-to-heading)
  8019. (set-window-start (selected-window) (point-at-bol))
  8020. (cond
  8021. ((= more 0)
  8022. (outline-hide-subtree)
  8023. (save-excursion
  8024. (org-back-to-heading)
  8025. (run-hook-with-args 'org-cycle-hook 'folded))
  8026. (message "Remote: FOLDED"))
  8027. ((and (called-interactively-p 'any) (= more 1))
  8028. (message "Remote: show with default settings"))
  8029. ((= more 2)
  8030. (outline-show-entry)
  8031. (org-show-children)
  8032. (save-excursion
  8033. (org-back-to-heading)
  8034. (run-hook-with-args 'org-cycle-hook 'children))
  8035. (message "Remote: CHILDREN"))
  8036. ((= more 3)
  8037. (outline-show-subtree)
  8038. (save-excursion
  8039. (org-back-to-heading)
  8040. (run-hook-with-args 'org-cycle-hook 'subtree))
  8041. (message "Remote: SUBTREE"))
  8042. ((= more 4)
  8043. (outline-show-subtree)
  8044. (save-excursion
  8045. (org-back-to-heading)
  8046. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8047. (message "Remote: SUBTREE AND LOGBOOK"))
  8048. ((> more 4)
  8049. (outline-show-subtree)
  8050. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8051. (select-window win)))
  8052. (defvar org-agenda-cycle-counter nil)
  8053. (defun org-agenda-cycle-show (&optional n)
  8054. "Show the current entry in another window, with default settings.
  8055. Default settings are taken from `org-show-context-detail'. When
  8056. use repeatedly in immediate succession, the remote entry will
  8057. cycle through visibility
  8058. children -> subtree -> folded
  8059. When called with a numeric prefix arg, that arg will be passed through to
  8060. `org-agenda-show-1'. For the interpretation of that argument, see the
  8061. docstring of `org-agenda-show-1'."
  8062. (interactive "P")
  8063. (if (integerp n)
  8064. (setq org-agenda-cycle-counter n)
  8065. (if (not (eq last-command this-command))
  8066. (setq org-agenda-cycle-counter 1)
  8067. (if (equal org-agenda-cycle-counter 0)
  8068. (setq org-agenda-cycle-counter 2)
  8069. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8070. (if (> org-agenda-cycle-counter 3)
  8071. (setq org-agenda-cycle-counter 0)))))
  8072. (org-agenda-show-1 org-agenda-cycle-counter))
  8073. (defun org-agenda-recenter (arg)
  8074. "Display the Org file which contains the item at point and recenter."
  8075. (interactive "P")
  8076. (let ((win (selected-window)))
  8077. (org-agenda-goto t)
  8078. (recenter arg)
  8079. (select-window win)))
  8080. (defun org-agenda-show-mouse (ev)
  8081. "Display the Org file which contains the item at the mouse click."
  8082. (interactive "e")
  8083. (mouse-set-point ev)
  8084. (org-agenda-show))
  8085. (defun org-agenda-check-no-diary ()
  8086. "Check if the entry is a diary link and abort if yes."
  8087. (if (org-get-at-bol 'org-agenda-diary-link)
  8088. (org-agenda-error)))
  8089. (defun org-agenda-error ()
  8090. "Throw an error when a command is not allowed in the agenda."
  8091. (user-error "Command not allowed in this line"))
  8092. (defun org-agenda-tree-to-indirect-buffer (arg)
  8093. "Show the subtree corresponding to the current entry in an indirect buffer.
  8094. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8095. With a numerical prefix ARG, go up to this level and then take that tree.
  8096. With a negative numeric ARG, go up by this number of levels.
  8097. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8098. i.e. don't use
  8099. the dedicated frame."
  8100. (interactive "P")
  8101. (if current-prefix-arg
  8102. (org-agenda-do-tree-to-indirect-buffer arg)
  8103. (let ((agenda-buffer (buffer-name))
  8104. (agenda-window (selected-window))
  8105. (indirect-window
  8106. (and org-last-indirect-buffer
  8107. (get-buffer-window org-last-indirect-buffer))))
  8108. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8109. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8110. (eq org-indirect-buffer-display 'dedicated-frame))
  8111. (unwind-protect
  8112. (unless (and indirect-window (window-live-p indirect-window))
  8113. (setq indirect-window (split-window agenda-window)))
  8114. (and indirect-window (select-window indirect-window))
  8115. (switch-to-buffer org-last-indirect-buffer :norecord)
  8116. (fit-window-to-buffer indirect-window)))
  8117. (select-window (get-buffer-window agenda-buffer))
  8118. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8119. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8120. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8121. (org-agenda-check-no-diary)
  8122. (let* ((marker (or (org-get-at-bol 'org-marker)
  8123. (org-agenda-error)))
  8124. (buffer (marker-buffer marker))
  8125. (pos (marker-position marker)))
  8126. (with-current-buffer buffer
  8127. (save-excursion
  8128. (goto-char pos)
  8129. (funcall 'org-tree-to-indirect-buffer arg)))))
  8130. (defvar org-last-heading-marker (make-marker)
  8131. "Marker pointing to the headline that last changed its TODO state
  8132. by a remote command from the agenda.")
  8133. (defun org-agenda-todo-nextset ()
  8134. "Switch TODO entry to next sequence."
  8135. (interactive)
  8136. (org-agenda-todo 'nextset))
  8137. (defun org-agenda-todo-previousset ()
  8138. "Switch TODO entry to previous sequence."
  8139. (interactive)
  8140. (org-agenda-todo 'previousset))
  8141. (defun org-agenda-todo (&optional arg)
  8142. "Cycle TODO state of line at point, also in Org file.
  8143. This changes the line at point, all other lines in the agenda referring to
  8144. the same tree node, and the headline of the tree node in the Org file."
  8145. (interactive "P")
  8146. (org-agenda-check-no-diary)
  8147. (let* ((col (current-column))
  8148. (marker (or (org-get-at-bol 'org-marker)
  8149. (org-agenda-error)))
  8150. (buffer (marker-buffer marker))
  8151. (pos (marker-position marker))
  8152. (hdmarker (org-get-at-bol 'org-hd-marker))
  8153. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8154. (inhibit-read-only t)
  8155. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8156. (org-with-remote-undo buffer
  8157. (with-current-buffer buffer
  8158. (widen)
  8159. (goto-char pos)
  8160. (org-show-context 'agenda)
  8161. (let ((current-prefix-arg arg))
  8162. (call-interactively 'org-todo))
  8163. (and (bolp) (forward-char 1))
  8164. (setq newhead (org-get-heading))
  8165. (when (and (bound-and-true-p
  8166. org-agenda-headline-snapshot-before-repeat)
  8167. (not (equal org-agenda-headline-snapshot-before-repeat
  8168. newhead))
  8169. todayp)
  8170. (setq newhead org-agenda-headline-snapshot-before-repeat
  8171. just-one t))
  8172. (save-excursion
  8173. (org-back-to-heading)
  8174. (move-marker org-last-heading-marker (point))))
  8175. (beginning-of-line 1)
  8176. (save-window-excursion
  8177. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8178. (when (bound-and-true-p org-clock-out-when-done)
  8179. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8180. newhead)
  8181. (org-agenda-unmark-clocking-task))
  8182. (org-move-to-column col)
  8183. (org-agenda-mark-clocking-task))))
  8184. (defun org-agenda-add-note (&optional arg)
  8185. "Add a time-stamped note to the entry at point."
  8186. (interactive "P")
  8187. (org-agenda-check-no-diary)
  8188. (let* ((marker (or (org-get-at-bol 'org-marker)
  8189. (org-agenda-error)))
  8190. (buffer (marker-buffer marker))
  8191. (pos (marker-position marker))
  8192. (hdmarker (org-get-at-bol 'org-hd-marker))
  8193. (inhibit-read-only t))
  8194. (with-current-buffer buffer
  8195. (widen)
  8196. (goto-char pos)
  8197. (org-show-context 'agenda)
  8198. (org-add-note))))
  8199. (defun org-agenda-change-all-lines (newhead hdmarker
  8200. &optional fixface just-this)
  8201. "Change all lines in the agenda buffer which match HDMARKER.
  8202. The new content of the line will be NEWHEAD (as modified by
  8203. `org-agenda-format-item'). HDMARKER is checked with
  8204. `equal' against all `org-hd-marker' text properties in the file.
  8205. If FIXFACE is non-nil, the face of each item is modified according to
  8206. the new TODO state.
  8207. If JUST-THIS is non-nil, change just the current line, not all.
  8208. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8209. (let* ((inhibit-read-only t)
  8210. (line (org-current-line))
  8211. (org-agenda-buffer (current-buffer))
  8212. (thetags (with-current-buffer (marker-buffer hdmarker)
  8213. (org-with-wide-buffer
  8214. (goto-char hdmarker)
  8215. (org-get-tags-at))))
  8216. props m pl undone-face done-face finish new dotime level cat tags)
  8217. (save-excursion
  8218. (goto-char (point-max))
  8219. (beginning-of-line 1)
  8220. (while (not finish)
  8221. (setq finish (bobp))
  8222. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8223. (or (not just-this) (= (org-current-line) line))
  8224. (equal m hdmarker))
  8225. (setq props (text-properties-at (point))
  8226. dotime (org-get-at-bol 'dotime)
  8227. cat (org-get-at-eol 'org-category 1)
  8228. level (org-get-at-bol 'level)
  8229. tags thetags
  8230. new
  8231. (let ((org-prefix-format-compiled
  8232. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8233. org-prefix-format-compiled))
  8234. (extra (org-get-at-bol 'extra)))
  8235. (with-current-buffer (marker-buffer hdmarker)
  8236. (org-with-wide-buffer
  8237. (org-agenda-format-item extra newhead level cat tags dotime))))
  8238. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8239. undone-face (org-get-at-bol 'undone-face)
  8240. done-face (org-get-at-bol 'done-face))
  8241. (beginning-of-line 1)
  8242. (cond
  8243. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8244. ((looking-at ".*")
  8245. ;; When replacing the whole line, preserve bulk mark
  8246. ;; overlay, if any.
  8247. (let ((mark (catch :overlay
  8248. (dolist (o (overlays-in (point) (+ 2 (point))))
  8249. (when (eq (overlay-get o 'type)
  8250. 'org-marked-entry-overlay)
  8251. (throw :overlay o))))))
  8252. (replace-match new t t)
  8253. (beginning-of-line)
  8254. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8255. (add-text-properties (point-at-bol) (point-at-eol) props)
  8256. (when fixface
  8257. (add-text-properties
  8258. (point-at-bol) (point-at-eol)
  8259. (list 'face
  8260. (if org-last-todo-state-is-todo
  8261. undone-face done-face))))
  8262. (org-agenda-highlight-todo 'line)
  8263. (beginning-of-line 1))
  8264. (t (error "Line update did not work")))
  8265. (save-restriction
  8266. (narrow-to-region (point-at-bol) (point-at-eol))
  8267. (org-agenda-finalize)))
  8268. (beginning-of-line 0)))))
  8269. (defun org-agenda-align-tags (&optional line)
  8270. "Align all tags in agenda items to `org-agenda-tags-column'."
  8271. (let ((inhibit-read-only t) l c)
  8272. (save-excursion
  8273. (goto-char (if line (point-at-bol) (point-min)))
  8274. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8275. (if line (point-at-eol) nil) t)
  8276. (add-text-properties
  8277. (match-beginning 2) (match-end 2)
  8278. (list 'face (delq nil (let ((prop (get-text-property
  8279. (match-beginning 2) 'face)))
  8280. (or (listp prop) (setq prop (list prop)))
  8281. (if (memq 'org-tag prop)
  8282. prop
  8283. (cons 'org-tag prop))))))
  8284. (setq l (- (match-end 2) (match-beginning 2))
  8285. c (if (< org-agenda-tags-column 0)
  8286. (- (abs org-agenda-tags-column) l)
  8287. org-agenda-tags-column))
  8288. (delete-region (match-beginning 1) (match-end 1))
  8289. (goto-char (match-beginning 1))
  8290. (insert (org-add-props
  8291. (make-string (max 1 (- c (current-column))) ?\ )
  8292. (plist-put (copy-sequence (text-properties-at (point)))
  8293. 'face nil))))
  8294. (goto-char (point-min))
  8295. (org-font-lock-add-tag-faces (point-max)))))
  8296. (defun org-agenda-priority-up ()
  8297. "Increase the priority of line at point, also in Org file."
  8298. (interactive)
  8299. (org-agenda-priority 'up))
  8300. (defun org-agenda-priority-down ()
  8301. "Decrease the priority of line at point, also in Org file."
  8302. (interactive)
  8303. (org-agenda-priority 'down))
  8304. (defun org-agenda-priority (&optional force-direction)
  8305. "Set the priority of line at point, also in Org file.
  8306. This changes the line at point, all other lines in the agenda referring to
  8307. the same tree node, and the headline of the tree node in the Org file.
  8308. Called with a universal prefix arg, show the priority instead of setting it."
  8309. (interactive "P")
  8310. (if (equal force-direction '(4))
  8311. (org-show-priority)
  8312. (unless org-enable-priority-commands
  8313. (error "Priority commands are disabled"))
  8314. (org-agenda-check-no-diary)
  8315. (let* ((col (current-column))
  8316. (marker (or (org-get-at-bol 'org-marker)
  8317. (org-agenda-error)))
  8318. (hdmarker (org-get-at-bol 'org-hd-marker))
  8319. (buffer (marker-buffer hdmarker))
  8320. (pos (marker-position hdmarker))
  8321. (inhibit-read-only t)
  8322. newhead)
  8323. (org-with-remote-undo buffer
  8324. (with-current-buffer buffer
  8325. (widen)
  8326. (goto-char pos)
  8327. (org-show-context 'agenda)
  8328. (funcall 'org-priority force-direction)
  8329. (end-of-line 1)
  8330. (setq newhead (org-get-heading)))
  8331. (org-agenda-change-all-lines newhead hdmarker)
  8332. (org-move-to-column col)))))
  8333. ;; FIXME: should fix the tags property of the agenda line.
  8334. (defun org-agenda-set-tags (&optional tag onoff)
  8335. "Set tags for the current headline."
  8336. (interactive)
  8337. (org-agenda-check-no-diary)
  8338. (if (and (org-region-active-p) (called-interactively-p 'any))
  8339. (call-interactively 'org-change-tag-in-region)
  8340. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8341. (org-agenda-error)))
  8342. (buffer (marker-buffer hdmarker))
  8343. (pos (marker-position hdmarker))
  8344. (inhibit-read-only t)
  8345. newhead)
  8346. (org-with-remote-undo buffer
  8347. (with-current-buffer buffer
  8348. (widen)
  8349. (goto-char pos)
  8350. (org-show-context 'agenda)
  8351. (if tag
  8352. (org-toggle-tag tag onoff)
  8353. (call-interactively 'org-set-tags))
  8354. (end-of-line 1)
  8355. (setq newhead (org-get-heading)))
  8356. (org-agenda-change-all-lines newhead hdmarker)
  8357. (beginning-of-line 1)))))
  8358. (defun org-agenda-set-property ()
  8359. "Set a property for the current headline."
  8360. (interactive)
  8361. (org-agenda-check-no-diary)
  8362. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8363. (org-agenda-error)))
  8364. (buffer (marker-buffer hdmarker))
  8365. (pos (marker-position hdmarker))
  8366. (inhibit-read-only t)
  8367. newhead)
  8368. (org-with-remote-undo buffer
  8369. (with-current-buffer buffer
  8370. (widen)
  8371. (goto-char pos)
  8372. (org-show-context 'agenda)
  8373. (call-interactively 'org-set-property)))))
  8374. (defun org-agenda-set-effort ()
  8375. "Set the effort property for the current headline."
  8376. (interactive)
  8377. (org-agenda-check-no-diary)
  8378. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8379. (org-agenda-error)))
  8380. (buffer (marker-buffer hdmarker))
  8381. (pos (marker-position hdmarker))
  8382. (inhibit-read-only t)
  8383. newhead)
  8384. (org-with-remote-undo buffer
  8385. (with-current-buffer buffer
  8386. (widen)
  8387. (goto-char pos)
  8388. (org-show-context 'agenda)
  8389. (call-interactively 'org-set-effort)
  8390. (end-of-line 1)
  8391. (setq newhead (org-get-heading)))
  8392. (org-agenda-change-all-lines newhead hdmarker))))
  8393. (defun org-agenda-toggle-archive-tag ()
  8394. "Toggle the archive tag for the current entry."
  8395. (interactive)
  8396. (org-agenda-check-no-diary)
  8397. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8398. (org-agenda-error)))
  8399. (buffer (marker-buffer hdmarker))
  8400. (pos (marker-position hdmarker))
  8401. (inhibit-read-only t)
  8402. newhead)
  8403. (org-with-remote-undo buffer
  8404. (with-current-buffer buffer
  8405. (widen)
  8406. (goto-char pos)
  8407. (org-show-context 'agenda)
  8408. (call-interactively 'org-toggle-archive-tag)
  8409. (end-of-line 1)
  8410. (setq newhead (org-get-heading)))
  8411. (org-agenda-change-all-lines newhead hdmarker)
  8412. (beginning-of-line 1))))
  8413. (defun org-agenda-do-date-later (arg)
  8414. (interactive "P")
  8415. (cond
  8416. ((or (equal arg '(16))
  8417. (memq last-command
  8418. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8419. (setq this-command 'org-agenda-date-later-minutes)
  8420. (org-agenda-date-later-minutes 1))
  8421. ((or (equal arg '(4))
  8422. (memq last-command
  8423. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8424. (setq this-command 'org-agenda-date-later-hours)
  8425. (org-agenda-date-later-hours 1))
  8426. (t
  8427. (org-agenda-date-later (prefix-numeric-value arg)))))
  8428. (defun org-agenda-do-date-earlier (arg)
  8429. (interactive "P")
  8430. (cond
  8431. ((or (equal arg '(16))
  8432. (memq last-command
  8433. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8434. (setq this-command 'org-agenda-date-earlier-minutes)
  8435. (org-agenda-date-earlier-minutes 1))
  8436. ((or (equal arg '(4))
  8437. (memq last-command
  8438. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8439. (setq this-command 'org-agenda-date-earlier-hours)
  8440. (org-agenda-date-earlier-hours 1))
  8441. (t
  8442. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8443. (defun org-agenda-date-later (arg &optional what)
  8444. "Change the date of this item to ARG day(s) later."
  8445. (interactive "p")
  8446. (org-agenda-check-type t 'agenda 'timeline)
  8447. (org-agenda-check-no-diary)
  8448. (let* ((marker (or (org-get-at-bol 'org-marker)
  8449. (org-agenda-error)))
  8450. (buffer (marker-buffer marker))
  8451. (pos (marker-position marker))
  8452. cdate today)
  8453. (org-with-remote-undo buffer
  8454. (with-current-buffer buffer
  8455. (widen)
  8456. (goto-char pos)
  8457. (if (not (org-at-timestamp-p))
  8458. (error "Cannot find time stamp"))
  8459. (when (and org-agenda-move-date-from-past-immediately-to-today
  8460. (equal arg 1)
  8461. (or (not what) (eq what 'day))
  8462. (not (save-match-data (org-at-date-range-p))))
  8463. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8464. cdate (calendar-absolute-from-gregorian
  8465. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8466. today (org-today))
  8467. (if (> today cdate)
  8468. ;; immediately shift to today
  8469. (setq arg (- today cdate))))
  8470. (org-timestamp-change arg (or what 'day))
  8471. (when (and (org-at-date-range-p)
  8472. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8473. (let ((end org-last-changed-timestamp))
  8474. (org-timestamp-change arg (or what 'day))
  8475. (setq org-last-changed-timestamp
  8476. (concat org-last-changed-timestamp "--" end)))))
  8477. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8478. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8479. (defun org-agenda-date-earlier (arg &optional what)
  8480. "Change the date of this item to ARG day(s) earlier."
  8481. (interactive "p")
  8482. (org-agenda-date-later (- arg) what))
  8483. (defun org-agenda-date-later-minutes (arg)
  8484. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8485. (interactive "p")
  8486. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8487. (org-agenda-date-later arg 'minute))
  8488. (defun org-agenda-date-earlier-minutes (arg)
  8489. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8490. (interactive "p")
  8491. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8492. (org-agenda-date-earlier arg 'minute))
  8493. (defun org-agenda-date-later-hours (arg)
  8494. "Change the time of this item, in hour steps."
  8495. (interactive "p")
  8496. (org-agenda-date-later arg 'hour))
  8497. (defun org-agenda-date-earlier-hours (arg)
  8498. "Change the time of this item, in hour steps."
  8499. (interactive "p")
  8500. (org-agenda-date-earlier arg 'hour))
  8501. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8502. "Show new date stamp via text properties."
  8503. ;; We use text properties to make this undoable
  8504. (let ((inhibit-read-only t))
  8505. (setq stamp (concat prefix " => " stamp " "))
  8506. (save-excursion
  8507. (goto-char (point-max))
  8508. (while (not (bobp))
  8509. (when (equal marker (org-get-at-bol 'org-marker))
  8510. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8511. (org-move-to-column (- (window-width) (length stamp)) t)
  8512. (add-text-properties
  8513. (1- (point)) (point-at-eol)
  8514. (list 'display (org-add-props stamp nil
  8515. 'face '(secondary-selection default))))
  8516. (beginning-of-line 1))
  8517. (beginning-of-line 0)))))
  8518. (defun org-agenda-date-prompt (arg)
  8519. "Change the date of this item. Date is prompted for, with default today.
  8520. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8521. be used to request time specification in the time stamp."
  8522. (interactive "P")
  8523. (org-agenda-check-type t 'agenda 'timeline)
  8524. (org-agenda-check-no-diary)
  8525. (let* ((marker (or (org-get-at-bol 'org-marker)
  8526. (org-agenda-error)))
  8527. (buffer (marker-buffer marker))
  8528. (pos (marker-position marker)))
  8529. (org-with-remote-undo buffer
  8530. (with-current-buffer buffer
  8531. (widen)
  8532. (goto-char pos)
  8533. (if (not (org-at-timestamp-p t))
  8534. (error "Cannot find time stamp"))
  8535. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8536. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8537. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8538. (defun org-agenda-schedule (arg &optional time)
  8539. "Schedule the item at point.
  8540. ARG is passed through to `org-schedule'."
  8541. (interactive "P")
  8542. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8543. (org-agenda-check-no-diary)
  8544. (let* ((marker (or (org-get-at-bol 'org-marker)
  8545. (org-agenda-error)))
  8546. (type (marker-insertion-type marker))
  8547. (buffer (marker-buffer marker))
  8548. (pos (marker-position marker))
  8549. ts)
  8550. (set-marker-insertion-type marker t)
  8551. (org-with-remote-undo buffer
  8552. (with-current-buffer buffer
  8553. (widen)
  8554. (goto-char pos)
  8555. (setq ts (org-schedule arg time)))
  8556. (org-agenda-show-new-time marker ts " S"))
  8557. (message "%s" ts)))
  8558. (defun org-agenda-deadline (arg &optional time)
  8559. "Schedule the item at point.
  8560. ARG is passed through to `org-deadline'."
  8561. (interactive "P")
  8562. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8563. (org-agenda-check-no-diary)
  8564. (let* ((marker (or (org-get-at-bol 'org-marker)
  8565. (org-agenda-error)))
  8566. (buffer (marker-buffer marker))
  8567. (pos (marker-position marker))
  8568. ts)
  8569. (org-with-remote-undo buffer
  8570. (with-current-buffer buffer
  8571. (widen)
  8572. (goto-char pos)
  8573. (setq ts (org-deadline arg time)))
  8574. (org-agenda-show-new-time marker ts " D"))
  8575. (message "%s" ts)))
  8576. (defun org-agenda-clock-in (&optional arg)
  8577. "Start the clock on the currently selected item."
  8578. (interactive "P")
  8579. (org-agenda-check-no-diary)
  8580. (if (equal arg '(4))
  8581. (org-clock-in arg)
  8582. (let* ((marker (or (org-get-at-bol 'org-marker)
  8583. (org-agenda-error)))
  8584. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8585. (pos (marker-position marker))
  8586. (col (current-column))
  8587. newhead)
  8588. (org-with-remote-undo (marker-buffer marker)
  8589. (with-current-buffer (marker-buffer marker)
  8590. (widen)
  8591. (goto-char pos)
  8592. (org-show-context 'agenda)
  8593. (org-cycle-hide-drawers 'children)
  8594. (org-clock-in arg)
  8595. (setq newhead (org-get-heading)))
  8596. (org-agenda-change-all-lines newhead hdmarker))
  8597. (org-move-to-column col))))
  8598. (defun org-agenda-clock-out ()
  8599. "Stop the currently running clock."
  8600. (interactive)
  8601. (unless (marker-buffer org-clock-marker)
  8602. (error "No running clock"))
  8603. (let ((marker (make-marker)) (col (current-column)) newhead)
  8604. (org-with-remote-undo (marker-buffer org-clock-marker)
  8605. (with-current-buffer (marker-buffer org-clock-marker)
  8606. (org-with-wide-buffer
  8607. (goto-char org-clock-marker)
  8608. (org-back-to-heading t)
  8609. (move-marker marker (point))
  8610. (org-clock-out)
  8611. (setq newhead (org-get-heading)))))
  8612. (org-agenda-change-all-lines newhead marker)
  8613. (move-marker marker nil)
  8614. (org-move-to-column col)
  8615. (org-agenda-unmark-clocking-task)))
  8616. (defun org-agenda-clock-cancel (&optional arg)
  8617. "Cancel the currently running clock."
  8618. (interactive "P")
  8619. (unless (marker-buffer org-clock-marker)
  8620. (user-error "No running clock"))
  8621. (org-with-remote-undo (marker-buffer org-clock-marker)
  8622. (org-clock-cancel)))
  8623. (defun org-agenda-clock-goto ()
  8624. "Jump to the currently clocked in task within the agenda.
  8625. If the currently clocked in task is not listed in the agenda
  8626. buffer, display it in another window."
  8627. (interactive)
  8628. (let (pos)
  8629. (mapc (lambda (o)
  8630. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8631. (setq pos (overlay-start o))))
  8632. (overlays-in (point-min) (point-max)))
  8633. (cond (pos (goto-char pos))
  8634. ;; If the currently clocked entry is not in the agenda
  8635. ;; buffer, we visit it in another window:
  8636. ((bound-and-true-p org-clock-current-task)
  8637. (org-switch-to-buffer-other-window (org-clock-goto)))
  8638. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8639. (defun org-agenda-diary-entry-in-org-file ()
  8640. "Make a diary entry in the file `org-agenda-diary-file'."
  8641. (let (d1 d2 char (text "") dp1 dp2)
  8642. (if (equal (buffer-name) "*Calendar*")
  8643. (setq d1 (calendar-cursor-to-date t)
  8644. d2 (car calendar-mark-ring))
  8645. (setq dp1 (get-text-property (point-at-bol) 'day))
  8646. (unless dp1 (user-error "No date defined in current line"))
  8647. (setq d1 (calendar-gregorian-from-absolute dp1)
  8648. d2 (and (ignore-errors (mark))
  8649. (save-excursion
  8650. (goto-char (mark))
  8651. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8652. (calendar-gregorian-from-absolute dp2))))
  8653. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8654. (setq char (read-char-exclusive))
  8655. (cond
  8656. ((equal char ?d)
  8657. (setq text (read-string "Day entry: "))
  8658. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8659. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8660. ((equal char ?a)
  8661. (setq d1 (list (car d1) (nth 1 d1)
  8662. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8663. (nth 2 d1))))
  8664. (setq text (read-string "Anniversary (use %d to show years): "))
  8665. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8666. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8667. ((equal char ?b)
  8668. (setq text (read-string "Block entry: "))
  8669. (unless (and d1 d2 (not (equal d1 d2)))
  8670. (user-error "No block of days selected"))
  8671. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8672. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8673. ((equal char ?j)
  8674. (org-switch-to-buffer-other-window
  8675. (find-file-noselect org-agenda-diary-file))
  8676. (require 'org-datetree)
  8677. (org-datetree-find-date-create d1)
  8678. (org-reveal t))
  8679. (t (user-error "Invalid selection character `%c'" char)))))
  8680. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8681. "Where in `org-agenda-diary-file' should new entries be added?
  8682. Valid values:
  8683. date-tree in the date tree, as first child of the date
  8684. date-tree-last in the date tree, as last child of the date
  8685. top-level as top-level entries at the end of the file."
  8686. :group 'org-agenda
  8687. :type '(choice
  8688. (const :tag "first in a date tree" date-tree)
  8689. (const :tag "last in a date tree" date-tree-last)
  8690. (const :tag "as top level at end of file" top-level)))
  8691. (defcustom org-agenda-insert-diary-extract-time nil
  8692. "Non-nil means extract any time specification from the diary entry."
  8693. :group 'org-agenda
  8694. :version "24.1"
  8695. :type 'boolean)
  8696. (defcustom org-agenda-bulk-mark-char ">"
  8697. "A single-character string to be used as the bulk mark."
  8698. :group 'org-agenda
  8699. :version "24.1"
  8700. :type 'string)
  8701. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8702. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8703. If TEXT is not empty, it will become the headline of the new entry, and
  8704. the resulting entry will not be shown. When TEXT is empty, switch to
  8705. `org-agenda-diary-file' and let the user finish the entry there."
  8706. (let ((cw (current-window-configuration)))
  8707. (org-switch-to-buffer-other-window
  8708. (find-file-noselect org-agenda-diary-file))
  8709. (widen)
  8710. (goto-char (point-min))
  8711. (cond
  8712. ((eq type 'anniversary)
  8713. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8714. (progn
  8715. (or (org-at-heading-p t)
  8716. (progn
  8717. (outline-next-heading)
  8718. (insert "* Anniversaries\n\n")
  8719. (beginning-of-line -1)))))
  8720. (outline-next-heading)
  8721. (org-back-over-empty-lines)
  8722. (backward-char 1)
  8723. (insert "\n")
  8724. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8725. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8726. ((eq type 'day)
  8727. (let ((org-prefix-has-time t)
  8728. (org-agenda-time-leading-zero t)
  8729. fmt time time2)
  8730. (if org-agenda-insert-diary-extract-time
  8731. ;; Use org-agenda-format-item to parse text for a time-range and
  8732. ;; remove it. FIXME: This is a hack, we should refactor
  8733. ;; that function to make time extraction available separately
  8734. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8735. time (get-text-property 0 'time fmt)
  8736. time2 (if (> (length time) 0)
  8737. ;; split-string removes trailing ...... if
  8738. ;; no end time given. First space
  8739. ;; separates time from date.
  8740. (concat " " (car (split-string time "\\.")))
  8741. nil)
  8742. text (get-text-property 0 'txt fmt)))
  8743. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8744. (org-agenda-insert-diary-as-top-level text)
  8745. (require 'org-datetree)
  8746. (org-datetree-find-date-create d1)
  8747. (org-agenda-insert-diary-make-new-entry text))
  8748. (org-insert-time-stamp (org-time-from-absolute
  8749. (calendar-absolute-from-gregorian d1))
  8750. nil nil nil nil time2))
  8751. (end-of-line 0))
  8752. ((eq type 'block)
  8753. (if (> (calendar-absolute-from-gregorian d1)
  8754. (calendar-absolute-from-gregorian d2))
  8755. (setq d1 (prog1 d2 (setq d2 d1))))
  8756. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8757. (org-agenda-insert-diary-as-top-level text)
  8758. (require 'org-datetree)
  8759. (org-datetree-find-date-create d1)
  8760. (org-agenda-insert-diary-make-new-entry text))
  8761. (org-insert-time-stamp (org-time-from-absolute
  8762. (calendar-absolute-from-gregorian d1)))
  8763. (insert "--")
  8764. (org-insert-time-stamp (org-time-from-absolute
  8765. (calendar-absolute-from-gregorian d2)))
  8766. (end-of-line 0)))
  8767. (if (string-match "\\S-" text)
  8768. (progn
  8769. (set-window-configuration cw)
  8770. (message "%s entry added to %s"
  8771. (capitalize (symbol-name type))
  8772. (abbreviate-file-name org-agenda-diary-file)))
  8773. (org-reveal t)
  8774. (message "Please finish entry here"))))
  8775. (defun org-agenda-insert-diary-as-top-level (text)
  8776. "Make new entry as a top-level entry at the end of the file.
  8777. Add TEXT as headline, and position the cursor in the second line so that
  8778. a timestamp can be added there."
  8779. (widen)
  8780. (goto-char (point-max))
  8781. (unless (bolp) (insert "\n"))
  8782. (org-insert-heading nil t t)
  8783. (insert text)
  8784. (org-end-of-meta-data)
  8785. (unless (bolp) (insert "\n"))
  8786. (when org-adapt-indentation (indent-to-column 2)))
  8787. (defun org-agenda-insert-diary-make-new-entry (text)
  8788. "Make a new entry with TEXT as a child of the current subtree.
  8789. Position the point in the heading's first body line so that
  8790. a timestamp can be added there."
  8791. (cond
  8792. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8793. (end-of-line)
  8794. (org-insert-heading '(4) t)
  8795. (org-do-demote))
  8796. (t
  8797. (outline-next-heading)
  8798. (org-back-over-empty-lines)
  8799. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8800. (org-insert-heading nil t)
  8801. (org-do-demote)))
  8802. (let ((col (current-column)))
  8803. (insert text)
  8804. (org-end-of-meta-data)
  8805. ;; Ensure point is left on a blank line, at proper indentation.
  8806. (unless (bolp) (insert "\n"))
  8807. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8808. (when org-adapt-indentation (indent-to-column col)))
  8809. (org-show-set-visibility 'lineage))
  8810. (defun org-agenda-diary-entry ()
  8811. "Make a diary entry, like the `i' command from the calendar.
  8812. All the standard commands work: block, weekly etc.
  8813. When `org-agenda-diary-file' points to a file,
  8814. `org-agenda-diary-entry-in-org-file' is called instead to create
  8815. entries in that Org file."
  8816. (interactive)
  8817. (if (not (eq org-agenda-diary-file 'diary-file))
  8818. (org-agenda-diary-entry-in-org-file)
  8819. (require 'diary-lib)
  8820. (let* ((char (progn
  8821. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8822. (read-char-exclusive)))
  8823. (cmd (cdr (assoc char
  8824. '((?d . diary-insert-entry)
  8825. (?w . diary-insert-weekly-entry)
  8826. (?m . diary-insert-monthly-entry)
  8827. (?y . diary-insert-yearly-entry)
  8828. (?a . diary-insert-anniversary-entry)
  8829. (?b . diary-insert-block-entry)
  8830. (?c . diary-insert-cyclic-entry)))))
  8831. (oldf (symbol-function 'calendar-cursor-to-date))
  8832. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8833. (point (point))
  8834. (mark (or (mark t) (point))))
  8835. (unless cmd
  8836. (user-error "No command associated with <%c>" char))
  8837. (unless (and (get-text-property point 'day)
  8838. (or (not (equal ?b char))
  8839. (get-text-property mark 'day)))
  8840. (user-error "Don't know which date to use for diary entry"))
  8841. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8842. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8843. (let ((calendar-mark-ring
  8844. (list (calendar-gregorian-from-absolute
  8845. (or (get-text-property mark 'day)
  8846. (get-text-property point 'day))))))
  8847. (unwind-protect
  8848. (progn
  8849. (fset 'calendar-cursor-to-date
  8850. (lambda (&optional error dummy)
  8851. (calendar-gregorian-from-absolute
  8852. (get-text-property point 'day))))
  8853. (call-interactively cmd))
  8854. (fset 'calendar-cursor-to-date oldf))))))
  8855. (defun org-agenda-execute-calendar-command (cmd)
  8856. "Execute a calendar command from the agenda with date from cursor."
  8857. (org-agenda-check-type t 'agenda 'timeline)
  8858. (require 'diary-lib)
  8859. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8860. (user-error "Don't know which date to use for the calendar command"))
  8861. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8862. (point (point))
  8863. (date (calendar-gregorian-from-absolute
  8864. (get-text-property point 'day)))
  8865. ;; the following 2 vars are needed in the calendar
  8866. (displayed-month (car date))
  8867. (displayed-year (nth 2 date)))
  8868. (unwind-protect
  8869. (progn
  8870. (fset 'calendar-cursor-to-date
  8871. (lambda (&optional error dummy)
  8872. (calendar-gregorian-from-absolute
  8873. (get-text-property point 'day))))
  8874. (call-interactively cmd))
  8875. (fset 'calendar-cursor-to-date oldf))))
  8876. (defun org-agenda-phases-of-moon ()
  8877. "Display the phases of the moon for the 3 months around the cursor date."
  8878. (interactive)
  8879. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  8880. (defun org-agenda-holidays ()
  8881. "Display the holidays for the 3 months around the cursor date."
  8882. (interactive)
  8883. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  8884. (defvar calendar-longitude) ; defined in calendar.el
  8885. (defvar calendar-latitude) ; defined in calendar.el
  8886. (defvar calendar-location-name) ; defined in calendar.el
  8887. (defun org-agenda-sunrise-sunset (arg)
  8888. "Display sunrise and sunset for the cursor date.
  8889. Latitude and longitude can be specified with the variables
  8890. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8891. argument, latitude and longitude will be prompted for."
  8892. (interactive "P")
  8893. (require 'solar)
  8894. (let ((calendar-longitude (if arg nil calendar-longitude))
  8895. (calendar-latitude (if arg nil calendar-latitude))
  8896. (calendar-location-name
  8897. (if arg "the given coordinates" calendar-location-name)))
  8898. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8899. (defun org-agenda-goto-calendar ()
  8900. "Open the Emacs calendar with the date at the cursor."
  8901. (interactive)
  8902. (org-agenda-check-type t 'agenda 'timeline)
  8903. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8904. (user-error "Don't know which date to open in calendar")))
  8905. (date (calendar-gregorian-from-absolute day))
  8906. (calendar-move-hook nil)
  8907. (calendar-view-holidays-initially-flag nil)
  8908. (calendar-view-diary-initially-flag nil))
  8909. (calendar)
  8910. (calendar-goto-date date)))
  8911. ;;;###autoload
  8912. (defun org-calendar-goto-agenda ()
  8913. "Compute the Org agenda for the calendar date displayed at the cursor.
  8914. This is a command that has to be installed in `calendar-mode-map'."
  8915. (interactive)
  8916. ;; Temporarily disable sticky agenda since user clearly wants to
  8917. ;; refresh view anyway.
  8918. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  8919. (org-agenda-sticky nil))
  8920. (org-agenda-list nil (calendar-absolute-from-gregorian
  8921. (calendar-cursor-to-date))
  8922. nil)))
  8923. (defun org-agenda-convert-date ()
  8924. (interactive)
  8925. (org-agenda-check-type t 'agenda 'timeline)
  8926. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8927. date s)
  8928. (unless day
  8929. (user-error "Don't know which date to convert"))
  8930. (setq date (calendar-gregorian-from-absolute day))
  8931. (setq s (concat
  8932. "Gregorian: " (calendar-date-string date) "\n"
  8933. "ISO: " (calendar-iso-date-string date) "\n"
  8934. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8935. "Julian: " (calendar-julian-date-string date) "\n"
  8936. "Astron. JD: " (calendar-astro-date-string date)
  8937. " (Julian date number at noon UTC)\n"
  8938. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8939. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8940. "French: " (calendar-french-date-string date) "\n"
  8941. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  8942. "Mayan: " (calendar-mayan-date-string date) "\n"
  8943. "Coptic: " (calendar-coptic-date-string date) "\n"
  8944. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8945. "Persian: " (calendar-persian-date-string date) "\n"
  8946. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8947. (with-output-to-temp-buffer "*Dates*"
  8948. (princ s))
  8949. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8950. ;;; Bulk commands
  8951. (defun org-agenda-bulk-marked-p ()
  8952. "Non-nil when current entry is marked for bulk action."
  8953. (eq (get-char-property (point-at-bol) 'type)
  8954. 'org-marked-entry-overlay))
  8955. (defun org-agenda-bulk-mark (&optional arg)
  8956. "Mark the entry at point for future bulk action."
  8957. (interactive "p")
  8958. (dotimes (i (or arg 1))
  8959. (unless (org-get-at-bol 'org-agenda-diary-link)
  8960. (let* ((m (org-get-at-bol 'org-hd-marker))
  8961. ov)
  8962. (unless (org-agenda-bulk-marked-p)
  8963. (unless m (user-error "Nothing to mark at point"))
  8964. (push m org-agenda-bulk-marked-entries)
  8965. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8966. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8967. (org-get-todo-face "TODO")
  8968. 'evaporate)
  8969. (overlay-put ov 'type 'org-marked-entry-overlay))
  8970. (end-of-line 1)
  8971. (or (ignore-errors
  8972. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  8973. (beginning-of-line 2))
  8974. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8975. (beginning-of-line 2))
  8976. (message "%d entries marked for bulk action"
  8977. (length org-agenda-bulk-marked-entries))))))
  8978. (defun org-agenda-bulk-mark-all ()
  8979. "Mark all entries for future agenda bulk action."
  8980. (interactive)
  8981. (org-agenda-bulk-mark-regexp "."))
  8982. (defun org-agenda-bulk-mark-regexp (regexp)
  8983. "Mark entries matching REGEXP for future agenda bulk action."
  8984. (interactive "sMark entries matching regexp: ")
  8985. (let ((entries-marked 0) txt-at-point)
  8986. (save-excursion
  8987. (goto-char (point-min))
  8988. (goto-char (next-single-property-change (point) 'org-hd-marker))
  8989. (while (and (re-search-forward regexp nil t)
  8990. (setq txt-at-point (get-text-property (point) 'txt)))
  8991. (if (get-char-property (point) 'invisible)
  8992. (beginning-of-line 2)
  8993. (when (string-match regexp txt-at-point)
  8994. (setq entries-marked (1+ entries-marked))
  8995. (call-interactively 'org-agenda-bulk-mark)))))
  8996. (if (not entries-marked)
  8997. (message "No entry matching this regexp."))))
  8998. (defun org-agenda-bulk-unmark (&optional arg)
  8999. "Unmark the entry at point for future bulk action."
  9000. (interactive "P")
  9001. (if arg
  9002. (org-agenda-bulk-unmark-all)
  9003. (cond ((org-agenda-bulk-marked-p)
  9004. (org-agenda-bulk-remove-overlays
  9005. (point-at-bol) (+ 2 (point-at-bol)))
  9006. (setq org-agenda-bulk-marked-entries
  9007. (delete (org-get-at-bol 'org-hd-marker)
  9008. org-agenda-bulk-marked-entries))
  9009. (end-of-line 1)
  9010. (or (ignore-errors
  9011. (goto-char (next-single-property-change (point) 'txt)))
  9012. (beginning-of-line 2))
  9013. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9014. (beginning-of-line 2))
  9015. (message "%d entries left marked for bulk action"
  9016. (length org-agenda-bulk-marked-entries)))
  9017. (t (message "No entry to unmark here")))))
  9018. (defun org-agenda-bulk-toggle-all ()
  9019. "Toggle all marks for bulk action."
  9020. (interactive)
  9021. (save-excursion
  9022. (goto-char (point-min))
  9023. (while (ignore-errors
  9024. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9025. (org-agenda-bulk-toggle))))
  9026. (defun org-agenda-bulk-toggle ()
  9027. "Toggle the mark at point for bulk action."
  9028. (interactive)
  9029. (if (org-agenda-bulk-marked-p)
  9030. (org-agenda-bulk-unmark)
  9031. (org-agenda-bulk-mark)))
  9032. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9033. "Remove the mark overlays between BEG and END in the agenda buffer.
  9034. BEG and END default to the buffer limits.
  9035. This only removes the overlays, it does not remove the markers
  9036. from the list in `org-agenda-bulk-marked-entries'."
  9037. (interactive)
  9038. (mapc (lambda (ov)
  9039. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9040. (delete-overlay ov)))
  9041. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9042. (defun org-agenda-bulk-unmark-all ()
  9043. "Remove all marks in the agenda buffer.
  9044. This will remove the markers and the overlays."
  9045. (interactive)
  9046. (if (null org-agenda-bulk-marked-entries)
  9047. (message "No entry to unmark")
  9048. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9049. (setq org-agenda-bulk-marked-entries nil)
  9050. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9051. (defcustom org-agenda-persistent-marks nil
  9052. "Non-nil means marked items will stay marked after a bulk action.
  9053. You can toggle this interactively by typing `p' when prompted for a
  9054. bulk action."
  9055. :group 'org-agenda
  9056. :version "24.1"
  9057. :type 'boolean)
  9058. (defun org-agenda-bulk-action (&optional arg)
  9059. "Execute an remote-editing action on all marked entries.
  9060. The prefix arg is passed through to the command if possible."
  9061. (interactive "P")
  9062. ;; Make sure we have markers, and only valid ones
  9063. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9064. (mapc
  9065. (lambda (m)
  9066. (unless (and (markerp m)
  9067. (marker-buffer m)
  9068. (buffer-live-p (marker-buffer m))
  9069. (marker-position m))
  9070. (user-error "Marker %s for bulk command is invalid" m)))
  9071. org-agenda-bulk-marked-entries)
  9072. ;; Prompt for the bulk command
  9073. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9074. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9075. "[S]catter [f]unction "
  9076. (when org-agenda-bulk-custom-functions
  9077. (concat " Custom: ["
  9078. (mapconcat (lambda(f) (char-to-string (car f)))
  9079. org-agenda-bulk-custom-functions "")
  9080. "]"))))
  9081. (catch 'exit
  9082. (let* ((action (read-char-exclusive))
  9083. (org-log-refile (if org-log-refile 'time nil))
  9084. (entries (reverse org-agenda-bulk-marked-entries))
  9085. (org-overriding-default-time
  9086. (if (get-text-property (point) 'org-agenda-date-header)
  9087. (org-get-cursor-date)))
  9088. redo-at-end
  9089. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9090. (cond
  9091. ((equal action ?p)
  9092. (let ((org-agenda-persistent-marks
  9093. (not org-agenda-persistent-marks)))
  9094. (org-agenda-bulk-action)
  9095. (throw 'exit nil)))
  9096. ((equal action ?$)
  9097. (setq cmd '(org-agenda-archive)))
  9098. ((equal action ?A)
  9099. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9100. ((member action '(?r ?w))
  9101. (setq rfloc (org-refile-get-location
  9102. "Refile to"
  9103. (marker-buffer (car entries))
  9104. org-refile-allow-creating-parent-nodes))
  9105. (if (nth 3 rfloc)
  9106. (setcar (nthcdr 3 rfloc)
  9107. (move-marker (make-marker) (nth 3 rfloc)
  9108. (or (get-file-buffer (nth 1 rfloc))
  9109. (find-buffer-visiting (nth 1 rfloc))
  9110. (error "This should not happen")))))
  9111. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9112. redo-at-end t))
  9113. ((equal action ?t)
  9114. (setq state (completing-read
  9115. "Todo state: "
  9116. (with-current-buffer (marker-buffer (car entries))
  9117. (mapcar #'list org-todo-keywords-1))))
  9118. (setq cmd `(let ((org-inhibit-blocking t)
  9119. (org-inhibit-logging 'note))
  9120. (org-agenda-todo ,state))))
  9121. ((memq action '(?- ?+))
  9122. (setq tag (completing-read
  9123. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9124. (with-current-buffer (marker-buffer (car entries))
  9125. (delq nil
  9126. (mapcar (lambda (x) (and (stringp (car x)) x))
  9127. org-current-tag-alist)))))
  9128. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9129. ((memq action '(?s ?d))
  9130. (let* ((time
  9131. (unless arg
  9132. (org-read-date
  9133. nil nil nil
  9134. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9135. org-overriding-default-time)))
  9136. (c1 (if (eq action ?s) 'org-agenda-schedule
  9137. 'org-agenda-deadline)))
  9138. ;; Make sure to not prompt for a note when bulk
  9139. ;; rescheduling as Org cannot cope with simultaneous Org.
  9140. ;; Besides, it could be annoying depending on the number
  9141. ;; of items re-scheduled.
  9142. (setq cmd `(eval '(let ((org-log-reschedule
  9143. (and org-log-reschedule 'time)))
  9144. (,c1 arg ,time))))))
  9145. ((equal action ?S)
  9146. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9147. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9148. (let ((days (read-number
  9149. (format "Scatter tasks across how many %sdays: "
  9150. (if arg "week" "")) 7)))
  9151. (setq cmd
  9152. `(let ((distance (1+ (random ,days))))
  9153. (if arg
  9154. (let ((dist distance)
  9155. (day-of-week
  9156. (calendar-day-of-week
  9157. (calendar-gregorian-from-absolute (org-today)))))
  9158. (dotimes (i (1+ dist))
  9159. (while (member day-of-week org-agenda-weekend-days)
  9160. (cl-incf distance)
  9161. (cl-incf day-of-week)
  9162. (when (= day-of-week 7)
  9163. (setq day-of-week 0)))
  9164. (cl-incf day-of-week)
  9165. (when (= day-of-week 7)
  9166. (setq day-of-week 0)))))
  9167. ;; silently fail when try to replan a sexp entry
  9168. (condition-case nil
  9169. (let* ((date (calendar-gregorian-from-absolute
  9170. (+ (org-today) distance)))
  9171. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9172. (nth 2 date))))
  9173. (org-agenda-schedule nil time))
  9174. (error nil)))))))
  9175. ((assoc action org-agenda-bulk-custom-functions)
  9176. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9177. redo-at-end t))
  9178. ((equal action ?f)
  9179. (setq cmd (list (intern
  9180. (completing-read "Function: "
  9181. obarray 'fboundp t nil nil)))))
  9182. (t (user-error "Invalid bulk action")))
  9183. ;; Sort the markers, to make sure that parents are handled before children
  9184. (setq entries (sort entries
  9185. (lambda (a b)
  9186. (cond
  9187. ((equal (marker-buffer a) (marker-buffer b))
  9188. (< (marker-position a) (marker-position b)))
  9189. (t
  9190. (string< (buffer-name (marker-buffer a))
  9191. (buffer-name (marker-buffer b))))))))
  9192. ;; Now loop over all markers and apply cmd
  9193. (while (setq e (pop entries))
  9194. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9195. (if (not pos)
  9196. (progn (message "Skipping removed entry at %s" e)
  9197. (setq cntskip (1+ cntskip)))
  9198. (goto-char pos)
  9199. (let (org-loop-over-headlines-in-active-region)
  9200. (eval cmd))
  9201. ;; `post-command-hook' is not run yet. We make sure any
  9202. ;; pending log note is processed.
  9203. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9204. (memq 'org-add-log-note post-command-hook))
  9205. (org-add-log-note))
  9206. (setq cnt (1+ cnt))))
  9207. (when redo-at-end (org-agenda-redo))
  9208. (unless org-agenda-persistent-marks
  9209. (org-agenda-bulk-unmark-all))
  9210. (message "Acted on %d entries%s%s"
  9211. cnt
  9212. (if (= cntskip 0)
  9213. ""
  9214. (format ", skipped %d (disappeared before their turn)"
  9215. cntskip))
  9216. (if (not org-agenda-persistent-marks)
  9217. "" " (kept marked)"))))))
  9218. (defun org-agenda-capture (&optional with-time)
  9219. "Call `org-capture' with the date at point.
  9220. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9221. current HH:MM time."
  9222. (interactive "P")
  9223. (if (not (eq major-mode 'org-agenda-mode))
  9224. (user-error "You cannot do this outside of agenda buffers")
  9225. (let ((org-overriding-default-time
  9226. (org-get-cursor-date (equal with-time 1))))
  9227. (call-interactively 'org-capture))))
  9228. ;;; Dragging agenda lines forward/backward
  9229. (defun org-agenda-reapply-filters ()
  9230. "Re-apply all agenda filters."
  9231. (mapcar
  9232. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9233. `((,org-agenda-tag-filter tag)
  9234. (,org-agenda-category-filter category)
  9235. (,org-agenda-regexp-filter regexp)
  9236. (,org-agenda-effort-filter effort)
  9237. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9238. (,(get 'org-agenda-category-filter :preset-filter) category)
  9239. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9240. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9241. (defun org-agenda-drag-line-forward (arg &optional backward)
  9242. "Drag an agenda line forward by ARG lines.
  9243. When the optional argument `backward' is non-nil, move backward."
  9244. (interactive "p")
  9245. (let ((inhibit-read-only t) lst line)
  9246. (if (or (not (get-text-property (point) 'txt))
  9247. (save-excursion
  9248. (dotimes (n arg)
  9249. (move-beginning-of-line (if backward 0 2))
  9250. (push (not (get-text-property (point) 'txt)) lst))
  9251. (delq nil lst)))
  9252. (message "Cannot move line forward")
  9253. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9254. (move-beginning-of-line 1)
  9255. (setq line (buffer-substring (point) end))
  9256. (delete-region (point) end)
  9257. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9258. (insert line)
  9259. (org-agenda-reapply-filters)
  9260. (org-agenda-mark-clocking-task)
  9261. (move-beginning-of-line 0)))))
  9262. (defun org-agenda-drag-line-backward (arg)
  9263. "Drag an agenda line backward by ARG lines."
  9264. (interactive "p")
  9265. (org-agenda-drag-line-forward arg t))
  9266. ;;; Flagging notes
  9267. (defun org-agenda-show-the-flagging-note ()
  9268. "Display the flagging note in the other window.
  9269. When called a second time in direct sequence, offer to remove the FLAGGING
  9270. tag and (if present) the flagging note."
  9271. (interactive)
  9272. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9273. (win (selected-window))
  9274. note heading newhead)
  9275. (unless hdmarker
  9276. (user-error "No linked entry at point"))
  9277. (if (and (eq this-command last-command)
  9278. (y-or-n-p "Unflag and remove any flagging note? "))
  9279. (progn
  9280. (org-agenda-remove-flag hdmarker)
  9281. (let ((win (get-buffer-window "*Flagging Note*")))
  9282. (and win (delete-window win)))
  9283. (message "Entry unflagged"))
  9284. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9285. (unless note
  9286. (user-error "No flagging note"))
  9287. (org-kill-new note)
  9288. (org-switch-to-buffer-other-window "*Flagging Note*")
  9289. (erase-buffer)
  9290. (insert note)
  9291. (goto-char (point-min))
  9292. (while (re-search-forward "\\\\n" nil t)
  9293. (replace-match "\n" t t))
  9294. (goto-char (point-min))
  9295. (select-window win)
  9296. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9297. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9298. tag and note")))))
  9299. (defun org-agenda-remove-flag (marker)
  9300. "Remove the FLAGGED tag and any flagging note in the entry."
  9301. (let (newhead)
  9302. (org-with-point-at marker
  9303. (org-toggle-tag "FLAGGED" 'off)
  9304. (org-entry-delete nil "THEFLAGGINGNOTE")
  9305. (setq newhead (org-get-heading)))
  9306. (org-agenda-change-all-lines newhead marker)
  9307. (message "Entry unflagged")))
  9308. (defun org-agenda-get-any-marker (&optional pos)
  9309. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9310. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9311. ;;; Appointment reminders
  9312. (defvar appt-time-msg-list) ; defined in appt.el
  9313. ;;;###autoload
  9314. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9315. "Activate appointments found in `org-agenda-files'.
  9316. With a `\\[universal-argument]' prefix, refresh the list of \
  9317. appointments.
  9318. If FILTER is t, interactively prompt the user for a regular
  9319. expression, and filter out entries that don't match it.
  9320. If FILTER is a string, use this string as a regular expression
  9321. for filtering entries out.
  9322. If FILTER is a function, filter out entries against which
  9323. calling the function returns nil. This function takes one
  9324. argument: an entry from `org-agenda-get-day-entries'.
  9325. FILTER can also be an alist with the car of each cell being
  9326. either `headline' or `category'. For example:
  9327. \\='((headline \"IMPORTANT\")
  9328. (category \"Work\"))
  9329. will only add headlines containing IMPORTANT or headlines
  9330. belonging to the \"Work\" category.
  9331. ARGS are symbols indicating what kind of entries to consider.
  9332. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9333. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9334. and :timestamp entries. See the docstring of `org-diary' for
  9335. details and examples.
  9336. If an entry has a APPT_WARNTIME property, its value will be used
  9337. to override `appt-message-warning-time'."
  9338. (interactive "P")
  9339. (if refresh (setq appt-time-msg-list nil))
  9340. (if (eq filter t)
  9341. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9342. (let* ((cnt 0) ; count added events
  9343. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9344. (org-agenda-new-buffers nil)
  9345. (org-deadline-warning-days 0)
  9346. ;; Do not use `org-today' here because appt only takes
  9347. ;; time and without date as argument, so it may pass wrong
  9348. ;; information otherwise
  9349. (today (org-date-to-gregorian
  9350. (time-to-days (current-time))))
  9351. (org-agenda-restrict nil)
  9352. (files (org-agenda-files 'unrestricted)) entries file
  9353. (org-agenda-buffer nil))
  9354. ;; Get all entries which may contain an appt
  9355. (org-agenda-prepare-buffers files)
  9356. (while (setq file (pop files))
  9357. (setq entries
  9358. (delq nil
  9359. (append entries
  9360. (apply 'org-agenda-get-day-entries
  9361. file today scope)))))
  9362. ;; Map thru entries and find if we should filter them out
  9363. (mapc
  9364. (lambda (x)
  9365. (let* ((evt (org-trim
  9366. (replace-regexp-in-string
  9367. org-bracket-link-regexp "\\3"
  9368. (or (get-text-property 1 'txt x) ""))))
  9369. (cat (get-text-property (1- (length x)) 'org-category x))
  9370. (tod (get-text-property 1 'time-of-day x))
  9371. (ok (or (null filter)
  9372. (and (stringp filter) (string-match filter evt))
  9373. (and (functionp filter) (funcall filter x))
  9374. (and (listp filter)
  9375. (let ((cat-filter (cadr (assq 'category filter)))
  9376. (evt-filter (cadr (assq 'headline filter))))
  9377. (or (and (stringp cat-filter)
  9378. (string-match cat-filter cat))
  9379. (and (stringp evt-filter)
  9380. (string-match evt-filter evt)))))))
  9381. (wrn (get-text-property 1 'warntime x)))
  9382. ;; FIXME: Shall we remove text-properties for the appt text?
  9383. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9384. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9385. (setq tod (concat "00" (number-to-string tod)))
  9386. (setq tod (when (string-match
  9387. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9388. (concat (match-string 1 tod) ":"
  9389. (match-string 2 tod))))
  9390. (when (if (version< emacs-version "23.3")
  9391. (appt-add tod evt)
  9392. (appt-add tod evt wrn))
  9393. (setq cnt (1+ cnt))))))
  9394. entries)
  9395. (org-release-buffers org-agenda-new-buffers)
  9396. (if (eq cnt 0)
  9397. (message "No event to add")
  9398. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9399. (defun org-agenda-today-p (date)
  9400. "Non nil when DATE means today.
  9401. DATE is either a list of the form (month day year) or a number of
  9402. days as returned by `calendar-absolute-from-gregorian' or
  9403. `org-today'. This function considers `org-extend-today-until'
  9404. when defining today."
  9405. (eq (org-today)
  9406. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9407. (defun org-agenda-todo-yesterday (&optional arg)
  9408. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9409. (interactive "P")
  9410. (let* ((org-use-effective-time t)
  9411. (hour (nth 2 (decode-time (org-current-time))))
  9412. (org-extend-today-until (1+ hour)))
  9413. (org-agenda-todo arg)))
  9414. (provide 'org-agenda)
  9415. ;;; org-agenda.el ends here