org-agenda.el 392 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 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-mode.
  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 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-columns-remove-overlays "org-colview" ())
  64. (declare-function org-datetree-find-date-create "org-datetree"
  65. (date &optional keep-restriction))
  66. (declare-function org-columns-quit "org-colview" ())
  67. (declare-function diary-date-display-form "diary-lib" (&optional type))
  68. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  69. (declare-function org-habit-insert-consistency-graphs
  70. "org-habit" (&optional line))
  71. (declare-function org-is-habit-p "org-habit" (&optional pom))
  72. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  73. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  74. (declare-function org-pop-to-buffer-same-window "org-compat"
  75. (&optional buffer-or-name norecord label))
  76. (declare-function org-agenda-columns "org-colview" ())
  77. (declare-function org-add-archive-files "org-archive" (files))
  78. (declare-function org-capture "org-capture" (&optional goto keys))
  79. (defvar calendar-mode-map) ; defined in calendar.el
  80. (defvar org-clock-current-task nil) ; defined in org-clock.el
  81. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  82. (defvar org-habit-show-habits) ; defined in org-habit.el
  83. (defvar org-habit-show-habits-only-for-today)
  84. (defvar org-habit-show-all-today)
  85. ;; Defined somewhere in this file, but used before definition.
  86. (defvar org-agenda-buffer-name "*Org Agenda*")
  87. (defvar org-agenda-overriding-header nil)
  88. (defvar org-agenda-title-append nil)
  89. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  90. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  91. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  92. (defvar org-agenda-undo-list nil
  93. "List of undoable operations in the agenda since last refresh.")
  94. (defvar org-agenda-pending-undo-list nil
  95. "In a series of undo commands, this is the list of remaining undo items.")
  96. (defcustom org-agenda-confirm-kill 1
  97. "When set, remote killing from the agenda buffer needs confirmation.
  98. When t, a confirmation is always needed. When a number N, confirmation is
  99. only needed when the text to be killed contains more than N non-white lines."
  100. :group 'org-agenda
  101. :type '(choice
  102. (const :tag "Never" nil)
  103. (const :tag "Always" t)
  104. (integer :tag "When more than N lines")))
  105. (defcustom org-agenda-compact-blocks nil
  106. "Non-nil means make the block agenda more compact.
  107. This is done globally by leaving out lines like the agenda span
  108. name and week number or the separator lines."
  109. :group 'org-agenda
  110. :type 'boolean)
  111. (defcustom org-agenda-block-separator ?=
  112. "The separator between blocks in the agenda.
  113. If this is a string, it will be used as the separator, with a newline added.
  114. If it is a character, it will be repeated to fill the window width.
  115. If nil the separator is disabled. In `org-agenda-custom-commands' this
  116. addresses the separator between the current and the previous block."
  117. :group 'org-agenda
  118. :type '(choice
  119. (const :tag "Disabled" nil)
  120. (character)
  121. (string)))
  122. (defgroup org-agenda-export nil
  123. "Options concerning exporting agenda views in Org-mode."
  124. :tag "Org Agenda Export"
  125. :group 'org-agenda)
  126. (defcustom org-agenda-with-colors t
  127. "Non-nil means use colors in agenda views."
  128. :group 'org-agenda-export
  129. :type 'boolean)
  130. (defcustom org-agenda-exporter-settings nil
  131. "Alist of variable/value pairs that should be active during agenda export.
  132. This is a good place to set options for ps-print and for htmlize.
  133. Note that the way this is implemented, the values will be evaluated
  134. before assigned to the variables. So make sure to quote values you do
  135. *not* want evaluated, for example
  136. (setq org-agenda-exporter-settings
  137. '((ps-print-color-p 'black-white)))"
  138. :group 'org-agenda-export
  139. :type '(repeat
  140. (list
  141. (variable)
  142. (sexp :tag "Value"))))
  143. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  144. "Hook run in a temporary buffer before writing the agenda to an export file.
  145. A useful function for this hook is `org-agenda-add-entry-text'."
  146. :group 'org-agenda-export
  147. :type 'hook
  148. :options '(org-agenda-add-entry-text))
  149. (defcustom org-agenda-add-entry-text-maxlines 0
  150. "Maximum number of entry text lines to be added to agenda.
  151. This is only relevant when `org-agenda-add-entry-text' is part of
  152. `org-agenda-before-write-hook', which is the default.
  153. When this is 0, nothing will happen. When it is greater than 0, it
  154. specifies the maximum number of lines that will be added for each entry
  155. that is listed in the agenda view.
  156. Note that this variable is not used during display, only when exporting
  157. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  158. and `org-agenda-entry-text-maxlines'."
  159. :group 'org-agenda
  160. :type 'integer)
  161. (defcustom org-agenda-add-entry-text-descriptive-links t
  162. "Non-nil means export org-links as descriptive links in agenda added text.
  163. This variable applies to the text added to the agenda when
  164. `org-agenda-add-entry-text-maxlines' is larger than 0.
  165. When this variable nil, the URL will (also) be shown."
  166. :group 'org-agenda
  167. :type 'boolean)
  168. (defcustom org-agenda-export-html-style nil
  169. "The style specification for exported HTML Agenda files.
  170. If this variable contains a string, it will replace the default <style>
  171. section as produced by `htmlize'.
  172. Since there are different ways of setting style information, this variable
  173. needs to contain the full HTML structure to provide a style, including the
  174. surrounding HTML tags. The style specifications should include definitions
  175. the fonts used by the agenda, here is an example:
  176. <style type=\"text/css\">
  177. p { font-weight: normal; color: gray; }
  178. .org-agenda-structure {
  179. font-size: 110%;
  180. color: #003399;
  181. font-weight: 600;
  182. }
  183. .org-todo {
  184. color: #cc6666;
  185. font-weight: bold;
  186. }
  187. .org-agenda-done {
  188. color: #339933;
  189. }
  190. .org-done {
  191. color: #339933;
  192. }
  193. .title { text-align: center; }
  194. .todo, .deadline { color: red; }
  195. .done { color: green; }
  196. </style>
  197. or, if you want to keep the style in a file,
  198. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  199. As the value of this option simply gets inserted into the HTML <head> header,
  200. you can \"misuse\" it to also add other text to the header."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type '(choice
  204. (const nil)
  205. (string)))
  206. (defcustom org-agenda-persistent-filter nil
  207. "When set, keep filters from one agenda view to the next."
  208. :group 'org-agenda
  209. :type 'boolean)
  210. (defgroup org-agenda-custom-commands nil
  211. "Options concerning agenda views in Org-mode."
  212. :tag "Org Agenda Custom Commands"
  213. :group 'org-agenda)
  214. (defconst org-sorting-choice
  215. '(choice
  216. (const time-up) (const time-down)
  217. (const timestamp-up) (const timestamp-down)
  218. (const scheduled-up) (const scheduled-down)
  219. (const deadline-up) (const deadline-down)
  220. (const ts-up) (const ts-down)
  221. (const tsia-up) (const tsia-down)
  222. (const category-keep) (const category-up) (const category-down)
  223. (const tag-down) (const tag-up)
  224. (const priority-up) (const priority-down)
  225. (const todo-state-up) (const todo-state-down)
  226. (const effort-up) (const effort-down)
  227. (const habit-up) (const habit-down)
  228. (const alpha-up) (const alpha-down)
  229. (const user-defined-up) (const user-defined-down))
  230. "Sorting choices.")
  231. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  232. ;; the new variable `org-agenda-tag-filter-preset'.
  233. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  234. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  235. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  236. "List of types searched for when creating the daily/weekly agenda.
  237. This variable is a list of symbols that controls the types of
  238. items that appear in the daily/weekly agenda. Allowed symbols in this
  239. list are are
  240. :timestamp List items containing a date stamp or date range matching
  241. the selected date. This includes sexp entries in angular
  242. brackets.
  243. :sexp List entries resulting from plain diary-like sexps.
  244. :deadline List deadline due on that date. When the date is today,
  245. also list any deadlines past due, or due within
  246. `org-deadline-warning-days'. `:deadline' must appear before
  247. `:scheduled' if the setting of
  248. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  249. any effect.
  250. :deadline* Same as above, but only include the deadline if it has an
  251. hour specification as [h]h:mm.
  252. :scheduled List all items which are scheduled for the given date.
  253. The diary for *today* also contains items which were
  254. scheduled earlier and are not yet marked DONE.
  255. :scheduled* Same as above, but only include the scheduled item if it
  256. has an hour specification as [h]h:mm.
  257. By default, all four non-starred types are turned on.
  258. When :scheduled* or :deadline* are included, :schedule or :deadline
  259. will be ignored.
  260. Never set this variable globally using `setq', because then it
  261. will apply to all future agenda commands. Instead, bind it with
  262. `let' to scope it dynamically into the agenda-constructing
  263. command. A good way to set it is through options in
  264. `org-agenda-custom-commands'. For a more flexible (though
  265. somewhat less efficient) way of determining what is included in
  266. the daily/weekly agenda, see `org-agenda-skip-function'.")
  267. (defconst org-agenda-custom-commands-local-options
  268. `(repeat :tag "Local settings for this command. Remember to quote values"
  269. (choice :tag "Setting"
  270. (list :tag "Heading for this block"
  271. (const org-agenda-overriding-header)
  272. (string :tag "Headline"))
  273. (list :tag "Files to be searched"
  274. (const org-agenda-files)
  275. (list
  276. (const :format "" quote)
  277. (repeat (file))))
  278. (list :tag "Sorting strategy"
  279. (const org-agenda-sorting-strategy)
  280. (list
  281. (const :format "" quote)
  282. (repeat
  283. ,org-sorting-choice)))
  284. (list :tag "Prefix format"
  285. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  286. (string))
  287. (list :tag "Number of days in agenda"
  288. (const org-agenda-span)
  289. (choice (const :tag "Day" day)
  290. (const :tag "Week" week)
  291. (const :tag "Fortnight" fortnight)
  292. (const :tag "Month" month)
  293. (const :tag "Year" year)
  294. (integer :tag "Custom")))
  295. (list :tag "Fixed starting date"
  296. (const org-agenda-start-day)
  297. (string :value "2007-11-01"))
  298. (list :tag "Start on day of week"
  299. (const org-agenda-start-on-weekday)
  300. (choice :value 1
  301. (const :tag "Today" nil)
  302. (integer :tag "Weekday No.")))
  303. (list :tag "Include data from diary"
  304. (const org-agenda-include-diary)
  305. (boolean))
  306. (list :tag "Deadline Warning days"
  307. (const org-deadline-warning-days)
  308. (integer :value 1))
  309. (list :tag "Category filter preset"
  310. (const org-agenda-category-filter-preset)
  311. (list
  312. (const :format "" quote)
  313. (repeat
  314. (string :tag "+category or -category"))))
  315. (list :tag "Tags filter preset"
  316. (const org-agenda-tag-filter-preset)
  317. (list
  318. (const :format "" quote)
  319. (repeat
  320. (string :tag "+tag or -tag"))))
  321. (list :tag "Regexp filter preset"
  322. (const org-agenda-regexp-filter-preset)
  323. (list
  324. (const :format "" quote)
  325. (repeat
  326. (string :tag "+regexp or -regexp"))))
  327. (list :tag "Set daily/weekly entry types"
  328. (const org-agenda-entry-types)
  329. (list
  330. (const :format "" quote)
  331. (set :greedy t :value ,org-agenda-entry-types
  332. (const :deadline)
  333. (const :scheduled)
  334. (const :deadline*)
  335. (const :scheduled*)
  336. (const :timestamp)
  337. (const :sexp))))
  338. (list :tag "Standard skipping condition"
  339. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  340. (const org-agenda-skip-function)
  341. (list
  342. (const :format "" quote)
  343. (list
  344. (choice
  345. :tag "Skipping range"
  346. (const :tag "Skip entry" org-agenda-skip-entry-if)
  347. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  348. (repeat :inline t :tag "Conditions for skipping"
  349. (choice
  350. :tag "Condition type"
  351. (list :tag "Regexp matches" :inline t (const :format "" regexp) (regexp))
  352. (list :tag "Regexp does not match" :inline t (const :format "" notregexp) (regexp))
  353. (list :tag "TODO state is" :inline t
  354. (const todo)
  355. (choice
  356. (const :tag "any not-done state" todo)
  357. (const :tag "any done state" done)
  358. (const :tag "any state" any)
  359. (list :tag "Keyword list"
  360. (const :format "" quote)
  361. (repeat (string :tag "Keyword")))))
  362. (list :tag "TODO state is not" :inline t
  363. (const nottodo)
  364. (choice
  365. (const :tag "any not-done state" todo)
  366. (const :tag "any done state" done)
  367. (const :tag "any state" any)
  368. (list :tag "Keyword list"
  369. (const :format "" quote)
  370. (repeat (string :tag "Keyword")))))
  371. (const :tag "scheduled" scheduled)
  372. (const :tag "not scheduled" notscheduled)
  373. (const :tag "deadline" deadline)
  374. (const :tag "no deadline" notdeadline)
  375. (const :tag "timestamp" timestamp)
  376. (const :tag "no timestamp" nottimestamp))))))
  377. (list :tag "Non-standard skipping condition"
  378. :value (org-agenda-skip-function)
  379. (const org-agenda-skip-function)
  380. (sexp :tag "Function or form (quoted!)"))
  381. (list :tag "Any variable"
  382. (variable :tag "Variable")
  383. (sexp :tag "Value (sexp)"))))
  384. "Selection of examples for agenda command settings.
  385. This will be spliced into the custom type of
  386. `org-agenda-custom-commands'.")
  387. (defcustom org-agenda-custom-commands
  388. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  389. "Custom commands for the agenda.
  390. These commands will be offered on the splash screen displayed by the
  391. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  392. (key desc type match settings files)
  393. key The key (one or more characters as a string) to be associated
  394. with the command.
  395. desc A description of the command, when omitted or nil, a default
  396. description is built using MATCH.
  397. type The command type, any of the following symbols:
  398. agenda The daily/weekly agenda.
  399. todo Entries with a specific TODO keyword, in all agenda files.
  400. search Entries containing search words entry or headline.
  401. tags Tags/Property/TODO match in all agenda files.
  402. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  403. todo-tree Sparse tree of specific TODO keyword in *current* file.
  404. tags-tree Sparse tree with all tags matches in *current* file.
  405. occur-tree Occur sparse tree for *current* file.
  406. ... A user-defined function.
  407. match What to search for:
  408. - a single keyword for TODO keyword searches
  409. - a tags match expression for tags searches
  410. - a word search expression for text searches.
  411. - a regular expression for occur searches
  412. For all other commands, this should be the empty string.
  413. settings A list of option settings, similar to that in a let form, so like
  414. this: ((opt1 val1) (opt2 val2) ...). The values will be
  415. evaluated at the moment of execution, so quote them when needed.
  416. files A list of files file to write the produced agenda buffer to
  417. with the command `org-store-agenda-views'.
  418. If a file name ends in \".html\", an HTML version of the buffer
  419. is written out. If it ends in \".ps\", a postscript version is
  420. produced. Otherwise, only the plain text is written to the file.
  421. You can also define a set of commands, to create a composite agenda buffer.
  422. In this case, an entry looks like this:
  423. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  424. where
  425. desc A description string to be displayed in the dispatcher menu.
  426. cmd An agenda command, similar to the above. However, tree commands
  427. are not allowed, but instead you can get agenda and global todo list.
  428. So valid commands for a set are:
  429. (agenda \"\" settings)
  430. (alltodo \"\" settings)
  431. (stuck \"\" settings)
  432. (todo \"match\" settings files)
  433. (search \"match\" settings files)
  434. (tags \"match\" settings files)
  435. (tags-todo \"match\" settings files)
  436. Each command can carry a list of options, and another set of options can be
  437. given for the whole set of commands. Individual command options take
  438. precedence over the general options.
  439. When using several characters as key to a command, the first characters
  440. are prefix commands. For the dispatcher to display useful information, you
  441. should provide a description for the prefix, like
  442. (setq org-agenda-custom-commands
  443. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  444. (\"hl\" tags \"+HOME+Lisa\")
  445. (\"hp\" tags \"+HOME+Peter\")
  446. (\"hk\" tags \"+HOME+Kim\")))"
  447. :group 'org-agenda-custom-commands
  448. :type `(repeat
  449. (choice :value ("x" "Describe command here" tags "" nil)
  450. (list :tag "Single command"
  451. (string :tag "Access Key(s) ")
  452. (option (string :tag "Description"))
  453. (choice
  454. (const :tag "Agenda" agenda)
  455. (const :tag "TODO list" alltodo)
  456. (const :tag "Search words" search)
  457. (const :tag "Stuck projects" stuck)
  458. (const :tag "Tags/Property match (all agenda files)" tags)
  459. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  460. (const :tag "TODO keyword search (all agenda files)" todo)
  461. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  462. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  463. (const :tag "Occur tree (current buffer)" occur-tree)
  464. (sexp :tag "Other, user-defined function"))
  465. (string :tag "Match (only for some commands)")
  466. ,org-agenda-custom-commands-local-options
  467. (option (repeat :tag "Export" (file :tag "Export to"))))
  468. (list :tag "Command series, all agenda files"
  469. (string :tag "Access Key(s)")
  470. (string :tag "Description ")
  471. (repeat :tag "Component"
  472. (choice
  473. (list :tag "Agenda"
  474. (const :format "" agenda)
  475. (const :tag "" :format "" "")
  476. ,org-agenda-custom-commands-local-options)
  477. (list :tag "TODO list (all keywords)"
  478. (const :format "" alltodo)
  479. (const :tag "" :format "" "")
  480. ,org-agenda-custom-commands-local-options)
  481. (list :tag "Search words"
  482. (const :format "" search)
  483. (string :tag "Match")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "Stuck projects"
  486. (const :format "" stuck)
  487. (const :tag "" :format "" "")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Tags search"
  490. (const :format "" tags)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "Tags search, TODO entries only"
  494. (const :format "" tags-todo)
  495. (string :tag "Match")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "TODO keyword search"
  498. (const :format "" todo)
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)
  501. (list :tag "Other, user-defined function"
  502. (symbol :tag "function")
  503. (string :tag "Match")
  504. ,org-agenda-custom-commands-local-options)))
  505. (repeat :tag "Settings for entire command set"
  506. (list (variable :tag "Any variable")
  507. (sexp :tag "Value")))
  508. (option (repeat :tag "Export" (file :tag "Export to"))))
  509. (cons :tag "Prefix key documentation"
  510. (string :tag "Access Key(s)")
  511. (string :tag "Description ")))))
  512. (defcustom org-agenda-query-register ?o
  513. "The register holding the current query string.
  514. The purpose of this is that if you construct a query string interactively,
  515. you can then use it to define a custom command."
  516. :group 'org-agenda-custom-commands
  517. :type 'character)
  518. (defcustom org-stuck-projects
  519. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  520. "How to identify stuck projects.
  521. This is a list of four items:
  522. 1. A tags/todo/property matcher string that is used to identify a project.
  523. See the manual for a description of tag and property searches.
  524. The entire tree below a headline matched by this is considered one project.
  525. 2. A list of TODO keywords identifying non-stuck projects.
  526. If the project subtree contains any headline with one of these todo
  527. keywords, the project is considered to be not stuck. If you specify
  528. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  529. 3. A list of tags identifying non-stuck projects.
  530. If the project subtree contains any headline with one of these tags,
  531. the project is considered to be not stuck. If you specify \"*\" as
  532. a tag, any tag will mark the project unstuck. Note that this is about
  533. the explicit presence of a tag somewhere in the subtree, inherited
  534. tags do not count here. If inherited tags make a project not stuck,
  535. use \"-TAG\" in the tags part of the matcher under (1.) above.
  536. 4. An arbitrary regular expression matching non-stuck projects.
  537. If the project turns out to be not stuck, search continues also in the
  538. subtree to see if any of the subtasks have project status.
  539. See also the variable `org-tags-match-list-sublevels' which applies
  540. to projects matched by this search as well.
  541. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  542. or `C-c a #' to produce the list."
  543. :group 'org-agenda-custom-commands
  544. :type '(list
  545. (string :tag "Tags/TODO match to identify a project")
  546. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  547. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  548. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  549. (defcustom org-agenda-filter-effort-default-operator "<"
  550. "The default operator for effort estimate filtering.
  551. If you select an effort estimate limit without first pressing an operator,
  552. this one will be used."
  553. :group 'org-agenda-custom-commands
  554. :type '(choice (const :tag "less or equal" "<")
  555. (const :tag "greater or equal"">")
  556. (const :tag "equal" "=")))
  557. (defgroup org-agenda-skip nil
  558. "Options concerning skipping parts of agenda files."
  559. :tag "Org Agenda Skip"
  560. :group 'org-agenda)
  561. (defcustom org-agenda-skip-function-global nil
  562. "Function to be called at each match during agenda construction.
  563. If this function returns nil, the current match should not be skipped.
  564. If the function decided to skip an agenda match, is must return the
  565. buffer position from which the search should be continued.
  566. This may also be a Lisp form, which will be evaluated.
  567. This variable will be applied to every agenda match, including
  568. tags/property searches and TODO lists. So try to make the test function
  569. do its checking as efficiently as possible. To implement a skipping
  570. condition just for specific agenda commands, use the variable
  571. `org-agenda-skip-function' which can be set in the options section
  572. of custom agenda commands."
  573. :group 'org-agenda-skip
  574. :type 'sexp)
  575. (defgroup org-agenda-daily/weekly nil
  576. "Options concerning the daily/weekly agenda."
  577. :tag "Org Agenda Daily/Weekly"
  578. :group 'org-agenda)
  579. (defgroup org-agenda-todo-list nil
  580. "Options concerning the global todo list agenda view."
  581. :tag "Org Agenda Todo List"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-match-view nil
  584. "Options concerning the general tags/property/todo match agenda view."
  585. :tag "Org Agenda Match View"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-search-view nil
  588. "Options concerning the search agenda view."
  589. :tag "Org Agenda Search View"
  590. :group 'org-agenda)
  591. (defvar org-agenda-archives-mode nil
  592. "Non-nil means the agenda will include archived items.
  593. If this is the symbol `trees', trees in the selected agenda scope
  594. that are marked with the ARCHIVE tag will be included anyway. When this is
  595. t, also all archive files associated with the current selection of agenda
  596. files will be included.")
  597. (defcustom org-agenda-restriction-lock-highlight-subtree t
  598. "Non-nil means highlight the whole subtree when restriction is active.
  599. Otherwise only highlight the headline. Highlighting the whole subtree is
  600. useful to ensure no edits happen beyond the restricted region."
  601. :group 'org-agenda
  602. :type 'boolean)
  603. (defcustom org-agenda-skip-comment-trees t
  604. "Non-nil means skip trees that start with the COMMENT keyword.
  605. When nil, these trees are also scanned by agenda commands."
  606. :group 'org-agenda-skip
  607. :type 'boolean)
  608. (defcustom org-agenda-todo-list-sublevels t
  609. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  610. When nil, the sublevels of a TODO entry are not checked, resulting in
  611. potentially much shorter TODO lists."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type 'boolean)
  615. (defcustom org-agenda-todo-ignore-with-date nil
  616. "Non-nil means don't show entries with a date in the global todo list.
  617. You can use this if you prefer to mark mere appointments with a TODO keyword,
  618. but don't want them to show up in the TODO list.
  619. When this is set, it also covers deadlines and scheduled items, the settings
  620. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  621. will be ignored.
  622. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  623. :group 'org-agenda-skip
  624. :group 'org-agenda-todo-list
  625. :type 'boolean)
  626. (defcustom org-agenda-todo-ignore-timestamp nil
  627. "Non-nil means don't show entries with a timestamp.
  628. This applies when creating the global todo list.
  629. Valid values are:
  630. past Don't show entries for today or in the past.
  631. future Don't show entries with a timestamp in the future.
  632. The idea behind this is that if it has a future
  633. timestamp, you don't want to think about it until the
  634. date.
  635. all Don't show any entries with a timestamp in the global todo list.
  636. The idea behind this is that by setting a timestamp, you
  637. have already \"taken care\" of this item.
  638. This variable can also have an integer as a value. If positive (N),
  639. todos with a timestamp N or more days in the future will be ignored. If
  640. negative (-N), todos with a timestamp N or more days in the past will be
  641. ignored. If 0, todos with a timestamp either today or in the future will
  642. be ignored. For example, a value of -1 will exclude todos with a
  643. timestamp in the past (yesterday or earlier), while a value of 7 will
  644. exclude todos with a timestamp a week or more in the future.
  645. See also `org-agenda-todo-ignore-with-date'.
  646. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  647. to make his option also apply to the tags-todo list."
  648. :group 'org-agenda-skip
  649. :group 'org-agenda-todo-list
  650. :version "24.1"
  651. :type '(choice
  652. (const :tag "Ignore future timestamp todos" future)
  653. (const :tag "Ignore past or present timestamp todos" past)
  654. (const :tag "Ignore all timestamp todos" all)
  655. (const :tag "Show timestamp todos" nil)
  656. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  657. (defcustom org-agenda-todo-ignore-scheduled nil
  658. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  659. This applies when creating the global todo list.
  660. Valid values are:
  661. past Don't show entries scheduled today or in the past.
  662. future Don't show entries scheduled in the future.
  663. The idea behind this is that by scheduling it, you don't want to
  664. think about it until the scheduled date.
  665. all Don't show any scheduled entries in the global todo list.
  666. The idea behind this is that by scheduling it, you have already
  667. \"taken care\" of this item.
  668. t Same as `all', for backward compatibility.
  669. This variable can also have an integer as a value. See
  670. `org-agenda-todo-ignore-timestamp' for more details.
  671. See also `org-agenda-todo-ignore-with-date'.
  672. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  673. to make his option also apply to the tags-todo list."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-todo-list
  676. :type '(choice
  677. (const :tag "Ignore future-scheduled todos" future)
  678. (const :tag "Ignore past- or present-scheduled todos" past)
  679. (const :tag "Ignore all scheduled todos" all)
  680. (const :tag "Ignore all scheduled todos (compatibility)" t)
  681. (const :tag "Show scheduled todos" nil)
  682. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  683. (defcustom org-agenda-todo-ignore-deadlines nil
  684. "Non-nil means ignore some deadline TODO items when making TODO list.
  685. There are different motivations for using different values, please think
  686. carefully when configuring this variable.
  687. This applies when creating the global todo list.
  688. Valid values are:
  689. near Don't show near deadline entries. A deadline is near when it is
  690. closer than `org-deadline-warning-days' days. The idea behind this
  691. is that such items will appear in the agenda anyway.
  692. far Don't show TODO entries where a deadline has been defined, but
  693. the deadline is not near. This is useful if you don't want to
  694. use the todo list to figure out what to do now.
  695. past Don't show entries with a deadline timestamp for today or in the past.
  696. future Don't show entries with a deadline timestamp in the future, not even
  697. when they become `near' ones. Use it with caution.
  698. all Ignore all TODO entries that do have a deadline.
  699. t Same as `near', for backward compatibility.
  700. This variable can also have an integer as a value. See
  701. `org-agenda-todo-ignore-timestamp' for more details.
  702. See also `org-agenda-todo-ignore-with-date'.
  703. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  704. to make his option also apply to the tags-todo list."
  705. :group 'org-agenda-skip
  706. :group 'org-agenda-todo-list
  707. :type '(choice
  708. (const :tag "Ignore near deadlines" near)
  709. (const :tag "Ignore near deadlines (compatibility)" t)
  710. (const :tag "Ignore far deadlines" far)
  711. (const :tag "Ignore all TODOs with a deadlines" all)
  712. (const :tag "Show all TODOs, even if they have a deadline" nil)
  713. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  714. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  715. "Time unit to use when possibly ignoring an agenda item.
  716. See the docstring of various `org-agenda-todo-ignore-*' options.
  717. The default is to compare time stamps using days. An item is thus
  718. considered to be in the future if it is at least one day after today.
  719. Non-nil means to compare time stamps using seconds. An item is then
  720. considered future if it has a time value later than current time."
  721. :group 'org-agenda-skip
  722. :group 'org-agenda-todo-list
  723. :version "24.4"
  724. :package-version '(Org . "8.0")
  725. :type '(choice
  726. (const :tag "Compare time with days" nil)
  727. (const :tag "Compare time with seconds" t)))
  728. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  729. "Non-nil means honor todo-list ignores options also in tags-todo search.
  730. The variables
  731. `org-agenda-todo-ignore-with-date',
  732. `org-agenda-todo-ignore-timestamp',
  733. `org-agenda-todo-ignore-scheduled',
  734. `org-agenda-todo-ignore-deadlines'
  735. make the global TODO list skip entries that have time stamps of certain
  736. kinds. If this option is set, the same options will also apply for the
  737. tags-todo search, which is the general tags/property matcher
  738. restricted to unfinished TODO entries only."
  739. :group 'org-agenda-skip
  740. :group 'org-agenda-todo-list
  741. :group 'org-agenda-match-view
  742. :type 'boolean)
  743. (defcustom org-agenda-skip-scheduled-if-done nil
  744. "Non-nil means don't show scheduled items in agenda when they are done.
  745. This is relevant for the daily/weekly agenda, not for the TODO list. And
  746. it applies only to the actual date of the scheduling. Warnings about
  747. an item with a past scheduling dates are always turned off when the item
  748. is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  753. "Non-nil means skip scheduling line if same entry shows because of deadline.
  754. In the agenda of today, an entry can show up multiple times
  755. because it is both scheduled and has a nearby deadline, and maybe
  756. a plain time stamp as well.
  757. When this variable is nil, the entry will be shown several times.
  758. When set to t, then only the deadline is shown and the fact that
  759. the entry is scheduled today or was scheduled previously is not
  760. shown.
  761. When set to the symbol `not-today', skip scheduled previously,
  762. but not scheduled today.
  763. When set to the symbol `repeated-after-deadline', skip scheduled
  764. items if they are repeated beyond the current deadline."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-daily/weekly
  767. :type '(choice
  768. (const :tag "Never" nil)
  769. (const :tag "Always" t)
  770. (const :tag "Not when scheduled today" not-today)
  771. (const :tag "When repeated past deadline" repeated-after-deadline)))
  772. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  773. "Non-nil means skip timestamp line if same entry shows because of deadline.
  774. In the agenda of today, an entry can show up multiple times
  775. because it has both a plain timestamp and has a nearby deadline.
  776. When this variable is t, then only the deadline is shown and the
  777. fact that the entry has a timestamp for or including today is not
  778. shown. When this variable is nil, the entry will be shown
  779. several times."
  780. :group 'org-agenda-skip
  781. :group 'org-agenda-daily/weekly
  782. :version "24.1"
  783. :type '(choice
  784. (const :tag "Never" nil)
  785. (const :tag "Always" t)))
  786. (defcustom org-agenda-skip-deadline-if-done nil
  787. "Non-nil means don't show deadlines when the corresponding item is done.
  788. When nil, the deadline is still shown and should give you a happy feeling.
  789. This is relevant for the daily/weekly agenda. And it applied only to the
  790. actually date of the deadline. Warnings about approaching and past-due
  791. deadlines are always turned off when the item is DONE."
  792. :group 'org-agenda-skip
  793. :group 'org-agenda-daily/weekly
  794. :type 'boolean)
  795. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  796. "Non-nil means skip deadline prewarning when entry is also scheduled.
  797. This will apply on all days where a prewarning for the deadline would
  798. be shown, but not at the day when the entry is actually due. On that day,
  799. the deadline will be shown anyway.
  800. This variable may be set to nil, t, the symbol `pre-scheduled',
  801. or a number which will then give the number of days before the actual
  802. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  803. eliminates the deadline prewarning only prior to the scheduled date.
  804. This can be used in a workflow where the first showing of the deadline will
  805. trigger you to schedule it, and then you don't want to be reminded of it
  806. because you will take care of it on the day when scheduled."
  807. :group 'org-agenda-skip
  808. :group 'org-agenda-daily/weekly
  809. :version "24.1"
  810. :type '(choice
  811. (const :tag "Always show prewarning" nil)
  812. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  813. (const :tag "Remove prewarning if entry is scheduled" t)
  814. (integer :tag "Restart prewarning N days before deadline")))
  815. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  816. "Non-nil means skip scheduled delay when entry also has a deadline.
  817. This variable may be set to nil, t, the symbol `post-deadline',
  818. or a number which will then give the number of days after the actual
  819. scheduled date when the delay should expire. The symbol `post-deadline'
  820. eliminates the schedule delay when the date is posterior to the deadline."
  821. :group 'org-agenda-skip
  822. :group 'org-agenda-daily/weekly
  823. :version "24.4"
  824. :package-version '(Org . "8.0")
  825. :type '(choice
  826. (const :tag "Always honor delay" nil)
  827. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  828. (const :tag "Ignore delay if entry has a deadline" t)
  829. (integer :tag "Honor delay up until N days after the scheduled date")))
  830. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  831. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  832. When non-nil, after the search for timestamps has matched once in an
  833. entry, the rest of the entry will not be searched."
  834. :group 'org-agenda-skip
  835. :type 'boolean)
  836. (defcustom org-agenda-skip-timestamp-if-done nil
  837. "Non-nil means don't select item by timestamp or -range if it is DONE."
  838. :group 'org-agenda-skip
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-dim-blocked-tasks t
  842. "Non-nil means dim blocked tasks in the agenda display.
  843. This causes some overhead during agenda construction, but if you
  844. have turned on `org-enforce-todo-dependencies',
  845. `org-enforce-todo-checkbox-dependencies', or any other blocking
  846. mechanism, this will create useful feedback in the agenda.
  847. Instead of t, this variable can also have the value `invisible'.
  848. Then blocked tasks will be invisible and only become visible when
  849. they become unblocked. An exemption to this behavior is when a task is
  850. blocked because of unchecked checkboxes below it. Since checkboxes do
  851. not show up in the agenda views, making this task invisible you remove any
  852. trace from agenda views that there is something to do. Therefore, a task
  853. that is blocked because of checkboxes will never be made invisible, it
  854. will only be dimmed."
  855. :group 'org-agenda-daily/weekly
  856. :group 'org-agenda-todo-list
  857. :version "24.3"
  858. :type '(choice
  859. (const :tag "Do not dim" nil)
  860. (const :tag "Dim to a gray face" t)
  861. (const :tag "Make invisible" invisible)))
  862. (defcustom org-timeline-show-empty-dates 3
  863. "Non-nil means `org-timeline' also shows dates without an entry.
  864. When nil, only the days which actually have entries are shown.
  865. When t, all days between the first and the last date are shown.
  866. When an integer, show also empty dates, but if there is a gap of more than
  867. N days, just insert a special line indicating the size of the gap."
  868. :group 'org-agenda-skip
  869. :type '(choice
  870. (const :tag "None" nil)
  871. (const :tag "All" t)
  872. (integer :tag "at most")))
  873. (defgroup org-agenda-startup nil
  874. "Options concerning initial settings in the Agenda in Org Mode."
  875. :tag "Org Agenda Startup"
  876. :group 'org-agenda)
  877. (defcustom org-agenda-menu-show-matcher t
  878. "Non-nil means show the match string in the agenda dispatcher menu.
  879. When nil, the matcher string is not shown, but is put into the help-echo
  880. property so than moving the mouse over the command shows it.
  881. Setting it to nil is good if matcher strings are very long and/or if
  882. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  883. :group 'org-agenda
  884. :version "24.1"
  885. :type 'boolean)
  886. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  887. (defcustom org-agenda-menu-two-columns nil
  888. "Non-nil means, use two columns to show custom commands in the dispatcher.
  889. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  890. to nil."
  891. :group 'org-agenda
  892. :version "24.1"
  893. :type 'boolean)
  894. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  895. (defcustom org-agenda-finalize-hook nil
  896. "Hook run just before displaying an agenda buffer.
  897. The buffer is still writable when the hook is called.
  898. You can modify some of the buffer substrings but you should be
  899. extra careful not to modify the text properties of the agenda
  900. headlines as the agenda display heavily relies on them."
  901. :group 'org-agenda-startup
  902. :type 'hook)
  903. (defcustom org-agenda-mouse-1-follows-link nil
  904. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  905. A longer mouse click will still set point. Does not work on XEmacs.
  906. Needs to be set before org.el is loaded."
  907. :group 'org-agenda-startup
  908. :type 'boolean)
  909. (defcustom org-agenda-start-with-follow-mode nil
  910. "The initial value of follow mode in a newly created agenda window."
  911. :group 'org-agenda-startup
  912. :type 'boolean)
  913. (defcustom org-agenda-follow-indirect nil
  914. "Non-nil means `org-agenda-follow-mode' displays only the
  915. current item's tree, in an indirect buffer."
  916. :group 'org-agenda
  917. :version "24.1"
  918. :type 'boolean)
  919. (defcustom org-agenda-show-outline-path t
  920. "Non-nil means show outline path in echo area after line motion."
  921. :group 'org-agenda-startup
  922. :type 'boolean)
  923. (defcustom org-agenda-start-with-entry-text-mode nil
  924. "The initial value of entry-text-mode in a newly created agenda window."
  925. :group 'org-agenda-startup
  926. :type 'boolean)
  927. (defcustom org-agenda-entry-text-maxlines 5
  928. "Number of text lines to be added when `E' is pressed in the agenda.
  929. Note that this variable only used during agenda display. Add add entry text
  930. when exporting the agenda, configure the variable
  931. `org-agenda-add-entry-ext-maxlines'."
  932. :group 'org-agenda
  933. :type 'integer)
  934. (defcustom org-agenda-entry-text-exclude-regexps nil
  935. "List of regular expressions to clean up entry text.
  936. The complete matches of all regular expressions in this list will be
  937. removed from entry text before it is shown in the agenda."
  938. :group 'org-agenda
  939. :type '(repeat (regexp)))
  940. (defcustom org-agenda-entry-text-leaders " > "
  941. "Text prepended to the entry text in agenda buffers."
  942. :version "24.4"
  943. :package-version '(Org . "8.0")
  944. :group 'org-agenda
  945. :type 'string)
  946. (defvar org-agenda-entry-text-cleanup-hook nil
  947. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  948. This cleanup is done in a temporary buffer, so the function may inspect and
  949. change the entire buffer.
  950. Some default stuff like drawers and scheduling/deadline dates will already
  951. have been removed when this is called, as will any matches for regular
  952. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  953. (defvar org-agenda-include-inactive-timestamps nil
  954. "Non-nil means include inactive time stamps in agenda and timeline.
  955. Dynamically scoped.")
  956. (defgroup org-agenda-windows nil
  957. "Options concerning the windows used by the Agenda in Org Mode."
  958. :tag "Org Agenda Windows"
  959. :group 'org-agenda)
  960. (defcustom org-agenda-window-setup 'reorganize-frame
  961. "How the agenda buffer should be displayed.
  962. Possible values for this option are:
  963. current-window Show agenda in the current window, keeping all other windows.
  964. other-window Use `switch-to-buffer-other-window' to display agenda.
  965. reorganize-frame Show only two windows on the current frame, the current
  966. window and the agenda.
  967. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  968. Also, when exiting the agenda, kill that frame.
  969. See also the variable `org-agenda-restore-windows-after-quit'."
  970. :group 'org-agenda-windows
  971. :type '(choice
  972. (const current-window)
  973. (const other-frame)
  974. (const other-window)
  975. (const reorganize-frame)))
  976. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  977. "The min and max height of the agenda window as a fraction of frame height.
  978. The value of the variable is a cons cell with two numbers between 0 and 1.
  979. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  980. :group 'org-agenda-windows
  981. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  982. (defcustom org-agenda-restore-windows-after-quit nil
  983. "Non-nil means restore window configuration upon exiting agenda.
  984. Before the window configuration is changed for displaying the agenda,
  985. the current status is recorded. When the agenda is exited with
  986. `q' or `x' and this option is set, the old state is restored. If
  987. `org-agenda-window-setup' is `other-frame', the value of this
  988. option will be ignored."
  989. :group 'org-agenda-windows
  990. :type 'boolean)
  991. (defcustom org-agenda-ndays nil
  992. "Number of days to include in overview display.
  993. Should be 1 or 7.
  994. Obsolete, see `org-agenda-span'."
  995. :group 'org-agenda-daily/weekly
  996. :type '(choice (const nil)
  997. (integer)))
  998. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  999. (defcustom org-agenda-span 'week
  1000. "Number of days to include in overview display.
  1001. Can be day, week, month, year, or any number of days.
  1002. Custom commands can set this variable in the options section."
  1003. :group 'org-agenda-daily/weekly
  1004. :type '(choice (const :tag "Day" day)
  1005. (const :tag "Week" week)
  1006. (const :tag "Fortnight" fortnight)
  1007. (const :tag "Month" month)
  1008. (const :tag "Year" year)
  1009. (integer :tag "Custom")))
  1010. (defcustom org-agenda-start-on-weekday 1
  1011. "Non-nil means start the overview always on the specified weekday.
  1012. 0 denotes Sunday, 1 denotes Monday, etc.
  1013. When nil, always start on the current day.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type '(choice (const :tag "Today" nil)
  1017. (integer :tag "Weekday No.")))
  1018. (defcustom org-agenda-show-all-dates t
  1019. "Non-nil means `org-agenda' shows every day in the selected range.
  1020. When nil, only the days which actually have entries are shown."
  1021. :group 'org-agenda-daily/weekly
  1022. :type 'boolean)
  1023. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1024. "Format string for displaying dates in the agenda.
  1025. Used by the daily/weekly agenda and by the timeline. This should be
  1026. a format string understood by `format-time-string', or a function returning
  1027. the formatted date as a string. The function must take a single argument,
  1028. a calendar-style date list like (month day year)."
  1029. :group 'org-agenda-daily/weekly
  1030. :type '(choice
  1031. (string :tag "Format string")
  1032. (function :tag "Function")))
  1033. (defun org-agenda-format-date-aligned (date)
  1034. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1035. This function makes sure that dates are aligned for easy reading."
  1036. (require 'cal-iso)
  1037. (let* ((dayname (calendar-day-name date))
  1038. (day (cadr date))
  1039. (day-of-week (calendar-day-of-week date))
  1040. (month (car date))
  1041. (monthname (calendar-month-name month))
  1042. (year (nth 2 date))
  1043. (iso-week (org-days-to-iso-week
  1044. (calendar-absolute-from-gregorian date)))
  1045. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1046. (1- year))
  1047. ((and (= month 12) (<= iso-week 1))
  1048. (1+ year))
  1049. (t year)))
  1050. (weekstring (if (= day-of-week 1)
  1051. (format " W%02d" iso-week)
  1052. "")))
  1053. (format "%-10s %2d %s %4d%s"
  1054. dayname day monthname year weekstring)))
  1055. (defcustom org-agenda-time-leading-zero nil
  1056. "Non-nil means use leading zero for military times in agenda.
  1057. For example, 9:30am would become 09:30 rather than 9:30."
  1058. :group 'org-agenda-daily/weekly
  1059. :version "24.1"
  1060. :type 'boolean)
  1061. (defcustom org-agenda-timegrid-use-ampm nil
  1062. "When set, show AM/PM style timestamps on the timegrid."
  1063. :group 'org-agenda
  1064. :version "24.1"
  1065. :type 'boolean)
  1066. (defun org-agenda-time-of-day-to-ampm (time)
  1067. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1068. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1069. (minute (substring time -2))
  1070. (ampm "am"))
  1071. (cond
  1072. ((equal hour-number 12)
  1073. (setq ampm "pm"))
  1074. ((> hour-number 12)
  1075. (setq ampm "pm")
  1076. (setq hour-number (- hour-number 12))))
  1077. (concat
  1078. (if org-agenda-time-leading-zero
  1079. (format "%02d" hour-number)
  1080. (format "%02s" (number-to-string hour-number)))
  1081. ":" minute ampm)))
  1082. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1083. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1084. (if org-agenda-timegrid-use-ampm
  1085. (org-agenda-time-of-day-to-ampm time)
  1086. time))
  1087. (defcustom org-agenda-weekend-days '(6 0)
  1088. "Which days are weekend?
  1089. These days get the special face `org-agenda-date-weekend' in the agenda
  1090. and timeline buffers."
  1091. :group 'org-agenda-daily/weekly
  1092. :type '(set :greedy t
  1093. (const :tag "Monday" 1)
  1094. (const :tag "Tuesday" 2)
  1095. (const :tag "Wednesday" 3)
  1096. (const :tag "Thursday" 4)
  1097. (const :tag "Friday" 5)
  1098. (const :tag "Saturday" 6)
  1099. (const :tag "Sunday" 0)))
  1100. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1101. "Non-nil means jump to today when moving a past date forward in time.
  1102. When using S-right in the agenda to move a a date forward, and the date
  1103. stamp currently points to the past, the first key press will move it
  1104. to today. WHen nil, just move one day forward even if the date stays
  1105. in the past."
  1106. :group 'org-agenda-daily/weekly
  1107. :version "24.1"
  1108. :type 'boolean)
  1109. (defcustom org-agenda-include-diary nil
  1110. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1111. Custom commands can set this variable in the options section."
  1112. :group 'org-agenda-daily/weekly
  1113. :type 'boolean)
  1114. (defcustom org-agenda-include-deadlines t
  1115. "If non-nil, include entries within their deadline warning period.
  1116. Custom commands can set this variable in the options section."
  1117. :group 'org-agenda-daily/weekly
  1118. :version "24.1"
  1119. :type 'boolean)
  1120. (defcustom org-agenda-repeating-timestamp-show-all t
  1121. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1122. When set to a list of strings, only show occurrences of repeating
  1123. stamps for these TODO keywords. When nil, only one occurrence is
  1124. shown, either today or the nearest into the future."
  1125. :group 'org-agenda-daily/weekly
  1126. :type '(choice
  1127. (const :tag "Show repeating stamps" t)
  1128. (repeat :tag "Show repeating stamps for these TODO keywords"
  1129. (string :tag "TODO Keyword"))
  1130. (const :tag "Don't show repeating stamps" nil)))
  1131. (defcustom org-scheduled-past-days 10000
  1132. "Number of days to continue listing scheduled items not marked DONE.
  1133. When an item is scheduled on a date, it shows up in the agenda on this
  1134. day and will be listed until it is marked done for the number of days
  1135. given here."
  1136. :group 'org-agenda-daily/weekly
  1137. :type 'integer)
  1138. (defcustom org-agenda-log-mode-items '(closed clock)
  1139. "List of items that should be shown in agenda log mode.
  1140. This list may contain the following symbols:
  1141. closed Show entries that have been closed on that day.
  1142. clock Show entries that have received clocked time on that day.
  1143. state Show all logged state changes.
  1144. Note that instead of changing this variable, you can also press `C-u l' in
  1145. the agenda to display all available LOG items temporarily."
  1146. :group 'org-agenda-daily/weekly
  1147. :type '(set :greedy t (const closed) (const clock) (const state)))
  1148. (defcustom org-agenda-clock-consistency-checks
  1149. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1150. :gap-ok-around ("4:00")
  1151. :default-face ((:background "DarkRed") (:foreground "white"))
  1152. :overlap-face nil :gap-face nil :no-end-time-face nil
  1153. :long-face nil :short-face nil)
  1154. "This is a property list, with the following keys:
  1155. :max-duration Mark clocking chunks that are longer than this time.
  1156. This is a time string like \"HH:MM\", or the number
  1157. of minutes as an integer.
  1158. :min-duration Mark clocking chunks that are shorter that this.
  1159. This is a time string like \"HH:MM\", or the number
  1160. of minutes as an integer.
  1161. :max-gap Mark gaps between clocking chunks that are longer than
  1162. this duration. A number of minutes, or a string
  1163. like \"HH:MM\".
  1164. :gap-ok-around List of times during the day which are usually not working
  1165. times. When a gap is detected, but the gap contains any
  1166. of these times, the gap is *not* reported. For example,
  1167. if this is (\"4:00\" \"13:00\") then gaps that contain
  1168. 4:00 in the morning (i.e. the night) and 13:00
  1169. (i.e. a typical lunch time) do not cause a warning.
  1170. You should have at least one time during the night in this
  1171. list, or otherwise the first task each morning will trigger
  1172. a warning because it follows a long gap.
  1173. Furthermore, the following properties can be used to define faces for
  1174. issue display.
  1175. :default-face the default face, if the specific face is undefined
  1176. :overlap-face face for overlapping clocks
  1177. :gap-face face for gaps between clocks
  1178. :no-end-time-face face for incomplete clocks
  1179. :long-face face for clock intervals that are too long
  1180. :short-face face for clock intervals that are too short"
  1181. :group 'org-agenda-daily/weekly
  1182. :group 'org-clock
  1183. :version "24.1"
  1184. :type 'plist)
  1185. (defcustom org-agenda-log-mode-add-notes t
  1186. "Non-nil means add first line of notes to log entries in agenda views.
  1187. If a log item like a state change or a clock entry is associated with
  1188. notes, the first line of these notes will be added to the entry in the
  1189. agenda display."
  1190. :group 'org-agenda-daily/weekly
  1191. :type 'boolean)
  1192. (defcustom org-agenda-start-with-log-mode nil
  1193. "The initial value of log-mode in a newly created agenda window.
  1194. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1195. explanations on the possible values."
  1196. :group 'org-agenda-startup
  1197. :group 'org-agenda-daily/weekly
  1198. :type '(choice (const :tag "Don't show log items" nil)
  1199. (const :tag "Show only log items" only)
  1200. (const :tag "Show all possible log items" clockcheck)
  1201. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1202. (choice (const :tag "Show closed log items" closed)
  1203. (const :tag "Show clocked log items" clock)
  1204. (const :tag "Show all logged state changes" state)))))
  1205. (defcustom org-agenda-start-with-clockreport-mode nil
  1206. "The initial value of clockreport-mode in a newly created agenda window."
  1207. :group 'org-agenda-startup
  1208. :group 'org-agenda-daily/weekly
  1209. :type 'boolean)
  1210. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1211. "Property list with parameters for the clocktable in clockreport mode.
  1212. This is the display mode that shows a clock table in the daily/weekly
  1213. agenda, the properties for this dynamic block can be set here.
  1214. The usual clocktable parameters are allowed here, but you cannot set
  1215. the properties :name, :tstart, :tend, :block, and :scope - these will
  1216. be overwritten to make sure the content accurately reflects the
  1217. current display in the agenda."
  1218. :group 'org-agenda-daily/weekly
  1219. :type 'plist)
  1220. (defcustom org-agenda-search-view-always-boolean nil
  1221. "Non-nil means the search string is interpreted as individual parts.
  1222. The search string for search view can either be interpreted as a phrase,
  1223. or as a list of snippets that define a boolean search for a number of
  1224. strings.
  1225. When this is non-nil, the string will be split on whitespace, and each
  1226. snippet will be searched individually, and all must match in order to
  1227. select an entry. A snippet is then a single string of non-white
  1228. characters, or a string in double quotes, or a regexp in {} braces.
  1229. If a snippet is preceded by \"-\", the snippet must *not* match.
  1230. \"+\" is syntactic sugar for positive selection. Each snippet may
  1231. be found as a full word or a partial word, but see the variable
  1232. `org-agenda-search-view-force-full-words'.
  1233. When this is nil, search will look for the entire search phrase as one,
  1234. with each space character matching any amount of whitespace, including
  1235. line breaks.
  1236. Even when this is nil, you can still switch to Boolean search dynamically
  1237. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1238. is a regexp marked with braces like \"{abc}\", this will also switch to
  1239. boolean search."
  1240. :group 'org-agenda-search-view
  1241. :version "24.1"
  1242. :type 'boolean)
  1243. (org-defvaralias 'org-agenda-search-view-search-words-only
  1244. 'org-agenda-search-view-always-boolean)
  1245. (defcustom org-agenda-search-view-force-full-words nil
  1246. "Non-nil means, search words must be matches as complete words.
  1247. When nil, they may also match part of a word."
  1248. :group 'org-agenda-search-view
  1249. :version "24.1"
  1250. :type 'boolean)
  1251. (defcustom org-agenda-search-view-max-outline-level 0
  1252. "Maximum outline level to display in search view.
  1253. E.g. when this is set to 1, the search view will only
  1254. show headlines of level 1. When set to 0, the default
  1255. value, don't limit agenda view by outline level."
  1256. :group 'org-agenda-search-view
  1257. :version "24.4"
  1258. :package-version '(Org . "8.3")
  1259. :type 'integer)
  1260. (defgroup org-agenda-time-grid nil
  1261. "Options concerning the time grid in the Org-mode Agenda."
  1262. :tag "Org Agenda Time Grid"
  1263. :group 'org-agenda)
  1264. (defcustom org-agenda-search-headline-for-time t
  1265. "Non-nil means search headline for a time-of-day.
  1266. If the headline contains a time-of-day in one format or another, it will
  1267. be used to sort the entry into the time sequence of items for a day.
  1268. Some people have time stamps in the headline that refer to the creation
  1269. time or so, and then this produces an unwanted side effect. If this is
  1270. the case for your, use this variable to turn off searching the headline
  1271. for a time."
  1272. :group 'org-agenda-time-grid
  1273. :type 'boolean)
  1274. (defcustom org-agenda-use-time-grid t
  1275. "Non-nil means show a time grid in the agenda schedule.
  1276. A time grid is a set of lines for specific times (like every two hours between
  1277. 8:00 and 20:00). The items scheduled for a day at specific times are
  1278. sorted in between these lines.
  1279. For details about when the grid will be shown, and what it will look like, see
  1280. the variable `org-agenda-time-grid'."
  1281. :group 'org-agenda-time-grid
  1282. :type 'boolean)
  1283. (defcustom org-agenda-time-grid
  1284. '((daily today require-timed)
  1285. "----------------"
  1286. (800 1000 1200 1400 1600 1800 2000))
  1287. "The settings for time grid for agenda display.
  1288. This is a list of three items. The first item is again a list. It contains
  1289. symbols specifying conditions when the grid should be displayed:
  1290. daily if the agenda shows a single day
  1291. weekly if the agenda shows an entire week
  1292. today show grid on current date, independent of daily/weekly display
  1293. require-timed show grid only if at least one item has a time specification
  1294. The second item is a string which will be placed behind the grid time.
  1295. The third item is a list of integers, indicating the times that should have
  1296. a grid line."
  1297. :group 'org-agenda-time-grid
  1298. :type
  1299. '(list
  1300. (set :greedy t :tag "Grid Display Options"
  1301. (const :tag "Show grid in single day agenda display" daily)
  1302. (const :tag "Show grid in weekly agenda display" weekly)
  1303. (const :tag "Always show grid for today" today)
  1304. (const :tag "Show grid only if any timed entries are present"
  1305. require-timed)
  1306. (const :tag "Skip grid times already present in an entry"
  1307. remove-match))
  1308. (string :tag "Grid String")
  1309. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1310. (defcustom org-agenda-show-current-time-in-grid t
  1311. "Non-nil means show the current time in the time grid."
  1312. :group 'org-agenda-time-grid
  1313. :version "24.1"
  1314. :type 'boolean)
  1315. (defcustom org-agenda-current-time-string
  1316. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1317. "The string for the current time marker in the agenda."
  1318. :group 'org-agenda-time-grid
  1319. :version "24.1"
  1320. :type 'string)
  1321. (defgroup org-agenda-sorting nil
  1322. "Options concerning sorting in the Org-mode Agenda."
  1323. :tag "Org Agenda Sorting"
  1324. :group 'org-agenda)
  1325. (defcustom org-agenda-sorting-strategy
  1326. '((agenda habit-down time-up priority-down category-keep)
  1327. (todo priority-down category-keep)
  1328. (tags priority-down category-keep)
  1329. (search category-keep))
  1330. "Sorting structure for the agenda items of a single day.
  1331. This is a list of symbols which will be used in sequence to determine
  1332. if an entry should be listed before another entry. The following
  1333. symbols are recognized:
  1334. time-up Put entries with time-of-day indications first, early first
  1335. time-down Put entries with time-of-day indications first, late first
  1336. timestamp-up Sort by any timestamp, early first
  1337. timestamp-down Sort by any timestamp, late first
  1338. scheduled-up Sort by scheduled timestamp, early first
  1339. scheduled-down Sort by scheduled timestamp, late first
  1340. deadline-up Sort by deadline timestamp, early first
  1341. deadline-down Sort by deadline timestamp, late first
  1342. ts-up Sort by active timestamp, early first
  1343. ts-down Sort by active timestamp, late first
  1344. tsia-up Sort by inactive timestamp, early first
  1345. tsia-down Sort by inactive timestamp, late first
  1346. category-keep Keep the default order of categories, corresponding to the
  1347. sequence in `org-agenda-files'.
  1348. category-up Sort alphabetically by category, A-Z.
  1349. category-down Sort alphabetically by category, Z-A.
  1350. tag-up Sort alphabetically by last tag, A-Z.
  1351. tag-down Sort alphabetically by last tag, Z-A.
  1352. priority-up Sort numerically by priority, high priority last.
  1353. priority-down Sort numerically by priority, high priority first.
  1354. todo-state-up Sort by todo state, tasks that are done last.
  1355. todo-state-down Sort by todo state, tasks that are done first.
  1356. effort-up Sort numerically by estimated effort, high effort last.
  1357. effort-down Sort numerically by estimated effort, high effort first.
  1358. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1359. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1360. habit-up Put entries that are habits first
  1361. habit-down Put entries that are habits last
  1362. alpha-up Sort headlines alphabetically
  1363. alpha-down Sort headlines alphabetically, reversed
  1364. The different possibilities will be tried in sequence, and testing stops
  1365. if one comparison returns a \"not-equal\". For example, the default
  1366. '(time-up category-keep priority-down)
  1367. means: Pull out all entries having a specified time of day and sort them,
  1368. in order to make a time schedule for the current day the first thing in the
  1369. agenda listing for the day. Of the entries without a time indication, keep
  1370. the grouped in categories, don't sort the categories, but keep them in
  1371. the sequence given in `org-agenda-files'. Within each category sort by
  1372. priority.
  1373. Leaving out `category-keep' would mean that items will be sorted across
  1374. categories by priority.
  1375. Instead of a single list, this can also be a set of list for specific
  1376. contents, with a context symbol in the car of the list, any of
  1377. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1378. Custom commands can bind this variable in the options section."
  1379. :group 'org-agenda-sorting
  1380. :type `(choice
  1381. (repeat :tag "General" ,org-sorting-choice)
  1382. (list :tag "Individually"
  1383. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1384. (repeat ,org-sorting-choice))
  1385. (cons (const :tag "Strategy for TODO lists" todo)
  1386. (repeat ,org-sorting-choice))
  1387. (cons (const :tag "Strategy for Tags matches" tags)
  1388. (repeat ,org-sorting-choice))
  1389. (cons (const :tag "Strategy for search matches" search)
  1390. (repeat ,org-sorting-choice)))))
  1391. (defcustom org-agenda-cmp-user-defined nil
  1392. "A function to define the comparison `user-defined'.
  1393. This function must receive two arguments, agenda entry a and b.
  1394. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1395. the user comparison, return nil.
  1396. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1397. part of an agenda sorting strategy."
  1398. :group 'org-agenda-sorting
  1399. :type 'symbol)
  1400. (defcustom org-sort-agenda-notime-is-late t
  1401. "Non-nil means items without time are considered late.
  1402. This is only relevant for sorting. When t, items which have no explicit
  1403. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1404. do have a time. When nil, the default time is before 0:00. You can use this
  1405. option to decide if the schedule for today should come before or after timeless
  1406. agenda entries."
  1407. :group 'org-agenda-sorting
  1408. :type 'boolean)
  1409. (defcustom org-sort-agenda-noeffort-is-high t
  1410. "Non-nil means items without effort estimate are sorted as high effort.
  1411. This also applies when filtering an agenda view with respect to the
  1412. < or > effort operator. Then, tasks with no effort defined will be treated
  1413. as tasks with high effort.
  1414. When nil, such items are sorted as 0 minutes effort."
  1415. :group 'org-agenda-sorting
  1416. :type 'boolean)
  1417. (defgroup org-agenda-line-format nil
  1418. "Options concerning the entry prefix in the Org-mode agenda display."
  1419. :tag "Org Agenda Line Format"
  1420. :group 'org-agenda)
  1421. (defcustom org-agenda-prefix-format
  1422. '((agenda . " %i %-12:c%?-12t% s")
  1423. (timeline . " % s")
  1424. (todo . " %i %-12:c")
  1425. (tags . " %i %-12:c")
  1426. (search . " %i %-12:c"))
  1427. "Format specifications for the prefix of items in the agenda views.
  1428. An alist with five entries, each for the different agenda types. The
  1429. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1430. The values are format strings.
  1431. This format works similar to a printf format, with the following meaning:
  1432. %c the category of the item, \"Diary\" for entries from the diary,
  1433. or as given by the CATEGORY keyword or derived from the file name
  1434. %e the effort required by the item
  1435. %l the level of the item (insert X space(s) if item is of level X)
  1436. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1437. %T the last tag of the item (ignore inherited tags, which come first)
  1438. %t the HH:MM time-of-day specification if one applies to the entry
  1439. %s Scheduling/Deadline information, a short string
  1440. %b show breadcrumbs, i.e., the names of the higher levels
  1441. %(expression) Eval EXPRESSION and replace the control string
  1442. by the result
  1443. All specifiers work basically like the standard `%s' of printf, but may
  1444. contain two additional characters: a question mark just after the `%'
  1445. and a whitespace/punctuation character just before the final letter.
  1446. If the first character after `%' is a question mark, the entire field
  1447. will only be included if the corresponding value applies to the current
  1448. entry. This is useful for fields which should have fixed width when
  1449. present, but zero width when absent. For example, \"%?-12t\" will
  1450. result in a 12 character time field if a time of the day is specified,
  1451. but will completely disappear in entries which do not contain a time.
  1452. If there is punctuation or whitespace character just before the
  1453. final format letter, this character will be appended to the field
  1454. value if the value is not empty. For example, the format
  1455. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1456. the category is empty, no additional colon is inserted.
  1457. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1458. which means:
  1459. - Indent the line with two space characters
  1460. - Give the category a 12 chars wide field, padded with whitespace on
  1461. the right (because of `-'). Append a colon if there is a category
  1462. (because of `:').
  1463. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1464. time, don't put in an empty field, just skip it (because of '?').
  1465. - Finally, put the scheduling information.
  1466. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1467. `org-agenda-remove-tags'.
  1468. Custom commands can set this variable in the options section."
  1469. :type '(choice
  1470. (string :tag "General format")
  1471. (list :greedy t :tag "View dependent"
  1472. (cons (const agenda) (string :tag "Format"))
  1473. (cons (const timeline) (string :tag "Format"))
  1474. (cons (const todo) (string :tag "Format"))
  1475. (cons (const tags) (string :tag "Format"))
  1476. (cons (const search) (string :tag "Format"))))
  1477. :group 'org-agenda-line-format)
  1478. (defvar org-prefix-format-compiled nil
  1479. "The compiled prefix format and associated variables.
  1480. This is a list where first element is a list of variable bindings, and second
  1481. element is the compiled format expression. See the variable
  1482. `org-agenda-prefix-format'.")
  1483. (defcustom org-agenda-todo-keyword-format "%-1s"
  1484. "Format for the TODO keyword in agenda lines.
  1485. Set this to something like \"%-12s\" if you want all TODO keywords
  1486. to occupy a fixed space in the agenda display."
  1487. :group 'org-agenda-line-format
  1488. :type 'string)
  1489. (defcustom org-agenda-diary-sexp-prefix nil
  1490. "A regexp that matches part of a diary sexp entry
  1491. which should be treated as scheduling/deadline information in
  1492. `org-agenda'.
  1493. For example, you can use this to extract the `diary-remind-message' from
  1494. `diary-remind' entries."
  1495. :group 'org-agenda-line-format
  1496. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1497. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1498. "Text preceding timerange entries in the agenda view.
  1499. This is a list with two strings. The first applies when the range
  1500. is entirely on one day. The second applies if the range spans several days.
  1501. The strings may have two \"%d\" format specifiers which will be filled
  1502. with the sequence number of the days, and the total number of days in the
  1503. range, respectively."
  1504. :group 'org-agenda-line-format
  1505. :type '(list
  1506. (string :tag "Deadline today ")
  1507. (choice :tag "Deadline relative"
  1508. (string :tag "Format string")
  1509. (function))))
  1510. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1511. "Text preceding scheduled items in the agenda view.
  1512. This is a list with two strings. The first applies when the item is
  1513. scheduled on the current day. The second applies when it has been scheduled
  1514. previously, it may contain a %d indicating that this is the nth time that
  1515. this item is scheduled, due to automatic rescheduling of unfinished items
  1516. for the following day. So this number is one larger than the number of days
  1517. that passed since this item was scheduled first."
  1518. :group 'org-agenda-line-format
  1519. :version "24.4"
  1520. :package-version '(Org . "8.0")
  1521. :type '(list
  1522. (string :tag "Scheduled today ")
  1523. (string :tag "Scheduled previously")))
  1524. (defcustom org-agenda-inactive-leader "["
  1525. "Text preceding item pulled into the agenda by inactive time stamps.
  1526. These entries are added to the agenda when pressing \"[\"."
  1527. :group 'org-agenda-line-format
  1528. :version "24.1"
  1529. :type 'string)
  1530. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1531. "Text preceding deadline items in the agenda view.
  1532. This is a list with three strings. The first applies when the item has its
  1533. deadline on the current day. The second applies when the deadline is in the
  1534. future, the third one when it is in the past. The strings may contain %d
  1535. to capture the number of days."
  1536. :group 'org-agenda-line-format
  1537. :version "24.4"
  1538. :package-version '(Org . "8.0")
  1539. :type '(list
  1540. (string :tag "Deadline today ")
  1541. (string :tag "Deadline in the future ")
  1542. (string :tag "Deadline in the past ")))
  1543. (defcustom org-agenda-remove-times-when-in-prefix t
  1544. "Non-nil means remove duplicate time specifications in agenda items.
  1545. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1546. time-of-day specification in a headline or diary entry is extracted and
  1547. placed into the prefix. If this option is non-nil, the original specification
  1548. \(a timestamp or -range, or just a plain time(range) specification like
  1549. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1550. cluttered.
  1551. The option can be t or nil. It may also be the symbol `beg', indicating
  1552. that the time should only be removed when it is located at the beginning of
  1553. the headline/diary entry."
  1554. :group 'org-agenda-line-format
  1555. :type '(choice
  1556. (const :tag "Always" t)
  1557. (const :tag "Never" nil)
  1558. (const :tag "When at beginning of entry" beg)))
  1559. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1560. "Non-nil means remove time ranges specifications in agenda
  1561. items that span on several days."
  1562. :group 'org-agenda-line-format
  1563. :version "24.1"
  1564. :type 'boolean)
  1565. (defcustom org-agenda-default-appointment-duration nil
  1566. "Default duration for appointments that only have a starting time.
  1567. When nil, no duration is specified in such cases.
  1568. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1569. :group 'org-agenda-line-format
  1570. :type '(choice
  1571. (integer :tag "Minutes")
  1572. (const :tag "No default duration")))
  1573. (defcustom org-agenda-show-inherited-tags t
  1574. "Non-nil means show inherited tags in each agenda line.
  1575. When this option is set to 'always, it take precedences over
  1576. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1577. in every agenda.
  1578. When this option is set to t (the default), inherited tags are
  1579. shown when they are available, i.e. when the value of
  1580. `org-agenda-use-tag-inheritance' has been taken into account.
  1581. This can be set to a list of agenda types in which the agenda
  1582. must display the inherited tags. Available types are 'todo,
  1583. 'agenda, 'search and 'timeline.
  1584. When set to nil, never show inherited tags in agenda lines."
  1585. :group 'org-agenda-line-format
  1586. :group 'org-agenda
  1587. :version "24.3"
  1588. :type '(choice
  1589. (const :tag "Show inherited tags when available" t)
  1590. (const :tag "Always show inherited tags" always)
  1591. (repeat :tag "Show inherited tags only in selected agenda types"
  1592. (symbol :tag "Agenda type"))))
  1593. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1594. "List of agenda view types where to use tag inheritance.
  1595. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1596. controlled by `org-use-tag-inheritance'. In other agenda types,
  1597. `org-use-tag-inheritance' is not used for the selection of the
  1598. agenda entries. Still, you may want the agenda to be aware of
  1599. the inherited tags anyway, e.g. for later tag filtering.
  1600. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1601. This variable has no effect if `org-agenda-show-inherited-tags'
  1602. is set to 'always. In that case, the agenda is aware of those
  1603. tags.
  1604. The default value sets tags in every agenda type. Setting this
  1605. option to nil will speed up non-tags agenda view a lot."
  1606. :group 'org-agenda
  1607. :version "24.3"
  1608. :type '(choice
  1609. (const :tag "Use tag inheritance in all agenda types" t)
  1610. (repeat :tag "Use tag inheritance in selected agenda types"
  1611. (symbol :tag "Agenda type"))))
  1612. (defcustom org-agenda-hide-tags-regexp nil
  1613. "Regular expression used to filter away specific tags in agenda views.
  1614. This means that these tags will be present, but not be shown in the agenda
  1615. line. Secondary filtering will still work on the hidden tags.
  1616. Nil means don't hide any tags."
  1617. :group 'org-agenda-line-format
  1618. :type '(choice
  1619. (const :tag "Hide none" nil)
  1620. (string :tag "Regexp ")))
  1621. (defcustom org-agenda-remove-tags nil
  1622. "Non-nil means remove the tags from the headline copy in the agenda.
  1623. When this is the symbol `prefix', only remove tags when
  1624. `org-agenda-prefix-format' contains a `%T' specifier."
  1625. :group 'org-agenda-line-format
  1626. :type '(choice
  1627. (const :tag "Always" t)
  1628. (const :tag "Never" nil)
  1629. (const :tag "When prefix format contains %T" prefix)))
  1630. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1631. 'org-agenda-remove-tags)
  1632. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1633. "Shift tags in agenda items to this column.
  1634. If this number is positive, it specifies the column. If it is negative,
  1635. it means that the tags should be flushright to that column. For example,
  1636. -80 works well for a normal 80 character screen."
  1637. :group 'org-agenda-line-format
  1638. :type 'integer)
  1639. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1640. (defcustom org-agenda-fontify-priorities 'cookies
  1641. "Non-nil means highlight low and high priorities in agenda.
  1642. When t, the highest priority entries are bold, lowest priority italic.
  1643. However, settings in `org-priority-faces' will overrule these faces.
  1644. When this variable is the symbol `cookies', only fontify the
  1645. cookies, not the entire task.
  1646. This may also be an association list of priority faces, whose
  1647. keys are the character values of `org-highest-priority',
  1648. `org-default-priority', and `org-lowest-priority' (the default values
  1649. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1650. color as a string, or a list like `(:background \"Red\")'.
  1651. If it is a color, the variable `org-faces-easy-properties'
  1652. determines if it is a foreground or a background color."
  1653. :group 'org-agenda-line-format
  1654. :type '(choice
  1655. (const :tag "Never" nil)
  1656. (const :tag "Defaults" t)
  1657. (const :tag "Cookies only" cookies)
  1658. (repeat :tag "Specify"
  1659. (list (character :tag "Priority" :value ?A)
  1660. (choice :tag "Face "
  1661. (string :tag "Color")
  1662. (sexp :tag "Face"))))))
  1663. (defcustom org-agenda-day-face-function nil
  1664. "Function called to determine what face should be used to display a day.
  1665. The only argument passed to that function is the day. It should
  1666. returns a face, or nil if does not want to specify a face and let
  1667. the normal rules apply."
  1668. :group 'org-agenda-line-format
  1669. :version "24.1"
  1670. :type '(choice (const nil) (function)))
  1671. (defcustom org-agenda-category-icon-alist nil
  1672. "Alist of category icon to be displayed in agenda views.
  1673. Each entry should have the following format:
  1674. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1675. Where CATEGORY-REGEXP is a regexp matching the categories where
  1676. the icon should be displayed.
  1677. FILE-OR-DATA either a file path or a string containing image data.
  1678. The other fields can be omitted safely if not needed:
  1679. TYPE indicates the image type.
  1680. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1681. image data.
  1682. PROPS are additional image attributes to assign to the image,
  1683. like, e.g. `:ascent center'.
  1684. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1685. If you want to set the display properties yourself, just put a
  1686. list as second element:
  1687. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1688. For example, to display a 16px horizontal space for Emacs
  1689. category, you can use:
  1690. (\"Emacs\" '(space . (:width (16))))"
  1691. :group 'org-agenda-line-format
  1692. :version "24.1"
  1693. :type '(alist :key-type (string :tag "Regexp matching category")
  1694. :value-type (choice (list :tag "Icon"
  1695. (string :tag "File or data")
  1696. (symbol :tag "Type")
  1697. (boolean :tag "Data?")
  1698. (repeat :tag "Extra image properties" :inline t symbol))
  1699. (list :tag "Display properties" sexp))))
  1700. (defgroup org-agenda-column-view nil
  1701. "Options concerning column view in the agenda."
  1702. :tag "Org Agenda Column View"
  1703. :group 'org-agenda)
  1704. (defcustom org-agenda-columns-show-summaries t
  1705. "Non-nil means show summaries for columns displayed in the agenda view."
  1706. :group 'org-agenda-column-view
  1707. :type 'boolean)
  1708. (defcustom org-agenda-columns-compute-summary-properties t
  1709. "Non-nil means recompute all summary properties before column view.
  1710. When column view in the agenda is listing properties that have a summary
  1711. operator, it can go to all relevant buffers and recompute the summaries
  1712. there. This can mean overhead for the agenda column view, but is necessary
  1713. to have thing up to date.
  1714. As a special case, a CLOCKSUM property also makes sure that the clock
  1715. computations are current."
  1716. :group 'org-agenda-column-view
  1717. :type 'boolean)
  1718. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1719. "Non-nil means the duration of an appointment will add to day effort.
  1720. The property to which appointment durations will be added is the one given
  1721. in the option `org-effort-property'. If an appointment does not have
  1722. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1723. is not set, an appointment without end time will not contribute to the time
  1724. estimate."
  1725. :group 'org-agenda-column-view
  1726. :type 'boolean)
  1727. (defcustom org-agenda-auto-exclude-function nil
  1728. "A function called with a tag to decide if it is filtered on '/ RET'.
  1729. The sole argument to the function, which is called once for each
  1730. possible tag, is a string giving the name of the tag. The
  1731. function should return either nil if the tag should be included
  1732. as normal, or \"-<TAG>\" to exclude the tag.
  1733. Note that for the purpose of tag filtering, only the lower-case version of
  1734. all tags will be considered, so that this function will only ever see
  1735. the lower-case version of all tags."
  1736. :group 'org-agenda
  1737. :type '(choice (const nil) (function)))
  1738. (defcustom org-agenda-bulk-custom-functions nil
  1739. "Alist of characters and custom functions for bulk actions.
  1740. For example, this value makes those two functions available:
  1741. '((?R set-category)
  1742. (?C bulk-cut))
  1743. With selected entries in an agenda buffer, `B R' will call
  1744. the custom function `set-category' on the selected entries.
  1745. Note that functions in this alist don't need to be quoted."
  1746. :type 'alist
  1747. :version "24.1"
  1748. :group 'org-agenda)
  1749. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1750. "Execute BODY with point at location given by `org-hd-marker' property.
  1751. If STRING is non-nil, the text property will be fetched from position 0
  1752. in that string. If STRING is nil, it will be fetched from the beginning
  1753. of the current line."
  1754. (org-with-gensyms (marker)
  1755. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1756. 'org-hd-marker ,string)))
  1757. (with-current-buffer (marker-buffer ,marker)
  1758. (save-excursion
  1759. (goto-char ,marker)
  1760. ,@body)))))
  1761. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1762. (defun org-add-agenda-custom-command (entry)
  1763. "Replace or add a command in `org-agenda-custom-commands'.
  1764. This is mostly for hacking and trying a new command - once the command
  1765. works you probably want to add it to `org-agenda-custom-commands' for good."
  1766. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1767. (if ass
  1768. (setcdr ass (cdr entry))
  1769. (push entry org-agenda-custom-commands))))
  1770. ;;; Define the org-agenda-mode
  1771. (defvar org-agenda-mode-map (make-sparse-keymap)
  1772. "Keymap for `org-agenda-mode'.")
  1773. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1774. (defvar org-agenda-menu) ; defined later in this file.
  1775. (defvar org-agenda-restrict nil) ; defined later in this file.
  1776. (defvar org-agenda-follow-mode nil)
  1777. (defvar org-agenda-entry-text-mode nil)
  1778. (defvar org-agenda-clockreport-mode nil)
  1779. (defvar org-agenda-show-log nil)
  1780. (defvar org-agenda-redo-command nil)
  1781. (defvar org-agenda-query-string nil)
  1782. (defvar org-agenda-mode-hook nil
  1783. "Hook run after `org-agenda-mode' is turned on.
  1784. The buffer is still writable when this hook is called.")
  1785. (defvar org-agenda-type nil)
  1786. (defvar org-agenda-force-single-file nil)
  1787. (defvar org-agenda-bulk-marked-entries nil
  1788. "List of markers that refer to marked entries in the agenda.")
  1789. ;;; Multiple agenda buffers support
  1790. (defcustom org-agenda-sticky nil
  1791. "Non-nil means agenda q key will bury agenda buffers.
  1792. Agenda commands will then show existing buffer instead of generating new ones.
  1793. When nil, `q' will kill the single agenda buffer."
  1794. :group 'org-agenda
  1795. :version "24.3"
  1796. :type 'boolean)
  1797. ;;;###autoload
  1798. (defun org-toggle-sticky-agenda (&optional arg)
  1799. "Toggle `org-agenda-sticky'."
  1800. (interactive "P")
  1801. (let ((new-value (if arg
  1802. (> (prefix-numeric-value arg) 0)
  1803. (not org-agenda-sticky))))
  1804. (if (equal new-value org-agenda-sticky)
  1805. (and (org-called-interactively-p 'interactive)
  1806. (message "Sticky agenda was already %s"
  1807. (if org-agenda-sticky "enabled" "disabled")))
  1808. (setq org-agenda-sticky new-value)
  1809. (org-agenda-kill-all-agenda-buffers)
  1810. (and (org-called-interactively-p 'interactive)
  1811. (message "Sticky agenda was %s"
  1812. (if org-agenda-sticky "enabled" "disabled"))))))
  1813. (defvar org-agenda-buffer nil
  1814. "Agenda buffer currently being generated.")
  1815. (defvar org-agenda-last-prefix-arg nil)
  1816. (defvar org-agenda-this-buffer-name nil)
  1817. (defvar org-agenda-doing-sticky-redo nil)
  1818. (defvar org-agenda-this-buffer-is-sticky nil)
  1819. (defconst org-agenda-local-vars
  1820. '(org-agenda-this-buffer-name
  1821. org-agenda-undo-list
  1822. org-agenda-pending-undo-list
  1823. org-agenda-follow-mode
  1824. org-agenda-entry-text-mode
  1825. org-agenda-clockreport-mode
  1826. org-agenda-show-log
  1827. org-agenda-redo-command
  1828. org-agenda-query-string
  1829. org-agenda-type
  1830. org-agenda-bulk-marked-entries
  1831. org-agenda-undo-has-started-in
  1832. org-agenda-info
  1833. org-agenda-pre-window-conf
  1834. org-agenda-columns-active
  1835. org-agenda-tag-filter-overlays
  1836. org-agenda-tag-filter
  1837. org-agenda-cat-filter-overlays
  1838. org-agenda-category-filter
  1839. org-agenda-re-filter-overlays
  1840. org-agenda-regexp-filter
  1841. org-agenda-markers
  1842. org-agenda-last-search-view-search-was-boolean
  1843. org-agenda-filtered-by-category
  1844. org-agenda-filter-form
  1845. org-agenda-cycle-counter
  1846. org-agenda-last-prefix-arg)
  1847. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1848. (defun org-agenda-mode ()
  1849. "Mode for time-sorted view on action items in Org-mode files.
  1850. The following commands are available:
  1851. \\{org-agenda-mode-map}"
  1852. (interactive)
  1853. (cond (org-agenda-doing-sticky-redo
  1854. ;; Refreshing sticky agenda-buffer
  1855. ;;
  1856. ;; Preserve the value of `org-agenda-local-vars' variables,
  1857. ;; while letting `kill-all-local-variables' kill the rest
  1858. (let ((save (buffer-local-variables)))
  1859. (kill-all-local-variables)
  1860. (mapc 'make-local-variable org-agenda-local-vars)
  1861. (dolist (elem save)
  1862. (let ((var (car elem))
  1863. (val (cdr elem)))
  1864. (when (and val
  1865. (member var org-agenda-local-vars))
  1866. (set var val)))))
  1867. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1868. (org-agenda-sticky
  1869. ;; Creating a sticky Agenda buffer for the first time
  1870. (kill-all-local-variables)
  1871. (mapc 'make-local-variable org-agenda-local-vars)
  1872. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1873. (t
  1874. ;; Creating a non-sticky agenda buffer
  1875. (kill-all-local-variables)
  1876. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1877. (setq org-agenda-undo-list nil
  1878. org-agenda-pending-undo-list nil
  1879. org-agenda-bulk-marked-entries nil)
  1880. (setq major-mode 'org-agenda-mode)
  1881. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1882. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1883. (setq mode-name "Org-Agenda")
  1884. (setq indent-tabs-mode nil)
  1885. (use-local-map org-agenda-mode-map)
  1886. (easy-menu-add org-agenda-menu)
  1887. (if org-startup-truncated (setq truncate-lines t))
  1888. (org-set-local 'line-move-visual nil)
  1889. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1890. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1891. ;; Make sure properties are removed when copying text
  1892. (org-add-hook 'filter-buffer-substring-functions
  1893. (lambda (fun start end delete)
  1894. (substring-no-properties (funcall fun start end delete)))
  1895. nil t)
  1896. (unless org-agenda-keep-modes
  1897. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1898. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1899. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1900. org-agenda-show-log org-agenda-start-with-log-mode))
  1901. (easy-menu-change
  1902. '("Agenda") "Agenda Files"
  1903. (append
  1904. (list
  1905. (vector
  1906. (if (get 'org-agenda-files 'org-restrict)
  1907. "Restricted to single file"
  1908. "Edit File List")
  1909. '(org-edit-agenda-file-list)
  1910. (not (get 'org-agenda-files 'org-restrict)))
  1911. "--")
  1912. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1913. (org-agenda-set-mode-name)
  1914. (apply
  1915. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1916. (list 'org-agenda-mode-hook)))
  1917. (substitute-key-definition 'undo 'org-agenda-undo
  1918. org-agenda-mode-map global-map)
  1919. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1920. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1921. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1922. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1923. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1924. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1925. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1926. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1927. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1928. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1929. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1930. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1931. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1932. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1933. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1934. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1935. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1936. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1941. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1943. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1945. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1946. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1947. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1948. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1949. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1950. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1951. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1952. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1954. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1955. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1956. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1957. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1958. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1959. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1960. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1961. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1962. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1963. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1964. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1965. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1966. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1967. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1968. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1969. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1971. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1972. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1973. (while l (org-defkey org-agenda-mode-map
  1974. (int-to-string (pop l)) 'digit-argument)))
  1975. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1976. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1977. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1978. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1979. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1980. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1981. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1982. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1983. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1984. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1985. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1986. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1988. 'org-clock-modify-effort-estimate)
  1989. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1990. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1991. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1992. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1993. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1994. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1995. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1996. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1997. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1998. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1999. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2000. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2001. (substitute-key-definition 'next-line 'org-agenda-next-line
  2002. org-agenda-mode-map global-map)
  2003. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2004. org-agenda-mode-map global-map)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2007. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2008. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2009. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2010. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2011. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2012. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2013. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2014. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2015. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2016. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2017. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2018. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2019. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2020. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2022. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2023. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2024. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2025. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2026. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2027. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2028. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2029. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2030. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2031. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2032. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2033. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2034. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2035. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2036. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2037. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2038. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2039. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2040. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2041. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2042. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2043. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2044. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2045. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2046. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2047. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2049. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2050. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2051. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2052. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2053. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2054. (when org-agenda-mouse-1-follows-link
  2055. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2056. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2057. '("Agenda"
  2058. ("Agenda Files")
  2059. "--"
  2060. ("Agenda Dates"
  2061. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2062. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2063. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2064. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2065. "--"
  2066. ("View"
  2067. ["Day View" org-agenda-day-view
  2068. :active (org-agenda-check-type nil 'agenda)
  2069. :style radio :selected (eq org-agenda-current-span 'day)
  2070. :keys "v d (or just d)"]
  2071. ["Week View" org-agenda-week-view
  2072. :active (org-agenda-check-type nil 'agenda)
  2073. :style radio :selected (eq org-agenda-current-span 'week)
  2074. :keys "v w"]
  2075. ["Fortnight View" org-agenda-fortnight-view
  2076. :active (org-agenda-check-type nil 'agenda)
  2077. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2078. :keys "v f"]
  2079. ["Month View" org-agenda-month-view
  2080. :active (org-agenda-check-type nil 'agenda)
  2081. :style radio :selected (eq org-agenda-current-span 'month)
  2082. :keys "v m"]
  2083. ["Year View" org-agenda-year-view
  2084. :active (org-agenda-check-type nil 'agenda)
  2085. :style radio :selected (eq org-agenda-current-span 'year)
  2086. :keys "v y"]
  2087. "--"
  2088. ["Include Diary" org-agenda-toggle-diary
  2089. :style toggle :selected org-agenda-include-diary
  2090. :active (org-agenda-check-type nil 'agenda)]
  2091. ["Include Deadlines" org-agenda-toggle-deadlines
  2092. :style toggle :selected org-agenda-include-deadlines
  2093. :active (org-agenda-check-type nil 'agenda)]
  2094. ["Use Time Grid" org-agenda-toggle-time-grid
  2095. :style toggle :selected org-agenda-use-time-grid
  2096. :active (org-agenda-check-type nil 'agenda)]
  2097. "--"
  2098. ["Show clock report" org-agenda-clockreport-mode
  2099. :style toggle :selected org-agenda-clockreport-mode
  2100. :active (org-agenda-check-type nil 'agenda)]
  2101. ["Show some entry text" org-agenda-entry-text-mode
  2102. :style toggle :selected org-agenda-entry-text-mode
  2103. :active t]
  2104. "--"
  2105. ["Show Logbook entries" org-agenda-log-mode
  2106. :style toggle :selected org-agenda-show-log
  2107. :active (org-agenda-check-type nil 'agenda 'timeline)
  2108. :keys "v l (or just l)"]
  2109. ["Include archived trees" org-agenda-archives-mode
  2110. :style toggle :selected org-agenda-archives-mode :active t
  2111. :keys "v a"]
  2112. ["Include archive files" (org-agenda-archives-mode t)
  2113. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2114. :keys "v A"]
  2115. "--"
  2116. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2117. ["Write view to file" org-agenda-write t]
  2118. ["Rebuild buffer" org-agenda-redo t]
  2119. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2120. "--"
  2121. ["Show original entry" org-agenda-show t]
  2122. ["Go To (other window)" org-agenda-goto t]
  2123. ["Go To (this window)" org-agenda-switch-to t]
  2124. ["Capture with cursor date" org-agenda-capture t]
  2125. ["Follow Mode" org-agenda-follow-mode
  2126. :style toggle :selected org-agenda-follow-mode :active t]
  2127. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2128. "--"
  2129. ("TODO"
  2130. ["Cycle TODO" org-agenda-todo t]
  2131. ["Next TODO set" org-agenda-todo-nextset t]
  2132. ["Previous TODO set" org-agenda-todo-previousset t]
  2133. ["Add note" org-agenda-add-note t])
  2134. ("Archive/Refile/Delete"
  2135. ["Archive default" org-agenda-archive-default t]
  2136. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2137. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2138. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2139. ["Archive subtree" org-agenda-archive t]
  2140. "--"
  2141. ["Refile" org-agenda-refile t]
  2142. "--"
  2143. ["Delete subtree" org-agenda-kill t])
  2144. ("Bulk action"
  2145. ["Mark entry" org-agenda-bulk-mark t]
  2146. ["Mark all" org-agenda-bulk-mark-all t]
  2147. ["Unmark entry" org-agenda-bulk-unmark t]
  2148. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2149. ["Toggle mark" org-agenda-bulk-toggle t]
  2150. ["Toggle all" org-agenda-bulk-toggle-all t]
  2151. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2152. ["Act on all marked" org-agenda-bulk-action t]
  2153. "--"
  2154. ("Tags and Properties"
  2155. ["Show all Tags" org-agenda-show-tags t]
  2156. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2157. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2158. "--"
  2159. ["Column View" org-columns t])
  2160. ("Deadline/Schedule"
  2161. ["Schedule" org-agenda-schedule t]
  2162. ["Set Deadline" org-agenda-deadline t]
  2163. "--"
  2164. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2165. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2166. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2167. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2168. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2169. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2170. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2171. ("Clock and Effort"
  2172. ["Clock in" org-agenda-clock-in t]
  2173. ["Clock out" org-agenda-clock-out t]
  2174. ["Clock cancel" org-agenda-clock-cancel t]
  2175. ["Goto running clock" org-clock-goto t]
  2176. "--"
  2177. ["Set Effort" org-agenda-set-effort t]
  2178. ["Change clocked effort" org-clock-modify-effort-estimate
  2179. (org-clock-is-active)])
  2180. ("Priority"
  2181. ["Set Priority" org-agenda-priority t]
  2182. ["Increase Priority" org-agenda-priority-up t]
  2183. ["Decrease Priority" org-agenda-priority-down t]
  2184. ["Show Priority" org-show-priority t])
  2185. ("Calendar/Diary"
  2186. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2189. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2190. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2191. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2192. "--"
  2193. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2194. "--"
  2195. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2196. "--"
  2197. ("MobileOrg"
  2198. ["Push Files and Views" org-mobile-push t]
  2199. ["Get Captured and Flagged" org-mobile-pull t]
  2200. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2201. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2202. "--"
  2203. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2204. "--"
  2205. ["Quit" org-agenda-quit t]
  2206. ["Exit and Release Buffers" org-agenda-exit t]
  2207. ))
  2208. ;;; Agenda undo
  2209. (defvar org-agenda-allow-remote-undo t
  2210. "Non-nil means allow remote undo from the agenda buffer.")
  2211. (defvar org-agenda-undo-has-started-in nil
  2212. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2213. (defun org-agenda-undo ()
  2214. "Undo a remote editing step in the agenda.
  2215. This undoes changes both in the agenda buffer and in the remote buffer
  2216. that have been changed along."
  2217. (interactive)
  2218. (or org-agenda-allow-remote-undo
  2219. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2220. (if (not (eq this-command last-command))
  2221. (setq org-agenda-undo-has-started-in nil
  2222. org-agenda-pending-undo-list org-agenda-undo-list))
  2223. (if (not org-agenda-pending-undo-list)
  2224. (user-error "No further undo information"))
  2225. (let* ((entry (pop org-agenda-pending-undo-list))
  2226. buf line cmd rembuf)
  2227. (setq cmd (pop entry) line (pop entry))
  2228. (setq rembuf (nth 2 entry))
  2229. (org-with-remote-undo rembuf
  2230. (while (bufferp (setq buf (pop entry)))
  2231. (if (pop entry)
  2232. (with-current-buffer buf
  2233. (let ((last-undo-buffer buf)
  2234. (inhibit-read-only t))
  2235. (unless (memq buf org-agenda-undo-has-started-in)
  2236. (push buf org-agenda-undo-has-started-in)
  2237. (make-local-variable 'pending-undo-list)
  2238. (undo-start))
  2239. (while (and pending-undo-list
  2240. (listp pending-undo-list)
  2241. (not (car pending-undo-list)))
  2242. (pop pending-undo-list))
  2243. (undo-more 1))))))
  2244. (org-goto-line line)
  2245. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2246. (defun org-verify-change-for-undo (l1 l2)
  2247. "Verify that a real change occurred between the undo lists L1 and L2."
  2248. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2249. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2250. (not (eq l1 l2)))
  2251. ;;; Agenda dispatch
  2252. (defvar org-agenda-restrict-begin (make-marker))
  2253. (defvar org-agenda-restrict-end (make-marker))
  2254. (defvar org-agenda-last-dispatch-buffer nil)
  2255. (defvar org-agenda-overriding-restriction nil)
  2256. (defcustom org-agenda-custom-commands-contexts nil
  2257. "Alist of custom agenda keys and contextual rules.
  2258. For example, if you have a custom agenda command \"p\" and you
  2259. want this command to be accessible only from plain text files,
  2260. use this:
  2261. '((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2262. Here are the available contexts definitions:
  2263. in-file: command displayed only in matching files
  2264. in-mode: command displayed only in matching modes
  2265. not-in-file: command not displayed in matching files
  2266. not-in-mode: command not displayed in matching modes
  2267. in-buffer: command displayed only in matching buffers
  2268. not-in-buffer: command not displayed in matching buffers
  2269. [function]: a custom function taking no argument
  2270. If you define several checks, the agenda command will be
  2271. accessible if there is at least one valid check.
  2272. You can also bind a key to another agenda custom command
  2273. depending on contextual rules.
  2274. '((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2275. Here it means: in .txt files, use \"p\" as the key for the
  2276. agenda command otherwise associated with \"q\". (The command
  2277. originally associated with \"q\" is not displayed to avoid
  2278. duplicates.)"
  2279. :version "24.3"
  2280. :group 'org-agenda-custom-commands
  2281. :type '(repeat (list :tag "Rule"
  2282. (string :tag " Agenda key")
  2283. (string :tag "Replace by command")
  2284. (repeat :tag "Available when"
  2285. (choice
  2286. (cons :tag "Condition"
  2287. (choice
  2288. (const :tag "In file" in-file)
  2289. (const :tag "Not in file" not-in-file)
  2290. (const :tag "In buffer" in-buffer)
  2291. (const :tag "Not in buffer" not-in-buffer)
  2292. (const :tag "In mode" in-mode)
  2293. (const :tag "Not in mode" not-in-mode))
  2294. (regexp))
  2295. (function :tag "Custom function"))))))
  2296. (defcustom org-agenda-max-entries nil
  2297. "Maximum number of entries to display in an agenda.
  2298. This can be nil (no limit) or an integer or an alist of agenda
  2299. types with an associated number of entries to display in this
  2300. type."
  2301. :version "24.4"
  2302. :package-version '(Org . "8.0")
  2303. :group 'org-agenda-custom-commands
  2304. :type '(choice (symbol :tag "No limit" nil)
  2305. (integer :tag "Max number of entries")
  2306. (repeat
  2307. (cons (choice :tag "Agenda type"
  2308. (const agenda)
  2309. (const todo)
  2310. (const tags)
  2311. (const search)
  2312. (const timeline))
  2313. (integer :tag "Max number of entries")))))
  2314. (defcustom org-agenda-max-todos nil
  2315. "Maximum number of TODOs to display in an agenda.
  2316. This can be nil (no limit) or an integer or an alist of agenda
  2317. types with an associated number of entries to display in this
  2318. type."
  2319. :version "24.4"
  2320. :package-version '(Org . "8.0")
  2321. :group 'org-agenda-custom-commands
  2322. :type '(choice (symbol :tag "No limit" nil)
  2323. (integer :tag "Max number of TODOs")
  2324. (repeat
  2325. (cons (choice :tag "Agenda type"
  2326. (const agenda)
  2327. (const todo)
  2328. (const tags)
  2329. (const search)
  2330. (const timeline))
  2331. (integer :tag "Max number of TODOs")))))
  2332. (defcustom org-agenda-max-tags nil
  2333. "Maximum number of tagged entries to display in an agenda.
  2334. This can be nil (no limit) or an integer or an alist of agenda
  2335. types with an associated number of entries to display in this
  2336. type."
  2337. :version "24.4"
  2338. :package-version '(Org . "8.0")
  2339. :group 'org-agenda-custom-commands
  2340. :type '(choice (symbol :tag "No limit" nil)
  2341. (integer :tag "Max number of tagged entries")
  2342. (repeat
  2343. (cons (choice :tag "Agenda type"
  2344. (const agenda)
  2345. (const todo)
  2346. (const tags)
  2347. (const search)
  2348. (const timeline))
  2349. (integer :tag "Max number of tagged entries")))))
  2350. (defcustom org-agenda-max-effort nil
  2351. "Maximum cumulated effort duration for the agenda.
  2352. This can be nil (no limit) or a number of minutes (as an integer)
  2353. or an alist of agenda types with an associated number of minutes
  2354. to limit entries to in this type."
  2355. :version "24.4"
  2356. :package-version '(Org . "8.0")
  2357. :group 'org-agenda-custom-commands
  2358. :type '(choice (symbol :tag "No limit" nil)
  2359. (integer :tag "Max number of minutes")
  2360. (repeat
  2361. (cons (choice :tag "Agenda type"
  2362. (const agenda)
  2363. (const todo)
  2364. (const tags)
  2365. (const search)
  2366. (const timeline))
  2367. (integer :tag "Max number of minutes")))))
  2368. (defvar org-keys nil)
  2369. (defvar org-match nil)
  2370. ;;;###autoload
  2371. (defun org-agenda (&optional arg org-keys restriction)
  2372. "Dispatch agenda commands to collect entries to the agenda buffer.
  2373. Prompts for a command to execute. Any prefix arg will be passed
  2374. on to the selected command. The default selections are:
  2375. a Call `org-agenda-list' to display the agenda for current day or week.
  2376. t Call `org-todo-list' to display the global todo list.
  2377. T Call `org-todo-list' to display the global todo list, select only
  2378. entries with a specific TODO keyword (the user gets a prompt).
  2379. m Call `org-tags-view' to display headlines with tags matching
  2380. a condition (the user is prompted for the condition).
  2381. M Like `m', but select only TODO entries, no ordinary headlines.
  2382. L Create a timeline for the current buffer.
  2383. e Export views to associated files.
  2384. s Search entries for keywords.
  2385. S Search entries for keywords, only with TODO keywords.
  2386. / Multi occur across all agenda files and also files listed
  2387. in `org-agenda-text-search-extra-files'.
  2388. < Restrict agenda commands to buffer, subtree, or region.
  2389. Press several times to get the desired effect.
  2390. > Remove a previous restriction.
  2391. # List \"stuck\" projects.
  2392. ! Configure what \"stuck\" means.
  2393. C Configure custom agenda commands.
  2394. More commands can be added by configuring the variable
  2395. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2396. searches can be pre-defined in this way.
  2397. If the current buffer is in Org-mode and visiting a file, you can also
  2398. first press `<' once to indicate that the agenda should be temporarily
  2399. \(until the next use of \\[org-agenda]) restricted to the current file.
  2400. Pressing `<' twice means to restrict to the current subtree or region
  2401. \(if active)."
  2402. (interactive "P")
  2403. (catch 'exit
  2404. (let* ((prefix-descriptions nil)
  2405. (org-agenda-buffer-name org-agenda-buffer-name)
  2406. (org-agenda-window-setup (if (equal (buffer-name)
  2407. org-agenda-buffer-name)
  2408. 'current-window
  2409. org-agenda-window-setup))
  2410. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2411. (org-agenda-custom-commands
  2412. ;; normalize different versions
  2413. (delq nil
  2414. (mapcar
  2415. (lambda (x)
  2416. (cond ((stringp (cdr x))
  2417. (push x prefix-descriptions)
  2418. nil)
  2419. ((stringp (nth 1 x)) x)
  2420. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2421. (t (cons (car x) (cons "" (cdr x))))))
  2422. org-agenda-custom-commands)))
  2423. (org-agenda-custom-commands
  2424. (org-contextualize-keys
  2425. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2426. (buf (current-buffer))
  2427. (bfn (buffer-file-name (buffer-base-buffer)))
  2428. entry key type org-match lprops ans)
  2429. ;; Turn off restriction unless there is an overriding one,
  2430. (unless org-agenda-overriding-restriction
  2431. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2432. ;; There is a request to keep the file list in place
  2433. (put 'org-agenda-files 'org-restrict nil))
  2434. (setq org-agenda-restrict nil)
  2435. (move-marker org-agenda-restrict-begin nil)
  2436. (move-marker org-agenda-restrict-end nil))
  2437. ;; Delete old local properties
  2438. (put 'org-agenda-redo-command 'org-lprops nil)
  2439. ;; Delete previously set last-arguments
  2440. (put 'org-agenda-redo-command 'last-args nil)
  2441. ;; Remember where this call originated
  2442. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2443. (unless org-keys
  2444. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2445. org-keys (car ans)
  2446. restriction (cdr ans)))
  2447. ;; If we have sticky agenda buffers, set a name for the buffer,
  2448. ;; depending on the invoking keys. The user may still set this
  2449. ;; as a command option, which will overwrite what we do here.
  2450. (if org-agenda-sticky
  2451. (setq org-agenda-buffer-name
  2452. (format "*Org Agenda(%s)*" org-keys)))
  2453. ;; Establish the restriction, if any
  2454. (when (and (not org-agenda-overriding-restriction) restriction)
  2455. (put 'org-agenda-files 'org-restrict (list bfn))
  2456. (cond
  2457. ((eq restriction 'region)
  2458. (setq org-agenda-restrict (current-buffer))
  2459. (move-marker org-agenda-restrict-begin (region-beginning))
  2460. (move-marker org-agenda-restrict-end (region-end)))
  2461. ((eq restriction 'subtree)
  2462. (save-excursion
  2463. (setq org-agenda-restrict (current-buffer))
  2464. (org-back-to-heading t)
  2465. (move-marker org-agenda-restrict-begin (point))
  2466. (move-marker org-agenda-restrict-end
  2467. (progn (org-end-of-subtree t)))))))
  2468. ;; For example the todo list should not need it (but does...)
  2469. (cond
  2470. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2471. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2472. (progn
  2473. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2474. lprops (nth 4 entry))
  2475. (if org-agenda-sticky
  2476. (setq org-agenda-buffer-name
  2477. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2478. (format "*Org Agenda(%s)*" org-keys))))
  2479. (put 'org-agenda-redo-command 'org-lprops lprops)
  2480. (cond
  2481. ((eq type 'agenda)
  2482. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2483. ((eq type 'agenda*)
  2484. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2485. ((eq type 'alltodo)
  2486. (org-let lprops '(org-todo-list current-prefix-arg)))
  2487. ((eq type 'search)
  2488. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2489. ((eq type 'stuck)
  2490. (org-let lprops '(org-agenda-list-stuck-projects
  2491. current-prefix-arg)))
  2492. ((eq type 'tags)
  2493. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2494. ((eq type 'tags-todo)
  2495. (org-let lprops '(org-tags-view '(4) org-match)))
  2496. ((eq type 'todo)
  2497. (org-let lprops '(org-todo-list org-match)))
  2498. ((eq type 'tags-tree)
  2499. (org-check-for-org-mode)
  2500. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2501. ((eq type 'todo-tree)
  2502. (org-check-for-org-mode)
  2503. (org-let lprops
  2504. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2505. (regexp-quote org-match) "\\>"))))
  2506. ((eq type 'occur-tree)
  2507. (org-check-for-org-mode)
  2508. (org-let lprops '(org-occur org-match)))
  2509. ((functionp type)
  2510. (org-let lprops '(funcall type org-match)))
  2511. ((fboundp type)
  2512. (org-let lprops '(funcall type org-match)))
  2513. (t (user-error "Invalid custom agenda command type %s" type))))
  2514. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2515. ((equal org-keys "C")
  2516. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2517. (customize-variable 'org-agenda-custom-commands))
  2518. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2519. ((equal org-keys "s") (call-interactively 'org-search-view))
  2520. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2521. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2522. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2523. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2524. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2525. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2526. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2527. (org-add-hook
  2528. 'post-command-hook
  2529. (lambda ()
  2530. (unless (current-message)
  2531. (let* ((m (org-agenda-get-any-marker))
  2532. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2533. (when note
  2534. (message (concat
  2535. "FLAGGING-NOTE ([?] for more info): "
  2536. (org-add-props
  2537. (replace-regexp-in-string
  2538. "\\\\n" "//"
  2539. (copy-sequence note))
  2540. nil 'face 'org-warning)))))))
  2541. t t))
  2542. ((equal org-keys "L")
  2543. (unless (derived-mode-p 'org-mode)
  2544. (user-error "This is not an Org-mode file"))
  2545. (unless restriction
  2546. (put 'org-agenda-files 'org-restrict (list bfn))
  2547. (org-call-with-arg 'org-timeline arg)))
  2548. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2549. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2550. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2551. (t (user-error "Invalid agenda key"))))))
  2552. (defvar org-agenda-multi)
  2553. (defun org-agenda-append-agenda ()
  2554. "Append another agenda view to the current one.
  2555. This function allows interactive building of block agendas.
  2556. Agenda views are separated by `org-agenda-block-separator'."
  2557. (interactive)
  2558. (unless (derived-mode-p 'org-agenda-mode)
  2559. (user-error "Can only append from within agenda buffer"))
  2560. (let ((org-agenda-multi t))
  2561. (org-agenda)
  2562. (widen)
  2563. (org-agenda-finalize)
  2564. (setq buffer-read-only t)
  2565. (org-agenda-fit-window-to-buffer)))
  2566. (defun org-agenda-normalize-custom-commands (cmds)
  2567. "Normalize custom commands CMDS."
  2568. (delq nil
  2569. (mapcar
  2570. (lambda (x)
  2571. (cond ((stringp (cdr x)) nil)
  2572. ((stringp (nth 1 x)) x)
  2573. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2574. (t (cons (car x) (cons "" (cdr x))))))
  2575. cmds)))
  2576. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2577. "The user interface for selecting an agenda command."
  2578. (catch 'exit
  2579. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2580. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2581. (region-p (org-region-active-p))
  2582. (custom org-agenda-custom-commands)
  2583. (selstring "")
  2584. restriction second-time
  2585. c entry key type match prefixes rmheader header-end custom1 desc
  2586. line lines left right n n1)
  2587. (save-window-excursion
  2588. (delete-other-windows)
  2589. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2590. (erase-buffer)
  2591. (insert (eval-when-compile
  2592. (let ((header
  2593. "Press key for an agenda command: < Buffer, subtree/region restriction
  2594. -------------------------------- > Remove restriction
  2595. a Agenda for current week or day e Export agenda views
  2596. t List of all TODO entries T Entries with special TODO kwd
  2597. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2598. s Search for keywords S Like s, but only TODO entries
  2599. L Timeline for current buffer # List stuck projects (!=configure)
  2600. / Multi-occur C Configure custom agenda commands
  2601. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2602. ")
  2603. (start 0))
  2604. (while (string-match
  2605. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2606. header start)
  2607. (setq start (match-end 0))
  2608. (add-text-properties (match-beginning 2) (match-end 2)
  2609. '(face bold) header))
  2610. header)))
  2611. (setq header-end (point-marker))
  2612. (while t
  2613. (setq custom1 custom)
  2614. (when (eq rmheader t)
  2615. (org-goto-line 1)
  2616. (re-search-forward ":" nil t)
  2617. (delete-region (match-end 0) (point-at-eol))
  2618. (forward-char 1)
  2619. (looking-at "-+")
  2620. (delete-region (match-end 0) (point-at-eol))
  2621. (move-marker header-end (match-end 0)))
  2622. (goto-char header-end)
  2623. (delete-region (point) (point-max))
  2624. ;; Produce all the lines that describe custom commands and prefixes
  2625. (setq lines nil)
  2626. (while (setq entry (pop custom1))
  2627. (setq key (car entry) desc (nth 1 entry)
  2628. type (nth 2 entry)
  2629. match (nth 3 entry))
  2630. (if (> (length key) 1)
  2631. (add-to-list 'prefixes (string-to-char key))
  2632. (setq line
  2633. (format
  2634. "%-4s%-14s"
  2635. (org-add-props (copy-sequence key)
  2636. '(face bold))
  2637. (cond
  2638. ((string-match "\\S-" desc) desc)
  2639. ((eq type 'agenda) "Agenda for current week or day")
  2640. ((eq type 'agenda*) "Appointments for current week or day")
  2641. ((eq type 'alltodo) "List of all TODO entries")
  2642. ((eq type 'search) "Word search")
  2643. ((eq type 'stuck) "List of stuck projects")
  2644. ((eq type 'todo) "TODO keyword")
  2645. ((eq type 'tags) "Tags query")
  2646. ((eq type 'tags-todo) "Tags (TODO)")
  2647. ((eq type 'tags-tree) "Tags tree")
  2648. ((eq type 'todo-tree) "TODO kwd tree")
  2649. ((eq type 'occur-tree) "Occur tree")
  2650. ((functionp type) (if (symbolp type)
  2651. (symbol-name type)
  2652. "Lambda expression"))
  2653. (t "???"))))
  2654. (if org-agenda-menu-show-matcher
  2655. (setq line
  2656. (concat line ": "
  2657. (cond
  2658. ((stringp match)
  2659. (setq match (copy-sequence match))
  2660. (org-add-props match nil 'face 'org-warning))
  2661. ((listp type)
  2662. (format "set of %d commands" (length type))))))
  2663. (if (org-string-nw-p match)
  2664. (add-text-properties
  2665. 0 (length line) (list 'help-echo
  2666. (concat "Matcher: " match)) line)))
  2667. (push line lines)))
  2668. (setq lines (nreverse lines))
  2669. (when prefixes
  2670. (mapc (lambda (x)
  2671. (push
  2672. (format "%s %s"
  2673. (org-add-props (char-to-string x)
  2674. nil 'face 'bold)
  2675. (or (cdr (assoc (concat selstring
  2676. (char-to-string x))
  2677. prefix-descriptions))
  2678. "Prefix key"))
  2679. lines))
  2680. prefixes))
  2681. ;; Check if we should display in two columns
  2682. (if org-agenda-menu-two-columns
  2683. (progn
  2684. (setq n (length lines)
  2685. n1 (+ (/ n 2) (mod n 2))
  2686. right (nthcdr n1 lines)
  2687. left (copy-sequence lines))
  2688. (setcdr (nthcdr (1- n1) left) nil))
  2689. (setq left lines right nil))
  2690. (while left
  2691. (insert "\n" (pop left))
  2692. (when right
  2693. (if (< (current-column) 40)
  2694. (move-to-column 40 t)
  2695. (insert " "))
  2696. (insert (pop right))))
  2697. ;; Make the window the right size
  2698. (goto-char (point-min))
  2699. (if second-time
  2700. (if (not (pos-visible-in-window-p (point-max)))
  2701. (org-fit-window-to-buffer))
  2702. (setq second-time t)
  2703. (org-fit-window-to-buffer))
  2704. ;; Ask for selection
  2705. (message "Press key for agenda command%s:"
  2706. (if (or restrict-ok org-agenda-overriding-restriction)
  2707. (if org-agenda-overriding-restriction
  2708. " (restriction lock active)"
  2709. (if restriction
  2710. (format " (restricted to %s)" restriction)
  2711. " (unrestricted)"))
  2712. ""))
  2713. (setq c (read-char-exclusive))
  2714. (message "")
  2715. (cond
  2716. ((assoc (char-to-string c) custom)
  2717. (setq selstring (concat selstring (char-to-string c)))
  2718. (throw 'exit (cons selstring restriction)))
  2719. ((memq c prefixes)
  2720. (setq selstring (concat selstring (char-to-string c))
  2721. prefixes nil
  2722. rmheader (or rmheader t)
  2723. custom (delq nil (mapcar
  2724. (lambda (x)
  2725. (if (or (= (length (car x)) 1)
  2726. (/= (string-to-char (car x)) c))
  2727. nil
  2728. (cons (substring (car x) 1) (cdr x))))
  2729. custom))))
  2730. ((eq c ?*)
  2731. (call-interactively 'org-toggle-sticky-agenda)
  2732. (sit-for 2))
  2733. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2734. (message "Restriction is only possible in Org-mode buffers")
  2735. (ding) (sit-for 1))
  2736. ((eq c ?1)
  2737. (org-agenda-remove-restriction-lock 'noupdate)
  2738. (setq restriction 'buffer))
  2739. ((eq c ?0)
  2740. (org-agenda-remove-restriction-lock 'noupdate)
  2741. (setq restriction (if region-p 'region 'subtree)))
  2742. ((eq c ?<)
  2743. (org-agenda-remove-restriction-lock 'noupdate)
  2744. (setq restriction
  2745. (cond
  2746. ((eq restriction 'buffer)
  2747. (if region-p 'region 'subtree))
  2748. ((memq restriction '(subtree region))
  2749. nil)
  2750. (t 'buffer))))
  2751. ((eq c ?>)
  2752. (org-agenda-remove-restriction-lock 'noupdate)
  2753. (setq restriction nil))
  2754. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2755. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2756. ((and (> (length selstring) 0) (eq c ?\d))
  2757. (delete-window)
  2758. (org-agenda-get-restriction-and-command prefix-descriptions))
  2759. ((equal c ?q) (error "Abort"))
  2760. (t (user-error "Invalid key %c" c))))))))
  2761. (defun org-agenda-fit-window-to-buffer ()
  2762. "Fit the window to the buffer size."
  2763. (and (memq org-agenda-window-setup '(reorganize-frame))
  2764. (fboundp 'fit-window-to-buffer)
  2765. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2766. (= (car org-agenda-window-frame-fractions) 1.0))
  2767. (delete-other-windows)
  2768. (org-fit-window-to-buffer
  2769. nil
  2770. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2771. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2772. (defvar org-cmd nil)
  2773. (defvar org-agenda-overriding-cmd nil)
  2774. (defvar org-agenda-overriding-arguments nil)
  2775. (defvar org-agenda-overriding-cmd-arguments nil)
  2776. (defun org-agenda-run-series (name series)
  2777. "Run agenda NAME as a SERIES of agenda commands."
  2778. (org-let (nth 1 series) '(org-agenda-prepare name))
  2779. ;; We need to reset agenda markers here, because when constructing a
  2780. ;; block agenda, the individual blocks do not do that.
  2781. (org-agenda-reset-markers)
  2782. (let* ((org-agenda-multi t)
  2783. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2784. (cmds (car series))
  2785. (gprops (nth 1 series))
  2786. match ;; The byte compiler incorrectly complains about this. Keep it!
  2787. org-cmd type lprops)
  2788. (while (setq org-cmd (pop cmds))
  2789. (setq type (car org-cmd)
  2790. match (eval (nth 1 org-cmd))
  2791. lprops (nth 2 org-cmd))
  2792. (let ((org-agenda-overriding-arguments
  2793. (if (eq org-agenda-overriding-cmd org-cmd)
  2794. (or org-agenda-overriding-arguments
  2795. org-agenda-overriding-cmd-arguments))))
  2796. (cond
  2797. ((eq type 'agenda)
  2798. (org-let2 gprops lprops
  2799. '(call-interactively 'org-agenda-list)))
  2800. ((eq type 'agenda*)
  2801. (org-let2 gprops lprops
  2802. '(funcall 'org-agenda-list nil nil t)))
  2803. ((eq type 'alltodo)
  2804. (org-let2 gprops lprops
  2805. '(call-interactively 'org-todo-list)))
  2806. ((eq type 'search)
  2807. (org-let2 gprops lprops
  2808. '(org-search-view current-prefix-arg match nil)))
  2809. ((eq type 'stuck)
  2810. (org-let2 gprops lprops
  2811. '(call-interactively 'org-agenda-list-stuck-projects)))
  2812. ((eq type 'tags)
  2813. (org-let2 gprops lprops
  2814. '(org-tags-view current-prefix-arg match)))
  2815. ((eq type 'tags-todo)
  2816. (org-let2 gprops lprops
  2817. '(org-tags-view '(4) match)))
  2818. ((eq type 'todo)
  2819. (org-let2 gprops lprops
  2820. '(org-todo-list match)))
  2821. ((fboundp type)
  2822. (org-let2 gprops lprops
  2823. '(funcall type match)))
  2824. (t (error "Invalid type in command series")))))
  2825. (widen)
  2826. (let ((inhibit-read-only t))
  2827. (add-text-properties (point-min) (point-max)
  2828. `(org-series t org-series-redo-cmd ,redo)))
  2829. (setq org-agenda-redo-command redo)
  2830. (goto-char (point-min)))
  2831. (org-agenda-fit-window-to-buffer)
  2832. (org-let (nth 1 series) '(org-agenda-finalize)))
  2833. ;;;###autoload
  2834. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2835. "Run an agenda command in batch mode and send the result to STDOUT.
  2836. If CMD-KEY is a string of length 1, it is used as a key in
  2837. `org-agenda-custom-commands' and triggers this command. If it is a
  2838. longer string it is used as a tags/todo match string.
  2839. Parameters are alternating variable names and values that will be bound
  2840. before running the agenda command."
  2841. (org-eval-in-environment (org-make-parameter-alist parameters)
  2842. (let (org-agenda-sticky)
  2843. (if (> (length cmd-key) 2)
  2844. (org-tags-view nil cmd-key)
  2845. (org-agenda nil cmd-key))))
  2846. (set-buffer org-agenda-buffer-name)
  2847. (princ (buffer-string)))
  2848. (defvar org-agenda-info nil)
  2849. ;;;###autoload
  2850. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2851. "Run an agenda command in batch mode and send the result to STDOUT.
  2852. If CMD-KEY is a string of length 1, it is used as a key in
  2853. `org-agenda-custom-commands' and triggers this command. If it is a
  2854. longer string it is used as a tags/todo match string.
  2855. Parameters are alternating variable names and values that will be bound
  2856. before running the agenda command.
  2857. The output gives a line for each selected agenda item. Each
  2858. item is a list of comma-separated values, like this:
  2859. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2860. category The category of the item
  2861. head The headline, without TODO kwd, TAGS and PRIORITY
  2862. type The type of the agenda entry, can be
  2863. todo selected in TODO match
  2864. tagsmatch selected in tags match
  2865. diary imported from diary
  2866. deadline a deadline on given date
  2867. scheduled scheduled on given date
  2868. timestamp entry has timestamp on given date
  2869. closed entry was closed on given date
  2870. upcoming-deadline warning about deadline
  2871. past-scheduled forwarded scheduled item
  2872. block entry has date block including g. date
  2873. todo The todo keyword, if any
  2874. tags All tags including inherited ones, separated by colons
  2875. date The relevant date, like 2007-2-14
  2876. time The time, like 15:00-16:50
  2877. extra Sting with extra planning info
  2878. priority-l The priority letter if any was given
  2879. priority-n The computed numerical priority
  2880. agenda-day The day in the agenda where this is listed"
  2881. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2882. (org-make-parameter-alist parameters))
  2883. (if (> (length cmd-key) 2)
  2884. (org-tags-view nil cmd-key)
  2885. (org-agenda nil cmd-key)))
  2886. (set-buffer org-agenda-buffer-name)
  2887. (let* ((lines (org-split-string (buffer-string) "\n"))
  2888. line)
  2889. (while (setq line (pop lines))
  2890. (catch 'next
  2891. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2892. (setq org-agenda-info
  2893. (org-fix-agenda-info (text-properties-at 0 line)))
  2894. (princ
  2895. (mapconcat 'org-agenda-export-csv-mapper
  2896. '(org-category txt type todo tags date time extra
  2897. priority-letter priority agenda-day)
  2898. ","))
  2899. (princ "\n")))))
  2900. (defun org-fix-agenda-info (props)
  2901. "Make sure all properties on an agenda item have a canonical form.
  2902. This ensures the export commands can easily use it."
  2903. (let (tmp re)
  2904. (when (setq tmp (plist-get props 'tags))
  2905. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2906. (when (setq tmp (plist-get props 'date))
  2907. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2908. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2909. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2910. (setq tmp (calendar-date-string tmp)))
  2911. (setq props (plist-put props 'date tmp)))
  2912. (when (setq tmp (plist-get props 'day))
  2913. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2914. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2915. (setq tmp (calendar-date-string tmp)))
  2916. (setq props (plist-put props 'day tmp))
  2917. (setq props (plist-put props 'agenda-day tmp)))
  2918. (when (setq tmp (plist-get props 'txt))
  2919. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2920. (plist-put props 'priority-letter (match-string 1 tmp))
  2921. (setq tmp (replace-match "" t t tmp)))
  2922. (when (and (setq re (plist-get props 'org-todo-regexp))
  2923. (setq re (concat "\\`\\.*" re " ?"))
  2924. (string-match re tmp))
  2925. (plist-put props 'todo (match-string 1 tmp))
  2926. (setq tmp (replace-match "" t t tmp)))
  2927. (plist-put props 'txt tmp)))
  2928. props)
  2929. (defun org-agenda-export-csv-mapper (prop)
  2930. (let ((res (plist-get org-agenda-info prop)))
  2931. (setq res
  2932. (cond
  2933. ((not res) "")
  2934. ((stringp res) res)
  2935. (t (prin1-to-string res))))
  2936. (while (string-match "," res)
  2937. (setq res (replace-match ";" t t res)))
  2938. (org-trim res)))
  2939. ;;;###autoload
  2940. (defun org-store-agenda-views (&rest parameters)
  2941. "Store agenda views."
  2942. (interactive)
  2943. (eval (list 'org-batch-store-agenda-views)))
  2944. ;;;###autoload
  2945. (defmacro org-batch-store-agenda-views (&rest parameters)
  2946. "Run all custom agenda commands that have a file argument."
  2947. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2948. (pop-up-frames nil)
  2949. (dir default-directory)
  2950. (pars (org-make-parameter-alist parameters))
  2951. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2952. (save-window-excursion
  2953. (while cmds
  2954. (setq cmd (pop cmds)
  2955. thiscmdkey (car cmd)
  2956. thiscmdcmd (cdr cmd)
  2957. match (nth 2 thiscmdcmd)
  2958. bufname (if org-agenda-sticky
  2959. (or (and (stringp match)
  2960. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2961. (format "*Org Agenda(%s)*" thiscmdkey))
  2962. org-agenda-buffer-name)
  2963. cmd-or-set (nth 2 cmd)
  2964. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2965. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2966. (if (stringp files) (setq files (list files)))
  2967. (when files
  2968. (org-eval-in-environment (append org-agenda-exporter-settings
  2969. opts pars)
  2970. (org-agenda nil thiscmdkey))
  2971. (set-buffer bufname)
  2972. (while files
  2973. (org-eval-in-environment (append org-agenda-exporter-settings
  2974. opts pars)
  2975. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2976. (and (get-buffer bufname)
  2977. (kill-buffer bufname)))))))
  2978. (defvar org-agenda-current-span nil
  2979. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2980. (defun org-agenda-mark-header-line (pos)
  2981. "Mark the line at POS as an agenda structure header."
  2982. (save-excursion
  2983. (goto-char pos)
  2984. (put-text-property (point-at-bol) (point-at-eol)
  2985. 'org-agenda-structural-header t)
  2986. (when org-agenda-title-append
  2987. (put-text-property (point-at-bol) (point-at-eol)
  2988. 'org-agenda-title-append org-agenda-title-append))))
  2989. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2990. (defvar org-agenda-write-buffer-name "Agenda View")
  2991. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2992. "Write the current buffer (an agenda view) as a file.
  2993. Depending on the extension of the file name, plain text (.txt),
  2994. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2995. If the extension is .ics, run icalendar export over all files used
  2996. to construct the agenda and limit the export to entries listed in the
  2997. agenda now.
  2998. If the extension is .org, collect all subtrees corresponding to the
  2999. agenda entries and add them in an .org file.
  3000. With prefix argument OPEN, open the new file immediately.
  3001. If NOSETTINGS is given, do not scope the settings of
  3002. `org-agenda-exporter-settings' into the export commands. This is used when
  3003. the settings have already been scoped and we do not wish to overrule other,
  3004. higher priority settings.
  3005. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3006. (interactive "FWrite agenda to file: \nP")
  3007. (if (or (not (file-writable-p file))
  3008. (and (file-exists-p file)
  3009. (if (org-called-interactively-p 'any)
  3010. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3011. (user-error "Cannot write agenda to file %s" file))
  3012. (org-let (if nosettings nil org-agenda-exporter-settings)
  3013. '(save-excursion
  3014. (save-window-excursion
  3015. (org-agenda-mark-filtered-text)
  3016. (let ((bs (copy-sequence (buffer-string))) beg content)
  3017. (org-agenda-unmark-filtered-text)
  3018. (with-temp-buffer
  3019. (rename-buffer org-agenda-write-buffer-name t)
  3020. (set-buffer-modified-p nil)
  3021. (insert bs)
  3022. (org-agenda-remove-marked-text 'org-filtered)
  3023. (while (setq beg (text-property-any (point-min) (point-max)
  3024. 'org-filtered t))
  3025. (delete-region
  3026. beg (or (next-single-property-change beg 'org-filtered)
  3027. (point-max))))
  3028. (run-hooks 'org-agenda-before-write-hook)
  3029. (cond
  3030. ((org-bound-and-true-p org-mobile-creating-agendas)
  3031. (org-mobile-write-agenda-for-mobile file))
  3032. ((string-match "\\.org\\'" file)
  3033. (let (content p m message-log-max)
  3034. (goto-char (point-min))
  3035. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3036. (goto-char p)
  3037. (setq m (get-text-property (point) 'org-hd-marker))
  3038. (when m
  3039. (push (save-excursion
  3040. (set-buffer (marker-buffer m))
  3041. (goto-char m)
  3042. (org-copy-subtree 1 nil t t)
  3043. org-subtree-clip)
  3044. content)))
  3045. (find-file file)
  3046. (erase-buffer)
  3047. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3048. (write-file file)
  3049. (kill-buffer (current-buffer))
  3050. (message "Org file written to %s" file)))
  3051. ((string-match "\\.html?\\'" file)
  3052. (require 'htmlize)
  3053. (set-buffer (htmlize-buffer (current-buffer)))
  3054. (when org-agenda-export-html-style
  3055. ;; replace <style> section with org-agenda-export-html-style
  3056. (goto-char (point-min))
  3057. (kill-region (- (search-forward "<style") 6)
  3058. (search-forward "</style>"))
  3059. (insert org-agenda-export-html-style))
  3060. (write-file file)
  3061. (kill-buffer (current-buffer))
  3062. (message "HTML written to %s" file))
  3063. ((string-match "\\.ps\\'" file)
  3064. (require 'ps-print)
  3065. (ps-print-buffer-with-faces file)
  3066. (message "Postscript written to %s" file))
  3067. ((string-match "\\.pdf\\'" file)
  3068. (require 'ps-print)
  3069. (ps-print-buffer-with-faces
  3070. (concat (file-name-sans-extension file) ".ps"))
  3071. (call-process "ps2pdf" nil nil nil
  3072. (expand-file-name
  3073. (concat (file-name-sans-extension file) ".ps"))
  3074. (expand-file-name file))
  3075. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3076. (message "PDF written to %s" file))
  3077. ((string-match "\\.ics\\'" file)
  3078. (require 'ox-icalendar)
  3079. (org-icalendar-export-current-agenda (expand-file-name file)))
  3080. (t
  3081. (let ((bs (buffer-string)))
  3082. (find-file file)
  3083. (erase-buffer)
  3084. (insert bs)
  3085. (save-buffer 0)
  3086. (kill-buffer (current-buffer))
  3087. (message "Plain text written to %s" file))))))))
  3088. (set-buffer (or agenda-bufname
  3089. (and (org-called-interactively-p 'any) (buffer-name))
  3090. org-agenda-buffer-name)))
  3091. (when open (org-open-file file)))
  3092. (defvar org-agenda-tag-filter-overlays nil)
  3093. (defvar org-agenda-cat-filter-overlays nil)
  3094. (defvar org-agenda-re-filter-overlays nil)
  3095. (defun org-agenda-mark-filtered-text ()
  3096. "Mark all text hidden by filtering with a text property."
  3097. (let ((inhibit-read-only t))
  3098. (mapc
  3099. (lambda (o)
  3100. (when (equal (overlay-buffer o) (current-buffer))
  3101. (put-text-property
  3102. (overlay-start o) (overlay-end o)
  3103. 'org-filtered t)))
  3104. (append org-agenda-tag-filter-overlays
  3105. org-agenda-cat-filter-overlays
  3106. org-agenda-re-filter-overlays))))
  3107. (defun org-agenda-unmark-filtered-text ()
  3108. "Remove the filtering text property."
  3109. (let ((inhibit-read-only t))
  3110. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3111. (defun org-agenda-remove-marked-text (property &optional value)
  3112. "Delete all text marked with VALUE of PROPERTY.
  3113. VALUE defaults to t."
  3114. (let (beg)
  3115. (setq value (or value t))
  3116. (while (setq beg (text-property-any (point-min) (point-max)
  3117. property value))
  3118. (delete-region
  3119. beg (or (next-single-property-change beg 'org-filtered)
  3120. (point-max))))))
  3121. (defun org-agenda-add-entry-text ()
  3122. "Add entry text to agenda lines.
  3123. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3124. entry text following headings shown in the agenda.
  3125. Drawers will be excluded, also the line with scheduling/deadline info."
  3126. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3127. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3128. (let (m txt)
  3129. (goto-char (point-min))
  3130. (while (not (eobp))
  3131. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3132. (beginning-of-line 2)
  3133. (setq txt (org-agenda-get-some-entry-text
  3134. m org-agenda-add-entry-text-maxlines " > "))
  3135. (end-of-line 1)
  3136. (if (string-match "\\S-" txt)
  3137. (insert "\n" txt)
  3138. (or (eobp) (forward-char 1))))))))
  3139. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3140. &rest keep)
  3141. "Extract entry text from MARKER, at most N-LINES lines.
  3142. This will ignore drawers etc, just get the text.
  3143. If INDENT is given, prefix every line with this string. If KEEP is
  3144. given, it is a list of symbols, defining stuff that should not be
  3145. removed from the entry content. Currently only `planning' is allowed here."
  3146. (let (txt drawer-re kwd-time-re ind)
  3147. (save-excursion
  3148. (with-current-buffer (marker-buffer marker)
  3149. (if (not (derived-mode-p 'org-mode))
  3150. (setq txt "")
  3151. (save-excursion
  3152. (save-restriction
  3153. (widen)
  3154. (goto-char marker)
  3155. (end-of-line 1)
  3156. (setq txt (buffer-substring
  3157. (min (1+ (point)) (point-max))
  3158. (progn (outline-next-heading) (point)))
  3159. drawer-re org-drawer-regexp
  3160. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3161. ".*\n?"))
  3162. (with-temp-buffer
  3163. (insert txt)
  3164. (when org-agenda-add-entry-text-descriptive-links
  3165. (goto-char (point-min))
  3166. (while (org-activate-bracket-links (point-max))
  3167. (add-text-properties (match-beginning 0) (match-end 0)
  3168. '(face org-link))))
  3169. (goto-char (point-min))
  3170. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3171. (set-text-properties (match-beginning 0) (match-end 0)
  3172. nil))
  3173. (goto-char (point-min))
  3174. (while (re-search-forward drawer-re nil t)
  3175. (delete-region
  3176. (match-beginning 0)
  3177. (progn (re-search-forward
  3178. "^[ \t]*:END:.*\n?" nil 'move)
  3179. (point))))
  3180. (unless (member 'planning keep)
  3181. (goto-char (point-min))
  3182. (while (re-search-forward kwd-time-re nil t)
  3183. (replace-match "")))
  3184. (goto-char (point-min))
  3185. (when org-agenda-entry-text-exclude-regexps
  3186. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3187. (while (setq re (pop re-list))
  3188. (goto-char (point-min))
  3189. (while (re-search-forward re nil t)
  3190. (replace-match "")))))
  3191. (goto-char (point-max))
  3192. (skip-chars-backward " \t\n")
  3193. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3194. ;; find and remove min common indentation
  3195. (goto-char (point-min))
  3196. (untabify (point-min) (point-max))
  3197. (setq ind (org-get-indentation))
  3198. (while (not (eobp))
  3199. (unless (looking-at "[ \t]*$")
  3200. (setq ind (min ind (org-get-indentation))))
  3201. (beginning-of-line 2))
  3202. (goto-char (point-min))
  3203. (while (not (eobp))
  3204. (unless (looking-at "[ \t]*$")
  3205. (move-to-column ind)
  3206. (delete-region (point-at-bol) (point)))
  3207. (beginning-of-line 2))
  3208. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3209. (goto-char (point-min))
  3210. (when indent
  3211. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3212. (replace-match indent t t)))
  3213. (goto-char (point-min))
  3214. (while (looking-at "[ \t]*\n") (replace-match ""))
  3215. (goto-char (point-max))
  3216. (when (> (org-current-line)
  3217. n-lines)
  3218. (org-goto-line (1+ n-lines))
  3219. (backward-char 1))
  3220. (setq txt (buffer-substring (point-min) (point)))))))))
  3221. txt))
  3222. (defun org-check-for-org-mode ()
  3223. "Make sure current buffer is in org-mode. Error if not."
  3224. (or (derived-mode-p 'org-mode)
  3225. (error "Cannot execute org-mode agenda command on buffer in %s"
  3226. major-mode)))
  3227. ;;; Agenda prepare and finalize
  3228. (defvar org-agenda-multi nil) ; dynamically scoped
  3229. (defvar org-agenda-pre-window-conf nil)
  3230. (defvar org-agenda-columns-active nil)
  3231. (defvar org-agenda-name nil)
  3232. (defvar org-agenda-tag-filter nil)
  3233. (defvar org-agenda-category-filter nil)
  3234. (defvar org-agenda-regexp-filter nil)
  3235. (defvar org-agenda-top-headline-filter nil)
  3236. (defvar org-agenda-tag-filter-while-redo nil)
  3237. (defvar org-agenda-tag-filter-preset nil
  3238. "A preset of the tags filter used for secondary agenda filtering.
  3239. This must be a list of strings, each string must be a single tag preceded
  3240. by \"+\" or \"-\".
  3241. This variable should not be set directly, but agenda custom commands can
  3242. bind it in the options section. The preset filter is a global property of
  3243. the entire agenda view. In a block agenda, it will not work reliably to
  3244. define a filter for one of the individual blocks. You need to set it in
  3245. the global options and expect it to be applied to the entire view.")
  3246. (defvar org-agenda-category-filter-preset nil
  3247. "A preset of the category filter used for secondary agenda filtering.
  3248. This must be a list of strings, each string must be a single category
  3249. preceded by \"+\" or \"-\".
  3250. This variable should not be set directly, but agenda custom commands can
  3251. bind it in the options section. The preset filter is a global property of
  3252. the entire agenda view. In a block agenda, it will not work reliably to
  3253. define a filter for one of the individual blocks. You need to set it in
  3254. the global options and expect it to be applied to the entire view.")
  3255. (defvar org-agenda-regexp-filter-preset nil
  3256. "A preset of the regexp filter used for secondary agenda filtering.
  3257. This must be a list of strings, each string must be a single regexp
  3258. preceded by \"+\" or \"-\".
  3259. This variable should not be set directly, but agenda custom commands can
  3260. bind it in the options section. The preset filter is a global property of
  3261. the entire agenda view. In a block agenda, it will not work reliably to
  3262. define a filter for one of the individual blocks. You need to set it in
  3263. the global options and expect it to be applied to the entire view.")
  3264. (defun org-agenda-use-sticky-p ()
  3265. "Return non-nil if an agenda buffer named
  3266. `org-agenda-buffer-name' exists and should be shown instead of
  3267. generating a new one."
  3268. (and
  3269. ;; turned off by user
  3270. org-agenda-sticky
  3271. ;; For multi-agenda buffer already exists
  3272. (not org-agenda-multi)
  3273. ;; buffer found
  3274. (get-buffer org-agenda-buffer-name)
  3275. ;; C-u parameter is same as last call
  3276. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3277. (and
  3278. (equal current-prefix-arg
  3279. org-agenda-last-prefix-arg)
  3280. ;; In case user turned stickiness on, while having existing
  3281. ;; Agenda buffer active, don't reuse that buffer, because it
  3282. ;; does not have org variables local
  3283. org-agenda-this-buffer-is-sticky))))
  3284. (defun org-agenda-prepare-window (abuf)
  3285. "Setup agenda buffer in the window."
  3286. (let* ((awin (get-buffer-window abuf))
  3287. wconf)
  3288. (cond
  3289. ((equal (current-buffer) abuf) nil)
  3290. (awin (select-window awin))
  3291. ((not (setq wconf (current-window-configuration))))
  3292. ((equal org-agenda-window-setup 'current-window)
  3293. (org-pop-to-buffer-same-window abuf))
  3294. ((equal org-agenda-window-setup 'other-window)
  3295. (org-switch-to-buffer-other-window abuf))
  3296. ((equal org-agenda-window-setup 'other-frame)
  3297. (switch-to-buffer-other-frame abuf))
  3298. ((equal org-agenda-window-setup 'reorganize-frame)
  3299. (delete-other-windows)
  3300. (org-switch-to-buffer-other-window abuf)))
  3301. ;; additional test in case agenda is invoked from within agenda
  3302. ;; buffer via elisp link
  3303. (unless (equal (current-buffer) abuf)
  3304. (org-pop-to-buffer-same-window abuf))
  3305. (setq org-agenda-pre-window-conf
  3306. (or org-agenda-pre-window-conf wconf))))
  3307. (defun org-agenda-prepare (&optional name)
  3308. (if (org-agenda-use-sticky-p)
  3309. (progn
  3310. ;; Popup existing buffer
  3311. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3312. (message "Sticky Agenda buffer, use `r' to refresh")
  3313. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3314. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3315. (setq org-todo-keywords-for-agenda nil)
  3316. (unless org-agenda-persistent-filter
  3317. (setq org-agenda-tag-filter nil
  3318. org-agenda-category-filter nil
  3319. org-agenda-regexp-filter nil))
  3320. (put 'org-agenda-tag-filter :preset-filter
  3321. org-agenda-tag-filter-preset)
  3322. (put 'org-agenda-category-filter :preset-filter
  3323. org-agenda-category-filter-preset)
  3324. (put 'org-agenda-regexp-filter :preset-filter
  3325. org-agenda-regexp-filter-preset)
  3326. (if org-agenda-multi
  3327. (progn
  3328. (setq buffer-read-only nil)
  3329. (goto-char (point-max))
  3330. (unless (or (bobp) org-agenda-compact-blocks
  3331. (not org-agenda-block-separator))
  3332. (insert "\n"
  3333. (if (stringp org-agenda-block-separator)
  3334. org-agenda-block-separator
  3335. (make-string (window-width) org-agenda-block-separator))
  3336. "\n"))
  3337. (narrow-to-region (point) (point-max)))
  3338. (setq org-done-keywords-for-agenda nil)
  3339. ;; Setting any org variables that are in org-agenda-local-vars
  3340. ;; list need to be done after the prepare call
  3341. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3342. (setq buffer-read-only nil)
  3343. (org-agenda-reset-markers)
  3344. (let ((inhibit-read-only t)) (erase-buffer))
  3345. (org-agenda-mode)
  3346. (setq org-agenda-buffer (current-buffer))
  3347. (setq org-agenda-contributing-files nil)
  3348. (setq org-agenda-columns-active nil)
  3349. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3350. (setq org-todo-keywords-for-agenda
  3351. (org-uniquify org-todo-keywords-for-agenda))
  3352. (setq org-done-keywords-for-agenda
  3353. (org-uniquify org-done-keywords-for-agenda))
  3354. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3355. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3356. (and name (not org-agenda-name)
  3357. (org-set-local 'org-agenda-name name)))
  3358. (setq buffer-read-only nil)))
  3359. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3360. (defun org-agenda-finalize ()
  3361. "Finishing touch for the agenda buffer, called just before displaying it."
  3362. (unless org-agenda-multi
  3363. (save-excursion
  3364. (let ((inhibit-read-only t))
  3365. (goto-char (point-min))
  3366. (save-excursion
  3367. (while (org-activate-bracket-links (point-max))
  3368. (add-text-properties (match-beginning 0) (match-end 0)
  3369. '(face org-link))))
  3370. (save-excursion
  3371. (while (org-activate-plain-links (point-max))
  3372. (add-text-properties (match-beginning 0) (match-end 0)
  3373. '(face org-link))))
  3374. (unless (eq org-agenda-remove-tags t)
  3375. (org-agenda-align-tags))
  3376. (unless org-agenda-with-colors
  3377. (remove-text-properties (point-min) (point-max) '(face nil)))
  3378. (if (and (boundp 'org-agenda-overriding-columns-format)
  3379. org-agenda-overriding-columns-format)
  3380. (org-set-local 'org-agenda-overriding-columns-format
  3381. org-agenda-overriding-columns-format))
  3382. (if (and (boundp 'org-agenda-view-columns-initially)
  3383. org-agenda-view-columns-initially)
  3384. (org-agenda-columns))
  3385. (when org-agenda-fontify-priorities
  3386. (org-agenda-fontify-priorities))
  3387. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3388. (org-agenda-dim-blocked-tasks))
  3389. (org-agenda-mark-clocking-task)
  3390. (when org-agenda-entry-text-mode
  3391. (org-agenda-entry-text-hide)
  3392. (org-agenda-entry-text-show))
  3393. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3394. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3395. (org-habit-insert-consistency-graphs))
  3396. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3397. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3398. (and (listp org-agenda-show-inherited-tags)
  3399. (memq org-agenda-type org-agenda-show-inherited-tags))
  3400. (and (eq org-agenda-show-inherited-tags t)
  3401. (or (eq org-agenda-use-tag-inheritance t)
  3402. (and (listp org-agenda-use-tag-inheritance)
  3403. (not (memq org-agenda-type
  3404. org-agenda-use-tag-inheritance))))))
  3405. (let (mrk)
  3406. (save-excursion
  3407. (goto-char (point-min))
  3408. (while (equal (forward-line) 0)
  3409. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3410. (get-text-property (point) 'org-hd-marker)))
  3411. (put-text-property (point-at-bol) (point-at-eol)
  3412. 'tags (org-with-point-at mrk
  3413. (delete-dups
  3414. (mapcar 'downcase (org-get-tags-at))))))))))
  3415. (run-hooks 'org-agenda-finalize-hook)
  3416. (when org-agenda-top-headline-filter
  3417. (org-agenda-filter-top-headline-apply
  3418. org-agenda-top-headline-filter))
  3419. (when org-agenda-tag-filter
  3420. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3421. (when (get 'org-agenda-tag-filter :preset-filter)
  3422. (org-agenda-filter-apply
  3423. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3424. (when org-agenda-category-filter
  3425. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3426. (when (get 'org-agenda-category-filter :preset-filter)
  3427. (org-agenda-filter-apply
  3428. (get 'org-agenda-category-filter :preset-filter) 'category))
  3429. (when org-agenda-regexp-filter
  3430. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3431. (when (get 'org-agenda-regexp-filter :preset-filter)
  3432. (org-agenda-filter-apply
  3433. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3434. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3435. (defun org-agenda-mark-clocking-task ()
  3436. "Mark the current clock entry in the agenda if it is present."
  3437. ;; We need to widen when `org-agenda-finalize' is called from
  3438. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3439. (when org-clock-current-task
  3440. (save-restriction
  3441. (widen)
  3442. (org-agenda-unmark-clocking-task)
  3443. (when (marker-buffer org-clock-hd-marker)
  3444. (save-excursion
  3445. (goto-char (point-min))
  3446. (let (s ov)
  3447. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3448. (goto-char s)
  3449. (when (equal (org-get-at-bol 'org-hd-marker)
  3450. org-clock-hd-marker)
  3451. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3452. (overlay-put ov 'type 'org-agenda-clocking)
  3453. (overlay-put ov 'face 'org-agenda-clocking)
  3454. (overlay-put ov 'help-echo
  3455. "The clock is running in this item")))))))))
  3456. (defun org-agenda-unmark-clocking-task ()
  3457. "Unmark the current clocking task."
  3458. (mapc (lambda (o)
  3459. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3460. (delete-overlay o)))
  3461. (overlays-in (point-min) (point-max))))
  3462. (defun org-agenda-fontify-priorities ()
  3463. "Make highest priority lines bold, and lowest italic."
  3464. (interactive)
  3465. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3466. (delete-overlay o)))
  3467. (overlays-in (point-min) (point-max)))
  3468. (save-excursion
  3469. (let (b e p ov h l)
  3470. (goto-char (point-min))
  3471. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3472. (setq h (or (get-char-property (point) 'org-highest-priority)
  3473. org-highest-priority)
  3474. l (or (get-char-property (point) 'org-lowest-priority)
  3475. org-lowest-priority)
  3476. p (string-to-char (match-string 1))
  3477. b (match-beginning 0)
  3478. e (if (eq org-agenda-fontify-priorities 'cookies)
  3479. (match-end 0)
  3480. (point-at-eol))
  3481. ov (make-overlay b e))
  3482. (overlay-put
  3483. ov 'face
  3484. (cons (cond ((org-face-from-face-or-color
  3485. 'priority nil
  3486. (cdr (assoc p org-priority-faces))))
  3487. ((and (listp org-agenda-fontify-priorities)
  3488. (org-face-from-face-or-color
  3489. 'priority nil
  3490. (cdr (assoc p org-agenda-fontify-priorities)))))
  3491. ((equal p l) 'italic)
  3492. ((equal p h) 'bold))
  3493. 'org-priority))
  3494. (overlay-put ov 'org-type 'org-priority)))))
  3495. (defvar org-depend-tag-blocked)
  3496. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3497. "Dim currently blocked TODO's in the agenda display.
  3498. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3499. dimming them."
  3500. (interactive "P")
  3501. (when (org-called-interactively-p 'interactive)
  3502. (message "Dim or hide blocked tasks..."))
  3503. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3504. (delete-overlay o)))
  3505. (overlays-in (point-min) (point-max)))
  3506. (save-excursion
  3507. (let ((inhibit-read-only t)
  3508. (org-depend-tag-blocked nil)
  3509. (invis (or (not (null invisible))
  3510. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3511. org-blocked-by-checkboxes
  3512. invis1 b e p ov h l)
  3513. (goto-char (point-min))
  3514. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3515. (and pos (goto-char (1+ pos))))
  3516. (setq org-blocked-by-checkboxes nil invis1 invis)
  3517. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3518. (when (and marker
  3519. (with-current-buffer (marker-buffer marker)
  3520. (save-excursion (goto-char marker)
  3521. (org-entry-blocked-p))))
  3522. (if org-blocked-by-checkboxes (setq invis1 nil))
  3523. (setq b (if invis1
  3524. (max (point-min) (1- (point-at-bol)))
  3525. (point-at-bol))
  3526. e (point-at-eol)
  3527. ov (make-overlay b e))
  3528. (if invis1
  3529. (progn (overlay-put ov 'invisible t)
  3530. (overlay-put ov 'intangible t))
  3531. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3532. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3533. (when (org-called-interactively-p 'interactive)
  3534. (message "Dim or hide blocked tasks...done")))
  3535. (defvar org-agenda-skip-function nil
  3536. "Function to be called at each match during agenda construction.
  3537. If this function returns nil, the current match should not be skipped.
  3538. Otherwise, the function must return a position from where the search
  3539. should be continued.
  3540. This may also be a Lisp form, it will be evaluated.
  3541. Never set this variable using `setq' or so, because then it will apply
  3542. to all future agenda commands. If you do want a global skipping condition,
  3543. use the option `org-agenda-skip-function-global' instead.
  3544. The correct usage for `org-agenda-skip-function' is to bind it with
  3545. `let' to scope it dynamically into the agenda-constructing command.
  3546. A good way to set it is through options in `org-agenda-custom-commands'.")
  3547. (defun org-agenda-skip ()
  3548. "Throw to `:skip' in places that should be skipped.
  3549. Also moves point to the end of the skipped region, so that search can
  3550. continue from there."
  3551. (let ((p (point-at-bol)) to)
  3552. (when (or
  3553. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3554. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3555. (get-text-property p :org-archived)
  3556. (org-end-of-subtree t))
  3557. (and org-agenda-skip-comment-trees
  3558. (get-text-property p :org-comment)
  3559. (org-end-of-subtree t))
  3560. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3561. (org-agenda-skip-eval org-agenda-skip-function)))
  3562. (goto-char to))
  3563. (org-in-src-block-p t))
  3564. (throw :skip t))))
  3565. (defun org-agenda-skip-eval (form)
  3566. "If FORM is a function or a list, call (or eval) it and return the result.
  3567. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3568. and match data are returned to the previous state no matter what these
  3569. functions do."
  3570. (let (fp)
  3571. (and form
  3572. (or (setq fp (functionp form))
  3573. (consp form))
  3574. (save-excursion
  3575. (save-match-data
  3576. (if fp
  3577. (funcall form)
  3578. (eval form)))))))
  3579. (defvar org-agenda-markers nil
  3580. "List of all currently active markers created by `org-agenda'.")
  3581. (defvar org-agenda-last-marker-time (org-float-time)
  3582. "Creation time of the last agenda marker.")
  3583. (defun org-agenda-new-marker (&optional pos)
  3584. "Return a new agenda marker.
  3585. Org-mode keeps a list of these markers and resets them when they are
  3586. no longer in use."
  3587. (let ((m (copy-marker (or pos (point)))))
  3588. (setq org-agenda-last-marker-time (org-float-time))
  3589. (if org-agenda-buffer
  3590. (with-current-buffer org-agenda-buffer
  3591. (push m org-agenda-markers))
  3592. (push m org-agenda-markers))
  3593. m))
  3594. (defun org-agenda-reset-markers ()
  3595. "Reset markers created by `org-agenda'."
  3596. (while org-agenda-markers
  3597. (move-marker (pop org-agenda-markers) nil)))
  3598. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3599. "Save relative positions of markers in region.
  3600. This check for agenda markers in all agenda buffers currently active."
  3601. (dolist (buf (buffer-list))
  3602. (with-current-buffer buf
  3603. (when (eq major-mode 'org-agenda-mode)
  3604. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3605. org-agenda-markers)))))
  3606. ;;; Entry text mode
  3607. (defun org-agenda-entry-text-show-here ()
  3608. "Add some text from the entry as context to the current line."
  3609. (let (m txt o)
  3610. (setq m (org-get-at-bol 'org-hd-marker))
  3611. (unless (marker-buffer m)
  3612. (error "No marker points to an entry here"))
  3613. (setq txt (concat "\n" (org-no-properties
  3614. (org-agenda-get-some-entry-text
  3615. m org-agenda-entry-text-maxlines
  3616. org-agenda-entry-text-leaders))))
  3617. (when (string-match "\\S-" txt)
  3618. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3619. (overlay-put o 'evaporate t)
  3620. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3621. (overlay-put o 'after-string txt))))
  3622. (defun org-agenda-entry-text-show ()
  3623. "Add entry context for all agenda lines."
  3624. (interactive)
  3625. (save-excursion
  3626. (goto-char (point-max))
  3627. (beginning-of-line 1)
  3628. (while (not (bobp))
  3629. (when (org-get-at-bol 'org-hd-marker)
  3630. (org-agenda-entry-text-show-here))
  3631. (beginning-of-line 0))))
  3632. (defun org-agenda-entry-text-hide ()
  3633. "Remove any shown entry context."
  3634. (delq nil
  3635. (mapcar (lambda (o)
  3636. (if (eq (overlay-get o 'org-overlay-type)
  3637. 'agenda-entry-content)
  3638. (progn (delete-overlay o) t)))
  3639. (overlays-in (point-min) (point-max)))))
  3640. (defun org-agenda-get-day-face (date)
  3641. "Return the face DATE should be displayed with."
  3642. (or (and (functionp org-agenda-day-face-function)
  3643. (funcall org-agenda-day-face-function date))
  3644. (cond ((org-agenda-todayp date)
  3645. 'org-agenda-date-today)
  3646. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3647. 'org-agenda-date-weekend)
  3648. (t 'org-agenda-date))))
  3649. ;;; Agenda timeline
  3650. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3651. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3652. (defun org-timeline (&optional dotodo)
  3653. "Show a time-sorted view of the entries in the current org file.
  3654. Only entries with a time stamp of today or later will be listed. With
  3655. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3656. under the current date.
  3657. If the buffer contains an active region, only check the region for
  3658. dates."
  3659. (interactive "P")
  3660. (let* ((dopast t)
  3661. (org-agenda-show-log-scoped org-agenda-show-log)
  3662. (org-agenda-show-log org-agenda-show-log-scoped)
  3663. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3664. (current-buffer))))
  3665. (date (calendar-current-date))
  3666. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3667. (end (if (org-region-active-p) (region-end) (point-max)))
  3668. (day-numbers (org-get-all-dates
  3669. beg end 'no-ranges
  3670. t org-agenda-show-log-scoped ; always include today
  3671. org-timeline-show-empty-dates))
  3672. (org-deadline-warning-days 0)
  3673. (org-agenda-only-exact-dates t)
  3674. (today (org-today))
  3675. (past t)
  3676. args
  3677. s e rtn d emptyp)
  3678. (setq org-agenda-redo-command
  3679. (list 'let
  3680. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3681. (list 'org-switch-to-buffer-other-window (current-buffer))
  3682. (list 'org-timeline (list 'quote dotodo))))
  3683. (put 'org-agenda-redo-command 'org-lprops nil)
  3684. (if (not dopast)
  3685. ;; Remove past dates from the list of dates.
  3686. (setq day-numbers (delq nil (mapcar (lambda(x)
  3687. (if (>= x today) x nil))
  3688. day-numbers))))
  3689. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3690. (org-compile-prefix-format 'timeline)
  3691. (org-set-sorting-strategy 'timeline)
  3692. (if org-agenda-show-log-scoped (push :closed args))
  3693. (push :timestamp args)
  3694. (push :deadline args)
  3695. (push :scheduled args)
  3696. (push :sexp args)
  3697. (if dotodo (push :todo args))
  3698. (insert "Timeline of file " entry "\n")
  3699. (add-text-properties (point-min) (point)
  3700. (list 'face 'org-agenda-structure))
  3701. (org-agenda-mark-header-line (point-min))
  3702. (while (setq d (pop day-numbers))
  3703. (if (and (listp d) (eq (car d) :omitted))
  3704. (progn
  3705. (setq s (point))
  3706. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3707. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3708. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3709. (if (and (>= d today)
  3710. dopast
  3711. past)
  3712. (progn
  3713. (setq past nil)
  3714. (insert (make-string 79 ?-) "\n")))
  3715. (setq date (calendar-gregorian-from-absolute d))
  3716. (setq s (point))
  3717. (setq rtn (and (not emptyp)
  3718. (apply 'org-agenda-get-day-entries entry
  3719. date args)))
  3720. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3721. (progn
  3722. (insert
  3723. (if (stringp org-agenda-format-date)
  3724. (format-time-string org-agenda-format-date
  3725. (org-time-from-absolute date))
  3726. (funcall org-agenda-format-date date))
  3727. "\n")
  3728. (put-text-property s (1- (point)) 'face
  3729. (org-agenda-get-day-face date))
  3730. (put-text-property s (1- (point)) 'org-date-line t)
  3731. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3732. (if (equal d today)
  3733. (put-text-property s (1- (point)) 'org-today t))
  3734. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3735. (put-text-property s (1- (point)) 'day d)))))
  3736. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3737. (point-min)))
  3738. (add-text-properties
  3739. (point-min) (point-max)
  3740. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3741. (org-agenda-finalize)
  3742. (setq buffer-read-only t)))
  3743. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3744. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3745. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3746. not every single day in the range. If FORCE-TODAY is non-nil, make
  3747. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3748. inactive time stamps (those in square brackets) are included.
  3749. When EMPTY is non-nil, also include days without any entries."
  3750. (let ((re (concat
  3751. (if pre-re pre-re "")
  3752. (if inactive org-ts-regexp-both org-ts-regexp)))
  3753. dates dates1 date day day1 day2 ts1 ts2 pos)
  3754. (if force-today
  3755. (setq dates (list (org-today))))
  3756. (save-excursion
  3757. (goto-char beg)
  3758. (while (re-search-forward re end t)
  3759. (setq day (time-to-days (org-time-string-to-time
  3760. (substring (match-string 1) 0 10)
  3761. (current-buffer) (match-beginning 0))))
  3762. (or (memq day dates) (push day dates)))
  3763. (unless no-ranges
  3764. (goto-char beg)
  3765. (while (re-search-forward org-tr-regexp end t)
  3766. (setq pos (match-beginning 0))
  3767. (setq ts1 (substring (match-string 1) 0 10)
  3768. ts2 (substring (match-string 2) 0 10)
  3769. day1 (time-to-days (org-time-string-to-time
  3770. ts1 (current-buffer) pos))
  3771. day2 (time-to-days (org-time-string-to-time
  3772. ts2 (current-buffer) pos)))
  3773. (while (< (setq day1 (1+ day1)) day2)
  3774. (or (memq day1 dates) (push day1 dates)))))
  3775. (setq dates (sort dates '<))
  3776. (when empty
  3777. (while (setq day (pop dates))
  3778. (setq day2 (car dates))
  3779. (push day dates1)
  3780. (when (and day2 empty)
  3781. (if (or (eq empty t)
  3782. (and (numberp empty) (<= (- day2 day) empty)))
  3783. (while (< (setq day (1+ day)) day2)
  3784. (push (list day) dates1))
  3785. (push (cons :omitted (- day2 day)) dates1))))
  3786. (setq dates (nreverse dates1)))
  3787. dates)))
  3788. ;;; Agenda Daily/Weekly
  3789. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3790. "Start day for the agenda view.
  3791. Custom commands can set this variable in the options section.
  3792. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3793. input allowed when reading a date through the Org calendar.
  3794. See the docstring of `org-read-date' for details.")
  3795. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3796. (defvar org-arg-loc nil) ; local variable
  3797. (defvar org-agenda-buffer-tmp-name nil)
  3798. ;;;###autoload
  3799. (defun org-agenda-list (&optional arg start-day span with-hour)
  3800. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3801. The view will be for the current day or week, but from the overview buffer
  3802. you will be able to go to other days/weeks.
  3803. With a numeric prefix argument in an interactive call, the agenda will
  3804. span ARG days. Lisp programs should instead specify SPAN to change
  3805. the number of days. SPAN defaults to `org-agenda-span'.
  3806. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3807. given in `org-agenda-start-on-weekday'.
  3808. When WITH-HOUR is non-nil, only include scheduled and deadline
  3809. items if they have an hour specification like [h]h:mm."
  3810. (interactive "P")
  3811. (if org-agenda-overriding-arguments
  3812. (setq arg (car org-agenda-overriding-arguments)
  3813. start-day (nth 1 org-agenda-overriding-arguments)
  3814. span (nth 2 org-agenda-overriding-arguments)))
  3815. (if (and (integerp arg) (> arg 0))
  3816. (setq span arg arg nil))
  3817. (catch 'exit
  3818. (setq org-agenda-buffer-name
  3819. (or org-agenda-buffer-tmp-name
  3820. (if org-agenda-sticky
  3821. (cond ((and org-keys (stringp org-match))
  3822. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3823. (org-keys
  3824. (format "*Org Agenda(%s)*" org-keys))
  3825. (t "*Org Agenda(a)*")))
  3826. org-agenda-buffer-name))
  3827. (org-agenda-prepare "Day/Week")
  3828. (setq start-day (or start-day org-agenda-start-day))
  3829. (if (stringp start-day)
  3830. ;; Convert to an absolute day number
  3831. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3832. (org-compile-prefix-format 'agenda)
  3833. (org-set-sorting-strategy 'agenda)
  3834. (let* ((span (org-agenda-ndays-to-span
  3835. (or span org-agenda-ndays org-agenda-span)))
  3836. (today (org-today))
  3837. (sd (or start-day today))
  3838. (ndays (org-agenda-span-to-ndays span sd))
  3839. (org-agenda-start-on-weekday
  3840. (if (or (eq ndays 7) (eq ndays 14))
  3841. org-agenda-start-on-weekday))
  3842. (thefiles (org-agenda-files nil 'ifmode))
  3843. (files thefiles)
  3844. (start (if (or (null org-agenda-start-on-weekday)
  3845. (< ndays 7))
  3846. sd
  3847. (let* ((nt (calendar-day-of-week
  3848. (calendar-gregorian-from-absolute sd)))
  3849. (n1 org-agenda-start-on-weekday)
  3850. (d (- nt n1)))
  3851. (- sd (+ (if (< d 0) 7 0) d)))))
  3852. (day-numbers (list start))
  3853. (day-cnt 0)
  3854. (inhibit-redisplay (not debug-on-error))
  3855. (org-agenda-show-log-scoped org-agenda-show-log)
  3856. s e rtn rtnall file date d start-pos end-pos todayp
  3857. clocktable-start clocktable-end filter)
  3858. (setq org-agenda-redo-command
  3859. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3860. (dotimes (n (1- ndays))
  3861. (push (1+ (car day-numbers)) day-numbers))
  3862. (setq day-numbers (nreverse day-numbers))
  3863. (setq clocktable-start (car day-numbers)
  3864. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3865. (org-set-local 'org-starting-day (car day-numbers))
  3866. (org-set-local 'org-arg-loc arg)
  3867. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3868. (unless org-agenda-compact-blocks
  3869. (let* ((d1 (car day-numbers))
  3870. (d2 (org-last day-numbers))
  3871. (w1 (org-days-to-iso-week d1))
  3872. (w2 (org-days-to-iso-week d2)))
  3873. (setq s (point))
  3874. (if org-agenda-overriding-header
  3875. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3876. nil 'face 'org-agenda-structure) "\n")
  3877. (insert (org-agenda-span-name span)
  3878. "-agenda"
  3879. (if (< (- d2 d1) 350)
  3880. (if (= w1 w2)
  3881. (format " (W%02d)" w1)
  3882. (format " (W%02d-W%02d)" w1 w2))
  3883. "")
  3884. ":\n")))
  3885. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3886. 'org-date-line t))
  3887. (org-agenda-mark-header-line s))
  3888. (while (setq d (pop day-numbers))
  3889. (setq date (calendar-gregorian-from-absolute d)
  3890. s (point))
  3891. (if (or (setq todayp (= d today))
  3892. (and (not start-pos) (= d sd)))
  3893. (setq start-pos (point))
  3894. (if (and start-pos (not end-pos))
  3895. (setq end-pos (point))))
  3896. (setq files thefiles
  3897. rtnall nil)
  3898. (while (setq file (pop files))
  3899. (catch 'nextfile
  3900. (org-check-agenda-file file)
  3901. (let ((org-agenda-entry-types org-agenda-entry-types))
  3902. ;; Starred types override non-starred equivalents
  3903. (when (member :deadline* org-agenda-entry-types)
  3904. (setq org-agenda-entry-types
  3905. (delq :deadline org-agenda-entry-types)))
  3906. (when (member :scheduled* org-agenda-entry-types)
  3907. (setq org-agenda-entry-types
  3908. (delq :scheduled org-agenda-entry-types)))
  3909. ;; Honor with-hour
  3910. (when with-hour
  3911. (when (member :deadline org-agenda-entry-types)
  3912. (setq org-agenda-entry-types
  3913. (delq :deadline org-agenda-entry-types))
  3914. (push :deadline* org-agenda-entry-types))
  3915. (when (member :scheduled org-agenda-entry-types)
  3916. (setq org-agenda-entry-types
  3917. (delq :scheduled org-agenda-entry-types))
  3918. (push :scheduled* org-agenda-entry-types)))
  3919. (unless org-agenda-include-deadlines
  3920. (setq org-agenda-entry-types
  3921. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3922. (cond
  3923. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3924. (setq rtn (org-agenda-get-day-entries
  3925. file date :closed)))
  3926. (org-agenda-show-log-scoped
  3927. (setq rtn (apply 'org-agenda-get-day-entries
  3928. file date
  3929. (append '(:closed) org-agenda-entry-types))))
  3930. (t
  3931. (setq rtn (apply 'org-agenda-get-day-entries
  3932. file date
  3933. org-agenda-entry-types)))))
  3934. (setq rtnall (append rtnall rtn)))) ;; all entries
  3935. (if org-agenda-include-diary
  3936. (let ((org-agenda-search-headline-for-time t))
  3937. (require 'diary-lib)
  3938. (setq rtn (org-get-entries-from-diary date))
  3939. (setq rtnall (append rtnall rtn))))
  3940. (if (or rtnall org-agenda-show-all-dates)
  3941. (progn
  3942. (setq day-cnt (1+ day-cnt))
  3943. (insert
  3944. (if (stringp org-agenda-format-date)
  3945. (format-time-string org-agenda-format-date
  3946. (org-time-from-absolute date))
  3947. (funcall org-agenda-format-date date))
  3948. "\n")
  3949. (put-text-property s (1- (point)) 'face
  3950. (org-agenda-get-day-face date))
  3951. (put-text-property s (1- (point)) 'org-date-line t)
  3952. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3953. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3954. (when todayp
  3955. (put-text-property s (1- (point)) 'org-today t))
  3956. (setq rtnall
  3957. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3958. (if rtnall (insert ;; all entries
  3959. (org-agenda-finalize-entries rtnall 'agenda)
  3960. "\n"))
  3961. (put-text-property s (1- (point)) 'day d)
  3962. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3963. (when (and org-agenda-clockreport-mode clocktable-start)
  3964. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3965. ;; the above line is to ensure the restricted range!
  3966. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3967. tbl)
  3968. (setq p (org-plist-delete p :block))
  3969. (setq p (plist-put p :tstart clocktable-start))
  3970. (setq p (plist-put p :tend clocktable-end))
  3971. (setq p (plist-put p :scope 'agenda))
  3972. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3973. (setq filter (or org-agenda-tag-filter-while-redo
  3974. (get 'org-agenda-tag-filter :preset-filter))))
  3975. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3976. (if (string-match "[<>=]" x)
  3977. ""
  3978. x))
  3979. filter ""))))
  3980. (setq tbl (apply 'org-clock-get-clocktable p))
  3981. (insert tbl)))
  3982. (goto-char (point-min))
  3983. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3984. (unless (and (pos-visible-in-window-p (point-min))
  3985. (pos-visible-in-window-p (point-max)))
  3986. (goto-char (1- (point-max)))
  3987. (recenter -1)
  3988. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3989. (progn
  3990. (goto-char (or start-pos 1))
  3991. (recenter 1))))
  3992. (goto-char (or start-pos 1))
  3993. (add-text-properties (point-min) (point-max)
  3994. `(org-agenda-type agenda
  3995. org-last-args (,arg ,start-day ,span)
  3996. org-redo-cmd ,org-agenda-redo-command
  3997. org-series-cmd ,org-cmd))
  3998. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3999. (org-agenda-show-clocking-issues))
  4000. (org-agenda-finalize)
  4001. (setq buffer-read-only t)
  4002. (message ""))))
  4003. (defun org-agenda-ndays-to-span (n)
  4004. "Return a span symbol for a span of N days, or N if none matches."
  4005. (cond ((symbolp n) n)
  4006. ((= n 1) 'day)
  4007. ((= n 7) 'week)
  4008. ((= n 14) 'fortnight)
  4009. (t n)))
  4010. (defun org-agenda-span-to-ndays (span &optional start-day)
  4011. "Return ndays from SPAN, possibly starting at START-DAY.
  4012. START-DAY is an absolute time value."
  4013. (cond ((numberp span) span)
  4014. ((eq span 'day) 1)
  4015. ((eq span 'week) 7)
  4016. ((eq span 'fortnight) 14)
  4017. ((eq span 'month)
  4018. (let ((date (calendar-gregorian-from-absolute start-day)))
  4019. (calendar-last-day-of-month (car date) (caddr date))))
  4020. ((eq span 'year)
  4021. (let ((date (calendar-gregorian-from-absolute start-day)))
  4022. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4023. (defun org-agenda-span-name (span)
  4024. "Return a SPAN name."
  4025. (if (null span)
  4026. ""
  4027. (if (symbolp span)
  4028. (capitalize (symbol-name span))
  4029. (format "%d days" span))))
  4030. ;;; Agenda word search
  4031. (defvar org-agenda-search-history nil)
  4032. (defvar org-search-syntax-table nil
  4033. "Special syntax table for org-mode search.
  4034. In this table, we have single quotes not as word constituents, to
  4035. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4036. (defvar org-mode-syntax-table) ; From org.el
  4037. (defun org-search-syntax-table ()
  4038. (unless org-search-syntax-table
  4039. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4040. (modify-syntax-entry ?' "." org-search-syntax-table)
  4041. (modify-syntax-entry ?` "." org-search-syntax-table))
  4042. org-search-syntax-table)
  4043. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4044. ;;;###autoload
  4045. (defun org-search-view (&optional todo-only string edit-at)
  4046. "Show all entries that contain a phrase or words or regular expressions.
  4047. With optional prefix argument TODO-ONLY, only consider entries that are
  4048. TODO entries. The argument STRING can be used to pass a default search
  4049. string into this function. If EDIT-AT is non-nil, it means that the
  4050. user should get a chance to edit this string, with cursor at position
  4051. EDIT-AT.
  4052. The search string can be viewed either as a phrase that should be found as
  4053. is, or it can be broken into a number of snippets, each of which must match
  4054. in a Boolean way to select an entry. The default depends on the variable
  4055. `org-agenda-search-view-always-boolean'.
  4056. Even if this is turned off (the default) you can always switch to
  4057. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4058. The default is a direct search of the whole phrase, where each space in
  4059. the search string can expand to an arbitrary amount of whitespace,
  4060. including newlines.
  4061. If using a Boolean search, the search string is split on whitespace and
  4062. each snippet is searched separately, with logical AND to select an entry.
  4063. Words prefixed with a minus must *not* occur in the entry. Words without
  4064. a prefix or prefixed with a plus must occur in the entry. Matching is
  4065. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4066. match whole words, not parts of a word) if
  4067. `org-agenda-search-view-force-full-words' is set (default is nil).
  4068. Boolean search snippets enclosed by curly braces are interpreted as
  4069. regular expressions that must or (when preceded with \"-\") must not
  4070. match in the entry. Snippets enclosed into double quotes will be taken
  4071. as a whole, to include whitespace.
  4072. - If the search string starts with an asterisk, search only in headlines.
  4073. - If (possibly after the leading star) the search string starts with an
  4074. exclamation mark, this also means to look at TODO entries only, an effect
  4075. that can also be achieved with a prefix argument.
  4076. - If (possibly after star and exclamation mark) the search string starts
  4077. with a colon, this will mean that the (non-regexp) snippets of the
  4078. Boolean search must match as full words.
  4079. This command searches the agenda files, and in addition the files listed
  4080. in `org-agenda-text-search-extra-files'."
  4081. (interactive "P")
  4082. (if org-agenda-overriding-arguments
  4083. (setq todo-only (car org-agenda-overriding-arguments)
  4084. string (nth 1 org-agenda-overriding-arguments)
  4085. edit-at (nth 2 org-agenda-overriding-arguments)))
  4086. (let* ((props (list 'face nil
  4087. 'done-face 'org-agenda-done
  4088. 'org-not-done-regexp org-not-done-regexp
  4089. 'org-todo-regexp org-todo-regexp
  4090. 'org-complex-heading-regexp org-complex-heading-regexp
  4091. 'mouse-face 'highlight
  4092. 'help-echo (format "mouse-2 or RET jump to location")))
  4093. (full-words org-agenda-search-view-force-full-words)
  4094. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4095. regexp rtn rtnall files file pos inherited-tags
  4096. marker category category-pos level tags c neg re boolean
  4097. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4098. (unless (and (not edit-at)
  4099. (stringp string)
  4100. (string-match "\\S-" string))
  4101. (setq string (read-string
  4102. (if org-agenda-search-view-always-boolean
  4103. "[+-]Word/{Regexp} ...: "
  4104. "Phrase or [+-]Word/{Regexp} ...: ")
  4105. (cond
  4106. ((integerp edit-at) (cons string edit-at))
  4107. (edit-at string))
  4108. 'org-agenda-search-history)))
  4109. (catch 'exit
  4110. (if org-agenda-sticky
  4111. (setq org-agenda-buffer-name
  4112. (if (stringp string)
  4113. (format "*Org Agenda(%s:%s)*"
  4114. (or org-keys (or (and todo-only "S") "s")) string)
  4115. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4116. (org-agenda-prepare "SEARCH")
  4117. (org-compile-prefix-format 'search)
  4118. (org-set-sorting-strategy 'search)
  4119. (setq org-agenda-redo-command
  4120. (list 'org-search-view (if todo-only t nil)
  4121. (list 'if 'current-prefix-arg nil string)))
  4122. (setq org-agenda-query-string string)
  4123. (if (equal (string-to-char string) ?*)
  4124. (setq hdl-only t
  4125. words (substring string 1))
  4126. (setq words string))
  4127. (when (equal (string-to-char words) ?!)
  4128. (setq todo-only t
  4129. words (substring words 1)))
  4130. (when (equal (string-to-char words) ?:)
  4131. (setq full-words t
  4132. words (substring words 1)))
  4133. (if (or org-agenda-search-view-always-boolean
  4134. (member (string-to-char words) '(?- ?+ ?\{)))
  4135. (setq boolean t))
  4136. (setq words (org-split-string words))
  4137. (let (www w)
  4138. (while (setq w (pop words))
  4139. (while (and (string-match "\\\\\\'" w) words)
  4140. (setq w (concat (substring w 0 -1) " " (pop words))))
  4141. (push w www))
  4142. (setq words (nreverse www) www nil)
  4143. (while (setq w (pop words))
  4144. (when (and (string-match "\\`[-+]?{" w)
  4145. (not (string-match "}\\'" w)))
  4146. (while (and words (not (string-match "}\\'" (car words))))
  4147. (setq w (concat w " " (pop words))))
  4148. (setq w (concat w " " (pop words))))
  4149. (push w www))
  4150. (setq words (nreverse www)))
  4151. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4152. (when boolean
  4153. (let (wds w)
  4154. (while (setq w (pop words))
  4155. (if (or (equal (substring w 0 1) "\"")
  4156. (and (> (length w) 1)
  4157. (member (substring w 0 1) '("+" "-"))
  4158. (equal (substring w 1 2) "\"")))
  4159. (while (and words (not (equal (substring w -1) "\"")))
  4160. (setq w (concat w " " (pop words)))))
  4161. (and (string-match "\\`\\([-+]?\\)\"" w)
  4162. (setq w (replace-match "\\1" nil nil w)))
  4163. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4164. (push w wds))
  4165. (setq words (nreverse wds))))
  4166. (if boolean
  4167. (mapc (lambda (w)
  4168. (setq c (string-to-char w))
  4169. (if (equal c ?-)
  4170. (setq neg t w (substring w 1))
  4171. (if (equal c ?+)
  4172. (setq neg nil w (substring w 1))
  4173. (setq neg nil)))
  4174. (if (string-match "\\`{.*}\\'" w)
  4175. (setq re (substring w 1 -1))
  4176. (if full-words
  4177. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4178. (setq re (regexp-quote (downcase w)))))
  4179. (if neg (push re regexps-) (push re regexps+)))
  4180. words)
  4181. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4182. regexps+))
  4183. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4184. (if (not regexps+)
  4185. (setq regexp org-outline-regexp-bol)
  4186. (setq regexp (pop regexps+))
  4187. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4188. regexp))))
  4189. (setq files (org-agenda-files nil 'ifmode))
  4190. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4191. (pop org-agenda-text-search-extra-files)
  4192. (setq files (org-add-archive-files files)))
  4193. (setq files (append files org-agenda-text-search-extra-files)
  4194. rtnall nil)
  4195. (while (setq file (pop files))
  4196. (setq ee nil)
  4197. (catch 'nextfile
  4198. (org-check-agenda-file file)
  4199. (setq buffer (if (file-exists-p file)
  4200. (org-get-agenda-file-buffer file)
  4201. (error "No such file %s" file)))
  4202. (if (not buffer)
  4203. ;; If file does not exist, make sure an error message is sent
  4204. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4205. file))))
  4206. (with-current-buffer buffer
  4207. (with-syntax-table (org-search-syntax-table)
  4208. (unless (derived-mode-p 'org-mode)
  4209. (error "Agenda file %s is not in `org-mode'" file))
  4210. (let ((case-fold-search t))
  4211. (save-excursion
  4212. (save-restriction
  4213. (if (eq buffer org-agenda-restrict)
  4214. (narrow-to-region org-agenda-restrict-begin
  4215. org-agenda-restrict-end)
  4216. (widen))
  4217. (goto-char (point-min))
  4218. (unless (or (org-at-heading-p)
  4219. (outline-next-heading))
  4220. (throw 'nextfile t))
  4221. (goto-char (max (point-min) (1- (point))))
  4222. (while (re-search-forward regexp nil t)
  4223. (org-back-to-heading t)
  4224. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4225. (> (org-reduced-level (org-outline-level))
  4226. org-agenda-search-view-max-outline-level)
  4227. (forward-line -1)
  4228. (outline-back-to-heading t)))
  4229. (skip-chars-forward "* ")
  4230. (setq beg (point-at-bol)
  4231. beg1 (point)
  4232. end (progn
  4233. (outline-next-heading)
  4234. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4235. (> (org-reduced-level (org-outline-level))
  4236. org-agenda-search-view-max-outline-level)
  4237. (forward-line 1)
  4238. (outline-next-heading)))
  4239. (point)))
  4240. (catch :skip
  4241. (goto-char beg)
  4242. (org-agenda-skip)
  4243. (setq str (buffer-substring-no-properties
  4244. (point-at-bol)
  4245. (if hdl-only (point-at-eol) end)))
  4246. (mapc (lambda (wr) (when (string-match wr str)
  4247. (goto-char (1- end))
  4248. (throw :skip t)))
  4249. regexps-)
  4250. (mapc (lambda (wr) (unless (string-match wr str)
  4251. (goto-char (1- end))
  4252. (throw :skip t)))
  4253. (if todo-only
  4254. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4255. regexps+)
  4256. regexps+))
  4257. (goto-char beg)
  4258. (setq marker (org-agenda-new-marker (point))
  4259. category (org-get-category)
  4260. level (make-string (org-reduced-level (org-outline-level)) ? )
  4261. category-pos (get-text-property (point) 'org-category-position)
  4262. inherited-tags
  4263. (or (eq org-agenda-show-inherited-tags 'always)
  4264. (and (listp org-agenda-show-inherited-tags)
  4265. (memq 'todo org-agenda-show-inherited-tags))
  4266. (and (eq org-agenda-show-inherited-tags t)
  4267. (or (eq org-agenda-use-tag-inheritance t)
  4268. (memq 'todo org-agenda-use-tag-inheritance))))
  4269. tags (org-get-tags-at nil (not inherited-tags))
  4270. txt (org-agenda-format-item
  4271. ""
  4272. (buffer-substring-no-properties
  4273. beg1 (point-at-eol))
  4274. level category tags t))
  4275. (org-add-props txt props
  4276. 'org-marker marker 'org-hd-marker marker
  4277. 'org-todo-regexp org-todo-regexp
  4278. 'level level
  4279. 'org-complex-heading-regexp org-complex-heading-regexp
  4280. 'priority 1000 'org-category category
  4281. 'org-category-position category-pos
  4282. 'type "search")
  4283. (push txt ee)
  4284. (goto-char (1- end))))))))))
  4285. (setq rtn (nreverse ee))
  4286. (setq rtnall (append rtnall rtn)))
  4287. (if org-agenda-overriding-header
  4288. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4289. nil 'face 'org-agenda-structure) "\n")
  4290. (insert "Search words: ")
  4291. (add-text-properties (point-min) (1- (point))
  4292. (list 'face 'org-agenda-structure))
  4293. (setq pos (point))
  4294. (insert string "\n")
  4295. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4296. (setq pos (point))
  4297. (unless org-agenda-multi
  4298. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4299. (add-text-properties pos (1- (point))
  4300. (list 'face 'org-agenda-structure))))
  4301. (org-agenda-mark-header-line (point-min))
  4302. (when rtnall
  4303. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4304. (goto-char (point-min))
  4305. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4306. (add-text-properties (point-min) (point-max)
  4307. `(org-agenda-type search
  4308. org-last-args (,todo-only ,string ,edit-at)
  4309. org-redo-cmd ,org-agenda-redo-command
  4310. org-series-cmd ,org-cmd))
  4311. (org-agenda-finalize)
  4312. (setq buffer-read-only t))))
  4313. ;;; Agenda TODO list
  4314. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4315. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4316. (concat
  4317. (if (or (equal keywords "ALL") (not keywords))
  4318. (propertize "ALL" 'face 'warning)
  4319. (mapconcat
  4320. (lambda (kw)
  4321. (propertize kw 'face (org-get-todo-face kw)))
  4322. (org-split-string keywords "|")
  4323. "|"))
  4324. "\n"))
  4325. (defvar org-select-this-todo-keyword nil)
  4326. (defvar org-last-arg nil)
  4327. ;;;###autoload
  4328. (defun org-todo-list (&optional arg)
  4329. "Show all (not done) TODO entries from all agenda file in a single list.
  4330. The prefix arg can be used to select a specific TODO keyword and limit
  4331. the list to these. When using \\[universal-argument], you will be prompted
  4332. for a keyword. A numeric prefix directly selects the Nth keyword in
  4333. `org-todo-keywords-1'."
  4334. (interactive "P")
  4335. (if org-agenda-overriding-arguments
  4336. (setq arg org-agenda-overriding-arguments))
  4337. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4338. (let* ((today (org-today))
  4339. (date (calendar-gregorian-from-absolute today))
  4340. (kwds org-todo-keywords-for-agenda)
  4341. (completion-ignore-case t)
  4342. (org-select-this-todo-keyword
  4343. (if (stringp arg) arg
  4344. (and arg (integerp arg) (> arg 0)
  4345. (nth (1- arg) kwds))))
  4346. rtn rtnall files file pos)
  4347. (when (equal arg '(4))
  4348. (setq org-select-this-todo-keyword
  4349. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4350. (mapcar 'list kwds) nil nil)))
  4351. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4352. (catch 'exit
  4353. (if org-agenda-sticky
  4354. (setq org-agenda-buffer-name
  4355. (if (stringp org-select-this-todo-keyword)
  4356. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4357. org-select-this-todo-keyword)
  4358. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4359. (org-agenda-prepare "TODO")
  4360. (org-compile-prefix-format 'todo)
  4361. (org-set-sorting-strategy 'todo)
  4362. (setq org-agenda-redo-command
  4363. `(org-todo-list (or (and (numberp current-prefix-arg)
  4364. current-prefix-arg)
  4365. ,org-select-this-todo-keyword
  4366. current-prefix-arg ,arg)))
  4367. (setq files (org-agenda-files nil 'ifmode)
  4368. rtnall nil)
  4369. (while (setq file (pop files))
  4370. (catch 'nextfile
  4371. (org-check-agenda-file file)
  4372. (setq rtn (org-agenda-get-day-entries file date :todo))
  4373. (setq rtnall (append rtnall rtn))))
  4374. (if org-agenda-overriding-header
  4375. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4376. nil 'face 'org-agenda-structure) "\n")
  4377. (insert "Global list of TODO items of type: ")
  4378. (add-text-properties (point-min) (1- (point))
  4379. (list 'face 'org-agenda-structure
  4380. 'short-heading
  4381. (concat "ToDo: "
  4382. (or org-select-this-todo-keyword "ALL"))))
  4383. (org-agenda-mark-header-line (point-min))
  4384. (insert (org-agenda-propertize-selected-todo-keywords
  4385. org-select-this-todo-keyword))
  4386. (setq pos (point))
  4387. (unless org-agenda-multi
  4388. (insert "Available with `N r': (0)[ALL]")
  4389. (let ((n 0) s)
  4390. (mapc (lambda (x)
  4391. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4392. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4393. (insert "\n "))
  4394. (insert " " s))
  4395. kwds))
  4396. (insert "\n"))
  4397. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4398. (org-agenda-mark-header-line (point-min))
  4399. (when rtnall
  4400. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4401. (goto-char (point-min))
  4402. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4403. (add-text-properties (point-min) (point-max)
  4404. `(org-agenda-type todo
  4405. org-last-args ,arg
  4406. org-redo-cmd ,org-agenda-redo-command
  4407. org-series-cmd ,org-cmd))
  4408. (org-agenda-finalize)
  4409. (setq buffer-read-only t))))
  4410. ;;; Agenda tags match
  4411. ;;;###autoload
  4412. (defun org-tags-view (&optional todo-only match)
  4413. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4414. The prefix arg TODO-ONLY limits the search to TODO entries."
  4415. (interactive "P")
  4416. (if org-agenda-overriding-arguments
  4417. (setq todo-only (car org-agenda-overriding-arguments)
  4418. match (nth 1 org-agenda-overriding-arguments)))
  4419. (let* ((org-tags-match-list-sublevels
  4420. org-tags-match-list-sublevels)
  4421. (completion-ignore-case t)
  4422. rtn rtnall files file pos matcher
  4423. buffer)
  4424. (when (and (stringp match) (not (string-match "\\S-" match)))
  4425. (setq match nil))
  4426. (catch 'exit
  4427. (if org-agenda-sticky
  4428. (setq org-agenda-buffer-name
  4429. (if (stringp match)
  4430. (format "*Org Agenda(%s:%s)*"
  4431. (or org-keys (or (and todo-only "M") "m")) match)
  4432. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4433. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4434. ;; expanding tags within `org-make-tags-matcher'
  4435. (org-agenda-prepare (concat "TAGS " match))
  4436. (setq matcher (org-make-tags-matcher match)
  4437. match (car matcher) matcher (cdr matcher))
  4438. (org-compile-prefix-format 'tags)
  4439. (org-set-sorting-strategy 'tags)
  4440. (setq org-agenda-query-string match)
  4441. (setq org-agenda-redo-command
  4442. (list 'org-tags-view `(quote ,todo-only)
  4443. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4444. (setq files (org-agenda-files nil 'ifmode)
  4445. rtnall nil)
  4446. (while (setq file (pop files))
  4447. (catch 'nextfile
  4448. (org-check-agenda-file file)
  4449. (setq buffer (if (file-exists-p file)
  4450. (org-get-agenda-file-buffer file)
  4451. (error "No such file %s" file)))
  4452. (if (not buffer)
  4453. ;; If file does not exist, error message to agenda
  4454. (setq rtn (list
  4455. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4456. rtnall (append rtnall rtn))
  4457. (with-current-buffer buffer
  4458. (unless (derived-mode-p 'org-mode)
  4459. (error "Agenda file %s is not in `org-mode'" file))
  4460. (save-excursion
  4461. (save-restriction
  4462. (if (eq buffer org-agenda-restrict)
  4463. (narrow-to-region org-agenda-restrict-begin
  4464. org-agenda-restrict-end)
  4465. (widen))
  4466. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4467. (setq rtnall (append rtnall rtn))))))))
  4468. (if org-agenda-overriding-header
  4469. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4470. nil 'face 'org-agenda-structure) "\n")
  4471. (insert "Headlines with TAGS match: ")
  4472. (add-text-properties (point-min) (1- (point))
  4473. (list 'face 'org-agenda-structure
  4474. 'short-heading
  4475. (concat "Match: " match)))
  4476. (setq pos (point))
  4477. (insert match "\n")
  4478. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4479. (setq pos (point))
  4480. (unless org-agenda-multi
  4481. (insert "Press `C-u r' to search again with new search string\n"))
  4482. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4483. (org-agenda-mark-header-line (point-min))
  4484. (when rtnall
  4485. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4486. (goto-char (point-min))
  4487. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4488. (add-text-properties (point-min) (point-max)
  4489. `(org-agenda-type tags
  4490. org-last-args (,todo-only ,match)
  4491. org-redo-cmd ,org-agenda-redo-command
  4492. org-series-cmd ,org-cmd))
  4493. (org-agenda-finalize)
  4494. (setq buffer-read-only t))))
  4495. ;;; Agenda Finding stuck projects
  4496. (defvar org-agenda-skip-regexp nil
  4497. "Regular expression used in skipping subtrees for the agenda.
  4498. This is basically a temporary global variable that can be set and then
  4499. used by user-defined selections using `org-agenda-skip-function'.")
  4500. (defvar org-agenda-overriding-header nil
  4501. "When set during agenda, todo and tags searches it replaces the header.
  4502. This variable should not be set directly, but custom commands can bind it
  4503. in the options section.")
  4504. (defun org-agenda-skip-entry-when-regexp-matches ()
  4505. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4506. If yes, it returns the end position of this entry, causing agenda commands
  4507. to skip the entry but continuing the search in the subtree. This is a
  4508. function that can be put into `org-agenda-skip-function' for the duration
  4509. of a command."
  4510. (let ((end (save-excursion (org-end-of-subtree t)))
  4511. skip)
  4512. (save-excursion
  4513. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4514. (and skip end)))
  4515. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4516. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4517. If yes, it returns the end position of this tree, causing agenda commands
  4518. to skip this subtree. This is a function that can be put into
  4519. `org-agenda-skip-function' for the duration of a command."
  4520. (let ((end (save-excursion (org-end-of-subtree t)))
  4521. skip)
  4522. (save-excursion
  4523. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4524. (and skip end)))
  4525. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4526. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4527. If yes, it returns the end position of the current entry (NOT the tree),
  4528. causing agenda commands to skip the entry but continuing the search in
  4529. the subtree. This is a function that can be put into
  4530. `org-agenda-skip-function' for the duration of a command. An important
  4531. use of this function is for the stuck project list."
  4532. (let ((end (save-excursion (org-end-of-subtree t)))
  4533. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4534. skip)
  4535. (save-excursion
  4536. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4537. (and skip entry-end)))
  4538. (defun org-agenda-skip-entry-if (&rest conditions)
  4539. "Skip entry if any of CONDITIONS is true.
  4540. See `org-agenda-skip-if' for details."
  4541. (org-agenda-skip-if nil conditions))
  4542. (defun org-agenda-skip-subtree-if (&rest conditions)
  4543. "Skip subtree if any of CONDITIONS is true.
  4544. See `org-agenda-skip-if' for details."
  4545. (org-agenda-skip-if t conditions))
  4546. (defun org-agenda-skip-if (subtree conditions)
  4547. "Checks current entity for CONDITIONS.
  4548. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4549. the entry (i.e. the text before the next heading) is checked.
  4550. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4551. from different tests. Valid conditions are:
  4552. scheduled Check if there is a scheduled cookie
  4553. notscheduled Check if there is no scheduled cookie
  4554. deadline Check if there is a deadline
  4555. notdeadline Check if there is no deadline
  4556. timestamp Check if there is a timestamp (also deadline or scheduled)
  4557. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4558. regexp Check if regexp matches
  4559. notregexp Check if regexp does not match.
  4560. todo Check if TODO keyword matches
  4561. nottodo Check if TODO keyword does not match
  4562. The regexp is taken from the conditions list, it must come right after
  4563. the `regexp' or `notregexp' element.
  4564. `todo' and `nottodo' accept as an argument a list of todo
  4565. keywords, which may include \"*\" to match any todo keyword.
  4566. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4567. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4568. Instead of a list, a keyword class may be given. For example:
  4569. (org-agenda-skip-entry-if 'nottodo 'done)
  4570. would skip entries that haven't been marked with any of \"DONE\"
  4571. keywords. Possible classes are: `todo', `done', `any'.
  4572. If any of these conditions is met, this function returns the end point of
  4573. the entity, causing the search to continue from there. This is a function
  4574. that can be put into `org-agenda-skip-function' for the duration of a command."
  4575. (let (beg end m)
  4576. (org-back-to-heading t)
  4577. (setq beg (point)
  4578. end (if subtree
  4579. (progn (org-end-of-subtree t) (point))
  4580. (progn (outline-next-heading) (1- (point)))))
  4581. (goto-char beg)
  4582. (and
  4583. (or
  4584. (and (memq 'scheduled conditions)
  4585. (re-search-forward org-scheduled-time-regexp end t))
  4586. (and (memq 'notscheduled conditions)
  4587. (not (re-search-forward org-scheduled-time-regexp end t)))
  4588. (and (memq 'deadline conditions)
  4589. (re-search-forward org-deadline-time-regexp end t))
  4590. (and (memq 'notdeadline conditions)
  4591. (not (re-search-forward org-deadline-time-regexp end t)))
  4592. (and (memq 'timestamp conditions)
  4593. (re-search-forward org-ts-regexp end t))
  4594. (and (memq 'nottimestamp conditions)
  4595. (not (re-search-forward org-ts-regexp end t)))
  4596. (and (setq m (memq 'regexp conditions))
  4597. (stringp (nth 1 m))
  4598. (re-search-forward (nth 1 m) end t))
  4599. (and (setq m (memq 'notregexp conditions))
  4600. (stringp (nth 1 m))
  4601. (not (re-search-forward (nth 1 m) end t)))
  4602. (and (or
  4603. (setq m (memq 'nottodo conditions))
  4604. (setq m (memq 'todo-unblocked conditions))
  4605. (setq m (memq 'nottodo-unblocked conditions))
  4606. (setq m (memq 'todo conditions)))
  4607. (org-agenda-skip-if-todo m end)))
  4608. end)))
  4609. (defun org-agenda-skip-if-todo (args end)
  4610. "Helper function for `org-agenda-skip-if', do not use it directly.
  4611. ARGS is a list with first element either `todo', `nottodo',
  4612. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4613. a list of TODO keywords, or a state symbol `todo' or `done' or
  4614. `any'."
  4615. (let ((kw (car args))
  4616. (arg (cadr args))
  4617. todo-wds todo-re)
  4618. (setq todo-wds
  4619. (org-uniquify
  4620. (cond
  4621. ((listp arg) ;; list of keywords
  4622. (if (member "*" arg)
  4623. (mapcar 'substring-no-properties org-todo-keywords-1)
  4624. arg))
  4625. ((symbolp arg) ;; keyword class name
  4626. (cond
  4627. ((eq arg 'todo)
  4628. (org-delete-all org-done-keywords
  4629. (mapcar 'substring-no-properties
  4630. org-todo-keywords-1)))
  4631. ((eq arg 'done) org-done-keywords)
  4632. ((eq arg 'any)
  4633. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4634. (setq todo-re
  4635. (concat "^\\*+[ \t]+\\<\\("
  4636. (mapconcat 'identity todo-wds "\\|")
  4637. "\\)\\>"))
  4638. (cond
  4639. ((eq kw 'todo) (re-search-forward todo-re end t))
  4640. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4641. ((eq kw 'todo-unblocked)
  4642. (catch 'unblocked
  4643. (while (re-search-forward todo-re end t)
  4644. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4645. nil))
  4646. ((eq kw 'nottodo-unblocked)
  4647. (catch 'unblocked
  4648. (while (re-search-forward todo-re end t)
  4649. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4650. t))
  4651. )))
  4652. ;;;###autoload
  4653. (defun org-agenda-list-stuck-projects (&rest ignore)
  4654. "Create agenda view for projects that are stuck.
  4655. Stuck projects are project that have no next actions. For the definitions
  4656. of what a project is and how to check if it stuck, customize the variable
  4657. `org-stuck-projects'."
  4658. (interactive)
  4659. (let* ((org-agenda-skip-function
  4660. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4661. ;; We could have used org-agenda-skip-if here.
  4662. (org-agenda-overriding-header
  4663. (or org-agenda-overriding-header "List of stuck projects: "))
  4664. (matcher (nth 0 org-stuck-projects))
  4665. (todo (nth 1 org-stuck-projects))
  4666. (todo-wds (if (member "*" todo)
  4667. (progn
  4668. (org-agenda-prepare-buffers (org-agenda-files
  4669. nil 'ifmode))
  4670. (org-delete-all
  4671. org-done-keywords-for-agenda
  4672. (copy-sequence org-todo-keywords-for-agenda)))
  4673. todo))
  4674. (todo-re (concat "^\\*+[ \t]+\\("
  4675. (mapconcat 'identity todo-wds "\\|")
  4676. "\\)\\>"))
  4677. (tags (nth 2 org-stuck-projects))
  4678. (tags-re (if (member "*" tags)
  4679. (concat org-outline-regexp-bol
  4680. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4681. (if tags
  4682. (concat org-outline-regexp-bol
  4683. ".*:\\("
  4684. (mapconcat 'identity tags "\\|")
  4685. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4686. (gen-re (nth 3 org-stuck-projects))
  4687. (re-list
  4688. (delq nil
  4689. (list
  4690. (if todo todo-re)
  4691. (if tags tags-re)
  4692. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4693. gen-re)))))
  4694. (setq org-agenda-skip-regexp
  4695. (if re-list
  4696. (mapconcat 'identity re-list "\\|")
  4697. (error "No information how to identify unstuck projects")))
  4698. (org-tags-view nil matcher)
  4699. (setq org-agenda-buffer-name (buffer-name))
  4700. (with-current-buffer org-agenda-buffer-name
  4701. (setq org-agenda-redo-command
  4702. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4703. ;;; Diary integration
  4704. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4705. (defvar diary-list-entries-hook)
  4706. (defvar diary-time-regexp)
  4707. (defun org-get-entries-from-diary (date)
  4708. "Get the (Emacs Calendar) diary entries for DATE."
  4709. (require 'diary-lib)
  4710. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4711. (diary-display-hook '(fancy-diary-display))
  4712. (diary-display-function 'fancy-diary-display)
  4713. (pop-up-frames nil)
  4714. (diary-list-entries-hook
  4715. (cons 'org-diary-default-entry diary-list-entries-hook))
  4716. (diary-file-name-prefix nil) ; turn this feature off
  4717. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4718. entries
  4719. (org-disable-agenda-to-diary t))
  4720. (save-excursion
  4721. (save-window-excursion
  4722. (funcall (if (fboundp 'diary-list-entries)
  4723. 'diary-list-entries 'list-diary-entries)
  4724. date 1)))
  4725. (if (not (get-buffer diary-fancy-buffer))
  4726. (setq entries nil)
  4727. (with-current-buffer diary-fancy-buffer
  4728. (setq buffer-read-only nil)
  4729. (if (zerop (buffer-size))
  4730. ;; No entries
  4731. (setq entries nil)
  4732. ;; Omit the date and other unnecessary stuff
  4733. (org-agenda-cleanup-fancy-diary)
  4734. ;; Add prefix to each line and extend the text properties
  4735. (if (zerop (buffer-size))
  4736. (setq entries nil)
  4737. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4738. (setq entries
  4739. (with-temp-buffer
  4740. (insert entries) (goto-char (point-min))
  4741. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4742. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4743. (replace-match (concat "; " (match-string 1)))))
  4744. (buffer-string)))))
  4745. (set-buffer-modified-p nil)
  4746. (kill-buffer diary-fancy-buffer)))
  4747. (when entries
  4748. (setq entries (org-split-string entries "\n"))
  4749. (setq entries
  4750. (mapcar
  4751. (lambda (x)
  4752. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4753. ;; Extend the text properties to the beginning of the line
  4754. (org-add-props x (text-properties-at (1- (length x)) x)
  4755. 'type "diary" 'date date 'face 'org-agenda-diary))
  4756. entries)))))
  4757. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4758. "Hook run when the fancy diary buffer is cleaned up.")
  4759. (defun org-agenda-cleanup-fancy-diary ()
  4760. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4761. This gets rid of the date, the underline under the date, and
  4762. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4763. date. It also removes lines that contain only whitespace."
  4764. (goto-char (point-min))
  4765. (if (looking-at ".*?:[ \t]*")
  4766. (progn
  4767. (replace-match "")
  4768. (re-search-forward "\n=+$" nil t)
  4769. (replace-match "")
  4770. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4771. (re-search-forward "\n=+$" nil t)
  4772. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4773. (goto-char (point-min))
  4774. (while (re-search-forward "^ +\n" nil t)
  4775. (replace-match ""))
  4776. (goto-char (point-min))
  4777. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4778. (replace-match ""))
  4779. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4780. ;; Make sure entries from the diary have the right text properties.
  4781. (eval-after-load "diary-lib"
  4782. '(if (boundp 'diary-modify-entry-list-string-function)
  4783. ;; We can rely on the hook, nothing to do
  4784. nil
  4785. ;; Hook not available, must use advice to make this work
  4786. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4787. "Make the position visible."
  4788. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4789. (stringp string)
  4790. buffer-file-name)
  4791. (setq string (org-modify-diary-entry-string string))))))
  4792. (defun org-modify-diary-entry-string (string)
  4793. "Add text properties to string, allowing org-mode to act on it."
  4794. (org-add-props string nil
  4795. 'mouse-face 'highlight
  4796. 'help-echo (if buffer-file-name
  4797. (format "mouse-2 or RET jump to diary file %s"
  4798. (abbreviate-file-name buffer-file-name))
  4799. "")
  4800. 'org-agenda-diary-link t
  4801. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4802. (defun org-diary-default-entry ()
  4803. "Add a dummy entry to the diary.
  4804. Needed to avoid empty dates which mess up holiday display."
  4805. ;; Catch the error if dealing with the new add-to-diary-alist
  4806. (when org-disable-agenda-to-diary
  4807. (condition-case nil
  4808. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4809. (error
  4810. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4811. (defun org-add-to-diary-list (&rest args)
  4812. (if (fboundp 'diary-add-to-list)
  4813. (apply 'diary-add-to-list args)
  4814. (apply 'add-to-diary-list args)))
  4815. (defvar org-diary-last-run-time nil)
  4816. ;;;###autoload
  4817. (defun org-diary (&rest args)
  4818. "Return diary information from org files.
  4819. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4820. It accesses org files and extracts information from those files to be
  4821. listed in the diary. The function accepts arguments specifying what
  4822. items should be listed. For a list of arguments allowed here, see the
  4823. variable `org-agenda-entry-types'.
  4824. The call in the diary file should look like this:
  4825. &%%(org-diary) ~/path/to/some/orgfile.org
  4826. Use a separate line for each org file to check. Or, if you omit the file name,
  4827. all files listed in `org-agenda-files' will be checked automatically:
  4828. &%%(org-diary)
  4829. If you don't give any arguments (as in the example above), the default value
  4830. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4831. So the example above may also be written as
  4832. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4833. The function expects the lisp variables `entry' and `date' to be provided
  4834. by the caller, because this is how the calendar works. Don't use this
  4835. function from a program - use `org-agenda-get-day-entries' instead."
  4836. (when (> (- (org-float-time)
  4837. org-agenda-last-marker-time)
  4838. 5)
  4839. ;; I am not sure if this works with sticky agendas, because the marker
  4840. ;; list is then no longer a global variable.
  4841. (org-agenda-reset-markers))
  4842. (org-compile-prefix-format 'agenda)
  4843. (org-set-sorting-strategy 'agenda)
  4844. (setq args (or args org-agenda-entry-types))
  4845. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4846. (list entry)
  4847. (org-agenda-files t)))
  4848. (time (org-float-time))
  4849. file rtn results)
  4850. (when (or (not org-diary-last-run-time)
  4851. (> (- time
  4852. org-diary-last-run-time)
  4853. 3))
  4854. (org-agenda-prepare-buffers files))
  4855. (setq org-diary-last-run-time time)
  4856. ;; If this is called during org-agenda, don't return any entries to
  4857. ;; the calendar. Org Agenda will list these entries itself.
  4858. (if org-disable-agenda-to-diary (setq files nil))
  4859. (while (setq file (pop files))
  4860. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4861. (setq results (append results rtn)))
  4862. (when results
  4863. (setq results
  4864. (mapcar (lambda (i) (replace-regexp-in-string
  4865. org-bracket-link-regexp "\\3" i)) results))
  4866. (concat (org-agenda-finalize-entries results) "\n"))))
  4867. ;;; Agenda entry finders
  4868. (defun org-agenda-get-day-entries (file date &rest args)
  4869. "Does the work for `org-diary' and `org-agenda'.
  4870. FILE is the path to a file to be checked for entries. DATE is date like
  4871. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4872. which kind of entries should be extracted. For details about these, see
  4873. the documentation of `org-diary'."
  4874. (setq args (or args org-agenda-entry-types))
  4875. (let* ((org-startup-folded nil)
  4876. (org-startup-align-all-tables nil)
  4877. (buffer (if (file-exists-p file)
  4878. (org-get-agenda-file-buffer file)
  4879. (error "No such file %s" file)))
  4880. arg results rtn deadline-results)
  4881. (if (not buffer)
  4882. ;; If file does not exist, make sure an error message ends up in diary
  4883. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4884. (with-current-buffer buffer
  4885. (unless (derived-mode-p 'org-mode)
  4886. (error "Agenda file %s is not in `org-mode'" file))
  4887. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4888. (let ((case-fold-search nil))
  4889. (save-excursion
  4890. (save-restriction
  4891. (if (eq buffer org-agenda-restrict)
  4892. (narrow-to-region org-agenda-restrict-begin
  4893. org-agenda-restrict-end)
  4894. (widen))
  4895. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4896. (while (setq arg (pop args))
  4897. (cond
  4898. ((and (eq arg :todo)
  4899. (equal date (calendar-gregorian-from-absolute
  4900. (org-today))))
  4901. (setq rtn (org-agenda-get-todos))
  4902. (setq results (append results rtn)))
  4903. ((eq arg :timestamp)
  4904. (setq rtn (org-agenda-get-blocks))
  4905. (setq results (append results rtn))
  4906. (setq rtn (org-agenda-get-timestamps deadline-results))
  4907. (setq results (append results rtn)))
  4908. ((eq arg :sexp)
  4909. (setq rtn (org-agenda-get-sexps))
  4910. (setq results (append results rtn)))
  4911. ((eq arg :scheduled)
  4912. (setq rtn (org-agenda-get-scheduled deadline-results))
  4913. (setq results (append results rtn)))
  4914. ((eq arg :scheduled*)
  4915. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4916. (setq results (append results rtn)))
  4917. ((eq arg :closed)
  4918. (setq rtn (org-agenda-get-progress))
  4919. (setq results (append results rtn)))
  4920. ((eq arg :deadline)
  4921. (setq rtn (org-agenda-get-deadlines))
  4922. (setq deadline-results (copy-sequence rtn))
  4923. (setq results (append results rtn)))
  4924. ((eq arg :deadline*)
  4925. (setq rtn (org-agenda-get-deadlines t))
  4926. (setq deadline-results (copy-sequence rtn))
  4927. (setq results (append results rtn))))))))
  4928. results))))
  4929. (defsubst org-em (x y list)
  4930. "Is X or Y a member of LIST?"
  4931. (or (memq x list) (memq y list)))
  4932. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4933. (defvar org-agenda-sorting-strategy-selected nil)
  4934. (defun org-agenda-get-todos ()
  4935. "Return the TODO information for agenda display."
  4936. (let* ((props (list 'face nil
  4937. 'done-face 'org-agenda-done
  4938. 'org-not-done-regexp org-not-done-regexp
  4939. 'org-todo-regexp org-todo-regexp
  4940. 'org-complex-heading-regexp org-complex-heading-regexp
  4941. 'mouse-face 'highlight
  4942. 'help-echo
  4943. (format "mouse-2 or RET jump to org file %s"
  4944. (abbreviate-file-name buffer-file-name))))
  4945. (regexp (format org-heading-keyword-regexp-format
  4946. (cond
  4947. ((and org-select-this-todo-keyword
  4948. (equal org-select-this-todo-keyword "*"))
  4949. org-todo-regexp)
  4950. (org-select-this-todo-keyword
  4951. (concat "\\("
  4952. (mapconcat 'identity
  4953. (org-split-string
  4954. org-select-this-todo-keyword
  4955. "|")
  4956. "\\|") "\\)"))
  4957. (t org-not-done-regexp))))
  4958. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4959. ee txt beg end inherited-tags todo-state-end-pos)
  4960. (goto-char (point-min))
  4961. (while (re-search-forward regexp nil t)
  4962. (catch :skip
  4963. (save-match-data
  4964. (beginning-of-line)
  4965. (org-agenda-skip)
  4966. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4967. (unless (and (setq todo-state (org-get-todo-state))
  4968. (setq todo-state-end-pos (match-end 2)))
  4969. (goto-char end)
  4970. (throw :skip nil))
  4971. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4972. (goto-char (1+ beg))
  4973. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4974. (throw :skip nil)))
  4975. (goto-char (match-beginning 2))
  4976. (setq marker (org-agenda-new-marker (match-beginning 0))
  4977. category (org-get-category)
  4978. ts-date (let (ts)
  4979. (save-match-data
  4980. (cond ((org-em 'scheduled-up 'scheduled-down
  4981. org-agenda-sorting-strategy-selected)
  4982. (setq ts (org-entry-get (point) "SCHEDULED")
  4983. ts-date-type " scheduled"))
  4984. ((org-em 'deadline-up 'deadline-down
  4985. org-agenda-sorting-strategy-selected)
  4986. (setq ts (org-entry-get (point) "DEADLINE")
  4987. ts-date-type " deadline"))
  4988. ((org-em 'ts-up 'ts-down
  4989. org-agenda-sorting-strategy-selected)
  4990. (setq ts (org-entry-get (point) "TIMESTAMP")
  4991. ts-date-type " timestamp"))
  4992. ((org-em 'tsia-up 'tsia-down
  4993. org-agenda-sorting-strategy-selected)
  4994. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4995. ts-date-type " timestamp_ia"))
  4996. ((org-em 'timestamp-up 'timestamp-down
  4997. org-agenda-sorting-strategy-selected)
  4998. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4999. (org-entry-get (point) "DEADLINE")
  5000. (org-entry-get (point) "TIMESTAMP")
  5001. (org-entry-get (point) "TIMESTAMP_IA"))
  5002. ts-date-type ""))
  5003. (t (setq ts-date-type "")))
  5004. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  5005. category-pos (get-text-property (point) 'org-category-position)
  5006. txt (org-trim
  5007. (buffer-substring (match-beginning 2) (match-end 0)))
  5008. inherited-tags
  5009. (or (eq org-agenda-show-inherited-tags 'always)
  5010. (and (listp org-agenda-show-inherited-tags)
  5011. (memq 'todo org-agenda-show-inherited-tags))
  5012. (and (eq org-agenda-show-inherited-tags t)
  5013. (or (eq org-agenda-use-tag-inheritance t)
  5014. (memq 'todo org-agenda-use-tag-inheritance))))
  5015. tags (org-get-tags-at nil (not inherited-tags))
  5016. level (make-string (org-reduced-level (org-outline-level)) ? )
  5017. txt (org-agenda-format-item "" txt level category tags t)
  5018. priority (1+ (org-get-priority txt)))
  5019. (org-add-props txt props
  5020. 'org-marker marker 'org-hd-marker marker
  5021. 'priority priority 'org-category category
  5022. 'level level
  5023. 'ts-date ts-date
  5024. 'org-category-position category-pos
  5025. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5026. (push txt ee)
  5027. (if org-agenda-todo-list-sublevels
  5028. (goto-char todo-state-end-pos)
  5029. (org-end-of-subtree 'invisible))))
  5030. (nreverse ee)))
  5031. (defun org-agenda-todo-custom-ignore-p (time n)
  5032. "Check whether timestamp is farther away than n number of days.
  5033. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5034. `org-agenda-todo-ignore-scheduled' or
  5035. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5036. (let ((days (org-time-stamp-to-now
  5037. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5038. (if (>= n 0)
  5039. (>= days n)
  5040. (<= days n))))
  5041. ;;;###autoload
  5042. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5043. (&optional end)
  5044. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5045. (when (or org-agenda-todo-ignore-with-date
  5046. org-agenda-todo-ignore-scheduled
  5047. org-agenda-todo-ignore-deadlines
  5048. org-agenda-todo-ignore-timestamp)
  5049. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5050. (save-excursion
  5051. (or (and org-agenda-todo-ignore-with-date
  5052. (re-search-forward org-ts-regexp end t))
  5053. (and org-agenda-todo-ignore-scheduled
  5054. (re-search-forward org-scheduled-time-regexp end t)
  5055. (cond
  5056. ((eq org-agenda-todo-ignore-scheduled 'future)
  5057. (> (org-time-stamp-to-now
  5058. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5059. ((eq org-agenda-todo-ignore-scheduled 'past)
  5060. (<= (org-time-stamp-to-now
  5061. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5062. ((numberp org-agenda-todo-ignore-scheduled)
  5063. (org-agenda-todo-custom-ignore-p
  5064. (match-string 1) org-agenda-todo-ignore-scheduled))
  5065. (t)))
  5066. (and org-agenda-todo-ignore-deadlines
  5067. (re-search-forward org-deadline-time-regexp end t)
  5068. (cond
  5069. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5070. ((eq org-agenda-todo-ignore-deadlines 'far)
  5071. (not (org-deadline-close (match-string 1))))
  5072. ((eq org-agenda-todo-ignore-deadlines 'future)
  5073. (> (org-time-stamp-to-now
  5074. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5075. ((eq org-agenda-todo-ignore-deadlines 'past)
  5076. (<= (org-time-stamp-to-now
  5077. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5078. ((numberp org-agenda-todo-ignore-deadlines)
  5079. (org-agenda-todo-custom-ignore-p
  5080. (match-string 1) org-agenda-todo-ignore-deadlines))
  5081. (t (org-deadline-close (match-string 1)))))
  5082. (and org-agenda-todo-ignore-timestamp
  5083. (let ((buffer (current-buffer))
  5084. (regexp
  5085. (concat
  5086. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5087. (start (point)))
  5088. ;; Copy current buffer into a temporary one
  5089. (with-temp-buffer
  5090. (insert-buffer-substring buffer start end)
  5091. (goto-char (point-min))
  5092. ;; Delete SCHEDULED and DEADLINE items
  5093. (while (re-search-forward regexp end t)
  5094. (delete-region (match-beginning 0) (match-end 0)))
  5095. (goto-char (point-min))
  5096. ;; No search for timestamp left
  5097. (when (re-search-forward org-ts-regexp nil t)
  5098. (cond
  5099. ((eq org-agenda-todo-ignore-timestamp 'future)
  5100. (> (org-time-stamp-to-now
  5101. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5102. ((eq org-agenda-todo-ignore-timestamp 'past)
  5103. (<= (org-time-stamp-to-now
  5104. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5105. ((numberp org-agenda-todo-ignore-timestamp)
  5106. (org-agenda-todo-custom-ignore-p
  5107. (match-string 1) org-agenda-todo-ignore-timestamp))
  5108. (t))))))))))
  5109. (defun org-agenda-get-timestamps (&optional deadline-results)
  5110. "Return the date stamp information for agenda display."
  5111. (let* ((props (list 'face 'org-agenda-calendar-event
  5112. 'org-not-done-regexp org-not-done-regexp
  5113. 'org-todo-regexp org-todo-regexp
  5114. 'org-complex-heading-regexp org-complex-heading-regexp
  5115. 'mouse-face 'highlight
  5116. 'help-echo
  5117. (format "mouse-2 or RET jump to org file %s"
  5118. (abbreviate-file-name buffer-file-name))))
  5119. (d1 (calendar-absolute-from-gregorian date))
  5120. mm
  5121. (deadline-position-alist
  5122. (mapcar (lambda (a) (and (setq mm (get-text-property
  5123. 0 'org-hd-marker a))
  5124. (cons (marker-position mm) a)))
  5125. deadline-results))
  5126. (remove-re org-ts-regexp)
  5127. (regexp
  5128. (concat
  5129. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5130. (regexp-quote
  5131. (substring
  5132. (format-time-string
  5133. (car org-time-stamp-formats)
  5134. (apply 'encode-time ; DATE bound by calendar
  5135. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5136. 1 11))
  5137. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5138. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5139. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5140. donep tmp priority category category-pos level ee txt timestr tags
  5141. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5142. inherited-tags ts-date)
  5143. (goto-char (point-min))
  5144. (while (setq end-of-match (re-search-forward regexp nil t))
  5145. (setq b0 (match-beginning 0)
  5146. b3 (match-beginning 3) e3 (match-end 3)
  5147. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5148. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5149. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5150. (member todo-state
  5151. org-agenda-repeating-timestamp-show-all)))
  5152. (catch :skip
  5153. (and (org-at-date-range-p) (throw :skip nil))
  5154. (org-agenda-skip)
  5155. (if (and (match-end 1)
  5156. (not (= d1 (org-time-string-to-absolute
  5157. (match-string 1) d1 nil show-all
  5158. (current-buffer) b0))))
  5159. (throw :skip nil))
  5160. (if (and e3
  5161. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5162. (throw :skip nil))
  5163. (setq tmp (buffer-substring (max (point-min)
  5164. (- b0 org-ds-keyword-length))
  5165. b0)
  5166. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5167. inactivep (= (char-after b0) ?\[)
  5168. deadlinep (string-match org-deadline-regexp tmp)
  5169. scheduledp (string-match org-scheduled-regexp tmp)
  5170. closedp (and org-agenda-include-inactive-timestamps
  5171. (string-match org-closed-string tmp))
  5172. clockp (and org-agenda-include-inactive-timestamps
  5173. (or (string-match org-clock-string tmp)
  5174. (string-match "]-+\\'" tmp)))
  5175. warntime (get-text-property (point) 'org-appt-warntime)
  5176. donep (member todo-state org-done-keywords))
  5177. (if (or scheduledp deadlinep closedp clockp
  5178. (and donep org-agenda-skip-timestamp-if-done))
  5179. (throw :skip t))
  5180. (if (string-match ">" timestr)
  5181. ;; substring should only run to end of time stamp
  5182. (setq timestr (substring timestr 0 (match-end 0))))
  5183. (setq marker (org-agenda-new-marker b0)
  5184. category (org-get-category b0)
  5185. category-pos (get-text-property b0 'org-category-position))
  5186. (save-excursion
  5187. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5188. (throw :skip nil)
  5189. (goto-char (match-beginning 0))
  5190. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5191. (assoc (point) deadline-position-alist))
  5192. (throw :skip nil))
  5193. (setq hdmarker (org-agenda-new-marker)
  5194. inherited-tags
  5195. (or (eq org-agenda-show-inherited-tags 'always)
  5196. (and (listp org-agenda-show-inherited-tags)
  5197. (memq 'agenda org-agenda-show-inherited-tags))
  5198. (and (eq org-agenda-show-inherited-tags t)
  5199. (or (eq org-agenda-use-tag-inheritance t)
  5200. (memq 'agenda org-agenda-use-tag-inheritance))))
  5201. tags (org-get-tags-at nil (not inherited-tags))
  5202. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5203. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5204. (setq head (or (match-string 1) ""))
  5205. (setq txt (org-agenda-format-item
  5206. (if inactivep org-agenda-inactive-leader nil)
  5207. head level category tags timestr
  5208. remove-re habitp)))
  5209. (setq priority (org-get-priority txt))
  5210. (org-add-props txt props 'priority priority
  5211. 'org-marker marker 'org-hd-marker hdmarker
  5212. 'org-category category 'date date
  5213. 'level level
  5214. 'ts-date
  5215. (ignore-errors (org-time-string-to-absolute timestr))
  5216. 'org-category-position category-pos
  5217. 'todo-state todo-state
  5218. 'warntime warntime
  5219. 'type "timestamp")
  5220. (push txt ee))
  5221. (if org-agenda-skip-additional-timestamps-same-entry
  5222. (outline-next-heading)
  5223. (goto-char end-of-match))))
  5224. (nreverse ee)))
  5225. (defun org-agenda-get-sexps ()
  5226. "Return the sexp information for agenda display."
  5227. (require 'diary-lib)
  5228. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5229. 'mouse-face 'highlight
  5230. 'help-echo
  5231. (format "mouse-2 or RET jump to org file %s"
  5232. (abbreviate-file-name buffer-file-name))))
  5233. (regexp "^&?%%(")
  5234. marker category extra category-pos level ee txt tags entry
  5235. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5236. (goto-char (point-min))
  5237. (while (re-search-forward regexp nil t)
  5238. (catch :skip
  5239. (org-agenda-skip)
  5240. (setq beg (match-beginning 0))
  5241. (goto-char (1- (match-end 0)))
  5242. (setq b (point))
  5243. (forward-sexp 1)
  5244. (setq sexp (buffer-substring b (point)))
  5245. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5246. (org-trim (match-string 1))
  5247. ""))
  5248. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5249. (when result
  5250. (setq marker (org-agenda-new-marker beg)
  5251. level (make-string (org-reduced-level (org-outline-level)) ? )
  5252. category (org-get-category beg)
  5253. category-pos (get-text-property beg 'org-category-position)
  5254. inherited-tags
  5255. (or (eq org-agenda-show-inherited-tags 'always)
  5256. (and (listp org-agenda-show-inherited-tags)
  5257. (memq 'agenda org-agenda-show-inherited-tags))
  5258. (and (eq org-agenda-show-inherited-tags t)
  5259. (or (eq org-agenda-use-tag-inheritance t)
  5260. (memq 'agenda org-agenda-use-tag-inheritance))))
  5261. tags (org-get-tags-at nil (not inherited-tags))
  5262. todo-state (org-get-todo-state)
  5263. warntime (get-text-property (point) 'org-appt-warntime)
  5264. extra nil)
  5265. (dolist (r (if (stringp result)
  5266. (list result)
  5267. result)) ;; we expect a list here
  5268. (when (and org-agenda-diary-sexp-prefix
  5269. (string-match org-agenda-diary-sexp-prefix r))
  5270. (setq extra (match-string 0 r)
  5271. r (replace-match "" nil nil r)))
  5272. (if (string-match "\\S-" r)
  5273. (setq txt r)
  5274. (setq txt "SEXP entry returned empty string"))
  5275. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5276. (org-add-props txt props 'org-marker marker
  5277. 'org-category category 'date date 'todo-state todo-state
  5278. 'org-category-position category-pos 'tags tags
  5279. 'level level
  5280. 'type "sexp" 'warntime warntime)
  5281. (push txt ee)))))
  5282. (nreverse ee)))
  5283. ;; Calendar sanity: define some functions that are independent of
  5284. ;; `calendar-date-style'.
  5285. ;; Normally I would like to use ISO format when calling the diary functions,
  5286. ;; but to make sure we still have Emacs 22 compatibility we bind
  5287. ;; also `european-calendar-style' and use european format
  5288. (defun org-anniversary (year month day &optional mark)
  5289. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5290. (org-no-warnings
  5291. (let ((calendar-date-style 'european) (european-calendar-style t))
  5292. (diary-anniversary day month year mark))))
  5293. (defun org-cyclic (N year month day &optional mark)
  5294. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5295. (org-no-warnings
  5296. (let ((calendar-date-style 'european) (european-calendar-style t))
  5297. (diary-cyclic N day month year mark))))
  5298. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5299. "Like `diary-block', but with fixed (ISO) order of arguments."
  5300. (org-no-warnings
  5301. (let ((calendar-date-style 'european) (european-calendar-style t))
  5302. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5303. (defun org-date (year month day &optional mark)
  5304. "Like `diary-date', but with fixed (ISO) order of arguments."
  5305. (org-no-warnings
  5306. (let ((calendar-date-style 'european) (european-calendar-style t))
  5307. (diary-date day month year mark))))
  5308. ;; Define the` org-class' function
  5309. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5310. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5311. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5312. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5313. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5314. `holidays', then any date that is known by the Emacs calendar to be a
  5315. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5316. then those holidays will be skipped."
  5317. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5318. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5319. (d (calendar-absolute-from-gregorian date))
  5320. (h (when skip-weeks (calendar-check-holidays date))))
  5321. (and
  5322. (<= date1 d)
  5323. (<= d date2)
  5324. (= (calendar-day-of-week date) dayname)
  5325. (or (not skip-weeks)
  5326. (progn
  5327. (require 'cal-iso)
  5328. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5329. (not (or (and h (memq 'holidays skip-weeks))
  5330. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5331. entry)))
  5332. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5333. "Like `org-class', but honor `calendar-date-style'.
  5334. The order of the first 2 times 3 arguments depends on the variable
  5335. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5336. So for American calendars, give this as MONTH DAY YEAR, for European as
  5337. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5338. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5339. is any number of ISO weeks in the block period for which the item should
  5340. be skipped.
  5341. This function is here only for backward compatibility and it is deprecated,
  5342. please use `org-class' instead."
  5343. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5344. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5345. (org-class
  5346. (nth 2 date1) (car date1) (nth 1 date1)
  5347. (nth 2 date2) (car date2) (nth 1 date2)
  5348. dayname skip-weeks)))
  5349. (make-obsolete 'org-diary-class 'org-class "")
  5350. (defalias 'org-get-closed 'org-agenda-get-progress)
  5351. (defun org-agenda-get-progress ()
  5352. "Return the logged TODO entries for agenda display."
  5353. (let* ((props (list 'mouse-face 'highlight
  5354. 'org-not-done-regexp org-not-done-regexp
  5355. 'org-todo-regexp org-todo-regexp
  5356. 'org-complex-heading-regexp org-complex-heading-regexp
  5357. 'help-echo
  5358. (format "mouse-2 or RET jump to org file %s"
  5359. (abbreviate-file-name buffer-file-name))))
  5360. (items (if (consp org-agenda-show-log-scoped)
  5361. org-agenda-show-log-scoped
  5362. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5363. '(clock)
  5364. org-agenda-log-mode-items)))
  5365. (parts
  5366. (delq nil
  5367. (list
  5368. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5369. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5370. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5371. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5372. (error "`org-agenda-log-mode-items' is empty")))
  5373. (regexp (concat
  5374. "\\(" parts-re "\\)"
  5375. " *\\["
  5376. (regexp-quote
  5377. (substring
  5378. (format-time-string
  5379. (car org-time-stamp-formats)
  5380. (apply 'encode-time ; DATE bound by calendar
  5381. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5382. 1 11))))
  5383. (org-agenda-search-headline-for-time nil)
  5384. marker hdmarker priority category category-pos level tags closedp
  5385. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5386. (goto-char (point-min))
  5387. (while (re-search-forward regexp nil t)
  5388. (catch :skip
  5389. (org-agenda-skip)
  5390. (setq marker (org-agenda-new-marker (match-beginning 0))
  5391. closedp (equal (match-string 1) org-closed-string)
  5392. statep (equal (string-to-char (match-string 1)) ?-)
  5393. clockp (not (or closedp statep))
  5394. state (and statep (match-string 2))
  5395. category (org-get-category (match-beginning 0))
  5396. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5397. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5398. (when (string-match "\\]" timestr)
  5399. ;; substring should only run to end of time stamp
  5400. (setq rest (substring timestr (match-end 0))
  5401. timestr (substring timestr 0 (match-end 0)))
  5402. (if (and (not closedp) (not statep)
  5403. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5404. rest))
  5405. (progn (setq timestr (concat (substring timestr 0 -1)
  5406. "-" (match-string 1 rest) "]"))
  5407. (setq clocked (match-string 2 rest)))
  5408. (setq clocked "-")))
  5409. (save-excursion
  5410. (setq extra
  5411. (cond
  5412. ((not org-agenda-log-mode-add-notes) nil)
  5413. (statep
  5414. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5415. (match-string 1)))
  5416. (clockp
  5417. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5418. (match-string 1)))))
  5419. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5420. (throw :skip nil)
  5421. (goto-char (match-beginning 0))
  5422. (setq hdmarker (org-agenda-new-marker)
  5423. inherited-tags
  5424. (or (eq org-agenda-show-inherited-tags 'always)
  5425. (and (listp org-agenda-show-inherited-tags)
  5426. (memq 'todo org-agenda-show-inherited-tags))
  5427. (and (eq org-agenda-show-inherited-tags t)
  5428. (or (eq org-agenda-use-tag-inheritance t)
  5429. (memq 'todo org-agenda-use-tag-inheritance))))
  5430. tags (org-get-tags-at nil (not inherited-tags))
  5431. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5432. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5433. (setq txt (match-string 1))
  5434. (when extra
  5435. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5436. (setq txt (concat (substring txt 0 (match-beginning 1))
  5437. " - " extra " " (match-string 2 txt)))
  5438. (setq txt (concat txt " - " extra))))
  5439. (setq txt (org-agenda-format-item
  5440. (cond
  5441. (closedp "Closed: ")
  5442. (statep (concat "State: (" state ")"))
  5443. (t (concat "Clocked: (" clocked ")")))
  5444. txt level category tags timestr)))
  5445. (setq priority 100000)
  5446. (org-add-props txt props
  5447. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5448. 'priority priority 'org-category category
  5449. 'org-category-position category-pos
  5450. 'level level
  5451. 'type "closed" 'date date
  5452. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5453. (push txt ee))
  5454. (goto-char (point-at-eol))))
  5455. (nreverse ee)))
  5456. (defun org-agenda-show-clocking-issues ()
  5457. "Add overlays, showing issues with clocking.
  5458. See also the user option `org-agenda-clock-consistency-checks'."
  5459. (interactive)
  5460. (let* ((org-time-clocksum-use-effort-durations nil)
  5461. (pl org-agenda-clock-consistency-checks)
  5462. (re (concat "^[ \t]*"
  5463. org-clock-string
  5464. "[ \t]+"
  5465. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5466. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5467. (tlstart 0.)
  5468. (tlend 0.)
  5469. (maxtime (org-hh:mm-string-to-minutes
  5470. (or (plist-get pl :max-duration) "24:00")))
  5471. (mintime (org-hh:mm-string-to-minutes
  5472. (or (plist-get pl :min-duration) 0)))
  5473. (maxgap (org-hh:mm-string-to-minutes
  5474. ;; default 30:00 means never complain
  5475. (or (plist-get pl :max-gap) "30:00")))
  5476. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5477. (plist-get pl :gap-ok-around)))
  5478. (def-face (or (plist-get pl :default-face)
  5479. '((:background "DarkRed") (:foreground "white"))))
  5480. issue face m te ts dt ov)
  5481. (goto-char (point-min))
  5482. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5483. (setq issue nil face def-face)
  5484. (catch 'next
  5485. (setq m (org-get-at-bol 'org-marker)
  5486. te nil ts nil)
  5487. (unless (and m (markerp m))
  5488. (setq issue "No valid clock line") (throw 'next t))
  5489. (org-with-point-at m
  5490. (save-excursion
  5491. (goto-char (point-at-bol))
  5492. (unless (looking-at re)
  5493. (error "No valid Clock line")
  5494. (throw 'next t))
  5495. (unless (match-end 3)
  5496. (setq issue "No end time"
  5497. face (or (plist-get pl :no-end-time-face) face))
  5498. (throw 'next t))
  5499. (setq ts (match-string 1)
  5500. te (match-string 3)
  5501. ts (org-float-time
  5502. (apply 'encode-time (org-parse-time-string ts)))
  5503. te (org-float-time
  5504. (apply 'encode-time (org-parse-time-string te)))
  5505. dt (- te ts))))
  5506. (cond
  5507. ((> dt (* 60 maxtime))
  5508. ;; a very long clocking chunk
  5509. (setq issue (format "Clocking interval is very long: %s"
  5510. (org-minutes-to-clocksum-string
  5511. (floor (/ (float dt) 60.))))
  5512. face (or (plist-get pl :long-face) face)))
  5513. ((< dt (* 60 mintime))
  5514. ;; a very short clocking chunk
  5515. (setq issue (format "Clocking interval is very short: %s"
  5516. (org-minutes-to-clocksum-string
  5517. (floor (/ (float dt) 60.))))
  5518. face (or (plist-get pl :short-face) face)))
  5519. ((and (> tlend 0) (< ts tlend))
  5520. ;; Two clock entries are overlapping
  5521. (setq issue (format "Clocking overlap: %d minutes"
  5522. (/ (- tlend ts) 60))
  5523. face (or (plist-get pl :overlap-face) face)))
  5524. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5525. ;; There is a gap, lets see if we need to report it
  5526. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5527. (setq issue (format "Clocking gap: %d minutes"
  5528. (/ (- ts tlend) 60))
  5529. face (or (plist-get pl :gap-face) face))))
  5530. (t nil)))
  5531. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5532. (when issue
  5533. ;; OK, there was some issue, add an overlay to show the issue
  5534. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5535. (overlay-put ov 'before-string
  5536. (concat
  5537. (org-add-props
  5538. (format "%-43s" (concat " " issue))
  5539. nil
  5540. 'face face)
  5541. "\n"))
  5542. (overlay-put ov 'evaporate t)))))
  5543. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5544. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5545. (catch 'exit
  5546. (unless ok-list
  5547. ;; there are no OK times for gaps...
  5548. (throw 'exit nil))
  5549. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5550. ;; This is more than 24 hours, so it is OK.
  5551. ;; because we have at least one OK time, that must be in the
  5552. ;; 24 hour interval.
  5553. (throw 'exit t))
  5554. ;; We have a shorter gap.
  5555. ;; Now we have to get the minute of the day when these times are
  5556. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5557. (t2dec (decode-time (seconds-to-time t2)))
  5558. ;; compute the minute on the day
  5559. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5560. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5561. (when (< min2 min1)
  5562. ;; if min2 is smaller than min1, this means it is on the next day.
  5563. ;; Wrap it to after midnight.
  5564. (setq min2 (+ min2 1440)))
  5565. ;; Now check if any of the OK times is in the gap
  5566. (mapc (lambda (x)
  5567. ;; Wrap the time to after midnight if necessary
  5568. (if (< x min1) (setq x (+ x 1440)))
  5569. ;; Check if in interval
  5570. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5571. ok-list)
  5572. ;; Nope, this gap is not OK
  5573. nil)))
  5574. (defun org-agenda-get-deadlines (&optional with-hour)
  5575. "Return the deadline information for agenda display.
  5576. When WITH-HOUR is non-nil, only return deadlines with an hour
  5577. specification like [h]h:mm."
  5578. (let* ((props (list 'mouse-face 'highlight
  5579. 'org-not-done-regexp org-not-done-regexp
  5580. 'org-todo-regexp org-todo-regexp
  5581. 'org-complex-heading-regexp org-complex-heading-regexp
  5582. 'help-echo
  5583. (format "mouse-2 or RET jump to org file %s"
  5584. (abbreviate-file-name buffer-file-name))))
  5585. (regexp (if with-hour
  5586. org-deadline-time-hour-regexp
  5587. org-deadline-time-regexp))
  5588. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5589. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5590. (dl0 (car org-agenda-deadline-leaders))
  5591. (dl1 (nth 1 org-agenda-deadline-leaders))
  5592. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5593. d2 diff dfrac wdays pos pos1 category category-pos level
  5594. tags suppress-prewarning ee txt head face s todo-state
  5595. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5596. (goto-char (point-min))
  5597. (while (re-search-forward regexp nil t)
  5598. (catch :skip
  5599. (org-agenda-skip)
  5600. (setq s (match-string 1)
  5601. txt nil
  5602. pos (1- (match-beginning 1))
  5603. todo-state (save-match-data (org-get-todo-state))
  5604. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5605. (member todo-state
  5606. org-agenda-repeating-timestamp-show-all))
  5607. d2 (org-time-string-to-absolute
  5608. s d1 'past show-all (current-buffer) pos)
  5609. diff (- d2 d1))
  5610. (setq suppress-prewarning
  5611. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5612. (let ((item (buffer-substring (point-at-bol)
  5613. (point-at-eol))))
  5614. (save-match-data
  5615. (and (string-match
  5616. org-scheduled-time-regexp item)
  5617. (match-string 1 item)))))))
  5618. (cond
  5619. ((not ds) nil)
  5620. ;; The current item has a scheduled date (in ds), so
  5621. ;; evaluate its prewarning lead time.
  5622. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5623. ;; Use global prewarning-restart lead time.
  5624. org-agenda-skip-deadline-prewarning-if-scheduled)
  5625. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5626. 'pre-scheduled)
  5627. ;; Set prewarning to no earlier than scheduled.
  5628. (min (- d2 (org-time-string-to-absolute
  5629. ds d1 'past show-all (current-buffer) pos))
  5630. org-deadline-warning-days))
  5631. ;; Set prewarning to deadline.
  5632. (t 0))))
  5633. (setq wdays (if suppress-prewarning
  5634. (let ((org-deadline-warning-days suppress-prewarning))
  5635. (org-get-wdays s))
  5636. (org-get-wdays s))
  5637. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5638. upcomingp (and todayp (> diff 0)))
  5639. ;; When to show a deadline in the calendar:
  5640. ;; If the expiration is within wdays warning time.
  5641. ;; Past-due deadlines are only shown on the current date
  5642. (if (and (or (and (<= diff wdays)
  5643. (and todayp (not org-agenda-only-exact-dates)))
  5644. (= diff 0)))
  5645. (save-excursion
  5646. ;; (setq todo-state (org-get-todo-state))
  5647. (setq donep (member todo-state org-done-keywords))
  5648. (if (and donep
  5649. (or org-agenda-skip-deadline-if-done
  5650. (not (= diff 0))))
  5651. (setq txt nil)
  5652. (setq category (org-get-category)
  5653. warntime (get-text-property (point) 'org-appt-warntime)
  5654. category-pos (get-text-property (point) 'org-category-position))
  5655. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5656. (throw :skip nil)
  5657. (goto-char (match-end 0))
  5658. (setq pos1 (match-beginning 0))
  5659. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5660. (setq inherited-tags
  5661. (or (eq org-agenda-show-inherited-tags 'always)
  5662. (and (listp org-agenda-show-inherited-tags)
  5663. (memq 'agenda org-agenda-show-inherited-tags))
  5664. (and (eq org-agenda-show-inherited-tags t)
  5665. (or (eq org-agenda-use-tag-inheritance t)
  5666. (memq 'agenda org-agenda-use-tag-inheritance))))
  5667. tags (org-get-tags-at pos1 (not inherited-tags)))
  5668. (setq head (buffer-substring
  5669. (point)
  5670. (progn (skip-chars-forward "^\r\n")
  5671. (point))))
  5672. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5673. (setq timestr
  5674. (concat (substring s (match-beginning 1)) " "))
  5675. (setq timestr 'time))
  5676. (setq txt (org-agenda-format-item
  5677. (cond ((= diff 0) dl0)
  5678. ((> diff 0)
  5679. (if (functionp dl1)
  5680. (funcall dl1 diff date)
  5681. (format dl1 diff)))
  5682. (t
  5683. (if (functionp dl2)
  5684. (funcall dl2 diff date)
  5685. (format dl2 (if (string= dl2 dl1)
  5686. diff (abs diff))))))
  5687. head level category tags
  5688. (if (not (= diff 0)) nil timestr)))))
  5689. (when txt
  5690. (setq face (org-agenda-deadline-face dfrac))
  5691. (org-add-props txt props
  5692. 'org-marker (org-agenda-new-marker pos)
  5693. 'warntime warntime
  5694. 'level level
  5695. 'ts-date d2
  5696. 'org-hd-marker (org-agenda-new-marker pos1)
  5697. 'priority (+ (- diff)
  5698. (org-get-priority txt))
  5699. 'org-category category
  5700. 'org-category-position category-pos
  5701. 'todo-state todo-state
  5702. 'type (if upcomingp "upcoming-deadline" "deadline")
  5703. 'date (if upcomingp date d2)
  5704. 'face (if donep 'org-agenda-done face)
  5705. 'undone-face face 'done-face 'org-agenda-done)
  5706. (push txt ee))))))
  5707. (nreverse ee)))
  5708. (defun org-agenda-deadline-face (fraction)
  5709. "Return the face to displaying a deadline item.
  5710. FRACTION is what fraction of the head-warning time has passed."
  5711. (let ((faces org-agenda-deadline-faces) f)
  5712. (catch 'exit
  5713. (while (setq f (pop faces))
  5714. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5715. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5716. "Return the scheduled information for agenda display.
  5717. When WITH-HOUR is non-nil, only return scheduled items with
  5718. an hour specification like [h]h:mm."
  5719. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5720. 'org-todo-regexp org-todo-regexp
  5721. 'org-complex-heading-regexp org-complex-heading-regexp
  5722. 'done-face 'org-agenda-done
  5723. 'mouse-face 'highlight
  5724. 'help-echo
  5725. (format "mouse-2 or RET jump to org file %s"
  5726. (abbreviate-file-name buffer-file-name))))
  5727. (regexp (if with-hour
  5728. org-scheduled-time-hour-regexp
  5729. org-scheduled-time-regexp))
  5730. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5731. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5732. mm
  5733. (deadline-position-alist
  5734. (mapcar (lambda (a) (and (setq mm (get-text-property
  5735. 0 'org-hd-marker a))
  5736. (cons (marker-position mm) a)))
  5737. deadline-results))
  5738. d2 diff pos pos1 category category-pos level tags donep
  5739. ee txt head pastschedp todo-state face timestr s habitp show-all
  5740. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5741. ddays)
  5742. (goto-char (point-min))
  5743. (while (re-search-forward regexp nil t)
  5744. (catch :skip
  5745. (org-agenda-skip)
  5746. (setq s (match-string 1)
  5747. txt nil
  5748. pos (1- (match-beginning 1))
  5749. todo-state (save-match-data (org-get-todo-state))
  5750. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5751. (member todo-state
  5752. org-agenda-repeating-timestamp-show-all))
  5753. d2 (org-time-string-to-absolute
  5754. s d1 'past show-all (current-buffer) pos)
  5755. diff (- d2 d1)
  5756. warntime (get-text-property (point) 'org-appt-warntime))
  5757. (setq pastschedp (and todayp (< diff 0)))
  5758. (setq did-habit-check-p nil)
  5759. (setq suppress-delay
  5760. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5761. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5762. (save-match-data
  5763. (and (string-match
  5764. org-deadline-time-regexp item)
  5765. (match-string 1 item)))))))
  5766. (cond
  5767. ((not ds) nil)
  5768. ;; The current item has a deadline date (in ds), so
  5769. ;; evaluate its delay time.
  5770. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5771. ;; Use global delay time.
  5772. (- org-agenda-skip-scheduled-delay-if-deadline))
  5773. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5774. 'post-deadline)
  5775. ;; Set delay to no later than deadline.
  5776. (min (- d2 (org-time-string-to-absolute
  5777. ds d1 'past show-all (current-buffer) pos))
  5778. org-scheduled-delay-days))
  5779. (t 0))))
  5780. (setq ddays (if suppress-delay
  5781. (let ((org-scheduled-delay-days suppress-delay))
  5782. (org-get-wdays s t t))
  5783. (org-get-wdays s t)))
  5784. ;; Use a delay of 0 when there is a repeater and the delay is
  5785. ;; of the form --3d
  5786. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5787. (< (org-time-string-to-absolute s)
  5788. (org-time-string-to-absolute
  5789. s d2 'past nil (current-buffer) pos)))
  5790. (setq ddays 0))
  5791. ;; When to show a scheduled item in the calendar:
  5792. ;; If it is on or past the date.
  5793. (when (or (and (> ddays 0) (= diff (- ddays)))
  5794. (and (zerop ddays) (= diff 0))
  5795. (and (< (+ diff ddays) 0)
  5796. (< (abs diff) org-scheduled-past-days)
  5797. (and todayp (not org-agenda-only-exact-dates)))
  5798. ;; org-is-habit-p uses org-entry-get, which is expansive
  5799. ;; so we go extra mile to only call it once
  5800. (and todayp
  5801. (boundp 'org-habit-show-all-today)
  5802. org-habit-show-all-today
  5803. (setq did-habit-check-p t)
  5804. (setq habitp (and (functionp 'org-is-habit-p)
  5805. (org-is-habit-p)))))
  5806. (save-excursion
  5807. (setq donep (member todo-state org-done-keywords))
  5808. (if (and donep
  5809. (or org-agenda-skip-scheduled-if-done
  5810. (not (= diff 0))
  5811. (and (functionp 'org-is-habit-p)
  5812. (org-is-habit-p))))
  5813. (setq txt nil)
  5814. (setq habitp (if did-habit-check-p habitp
  5815. (and (functionp 'org-is-habit-p)
  5816. (org-is-habit-p))))
  5817. (setq category (org-get-category)
  5818. category-pos (get-text-property (point) 'org-category-position))
  5819. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5820. 'repeated-after-deadline)
  5821. (org-get-deadline-time (point))
  5822. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5823. (throw :skip nil))
  5824. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5825. (throw :skip nil)
  5826. (goto-char (match-end 0))
  5827. (setq pos1 (match-beginning 0))
  5828. (if habitp
  5829. (if (or (not org-habit-show-habits)
  5830. (and (not todayp)
  5831. (boundp 'org-habit-show-habits-only-for-today)
  5832. org-habit-show-habits-only-for-today))
  5833. (throw :skip nil))
  5834. (if (and
  5835. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5836. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5837. pastschedp))
  5838. (setq mm (assoc pos1 deadline-position-alist)))
  5839. (throw :skip nil)))
  5840. (setq inherited-tags
  5841. (or (eq org-agenda-show-inherited-tags 'always)
  5842. (and (listp org-agenda-show-inherited-tags)
  5843. (memq 'agenda org-agenda-show-inherited-tags))
  5844. (and (eq org-agenda-show-inherited-tags t)
  5845. (or (eq org-agenda-use-tag-inheritance t)
  5846. (memq 'agenda org-agenda-use-tag-inheritance))))
  5847. tags (org-get-tags-at nil (not inherited-tags)))
  5848. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5849. (setq head (buffer-substring
  5850. (point)
  5851. (progn (skip-chars-forward "^\r\n") (point))))
  5852. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5853. (setq timestr
  5854. (concat (substring s (match-beginning 1)) " "))
  5855. (setq timestr 'time))
  5856. (setq txt (org-agenda-format-item
  5857. (if (= diff 0)
  5858. (car org-agenda-scheduled-leaders)
  5859. (format (nth 1 org-agenda-scheduled-leaders)
  5860. (- 1 diff)))
  5861. head level category tags
  5862. (if (not (= diff 0)) nil timestr)
  5863. nil habitp))))
  5864. (when txt
  5865. (setq face
  5866. (cond
  5867. ((and (not habitp) pastschedp)
  5868. 'org-scheduled-previously)
  5869. (todayp 'org-scheduled-today)
  5870. (t 'org-scheduled))
  5871. habitp (and habitp (org-habit-parse-todo)))
  5872. (org-add-props txt props
  5873. 'undone-face face
  5874. 'face (if donep 'org-agenda-done face)
  5875. 'org-marker (org-agenda-new-marker pos)
  5876. 'org-hd-marker (org-agenda-new-marker pos1)
  5877. 'type (if pastschedp "past-scheduled" "scheduled")
  5878. 'date (if pastschedp d2 date)
  5879. 'ts-date d2
  5880. 'warntime warntime
  5881. 'level level
  5882. 'priority (if habitp
  5883. (org-habit-get-priority habitp)
  5884. (+ 94 (- 5 diff) (org-get-priority txt)))
  5885. 'org-category category
  5886. 'category-position category-pos
  5887. 'org-habit-p habitp
  5888. 'todo-state todo-state)
  5889. (push txt ee))))))
  5890. (nreverse ee)))
  5891. (defun org-agenda-get-blocks ()
  5892. "Return the date-range information for agenda display."
  5893. (let* ((props (list 'face nil
  5894. 'org-not-done-regexp org-not-done-regexp
  5895. 'org-todo-regexp org-todo-regexp
  5896. 'org-complex-heading-regexp org-complex-heading-regexp
  5897. 'mouse-face 'highlight
  5898. 'help-echo
  5899. (format "mouse-2 or RET jump to org file %s"
  5900. (abbreviate-file-name buffer-file-name))))
  5901. (regexp org-tr-regexp)
  5902. (d0 (calendar-absolute-from-gregorian date))
  5903. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5904. level todo-state tags pos head donep inherited-tags)
  5905. (goto-char (point-min))
  5906. (while (re-search-forward regexp nil t)
  5907. (catch :skip
  5908. (org-agenda-skip)
  5909. (setq pos (point))
  5910. (let ((start-time (match-string 1))
  5911. (end-time (match-string 2)))
  5912. (setq s1 (match-string 1)
  5913. s2 (match-string 2)
  5914. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5915. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5916. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5917. ;; Only allow days between the limits, because the normal
  5918. ;; date stamps will catch the limits.
  5919. (save-excursion
  5920. (setq todo-state (org-get-todo-state))
  5921. (setq donep (member todo-state org-done-keywords))
  5922. (if (and donep org-agenda-skip-timestamp-if-done)
  5923. (throw :skip t))
  5924. (setq marker (org-agenda-new-marker (point)))
  5925. (setq category (org-get-category)
  5926. category-pos (get-text-property (point) 'org-category-position))
  5927. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5928. (throw :skip nil)
  5929. (goto-char (match-beginning 0))
  5930. (setq hdmarker (org-agenda-new-marker (point))
  5931. inherited-tags
  5932. (or (eq org-agenda-show-inherited-tags 'always)
  5933. (and (listp org-agenda-show-inherited-tags)
  5934. (memq 'agenda org-agenda-show-inherited-tags))
  5935. (and (eq org-agenda-show-inherited-tags t)
  5936. (or (eq org-agenda-use-tag-inheritance t)
  5937. (memq 'agenda org-agenda-use-tag-inheritance))))
  5938. tags (org-get-tags-at nil (not inherited-tags)))
  5939. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5940. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5941. (setq head (match-string 1))
  5942. (let ((remove-re
  5943. (if org-agenda-remove-timeranges-from-blocks
  5944. (concat
  5945. "<" (regexp-quote s1) ".*?>"
  5946. "--"
  5947. "<" (regexp-quote s2) ".*?>")
  5948. nil)))
  5949. (setq txt (org-agenda-format-item
  5950. (format
  5951. (nth (if (= d1 d2) 0 1)
  5952. org-agenda-timerange-leaders)
  5953. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5954. head level category tags
  5955. (cond ((and (= d1 d0) (= d2 d0))
  5956. (concat "<" start-time ">--<" end-time ">"))
  5957. ((= d1 d0)
  5958. (concat "<" start-time ">"))
  5959. ((= d2 d0)
  5960. (concat "<" end-time ">")))
  5961. remove-re))))
  5962. (org-add-props txt props
  5963. 'org-marker marker 'org-hd-marker hdmarker
  5964. 'type "block" 'date date
  5965. 'level level
  5966. 'todo-state todo-state
  5967. 'priority (org-get-priority txt) 'org-category category
  5968. 'org-category-position category-pos)
  5969. (push txt ee))))
  5970. (goto-char pos)))
  5971. ;; Sort the entries by expiration date.
  5972. (nreverse ee)))
  5973. ;;; Agenda presentation and sorting
  5974. (defvar org-prefix-has-time nil
  5975. "A flag, set by `org-compile-prefix-format'.
  5976. The flag is set if the currently compiled format contains a `%t'.")
  5977. (defvar org-prefix-has-tag nil
  5978. "A flag, set by `org-compile-prefix-format'.
  5979. The flag is set if the currently compiled format contains a `%T'.")
  5980. (defvar org-prefix-has-effort nil
  5981. "A flag, set by `org-compile-prefix-format'.
  5982. The flag is set if the currently compiled format contains a `%e'.")
  5983. (defvar org-prefix-has-breadcrumbs nil
  5984. "A flag, set by `org-compile-prefix-format'.
  5985. The flag is set if the currently compiled format contains a `%b'.")
  5986. (defvar org-prefix-category-length nil
  5987. "Used by `org-compile-prefix-format' to remember the category field width.")
  5988. (defvar org-prefix-category-max-length nil
  5989. "Used by `org-compile-prefix-format' to remember the category field width.")
  5990. (defun org-agenda-get-category-icon (category)
  5991. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5992. (dolist (entry org-agenda-category-icon-alist)
  5993. (when (org-string-match-p (car entry) category)
  5994. (if (listp (cadr entry))
  5995. (return (cadr entry))
  5996. (return (apply 'create-image (cdr entry)))))))
  5997. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5998. remove-re habitp)
  5999. "Format TXT to be inserted into the agenda buffer.
  6000. In particular, add the prefix and corresponding text properties.
  6001. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6002. LEVEL may be a string to replace the `%l' specifier.
  6003. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6004. category taken from local variable or file name. It will replace the `%c'
  6005. specifier in the format.
  6006. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6007. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6008. When DOTIME is a string, this string is searched for a time before TXT is.
  6009. TAGS can be the tags of the headline.
  6010. Any match of REMOVE-RE will be removed from TXT."
  6011. ;; We keep the org-prefix-* variable values along with a compiled
  6012. ;; formatter, so that multiple agendas existing at the same time do
  6013. ;; not step on each other toes.
  6014. ;;
  6015. ;; It was inconvenient to make these variables buffer local in
  6016. ;; Agenda buffers, because this function expects to be called with
  6017. ;; the buffer where item comes from being current, and not agenda
  6018. ;; buffer
  6019. (let* ((bindings (car org-prefix-format-compiled))
  6020. (formatter (cadr org-prefix-format-compiled)))
  6021. (loop for (var value) in bindings
  6022. do (set var value))
  6023. (save-match-data
  6024. ;; Diary entries sometimes have extra whitespace at the beginning
  6025. (setq txt (org-trim txt))
  6026. ;; Fix the tags part in txt
  6027. (setq txt (org-agenda-fix-displayed-tags
  6028. txt tags
  6029. org-agenda-show-inherited-tags
  6030. org-agenda-hide-tags-regexp))
  6031. (let* ((category (or category
  6032. (if (stringp org-category)
  6033. org-category
  6034. (and org-category (symbol-name org-category)))
  6035. (if buffer-file-name
  6036. (file-name-sans-extension
  6037. (file-name-nondirectory buffer-file-name))
  6038. "")))
  6039. (category-icon (org-agenda-get-category-icon category))
  6040. (category-icon (if category-icon
  6041. (propertize " " 'display category-icon)
  6042. ""))
  6043. ;; time, tag, effort are needed for the eval of the prefix format
  6044. (tag (if tags (nth (1- (length tags)) tags) ""))
  6045. time effort neffort
  6046. (ts (if dotime (concat
  6047. (if (stringp dotime) dotime "")
  6048. (and org-agenda-search-headline-for-time txt))))
  6049. (time-of-day (and dotime (org-get-time-of-day ts)))
  6050. stamp plain s0 s1 s2 rtn srp l
  6051. duration thecategory breadcrumbs)
  6052. (and (derived-mode-p 'org-mode) buffer-file-name
  6053. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6054. (when (and dotime time-of-day)
  6055. ;; Extract starting and ending time and move them to prefix
  6056. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6057. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6058. (setq s0 (match-string 0 ts)
  6059. srp (and stamp (match-end 3))
  6060. s1 (match-string (if plain 1 2) ts)
  6061. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6062. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6063. ;; them, we might want to remove them there to avoid duplication.
  6064. ;; The user can turn this off with a variable.
  6065. (if (and org-prefix-has-time
  6066. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6067. (string-match (concat (regexp-quote s0) " *") txt)
  6068. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6069. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6070. (= (match-beginning 0) 0)
  6071. t))
  6072. (setq txt (replace-match "" nil nil txt))))
  6073. ;; Normalize the time(s) to 24 hour
  6074. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6075. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6076. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6077. (let (org-time-clocksum-use-effort-durations)
  6078. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6079. (setq s2
  6080. (org-minutes-to-clocksum-string
  6081. (+ (org-hh:mm-string-to-minutes s1)
  6082. org-agenda-default-appointment-duration)))))
  6083. ;; Compute the duration
  6084. (when s2
  6085. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6086. (org-hh:mm-string-to-minutes s1)))))
  6087. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6088. txt)
  6089. ;; Tags are in the string
  6090. (if (or (eq org-agenda-remove-tags t)
  6091. (and org-agenda-remove-tags
  6092. org-prefix-has-tag))
  6093. (setq txt (replace-match "" t t txt))
  6094. (setq txt (replace-match
  6095. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6096. (match-string 2 txt))
  6097. t t txt))))
  6098. (when (derived-mode-p 'org-mode)
  6099. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6100. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6101. ;; current buffer, so move this check outside of above
  6102. (if effort
  6103. (setq neffort (org-duration-string-to-minutes effort)
  6104. effort (setq effort (concat "[" effort "]")))
  6105. ;; prevent erroring out with %e format when there is no effort
  6106. (setq effort ""))
  6107. (when remove-re
  6108. (while (string-match remove-re txt)
  6109. (setq txt (replace-match "" t t txt))))
  6110. ;; Set org-heading property on `txt' to mark the start of the
  6111. ;; heading.
  6112. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6113. ;; Prepare the variables needed in the eval of the compiled format
  6114. (if org-prefix-has-breadcrumbs
  6115. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6116. (let ((s (org-display-outline-path nil nil "->" t)))
  6117. (if (eq "" s) "" (concat s "->"))))))
  6118. (setq time (cond (s2 (concat
  6119. (org-agenda-time-of-day-to-ampm-maybe s1)
  6120. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6121. (if org-agenda-timegrid-use-ampm " ")))
  6122. (s1 (concat
  6123. (org-agenda-time-of-day-to-ampm-maybe s1)
  6124. (if org-agenda-timegrid-use-ampm
  6125. "........ "
  6126. "......")))
  6127. (t ""))
  6128. extra (or (and (not habitp) extra) "")
  6129. category (if (symbolp category) (symbol-name category) category)
  6130. thecategory (copy-sequence category)
  6131. level (or level ""))
  6132. (if (string-match org-bracket-link-regexp category)
  6133. (progn
  6134. (setq l (if (match-end 3)
  6135. (- (match-end 3) (match-beginning 3))
  6136. (- (match-end 1) (match-beginning 1))))
  6137. (when (< l (or org-prefix-category-length 0))
  6138. (setq category (copy-sequence category))
  6139. (org-add-props category nil
  6140. 'extra-space (make-string
  6141. (- org-prefix-category-length l 1) ?\ ))))
  6142. (if (and org-prefix-category-max-length
  6143. (>= (length category) org-prefix-category-max-length))
  6144. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6145. ;; Evaluate the compiled format
  6146. (setq rtn (concat (eval formatter) txt))
  6147. ;; And finally add the text properties
  6148. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6149. (org-add-props rtn nil
  6150. 'org-category (if thecategory (downcase thecategory) category)
  6151. 'tags (mapcar 'org-downcase-keep-props tags)
  6152. 'org-highest-priority org-highest-priority
  6153. 'org-lowest-priority org-lowest-priority
  6154. 'time-of-day time-of-day
  6155. 'duration duration
  6156. 'effort effort
  6157. 'effort-minutes neffort
  6158. 'breadcrumbs breadcrumbs
  6159. 'txt txt
  6160. 'level level
  6161. 'time time
  6162. 'extra extra
  6163. 'format org-prefix-format-compiled
  6164. 'dotime dotime)))))
  6165. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6166. "Remove tags string from TXT, and add a modified list of tags.
  6167. The modified list may contain inherited tags, and tags matched by
  6168. `org-agenda-hide-tags-regexp' will be removed."
  6169. (when (or add-inherited hide-re)
  6170. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6171. (setq txt (substring txt 0 (match-beginning 0))))
  6172. (setq tags
  6173. (delq nil
  6174. (mapcar (lambda (tg)
  6175. (if (or (and hide-re (string-match hide-re tg))
  6176. (and (not add-inherited)
  6177. (get-text-property 0 'inherited tg)))
  6178. nil
  6179. tg))
  6180. tags)))
  6181. (when tags
  6182. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6183. i)
  6184. (setq txt (concat txt " :"
  6185. (mapconcat
  6186. (lambda (x)
  6187. (setq i (get-text-property 0 'inherited x))
  6188. (if (and have-i (not i))
  6189. (progn
  6190. (setq have-i nil)
  6191. (concat ":" x))
  6192. x))
  6193. tags ":")
  6194. (if have-i "::" ":"))))))
  6195. txt)
  6196. (defun org-downcase-keep-props (s)
  6197. (let ((props (text-properties-at 0 s)))
  6198. (setq s (downcase s))
  6199. (add-text-properties 0 (length s) props s)
  6200. s))
  6201. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6202. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6203. "Add a time-grid for agenda items which need it.
  6204. LIST is the list of agenda items formatted by `org-agenda-list'.
  6205. NDAYS is the span of the current agenda view.
  6206. TODAYP is `t' when the current agenda view is on today."
  6207. (catch 'exit
  6208. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6209. ((and todayp (member 'today (car org-agenda-time-grid))))
  6210. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6211. ((member 'weekly (car org-agenda-time-grid)))
  6212. (t (throw 'exit list)))
  6213. (let* ((have (delq nil (mapcar
  6214. (lambda (x) (get-text-property 1 'time-of-day x))
  6215. list)))
  6216. (string (nth 1 org-agenda-time-grid))
  6217. (gridtimes (nth 2 org-agenda-time-grid))
  6218. (req (car org-agenda-time-grid))
  6219. (remove (member 'remove-match req))
  6220. new time)
  6221. (if (and (member 'require-timed req) (not have))
  6222. ;; don't show empty grid
  6223. (throw 'exit list))
  6224. (while (setq time (pop gridtimes))
  6225. (unless (and remove (member time have))
  6226. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6227. (push (org-agenda-format-item
  6228. nil string nil "" nil
  6229. (concat (substring time 0 -2) ":" (substring time -2)))
  6230. new)
  6231. (put-text-property
  6232. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6233. (when (and todayp org-agenda-show-current-time-in-grid)
  6234. (push (org-agenda-format-item
  6235. nil org-agenda-current-time-string nil "" nil
  6236. (format-time-string "%H:%M "))
  6237. new)
  6238. (put-text-property
  6239. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6240. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6241. (append new list)
  6242. (append list new)))))
  6243. (defun org-compile-prefix-format (key)
  6244. "Compile the prefix format into a Lisp form that can be evaluated.
  6245. The resulting form and associated variable bindings is returned
  6246. and stored in the variable `org-prefix-format-compiled'."
  6247. (setq org-prefix-has-time nil
  6248. org-prefix-has-tag nil
  6249. org-prefix-category-length nil
  6250. org-prefix-has-effort nil
  6251. org-prefix-has-breadcrumbs nil)
  6252. (let ((s (cond
  6253. ((stringp org-agenda-prefix-format)
  6254. org-agenda-prefix-format)
  6255. ((assq key org-agenda-prefix-format)
  6256. (cdr (assq key org-agenda-prefix-format)))
  6257. (t " %-12:c%?-12t% s")))
  6258. (start 0)
  6259. varform vars var e c f opt)
  6260. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6261. s start)
  6262. (setq var (or (cdr (assoc (match-string 4 s)
  6263. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6264. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6265. 'eval)
  6266. c (or (match-string 3 s) "")
  6267. opt (match-beginning 1)
  6268. start (1+ (match-beginning 0)))
  6269. (if (equal var 'time) (setq org-prefix-has-time t))
  6270. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6271. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6272. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6273. (setq f (concat "%" (match-string 2 s) "s"))
  6274. (when (equal var 'category)
  6275. (setq org-prefix-category-length
  6276. (floor (abs (string-to-number (match-string 2 s)))))
  6277. (setq org-prefix-category-max-length
  6278. (let ((x (match-string 2 s)))
  6279. (save-match-data
  6280. (if (string-match "\\.[0-9]+" x)
  6281. (string-to-number (substring (match-string 0 x) 1)))))))
  6282. (if (eq var 'eval)
  6283. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6284. (if opt
  6285. (setq varform
  6286. `(if (equal "" ,var)
  6287. ""
  6288. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6289. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6290. (setq s (replace-match "%s" t nil s))
  6291. (push varform vars))
  6292. (setq vars (nreverse vars))
  6293. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6294. (setq org-prefix-format-compiled
  6295. (list
  6296. `((org-prefix-has-time ,org-prefix-has-time)
  6297. (org-prefix-has-tag ,org-prefix-has-tag)
  6298. (org-prefix-category-length ,org-prefix-category-length)
  6299. (org-prefix-has-effort ,org-prefix-has-effort)
  6300. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6301. `(format ,s ,@vars))))))
  6302. (defun org-set-sorting-strategy (key)
  6303. (if (symbolp (car org-agenda-sorting-strategy))
  6304. ;; the old format
  6305. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6306. (setq org-agenda-sorting-strategy-selected
  6307. (or (cdr (assq key org-agenda-sorting-strategy))
  6308. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6309. '(time-up category-keep priority-down)))))
  6310. (defun org-get-time-of-day (s &optional string mod24)
  6311. "Check string S for a time of day.
  6312. If found, return it as a military time number between 0 and 2400.
  6313. If not found, return nil.
  6314. The optional STRING argument forces conversion into a 5 character wide string
  6315. HH:MM."
  6316. (save-match-data
  6317. (when
  6318. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6319. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6320. (let* ((h (string-to-number (match-string 1 s)))
  6321. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6322. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6323. (am-p (equal ampm "am"))
  6324. (h1 (cond ((not ampm) h)
  6325. ((= h 12) (if am-p 0 12))
  6326. (t (+ h (if am-p 0 12)))))
  6327. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6328. (mod h1 24) h1))
  6329. (t0 (+ (* 100 h2) m))
  6330. (t1 (concat (if (>= h1 24) "+" " ")
  6331. (if (and org-agenda-time-leading-zero
  6332. (< t0 1000)) "0" "")
  6333. (if (< t0 100) "0" "")
  6334. (if (< t0 10) "0" "")
  6335. (int-to-string t0))))
  6336. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6337. (defvar org-agenda-before-sorting-filter-function nil
  6338. "Function to be applied to agenda items prior to sorting.
  6339. Prior to sorting also means just before they are inserted into the agenda.
  6340. To aid sorting, you may revisit the original entries and add more text
  6341. properties which will later be used by the sorting functions.
  6342. The function should take a string argument, an agenda line.
  6343. It has access to the text properties in that line, which contain among
  6344. other things, the property `org-hd-marker' that points to the entry
  6345. where the line comes from. Note that not all lines going into the agenda
  6346. have this property, only most.
  6347. The function should return the modified string. It is probably best
  6348. to ONLY change text properties.
  6349. You can also use this function as a filter, by returning nil for lines
  6350. you don't want to have in the agenda at all. For this application, you
  6351. could bind the variable in the options section of a custom command.")
  6352. (defun org-agenda-finalize-entries (list &optional type)
  6353. "Sort, limit and concatenate the LIST of agenda items.
  6354. The optional argument TYPE tells the agenda type."
  6355. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6356. (cdr (assoc type org-agenda-max-effort)))
  6357. (t org-agenda-max-effort)))
  6358. (max-todo (cond ((listp org-agenda-max-todos)
  6359. (cdr (assoc type org-agenda-max-todos)))
  6360. (t org-agenda-max-todos)))
  6361. (max-tags (cond ((listp org-agenda-max-tags)
  6362. (cdr (assoc type org-agenda-max-tags)))
  6363. (t org-agenda-max-tags)))
  6364. (max-entries (cond ((listp org-agenda-max-entries)
  6365. (cdr (assoc type org-agenda-max-entries)))
  6366. (t org-agenda-max-entries))) l)
  6367. (when org-agenda-before-sorting-filter-function
  6368. (setq list
  6369. (delq nil
  6370. (mapcar
  6371. org-agenda-before-sorting-filter-function list))))
  6372. (setq list (mapcar 'org-agenda-highlight-todo list)
  6373. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6374. (when max-effort
  6375. (setq list (org-agenda-limit-entries
  6376. list 'effort-minutes max-effort 'identity)))
  6377. (when max-todo
  6378. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6379. (when max-tags
  6380. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6381. (when max-entries
  6382. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6383. (mapconcat 'identity list "\n")))
  6384. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6385. "Limit the number of agenda entries."
  6386. (let ((include (and limit (< limit 0))))
  6387. (if limit
  6388. (let ((fun (or fn (lambda (p) (if p 1))))
  6389. (lim 0))
  6390. (delq nil
  6391. (mapcar
  6392. (lambda (e)
  6393. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6394. (if pval (setq lim (+ lim pval)))
  6395. (cond ((and pval (<= lim (abs limit))) e)
  6396. ((and include (not pval)) e))))
  6397. list)))
  6398. list)))
  6399. (defun org-agenda-limit-interactively ()
  6400. "In agenda, interactively limit entries to various maximums."
  6401. (interactive)
  6402. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6403. (num (string-to-number (read-from-minibuffer "How many? "))))
  6404. (cond ((equal max ?e)
  6405. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6406. ((equal max ?t)
  6407. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6408. ((equal max ?T)
  6409. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6410. ((equal max ?E)
  6411. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6412. (org-agenda-fit-window-to-buffer))
  6413. (defun org-agenda-highlight-todo (x)
  6414. (let ((org-done-keywords org-done-keywords-for-agenda)
  6415. (case-fold-search nil)
  6416. re)
  6417. (if (eq x 'line)
  6418. (save-excursion
  6419. (beginning-of-line 1)
  6420. (setq re (org-get-at-bol 'org-todo-regexp))
  6421. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6422. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6423. (add-text-properties (match-beginning 0) (match-end 1)
  6424. (list 'face (org-get-todo-face 1)))
  6425. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6426. (delete-region (match-beginning 1) (1- (match-end 0)))
  6427. (goto-char (match-beginning 1))
  6428. (insert (format org-agenda-todo-keyword-format s)))))
  6429. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6430. (setq re (get-text-property 0 'org-todo-regexp x))
  6431. (when (and re
  6432. ;; Test `pl' because if there's no heading content,
  6433. ;; there's no point matching to highlight. Note
  6434. ;; that if we didn't test `pl' first, and there
  6435. ;; happened to be no keyword from `org-todo-regexp'
  6436. ;; on this heading line, then the `equal' comparison
  6437. ;; afterwards would spuriously succeed in the case
  6438. ;; where `pl' is nil -- causing an args-out-of-range
  6439. ;; error when we try to add text properties to text
  6440. ;; that isn't there.
  6441. pl
  6442. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6443. x pl) pl))
  6444. (add-text-properties
  6445. (or (match-end 1) (match-end 0)) (match-end 0)
  6446. (list 'face (org-get-todo-face (match-string 2 x)))
  6447. x)
  6448. (when (match-end 1)
  6449. (setq x (concat (substring x 0 (match-end 1))
  6450. (format org-agenda-todo-keyword-format
  6451. (match-string 2 x))
  6452. (org-add-props " " (text-properties-at 0 x))
  6453. (substring x (match-end 3)))))))
  6454. x)))
  6455. (defsubst org-cmp-priority (a b)
  6456. "Compare the priorities of string A and B."
  6457. (let ((pa (or (get-text-property 1 'priority a) 0))
  6458. (pb (or (get-text-property 1 'priority b) 0)))
  6459. (cond ((> pa pb) +1)
  6460. ((< pa pb) -1))))
  6461. (defsubst org-cmp-effort (a b)
  6462. "Compare the effort values of string A and B."
  6463. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6464. (ea (or (get-text-property 1 'effort-minutes a) def))
  6465. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6466. (cond ((> ea eb) +1)
  6467. ((< ea eb) -1))))
  6468. (defsubst org-cmp-category (a b)
  6469. "Compare the string values of categories of strings A and B."
  6470. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6471. (cb (or (get-text-property 1 'org-category b) "")))
  6472. (cond ((string-lessp ca cb) -1)
  6473. ((string-lessp cb ca) +1))))
  6474. (defsubst org-cmp-todo-state (a b)
  6475. "Compare the todo states of strings A and B."
  6476. (let* ((ma (or (get-text-property 1 'org-marker a)
  6477. (get-text-property 1 'org-hd-marker a)))
  6478. (mb (or (get-text-property 1 'org-marker b)
  6479. (get-text-property 1 'org-hd-marker b)))
  6480. (fa (and ma (marker-buffer ma)))
  6481. (fb (and mb (marker-buffer mb)))
  6482. (todo-kwds
  6483. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6484. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6485. (ta (or (get-text-property 1 'todo-state a) ""))
  6486. (tb (or (get-text-property 1 'todo-state b) ""))
  6487. (la (- (length (member ta todo-kwds))))
  6488. (lb (- (length (member tb todo-kwds))))
  6489. (donepa (member ta org-done-keywords-for-agenda))
  6490. (donepb (member tb org-done-keywords-for-agenda)))
  6491. (cond ((and donepa (not donepb)) -1)
  6492. ((and (not donepa) donepb) +1)
  6493. ((< la lb) -1)
  6494. ((< lb la) +1))))
  6495. (defsubst org-cmp-alpha (a b)
  6496. "Compare the headlines, alphabetically."
  6497. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6498. (plb (text-property-any 0 (length b) 'org-heading t b))
  6499. (ta (and pla (substring a pla)))
  6500. (tb (and plb (substring b plb))))
  6501. (when pla
  6502. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6503. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6504. (setq ta (substring ta (match-end 0))))
  6505. (setq ta (downcase ta)))
  6506. (when plb
  6507. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6508. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6509. (setq tb (substring tb (match-end 0))))
  6510. (setq tb (downcase tb)))
  6511. (cond ((not ta) +1)
  6512. ((not tb) -1)
  6513. ((string-lessp ta tb) -1)
  6514. ((string-lessp tb ta) +1))))
  6515. (defsubst org-cmp-tag (a b)
  6516. "Compare the string values of the first tags of A and B."
  6517. (let ((ta (car (last (get-text-property 1 'tags a))))
  6518. (tb (car (last (get-text-property 1 'tags b)))))
  6519. (cond ((not ta) +1)
  6520. ((not tb) -1)
  6521. ((string-lessp ta tb) -1)
  6522. ((string-lessp tb ta) +1))))
  6523. (defsubst org-cmp-time (a b)
  6524. "Compare the time-of-day values of strings A and B."
  6525. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6526. (ta (or (get-text-property 1 'time-of-day a) def))
  6527. (tb (or (get-text-property 1 'time-of-day b) def)))
  6528. (cond ((< ta tb) -1)
  6529. ((< tb ta) +1))))
  6530. (defsubst org-cmp-ts (a b &optional type)
  6531. "Compare the timestamps values of entries A and B.
  6532. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6533. \"timestamp_ia\", compare within each of these type. When TYPE
  6534. is the empty string, compare all timestamps without respect of
  6535. their type."
  6536. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6537. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6538. (get-text-property 1 'ts-date a)) def))
  6539. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6540. (get-text-property 1 'ts-date b)) def)))
  6541. (cond ((< ta tb) -1)
  6542. ((< tb ta) +1))))
  6543. (defsubst org-cmp-habit-p (a b)
  6544. "Compare the todo states of strings A and B."
  6545. (let ((ha (get-text-property 1 'org-habit-p a))
  6546. (hb (get-text-property 1 'org-habit-p b)))
  6547. (cond ((and ha (not hb)) -1)
  6548. ((and (not ha) hb) +1))))
  6549. (defun org-entries-lessp (a b)
  6550. "Predicate for sorting agenda entries."
  6551. ;; The following variables will be used when the form is evaluated.
  6552. ;; So even though the compiler complains, keep them.
  6553. (let* ((ss org-agenda-sorting-strategy-selected)
  6554. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6555. (org-cmp-ts a b "")))
  6556. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6557. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6558. (org-cmp-ts a b "scheduled")))
  6559. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6560. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6561. (org-cmp-ts a b "deadline")))
  6562. (deadline-down (if deadline-up (- deadline-up) nil))
  6563. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6564. (org-cmp-ts a b "iatimestamp_ia")))
  6565. (tsia-down (if tsia-up (- tsia-up) nil))
  6566. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6567. (org-cmp-ts a b "timestamp")))
  6568. (ts-down (if ts-up (- ts-up) nil))
  6569. (time-up (and (org-em 'time-up 'time-down ss)
  6570. (org-cmp-time a b)))
  6571. (time-down (if time-up (- time-up) nil))
  6572. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6573. (org-cmp-priority a b)))
  6574. (priority-down (if priority-up (- priority-up) nil))
  6575. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6576. (org-cmp-effort a b)))
  6577. (effort-down (if effort-up (- effort-up) nil))
  6578. (category-up (and (or (org-em 'category-up 'category-down ss)
  6579. (memq 'category-keep ss))
  6580. (org-cmp-category a b)))
  6581. (category-down (if category-up (- category-up) nil))
  6582. (category-keep (if category-up +1 nil))
  6583. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6584. (org-cmp-tag a b)))
  6585. (tag-down (if tag-up (- tag-up) nil))
  6586. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6587. (org-cmp-todo-state a b)))
  6588. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6589. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6590. (org-cmp-habit-p a b)))
  6591. (habit-down (if habit-up (- habit-up) nil))
  6592. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6593. (org-cmp-alpha a b)))
  6594. (alpha-down (if alpha-up (- alpha-up) nil))
  6595. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6596. user-defined-up user-defined-down)
  6597. (if (and need-user-cmp org-agenda-cmp-user-defined
  6598. (functionp org-agenda-cmp-user-defined))
  6599. (setq user-defined-up
  6600. (funcall org-agenda-cmp-user-defined a b)
  6601. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6602. (cdr (assoc
  6603. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6604. '((-1 . t) (1 . nil) (nil . nil))))))
  6605. ;;; Agenda restriction lock
  6606. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6607. "Overlay to mark the headline to which agenda commands are restricted.")
  6608. (overlay-put org-agenda-restriction-lock-overlay
  6609. 'face 'org-agenda-restriction-lock)
  6610. (overlay-put org-agenda-restriction-lock-overlay
  6611. 'help-echo "Agendas are currently limited to this subtree.")
  6612. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6613. ;;;###autoload
  6614. (defun org-agenda-set-restriction-lock (&optional type)
  6615. "Set restriction lock for agenda, to current subtree or file.
  6616. Restriction will be the file if TYPE is `file', or if type is the
  6617. universal prefix '(4), or if the cursor is before the first headline
  6618. in the file. Otherwise, restriction will be to the current subtree."
  6619. (interactive "P")
  6620. (and (equal type '(4)) (setq type 'file))
  6621. (setq type (cond
  6622. (type type)
  6623. ((org-at-heading-p) 'subtree)
  6624. ((condition-case nil (org-back-to-heading t) (error nil))
  6625. 'subtree)
  6626. (t 'file)))
  6627. (if (eq type 'subtree)
  6628. (progn
  6629. (setq org-agenda-restrict (current-buffer))
  6630. (setq org-agenda-overriding-restriction 'subtree)
  6631. (put 'org-agenda-files 'org-restrict
  6632. (list (buffer-file-name (buffer-base-buffer))))
  6633. (org-back-to-heading t)
  6634. (move-overlay org-agenda-restriction-lock-overlay
  6635. (point)
  6636. (if org-agenda-restriction-lock-highlight-subtree
  6637. (save-excursion (org-end-of-subtree t t) (point))
  6638. (point-at-eol)))
  6639. (move-marker org-agenda-restrict-begin (point))
  6640. (move-marker org-agenda-restrict-end
  6641. (save-excursion (org-end-of-subtree t t)))
  6642. (message "Locking agenda restriction to subtree"))
  6643. (put 'org-agenda-files 'org-restrict
  6644. (list (buffer-file-name (buffer-base-buffer))))
  6645. (setq org-agenda-restrict nil)
  6646. (setq org-agenda-overriding-restriction 'file)
  6647. (move-marker org-agenda-restrict-begin nil)
  6648. (move-marker org-agenda-restrict-end nil)
  6649. (message "Locking agenda restriction to file"))
  6650. (setq current-prefix-arg nil)
  6651. (org-agenda-maybe-redo))
  6652. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6653. "Remove the agenda restriction lock."
  6654. (interactive "P")
  6655. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6656. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6657. (setq org-agenda-overriding-restriction nil)
  6658. (setq org-agenda-restrict nil)
  6659. (put 'org-agenda-files 'org-restrict nil)
  6660. (move-marker org-agenda-restrict-begin nil)
  6661. (move-marker org-agenda-restrict-end nil)
  6662. (setq current-prefix-arg nil)
  6663. (message "Agenda restriction lock removed")
  6664. (or noupdate (org-agenda-maybe-redo)))
  6665. (defun org-agenda-maybe-redo ()
  6666. "If there is any window showing the agenda view, update it."
  6667. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6668. (w0 (selected-window)))
  6669. (when w
  6670. (select-window w)
  6671. (org-agenda-redo)
  6672. (select-window w0)
  6673. (if org-agenda-overriding-restriction
  6674. (message "Agenda view shifted to new %s restriction"
  6675. org-agenda-overriding-restriction)
  6676. (message "Agenda restriction lock removed")))))
  6677. ;;; Agenda commands
  6678. (defun org-agenda-check-type (error &rest types)
  6679. "Check if agenda buffer is of allowed type.
  6680. If ERROR is non-nil, throw an error, otherwise just return nil.
  6681. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6682. (if (not org-agenda-type)
  6683. (error "No Org agenda currently displayed")
  6684. (if (memq org-agenda-type types)
  6685. t
  6686. (if error
  6687. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6688. nil))))
  6689. (defun org-agenda-Quit ()
  6690. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6691. Also restore the window configuration."
  6692. (interactive)
  6693. (if org-agenda-columns-active
  6694. (org-columns-quit)
  6695. (let ((buf (current-buffer)))
  6696. (if (eq org-agenda-window-setup 'other-frame)
  6697. (progn
  6698. (org-agenda-reset-markers)
  6699. (kill-buffer buf)
  6700. (org-columns-remove-overlays)
  6701. (setq org-agenda-archives-mode nil)
  6702. (delete-frame))
  6703. (and (not (eq org-agenda-window-setup 'current-window))
  6704. (not (one-window-p))
  6705. (delete-window))
  6706. (org-agenda-reset-markers)
  6707. (kill-buffer buf)
  6708. (org-columns-remove-overlays)
  6709. (setq org-agenda-archives-mode nil)))
  6710. (setq org-agenda-buffer nil)
  6711. ;; Maybe restore the pre-agenda window configuration.
  6712. (and org-agenda-restore-windows-after-quit
  6713. (not (eq org-agenda-window-setup 'other-frame))
  6714. org-agenda-pre-window-conf
  6715. (set-window-configuration org-agenda-pre-window-conf)
  6716. (setq org-agenda-pre-window-conf nil))))
  6717. (defun org-agenda-quit ()
  6718. "Exit the agenda and restore the window configuration.
  6719. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6720. (interactive)
  6721. (if (and (eq org-indirect-buffer-display 'other-window)
  6722. org-last-indirect-buffer)
  6723. (let ((org-last-indirect-window
  6724. (get-buffer-window org-last-indirect-buffer)))
  6725. (if org-last-indirect-window
  6726. (delete-window org-last-indirect-window))))
  6727. (if org-agenda-columns-active
  6728. (org-columns-quit)
  6729. (if org-agenda-sticky
  6730. (let ((buf (current-buffer)))
  6731. (if (eq org-agenda-window-setup 'other-frame)
  6732. (progn
  6733. (delete-frame))
  6734. (and (not (eq org-agenda-window-setup 'current-window))
  6735. (not (one-window-p))
  6736. (delete-window)))
  6737. (with-current-buffer buf
  6738. (bury-buffer)
  6739. ;; Maybe restore the pre-agenda window configuration.
  6740. (and org-agenda-restore-windows-after-quit
  6741. (not (eq org-agenda-window-setup 'other-frame))
  6742. org-agenda-pre-window-conf
  6743. (set-window-configuration org-agenda-pre-window-conf)
  6744. (setq org-agenda-pre-window-conf nil))))
  6745. (org-agenda-Quit))))
  6746. (defun org-agenda-exit ()
  6747. "Exit the agenda and restore the window configuration.
  6748. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6749. buffers visited directly by the user will not be touched."
  6750. (interactive)
  6751. (org-release-buffers org-agenda-new-buffers)
  6752. (setq org-agenda-new-buffers nil)
  6753. (org-agenda-Quit))
  6754. (defun org-agenda-kill-all-agenda-buffers ()
  6755. "Kill all buffers in `org-agenda-mode'.
  6756. This is used when toggling sticky agendas.
  6757. You can also explicitly invoke it with `C-c a C-k'."
  6758. (interactive)
  6759. (let (blist)
  6760. (dolist (buf (buffer-list))
  6761. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6762. (push buf blist)))
  6763. (mapc 'kill-buffer blist)))
  6764. (defun org-agenda-execute (arg)
  6765. "Execute another agenda command, keeping same window.
  6766. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6767. in the agenda."
  6768. (interactive "P")
  6769. (let ((org-agenda-window-setup 'current-window))
  6770. (org-agenda arg)))
  6771. (defun org-agenda-redo (&optional all)
  6772. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6773. (interactive "P")
  6774. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6775. (cpa (unless (eq all t) current-prefix-arg))
  6776. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6777. (org-agenda-sticky nil)
  6778. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6779. org-agenda-buffer-name))
  6780. (org-agenda-keep-modes t)
  6781. (tag-filter org-agenda-tag-filter)
  6782. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6783. (top-hl-filter org-agenda-top-headline-filter)
  6784. (cat-filter org-agenda-category-filter)
  6785. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6786. (re-filter org-agenda-regexp-filter)
  6787. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6788. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6789. (cols org-agenda-columns-active)
  6790. (line (org-current-line))
  6791. (window-line (- line (org-current-line (window-start))))
  6792. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6793. (redo-cmd (get-text-property p 'org-redo-cmd))
  6794. (last-args (get-text-property p 'org-last-args))
  6795. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6796. (org-agenda-overriding-cmd-arguments
  6797. (unless (eq all t)
  6798. (cond ((listp last-args)
  6799. (cons (or cpa (car last-args)) (cdr last-args)))
  6800. ((stringp last-args)
  6801. last-args))))
  6802. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6803. (put 'org-agenda-tag-filter :preset-filter nil)
  6804. (put 'org-agenda-category-filter :preset-filter nil)
  6805. (put 'org-agenda-regexp-filter :preset-filter nil)
  6806. (and cols (org-columns-quit))
  6807. (message "Rebuilding agenda buffer...")
  6808. (if series-redo-cmd
  6809. (eval series-redo-cmd)
  6810. (org-let lprops redo-cmd))
  6811. (setq org-agenda-undo-list nil
  6812. org-agenda-pending-undo-list nil
  6813. org-agenda-tag-filter tag-filter
  6814. org-agenda-category-filter cat-filter
  6815. org-agenda-regexp-filter re-filter
  6816. org-agenda-top-headline-filter top-hl-filter)
  6817. (message "Rebuilding agenda buffer...done")
  6818. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6819. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6820. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6821. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6822. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6823. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6824. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6825. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6826. (org-goto-line line)
  6827. (recenter window-line)))
  6828. (defvar org-global-tags-completion-table nil)
  6829. (defvar org-agenda-filter-form nil)
  6830. (defvar org-agenda-filtered-by-category nil)
  6831. (defun org-agenda-filter-by-category (strip)
  6832. "Keep only those lines in the agenda buffer that have a specific category.
  6833. The category is that of the current line."
  6834. (interactive "P")
  6835. (if (and org-agenda-filtered-by-category
  6836. org-agenda-category-filter)
  6837. (org-agenda-filter-show-all-cat)
  6838. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6839. (cond
  6840. ((and cat strip)
  6841. (org-agenda-filter-apply
  6842. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6843. ((and cat)
  6844. (org-agenda-filter-apply
  6845. (setq org-agenda-category-filter
  6846. (list (concat "+" cat))) 'category))
  6847. ((error "No category at point"))))))
  6848. (defun org-find-top-headline (&optional pos)
  6849. "Find the topmost parent headline and return it."
  6850. (save-excursion
  6851. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6852. (if pos (goto-char pos))
  6853. ;; Skip up to the topmost parent
  6854. (while (ignore-errors (outline-up-heading 1) t))
  6855. (ignore-errors
  6856. (nth 4 (org-heading-components))))))
  6857. (defvar org-agenda-filtered-by-top-headline nil)
  6858. (defun org-agenda-filter-by-top-headline (strip)
  6859. "Keep only those lines that are descendants from the same top headline.
  6860. The top headline is that of the current line."
  6861. (interactive "P")
  6862. (if org-agenda-filtered-by-top-headline
  6863. (progn
  6864. (setq org-agenda-filtered-by-top-headline nil
  6865. org-agenda-top-headline-filter nil)
  6866. (org-agenda-filter-show-all-cat))
  6867. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6868. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6869. (error "No top-level category at point")))))
  6870. (defvar org-agenda-regexp-filter nil)
  6871. (defun org-agenda-filter-by-regexp (strip)
  6872. "Filter agenda entries by a regular expression.
  6873. Regexp filters are cumulative.
  6874. With no prefix argument, keep entries matching the regexp.
  6875. With one prefix argument, filter out entries matching the regexp.
  6876. With two prefix arguments, remove the regexp filters."
  6877. (interactive "P")
  6878. (if (not (equal strip '(16)))
  6879. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6880. (read-from-minibuffer
  6881. (if (equal strip '(4))
  6882. "Filter out entries matching regexp: "
  6883. "Narrow to entries matching regexp: ")))))
  6884. (push flt org-agenda-regexp-filter)
  6885. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6886. (org-agenda-filter-show-all-re)
  6887. (message "Regexp filter removed")))
  6888. (defun org-agenda-filter-remove-all ()
  6889. "Remove all filters from the current agenda buffer."
  6890. (interactive)
  6891. (when org-agenda-tag-filter
  6892. (org-agenda-filter-show-all-tag))
  6893. (when org-agenda-category-filter
  6894. (org-agenda-filter-show-all-cat))
  6895. (when org-agenda-regexp-filter
  6896. (org-agenda-filter-show-all-re)))
  6897. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6898. "Keep only those lines in the agenda buffer that have a specific tag.
  6899. The tag is selected with its fast selection letter, as configured.
  6900. With prefix argument STRIP, remove all lines that do have the tag.
  6901. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6902. used to narrow the search - the interactive user can also press `-' or `+'
  6903. to switch to narrowing."
  6904. (interactive "P")
  6905. (let* ((alist org-tag-alist-for-agenda)
  6906. (tag-chars (mapconcat
  6907. (lambda (x) (if (and (not (symbolp (car x)))
  6908. (cdr x))
  6909. (char-to-string (cdr x))
  6910. ""))
  6911. alist ""))
  6912. (efforts (org-split-string
  6913. (or (cdr (assoc (concat org-effort-property "_ALL")
  6914. org-global-properties))
  6915. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6916. "")))
  6917. (effort-op org-agenda-filter-effort-default-operator)
  6918. (effort-prompt "")
  6919. (inhibit-read-only t)
  6920. (current org-agenda-tag-filter)
  6921. maybe-refresh a n tag)
  6922. (unless char
  6923. (message
  6924. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6925. (if narrow "Narrow" "Filter") tag-chars
  6926. (if org-agenda-auto-exclude-function "[RET], " ""))
  6927. (setq char (read-char-exclusive)))
  6928. (when (member char '(?+ ?-))
  6929. ;; Narrowing down
  6930. (cond ((equal char ?-) (setq strip t narrow t))
  6931. ((equal char ?+) (setq strip nil narrow t)))
  6932. (message
  6933. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6934. (setq char (read-char-exclusive)))
  6935. (when (member char '(?< ?> ?= ??))
  6936. ;; An effort operator
  6937. (setq effort-op (char-to-string char))
  6938. (setq alist nil) ; to make sure it will be interpreted as effort.
  6939. (unless (equal char ??)
  6940. (loop for i from 0 to 9 do
  6941. (setq effort-prompt
  6942. (concat
  6943. effort-prompt " ["
  6944. (if (= i 9) "0" (int-to-string (1+ i)))
  6945. "]" (nth i efforts))))
  6946. (message "Effort%s: %s " effort-op effort-prompt)
  6947. (setq char (read-char-exclusive))
  6948. (when (or (< char ?0) (> char ?9))
  6949. (error "Need 1-9,0 to select effort"))))
  6950. (when (equal char ?\t)
  6951. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6952. (org-set-local 'org-global-tags-completion-table
  6953. (org-global-tags-completion-table)))
  6954. (let ((completion-ignore-case t))
  6955. (setq tag (org-icompleting-read
  6956. "Tag: " org-global-tags-completion-table))))
  6957. (cond
  6958. ((equal char ?\r)
  6959. (org-agenda-filter-show-all-tag)
  6960. (when org-agenda-auto-exclude-function
  6961. (setq org-agenda-tag-filter nil)
  6962. (dolist (tag (org-agenda-get-represented-tags))
  6963. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6964. (if modifier
  6965. (push modifier org-agenda-tag-filter))))
  6966. (if (not (null org-agenda-tag-filter))
  6967. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6968. (setq maybe-refresh t))
  6969. ((equal char ?/)
  6970. (org-agenda-filter-show-all-tag)
  6971. (when (get 'org-agenda-tag-filter :preset-filter)
  6972. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6973. (setq maybe-refresh t))
  6974. ((equal char ?. )
  6975. (setq org-agenda-tag-filter
  6976. (mapcar (lambda(tag) (concat "+" tag))
  6977. (org-get-at-bol 'tags)))
  6978. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6979. (setq maybe-refresh t))
  6980. ((or (equal char ?\ )
  6981. (setq a (rassoc char alist))
  6982. (and (>= char ?0) (<= char ?9)
  6983. (setq n (if (= char ?0) 9 (- char ?0 1))
  6984. tag (concat effort-op (nth n efforts))
  6985. a (cons tag nil)))
  6986. (and (= char ??)
  6987. (setq tag "?eff")
  6988. a (cons tag nil))
  6989. (and tag (setq a (cons tag nil))))
  6990. (org-agenda-filter-show-all-tag)
  6991. (setq tag (car a))
  6992. (setq org-agenda-tag-filter
  6993. (cons (concat (if strip "-" "+") tag)
  6994. (if narrow current nil)))
  6995. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6996. (setq maybe-refresh t))
  6997. (t (error "Invalid tag selection character %c" char)))
  6998. (when (and maybe-refresh
  6999. (eq org-agenda-clockreport-mode 'with-filter))
  7000. (org-agenda-redo))))
  7001. (defun org-agenda-get-represented-tags ()
  7002. "Get a list of all tags currently represented in the agenda."
  7003. (let (p tags)
  7004. (save-excursion
  7005. (goto-char (point-min))
  7006. (while (setq p (next-single-property-change (point) 'tags))
  7007. (goto-char p)
  7008. (mapc (lambda (x) (add-to-list 'tags x))
  7009. (get-text-property (point) 'tags))))
  7010. tags))
  7011. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  7012. "Refine the current filter. See `org-agenda-filter-by-tag'."
  7013. (interactive "P")
  7014. (org-agenda-filter-by-tag strip char 'refine))
  7015. (defun org-agenda-filter-make-matcher (filter type)
  7016. "Create the form that tests a line for agenda filter."
  7017. (let (f f1)
  7018. (cond
  7019. ;; Tag filter
  7020. ((eq type 'tag)
  7021. (setq filter
  7022. (delete-dups
  7023. (append (get 'org-agenda-tag-filter :preset-filter)
  7024. filter)))
  7025. (dolist (x filter)
  7026. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7027. (ffunc
  7028. (lambda (nf0 nf01 fltr notgroup op)
  7029. (dolist (x fltr)
  7030. (if (member x '("-" "+"))
  7031. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7032. (if (string-match "[<=>?]" x)
  7033. (setq nf01 (org-agenda-filter-effort-form x))
  7034. (setq nf01 (list 'member (downcase (substring x 1))
  7035. 'tags)))
  7036. (when (equal (string-to-char x) ?-)
  7037. (setq nf01 (list 'not nf01))
  7038. (when (not notgroup) (setq op 'and))))
  7039. (push nf01 nf0))
  7040. (if notgroup
  7041. (push (cons 'and nf0) f)
  7042. (push (cons (or op 'or) nf0) f)))))
  7043. (cond ((equal filter '("+"))
  7044. (setq f (list (list 'not 'tags))))
  7045. ((equal nfilter filter)
  7046. (funcall ffunc f1 f filter t nil))
  7047. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  7048. ;; Category filter
  7049. ((eq type 'category)
  7050. (setq filter
  7051. (delete-dups
  7052. (append (get 'org-agenda-category-filter :preset-filter)
  7053. filter)))
  7054. (dolist (x filter)
  7055. (if (equal "-" (substring x 0 1))
  7056. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7057. (setq f1 (list 'equal (substring x 1) 'cat)))
  7058. (push f1 f)))
  7059. ;; Regexp filter
  7060. ((eq type 'regexp)
  7061. (setq filter
  7062. (delete-dups
  7063. (append (get 'org-agenda-regexp-filter :preset-filter)
  7064. filter)))
  7065. (dolist (x filter)
  7066. (if (equal "-" (substring x 0 1))
  7067. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7068. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7069. (push f1 f))))
  7070. (cons 'and (nreverse f))))
  7071. (defun org-agenda-filter-effort-form (e)
  7072. "Return the form to compare the effort of the current line with what E says.
  7073. E looks like \"+<2:25\"."
  7074. (let (op)
  7075. (setq e (substring e 1))
  7076. (setq op (string-to-char e) e (substring e 1))
  7077. (setq op (cond ((equal op ?<) '<=)
  7078. ((equal op ?>) '>=)
  7079. ((equal op ??) op)
  7080. (t '=)))
  7081. (list 'org-agenda-compare-effort (list 'quote op)
  7082. (org-duration-string-to-minutes e))))
  7083. (defun org-agenda-compare-effort (op value)
  7084. "Compare the effort of the current line with VALUE, using OP.
  7085. If the line does not have an effort defined, return nil."
  7086. (let ((eff (org-get-at-bol 'effort-minutes)))
  7087. (if (equal op ??)
  7088. (not eff)
  7089. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7090. value))))
  7091. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7092. "Expand group tags in FILTER for the agenda.
  7093. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7094. (if org-group-tags
  7095. (let ((case-fold-search t) rtn)
  7096. (mapc
  7097. (lambda (f)
  7098. (let (f0 dir)
  7099. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7100. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7101. (setq dir (if no-operator "" "+") f0 f))
  7102. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7103. (org-tags-expand f0 t t))
  7104. rtn))))
  7105. filter)
  7106. (reverse rtn))
  7107. filter))
  7108. (defun org-agenda-filter-apply (filter type)
  7109. "Set FILTER as the new agenda filter and apply it."
  7110. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7111. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7112. (let (tags cat txt)
  7113. (setq org-agenda-filter-form
  7114. (org-agenda-filter-make-matcher filter type))
  7115. (if (and (eq type 'category)
  7116. (not (equal (substring (car filter) 0 1) "-")))
  7117. ;; Only set `org-agenda-filtered-by-category' to t
  7118. ;; when a unique category is used as the filter
  7119. (setq org-agenda-filtered-by-category t))
  7120. (org-agenda-set-mode-name)
  7121. (save-excursion
  7122. (goto-char (point-min))
  7123. (while (not (eobp))
  7124. (if (org-get-at-bol 'org-marker)
  7125. (progn
  7126. (setq tags ; used in eval
  7127. (apply 'append
  7128. (mapcar (lambda (f)
  7129. (org-agenda-filter-expand-tags (list f) t))
  7130. (org-get-at-bol 'tags)))
  7131. cat (get-text-property (point) 'org-category)
  7132. txt (get-text-property (point) 'txt))
  7133. (if (not (eval org-agenda-filter-form))
  7134. (org-agenda-filter-hide-line type))
  7135. (beginning-of-line 2))
  7136. (beginning-of-line 2))))
  7137. (if (get-char-property (point) 'invisible)
  7138. (ignore-errors (org-agenda-previous-line)))))
  7139. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7140. "Filter by top headline HL."
  7141. (org-agenda-set-mode-name)
  7142. (save-excursion
  7143. (goto-char (point-min))
  7144. (while (not (eobp))
  7145. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7146. (tophl (and pos (org-find-top-headline pos))))
  7147. (if (and tophl (funcall (if negative 'identity 'not)
  7148. (string= hl tophl)))
  7149. (org-agenda-filter-hide-line 'category)))
  7150. (beginning-of-line 2)))
  7151. (if (get-char-property (point) 'invisible)
  7152. (org-agenda-previous-line))
  7153. (setq org-agenda-top-headline-filter hl
  7154. org-agenda-filtered-by-top-headline t))
  7155. (defun org-agenda-filter-hide-line (type)
  7156. "Hide lines with TYPE in the agenda buffer."
  7157. (let* ((b (max (point-min) (1- (point-at-bol))))
  7158. (e (point-at-eol))
  7159. (ov (make-overlay b e)))
  7160. (overlay-put ov 'invisible t)
  7161. (overlay-put ov 'intangible t)
  7162. (overlay-put ov 'type type)
  7163. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7164. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7165. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7166. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7167. (setq pos (or pos (point)))
  7168. (save-excursion
  7169. (dolist (ov (overlays-at pos))
  7170. (when (and (overlay-get ov 'invisible)
  7171. (eq (overlay-get ov 'type) 'tag))
  7172. (goto-char pos)
  7173. (if (< (overlay-start ov) (point-at-eol))
  7174. (move-overlay ov (point-at-eol)
  7175. (overlay-end ov)))))))
  7176. (defun org-agenda-filter-show-all-tag nil
  7177. "Remove tag filter overlays from the agenda buffer."
  7178. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7179. (setq org-agenda-tag-filter-overlays nil
  7180. org-agenda-tag-filter nil
  7181. org-agenda-filter-form nil)
  7182. (org-agenda-set-mode-name))
  7183. (defun org-agenda-filter-show-all-re nil
  7184. "Remove regexp filter overlays from the agenda buffer."
  7185. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7186. (setq org-agenda-re-filter-overlays nil
  7187. org-agenda-regexp-filter nil
  7188. org-agenda-filter-form nil)
  7189. (org-agenda-set-mode-name))
  7190. (defun org-agenda-filter-show-all-cat nil
  7191. "Remove category filter overlays from the agenda buffer."
  7192. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7193. (setq org-agenda-cat-filter-overlays nil
  7194. org-agenda-filtered-by-category nil
  7195. org-agenda-category-filter nil
  7196. org-agenda-filter-form nil)
  7197. (org-agenda-set-mode-name))
  7198. (defun org-agenda-manipulate-query-add ()
  7199. "Manipulate the query by adding a search term with positive selection.
  7200. Positive selection means the term must be matched for selection of an entry."
  7201. (interactive)
  7202. (org-agenda-manipulate-query ?\[))
  7203. (defun org-agenda-manipulate-query-subtract ()
  7204. "Manipulate the query by adding a search term with negative selection.
  7205. Negative selection means term must not be matched for selection of an entry."
  7206. (interactive)
  7207. (org-agenda-manipulate-query ?\]))
  7208. (defun org-agenda-manipulate-query-add-re ()
  7209. "Manipulate the query by adding a search regexp with positive selection.
  7210. Positive selection means the regexp must match for selection of an entry."
  7211. (interactive)
  7212. (org-agenda-manipulate-query ?\{))
  7213. (defun org-agenda-manipulate-query-subtract-re ()
  7214. "Manipulate the query by adding a search regexp with negative selection.
  7215. Negative selection means regexp must not match for selection of an entry."
  7216. (interactive)
  7217. (org-agenda-manipulate-query ?\}))
  7218. (defun org-agenda-manipulate-query (char)
  7219. (cond
  7220. ((memq org-agenda-type '(timeline agenda))
  7221. (let ((org-agenda-include-inactive-timestamps t))
  7222. (org-agenda-redo))
  7223. (message "Display now includes inactive timestamps as well"))
  7224. ((eq org-agenda-type 'search)
  7225. (org-add-to-string
  7226. 'org-agenda-query-string
  7227. (if org-agenda-last-search-view-search-was-boolean
  7228. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7229. (?\{ . " +{}") (?\} . " -{}"))))
  7230. " "))
  7231. (setq org-agenda-redo-command
  7232. (list 'org-search-view
  7233. (car (get-text-property (min (1- (point-max)) (point))
  7234. 'org-last-args))
  7235. org-agenda-query-string
  7236. (+ (length org-agenda-query-string)
  7237. (if (member char '(?\{ ?\})) 0 1))))
  7238. (set-register org-agenda-query-register org-agenda-query-string)
  7239. (let ((org-agenda-overriding-arguments
  7240. (cdr org-agenda-redo-command)))
  7241. (org-agenda-redo)))
  7242. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7243. org-agenda-type))))
  7244. (defun org-add-to-string (var string)
  7245. (set var (concat (symbol-value var) string)))
  7246. (defun org-agenda-goto-date (span)
  7247. "Jump to DATE in agenda."
  7248. (interactive "P")
  7249. (let* ((org-read-date-prefer-future
  7250. (eval org-agenda-jump-prefer-future))
  7251. (date (org-read-date))
  7252. (day (time-to-days (org-time-string-to-time date)))
  7253. (org-agenda-sticky-orig org-agenda-sticky)
  7254. (org-agenda-buffer-tmp-name (buffer-name))
  7255. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7256. (0-arg (or current-prefix-arg (car args)))
  7257. (2-arg (nth 2 args))
  7258. (with-hour-p (nth 4 org-agenda-redo-command))
  7259. (newcmd (list 'org-agenda-list 0-arg date
  7260. (org-agenda-span-to-ndays
  7261. 2-arg (org-time-string-to-absolute date))
  7262. with-hour-p))
  7263. (newargs (cdr newcmd))
  7264. (inhibit-read-only t)
  7265. org-agenda-sticky)
  7266. (if (not (org-agenda-check-type t 'agenda))
  7267. (error "Not available in non-agenda views")
  7268. (add-text-properties (point-min) (point-max)
  7269. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7270. (org-agenda-redo)
  7271. (goto-char (point-min))
  7272. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7273. (save-excursion (move-beginning-of-line 2) (eobp))))
  7274. (move-beginning-of-line 2))
  7275. (setq org-agenda-sticky org-agenda-sticky-orig
  7276. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7277. (defun org-agenda-goto-today ()
  7278. "Go to today."
  7279. (interactive)
  7280. (org-agenda-check-type t 'timeline 'agenda)
  7281. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7282. (curspan (nth 2 args))
  7283. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7284. (cond
  7285. (tdpos (goto-char tdpos))
  7286. ((eq org-agenda-type 'agenda)
  7287. (let* ((sd (org-agenda-compute-starting-span
  7288. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7289. (org-agenda-overriding-arguments args))
  7290. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7291. (org-agenda-redo)
  7292. (org-agenda-find-same-or-today-or-agenda)))
  7293. (t (error "Cannot find today")))))
  7294. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7295. (goto-char
  7296. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7297. (text-property-any (point-min) (point-max) 'org-today t)
  7298. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7299. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7300. (org-agenda-backward-block))
  7301. (point-min))))
  7302. (defun org-agenda-backward-block ()
  7303. "Move backward by one agenda block."
  7304. (interactive)
  7305. (org-agenda-forward-block 'backward))
  7306. (defun org-agenda-forward-block (&optional backward)
  7307. "Move forward by one agenda block.
  7308. When optional argument BACKWARD is set, go backward"
  7309. (interactive)
  7310. (cond ((not (derived-mode-p 'org-agenda-mode))
  7311. (user-error
  7312. "Cannot execute this command outside of org-agenda-mode buffers"))
  7313. ((looking-at (if backward "\\`" "\\'"))
  7314. (message "Already at the %s block" (if backward "first" "last")))
  7315. (t (let ((pos (prog1 (point)
  7316. (ignore-errors (if backward (backward-char 1)
  7317. (move-end-of-line 1)))))
  7318. (f (if backward
  7319. 'previous-single-property-change
  7320. 'next-single-property-change))
  7321. moved dest)
  7322. (while (and (setq dest (funcall
  7323. f (point) 'org-agenda-structural-header))
  7324. (not (get-text-property
  7325. (point) 'org-agenda-structural-header)))
  7326. (setq moved t)
  7327. (goto-char dest))
  7328. (if moved (move-beginning-of-line 1)
  7329. (goto-char (if backward (point-min) (point-max)))
  7330. (move-beginning-of-line 1)
  7331. (message "No %s block" (if backward "previous" "further")))))))
  7332. (defun org-agenda-later (arg)
  7333. "Go forward in time by the current span.
  7334. With prefix ARG, go forward that many times the current span."
  7335. (interactive "p")
  7336. (org-agenda-check-type t 'agenda)
  7337. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7338. (span (or (nth 2 args) org-agenda-current-span))
  7339. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7340. (greg (calendar-gregorian-from-absolute sd))
  7341. (cnt (org-get-at-bol 'org-day-cnt))
  7342. greg2)
  7343. (cond
  7344. ((numberp span)
  7345. (setq sd (+ (* span arg) sd)))
  7346. ((eq span 'day)
  7347. (setq sd (+ arg sd)))
  7348. ((eq span 'week)
  7349. (setq sd (+ (* 7 arg) sd)))
  7350. ((eq span 'fortnight)
  7351. (setq sd (+ (* 14 arg) sd)))
  7352. ((eq span 'month)
  7353. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7354. sd (calendar-absolute-from-gregorian greg2))
  7355. (setcar greg2 (1+ (car greg2))))
  7356. ((eq span 'year)
  7357. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7358. sd (calendar-absolute-from-gregorian greg2))
  7359. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7360. (t
  7361. (setq sd (+ (* span arg) sd))))
  7362. (let ((org-agenda-overriding-cmd
  7363. ;; `cmd' may have been set by `org-agenda-run-series' which
  7364. ;; uses `org-agenda-overriding-cmd' to decide whether
  7365. ;; overriding is allowed for `cmd'
  7366. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7367. (org-agenda-overriding-arguments
  7368. (list (car args) sd span)))
  7369. (org-agenda-redo)
  7370. (org-agenda-find-same-or-today-or-agenda cnt))))
  7371. (defun org-agenda-earlier (arg)
  7372. "Go backward in time by the current span.
  7373. With prefix ARG, go backward that many times the current span."
  7374. (interactive "p")
  7375. (org-agenda-later (- arg)))
  7376. (defun org-agenda-view-mode-dispatch ()
  7377. "Call one of the view mode commands."
  7378. (interactive)
  7379. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7380. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7381. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7382. (let ((a (read-char-exclusive)))
  7383. (case a
  7384. (?\ (call-interactively 'org-agenda-reset-view))
  7385. (?d (call-interactively 'org-agenda-day-view))
  7386. (?w (call-interactively 'org-agenda-week-view))
  7387. (?t (call-interactively 'org-agenda-fortnight-view))
  7388. (?m (call-interactively 'org-agenda-month-view))
  7389. (?y (call-interactively 'org-agenda-year-view))
  7390. (?l (call-interactively 'org-agenda-log-mode))
  7391. (?L (org-agenda-log-mode '(4)))
  7392. (?c (org-agenda-log-mode 'clockcheck))
  7393. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7394. (?a (call-interactively 'org-agenda-archives-mode))
  7395. (?A (org-agenda-archives-mode 'files))
  7396. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7397. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7398. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7399. (?D (call-interactively 'org-agenda-toggle-diary))
  7400. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7401. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7402. (org-agenda-check-type t 'timeline 'agenda)
  7403. (org-agenda-redo))
  7404. (message "Display now includes inactive timestamps as well"))
  7405. (?q (message "Abort"))
  7406. (otherwise (error "Invalid key" )))))
  7407. (defun org-agenda-reset-view ()
  7408. "Switch to default view for agenda."
  7409. (interactive)
  7410. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7411. (defun org-agenda-day-view (&optional day-of-month)
  7412. "Switch to daily view for agenda.
  7413. With argument DAY-OF-MONTH, switch to that day of the month."
  7414. (interactive "P")
  7415. (org-agenda-change-time-span 'day day-of-month))
  7416. (defun org-agenda-week-view (&optional iso-week)
  7417. "Switch to daily view for agenda.
  7418. With argument ISO-WEEK, switch to the corresponding ISO week.
  7419. If ISO-WEEK has more then 2 digits, only the last two encode the
  7420. week. Any digits before this encode a year. So 200712 means
  7421. week 12 of year 2007. Years in the range 1938-2037 can also be
  7422. written as 2-digit years."
  7423. (interactive "P")
  7424. (org-agenda-change-time-span 'week iso-week))
  7425. (defun org-agenda-fortnight-view (&optional iso-week)
  7426. "Switch to daily view for agenda.
  7427. With argument ISO-WEEK, switch to the corresponding ISO week.
  7428. If ISO-WEEK has more then 2 digits, only the last two encode the
  7429. week. Any digits before this encode a year. So 200712 means
  7430. week 12 of year 2007. Years in the range 1938-2037 can also be
  7431. written as 2-digit years."
  7432. (interactive "P")
  7433. (org-agenda-change-time-span 'fortnight iso-week))
  7434. (defun org-agenda-month-view (&optional month)
  7435. "Switch to monthly view for agenda.
  7436. With argument MONTH, switch to that month."
  7437. (interactive "P")
  7438. (org-agenda-change-time-span 'month month))
  7439. (defun org-agenda-year-view (&optional year)
  7440. "Switch to yearly view for agenda.
  7441. With argument YEAR, switch to that year.
  7442. If MONTH has more then 2 digits, only the last two encode the
  7443. month. Any digits before this encode a year. So 200712 means
  7444. December year 2007. Years in the range 1938-2037 can also be
  7445. written as 2-digit years."
  7446. (interactive "P")
  7447. (when year
  7448. (setq year (org-small-year-to-year year)))
  7449. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7450. (org-agenda-change-time-span 'year year)
  7451. (error "Abort")))
  7452. (defun org-agenda-change-time-span (span &optional n)
  7453. "Change the agenda view to SPAN.
  7454. SPAN may be `day', `week', `fortnight', `month', `year'."
  7455. (org-agenda-check-type t 'agenda)
  7456. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7457. (curspan (nth 2 args)))
  7458. (if (and (not n) (equal curspan span))
  7459. (error "Viewing span is already \"%s\"" span))
  7460. (let* ((sd (or (org-get-at-bol 'day)
  7461. (nth 1 args)
  7462. org-starting-day))
  7463. (sd (org-agenda-compute-starting-span sd span n))
  7464. (org-agenda-overriding-cmd
  7465. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7466. (org-agenda-overriding-arguments
  7467. (list (car args) sd span)))
  7468. (org-agenda-redo)
  7469. (org-agenda-find-same-or-today-or-agenda))
  7470. (org-agenda-set-mode-name)
  7471. (message "Switched to %s view" span)))
  7472. (defun org-agenda-compute-starting-span (sd span &optional n)
  7473. "Compute starting date for agenda.
  7474. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7475. is a cons cell with the starting date and the number of days,
  7476. so that the date SD will be in that range."
  7477. (let* ((greg (calendar-gregorian-from-absolute sd))
  7478. (dg (nth 1 greg))
  7479. (mg (car greg))
  7480. (yg (nth 2 greg)))
  7481. (cond
  7482. ((eq span 'day)
  7483. (when n
  7484. (setq sd (+ (calendar-absolute-from-gregorian
  7485. (list mg 1 yg))
  7486. n -1))))
  7487. ((or (eq span 'week) (eq span 'fortnight))
  7488. (let* ((nt (calendar-day-of-week
  7489. (calendar-gregorian-from-absolute sd)))
  7490. (d (if org-agenda-start-on-weekday
  7491. (- nt org-agenda-start-on-weekday)
  7492. 0))
  7493. y1)
  7494. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7495. (when n
  7496. (require 'cal-iso)
  7497. (when (> n 99)
  7498. (setq y1 (org-small-year-to-year (/ n 100))
  7499. n (mod n 100)))
  7500. (setq sd
  7501. (calendar-absolute-from-iso
  7502. (list n 1
  7503. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7504. ((eq span 'month)
  7505. (let (y1)
  7506. (when (and n (> n 99))
  7507. (setq y1 (org-small-year-to-year (/ n 100))
  7508. n (mod n 100)))
  7509. (setq sd (calendar-absolute-from-gregorian
  7510. (list (or n mg) 1 (or y1 yg))))))
  7511. ((eq span 'year)
  7512. (setq sd (calendar-absolute-from-gregorian
  7513. (list 1 1 (or n yg))))))
  7514. sd))
  7515. (defun org-agenda-next-date-line (&optional arg)
  7516. "Jump to the next line indicating a date in agenda buffer."
  7517. (interactive "p")
  7518. (org-agenda-check-type t 'agenda 'timeline)
  7519. (beginning-of-line 1)
  7520. ;; This does not work if user makes date format that starts with a blank
  7521. (if (looking-at "^\\S-") (forward-char 1))
  7522. (if (not (re-search-forward "^\\S-" nil t arg))
  7523. (progn
  7524. (backward-char 1)
  7525. (error "No next date after this line in this buffer")))
  7526. (goto-char (match-beginning 0)))
  7527. (defun org-agenda-previous-date-line (&optional arg)
  7528. "Jump to the previous line indicating a date in agenda buffer."
  7529. (interactive "p")
  7530. (org-agenda-check-type t 'agenda 'timeline)
  7531. (beginning-of-line 1)
  7532. (if (not (re-search-backward "^\\S-" nil t arg))
  7533. (error "No previous date before this line in this buffer")))
  7534. ;; Initialize the highlight
  7535. (defvar org-hl (make-overlay 1 1))
  7536. (overlay-put org-hl 'face 'highlight)
  7537. (defun org-highlight (begin end &optional buffer)
  7538. "Highlight a region with overlay."
  7539. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7540. (defun org-unhighlight ()
  7541. "Detach overlay INDEX."
  7542. (org-detach-overlay org-hl))
  7543. (defun org-unhighlight-once ()
  7544. "Remove the highlight from its position, and this function from the hook."
  7545. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7546. (org-unhighlight))
  7547. (defvar org-agenda-pre-follow-window-conf nil)
  7548. (defun org-agenda-follow-mode ()
  7549. "Toggle follow mode in an agenda buffer."
  7550. (interactive)
  7551. (unless org-agenda-follow-mode
  7552. (setq org-agenda-pre-follow-window-conf
  7553. (current-window-configuration)))
  7554. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7555. (unless org-agenda-follow-mode
  7556. (set-window-configuration org-agenda-pre-follow-window-conf))
  7557. (org-agenda-set-mode-name)
  7558. (org-agenda-do-context-action)
  7559. (message "Follow mode is %s"
  7560. (if org-agenda-follow-mode "on" "off")))
  7561. (defun org-agenda-entry-text-mode (&optional arg)
  7562. "Toggle entry text mode in an agenda buffer."
  7563. (interactive "P")
  7564. (if (or org-agenda-tag-filter
  7565. org-agenda-category-filter
  7566. org-agenda-regexp-filter
  7567. org-agenda-top-headline-filter)
  7568. (user-error "Can't show entry text in filtered views")
  7569. (setq org-agenda-entry-text-mode (or (integerp arg)
  7570. (not org-agenda-entry-text-mode)))
  7571. (org-agenda-entry-text-hide)
  7572. (and org-agenda-entry-text-mode
  7573. (let ((org-agenda-entry-text-maxlines
  7574. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7575. (org-agenda-entry-text-show)))
  7576. (org-agenda-set-mode-name)
  7577. (message "Entry text mode is %s%s"
  7578. (if org-agenda-entry-text-mode "on" "off")
  7579. (if (not org-agenda-entry-text-mode) ""
  7580. (format " (maximum number of lines is %d)"
  7581. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7582. (defun org-agenda-clockreport-mode (&optional with-filter)
  7583. "Toggle clocktable mode in an agenda buffer.
  7584. With prefix arg WITH-FILTER, make the clocktable respect the current
  7585. agenda filter."
  7586. (interactive "P")
  7587. (org-agenda-check-type t 'agenda)
  7588. (if with-filter
  7589. (setq org-agenda-clockreport-mode 'with-filter)
  7590. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7591. (org-agenda-set-mode-name)
  7592. (org-agenda-redo)
  7593. (message "Clocktable mode is %s"
  7594. (if org-agenda-clockreport-mode "on" "off")))
  7595. (defun org-agenda-log-mode (&optional special)
  7596. "Toggle log mode in an agenda buffer.
  7597. With argument SPECIAL, show all possible log items, not only the ones
  7598. configured in `org-agenda-log-mode-items'.
  7599. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7600. (interactive "P")
  7601. (org-agenda-check-type t 'agenda 'timeline)
  7602. (setq org-agenda-show-log
  7603. (cond
  7604. ((equal special '(16)) 'only)
  7605. ((eq special 'clockcheck)
  7606. (if (eq org-agenda-show-log 'clockcheck)
  7607. nil 'clockcheck))
  7608. (special '(closed clock state))
  7609. (t (not org-agenda-show-log))))
  7610. (org-agenda-set-mode-name)
  7611. (org-agenda-redo)
  7612. (message "Log mode is %s"
  7613. (if org-agenda-show-log "on" "off")))
  7614. (defun org-agenda-archives-mode (&optional with-files)
  7615. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7616. When called with a prefix argument, include all archive files as well."
  7617. (interactive "P")
  7618. (setq org-agenda-archives-mode
  7619. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7620. (org-agenda-set-mode-name)
  7621. (org-agenda-redo)
  7622. (message
  7623. "%s"
  7624. (cond
  7625. ((eq org-agenda-archives-mode nil)
  7626. "No archives are included")
  7627. ((eq org-agenda-archives-mode 'trees)
  7628. (format "Trees with :%s: tag are included" org-archive-tag))
  7629. ((eq org-agenda-archives-mode t)
  7630. (format "Trees with :%s: tag and all active archive files are included"
  7631. org-archive-tag)))))
  7632. (defun org-agenda-toggle-diary ()
  7633. "Toggle diary inclusion in an agenda buffer."
  7634. (interactive)
  7635. (org-agenda-check-type t 'agenda)
  7636. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7637. (org-agenda-redo)
  7638. (org-agenda-set-mode-name)
  7639. (message "Diary inclusion turned %s"
  7640. (if org-agenda-include-diary "on" "off")))
  7641. (defun org-agenda-toggle-deadlines ()
  7642. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7643. (interactive)
  7644. (org-agenda-check-type t 'agenda)
  7645. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7646. (org-agenda-redo)
  7647. (org-agenda-set-mode-name)
  7648. (message "Deadlines inclusion turned %s"
  7649. (if org-agenda-include-deadlines "on" "off")))
  7650. (defun org-agenda-toggle-time-grid ()
  7651. "Toggle time grid in an agenda buffer."
  7652. (interactive)
  7653. (org-agenda-check-type t 'agenda)
  7654. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7655. (org-agenda-redo)
  7656. (org-agenda-set-mode-name)
  7657. (message "Time-grid turned %s"
  7658. (if org-agenda-use-time-grid "on" "off")))
  7659. (defun org-agenda-set-mode-name ()
  7660. "Set the mode name to indicate all the small mode settings."
  7661. (setq mode-name
  7662. (list "Org-Agenda"
  7663. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7664. " "
  7665. '(:eval (org-agenda-span-name org-agenda-current-span))
  7666. (if org-agenda-follow-mode " Follow" "")
  7667. (if org-agenda-entry-text-mode " ETxt" "")
  7668. (if org-agenda-include-diary " Diary" "")
  7669. (if org-agenda-include-deadlines " Ddl" "")
  7670. (if org-agenda-use-time-grid " Grid" "")
  7671. (if (and (boundp 'org-habit-show-habits)
  7672. org-habit-show-habits) " Habit" "")
  7673. (cond
  7674. ((consp org-agenda-show-log) " LogAll")
  7675. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7676. (org-agenda-show-log " Log")
  7677. (t ""))
  7678. (if (or org-agenda-category-filter
  7679. (get 'org-agenda-category-filter :preset-filter))
  7680. '(:eval (org-propertize
  7681. (concat " <"
  7682. (mapconcat
  7683. 'identity
  7684. (append
  7685. (get 'org-agenda-category-filter :preset-filter)
  7686. org-agenda-category-filter)
  7687. "")
  7688. ">")
  7689. 'face 'org-agenda-filter-category
  7690. 'help-echo "Category used in filtering")) "")
  7691. (if (or org-agenda-tag-filter
  7692. (get 'org-agenda-tag-filter :preset-filter))
  7693. '(:eval (org-propertize
  7694. (concat " {"
  7695. (mapconcat
  7696. 'identity
  7697. (append
  7698. (get 'org-agenda-tag-filter :preset-filter)
  7699. org-agenda-tag-filter)
  7700. "")
  7701. "}")
  7702. 'face 'org-agenda-filter-tags
  7703. 'help-echo "Tags used in filtering")) "")
  7704. (if (or org-agenda-regexp-filter
  7705. (get 'org-agenda-regexp-filter :preset-filter))
  7706. '(:eval (org-propertize
  7707. (concat " ["
  7708. (mapconcat
  7709. 'identity
  7710. (append
  7711. (get 'org-agenda-regexp-filter :preset-filter)
  7712. org-agenda-regexp-filter)
  7713. "")
  7714. "]")
  7715. 'face 'org-agenda-filter-regexp
  7716. 'help-echo "Regexp used in filtering")) "")
  7717. (if org-agenda-archives-mode
  7718. (if (eq org-agenda-archives-mode t)
  7719. " Archives"
  7720. (format " :%s:" org-archive-tag))
  7721. "")
  7722. (if org-agenda-clockreport-mode
  7723. (if (eq org-agenda-clockreport-mode 'with-filter)
  7724. " Clock{}" " Clock")
  7725. "")))
  7726. (force-mode-line-update))
  7727. (define-obsolete-function-alias
  7728. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7729. (defun org-agenda-update-agenda-type ()
  7730. "Update the agenda type after each command."
  7731. (setq org-agenda-type
  7732. (or (get-text-property (point) 'org-agenda-type)
  7733. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7734. (defun org-agenda-next-line ()
  7735. "Move cursor to the next line, and show if follow mode is active."
  7736. (interactive)
  7737. (call-interactively 'next-line)
  7738. (org-agenda-do-context-action))
  7739. (defun org-agenda-previous-line ()
  7740. "Move cursor to the previous line, and show if follow-mode is active."
  7741. (interactive)
  7742. (call-interactively 'previous-line)
  7743. (org-agenda-do-context-action))
  7744. (defun org-agenda-next-item (n)
  7745. "Move cursor to next agenda item."
  7746. (interactive "p")
  7747. (let ((col (current-column)))
  7748. (dotimes (c n)
  7749. (when (next-single-property-change (point-at-eol) 'org-marker)
  7750. (move-end-of-line 1)
  7751. (goto-char (next-single-property-change (point) 'org-marker))))
  7752. (org-move-to-column col))
  7753. (org-agenda-do-context-action))
  7754. (defun org-agenda-previous-item (n)
  7755. "Move cursor to next agenda item."
  7756. (interactive "p")
  7757. (dotimes (c n)
  7758. (let ((col (current-column))
  7759. (goto (save-excursion
  7760. (move-end-of-line 0)
  7761. (previous-single-property-change (point) 'org-marker))))
  7762. (if goto (goto-char goto))
  7763. (org-move-to-column col)))
  7764. (org-agenda-do-context-action))
  7765. (defun org-agenda-do-context-action ()
  7766. "Show outline path and, maybe, follow mode window."
  7767. (let ((m (org-get-at-bol 'org-marker)))
  7768. (when (and (markerp m) (marker-buffer m))
  7769. (and org-agenda-follow-mode
  7770. (if org-agenda-follow-indirect
  7771. (org-agenda-tree-to-indirect-buffer nil)
  7772. (org-agenda-show)))
  7773. (and org-agenda-show-outline-path
  7774. (org-with-point-at m (org-display-outline-path t))))))
  7775. (defun org-agenda-show-tags ()
  7776. "Show the tags applicable to the current item."
  7777. (interactive)
  7778. (let* ((tags (org-get-at-bol 'tags)))
  7779. (if tags
  7780. (message "Tags are :%s:"
  7781. (org-no-properties (mapconcat 'identity tags ":")))
  7782. (message "No tags associated with this line"))))
  7783. (defun org-agenda-goto (&optional highlight)
  7784. "Go to the Org-mode file which contains the item at point."
  7785. (interactive)
  7786. (let* ((marker (or (org-get-at-bol 'org-marker)
  7787. (org-agenda-error)))
  7788. (buffer (marker-buffer marker))
  7789. (pos (marker-position marker)))
  7790. (switch-to-buffer-other-window buffer)
  7791. (widen)
  7792. (push-mark)
  7793. (goto-char pos)
  7794. (when (derived-mode-p 'org-mode)
  7795. (org-show-context 'agenda)
  7796. (save-excursion
  7797. (and (outline-next-heading)
  7798. (org-flag-heading nil)))) ; show the next heading
  7799. (when (outline-invisible-p)
  7800. (show-entry)) ; display invisible text
  7801. (recenter (/ (window-height) 2))
  7802. (run-hooks 'org-agenda-after-show-hook)
  7803. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7804. (defvar org-agenda-after-show-hook nil
  7805. "Normal hook run after an item has been shown from the agenda.
  7806. Point is in the buffer where the item originated.")
  7807. (defun org-agenda-kill ()
  7808. "Kill the entry or subtree belonging to the current agenda entry."
  7809. (interactive)
  7810. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7811. (let* ((bufname-orig (buffer-name))
  7812. (marker (or (org-get-at-bol 'org-marker)
  7813. (org-agenda-error)))
  7814. (buffer (marker-buffer marker))
  7815. (pos (marker-position marker))
  7816. (type (org-get-at-bol 'type))
  7817. dbeg dend (n 0) conf)
  7818. (org-with-remote-undo buffer
  7819. (with-current-buffer buffer
  7820. (save-excursion
  7821. (goto-char pos)
  7822. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7823. (setq dbeg (progn (org-back-to-heading t) (point))
  7824. dend (org-end-of-subtree t t))
  7825. (setq dbeg (point-at-bol)
  7826. dend (min (point-max) (1+ (point-at-eol)))))
  7827. (goto-char dbeg)
  7828. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7829. (setq conf (or (eq t org-agenda-confirm-kill)
  7830. (and (numberp org-agenda-confirm-kill)
  7831. (> n org-agenda-confirm-kill))))
  7832. (and conf
  7833. (not (y-or-n-p
  7834. (format "Delete entry with %d lines in buffer \"%s\"? "
  7835. n (buffer-name buffer))))
  7836. (error "Abort"))
  7837. (let ((org-agenda-buffer-name bufname-orig))
  7838. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7839. (with-current-buffer buffer (delete-region dbeg dend))
  7840. (message "Agenda item and source killed"))))
  7841. (defvar org-archive-default-command) ; defined in org-archive.el
  7842. (defun org-agenda-archive-default ()
  7843. "Archive the entry or subtree belonging to the current agenda entry."
  7844. (interactive)
  7845. (require 'org-archive)
  7846. (org-agenda-archive-with org-archive-default-command))
  7847. (defun org-agenda-archive-default-with-confirmation ()
  7848. "Archive the entry or subtree belonging to the current agenda entry."
  7849. (interactive)
  7850. (require 'org-archive)
  7851. (org-agenda-archive-with org-archive-default-command 'confirm))
  7852. (defun org-agenda-archive ()
  7853. "Archive the entry or subtree belonging to the current agenda entry."
  7854. (interactive)
  7855. (org-agenda-archive-with 'org-archive-subtree))
  7856. (defun org-agenda-archive-to-archive-sibling ()
  7857. "Move the entry to the archive sibling."
  7858. (interactive)
  7859. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7860. (defun org-agenda-archive-with (cmd &optional confirm)
  7861. "Move the entry to the archive sibling."
  7862. (interactive)
  7863. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7864. (let* ((bufname-orig (buffer-name))
  7865. (marker (or (org-get-at-bol 'org-marker)
  7866. (org-agenda-error)))
  7867. (buffer (marker-buffer marker))
  7868. (pos (marker-position marker)))
  7869. (org-with-remote-undo buffer
  7870. (with-current-buffer buffer
  7871. (if (derived-mode-p 'org-mode)
  7872. (if (and confirm
  7873. (not (y-or-n-p "Archive this subtree or entry? ")))
  7874. (error "Abort")
  7875. (save-window-excursion
  7876. (goto-char pos)
  7877. (let ((org-agenda-buffer-name bufname-orig))
  7878. (org-remove-subtree-entries-from-agenda))
  7879. (org-back-to-heading t)
  7880. (funcall cmd)))
  7881. (error "Archiving works only in Org-mode files"))))))
  7882. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7883. "Remove all lines in the agenda that correspond to a given subtree.
  7884. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7885. If this information is not given, the function uses the tree at point."
  7886. (let ((buf (or buf (current-buffer))) m p)
  7887. (save-excursion
  7888. (unless (and beg end)
  7889. (org-back-to-heading t)
  7890. (setq beg (point))
  7891. (org-end-of-subtree t)
  7892. (setq end (point)))
  7893. (set-buffer (get-buffer org-agenda-buffer-name))
  7894. (save-excursion
  7895. (goto-char (point-max))
  7896. (beginning-of-line 1)
  7897. (while (not (bobp))
  7898. (when (and (setq m (org-get-at-bol 'org-marker))
  7899. (equal buf (marker-buffer m))
  7900. (setq p (marker-position m))
  7901. (>= p beg)
  7902. (< p end))
  7903. (let ((inhibit-read-only t))
  7904. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7905. (beginning-of-line 0))))))
  7906. (defun org-agenda-refile (&optional goto rfloc no-update)
  7907. "Refile the item at point.
  7908. When GOTO is 0 or '(64), clear the refile cache.
  7909. When GOTO is '(16), go to the location of the last refiled item.
  7910. RFLOC can be a refile location obtained in a different way.
  7911. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7912. (interactive "P")
  7913. (cond
  7914. ((member goto '(0 (64)))
  7915. (org-refile-cache-clear))
  7916. ((equal goto '(16))
  7917. (org-refile-goto-last-stored))
  7918. (t
  7919. (let* ((buffer-orig (buffer-name))
  7920. (marker (or (org-get-at-bol 'org-hd-marker)
  7921. (org-agenda-error)))
  7922. (buffer (marker-buffer marker))
  7923. (pos (marker-position marker))
  7924. (rfloc (or rfloc
  7925. (org-refile-get-location
  7926. (if goto "Goto" "Refile to") buffer
  7927. org-refile-allow-creating-parent-nodes))))
  7928. (with-current-buffer buffer
  7929. (save-excursion
  7930. (save-restriction
  7931. (widen)
  7932. (goto-char marker)
  7933. (let ((org-agenda-buffer-name buffer-orig))
  7934. (org-remove-subtree-entries-from-agenda))
  7935. (org-refile goto buffer rfloc)))))
  7936. (unless no-update (org-agenda-redo)))))
  7937. (defun org-agenda-open-link (&optional arg)
  7938. "Open the link(s) in the current entry, if any.
  7939. This looks for a link in the displayed line in the agenda.
  7940. It also looks at the text of the entry itself."
  7941. (interactive "P")
  7942. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7943. (org-get-at-bol 'org-marker)))
  7944. (buffer (and marker (marker-buffer marker)))
  7945. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7946. (lkall (and buffer (org-offer-links-in-entry
  7947. buffer marker arg prefix)))
  7948. (lk0 (car lkall))
  7949. (lk (if (stringp lk0) (list lk0) lk0))
  7950. (lkend (cdr lkall))
  7951. trg)
  7952. (cond
  7953. ((and buffer lk)
  7954. (mapcar (lambda(l)
  7955. (with-current-buffer buffer
  7956. (setq trg (and (string-match org-bracket-link-regexp l)
  7957. (match-string 1 l)))
  7958. (if (or (not trg) (string-match org-any-link-re trg))
  7959. (save-excursion
  7960. (save-restriction
  7961. (widen)
  7962. (goto-char marker)
  7963. (when (search-forward l nil lkend)
  7964. (goto-char (match-beginning 0))
  7965. (org-open-at-point))))
  7966. ;; This is an internal link, widen the buffer
  7967. (switch-to-buffer-other-window buffer)
  7968. (widen)
  7969. (goto-char marker)
  7970. (when (search-forward l nil lkend)
  7971. (goto-char (match-beginning 0))
  7972. (org-open-at-point)))))
  7973. lk))
  7974. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7975. (save-excursion
  7976. (beginning-of-line 1)
  7977. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7978. (org-open-link-from-string (match-string 1)))
  7979. (t (message "No link to open here")))))
  7980. (defun org-agenda-copy-local-variable (var)
  7981. "Get a variable from a referenced buffer and install it here."
  7982. (let ((m (org-get-at-bol 'org-marker)))
  7983. (when (and m (buffer-live-p (marker-buffer m)))
  7984. (org-set-local var (with-current-buffer (marker-buffer m)
  7985. (symbol-value var))))))
  7986. (defun org-agenda-switch-to (&optional delete-other-windows)
  7987. "Go to the Org-mode file which contains the item at point."
  7988. (interactive)
  7989. (if (and org-return-follows-link
  7990. (not (org-get-at-bol 'org-marker))
  7991. (org-in-regexp org-bracket-link-regexp))
  7992. (org-open-link-from-string (match-string 0))
  7993. (let* ((marker (or (org-get-at-bol 'org-marker)
  7994. (org-agenda-error)))
  7995. (buffer (marker-buffer marker))
  7996. (pos (marker-position marker)))
  7997. (org-pop-to-buffer-same-window buffer)
  7998. (and delete-other-windows (delete-other-windows))
  7999. (widen)
  8000. (goto-char pos)
  8001. (org-back-to-heading t)
  8002. (when (derived-mode-p 'org-mode)
  8003. (org-show-context 'agenda)
  8004. (save-excursion
  8005. (and (outline-next-heading)
  8006. (org-flag-heading nil))) ; show the next heading
  8007. (when (outline-invisible-p)
  8008. (show-entry)) ; display invisible text
  8009. (run-hooks 'org-agenda-after-show-hook)))))
  8010. (defun org-agenda-goto-mouse (ev)
  8011. "Go to the Org-mode file which contains the item at the mouse click."
  8012. (interactive "e")
  8013. (mouse-set-point ev)
  8014. (org-agenda-goto))
  8015. (defun org-agenda-show (&optional full-entry)
  8016. "Display the Org-mode file which contains the item at point.
  8017. With prefix argument FULL-ENTRY, make the entire entry visible
  8018. if it was hidden in the outline."
  8019. (interactive "P")
  8020. (let ((win (selected-window)))
  8021. (if full-entry
  8022. (let ((org-show-entry-below t))
  8023. (org-agenda-goto t))
  8024. (org-agenda-goto t))
  8025. (select-window win)))
  8026. (defvar org-agenda-show-window nil)
  8027. (defun org-agenda-show-and-scroll-up (&optional arg)
  8028. "Display the Org-mode file which contains the item at point.
  8029. When called repeatedly, scroll the window that is displaying the buffer.
  8030. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  8031. `show-subtree' to display the item, so that drawers and logbooks stay
  8032. folded."
  8033. (interactive "P")
  8034. (let ((win (selected-window)))
  8035. (if (and (window-live-p org-agenda-show-window)
  8036. (eq this-command last-command))
  8037. (progn
  8038. (select-window org-agenda-show-window)
  8039. (ignore-errors (scroll-up)))
  8040. (org-agenda-goto t)
  8041. (if arg (org-show-entry) (show-subtree))
  8042. (setq org-agenda-show-window (selected-window)))
  8043. (select-window win)))
  8044. (defun org-agenda-show-scroll-down ()
  8045. "Scroll down the window showing the agenda."
  8046. (interactive)
  8047. (let ((win (selected-window)))
  8048. (when (window-live-p org-agenda-show-window)
  8049. (select-window org-agenda-show-window)
  8050. (ignore-errors (scroll-down))
  8051. (select-window win))))
  8052. (defun org-agenda-show-1 (&optional more)
  8053. "Display the Org-mode file which contains the item at point.
  8054. The prefix arg selects the amount of information to display:
  8055. 0 hide the subtree
  8056. 1 just show the entry according to defaults.
  8057. 2 show the children view
  8058. 3 show the subtree view
  8059. 4 show the entire subtree and any LOGBOOK drawers
  8060. 5 show the entire subtree and any drawers
  8061. With prefix argument FULL-ENTRY, make the entire entry visible
  8062. if it was hidden in the outline."
  8063. (interactive "p")
  8064. (let ((win (selected-window)))
  8065. (org-agenda-goto t)
  8066. (org-recenter-heading 1)
  8067. (cond
  8068. ((= more 0)
  8069. (hide-subtree)
  8070. (save-excursion
  8071. (org-back-to-heading)
  8072. (run-hook-with-args 'org-cycle-hook 'folded))
  8073. (message "Remote: FOLDED"))
  8074. ((and (org-called-interactively-p 'any) (= more 1))
  8075. (message "Remote: show with default settings"))
  8076. ((= more 2)
  8077. (show-entry)
  8078. (show-children)
  8079. (save-excursion
  8080. (org-back-to-heading)
  8081. (run-hook-with-args 'org-cycle-hook 'children))
  8082. (message "Remote: CHILDREN"))
  8083. ((= more 3)
  8084. (show-subtree)
  8085. (save-excursion
  8086. (org-back-to-heading)
  8087. (run-hook-with-args 'org-cycle-hook 'subtree))
  8088. (message "Remote: SUBTREE"))
  8089. ((= more 4)
  8090. (show-subtree)
  8091. (save-excursion
  8092. (org-back-to-heading)
  8093. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8094. (message "Remote: SUBTREE AND LOGBOOK"))
  8095. ((> more 4)
  8096. (show-subtree)
  8097. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8098. (select-window win)))
  8099. (defun org-recenter-heading (n)
  8100. (save-excursion
  8101. (org-back-to-heading)
  8102. (recenter n)))
  8103. (defvar org-agenda-cycle-counter nil)
  8104. (defun org-agenda-cycle-show (&optional n)
  8105. "Show the current entry in another window, with default settings.
  8106. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8107. When use repeatedly in immediate succession, the remote entry will cycle
  8108. through visibility
  8109. children -> subtree -> folded
  8110. When called with a numeric prefix arg, that arg will be passed through to
  8111. `org-agenda-show-1'. For the interpretation of that argument, see the
  8112. docstring of `org-agenda-show-1'."
  8113. (interactive "P")
  8114. (if (integerp n)
  8115. (setq org-agenda-cycle-counter n)
  8116. (if (not (eq last-command this-command))
  8117. (setq org-agenda-cycle-counter 1)
  8118. (if (equal org-agenda-cycle-counter 0)
  8119. (setq org-agenda-cycle-counter 2)
  8120. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8121. (if (> org-agenda-cycle-counter 3)
  8122. (setq org-agenda-cycle-counter 0)))))
  8123. (org-agenda-show-1 org-agenda-cycle-counter))
  8124. (defun org-agenda-recenter (arg)
  8125. "Display the Org-mode file which contains the item at point and recenter."
  8126. (interactive "P")
  8127. (let ((win (selected-window)))
  8128. (org-agenda-goto t)
  8129. (recenter arg)
  8130. (select-window win)))
  8131. (defun org-agenda-show-mouse (ev)
  8132. "Display the Org-mode file which contains the item at the mouse click."
  8133. (interactive "e")
  8134. (mouse-set-point ev)
  8135. (org-agenda-show))
  8136. (defun org-agenda-check-no-diary ()
  8137. "Check if the entry is a diary link and abort if yes."
  8138. (if (org-get-at-bol 'org-agenda-diary-link)
  8139. (org-agenda-error)))
  8140. (defun org-agenda-error ()
  8141. "Throw an error when a command is not allowed in the agenda."
  8142. (user-error "Command not allowed in this line"))
  8143. (defun org-agenda-tree-to-indirect-buffer (arg)
  8144. "Show the subtree corresponding to the current entry in an indirect buffer.
  8145. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8146. With a numerical prefix ARG, go up to this level and then take that tree.
  8147. With a negative numeric ARG, go up by this number of levels.
  8148. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8149. use the dedicated frame)."
  8150. (interactive "P")
  8151. (if current-prefix-arg
  8152. (org-agenda-do-tree-to-indirect-buffer arg)
  8153. (let ((agenda-buffer (buffer-name))
  8154. (agenda-window (selected-window))
  8155. (indirect-window
  8156. (and org-last-indirect-buffer
  8157. (get-buffer-window org-last-indirect-buffer))))
  8158. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8159. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8160. (eq org-indirect-buffer-display 'dedicated-frame))
  8161. (unwind-protect
  8162. (unless (and indirect-window (window-live-p indirect-window))
  8163. (setq indirect-window (split-window agenda-window)))
  8164. (and indirect-window (select-window indirect-window))
  8165. (switch-to-buffer org-last-indirect-buffer :norecord)
  8166. (fit-window-to-buffer indirect-window)))
  8167. (select-window (get-buffer-window agenda-buffer)))))
  8168. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8169. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8170. (org-agenda-check-no-diary)
  8171. (let* ((marker (or (org-get-at-bol 'org-marker)
  8172. (org-agenda-error)))
  8173. (buffer (marker-buffer marker))
  8174. (pos (marker-position marker)))
  8175. (with-current-buffer buffer
  8176. (save-excursion
  8177. (goto-char pos)
  8178. (funcall 'org-tree-to-indirect-buffer arg)))))
  8179. (defvar org-last-heading-marker (make-marker)
  8180. "Marker pointing to the headline that last changed its TODO state
  8181. by a remote command from the agenda.")
  8182. (defun org-agenda-todo-nextset ()
  8183. "Switch TODO entry to next sequence."
  8184. (interactive)
  8185. (org-agenda-todo 'nextset))
  8186. (defun org-agenda-todo-previousset ()
  8187. "Switch TODO entry to previous sequence."
  8188. (interactive)
  8189. (org-agenda-todo 'previousset))
  8190. (defun org-agenda-todo (&optional arg)
  8191. "Cycle TODO state of line at point, also in Org-mode file.
  8192. This changes the line at point, all other lines in the agenda referring to
  8193. the same tree node, and the headline of the tree node in the Org-mode file."
  8194. (interactive "P")
  8195. (org-agenda-check-no-diary)
  8196. (let* ((col (current-column))
  8197. (marker (or (org-get-at-bol 'org-marker)
  8198. (org-agenda-error)))
  8199. (buffer (marker-buffer marker))
  8200. (pos (marker-position marker))
  8201. (hdmarker (org-get-at-bol 'org-hd-marker))
  8202. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8203. (inhibit-read-only t)
  8204. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8205. (org-with-remote-undo buffer
  8206. (with-current-buffer buffer
  8207. (widen)
  8208. (goto-char pos)
  8209. (org-show-context 'agenda)
  8210. (save-excursion
  8211. (and (outline-next-heading)
  8212. (org-flag-heading nil))) ; show the next heading
  8213. (let ((current-prefix-arg arg))
  8214. (call-interactively 'org-todo))
  8215. (and (bolp) (forward-char 1))
  8216. (setq newhead (org-get-heading))
  8217. (when (and (org-bound-and-true-p
  8218. org-agenda-headline-snapshot-before-repeat)
  8219. (not (equal org-agenda-headline-snapshot-before-repeat
  8220. newhead))
  8221. todayp)
  8222. (setq newhead org-agenda-headline-snapshot-before-repeat
  8223. just-one t))
  8224. (save-excursion
  8225. (org-back-to-heading)
  8226. (move-marker org-last-heading-marker (point))))
  8227. (beginning-of-line 1)
  8228. (save-window-excursion
  8229. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8230. (when (org-bound-and-true-p org-clock-out-when-done)
  8231. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8232. newhead)
  8233. (org-agenda-unmark-clocking-task))
  8234. (org-move-to-column col))))
  8235. (defun org-agenda-add-note (&optional arg)
  8236. "Add a time-stamped note to the entry at point."
  8237. (interactive "P")
  8238. (org-agenda-check-no-diary)
  8239. (let* ((marker (or (org-get-at-bol 'org-marker)
  8240. (org-agenda-error)))
  8241. (buffer (marker-buffer marker))
  8242. (pos (marker-position marker))
  8243. (hdmarker (org-get-at-bol 'org-hd-marker))
  8244. (inhibit-read-only t))
  8245. (with-current-buffer buffer
  8246. (widen)
  8247. (goto-char pos)
  8248. (org-show-context 'agenda)
  8249. (save-excursion
  8250. (and (outline-next-heading)
  8251. (org-flag-heading nil))) ; show the next heading
  8252. (org-add-note))))
  8253. (defun org-agenda-change-all-lines (newhead hdmarker
  8254. &optional fixface just-this)
  8255. "Change all lines in the agenda buffer which match HDMARKER.
  8256. The new content of the line will be NEWHEAD (as modified by
  8257. `org-agenda-format-item'). HDMARKER is checked with
  8258. `equal' against all `org-hd-marker' text properties in the file.
  8259. If FIXFACE is non-nil, the face of each item is modified according to
  8260. the new TODO state.
  8261. If JUST-THIS is non-nil, change just the current line, not all.
  8262. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8263. (let* ((inhibit-read-only t)
  8264. (line (org-current-line))
  8265. (org-agenda-buffer (current-buffer))
  8266. (thetags (with-current-buffer (marker-buffer hdmarker)
  8267. (save-excursion (save-restriction (widen)
  8268. (goto-char hdmarker)
  8269. (org-get-tags-at)))))
  8270. props m pl undone-face done-face finish new dotime level cat tags)
  8271. (save-excursion
  8272. (goto-char (point-max))
  8273. (beginning-of-line 1)
  8274. (while (not finish)
  8275. (setq finish (bobp))
  8276. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8277. (or (not just-this) (= (org-current-line) line))
  8278. (equal m hdmarker))
  8279. (setq props (text-properties-at (point))
  8280. dotime (org-get-at-bol 'dotime)
  8281. cat (org-get-at-bol 'org-category)
  8282. level (org-get-at-bol 'level)
  8283. tags thetags
  8284. new
  8285. (let ((org-prefix-format-compiled
  8286. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8287. org-prefix-format-compiled))
  8288. (extra (org-get-at-bol 'extra)))
  8289. (with-current-buffer (marker-buffer hdmarker)
  8290. (save-excursion
  8291. (save-restriction
  8292. (widen)
  8293. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8294. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8295. undone-face (org-get-at-bol 'undone-face)
  8296. done-face (org-get-at-bol 'done-face))
  8297. (beginning-of-line 1)
  8298. (cond
  8299. ((equal new "")
  8300. (and (looking-at ".*\n?") (replace-match "")))
  8301. ((looking-at ".*")
  8302. (replace-match new t t)
  8303. (beginning-of-line 1)
  8304. (add-text-properties (point-at-bol) (point-at-eol) props)
  8305. (when fixface
  8306. (add-text-properties
  8307. (point-at-bol) (point-at-eol)
  8308. (list 'face
  8309. (if org-last-todo-state-is-todo
  8310. undone-face done-face))))
  8311. (org-agenda-highlight-todo 'line)
  8312. (beginning-of-line 1))
  8313. (t (error "Line update did not work")))
  8314. (save-restriction
  8315. (narrow-to-region (point-at-bol) (point-at-eol))
  8316. (org-agenda-finalize)))
  8317. (beginning-of-line 0)))))
  8318. (defun org-agenda-align-tags (&optional line)
  8319. "Align all tags in agenda items to `org-agenda-tags-column'."
  8320. (let ((inhibit-read-only t) l c)
  8321. (save-excursion
  8322. (goto-char (if line (point-at-bol) (point-min)))
  8323. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8324. (if line (point-at-eol) nil) t)
  8325. (add-text-properties
  8326. (match-beginning 2) (match-end 2)
  8327. (list 'face (delq nil (let ((prop (get-text-property
  8328. (match-beginning 2) 'face)))
  8329. (or (listp prop) (setq prop (list prop)))
  8330. (if (memq 'org-tag prop)
  8331. prop
  8332. (cons 'org-tag prop))))))
  8333. (setq l (- (match-end 2) (match-beginning 2))
  8334. c (if (< org-agenda-tags-column 0)
  8335. (- (abs org-agenda-tags-column) l)
  8336. org-agenda-tags-column))
  8337. (delete-region (match-beginning 1) (match-end 1))
  8338. (goto-char (match-beginning 1))
  8339. (insert (org-add-props
  8340. (make-string (max 1 (- c (current-column))) ?\ )
  8341. (plist-put (copy-sequence (text-properties-at (point)))
  8342. 'face nil))))
  8343. (goto-char (point-min))
  8344. (org-font-lock-add-tag-faces (point-max)))))
  8345. (defun org-agenda-priority-up ()
  8346. "Increase the priority of line at point, also in Org-mode file."
  8347. (interactive)
  8348. (org-agenda-priority 'up))
  8349. (defun org-agenda-priority-down ()
  8350. "Decrease the priority of line at point, also in Org-mode file."
  8351. (interactive)
  8352. (org-agenda-priority 'down))
  8353. (defun org-agenda-priority (&optional force-direction)
  8354. "Set the priority of line at point, also in Org-mode file.
  8355. This changes the line at point, all other lines in the agenda referring to
  8356. the same tree node, and the headline of the tree node in the Org-mode file.
  8357. Called with a universal prefix arg, show the priority instead of setting it."
  8358. (interactive "P")
  8359. (if (equal force-direction '(4))
  8360. (org-show-priority)
  8361. (unless org-enable-priority-commands
  8362. (error "Priority commands are disabled"))
  8363. (org-agenda-check-no-diary)
  8364. (let* ((col (current-column))
  8365. (marker (or (org-get-at-bol 'org-marker)
  8366. (org-agenda-error)))
  8367. (hdmarker (org-get-at-bol 'org-hd-marker))
  8368. (buffer (marker-buffer hdmarker))
  8369. (pos (marker-position hdmarker))
  8370. (inhibit-read-only t)
  8371. newhead)
  8372. (org-with-remote-undo buffer
  8373. (with-current-buffer buffer
  8374. (widen)
  8375. (goto-char pos)
  8376. (org-show-context 'agenda)
  8377. (save-excursion
  8378. (and (outline-next-heading)
  8379. (org-flag-heading nil))) ; show the next heading
  8380. (funcall 'org-priority force-direction)
  8381. (end-of-line 1)
  8382. (setq newhead (org-get-heading)))
  8383. (org-agenda-change-all-lines newhead hdmarker)
  8384. (org-move-to-column col)))))
  8385. ;; FIXME: should fix the tags property of the agenda line.
  8386. (defun org-agenda-set-tags (&optional tag onoff)
  8387. "Set tags for the current headline."
  8388. (interactive)
  8389. (org-agenda-check-no-diary)
  8390. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8391. (call-interactively 'org-change-tag-in-region)
  8392. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8393. (org-agenda-error)))
  8394. (buffer (marker-buffer hdmarker))
  8395. (pos (marker-position hdmarker))
  8396. (inhibit-read-only t)
  8397. newhead)
  8398. (org-with-remote-undo buffer
  8399. (with-current-buffer buffer
  8400. (widen)
  8401. (goto-char pos)
  8402. (save-excursion
  8403. (org-show-context 'agenda))
  8404. (save-excursion
  8405. (and (outline-next-heading)
  8406. (org-flag-heading nil))) ; show the next heading
  8407. (goto-char pos)
  8408. (if tag
  8409. (org-toggle-tag tag onoff)
  8410. (call-interactively 'org-set-tags))
  8411. (end-of-line 1)
  8412. (setq newhead (org-get-heading)))
  8413. (org-agenda-change-all-lines newhead hdmarker)
  8414. (beginning-of-line 1)))))
  8415. (defun org-agenda-set-property ()
  8416. "Set a property for the current headline."
  8417. (interactive)
  8418. (org-agenda-check-no-diary)
  8419. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8420. (org-agenda-error)))
  8421. (buffer (marker-buffer hdmarker))
  8422. (pos (marker-position hdmarker))
  8423. (inhibit-read-only t)
  8424. newhead)
  8425. (org-with-remote-undo buffer
  8426. (with-current-buffer buffer
  8427. (widen)
  8428. (goto-char pos)
  8429. (save-excursion
  8430. (org-show-context 'agenda))
  8431. (save-excursion
  8432. (and (outline-next-heading)
  8433. (org-flag-heading nil))) ; show the next heading
  8434. (goto-char pos)
  8435. (call-interactively 'org-set-property)))))
  8436. (defun org-agenda-set-effort ()
  8437. "Set the effort property for the current headline."
  8438. (interactive)
  8439. (org-agenda-check-no-diary)
  8440. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8441. (org-agenda-error)))
  8442. (buffer (marker-buffer hdmarker))
  8443. (pos (marker-position hdmarker))
  8444. (inhibit-read-only t)
  8445. newhead)
  8446. (org-with-remote-undo buffer
  8447. (with-current-buffer buffer
  8448. (widen)
  8449. (goto-char pos)
  8450. (save-excursion
  8451. (org-show-context 'agenda))
  8452. (save-excursion
  8453. (and (outline-next-heading)
  8454. (org-flag-heading nil))) ; show the next heading
  8455. (goto-char pos)
  8456. (call-interactively 'org-set-effort)
  8457. (end-of-line 1)
  8458. (setq newhead (org-get-heading)))
  8459. (org-agenda-change-all-lines newhead hdmarker))))
  8460. (defun org-agenda-toggle-archive-tag ()
  8461. "Toggle the archive tag for the current entry."
  8462. (interactive)
  8463. (org-agenda-check-no-diary)
  8464. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8465. (org-agenda-error)))
  8466. (buffer (marker-buffer hdmarker))
  8467. (pos (marker-position hdmarker))
  8468. (inhibit-read-only t)
  8469. newhead)
  8470. (org-with-remote-undo buffer
  8471. (with-current-buffer buffer
  8472. (widen)
  8473. (goto-char pos)
  8474. (org-show-context 'agenda)
  8475. (save-excursion
  8476. (and (outline-next-heading)
  8477. (org-flag-heading nil))) ; show the next heading
  8478. (call-interactively 'org-toggle-archive-tag)
  8479. (end-of-line 1)
  8480. (setq newhead (org-get-heading)))
  8481. (org-agenda-change-all-lines newhead hdmarker)
  8482. (beginning-of-line 1))))
  8483. (defun org-agenda-do-date-later (arg)
  8484. (interactive "P")
  8485. (cond
  8486. ((or (equal arg '(16))
  8487. (memq last-command
  8488. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8489. (setq this-command 'org-agenda-date-later-minutes)
  8490. (org-agenda-date-later-minutes 1))
  8491. ((or (equal arg '(4))
  8492. (memq last-command
  8493. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8494. (setq this-command 'org-agenda-date-later-hours)
  8495. (org-agenda-date-later-hours 1))
  8496. (t
  8497. (org-agenda-date-later (prefix-numeric-value arg)))))
  8498. (defun org-agenda-do-date-earlier (arg)
  8499. (interactive "P")
  8500. (cond
  8501. ((or (equal arg '(16))
  8502. (memq last-command
  8503. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8504. (setq this-command 'org-agenda-date-earlier-minutes)
  8505. (org-agenda-date-earlier-minutes 1))
  8506. ((or (equal arg '(4))
  8507. (memq last-command
  8508. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8509. (setq this-command 'org-agenda-date-earlier-hours)
  8510. (org-agenda-date-earlier-hours 1))
  8511. (t
  8512. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8513. (defun org-agenda-date-later (arg &optional what)
  8514. "Change the date of this item to ARG day(s) later."
  8515. (interactive "p")
  8516. (org-agenda-check-type t 'agenda 'timeline)
  8517. (org-agenda-check-no-diary)
  8518. (let* ((marker (or (org-get-at-bol 'org-marker)
  8519. (org-agenda-error)))
  8520. (buffer (marker-buffer marker))
  8521. (pos (marker-position marker))
  8522. cdate today)
  8523. (org-with-remote-undo buffer
  8524. (with-current-buffer buffer
  8525. (widen)
  8526. (goto-char pos)
  8527. (if (not (org-at-timestamp-p))
  8528. (error "Cannot find time stamp"))
  8529. (when (and org-agenda-move-date-from-past-immediately-to-today
  8530. (equal arg 1)
  8531. (or (not what) (eq what 'day))
  8532. (not (save-match-data (org-at-date-range-p))))
  8533. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8534. cdate (calendar-absolute-from-gregorian
  8535. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8536. today (org-today))
  8537. (if (> today cdate)
  8538. ;; immediately shift to today
  8539. (setq arg (- today cdate))))
  8540. (org-timestamp-change arg (or what 'day))
  8541. (when (and (org-at-date-range-p)
  8542. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8543. (let ((end org-last-changed-timestamp))
  8544. (org-timestamp-change arg (or what 'day))
  8545. (setq org-last-changed-timestamp
  8546. (concat org-last-changed-timestamp "--" end)))))
  8547. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8548. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8549. (defun org-agenda-date-earlier (arg &optional what)
  8550. "Change the date of this item to ARG day(s) earlier."
  8551. (interactive "p")
  8552. (org-agenda-date-later (- arg) what))
  8553. (defun org-agenda-date-later-minutes (arg)
  8554. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8555. (interactive "p")
  8556. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8557. (org-agenda-date-later arg 'minute))
  8558. (defun org-agenda-date-earlier-minutes (arg)
  8559. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8560. (interactive "p")
  8561. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8562. (org-agenda-date-earlier arg 'minute))
  8563. (defun org-agenda-date-later-hours (arg)
  8564. "Change the time of this item, in hour steps."
  8565. (interactive "p")
  8566. (org-agenda-date-later arg 'hour))
  8567. (defun org-agenda-date-earlier-hours (arg)
  8568. "Change the time of this item, in hour steps."
  8569. (interactive "p")
  8570. (org-agenda-date-earlier arg 'hour))
  8571. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8572. "Show new date stamp via text properties."
  8573. ;; We use text properties to make this undoable
  8574. (let ((inhibit-read-only t))
  8575. (setq stamp (concat prefix " => " stamp " "))
  8576. (save-excursion
  8577. (goto-char (point-max))
  8578. (while (not (bobp))
  8579. (when (equal marker (org-get-at-bol 'org-marker))
  8580. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8581. (org-move-to-column (- (window-width) (length stamp)) t)
  8582. (org-agenda-fix-tags-filter-overlays-at (point))
  8583. (if (featurep 'xemacs)
  8584. ;; Use `duplicable' property to trigger undo recording
  8585. (let ((ex (make-extent nil nil))
  8586. (gl (make-glyph stamp)))
  8587. (set-glyph-face gl 'secondary-selection)
  8588. (set-extent-properties
  8589. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8590. (insert-extent ex (1- (point)) (point-at-eol)))
  8591. (add-text-properties
  8592. (1- (point)) (point-at-eol)
  8593. (list 'display (org-add-props stamp nil
  8594. 'face 'secondary-selection))))
  8595. (beginning-of-line 1))
  8596. (beginning-of-line 0)))))
  8597. (defun org-agenda-date-prompt (arg)
  8598. "Change the date of this item. Date is prompted for, with default today.
  8599. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8600. be used to request time specification in the time stamp."
  8601. (interactive "P")
  8602. (org-agenda-check-type t 'agenda 'timeline)
  8603. (org-agenda-check-no-diary)
  8604. (let* ((marker (or (org-get-at-bol 'org-marker)
  8605. (org-agenda-error)))
  8606. (buffer (marker-buffer marker))
  8607. (pos (marker-position marker)))
  8608. (org-with-remote-undo buffer
  8609. (with-current-buffer buffer
  8610. (widen)
  8611. (goto-char pos)
  8612. (if (not (org-at-timestamp-p t))
  8613. (error "Cannot find time stamp"))
  8614. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8615. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8616. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8617. (defun org-agenda-schedule (arg &optional time)
  8618. "Schedule the item at point.
  8619. ARG is passed through to `org-schedule'."
  8620. (interactive "P")
  8621. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8622. (org-agenda-check-no-diary)
  8623. (let* ((marker (or (org-get-at-bol 'org-marker)
  8624. (org-agenda-error)))
  8625. (type (marker-insertion-type marker))
  8626. (buffer (marker-buffer marker))
  8627. (pos (marker-position marker))
  8628. (org-insert-labeled-timestamps-at-point nil)
  8629. ts)
  8630. (set-marker-insertion-type marker t)
  8631. (org-with-remote-undo buffer
  8632. (with-current-buffer buffer
  8633. (widen)
  8634. (goto-char pos)
  8635. (setq ts (org-schedule arg time)))
  8636. (org-agenda-show-new-time marker ts " S"))
  8637. (message "%s" ts)))
  8638. (defun org-agenda-deadline (arg &optional time)
  8639. "Schedule the item at point.
  8640. ARG is passed through to `org-deadline'."
  8641. (interactive "P")
  8642. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8643. (org-agenda-check-no-diary)
  8644. (let* ((marker (or (org-get-at-bol 'org-marker)
  8645. (org-agenda-error)))
  8646. (buffer (marker-buffer marker))
  8647. (pos (marker-position marker))
  8648. (org-insert-labeled-timestamps-at-point nil)
  8649. ts)
  8650. (org-with-remote-undo buffer
  8651. (with-current-buffer buffer
  8652. (widen)
  8653. (goto-char pos)
  8654. (setq ts (org-deadline arg time)))
  8655. (org-agenda-show-new-time marker ts " D"))
  8656. (message "%s" ts)))
  8657. (defun org-agenda-clock-in (&optional arg)
  8658. "Start the clock on the currently selected item."
  8659. (interactive "P")
  8660. (org-agenda-check-no-diary)
  8661. (if (equal arg '(4))
  8662. (org-clock-in arg)
  8663. (let* ((marker (or (org-get-at-bol 'org-marker)
  8664. (org-agenda-error)))
  8665. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8666. (pos (marker-position marker))
  8667. (col (current-column))
  8668. newhead)
  8669. (org-with-remote-undo (marker-buffer marker)
  8670. (with-current-buffer (marker-buffer marker)
  8671. (widen)
  8672. (goto-char pos)
  8673. (org-show-context 'agenda)
  8674. (org-show-entry)
  8675. (org-cycle-hide-drawers 'children)
  8676. (org-clock-in arg)
  8677. (setq newhead (org-get-heading)))
  8678. (org-agenda-change-all-lines newhead hdmarker))
  8679. (org-move-to-column col))))
  8680. (defun org-agenda-clock-out ()
  8681. "Stop the currently running clock."
  8682. (interactive)
  8683. (unless (marker-buffer org-clock-marker)
  8684. (error "No running clock"))
  8685. (let ((marker (make-marker)) (col (current-column)) newhead)
  8686. (org-with-remote-undo (marker-buffer org-clock-marker)
  8687. (with-current-buffer (marker-buffer org-clock-marker)
  8688. (save-excursion
  8689. (save-restriction
  8690. (widen)
  8691. (goto-char org-clock-marker)
  8692. (org-back-to-heading t)
  8693. (move-marker marker (point))
  8694. (org-clock-out)
  8695. (setq newhead (org-get-heading))))))
  8696. (org-agenda-change-all-lines newhead marker)
  8697. (move-marker marker nil)
  8698. (org-move-to-column col)
  8699. (org-agenda-unmark-clocking-task)))
  8700. (defun org-agenda-clock-cancel (&optional arg)
  8701. "Cancel the currently running clock."
  8702. (interactive "P")
  8703. (unless (marker-buffer org-clock-marker)
  8704. (user-error "No running clock"))
  8705. (org-with-remote-undo (marker-buffer org-clock-marker)
  8706. (org-clock-cancel)))
  8707. (defun org-agenda-clock-goto ()
  8708. "Jump to the currently clocked in task within the agenda.
  8709. If the currently clocked in task is not listed in the agenda
  8710. buffer, display it in another window."
  8711. (interactive)
  8712. (let (pos)
  8713. (mapc (lambda (o)
  8714. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8715. (setq pos (overlay-start o))))
  8716. (overlays-in (point-min) (point-max)))
  8717. (cond (pos (goto-char pos))
  8718. ;; If the currently clocked entry is not in the agenda
  8719. ;; buffer, we visit it in another window:
  8720. (org-clock-current-task
  8721. (org-switch-to-buffer-other-window (org-clock-goto)))
  8722. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8723. (defun org-agenda-diary-entry-in-org-file ()
  8724. "Make a diary entry in the file `org-agenda-diary-file'."
  8725. (let (d1 d2 char (text "") dp1 dp2)
  8726. (if (equal (buffer-name) "*Calendar*")
  8727. (setq d1 (calendar-cursor-to-date t)
  8728. d2 (car calendar-mark-ring))
  8729. (setq dp1 (get-text-property (point-at-bol) 'day))
  8730. (unless dp1 (user-error "No date defined in current line"))
  8731. (setq d1 (calendar-gregorian-from-absolute dp1)
  8732. d2 (and (ignore-errors (mark))
  8733. (save-excursion
  8734. (goto-char (mark))
  8735. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8736. (calendar-gregorian-from-absolute dp2))))
  8737. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8738. (setq char (read-char-exclusive))
  8739. (cond
  8740. ((equal char ?d)
  8741. (setq text (read-string "Day entry: "))
  8742. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8743. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8744. ((equal char ?a)
  8745. (setq d1 (list (car d1) (nth 1 d1)
  8746. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8747. (nth 2 d1))))
  8748. (setq text (read-string "Anniversary (use %d to show years): "))
  8749. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8750. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8751. ((equal char ?b)
  8752. (setq text (read-string "Block entry: "))
  8753. (unless (and d1 d2 (not (equal d1 d2)))
  8754. (user-error "No block of days selected"))
  8755. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8756. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8757. ((equal char ?j)
  8758. (org-switch-to-buffer-other-window
  8759. (find-file-noselect org-agenda-diary-file))
  8760. (require 'org-datetree)
  8761. (org-datetree-find-date-create d1)
  8762. (org-reveal t))
  8763. (t (user-error "Invalid selection character `%c'" char)))))
  8764. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8765. "Where in `org-agenda-diary-file' should new entries be added?
  8766. Valid values:
  8767. date-tree in the date tree, as child of the date
  8768. top-level as top-level entries at the end of the file."
  8769. :group 'org-agenda
  8770. :type '(choice
  8771. (const :tag "in a date tree" date-tree)
  8772. (const :tag "as top level at end of file" top-level)))
  8773. (defcustom org-agenda-insert-diary-extract-time nil
  8774. "Non-nil means extract any time specification from the diary entry."
  8775. :group 'org-agenda
  8776. :version "24.1"
  8777. :type 'boolean)
  8778. (defcustom org-agenda-bulk-mark-char ">"
  8779. "A single-character string to be used as the bulk mark."
  8780. :group 'org-agenda
  8781. :version "24.1"
  8782. :type 'string)
  8783. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8784. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8785. If TEXT is not empty, it will become the headline of the new entry, and
  8786. the resulting entry will not be shown. When TEXT is empty, switch to
  8787. `org-agenda-diary-file' and let the user finish the entry there."
  8788. (let ((cw (current-window-configuration)))
  8789. (org-switch-to-buffer-other-window
  8790. (find-file-noselect org-agenda-diary-file))
  8791. (widen)
  8792. (goto-char (point-min))
  8793. (cond
  8794. ((eq type 'anniversary)
  8795. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8796. (progn
  8797. (or (org-at-heading-p t)
  8798. (progn
  8799. (outline-next-heading)
  8800. (insert "* Anniversaries\n\n")
  8801. (beginning-of-line -1)))))
  8802. (outline-next-heading)
  8803. (org-back-over-empty-lines)
  8804. (backward-char 1)
  8805. (insert "\n")
  8806. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8807. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8808. ((eq type 'day)
  8809. (let ((org-prefix-has-time t)
  8810. (org-agenda-time-leading-zero t)
  8811. fmt time time2)
  8812. (if org-agenda-insert-diary-extract-time
  8813. ;; Use org-agenda-format-item to parse text for a time-range and
  8814. ;; remove it. FIXME: This is a hack, we should refactor
  8815. ;; that function to make time extraction available separately
  8816. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8817. time (get-text-property 0 'time fmt)
  8818. time2 (if (> (length time) 0)
  8819. ;; split-string removes trailing ...... if
  8820. ;; no end time given. First space
  8821. ;; separates time from date.
  8822. (concat " " (car (split-string time "\\.")))
  8823. nil)
  8824. text (get-text-property 0 'txt fmt)))
  8825. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8826. (org-agenda-insert-diary-as-top-level text)
  8827. (require 'org-datetree)
  8828. (org-datetree-find-date-create d1)
  8829. (org-agenda-insert-diary-make-new-entry text))
  8830. (org-insert-time-stamp (org-time-from-absolute
  8831. (calendar-absolute-from-gregorian d1))
  8832. nil nil nil nil time2))
  8833. (end-of-line 0))
  8834. ((eq type 'block)
  8835. (if (> (calendar-absolute-from-gregorian d1)
  8836. (calendar-absolute-from-gregorian d2))
  8837. (setq d1 (prog1 d2 (setq d2 d1))))
  8838. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8839. (org-agenda-insert-diary-as-top-level text)
  8840. (require 'org-datetree)
  8841. (org-datetree-find-date-create d1)
  8842. (org-agenda-insert-diary-make-new-entry text))
  8843. (org-insert-time-stamp (org-time-from-absolute
  8844. (calendar-absolute-from-gregorian d1)))
  8845. (insert "--")
  8846. (org-insert-time-stamp (org-time-from-absolute
  8847. (calendar-absolute-from-gregorian d2)))
  8848. (end-of-line 0)))
  8849. (if (string-match "\\S-" text)
  8850. (progn
  8851. (set-window-configuration cw)
  8852. (message "%s entry added to %s"
  8853. (capitalize (symbol-name type))
  8854. (abbreviate-file-name org-agenda-diary-file)))
  8855. (org-reveal t)
  8856. (message "Please finish entry here"))))
  8857. (defun org-agenda-insert-diary-as-top-level (text)
  8858. "Make new entry as a top-level entry at the end of the file.
  8859. Add TEXT as headline, and position the cursor in the second line so that
  8860. a timestamp can be added there."
  8861. (widen)
  8862. (goto-char (point-max))
  8863. (or (bolp) (insert "\n"))
  8864. (insert "* " text "\n")
  8865. (if org-adapt-indentation (org-indent-to-column 2)))
  8866. (defun org-agenda-insert-diary-make-new-entry (text)
  8867. "Make new entry as last child of current entry.
  8868. Add TEXT as headline, and position the cursor in the second line so that
  8869. a timestamp can be added there."
  8870. (let ((org-show-following-heading t)
  8871. (org-show-siblings t)
  8872. (org-show-hierarchy-above t)
  8873. (org-show-entry-below t)
  8874. col)
  8875. (outline-next-heading)
  8876. (org-back-over-empty-lines)
  8877. (or (looking-at "[ \t]*$")
  8878. (progn (insert "\n") (backward-char 1)))
  8879. (org-insert-heading nil t)
  8880. (org-do-demote)
  8881. (setq col (current-column))
  8882. (insert text "\n")
  8883. (if org-adapt-indentation (org-indent-to-column col))
  8884. (let ((org-show-following-heading t)
  8885. (org-show-siblings t)
  8886. (org-show-hierarchy-above t)
  8887. (org-show-entry-below t))
  8888. (org-show-context))))
  8889. (defun org-agenda-diary-entry ()
  8890. "Make a diary entry, like the `i' command from the calendar.
  8891. All the standard commands work: block, weekly etc.
  8892. When `org-agenda-diary-file' points to a file,
  8893. `org-agenda-diary-entry-in-org-file' is called instead to create
  8894. entries in that Org-mode file."
  8895. (interactive)
  8896. (if (not (eq org-agenda-diary-file 'diary-file))
  8897. (org-agenda-diary-entry-in-org-file)
  8898. (require 'diary-lib)
  8899. (let* ((char (progn
  8900. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8901. (read-char-exclusive)))
  8902. (cmd (cdr (assoc char
  8903. '((?d . insert-diary-entry)
  8904. (?w . insert-weekly-diary-entry)
  8905. (?m . insert-monthly-diary-entry)
  8906. (?y . insert-yearly-diary-entry)
  8907. (?a . insert-anniversary-diary-entry)
  8908. (?b . insert-block-diary-entry)
  8909. (?c . insert-cyclic-diary-entry)))))
  8910. (oldf (symbol-function 'calendar-cursor-to-date))
  8911. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8912. (point (point))
  8913. (mark (or (mark t) (point))))
  8914. (unless cmd
  8915. (user-error "No command associated with <%c>" char))
  8916. (unless (and (get-text-property point 'day)
  8917. (or (not (equal ?b char))
  8918. (get-text-property mark 'day)))
  8919. (user-error "Don't know which date to use for diary entry"))
  8920. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8921. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8922. (let ((calendar-mark-ring
  8923. (list (calendar-gregorian-from-absolute
  8924. (or (get-text-property mark 'day)
  8925. (get-text-property point 'day))))))
  8926. (unwind-protect
  8927. (progn
  8928. (fset 'calendar-cursor-to-date
  8929. (lambda (&optional error dummy)
  8930. (calendar-gregorian-from-absolute
  8931. (get-text-property point 'day))))
  8932. (call-interactively cmd))
  8933. (fset 'calendar-cursor-to-date oldf))))))
  8934. (defun org-agenda-execute-calendar-command (cmd)
  8935. "Execute a calendar command from the agenda with date from cursor."
  8936. (org-agenda-check-type t 'agenda 'timeline)
  8937. (require 'diary-lib)
  8938. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8939. (user-error "Don't know which date to use for the calendar command"))
  8940. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8941. (point (point))
  8942. (date (calendar-gregorian-from-absolute
  8943. (get-text-property point 'day)))
  8944. ;; the following 2 vars are needed in the calendar
  8945. (displayed-month (car date))
  8946. (displayed-year (nth 2 date)))
  8947. (unwind-protect
  8948. (progn
  8949. (fset 'calendar-cursor-to-date
  8950. (lambda (&optional error dummy)
  8951. (calendar-gregorian-from-absolute
  8952. (get-text-property point 'day))))
  8953. (call-interactively cmd))
  8954. (fset 'calendar-cursor-to-date oldf))))
  8955. (defun org-agenda-phases-of-moon ()
  8956. "Display the phases of the moon for the 3 months around the cursor date."
  8957. (interactive)
  8958. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8959. (defun org-agenda-holidays ()
  8960. "Display the holidays for the 3 months around the cursor date."
  8961. (interactive)
  8962. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8963. (defvar calendar-longitude) ; defined in calendar.el
  8964. (defvar calendar-latitude) ; defined in calendar.el
  8965. (defvar calendar-location-name) ; defined in calendar.el
  8966. (defun org-agenda-sunrise-sunset (arg)
  8967. "Display sunrise and sunset for the cursor date.
  8968. Latitude and longitude can be specified with the variables
  8969. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8970. argument, latitude and longitude will be prompted for."
  8971. (interactive "P")
  8972. (require 'solar)
  8973. (let ((calendar-longitude (if arg nil calendar-longitude))
  8974. (calendar-latitude (if arg nil calendar-latitude))
  8975. (calendar-location-name
  8976. (if arg "the given coordinates" calendar-location-name)))
  8977. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8978. (defun org-agenda-goto-calendar ()
  8979. "Open the Emacs calendar with the date at the cursor."
  8980. (interactive)
  8981. (org-agenda-check-type t 'agenda 'timeline)
  8982. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8983. (user-error "Don't know which date to open in calendar")))
  8984. (date (calendar-gregorian-from-absolute day))
  8985. (calendar-move-hook nil)
  8986. (calendar-view-holidays-initially-flag nil)
  8987. (calendar-view-diary-initially-flag nil))
  8988. (calendar)
  8989. (calendar-goto-date date)))
  8990. ;;;###autoload
  8991. (defun org-calendar-goto-agenda ()
  8992. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8993. This is a command that has to be installed in `calendar-mode-map'."
  8994. (interactive)
  8995. (org-agenda-list nil (calendar-absolute-from-gregorian
  8996. (calendar-cursor-to-date))
  8997. nil))
  8998. (defun org-agenda-convert-date ()
  8999. (interactive)
  9000. (org-agenda-check-type t 'agenda 'timeline)
  9001. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9002. date s)
  9003. (unless day
  9004. (user-error "Don't know which date to convert"))
  9005. (setq date (calendar-gregorian-from-absolute day))
  9006. (setq s (concat
  9007. "Gregorian: " (calendar-date-string date) "\n"
  9008. "ISO: " (calendar-iso-date-string date) "\n"
  9009. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9010. "Julian: " (calendar-julian-date-string date) "\n"
  9011. "Astron. JD: " (calendar-astro-date-string date)
  9012. " (Julian date number at noon UTC)\n"
  9013. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9014. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9015. "French: " (calendar-french-date-string date) "\n"
  9016. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  9017. "Mayan: " (calendar-mayan-date-string date) "\n"
  9018. "Coptic: " (calendar-coptic-date-string date) "\n"
  9019. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9020. "Persian: " (calendar-persian-date-string date) "\n"
  9021. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9022. (with-output-to-temp-buffer "*Dates*"
  9023. (princ s))
  9024. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9025. ;;; Bulk commands
  9026. (defun org-agenda-bulk-marked-p ()
  9027. (eq (get-char-property (point-at-bol) 'type)
  9028. 'org-marked-entry-overlay))
  9029. (defun org-agenda-bulk-mark (&optional arg)
  9030. "Mark the entry at point for future bulk action."
  9031. (interactive "p")
  9032. (dotimes (i (or arg 1))
  9033. (unless (org-get-at-bol 'org-agenda-diary-link)
  9034. (let* ((m (org-get-at-bol 'org-hd-marker))
  9035. ov)
  9036. (unless (org-agenda-bulk-marked-p)
  9037. (unless m (user-error "Nothing to mark at point"))
  9038. (push m org-agenda-bulk-marked-entries)
  9039. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9040. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9041. (org-get-todo-face "TODO")
  9042. 'evaporate)
  9043. (overlay-put ov 'type 'org-marked-entry-overlay))
  9044. (end-of-line 1)
  9045. (or (ignore-errors
  9046. (goto-char (next-single-property-change (point) 'txt)))
  9047. (beginning-of-line 2))
  9048. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9049. (beginning-of-line 2))
  9050. (message "%d entries marked for bulk action"
  9051. (length org-agenda-bulk-marked-entries))))))
  9052. (defun org-agenda-bulk-mark-all ()
  9053. "Mark all entries for future agenda bulk action."
  9054. (interactive)
  9055. (org-agenda-bulk-mark-regexp "."))
  9056. (defun org-agenda-bulk-mark-regexp (regexp)
  9057. "Mark entries matching REGEXP for future agenda bulk action."
  9058. (interactive "sMark entries matching regexp: ")
  9059. (let ((entries-marked 0) txt-at-point)
  9060. (save-excursion
  9061. (goto-char (point-min))
  9062. (goto-char (next-single-property-change (point) 'txt))
  9063. (while (and (re-search-forward regexp nil t)
  9064. (setq txt-at-point (get-text-property (point) 'txt)))
  9065. (when (string-match regexp txt-at-point)
  9066. (setq entries-marked (1+ entries-marked))
  9067. (call-interactively 'org-agenda-bulk-mark))))
  9068. (if (not entries-marked)
  9069. (message "No entry matching this regexp."))))
  9070. (defun org-agenda-bulk-unmark (&optional arg)
  9071. "Unmark the entry at point for future bulk action."
  9072. (interactive "P")
  9073. (if arg
  9074. (org-agenda-bulk-unmark-all)
  9075. (cond ((org-agenda-bulk-marked-p)
  9076. (org-agenda-bulk-remove-overlays
  9077. (point-at-bol) (+ 2 (point-at-bol)))
  9078. (setq org-agenda-bulk-marked-entries
  9079. (delete (org-get-at-bol 'org-hd-marker)
  9080. org-agenda-bulk-marked-entries))
  9081. (end-of-line 1)
  9082. (or (ignore-errors
  9083. (goto-char (next-single-property-change (point) 'txt)))
  9084. (beginning-of-line 2))
  9085. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9086. (beginning-of-line 2))
  9087. (message "%d entries left marked for bulk action"
  9088. (length org-agenda-bulk-marked-entries)))
  9089. (t (message "No entry to unmark here")))))
  9090. (defun org-agenda-bulk-toggle-all ()
  9091. "Toggle all marks for bulk action."
  9092. (interactive)
  9093. (save-excursion
  9094. (goto-char (point-min))
  9095. (while (ignore-errors
  9096. (goto-char (next-single-property-change (point) 'txt)))
  9097. (org-agenda-bulk-toggle))))
  9098. (defun org-agenda-bulk-toggle ()
  9099. "Toggle the mark at point for bulk action."
  9100. (interactive)
  9101. (if (org-agenda-bulk-marked-p)
  9102. (org-agenda-bulk-unmark)
  9103. (org-agenda-bulk-mark)))
  9104. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9105. "Remove the mark overlays between BEG and END in the agenda buffer.
  9106. BEG and END default to the buffer limits.
  9107. This only removes the overlays, it does not remove the markers
  9108. from the list in `org-agenda-bulk-marked-entries'."
  9109. (interactive)
  9110. (mapc (lambda (ov)
  9111. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9112. (delete-overlay ov)))
  9113. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9114. (defun org-agenda-bulk-unmark-all ()
  9115. "Remove all marks in the agenda buffer.
  9116. This will remove the markers and the overlays."
  9117. (interactive)
  9118. (if (null org-agenda-bulk-marked-entries)
  9119. (message "No entry to unmark")
  9120. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9121. (setq org-agenda-bulk-marked-entries nil)
  9122. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9123. (defcustom org-agenda-persistent-marks nil
  9124. "Non-nil means marked items will stay marked after a bulk action.
  9125. You can toggle this interactively by typing `p' when prompted for a
  9126. bulk action."
  9127. :group 'org-agenda
  9128. :version "24.1"
  9129. :type 'boolean)
  9130. (defun org-agenda-bulk-action (&optional arg)
  9131. "Execute an remote-editing action on all marked entries.
  9132. The prefix arg is passed through to the command if possible."
  9133. (interactive "P")
  9134. ;; Make sure we have markers, and only valid ones
  9135. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9136. (mapc
  9137. (lambda (m)
  9138. (unless (and (markerp m)
  9139. (marker-buffer m)
  9140. (buffer-live-p (marker-buffer m))
  9141. (marker-position m))
  9142. (user-error "Marker %s for bulk command is invalid" m)))
  9143. org-agenda-bulk-marked-entries)
  9144. ;; Prompt for the bulk command
  9145. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9146. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9147. "[S]catter [f]unction "
  9148. (when org-agenda-bulk-custom-functions
  9149. (concat " Custom: ["
  9150. (mapconcat (lambda(f) (char-to-string (car f)))
  9151. org-agenda-bulk-custom-functions "")
  9152. "]"))))
  9153. (catch 'exit
  9154. (let* ((action (read-char-exclusive))
  9155. (org-log-refile (if org-log-refile 'time nil))
  9156. (entries (reverse org-agenda-bulk-marked-entries))
  9157. (org-overriding-default-time
  9158. (if (get-text-property (point) 'org-agenda-date-header)
  9159. (org-get-cursor-date)))
  9160. redo-at-end
  9161. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9162. (cond
  9163. ((equal action ?p)
  9164. (let ((org-agenda-persistent-marks
  9165. (not org-agenda-persistent-marks)))
  9166. (org-agenda-bulk-action)
  9167. (throw 'exit nil)))
  9168. ((equal action ?$)
  9169. (setq cmd '(org-agenda-archive)))
  9170. ((equal action ?A)
  9171. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9172. ((member action '(?r ?w))
  9173. (setq rfloc (org-refile-get-location
  9174. "Refile to"
  9175. (marker-buffer (car entries))
  9176. org-refile-allow-creating-parent-nodes))
  9177. (if (nth 3 rfloc)
  9178. (setcar (nthcdr 3 rfloc)
  9179. (move-marker (make-marker) (nth 3 rfloc)
  9180. (or (get-file-buffer (nth 1 rfloc))
  9181. (find-buffer-visiting (nth 1 rfloc))
  9182. (error "This should not happen")))))
  9183. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9184. redo-at-end t))
  9185. ((equal action ?t)
  9186. (setq state (org-icompleting-read
  9187. "Todo state: "
  9188. (with-current-buffer (marker-buffer (car entries))
  9189. (mapcar 'list org-todo-keywords-1))))
  9190. (setq cmd `(let ((org-inhibit-blocking t)
  9191. (org-inhibit-logging 'note))
  9192. (org-agenda-todo ,state))))
  9193. ((memq action '(?- ?+))
  9194. (setq tag (org-icompleting-read
  9195. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9196. (with-current-buffer (marker-buffer (car entries))
  9197. (delq nil
  9198. (mapcar (lambda (x)
  9199. (if (stringp (car x)) x)) org-tag-alist)))))
  9200. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9201. ((memq action '(?s ?d))
  9202. (let* ((time
  9203. (unless arg
  9204. (org-read-date
  9205. nil nil nil
  9206. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9207. org-overriding-default-time)))
  9208. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9209. (setq cmd `(eval '(,c1 arg ,time)))))
  9210. ((equal action ?S)
  9211. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9212. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9213. (let ((days (read-number
  9214. (format "Scatter tasks across how many %sdays: "
  9215. (if arg "week" "")) 7)))
  9216. (setq cmd
  9217. `(let ((distance (1+ (random ,days))))
  9218. (if arg
  9219. (let ((dist distance)
  9220. (day-of-week
  9221. (calendar-day-of-week
  9222. (calendar-gregorian-from-absolute (org-today)))))
  9223. (dotimes (i (1+ dist))
  9224. (while (member day-of-week org-agenda-weekend-days)
  9225. (incf distance)
  9226. (incf day-of-week)
  9227. (if (= day-of-week 7)
  9228. (setq day-of-week 0)))
  9229. (incf day-of-week)
  9230. (if (= day-of-week 7)
  9231. (setq day-of-week 0)))))
  9232. ;; silently fail when try to replan a sexp entry
  9233. (condition-case nil
  9234. (let* ((date (calendar-gregorian-from-absolute
  9235. (+ (org-today) distance)))
  9236. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9237. (nth 2 date))))
  9238. (org-agenda-schedule nil time))
  9239. (error nil)))))))
  9240. ((assoc action org-agenda-bulk-custom-functions)
  9241. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9242. redo-at-end t))
  9243. ((equal action ?f)
  9244. (setq cmd (list (intern
  9245. (org-icompleting-read "Function: "
  9246. obarray 'fboundp t nil nil)))))
  9247. (t (user-error "Invalid bulk action")))
  9248. ;; Sort the markers, to make sure that parents are handled before children
  9249. (setq entries (sort entries
  9250. (lambda (a b)
  9251. (cond
  9252. ((equal (marker-buffer a) (marker-buffer b))
  9253. (< (marker-position a) (marker-position b)))
  9254. (t
  9255. (string< (buffer-name (marker-buffer a))
  9256. (buffer-name (marker-buffer b))))))))
  9257. ;; Now loop over all markers and apply cmd
  9258. (while (setq e (pop entries))
  9259. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9260. (if (not pos)
  9261. (progn (message "Skipping removed entry at %s" e)
  9262. (setq cntskip (1+ cntskip)))
  9263. (goto-char pos)
  9264. (let (org-loop-over-headlines-in-active-region)
  9265. (eval cmd))
  9266. (setq cnt (1+ cnt))))
  9267. (when redo-at-end (org-agenda-redo))
  9268. (unless org-agenda-persistent-marks
  9269. (org-agenda-bulk-unmark-all))
  9270. (message "Acted on %d entries%s%s"
  9271. cnt
  9272. (if (= cntskip 0)
  9273. ""
  9274. (format ", skipped %d (disappeared before their turn)"
  9275. cntskip))
  9276. (if (not org-agenda-persistent-marks)
  9277. "" " (kept marked)"))))))
  9278. (defun org-agenda-capture (&optional with-time)
  9279. "Call `org-capture' with the date at point.
  9280. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9281. current HH:MM time."
  9282. (interactive "P")
  9283. (if (not (eq major-mode 'org-agenda-mode))
  9284. (user-error "You cannot do this outside of agenda buffers")
  9285. (let ((org-overriding-default-time
  9286. (org-get-cursor-date (equal with-time 1))))
  9287. (call-interactively 'org-capture))))
  9288. ;;; Dragging agenda lines forward/backward
  9289. (defun org-agenda-reapply-filters ()
  9290. "Re-apply all agenda filters."
  9291. (mapcar
  9292. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9293. `((,org-agenda-tag-filter tag)
  9294. (,org-agenda-category-filter category)
  9295. (,org-agenda-regexp-filter regexp)
  9296. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9297. (,(get 'org-agenda-category-filter :preset-filter) category)
  9298. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9299. (defun org-agenda-drag-line-forward (arg &optional backward)
  9300. "Drag an agenda line forward by ARG lines.
  9301. When the optional argument `backward' is non-nil, move backward."
  9302. (interactive "p")
  9303. (let ((inhibit-read-only t) lst line)
  9304. (if (or (not (get-text-property (point) 'txt))
  9305. (save-excursion
  9306. (dotimes (n arg)
  9307. (move-beginning-of-line (if backward 0 2))
  9308. (push (not (get-text-property (point) 'txt)) lst))
  9309. (delq nil lst)))
  9310. (message "Cannot move line forward")
  9311. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9312. (move-beginning-of-line 1)
  9313. (setq line (buffer-substring (point) end))
  9314. (delete-region (point) end)
  9315. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9316. (insert line)
  9317. (org-agenda-reapply-filters)
  9318. (org-agenda-mark-clocking-task)
  9319. (move-beginning-of-line 0)))))
  9320. (defun org-agenda-drag-line-backward (arg)
  9321. "Drag an agenda line backward by ARG lines."
  9322. (interactive "p")
  9323. (org-agenda-drag-line-forward arg t))
  9324. ;;; Flagging notes
  9325. (defun org-agenda-show-the-flagging-note ()
  9326. "Display the flagging note in the other window.
  9327. When called a second time in direct sequence, offer to remove the FLAGGING
  9328. tag and (if present) the flagging note."
  9329. (interactive)
  9330. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9331. (win (selected-window))
  9332. note heading newhead)
  9333. (unless hdmarker
  9334. (user-error "No linked entry at point"))
  9335. (if (and (eq this-command last-command)
  9336. (y-or-n-p "Unflag and remove any flagging note? "))
  9337. (progn
  9338. (org-agenda-remove-flag hdmarker)
  9339. (let ((win (get-buffer-window "*Flagging Note*")))
  9340. (and win (delete-window win)))
  9341. (message "Entry unflagged"))
  9342. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9343. (unless note
  9344. (user-error "No flagging note"))
  9345. (org-kill-new note)
  9346. (org-switch-to-buffer-other-window "*Flagging Note*")
  9347. (erase-buffer)
  9348. (insert note)
  9349. (goto-char (point-min))
  9350. (while (re-search-forward "\\\\n" nil t)
  9351. (replace-match "\n" t t))
  9352. (goto-char (point-min))
  9353. (select-window win)
  9354. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9355. (defun org-agenda-remove-flag (marker)
  9356. "Remove the FLAGGED tag and any flagging note in the entry."
  9357. (let (newhead)
  9358. (org-with-point-at marker
  9359. (org-toggle-tag "FLAGGED" 'off)
  9360. (org-entry-delete nil "THEFLAGGINGNOTE")
  9361. (setq newhead (org-get-heading)))
  9362. (org-agenda-change-all-lines newhead marker)
  9363. (message "Entry unflagged")))
  9364. (defun org-agenda-get-any-marker (&optional pos)
  9365. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9366. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9367. ;;; Appointment reminders
  9368. (defvar appt-time-msg-list) ; defined in appt.el
  9369. ;;;###autoload
  9370. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9371. "Activate appointments found in `org-agenda-files'.
  9372. With a \\[universal-argument] prefix, refresh the list of
  9373. appointments.
  9374. If FILTER is t, interactively prompt the user for a regular
  9375. expression, and filter out entries that don't match it.
  9376. If FILTER is a string, use this string as a regular expression
  9377. for filtering entries out.
  9378. If FILTER is a function, filter out entries against which
  9379. calling the function returns nil. This function takes one
  9380. argument: an entry from `org-agenda-get-day-entries'.
  9381. FILTER can also be an alist with the car of each cell being
  9382. either 'headline or 'category. For example:
  9383. '((headline \"IMPORTANT\")
  9384. (category \"Work\"))
  9385. will only add headlines containing IMPORTANT or headlines
  9386. belonging to the \"Work\" category.
  9387. ARGS are symbols indicating what kind of entries to consider.
  9388. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9389. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9390. and :timestamp entries. See the docstring of `org-diary' for
  9391. details and examples.
  9392. If an entry has a APPT_WARNTIME property, its value will be used
  9393. to override `appt-message-warning-time'."
  9394. (interactive "P")
  9395. (if refresh (setq appt-time-msg-list nil))
  9396. (if (eq filter t)
  9397. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9398. (let* ((cnt 0) ; count added events
  9399. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9400. (org-agenda-new-buffers nil)
  9401. (org-deadline-warning-days 0)
  9402. ;; Do not use `org-today' here because appt only takes
  9403. ;; time and without date as argument, so it may pass wrong
  9404. ;; information otherwise
  9405. (today (org-date-to-gregorian
  9406. (time-to-days (current-time))))
  9407. (org-agenda-restrict nil)
  9408. (files (org-agenda-files 'unrestricted)) entries file
  9409. (org-agenda-buffer nil))
  9410. ;; Get all entries which may contain an appt
  9411. (org-agenda-prepare-buffers files)
  9412. (while (setq file (pop files))
  9413. (setq entries
  9414. (delq nil
  9415. (append entries
  9416. (apply 'org-agenda-get-day-entries
  9417. file today scope)))))
  9418. ;; Map thru entries and find if we should filter them out
  9419. (mapc
  9420. (lambda(x)
  9421. (let* ((evt (org-trim
  9422. (replace-regexp-in-string
  9423. org-bracket-link-regexp "\\3"
  9424. (or (get-text-property 1 'txt x) ""))))
  9425. (cat (get-text-property 1 'org-category x))
  9426. (tod (get-text-property 1 'time-of-day x))
  9427. (ok (or (null filter)
  9428. (and (stringp filter) (string-match filter evt))
  9429. (and (functionp filter) (funcall filter x))
  9430. (and (listp filter)
  9431. (let ((cat-filter (cadr (assoc 'category filter)))
  9432. (evt-filter (cadr (assoc 'headline filter))))
  9433. (or (and (stringp cat-filter)
  9434. (string-match cat-filter cat))
  9435. (and (stringp evt-filter)
  9436. (string-match evt-filter evt)))))))
  9437. (wrn (get-text-property 1 'warntime x)))
  9438. ;; FIXME: Shall we remove text-properties for the appt text?
  9439. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9440. (when (and ok tod)
  9441. (setq tod (concat "00" (number-to-string tod))
  9442. tod (when (string-match
  9443. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9444. (concat (match-string 1 tod) ":"
  9445. (match-string 2 tod))))
  9446. (if (version< emacs-version "23.3")
  9447. (appt-add tod evt)
  9448. (appt-add tod evt wrn))
  9449. (setq cnt (1+ cnt))))) entries)
  9450. (org-release-buffers org-agenda-new-buffers)
  9451. (if (eq cnt 0)
  9452. (message "No event to add")
  9453. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9454. (defun org-agenda-todayp (date)
  9455. "Does DATE mean today, when considering `org-extend-today-until'?"
  9456. (let ((today (org-today))
  9457. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9458. date)))
  9459. (eq date today)))
  9460. (defun org-agenda-todo-yesterday (&optional arg)
  9461. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9462. (interactive "P")
  9463. (let* ((hour (third (decode-time
  9464. (org-current-time))))
  9465. (org-extend-today-until (1+ hour)))
  9466. (org-agenda-todo arg)))
  9467. (provide 'org-agenda)
  9468. ;;; org-agenda.el ends here