org-agenda.el 366 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 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-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  661. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  662. The variables
  663. `org-agenda-todo-ignore-with-date',
  664. `org-agenda-todo-ignore-timestamp',
  665. `org-agenda-todo-ignore-scheduled',
  666. `org-agenda-todo-ignore-deadlines'
  667. make the global TODO list skip entries that have time stamps of certain
  668. kinds. If this option is set, the same options will also apply for the
  669. tags-todo search, which is the general tags/property matcher
  670. restricted to unfinished TODO entries only."
  671. :group 'org-agenda-skip
  672. :group 'org-agenda-todo-list
  673. :group 'org-agenda-match-view
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-done nil
  676. "Non-nil means don't show scheduled items in agenda when they are done.
  677. This is relevant for the daily/weekly agenda, not for the TODO list. And
  678. it applies only to the actual date of the scheduling. Warnings about
  679. an item with a past scheduling dates are always turned off when the item
  680. is DONE."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  685. "Non-nil means skip scheduling line if same entry shows because of deadline.
  686. In the agenda of today, an entry can show up multiple times because
  687. it is both scheduled and has a nearby deadline, and maybe a plain time
  688. stamp as well.
  689. When this variable is t, then only the deadline is shown and the fact that
  690. the entry is scheduled today or was scheduled previously is not shown.
  691. When this variable is nil, the entry will be shown several times. When
  692. the variable is the symbol `not-today', then skip scheduled previously,
  693. but not scheduled today."
  694. :group 'org-agenda-skip
  695. :group 'org-agenda-daily/weekly
  696. :type '(choice
  697. (const :tag "Never" nil)
  698. (const :tag "Always" t)
  699. (const :tag "Not when scheduled today" not-today)))
  700. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  701. "Non-nil means skip timestamp line if same entry shows because of deadline.
  702. In the agenda of today, an entry can show up multiple times
  703. because it has both a plain timestamp and has a nearby deadline.
  704. When this variable is t, then only the deadline is shown and the
  705. fact that the entry has a timestamp for or including today is not
  706. shown. When this variable is nil, the entry will be shown
  707. several times."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :version "24.1"
  711. :type '(choice
  712. (const :tag "Never" nil)
  713. (const :tag "Always" t)))
  714. (defcustom org-agenda-skip-deadline-if-done nil
  715. "Non-nil means don't show deadlines when the corresponding item is done.
  716. When nil, the deadline is still shown and should give you a happy feeling.
  717. This is relevant for the daily/weekly agenda. And it applied only to the
  718. actually date of the deadline. Warnings about approaching and past-due
  719. deadlines are always turned off when the item is DONE."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  724. "Non-nil means skip deadline prewarning when entry is also scheduled.
  725. This will apply on all days where a prewarning for the deadline would
  726. be shown, but not at the day when the entry is actually due. On that day,
  727. the deadline will be shown anyway.
  728. This variable may be set to nil, t, or a number which will then give
  729. the number of days before the actual deadline when the prewarnings
  730. should resume.
  731. This can be used in a workflow where the first showing of the deadline will
  732. trigger you to schedule it, and then you don't want to be reminded of it
  733. because you will take care of it on the day when scheduled."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :version "24.1"
  737. :type '(choice
  738. (const :tag "Alwas show prewarning" nil)
  739. (const :tag "Remove prewarning if entry is scheduled" t)
  740. (integer :tag "Restart prewarning N days before deadline")))
  741. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  742. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  743. When non-nil, after the search for timestamps has matched once in an
  744. entry, the rest of the entry will not be searched."
  745. :group 'org-agenda-skip
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-timestamp-if-done nil
  748. "Non-nil means don't select item by timestamp or -range if it is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-dim-blocked-tasks t
  753. "Non-nil means dim blocked tasks in the agenda display.
  754. This causes some overhead during agenda construction, but if you
  755. have turned on `org-enforce-todo-dependencies',
  756. `org-enforce-todo-checkbox-dependencies', or any other blocking
  757. mechanism, this will create useful feedback in the agenda.
  758. Instead of t, this variable can also have the value `invisible'.
  759. Then blocked tasks will be invisible and only become visible when
  760. they become unblocked. An exemption to this behavior is when a task is
  761. blocked because of unchecked checkboxes below it. Since checkboxes do
  762. not show up in the agenda views, making this task invisible you remove any
  763. trace from agenda views that there is something to do. Therefore, a task
  764. that is blocked because of checkboxes will never be made invisible, it
  765. will only be dimmed."
  766. :group 'org-agenda-daily/weekly
  767. :group 'org-agenda-todo-list
  768. :type '(choice
  769. (const :tag "Do not dim" nil)
  770. (const :tag "Dim to a gray face" t)
  771. (const :tag "Make invisible" invisible)))
  772. (defcustom org-timeline-show-empty-dates 3
  773. "Non-nil means `org-timeline' also shows dates without an entry.
  774. When nil, only the days which actually have entries are shown.
  775. When t, all days between the first and the last date are shown.
  776. When an integer, show also empty dates, but if there is a gap of more than
  777. N days, just insert a special line indicating the size of the gap."
  778. :group 'org-agenda-skip
  779. :type '(choice
  780. (const :tag "None" nil)
  781. (const :tag "All" t)
  782. (integer :tag "at most")))
  783. (defgroup org-agenda-startup nil
  784. "Options concerning initial settings in the Agenda in Org Mode."
  785. :tag "Org Agenda Startup"
  786. :group 'org-agenda)
  787. (defcustom org-agenda-menu-show-matcher t
  788. "Non-nil means show the match string in the agenda dispatcher menu.
  789. When nil, the matcher string is not shown, but is put into the help-echo
  790. property so than moving the mouse over the command shows it.
  791. Setting it to nil is good if matcher strings are very long and/or if
  792. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  793. :group 'org-agenda
  794. :version "24.1"
  795. :type 'boolean)
  796. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  797. (defcustom org-agenda-menu-two-columns nil
  798. "Non-nil means, use two columns to show custom commands in the dispatcher.
  799. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  800. to nil."
  801. :group 'org-agenda
  802. :version "24.1"
  803. :type 'boolean)
  804. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  805. (defcustom org-agenda-finalize-hook nil
  806. "Hook run just before displaying an agenda buffer.
  807. The buffer is still writable when the hook is called.
  808. You can modify some of the buffer substrings but you should be
  809. extra careful not to modify the text properties of the agenda
  810. headlines as the agenda display heavily relies on them."
  811. :group 'org-agenda-startup
  812. :type 'hook)
  813. (defcustom org-agenda-mouse-1-follows-link nil
  814. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  815. A longer mouse click will still set point. Does not work on XEmacs.
  816. Needs to be set before org.el is loaded."
  817. :group 'org-agenda-startup
  818. :type 'boolean)
  819. (defcustom org-agenda-start-with-follow-mode nil
  820. "The initial value of follow mode in a newly created agenda window."
  821. :group 'org-agenda-startup
  822. :type 'boolean)
  823. (defcustom org-agenda-follow-indirect nil
  824. "Non-nil means `org-agenda-follow-mode' displays only the
  825. current item's tree, in an indirect buffer."
  826. :group 'org-agenda
  827. :version "24.1"
  828. :type 'boolean)
  829. (defcustom org-agenda-show-outline-path t
  830. "Non-nil means show outline path in echo area after line motion."
  831. :group 'org-agenda-startup
  832. :type 'boolean)
  833. (defcustom org-agenda-start-with-entry-text-mode nil
  834. "The initial value of entry-text-mode in a newly created agenda window."
  835. :group 'org-agenda-startup
  836. :type 'boolean)
  837. (defcustom org-agenda-entry-text-maxlines 5
  838. "Number of text lines to be added when `E' is pressed in the agenda.
  839. Note that this variable only used during agenda display. Add add entry text
  840. when exporting the agenda, configure the variable
  841. `org-agenda-add-entry-ext-maxlines'."
  842. :group 'org-agenda
  843. :type 'integer)
  844. (defcustom org-agenda-entry-text-exclude-regexps nil
  845. "List of regular expressions to clean up entry text.
  846. The complete matches of all regular expressions in this list will be
  847. removed from entry text before it is shown in the agenda."
  848. :group 'org-agenda
  849. :type '(repeat (regexp)))
  850. (defvar org-agenda-entry-text-cleanup-hook nil
  851. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  852. This cleanup is done in a temporary buffer, so the function may inspect and
  853. change the entire buffer.
  854. Some default stuff like drawers and scheduling/deadline dates will already
  855. have been removed when this is called, as will any matches for regular
  856. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  857. (defvar org-agenda-include-inactive-timestamps nil
  858. "Non-nil means include inactive time stamps in agenda and timeline.
  859. Dynamically scoped.")
  860. (defgroup org-agenda-windows nil
  861. "Options concerning the windows used by the Agenda in Org Mode."
  862. :tag "Org Agenda Windows"
  863. :group 'org-agenda)
  864. (defcustom org-agenda-window-setup 'reorganize-frame
  865. "How the agenda buffer should be displayed.
  866. Possible values for this option are:
  867. current-window Show agenda in the current window, keeping all other windows.
  868. other-window Use `switch-to-buffer-other-window' to display agenda.
  869. reorganize-frame Show only two windows on the current frame, the current
  870. window and the agenda.
  871. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  872. Also, when exiting the agenda, kill that frame.
  873. See also the variable `org-agenda-restore-windows-after-quit'."
  874. :group 'org-agenda-windows
  875. :type '(choice
  876. (const current-window)
  877. (const other-frame)
  878. (const other-window)
  879. (const reorganize-frame)))
  880. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  881. "The min and max height of the agenda window as a fraction of frame height.
  882. The value of the variable is a cons cell with two numbers between 0 and 1.
  883. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  884. :group 'org-agenda-windows
  885. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  886. (defcustom org-agenda-restore-windows-after-quit nil
  887. "Non-nil means restore window configuration upon exiting agenda.
  888. Before the window configuration is changed for displaying the agenda,
  889. the current status is recorded. When the agenda is exited with
  890. `q' or `x' and this option is set, the old state is restored. If
  891. `org-agenda-window-setup' is `other-frame', the value of this
  892. option will be ignored."
  893. :group 'org-agenda-windows
  894. :type 'boolean)
  895. (defcustom org-agenda-ndays nil
  896. "Number of days to include in overview display.
  897. Should be 1 or 7.
  898. Obsolete, see `org-agenda-span'."
  899. :group 'org-agenda-daily/weekly
  900. :type 'integer)
  901. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  902. (defcustom org-agenda-span 'week
  903. "Number of days to include in overview display.
  904. Can be day, week, month, year, or any number of days.
  905. Custom commands can set this variable in the options section."
  906. :group 'org-agenda-daily/weekly
  907. :type '(choice (const :tag "Day" day)
  908. (const :tag "Week" week)
  909. (const :tag "Month" month)
  910. (const :tag "Year" year)
  911. (integer :tag "Custom")))
  912. (defcustom org-agenda-start-on-weekday 1
  913. "Non-nil means start the overview always on the specified weekday.
  914. 0 denotes Sunday, 1 denotes Monday etc.
  915. When nil, always start on the current day.
  916. Custom commands can set this variable in the options section."
  917. :group 'org-agenda-daily/weekly
  918. :type '(choice (const :tag "Today" nil)
  919. (integer :tag "Weekday No.")))
  920. (defcustom org-agenda-show-all-dates t
  921. "Non-nil means `org-agenda' shows every day in the selected range.
  922. When nil, only the days which actually have entries are shown."
  923. :group 'org-agenda-daily/weekly
  924. :type 'boolean)
  925. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  926. "Format string for displaying dates in the agenda.
  927. Used by the daily/weekly agenda and by the timeline. This should be
  928. a format string understood by `format-time-string', or a function returning
  929. the formatted date as a string. The function must take a single argument,
  930. a calendar-style date list like (month day year)."
  931. :group 'org-agenda-daily/weekly
  932. :type '(choice
  933. (string :tag "Format string")
  934. (function :tag "Function")))
  935. (defun org-agenda-format-date-aligned (date)
  936. "Format a date string for display in the daily/weekly agenda, or timeline.
  937. This function makes sure that dates are aligned for easy reading."
  938. (require 'cal-iso)
  939. (let* ((dayname (calendar-day-name date))
  940. (day (cadr date))
  941. (day-of-week (calendar-day-of-week date))
  942. (month (car date))
  943. (monthname (calendar-month-name month))
  944. (year (nth 2 date))
  945. (iso-week (org-days-to-iso-week
  946. (calendar-absolute-from-gregorian date)))
  947. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  948. (1- year))
  949. ((and (= month 12) (<= iso-week 1))
  950. (1+ year))
  951. (t year)))
  952. (weekstring (if (= day-of-week 1)
  953. (format " W%02d" iso-week)
  954. "")))
  955. (format "%-10s %2d %s %4d%s"
  956. dayname day monthname year weekstring)))
  957. (defcustom org-agenda-time-leading-zero nil
  958. "Non-nil means use leading zero for military times in agenda.
  959. For example, 9:30am would become 09:30 rather than 9:30."
  960. :group 'org-agenda-daily/weekly
  961. :version "24.1"
  962. :type 'boolean)
  963. (defcustom org-agenda-timegrid-use-ampm nil
  964. "When set, show AM/PM style timestamps on the timegrid."
  965. :group 'org-agenda
  966. :version "24.1"
  967. :type 'boolean)
  968. (defun org-agenda-time-of-day-to-ampm (time)
  969. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  970. (let* ((hour-number (string-to-number (substring time 0 -3)))
  971. (minute (substring time -2))
  972. (ampm "am"))
  973. (cond
  974. ((equal hour-number 12)
  975. (setq ampm "pm"))
  976. ((> hour-number 12)
  977. (setq ampm "pm")
  978. (setq hour-number (- hour-number 12))))
  979. (concat
  980. (if org-agenda-time-leading-zero
  981. (format "%02d" hour-number)
  982. (format "%02s" (number-to-string hour-number)))
  983. ":" minute ampm)))
  984. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  985. "Conditionally convert TIME to AM/PM format
  986. based on `org-agenda-timegrid-use-ampm'"
  987. (if org-agenda-timegrid-use-ampm
  988. (org-agenda-time-of-day-to-ampm time)
  989. time))
  990. (defcustom org-agenda-weekend-days '(6 0)
  991. "Which days are weekend?
  992. These days get the special face `org-agenda-date-weekend' in the agenda
  993. and timeline buffers."
  994. :group 'org-agenda-daily/weekly
  995. :type '(set :greedy t
  996. (const :tag "Monday" 1)
  997. (const :tag "Tuesday" 2)
  998. (const :tag "Wednesday" 3)
  999. (const :tag "Thursday" 4)
  1000. (const :tag "Friday" 5)
  1001. (const :tag "Saturday" 6)
  1002. (const :tag "Sunday" 0)))
  1003. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1004. "Non-nil means jump to today when moving a past date forward in time.
  1005. When using S-right in the agenda to move a a date forward, and the date
  1006. stamp currently points to the past, the first key press will move it
  1007. to today. WHen nil, just move one day forward even if the date stays
  1008. in the past."
  1009. :group 'org-agenda-daily/weekly
  1010. :version "24.1"
  1011. :type 'boolean)
  1012. (defcustom org-agenda-include-diary nil
  1013. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type 'boolean)
  1017. (defcustom org-agenda-include-deadlines t
  1018. "If non-nil, include entries within their deadline warning period.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :version "24.1"
  1022. :type 'boolean)
  1023. (defcustom org-agenda-repeating-timestamp-show-all t
  1024. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1025. When set to a list of strings, only show occurrences of repeating
  1026. stamps for these TODO keywords. When nil, only one occurrence is
  1027. shown, either today or the nearest into the future."
  1028. :group 'org-agenda-daily/weekly
  1029. :type '(choice
  1030. (const :tag "Show repeating stamps" t)
  1031. (repeat :tag "Show repeating stamps for these TODO keywords"
  1032. (string :tag "TODO Keyword"))
  1033. (const :tag "Don't show repeating stamps" nil)))
  1034. (defcustom org-scheduled-past-days 10000
  1035. "No. of days to continue listing scheduled items that are not marked DONE.
  1036. When an item is scheduled on a date, it shows up in the agenda on this
  1037. day and will be listed until it is marked done for the number of days
  1038. given here."
  1039. :group 'org-agenda-daily/weekly
  1040. :type 'integer)
  1041. (defcustom org-agenda-log-mode-items '(closed clock)
  1042. "List of items that should be shown in agenda log mode.
  1043. This list may contain the following symbols:
  1044. closed Show entries that have been closed on that day.
  1045. clock Show entries that have received clocked time on that day.
  1046. state Show all logged state changes.
  1047. Note that instead of changing this variable, you can also press `C-u l' in
  1048. the agenda to display all available LOG items temporarily."
  1049. :group 'org-agenda-daily/weekly
  1050. :type '(set :greedy t (const closed) (const clock) (const state)))
  1051. (defcustom org-agenda-clock-consistency-checks
  1052. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1053. :gap-ok-around ("4:00")
  1054. :default-face ((:background "DarkRed") (:foreground "white"))
  1055. :overlap-face nil :gap-face nil :no-end-time-face nil
  1056. :long-face nil :short-face nil)
  1057. "This is a property list, with the following keys:
  1058. :max-duration Mark clocking chunks that are longer than this time.
  1059. This is a time string like \"HH:MM\", or the number
  1060. of minutes as an integer.
  1061. :min-duration Mark clocking chunks that are shorter that this.
  1062. This is a time string like \"HH:MM\", or the number
  1063. of minutes as an integer.
  1064. :max-gap Mark gaps between clocking chunks that are longer than
  1065. this duration. A number of minutes, or a string
  1066. like \"HH:MM\".
  1067. :gap-ok-around List of times during the day which are usually not working
  1068. times. When a gap is detected, but the gap contains any
  1069. of these times, the gap is *not* reported. For example,
  1070. if this is (\"4:00\" \"13:00\") then gaps that contain
  1071. 4:00 in the morning (i.e. the night) and 13:00
  1072. (i.e. a typical lunch time) do not cause a warning.
  1073. You should have at least one time during the night in this
  1074. list, or otherwise the first task each morning will trigger
  1075. a warning because it follows a long gap.
  1076. Furthermore, the following properties can be used to define faces for
  1077. issue display.
  1078. :default-face the default face, if the specific face is undefined
  1079. :overlap-face face for overlapping clocks
  1080. :gap-face face for gaps between clocks
  1081. :no-end-time-face face for incomplete clocks
  1082. :long-face face for clock intervals that are too long
  1083. :short-face face for clock intervals that are too short"
  1084. :group 'org-agenda-daily/weekly
  1085. :group 'org-clock
  1086. :version "24.1"
  1087. :type 'plist)
  1088. (defcustom org-agenda-log-mode-add-notes t
  1089. "Non-nil means add first line of notes to log entries in agenda views.
  1090. If a log item like a state change or a clock entry is associated with
  1091. notes, the first line of these notes will be added to the entry in the
  1092. agenda display."
  1093. :group 'org-agenda-daily/weekly
  1094. :type 'boolean)
  1095. (defcustom org-agenda-start-with-log-mode nil
  1096. "The initial value of log-mode in a newly created agenda window.
  1097. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1098. explanations on the possible values."
  1099. :group 'org-agenda-startup
  1100. :group 'org-agenda-daily/weekly
  1101. :type '(choice (const :tag "Don't show log items" nil)
  1102. (const :tag "Show only log items" 'only)
  1103. (const :tag "Show all possible log items" 'clockcheck)
  1104. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1105. (choice (const :tag "Show closed log items" 'closed)
  1106. (const :tag "Show clocked log items" 'clock)
  1107. (const :tag "Show all logged state changes" 'state)))))
  1108. (defcustom org-agenda-start-with-clockreport-mode nil
  1109. "The initial value of clockreport-mode in a newly created agenda window."
  1110. :group 'org-agenda-startup
  1111. :group 'org-agenda-daily/weekly
  1112. :type 'boolean)
  1113. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1114. "Property list with parameters for the clocktable in clockreport mode.
  1115. This is the display mode that shows a clock table in the daily/weekly
  1116. agenda, the properties for this dynamic block can be set here.
  1117. The usual clocktable parameters are allowed here, but you cannot set
  1118. the properties :name, :tstart, :tend, :block, and :scope - these will
  1119. be overwritten to make sure the content accurately reflects the
  1120. current display in the agenda."
  1121. :group 'org-agenda-daily/weekly
  1122. :type 'plist)
  1123. (defcustom org-agenda-search-view-always-boolean nil
  1124. "Non-nil means the search string is interpreted as individual parts.
  1125. The search string for search view can either be interpreted as a phrase,
  1126. or as a list of snippets that define a boolean search for a number of
  1127. strings.
  1128. When this is non-nil, the string will be split on whitespace, and each
  1129. snippet will be searched individually, and all must match in order to
  1130. select an entry. A snippet is then a single string of non-white
  1131. characters, or a string in double quotes, or a regexp in {} braces.
  1132. If a snippet is preceded by \"-\", the snippet must *not* match.
  1133. \"+\" is syntactic sugar for positive selection. Each snippet may
  1134. be found as a full word or a partial word, but see the variable
  1135. `org-agenda-search-view-force-full-words'.
  1136. When this is nil, search will look for the entire search phrase as one,
  1137. with each space character matching any amount of whitespace, including
  1138. line breaks.
  1139. Even when this is nil, you can still switch to Boolean search dynamically
  1140. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1141. is a regexp marked with braces like \"{abc}\", this will also switch to
  1142. boolean search."
  1143. :group 'org-agenda-search-view
  1144. :version "24.1"
  1145. :type 'boolean)
  1146. (if (fboundp 'defvaralias)
  1147. (defvaralias 'org-agenda-search-view-search-words-only
  1148. 'org-agenda-search-view-always-boolean))
  1149. (defcustom org-agenda-search-view-force-full-words nil
  1150. "Non-nil means, search words must be matches as complete words.
  1151. When nil, they may also match part of a word."
  1152. :group 'org-agenda-search-view
  1153. :version "24.1"
  1154. :type 'boolean)
  1155. (defgroup org-agenda-time-grid nil
  1156. "Options concerning the time grid in the Org-mode Agenda."
  1157. :tag "Org Agenda Time Grid"
  1158. :group 'org-agenda)
  1159. (defcustom org-agenda-search-headline-for-time t
  1160. "Non-nil means search headline for a time-of-day.
  1161. If the headline contains a time-of-day in one format or another, it will
  1162. be used to sort the entry into the time sequence of items for a day.
  1163. Some people have time stamps in the headline that refer to the creation
  1164. time or so, and then this produces an unwanted side effect. If this is
  1165. the case for your, use this variable to turn off searching the headline
  1166. for a time."
  1167. :group 'org-agenda-time-grid
  1168. :type 'boolean)
  1169. (defcustom org-agenda-use-time-grid t
  1170. "Non-nil means show a time grid in the agenda schedule.
  1171. A time grid is a set of lines for specific times (like every two hours between
  1172. 8:00 and 20:00). The items scheduled for a day at specific times are
  1173. sorted in between these lines.
  1174. For details about when the grid will be shown, and what it will look like, see
  1175. the variable `org-agenda-time-grid'."
  1176. :group 'org-agenda-time-grid
  1177. :type 'boolean)
  1178. (defcustom org-agenda-time-grid
  1179. '((daily today require-timed)
  1180. "----------------"
  1181. (800 1000 1200 1400 1600 1800 2000))
  1182. "The settings for time grid for agenda display.
  1183. This is a list of three items. The first item is again a list. It contains
  1184. symbols specifying conditions when the grid should be displayed:
  1185. daily if the agenda shows a single day
  1186. weekly if the agenda shows an entire week
  1187. today show grid on current date, independent of daily/weekly display
  1188. require-timed show grid only if at least one item has a time specification
  1189. The second item is a string which will be placed behind the grid time.
  1190. The third item is a list of integers, indicating the times that should have
  1191. a grid line."
  1192. :group 'org-agenda-time-grid
  1193. :type
  1194. '(list
  1195. (set :greedy t :tag "Grid Display Options"
  1196. (const :tag "Show grid in single day agenda display" daily)
  1197. (const :tag "Show grid in weekly agenda display" weekly)
  1198. (const :tag "Always show grid for today" today)
  1199. (const :tag "Show grid only if any timed entries are present"
  1200. require-timed)
  1201. (const :tag "Skip grid times already present in an entry"
  1202. remove-match))
  1203. (string :tag "Grid String")
  1204. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1205. (defcustom org-agenda-show-current-time-in-grid t
  1206. "Non-nil means show the current time in the time grid."
  1207. :group 'org-agenda-time-grid
  1208. :version "24.1"
  1209. :type 'boolean)
  1210. (defcustom org-agenda-current-time-string
  1211. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1212. "The string for the current time marker in the agenda."
  1213. :group 'org-agenda-time-grid
  1214. :version "24.1"
  1215. :type 'string)
  1216. (defgroup org-agenda-sorting nil
  1217. "Options concerning sorting in the Org-mode Agenda."
  1218. :tag "Org Agenda Sorting"
  1219. :group 'org-agenda)
  1220. (defcustom org-agenda-sorting-strategy
  1221. '((agenda habit-down time-up priority-down category-keep)
  1222. (todo priority-down category-keep)
  1223. (tags priority-down category-keep)
  1224. (search category-keep))
  1225. "Sorting structure for the agenda items of a single day.
  1226. This is a list of symbols which will be used in sequence to determine
  1227. if an entry should be listed before another entry. The following
  1228. symbols are recognized:
  1229. time-up Put entries with time-of-day indications first, early first
  1230. time-down Put entries with time-of-day indications first, late first
  1231. category-keep Keep the default order of categories, corresponding to the
  1232. sequence in `org-agenda-files'.
  1233. category-up Sort alphabetically by category, A-Z.
  1234. category-down Sort alphabetically by category, Z-A.
  1235. tag-up Sort alphabetically by last tag, A-Z.
  1236. tag-down Sort alphabetically by last tag, Z-A.
  1237. priority-up Sort numerically by priority, high priority last.
  1238. priority-down Sort numerically by priority, high priority first.
  1239. todo-state-up Sort by todo state, tasks that are done last.
  1240. todo-state-down Sort by todo state, tasks that are done first.
  1241. effort-up Sort numerically by estimated effort, high effort last.
  1242. effort-down Sort numerically by estimated effort, high effort first.
  1243. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1244. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1245. habit-up Put entries that are habits first
  1246. habit-down Put entries that are habits last
  1247. alpha-up Sort headlines alphabetically
  1248. alpha-down Sort headlines alphabetically, reversed
  1249. The different possibilities will be tried in sequence, and testing stops
  1250. if one comparison returns a \"not-equal\". For example, the default
  1251. '(time-up category-keep priority-down)
  1252. means: Pull out all entries having a specified time of day and sort them,
  1253. in order to make a time schedule for the current day the first thing in the
  1254. agenda listing for the day. Of the entries without a time indication, keep
  1255. the grouped in categories, don't sort the categories, but keep them in
  1256. the sequence given in `org-agenda-files'. Within each category sort by
  1257. priority.
  1258. Leaving out `category-keep' would mean that items will be sorted across
  1259. categories by priority.
  1260. Instead of a single list, this can also be a set of list for specific
  1261. contents, with a context symbol in the car of the list, any of
  1262. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1263. Custom commands can bind this variable in the options section."
  1264. :group 'org-agenda-sorting
  1265. :type `(choice
  1266. (repeat :tag "General" ,org-sorting-choice)
  1267. (list :tag "Individually"
  1268. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1269. (repeat ,org-sorting-choice))
  1270. (cons (const :tag "Strategy for TODO lists" todo)
  1271. (repeat ,org-sorting-choice))
  1272. (cons (const :tag "Strategy for Tags matches" tags)
  1273. (repeat ,org-sorting-choice))
  1274. (cons (const :tag "Strategy for search matches" search)
  1275. (repeat ,org-sorting-choice)))))
  1276. (defcustom org-agenda-cmp-user-defined nil
  1277. "A function to define the comparison `user-defined'.
  1278. This function must receive two arguments, agenda entry a and b.
  1279. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1280. the user comparison, return nil.
  1281. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1282. part of an agenda sorting strategy."
  1283. :group 'org-agenda-sorting
  1284. :type 'symbol)
  1285. (defcustom org-sort-agenda-notime-is-late t
  1286. "Non-nil means items without time are considered late.
  1287. This is only relevant for sorting. When t, items which have no explicit
  1288. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1289. do have a time. When nil, the default time is before 0:00. You can use this
  1290. option to decide if the schedule for today should come before or after timeless
  1291. agenda entries."
  1292. :group 'org-agenda-sorting
  1293. :type 'boolean)
  1294. (defcustom org-sort-agenda-noeffort-is-high t
  1295. "Non-nil means items without effort estimate are sorted as high effort.
  1296. This also applies when filtering an agenda view with respect to the
  1297. < or > effort operator. Then, tasks with no effort defined will be treated
  1298. as tasks with high effort.
  1299. When nil, such items are sorted as 0 minutes effort."
  1300. :group 'org-agenda-sorting
  1301. :type 'boolean)
  1302. (defgroup org-agenda-line-format nil
  1303. "Options concerning the entry prefix in the Org-mode agenda display."
  1304. :tag "Org Agenda Line Format"
  1305. :group 'org-agenda)
  1306. (defcustom org-agenda-prefix-format
  1307. '((agenda . " %i %-12:c%?-12t% s")
  1308. (timeline . " % s")
  1309. (todo . " %i %-12:c")
  1310. (tags . " %i %-12:c")
  1311. (search . " %i %-12:c"))
  1312. "Format specifications for the prefix of items in the agenda views.
  1313. An alist with five entries, each for the different agenda types. The
  1314. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1315. The values are format strings.
  1316. This format works similar to a printf format, with the following meaning:
  1317. %c the category of the item, \"Diary\" for entries from the diary,
  1318. or as given by the CATEGORY keyword or derived from the file name
  1319. %e the effort required by the item
  1320. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1321. %T the last tag of the item (ignore inherited tags, which come first)
  1322. %t the HH:MM time-of-day specification if one applies to the entry
  1323. %s Scheduling/Deadline information, a short string
  1324. %(expression) Eval EXPRESSION and replace the control string
  1325. by the result
  1326. All specifiers work basically like the standard `%s' of printf, but may
  1327. contain two additional characters: a question mark just after the `%'
  1328. and a whitespace/punctuation character just before the final letter.
  1329. If the first character after `%' is a question mark, the entire field
  1330. will only be included if the corresponding value applies to the current
  1331. entry. This is useful for fields which should have fixed width when
  1332. present, but zero width when absent. For example, \"%?-12t\" will
  1333. result in a 12 character time field if a time of the day is specified,
  1334. but will completely disappear in entries which do not contain a time.
  1335. If there is punctuation or whitespace character just before the final
  1336. format letter, this character will be appended to the field value if
  1337. the value is not empty. For example, the format \"%-12:c\" leads to
  1338. \"Diary: \" if the category is \"Diary\". If the category were be
  1339. empty, no additional colon would be inserted.
  1340. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1341. which means:
  1342. - Indent the line with two space characters
  1343. - Give the category a 12 chars wide field, padded with whitespace on
  1344. the right (because of `-'). Append a colon if there is a category
  1345. (because of `:').
  1346. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1347. time, don't put in an empty field, just skip it (because of '?').
  1348. - Finally, put the scheduling information.
  1349. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1350. `org-agenda-remove-tags'.
  1351. Custom commands can set this variable in the options section."
  1352. :type '(choice
  1353. (string :tag "General format")
  1354. (list :greedy t :tag "View dependent"
  1355. (cons (const agenda) (string :tag "Format"))
  1356. (cons (const timeline) (string :tag "Format"))
  1357. (cons (const todo) (string :tag "Format"))
  1358. (cons (const tags) (string :tag "Format"))
  1359. (cons (const search) (string :tag "Format"))))
  1360. :group 'org-agenda-line-format)
  1361. (defvar org-prefix-format-compiled nil
  1362. "The compiled prefix format and associated variables.
  1363. This is a list where first element is a list of variable bindings, and second
  1364. element is the compiled format expression. See the variable
  1365. `org-agenda-prefix-format'.")
  1366. (defcustom org-agenda-todo-keyword-format "%-1s"
  1367. "Format for the TODO keyword in agenda lines.
  1368. Set this to something like \"%-12s\" if you want all TODO keywords
  1369. to occupy a fixed space in the agenda display."
  1370. :group 'org-agenda-line-format
  1371. :type 'string)
  1372. (defcustom org-agenda-diary-sexp-prefix nil
  1373. "A regexp that matches part of a diary sexp entry
  1374. which should be treated as scheduling/deadline information in
  1375. `org-agenda'.
  1376. For example, you can use this to extract the `diary-remind-message' from
  1377. `diary-remind' entries."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1380. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1381. "Text preceding timerange entries in the agenda view.
  1382. This is a list with two strings. The first applies when the range
  1383. is entirely on one day. The second applies if the range spans several days.
  1384. The strings may have two \"%d\" format specifiers which will be filled
  1385. with the sequence number of the days, and the total number of days in the
  1386. range, respectively."
  1387. :group 'org-agenda-line-format
  1388. :type '(list
  1389. (string :tag "Deadline today ")
  1390. (choice :tag "Deadline relative"
  1391. (string :tag "Format string")
  1392. (function))))
  1393. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1394. "Text preceding scheduled items in the agenda view.
  1395. This is a list with two strings. The first applies when the item is
  1396. scheduled on the current day. The second applies when it has been scheduled
  1397. previously, it may contain a %d indicating that this is the nth time that
  1398. this item is scheduled, due to automatic rescheduling of unfinished items
  1399. for the following day. So this number is one larger than the number of days
  1400. that passed since this item was scheduled first."
  1401. :group 'org-agenda-line-format
  1402. :type '(list
  1403. (string :tag "Scheduled today ")
  1404. (string :tag "Scheduled previously")))
  1405. (defcustom org-agenda-inactive-leader "["
  1406. "Text preceding item pulled into the agenda by inactive time stamps.
  1407. These entries are added to the agenda when pressing \"[\"."
  1408. :group 'org-agenda-line-format
  1409. :version "24.1"
  1410. :type '(list
  1411. (string :tag "Scheduled today ")
  1412. (string :tag "Scheduled previously")))
  1413. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1414. "Text preceding deadline items in the agenda view.
  1415. This is a list with two strings. The first applies when the item has its
  1416. deadline on the current day. The second applies when it is in the past or
  1417. in the future, it may contain %d to capture how many days away the deadline
  1418. is (was)."
  1419. :group 'org-agenda-line-format
  1420. :type '(list
  1421. (string :tag "Deadline today ")
  1422. (choice :tag "Deadline relative"
  1423. (string :tag "Format string")
  1424. (function))))
  1425. (defcustom org-agenda-remove-times-when-in-prefix t
  1426. "Non-nil means remove duplicate time specifications in agenda items.
  1427. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1428. time-of-day specification in a headline or diary entry is extracted and
  1429. placed into the prefix. If this option is non-nil, the original specification
  1430. \(a timestamp or -range, or just a plain time(range) specification like
  1431. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1432. cluttered.
  1433. The option can be t or nil. It may also be the symbol `beg', indicating
  1434. that the time should only be removed when it is located at the beginning of
  1435. the headline/diary entry."
  1436. :group 'org-agenda-line-format
  1437. :type '(choice
  1438. (const :tag "Always" t)
  1439. (const :tag "Never" nil)
  1440. (const :tag "When at beginning of entry" beg)))
  1441. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1442. "Non-nil means remove time ranges specifications in agenda
  1443. items that span on several days."
  1444. :group 'org-agenda-line-format
  1445. :version "24.1"
  1446. :type 'boolean)
  1447. (defcustom org-agenda-default-appointment-duration nil
  1448. "Default duration for appointments that only have a starting time.
  1449. When nil, no duration is specified in such cases.
  1450. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1451. :group 'org-agenda-line-format
  1452. :type '(choice
  1453. (integer :tag "Minutes")
  1454. (const :tag "No default duration")))
  1455. (defcustom org-agenda-show-inherited-tags t
  1456. "Non-nil means show inherited tags in each agenda line."
  1457. :group 'org-agenda-line-format
  1458. :type 'boolean)
  1459. (defcustom org-agenda-hide-tags-regexp nil
  1460. "Regular expression used to filter away specific tags in agenda views.
  1461. This means that these tags will be present, but not be shown in the agenda
  1462. line. Secondary filtering will still work on the hidden tags.
  1463. Nil means don't hide any tags."
  1464. :group 'org-agenda-line-format
  1465. :type '(choice
  1466. (const :tag "Hide none" nil)
  1467. (string :tag "Regexp ")))
  1468. (defcustom org-agenda-remove-tags nil
  1469. "Non-nil means remove the tags from the headline copy in the agenda.
  1470. When this is the symbol `prefix', only remove tags when
  1471. `org-agenda-prefix-format' contains a `%T' specifier."
  1472. :group 'org-agenda-line-format
  1473. :type '(choice
  1474. (const :tag "Always" t)
  1475. (const :tag "Never" nil)
  1476. (const :tag "When prefix format contains %T" prefix)))
  1477. (if (fboundp 'defvaralias)
  1478. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1479. 'org-agenda-remove-tags))
  1480. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1481. "Shift tags in agenda items to this column.
  1482. If this number is positive, it specifies the column. If it is negative,
  1483. it means that the tags should be flushright to that column. For example,
  1484. -80 works well for a normal 80 character screen."
  1485. :group 'org-agenda-line-format
  1486. :type 'integer)
  1487. (if (fboundp 'defvaralias)
  1488. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1489. (defcustom org-agenda-fontify-priorities 'cookies
  1490. "Non-nil means highlight low and high priorities in agenda.
  1491. When t, the highest priority entries are bold, lowest priority italic.
  1492. However, settings in `org-priority-faces' will overrule these faces.
  1493. When this variable is the symbol `cookies', only fontify the
  1494. cookies, not the entire task.
  1495. This may also be an association list of priority faces, whose
  1496. keys are the character values of `org-highest-priority',
  1497. `org-default-priority', and `org-lowest-priority' (the default values
  1498. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1499. color as a string, or a list like `(:background \"Red\")'.
  1500. If it is a color, the variable `org-faces-easy-properties'
  1501. determines if it is a foreground or a background color."
  1502. :group 'org-agenda-line-format
  1503. :type '(choice
  1504. (const :tag "Never" nil)
  1505. (const :tag "Defaults" t)
  1506. (const :tag "Cookies only" cookies)
  1507. (repeat :tag "Specify"
  1508. (list (character :tag "Priority" :value ?A)
  1509. (choice :tag "Face "
  1510. (string :tag "Color")
  1511. (sexp :tag "Face"))))))
  1512. (defcustom org-agenda-day-face-function nil
  1513. "Function called to determine what face should be used to display a day.
  1514. The only argument passed to that function is the day. It should
  1515. returns a face, or nil if does not want to specify a face and let
  1516. the normal rules apply."
  1517. :group 'org-agenda-line-format
  1518. :version "24.1"
  1519. :type 'function)
  1520. (defcustom org-agenda-category-icon-alist nil
  1521. "Alist of category icon to be displayed in agenda views.
  1522. Each entry should have the following format:
  1523. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1524. Where CATEGORY-REGEXP is a regexp matching the categories where
  1525. the icon should be displayed.
  1526. FILE-OR-DATA either a file path or a string containing image data.
  1527. The other fields can be omitted safely if not needed:
  1528. TYPE indicates the image type.
  1529. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1530. image data.
  1531. PROPS are additional image attributes to assign to the image,
  1532. like, e.g. `:ascent center'.
  1533. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1534. If you want to set the display properties yourself, just put a
  1535. list as second element:
  1536. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1537. For example, to display a 16px horizontal space for Emacs
  1538. category, you can use:
  1539. (\"Emacs\" '(space . (:width (16))))"
  1540. :group 'org-agenda-line-format
  1541. :version "24.1"
  1542. :type '(alist :key-type (string :tag "Regexp matching category")
  1543. :value-type (choice (list :tag "Icon"
  1544. (string :tag "File or data")
  1545. (symbol :tag "Type")
  1546. (boolean :tag "Data?")
  1547. (repeat :tag "Extra image properties" :inline t symbol))
  1548. (list :tag "Display properties" sexp))))
  1549. (defgroup org-agenda-column-view nil
  1550. "Options concerning column view in the agenda."
  1551. :tag "Org Agenda Column View"
  1552. :group 'org-agenda)
  1553. (defcustom org-agenda-columns-show-summaries t
  1554. "Non-nil means show summaries for columns displayed in the agenda view."
  1555. :group 'org-agenda-column-view
  1556. :type 'boolean)
  1557. (defcustom org-agenda-columns-compute-summary-properties t
  1558. "Non-nil means recompute all summary properties before column view.
  1559. When column view in the agenda is listing properties that have a summary
  1560. operator, it can go to all relevant buffers and recompute the summaries
  1561. there. This can mean overhead for the agenda column view, but is necessary
  1562. to have thing up to date.
  1563. As a special case, a CLOCKSUM property also makes sure that the clock
  1564. computations are current."
  1565. :group 'org-agenda-column-view
  1566. :type 'boolean)
  1567. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1568. "Non-nil means the duration of an appointment will add to day effort.
  1569. The property to which appointment durations will be added is the one given
  1570. in the option `org-effort-property'. If an appointment does not have
  1571. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1572. is not set, an appointment without end time will not contribute to the time
  1573. estimate."
  1574. :group 'org-agenda-column-view
  1575. :type 'boolean)
  1576. (defcustom org-agenda-auto-exclude-function nil
  1577. "A function called with a tag to decide if it is filtered on '/ RET'.
  1578. The sole argument to the function, which is called once for each
  1579. possible tag, is a string giving the name of the tag. The
  1580. function should return either nil if the tag should be included
  1581. as normal, or \"-<TAG>\" to exclude the tag.
  1582. Note that for the purpose of tag filtering, only the lower-case version of
  1583. all tags will be considered, so that this function will only ever see
  1584. the lower-case version of all tags."
  1585. :group 'org-agenda
  1586. :type 'function)
  1587. (defcustom org-agenda-bulk-custom-functions nil
  1588. "Alist of characters and custom functions for bulk actions.
  1589. For example, this value makes those two functions available:
  1590. '((?R set-category)
  1591. (?C bulk-cut))
  1592. With selected entries in an agenda buffer, `B R' will call
  1593. the custom function `set-category' on the selected entries.
  1594. Note that functions in this alist don't need to be quoted."
  1595. :type 'alist
  1596. :version "24.1"
  1597. :group 'org-agenda)
  1598. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1599. "Execute BODY with point at location given by `org-hd-marker' property.
  1600. If STRING is non-nil, the text property will be fetched from position 0
  1601. in that string. If STRING is nil, it will be fetched from the beginning
  1602. of the current line."
  1603. (org-with-gensyms (marker)
  1604. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1605. 'org-hd-marker ,string)))
  1606. (with-current-buffer (marker-buffer ,marker)
  1607. (save-excursion
  1608. (goto-char ,marker)
  1609. ,@body)))))
  1610. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1611. (defun org-add-agenda-custom-command (entry)
  1612. "Replace or add a command in `org-agenda-custom-commands'.
  1613. This is mostly for hacking and trying a new command - once the command
  1614. works you probably want to add it to `org-agenda-custom-commands' for good."
  1615. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1616. (if ass
  1617. (setcdr ass (cdr entry))
  1618. (push entry org-agenda-custom-commands))))
  1619. ;;; Define the org-agenda-mode
  1620. (defvar org-agenda-mode-map (make-sparse-keymap)
  1621. "Keymap for `org-agenda-mode'.")
  1622. (if (fboundp 'defvaralias)
  1623. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1624. (defvar org-agenda-menu) ; defined later in this file.
  1625. (defvar org-agenda-restrict nil) ; defined later in this file.
  1626. (defvar org-agenda-follow-mode nil)
  1627. (defvar org-agenda-entry-text-mode nil)
  1628. (defvar org-agenda-clockreport-mode nil)
  1629. (defvar org-agenda-show-log nil)
  1630. (defvar org-agenda-redo-command nil)
  1631. (defvar org-agenda-query-string nil)
  1632. (defvar org-agenda-mode-hook nil
  1633. "Hook run after `org-agenda-mode' is turned on.
  1634. The buffer is still writable when this hook is called.")
  1635. (defvar org-agenda-type nil)
  1636. (defvar org-agenda-force-single-file nil)
  1637. (defvar org-agenda-bulk-marked-entries nil
  1638. "List of markers that refer to marked entries in the agenda.")
  1639. ;;; Multiple agenda buffers support
  1640. (defcustom org-agenda-sticky nil
  1641. "Non-nil means agenda q key will bury agenda buffers.
  1642. Agenda commands will then show existing buffer instead of generating new ones.
  1643. When nil, `q' will kill the single agenda buffer."
  1644. :group 'org-agenda
  1645. :version "24.3"
  1646. :type 'boolean)
  1647. ;;;###autoload
  1648. (defun org-toggle-sticky-agenda (&optional arg)
  1649. "Toggle `org-agenda-sticky'."
  1650. (interactive "P")
  1651. (let ((new-value (if arg
  1652. (> (prefix-numeric-value arg) 0)
  1653. (not org-agenda-sticky))))
  1654. (if (equal new-value org-agenda-sticky)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was already %s"
  1657. (if org-agenda-sticky "enabled" "disabled")))
  1658. (setq org-agenda-sticky new-value)
  1659. (org-agenda-kill-all-agenda-buffers)
  1660. (and (org-called-interactively-p 'interactive)
  1661. (message "Sticky agenda was %s"
  1662. (if org-agenda-sticky "enabled" "disabled"))))))
  1663. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1664. Toggle `org-agenda-sticky'.
  1665. \(fn &optional ARG)" t nil)
  1666. (defvar org-agenda-buffer nil
  1667. "Agenda buffer currently being generated.")
  1668. (defvar org-agenda-last-prefix-arg nil)
  1669. (defvar org-agenda-this-buffer-name nil)
  1670. (defvar org-agenda-doing-sticky-redo nil)
  1671. (defvar org-agenda-this-buffer-is-sticky nil)
  1672. (defconst org-agenda-local-vars
  1673. '(org-agenda-this-buffer-name
  1674. org-agenda-undo-list
  1675. org-agenda-pending-undo-list
  1676. org-agenda-follow-mode
  1677. org-agenda-entry-text-mode
  1678. org-agenda-clockreport-mode
  1679. org-agenda-show-log
  1680. org-agenda-redo-command
  1681. org-agenda-query-string
  1682. org-agenda-type
  1683. org-agenda-bulk-marked-entries
  1684. org-agenda-undo-has-started-in
  1685. org-agenda-info
  1686. org-agenda-tag-filter-overlays
  1687. org-agenda-cat-filter-overlays
  1688. org-agenda-pre-window-conf
  1689. org-agenda-columns-active
  1690. org-agenda-tag-filter
  1691. org-agenda-category-filter
  1692. org-agenda-markers
  1693. org-agenda-last-search-view-search-was-boolean
  1694. org-agenda-filtered-by-category
  1695. org-agenda-filter-form
  1696. org-agenda-show-window
  1697. org-agenda-cycle-counter
  1698. org-agenda-last-prefix-arg)
  1699. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1700. (defun org-agenda-mode ()
  1701. "Mode for time-sorted view on action items in Org-mode files.
  1702. The following commands are available:
  1703. \\{org-agenda-mode-map}"
  1704. (interactive)
  1705. (cond (org-agenda-doing-sticky-redo
  1706. ;; Refreshing sticky agenda-buffer
  1707. ;;
  1708. ;; Preserve the value of `org-agenda-local-vars' variables,
  1709. ;; while letting `kill-all-local-variables' kill the rest
  1710. (let ((save (buffer-local-variables)))
  1711. (kill-all-local-variables)
  1712. (mapc 'make-local-variable org-agenda-local-vars)
  1713. (dolist (elem save)
  1714. (let ((var (car elem))
  1715. (val (cdr elem)))
  1716. (when (and val
  1717. (member var org-agenda-local-vars))
  1718. (set var val)))))
  1719. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1720. (org-agenda-sticky
  1721. ;; Creating a sticky Agenda buffer for the first time
  1722. (kill-all-local-variables)
  1723. (mapc 'make-local-variable org-agenda-local-vars)
  1724. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1725. (t
  1726. ;; Creating a non-sticky agenda buffer
  1727. (kill-all-local-variables)
  1728. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1729. (setq org-agenda-undo-list nil
  1730. org-agenda-pending-undo-list nil
  1731. org-agenda-bulk-marked-entries nil)
  1732. (setq major-mode 'org-agenda-mode)
  1733. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1734. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1735. (setq mode-name "Org-Agenda")
  1736. (use-local-map org-agenda-mode-map)
  1737. (easy-menu-add org-agenda-menu)
  1738. (if org-startup-truncated (setq truncate-lines t))
  1739. (org-set-local 'line-move-visual nil)
  1740. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1741. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1742. ;; Make sure properties are removed when copying text
  1743. (make-local-variable 'filter-buffer-substring-functions)
  1744. (add-hook 'filter-buffer-substring-functions
  1745. (lambda (fun start end delete)
  1746. (substring-no-properties (funcall fun start end delete))))
  1747. (unless org-agenda-keep-modes
  1748. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1749. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1750. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1751. org-agenda-show-log org-agenda-start-with-log-mode))
  1752. (easy-menu-change
  1753. '("Agenda") "Agenda Files"
  1754. (append
  1755. (list
  1756. (vector
  1757. (if (get 'org-agenda-files 'org-restrict)
  1758. "Restricted to single file"
  1759. "Edit File List")
  1760. '(org-edit-agenda-file-list)
  1761. (not (get 'org-agenda-files 'org-restrict)))
  1762. "--")
  1763. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1764. (org-agenda-set-mode-name)
  1765. (apply
  1766. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1767. (list 'org-agenda-mode-hook)))
  1768. (substitute-key-definition 'undo 'org-agenda-undo
  1769. org-agenda-mode-map global-map)
  1770. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1771. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1772. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1773. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1774. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1775. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1776. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1777. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1778. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1779. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1780. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1781. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1782. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1785. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1786. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1788. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1789. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1791. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1792. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1793. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1794. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1795. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1797. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1798. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1800. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1801. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1802. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1804. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1805. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1806. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1807. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1808. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1810. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1811. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1812. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1813. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1814. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1815. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1816. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1817. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1818. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1819. (while l (org-defkey org-agenda-mode-map
  1820. (int-to-string (pop l)) 'digit-argument)))
  1821. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1822. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1823. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1824. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1825. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1826. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1827. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1828. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1829. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1830. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1831. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1833. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1834. 'org-clock-modify-effort-estimate)
  1835. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1836. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1837. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1838. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1839. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1840. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1841. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1842. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1843. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1844. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1845. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1846. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1847. (substitute-key-definition 'next-line 'org-agenda-next-line
  1848. org-agenda-mode-map global-map)
  1849. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1850. org-agenda-mode-map global-map)
  1851. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1852. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1853. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1854. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1855. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1856. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1857. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1858. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1859. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1860. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1861. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1862. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1863. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1864. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1865. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1866. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1867. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1868. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1869. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1870. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1871. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1872. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1873. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1874. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1875. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1876. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1877. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1878. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1879. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1880. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1881. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1882. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1883. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1884. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1885. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1886. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1887. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1888. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1889. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1890. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1891. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1893. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1894. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1895. (when org-agenda-mouse-1-follows-link
  1896. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1897. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1898. '("Agenda"
  1899. ("Agenda Files")
  1900. "--"
  1901. ("Agenda Dates"
  1902. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1903. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1904. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1905. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1906. "--"
  1907. ("View"
  1908. ["Day View" org-agenda-day-view
  1909. :active (org-agenda-check-type nil 'agenda)
  1910. :style radio :selected (eq org-agenda-current-span 'day)
  1911. :keys "v d (or just d)"]
  1912. ["Week View" org-agenda-week-view
  1913. :active (org-agenda-check-type nil 'agenda)
  1914. :style radio :selected (eq org-agenda-current-span 'week)
  1915. :keys "v w (or just w)"]
  1916. ["Month View" org-agenda-month-view
  1917. :active (org-agenda-check-type nil 'agenda)
  1918. :style radio :selected (eq org-agenda-current-span 'month)
  1919. :keys "v m"]
  1920. ["Year View" org-agenda-year-view
  1921. :active (org-agenda-check-type nil 'agenda)
  1922. :style radio :selected (eq org-agenda-current-span 'year)
  1923. :keys "v y"]
  1924. "--"
  1925. ["Include Diary" org-agenda-toggle-diary
  1926. :style toggle :selected org-agenda-include-diary
  1927. :active (org-agenda-check-type nil 'agenda)]
  1928. ["Include Deadlines" org-agenda-toggle-deadlines
  1929. :style toggle :selected org-agenda-include-deadlines
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. ["Use Time Grid" org-agenda-toggle-time-grid
  1932. :style toggle :selected org-agenda-use-time-grid
  1933. :active (org-agenda-check-type nil 'agenda)]
  1934. "--"
  1935. ["Show clock report" org-agenda-clockreport-mode
  1936. :style toggle :selected org-agenda-clockreport-mode
  1937. :active (org-agenda-check-type nil 'agenda)]
  1938. ["Show some entry text" org-agenda-entry-text-mode
  1939. :style toggle :selected org-agenda-entry-text-mode
  1940. :active t]
  1941. "--"
  1942. ["Show Logbook entries" org-agenda-log-mode
  1943. :style toggle :selected org-agenda-show-log
  1944. :active (org-agenda-check-type nil 'agenda 'timeline)
  1945. :keys "v l (or just l)"]
  1946. ["Include archived trees" org-agenda-archives-mode
  1947. :style toggle :selected org-agenda-archives-mode :active t
  1948. :keys "v a"]
  1949. ["Include archive files" (org-agenda-archives-mode t)
  1950. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1951. :keys "v A"]
  1952. "--"
  1953. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1954. ["Write view to file" org-agenda-write t]
  1955. ["Rebuild buffer" org-agenda-redo t]
  1956. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1957. "--"
  1958. ["Show original entry" org-agenda-show t]
  1959. ["Go To (other window)" org-agenda-goto t]
  1960. ["Go To (this window)" org-agenda-switch-to t]
  1961. ["Capture with cursor date" org-agenda-capture t]
  1962. ["Follow Mode" org-agenda-follow-mode
  1963. :style toggle :selected org-agenda-follow-mode :active t]
  1964. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1965. "--"
  1966. ("TODO"
  1967. ["Cycle TODO" org-agenda-todo t]
  1968. ["Next TODO set" org-agenda-todo-nextset t]
  1969. ["Previous TODO set" org-agenda-todo-previousset t]
  1970. ["Add note" org-agenda-add-note t])
  1971. ("Archive/Refile/Delete"
  1972. ["Archive default" org-agenda-archive-default t]
  1973. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1974. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1975. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1976. ["Archive subtree" org-agenda-archive t]
  1977. "--"
  1978. ["Refile" org-agenda-refile t]
  1979. "--"
  1980. ["Delete subtree" org-agenda-kill t])
  1981. ("Bulk action"
  1982. ["Mark entry" org-agenda-bulk-mark t]
  1983. ["Mark all" org-agenda-bulk-mark-all t]
  1984. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1985. ["Unmark entry" org-agenda-bulk-unmark t]
  1986. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1987. ["Act on all marked" org-agenda-bulk-action t]
  1988. "--"
  1989. ("Tags and Properties"
  1990. ["Show all Tags" org-agenda-show-tags t]
  1991. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1992. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1993. "--"
  1994. ["Column View" org-columns t])
  1995. ("Deadline/Schedule"
  1996. ["Schedule" org-agenda-schedule t]
  1997. ["Set Deadline" org-agenda-deadline t]
  1998. "--"
  1999. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2000. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2001. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2002. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2003. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2004. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2005. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2006. ("Clock and Effort"
  2007. ["Clock in" org-agenda-clock-in t]
  2008. ["Clock out" org-agenda-clock-out t]
  2009. ["Clock cancel" org-agenda-clock-cancel t]
  2010. ["Goto running clock" org-clock-goto t]
  2011. "--"
  2012. ["Set Effort" org-agenda-set-effort t]
  2013. ["Change clocked effort" org-clock-modify-effort-estimate
  2014. (org-clock-is-active)])
  2015. ("Priority"
  2016. ["Set Priority" org-agenda-priority t]
  2017. ["Increase Priority" org-agenda-priority-up t]
  2018. ["Decrease Priority" org-agenda-priority-down t]
  2019. ["Show Priority" org-show-priority t])
  2020. ("Calendar/Diary"
  2021. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2024. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2025. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2026. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2027. "--"
  2028. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2029. "--"
  2030. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2031. "--"
  2032. ("MobileOrg"
  2033. ["Push Files and Views" org-mobile-push t]
  2034. ["Get Captured and Flagged" org-mobile-pull t]
  2035. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2036. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2037. "--"
  2038. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2039. "--"
  2040. ["Quit" org-agenda-quit t]
  2041. ["Exit and Release Buffers" org-agenda-exit t]
  2042. ))
  2043. ;;; Agenda undo
  2044. (defvar org-agenda-allow-remote-undo t
  2045. "Non-nil means allow remote undo from the agenda buffer.")
  2046. (defvar org-agenda-undo-has-started-in nil
  2047. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2048. (defun org-agenda-undo ()
  2049. "Undo a remote editing step in the agenda.
  2050. This undoes changes both in the agenda buffer and in the remote buffer
  2051. that have been changed along."
  2052. (interactive)
  2053. (or org-agenda-allow-remote-undo
  2054. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2055. (if (not (eq this-command last-command))
  2056. (setq org-agenda-undo-has-started-in nil
  2057. org-agenda-pending-undo-list org-agenda-undo-list))
  2058. (if (not org-agenda-pending-undo-list)
  2059. (error "No further undo information"))
  2060. (let* ((entry (pop org-agenda-pending-undo-list))
  2061. buf line cmd rembuf)
  2062. (setq cmd (pop entry) line (pop entry))
  2063. (setq rembuf (nth 2 entry))
  2064. (org-with-remote-undo rembuf
  2065. (while (bufferp (setq buf (pop entry)))
  2066. (if (pop entry)
  2067. (with-current-buffer buf
  2068. (let ((last-undo-buffer buf)
  2069. (inhibit-read-only t))
  2070. (unless (memq buf org-agenda-undo-has-started-in)
  2071. (push buf org-agenda-undo-has-started-in)
  2072. (make-local-variable 'pending-undo-list)
  2073. (undo-start))
  2074. (while (and pending-undo-list
  2075. (listp pending-undo-list)
  2076. (not (car pending-undo-list)))
  2077. (pop pending-undo-list))
  2078. (undo-more 1))))))
  2079. (org-goto-line line)
  2080. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2081. (defun org-verify-change-for-undo (l1 l2)
  2082. "Verify that a real change occurred between the undo lists L1 and L2."
  2083. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2084. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2085. (not (eq l1 l2)))
  2086. ;;; Agenda dispatch
  2087. (defvar org-agenda-restrict-begin (make-marker))
  2088. (defvar org-agenda-restrict-end (make-marker))
  2089. (defvar org-agenda-last-dispatch-buffer nil)
  2090. (defvar org-agenda-overriding-restriction nil)
  2091. (defcustom org-agenda-custom-commands-contexts nil
  2092. "Alist of custom agenda keys and contextual rules.
  2093. For example, if you have a custom agenda command \"p\" and you
  2094. want this command to be accessible only from plain text files,
  2095. use this:
  2096. '((\"p\" (in-file . \"\\.txt\")))
  2097. Here are the available contexts definitions:
  2098. in-file: command displayed only in matching files
  2099. in-mode: command displayed only in matching modes
  2100. not-in-file: command not displayed in matching files
  2101. not-in-mode: command not displayed in matching modes
  2102. [function]: a custom function taking no argument
  2103. If you define several checks, the agenda command will be
  2104. accessible if there is at least one valid check.
  2105. You can also bind a key to another agenda custom command
  2106. depending on contextual rules.
  2107. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2108. Here it means: in .txt files, use \"p\" as the key for the
  2109. agenda command otherwise associated with \"q\". (The command
  2110. originally associated with \"q\" is not displayed to avoid
  2111. duplicates.)"
  2112. :version "24.3"
  2113. :group 'org-agenda-custom-commands
  2114. :type '(repeat (list :tag "Rule"
  2115. (string :tag " Agenda key")
  2116. (string :tag "Replace by command")
  2117. (repeat :tag "Available when"
  2118. (choice
  2119. (cons :tag "Condition"
  2120. (choice
  2121. (const :tag "In file" in-file)
  2122. (const :tag "Not in file" not-in-file)
  2123. (const :tag "In mode" in-mode)
  2124. (const :tag "Not in mode" not-in-mode))
  2125. (regexp))
  2126. (function :tag "Custom function"))))))
  2127. (defvar org-keys nil)
  2128. (defvar org-match nil)
  2129. ;;;###autoload
  2130. (defun org-agenda (&optional arg org-keys restriction)
  2131. "Dispatch agenda commands to collect entries to the agenda buffer.
  2132. Prompts for a command to execute. Any prefix arg will be passed
  2133. on to the selected command. The default selections are:
  2134. a Call `org-agenda-list' to display the agenda for current day or week.
  2135. t Call `org-todo-list' to display the global todo list.
  2136. T Call `org-todo-list' to display the global todo list, select only
  2137. entries with a specific TODO keyword (the user gets a prompt).
  2138. m Call `org-tags-view' to display headlines with tags matching
  2139. a condition (the user is prompted for the condition).
  2140. M Like `m', but select only TODO entries, no ordinary headlines.
  2141. L Create a timeline for the current buffer.
  2142. e Export views to associated files.
  2143. s Search entries for keywords.
  2144. S Search entries for keywords, only with TODO keywords.
  2145. / Multi occur across all agenda files and also files listed
  2146. in `org-agenda-text-search-extra-files'.
  2147. < Restrict agenda commands to buffer, subtree, or region.
  2148. Press several times to get the desired effect.
  2149. > Remove a previous restriction.
  2150. # List \"stuck\" projects.
  2151. ! Configure what \"stuck\" means.
  2152. C Configure custom agenda commands.
  2153. More commands can be added by configuring the variable
  2154. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2155. searches can be pre-defined in this way.
  2156. If the current buffer is in Org-mode and visiting a file, you can also
  2157. first press `<' once to indicate that the agenda should be temporarily
  2158. \(until the next use of \\[org-agenda]) restricted to the current file.
  2159. Pressing `<' twice means to restrict to the current subtree or region
  2160. \(if active)."
  2161. (interactive "P")
  2162. (catch 'exit
  2163. (let* ((prefix-descriptions nil)
  2164. (org-agenda-buffer-name org-agenda-buffer-name)
  2165. (org-agenda-window-setup (if (equal (buffer-name)
  2166. org-agenda-buffer-name)
  2167. 'current-window
  2168. org-agenda-window-setup))
  2169. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2170. (org-agenda-custom-commands
  2171. ;; normalize different versions
  2172. (delq nil
  2173. (mapcar
  2174. (lambda (x)
  2175. (cond ((stringp (cdr x))
  2176. (push x prefix-descriptions)
  2177. nil)
  2178. ((stringp (nth 1 x)) x)
  2179. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2180. (t (cons (car x) (cons "" (cdr x))))))
  2181. org-agenda-custom-commands)))
  2182. (org-agenda-custom-commands
  2183. (org-contextualize-keys
  2184. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2185. (buf (current-buffer))
  2186. (bfn (buffer-file-name (buffer-base-buffer)))
  2187. entry key type org-match lprops ans)
  2188. ;; Turn off restriction unless there is an overriding one,
  2189. (unless org-agenda-overriding-restriction
  2190. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2191. ;; There is a request to keep the file list in place
  2192. (put 'org-agenda-files 'org-restrict nil))
  2193. (setq org-agenda-restrict nil)
  2194. (move-marker org-agenda-restrict-begin nil)
  2195. (move-marker org-agenda-restrict-end nil))
  2196. ;; Delete old local properties
  2197. (put 'org-agenda-redo-command 'org-lprops nil)
  2198. ;; Delete previously set last-arguments
  2199. (put 'org-agenda-redo-command 'last-args nil)
  2200. ;; Remember where this call originated
  2201. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2202. (unless org-keys
  2203. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2204. org-keys (car ans)
  2205. restriction (cdr ans)))
  2206. ;; If we have sticky agenda buffers, set a name for the buffer,
  2207. ;; depending on the invoking keys. The user may still set this
  2208. ;; as a command option, which will overwrite what we do here.
  2209. (if org-agenda-sticky
  2210. (setq org-agenda-buffer-name
  2211. (format "*Org Agenda(%s)*" org-keys)))
  2212. ;; Establish the restriction, if any
  2213. (when (and (not org-agenda-overriding-restriction) restriction)
  2214. (put 'org-agenda-files 'org-restrict (list bfn))
  2215. (cond
  2216. ((eq restriction 'region)
  2217. (setq org-agenda-restrict t)
  2218. (move-marker org-agenda-restrict-begin (region-beginning))
  2219. (move-marker org-agenda-restrict-end (region-end)))
  2220. ((eq restriction 'subtree)
  2221. (save-excursion
  2222. (setq org-agenda-restrict t)
  2223. (org-back-to-heading t)
  2224. (move-marker org-agenda-restrict-begin (point))
  2225. (move-marker org-agenda-restrict-end
  2226. (progn (org-end-of-subtree t)))))))
  2227. ;; For example the todo list should not need it (but does...)
  2228. (cond
  2229. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2230. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2231. (progn
  2232. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2233. lprops (nth 4 entry))
  2234. (if org-agenda-sticky
  2235. (setq org-agenda-buffer-name
  2236. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2237. (format "*Org Agenda(%s)*" org-keys))))
  2238. (put 'org-agenda-redo-command 'org-lprops lprops)
  2239. (cond
  2240. ((eq type 'agenda)
  2241. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2242. ((eq type 'alltodo)
  2243. (org-let lprops '(org-todo-list current-prefix-arg)))
  2244. ((eq type 'search)
  2245. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2246. ((eq type 'stuck)
  2247. (org-let lprops '(org-agenda-list-stuck-projects
  2248. current-prefix-arg)))
  2249. ((eq type 'tags)
  2250. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2251. ((eq type 'tags-todo)
  2252. (org-let lprops '(org-tags-view '(4) org-match)))
  2253. ((eq type 'todo)
  2254. (org-let lprops '(org-todo-list org-match)))
  2255. ((eq type 'tags-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2258. ((eq type 'todo-tree)
  2259. (org-check-for-org-mode)
  2260. (org-let lprops
  2261. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2262. (regexp-quote org-match) "\\>"))))
  2263. ((eq type 'occur-tree)
  2264. (org-check-for-org-mode)
  2265. (org-let lprops '(org-occur org-match)))
  2266. ((functionp type)
  2267. (org-let lprops '(funcall type org-match)))
  2268. ((fboundp type)
  2269. (org-let lprops '(funcall type org-match)))
  2270. (t (error "Invalid custom agenda command type %s" type))))
  2271. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2272. ((equal org-keys "C")
  2273. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2274. (customize-variable 'org-agenda-custom-commands))
  2275. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2276. ((equal org-keys "s") (call-interactively 'org-search-view))
  2277. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2278. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2279. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2280. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2281. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2282. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2283. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2284. (org-add-hook
  2285. 'post-command-hook
  2286. (lambda ()
  2287. (unless (current-message)
  2288. (let* ((m (org-agenda-get-any-marker))
  2289. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2290. (when note
  2291. (message (concat
  2292. "FLAGGING-NOTE ([?] for more info): "
  2293. (org-add-props
  2294. (replace-regexp-in-string
  2295. "\\\\n" "//"
  2296. (copy-sequence note))
  2297. nil 'face 'org-warning)))))))
  2298. t t))
  2299. ((equal org-keys "L")
  2300. (unless (derived-mode-p 'org-mode)
  2301. (error "This is not an Org-mode file"))
  2302. (unless restriction
  2303. (put 'org-agenda-files 'org-restrict (list bfn))
  2304. (org-call-with-arg 'org-timeline arg)))
  2305. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2306. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2307. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2308. (t (error "Invalid agenda key"))))))
  2309. (autoload 'org-agenda "org-agenda" "\
  2310. Dispatch agenda commands to collect entries to the agenda buffer.
  2311. Prompts for a command to execute. Any prefix arg will be passed
  2312. on to the selected command. The default selections are:
  2313. a Call `org-agenda-list' to display the agenda for current day or week.
  2314. t Call `org-todo-list' to display the global todo list.
  2315. T Call `org-todo-list' to display the global todo list, select only
  2316. entries with a specific TODO keyword (the user gets a prompt).
  2317. m Call `org-tags-view' to display headlines with tags matching
  2318. a condition (the user is prompted for the condition).
  2319. M Like `m', but select only TODO entries, no ordinary headlines.
  2320. L Create a timeline for the current buffer.
  2321. e Export views to associated files.
  2322. s Search entries for keywords.
  2323. S Search entries for keywords, only with TODO keywords.
  2324. / Multi occur across all agenda files and also files listed
  2325. in `org-agenda-text-search-extra-files'.
  2326. < Restrict agenda commands to buffer, subtree, or region.
  2327. Press several times to get the desired effect.
  2328. > Remove a previous restriction.
  2329. # List \"stuck\" projects.
  2330. ! Configure what \"stuck\" means.
  2331. C Configure custom agenda commands.
  2332. More commands can be added by configuring the variable
  2333. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2334. searches can be pre-defined in this way.
  2335. If the current buffer is in Org-mode and visiting a file, you can also
  2336. first press `<' once to indicate that the agenda should be temporarily
  2337. \(until the next use of \\[org-agenda]) restricted to the current file.
  2338. Pressing `<' twice means to restrict to the current subtree or region
  2339. \(if active).
  2340. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2341. (defun org-agenda-append-agenda ()
  2342. "Append another agenda view to the current one.
  2343. This function allows interactive building of block agendas.
  2344. Agenda views are separated by `org-agenda-block-separator'."
  2345. (interactive)
  2346. (unless (derived-mode-p 'org-agenda-mode)
  2347. (error "Can only append from within agenda buffer"))
  2348. (let ((org-agenda-multi t))
  2349. (org-agenda)
  2350. (widen)
  2351. (org-agenda-finalize)
  2352. (org-agenda-fit-window-to-buffer)))
  2353. (defun org-agenda-normalize-custom-commands (cmds)
  2354. (delq nil
  2355. (mapcar
  2356. (lambda (x)
  2357. (cond ((stringp (cdr x)) nil)
  2358. ((stringp (nth 1 x)) x)
  2359. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2360. (t (cons (car x) (cons "" (cdr x))))))
  2361. cmds)))
  2362. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2363. "The user interface for selecting an agenda command."
  2364. (catch 'exit
  2365. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2366. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2367. (region-p (org-region-active-p))
  2368. (custom org-agenda-custom-commands)
  2369. (selstring "")
  2370. restriction second-time
  2371. c entry key type match prefixes rmheader header-end custom1 desc
  2372. line lines left right n n1)
  2373. (save-window-excursion
  2374. (delete-other-windows)
  2375. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2376. (erase-buffer)
  2377. (insert (eval-when-compile
  2378. (let ((header
  2379. "Press key for an agenda command: < Buffer, subtree/region restriction
  2380. -------------------------------- > Remove restriction
  2381. a Agenda for current week or day e Export agenda views
  2382. t List of all TODO entries T Entries with special TODO kwd
  2383. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2384. s Search for keywords S Like s, but only TODO entries
  2385. L Timeline for current buffer # List stuck projects (!=configure)
  2386. / Multi-occur C Configure custom agenda commands
  2387. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2388. ")
  2389. (start 0))
  2390. (while (string-match
  2391. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2392. header start)
  2393. (setq start (match-end 0))
  2394. (add-text-properties (match-beginning 2) (match-end 2)
  2395. '(face bold) header))
  2396. header)))
  2397. (setq header-end (move-marker (make-marker) (point)))
  2398. (while t
  2399. (setq custom1 custom)
  2400. (when (eq rmheader t)
  2401. (org-goto-line 1)
  2402. (re-search-forward ":" nil t)
  2403. (delete-region (match-end 0) (point-at-eol))
  2404. (forward-char 1)
  2405. (looking-at "-+")
  2406. (delete-region (match-end 0) (point-at-eol))
  2407. (move-marker header-end (match-end 0)))
  2408. (goto-char header-end)
  2409. (delete-region (point) (point-max))
  2410. ;; Produce all the lines that describe custom commands and prefixes
  2411. (setq lines nil)
  2412. (while (setq entry (pop custom1))
  2413. (setq key (car entry) desc (nth 1 entry)
  2414. type (nth 2 entry)
  2415. match (nth 3 entry))
  2416. (if (> (length key) 1)
  2417. (add-to-list 'prefixes (string-to-char key))
  2418. (setq line
  2419. (format
  2420. "%-4s%-14s"
  2421. (org-add-props (copy-sequence key)
  2422. '(face bold))
  2423. (cond
  2424. ((string-match "\\S-" desc) desc)
  2425. ((eq type 'agenda) "Agenda for current week or day")
  2426. ((eq type 'alltodo) "List of all TODO entries")
  2427. ((eq type 'search) "Word search")
  2428. ((eq type 'stuck) "List of stuck projects")
  2429. ((eq type 'todo) "TODO keyword")
  2430. ((eq type 'tags) "Tags query")
  2431. ((eq type 'tags-todo) "Tags (TODO)")
  2432. ((eq type 'tags-tree) "Tags tree")
  2433. ((eq type 'todo-tree) "TODO kwd tree")
  2434. ((eq type 'occur-tree) "Occur tree")
  2435. ((functionp type) (if (symbolp type)
  2436. (symbol-name type)
  2437. "Lambda expression"))
  2438. (t "???"))))
  2439. (if org-agenda-menu-show-matcher
  2440. (setq line
  2441. (concat line ": "
  2442. (cond
  2443. ((stringp match)
  2444. (setq match (copy-sequence match))
  2445. (org-add-props match nil 'face 'org-warning))
  2446. ((listp type)
  2447. (format "set of %d commands" (length type))))))
  2448. (if (org-string-nw-p match)
  2449. (add-text-properties
  2450. 0 (length line) (list 'help-echo
  2451. (concat "Matcher: " match)) line)))
  2452. (push line lines)))
  2453. (setq lines (nreverse lines))
  2454. (when prefixes
  2455. (mapc (lambda (x)
  2456. (push
  2457. (format "%s %s"
  2458. (org-add-props (char-to-string x)
  2459. nil 'face 'bold)
  2460. (or (cdr (assoc (concat selstring
  2461. (char-to-string x))
  2462. prefix-descriptions))
  2463. "Prefix key"))
  2464. lines))
  2465. prefixes))
  2466. ;; Check if we should display in two columns
  2467. (if org-agenda-menu-two-columns
  2468. (progn
  2469. (setq n (length lines)
  2470. n1 (+ (/ n 2) (mod n 2))
  2471. right (nthcdr n1 lines)
  2472. left (copy-sequence lines))
  2473. (setcdr (nthcdr (1- n1) left) nil))
  2474. (setq left lines right nil))
  2475. (while left
  2476. (insert "\n" (pop left))
  2477. (when right
  2478. (if (< (current-column) 40)
  2479. (move-to-column 40 t)
  2480. (insert " "))
  2481. (insert (pop right))))
  2482. ;; Make the window the right size
  2483. (goto-char (point-min))
  2484. (if second-time
  2485. (if (not (pos-visible-in-window-p (point-max)))
  2486. (org-fit-window-to-buffer))
  2487. (setq second-time t)
  2488. (org-fit-window-to-buffer))
  2489. ;; Ask for selection
  2490. (message "Press key for agenda command%s:"
  2491. (if (or restrict-ok org-agenda-overriding-restriction)
  2492. (if org-agenda-overriding-restriction
  2493. " (restriction lock active)"
  2494. (if restriction
  2495. (format " (restricted to %s)" restriction)
  2496. " (unrestricted)"))
  2497. ""))
  2498. (setq c (read-char-exclusive))
  2499. (message "")
  2500. (cond
  2501. ((assoc (char-to-string c) custom)
  2502. (setq selstring (concat selstring (char-to-string c)))
  2503. (throw 'exit (cons selstring restriction)))
  2504. ((memq c prefixes)
  2505. (setq selstring (concat selstring (char-to-string c))
  2506. prefixes nil
  2507. rmheader (or rmheader t)
  2508. custom (delq nil (mapcar
  2509. (lambda (x)
  2510. (if (or (= (length (car x)) 1)
  2511. (/= (string-to-char (car x)) c))
  2512. nil
  2513. (cons (substring (car x) 1) (cdr x))))
  2514. custom))))
  2515. ((eq c ?*)
  2516. (call-interactively 'org-toggle-sticky-agenda)
  2517. (sit-for 2))
  2518. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2519. (message "Restriction is only possible in Org-mode buffers")
  2520. (ding) (sit-for 1))
  2521. ((eq c ?1)
  2522. (org-agenda-remove-restriction-lock 'noupdate)
  2523. (setq restriction 'buffer))
  2524. ((eq c ?0)
  2525. (org-agenda-remove-restriction-lock 'noupdate)
  2526. (setq restriction (if region-p 'region 'subtree)))
  2527. ((eq c ?<)
  2528. (org-agenda-remove-restriction-lock 'noupdate)
  2529. (setq restriction
  2530. (cond
  2531. ((eq restriction 'buffer)
  2532. (if region-p 'region 'subtree))
  2533. ((memq restriction '(subtree region))
  2534. nil)
  2535. (t 'buffer))))
  2536. ((eq c ?>)
  2537. (org-agenda-remove-restriction-lock 'noupdate)
  2538. (setq restriction nil))
  2539. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2540. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2541. ((and (> (length selstring) 0) (eq c ?\d))
  2542. (delete-window)
  2543. (org-agenda-get-restriction-and-command prefix-descriptions))
  2544. ((equal c ?q) (error "Abort"))
  2545. (t (error "Invalid key %c" c))))))))
  2546. (defun org-agenda-fit-window-to-buffer ()
  2547. "Fit the window to the buffer size."
  2548. (and (memq org-agenda-window-setup '(reorganize-frame))
  2549. (fboundp 'fit-window-to-buffer)
  2550. (org-fit-window-to-buffer
  2551. nil
  2552. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2553. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2554. (defvar org-cmd nil)
  2555. (defvar org-agenda-overriding-cmd nil)
  2556. (defvar org-agenda-overriding-arguments nil)
  2557. (defvar org-agenda-overriding-cmd-arguments nil)
  2558. (defun org-agenda-run-series (name series)
  2559. (org-let (nth 1 series) '(org-agenda-prepare name))
  2560. ;; We need to reset agenda markers here, because when constructing a
  2561. ;; block agenda, the individual blocks do not do that.
  2562. (org-agenda-reset-markers)
  2563. (let* ((org-agenda-multi t)
  2564. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2565. (cmds (car series))
  2566. (gprops (nth 1 series))
  2567. match ;; The byte compiler incorrectly complains about this. Keep it!
  2568. org-cmd type lprops)
  2569. (while (setq org-cmd (pop cmds))
  2570. (setq type (car org-cmd)
  2571. match (eval (nth 1 org-cmd))
  2572. lprops (nth 2 org-cmd))
  2573. (let ((org-agenda-overriding-arguments
  2574. (if (eq org-agenda-overriding-cmd org-cmd)
  2575. (or org-agenda-overriding-arguments
  2576. org-agenda-overriding-cmd-arguments))))
  2577. (cond
  2578. ((eq type 'agenda)
  2579. (org-let2 gprops lprops
  2580. '(call-interactively 'org-agenda-list)))
  2581. ((eq type 'alltodo)
  2582. (org-let2 gprops lprops
  2583. '(call-interactively 'org-todo-list)))
  2584. ((eq type 'search)
  2585. (org-let2 gprops lprops
  2586. '(org-search-view current-prefix-arg match nil)))
  2587. ((eq type 'stuck)
  2588. (org-let2 gprops lprops
  2589. '(call-interactively 'org-agenda-list-stuck-projects)))
  2590. ((eq type 'tags)
  2591. (org-let2 gprops lprops
  2592. '(org-tags-view current-prefix-arg match)))
  2593. ((eq type 'tags-todo)
  2594. (org-let2 gprops lprops
  2595. '(org-tags-view '(4) match)))
  2596. ((eq type 'todo)
  2597. (org-let2 gprops lprops
  2598. '(org-todo-list match)))
  2599. ((fboundp type)
  2600. (org-let2 gprops lprops
  2601. '(funcall type match)))
  2602. (t (error "Invalid type in command series")))))
  2603. (widen)
  2604. (let ((inhibit-read-only t))
  2605. (add-text-properties (point-min) (point-max)
  2606. `(org-serie t org-serie-redo-cmd ,redo)))
  2607. (setq org-agenda-redo-command redo)
  2608. (goto-char (point-min)))
  2609. (org-agenda-fit-window-to-buffer)
  2610. (org-let (nth 1 series) '(org-agenda-finalize)))
  2611. ;;;###autoload
  2612. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2613. "Run an agenda command in batch mode and send the result to STDOUT.
  2614. If CMD-KEY is a string of length 1, it is used as a key in
  2615. `org-agenda-custom-commands' and triggers this command. If it is a
  2616. longer string it is used as a tags/todo match string.
  2617. Parameters are alternating variable names and values that will be bound
  2618. before running the agenda command."
  2619. (org-eval-in-environment (org-make-parameter-alist parameters)
  2620. (if (> (length cmd-key) 2)
  2621. (org-tags-view nil cmd-key)
  2622. (org-agenda nil cmd-key)))
  2623. (set-buffer org-agenda-buffer-name)
  2624. (princ (buffer-string)))
  2625. (autoload 'org-batch-agenda "org-agenda" "\
  2626. Run an agenda command in batch mode and send the result to STDOUT.
  2627. If CMD-KEY is a string of length 1, it is used as a key in
  2628. `org-agenda-custom-commands' and triggers this command. If it is a
  2629. longer string it is used as a tags/todo match string.
  2630. Parameters are alternating variable names and values that will be bound
  2631. before running the agenda command.
  2632. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2633. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2634. (defvar org-agenda-info nil)
  2635. ;;;###autoload
  2636. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2637. "Run an agenda command in batch mode and send the result to STDOUT.
  2638. If CMD-KEY is a string of length 1, it is used as a key in
  2639. `org-agenda-custom-commands' and triggers this command. If it is a
  2640. longer string it is used as a tags/todo match string.
  2641. Parameters are alternating variable names and values that will be bound
  2642. before running the agenda command.
  2643. The output gives a line for each selected agenda item. Each
  2644. item is a list of comma-separated values, like this:
  2645. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2646. category The category of the item
  2647. head The headline, without TODO kwd, TAGS and PRIORITY
  2648. type The type of the agenda entry, can be
  2649. todo selected in TODO match
  2650. tagsmatch selected in tags match
  2651. diary imported from diary
  2652. deadline a deadline on given date
  2653. scheduled scheduled on given date
  2654. timestamp entry has timestamp on given date
  2655. closed entry was closed on given date
  2656. upcoming-deadline warning about deadline
  2657. past-scheduled forwarded scheduled item
  2658. block entry has date block including g. date
  2659. todo The todo keyword, if any
  2660. tags All tags including inherited ones, separated by colons
  2661. date The relevant date, like 2007-2-14
  2662. time The time, like 15:00-16:50
  2663. extra Sting with extra planning info
  2664. priority-l The priority letter if any was given
  2665. priority-n The computed numerical priority
  2666. agenda-day The day in the agenda where this is listed"
  2667. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2668. (org-make-parameter-alist parameters))
  2669. (if (> (length cmd-key) 2)
  2670. (org-tags-view nil cmd-key)
  2671. (org-agenda nil cmd-key)))
  2672. (set-buffer org-agenda-buffer-name)
  2673. (let* ((lines (org-split-string (buffer-string) "\n"))
  2674. line)
  2675. (while (setq line (pop lines))
  2676. (catch 'next
  2677. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2678. (setq org-agenda-info
  2679. (org-fix-agenda-info (text-properties-at 0 line)))
  2680. (princ
  2681. (mapconcat 'org-agenda-export-csv-mapper
  2682. '(org-category txt type todo tags date time extra
  2683. priority-letter priority agenda-day)
  2684. ","))
  2685. (princ "\n")))))
  2686. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2687. Run an agenda command in batch mode and send the result to STDOUT.
  2688. If CMD-KEY is a string of length 1, it is used as a key in
  2689. `org-agenda-custom-commands' and triggers this command. If it is a
  2690. longer string it is used as a tags/todo match string.
  2691. Parameters are alternating variable names and values that will be bound
  2692. before running the agenda command.
  2693. The output gives a line for each selected agenda item. Each
  2694. item is a list of comma-separated values, like this:
  2695. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2696. category The category of the item
  2697. head The headline, without TODO kwd, TAGS and PRIORITY
  2698. type The type of the agenda entry, can be
  2699. todo selected in TODO match
  2700. tagsmatch selected in tags match
  2701. diary imported from diary
  2702. deadline a deadline on given date
  2703. scheduled scheduled on given date
  2704. timestamp entry has timestamp on given date
  2705. closed entry was closed on given date
  2706. upcoming-deadline warning about deadline
  2707. past-scheduled forwarded scheduled item
  2708. block entry has date block including g. date
  2709. todo The todo keyword, if any
  2710. tags All tags including inherited ones, separated by colons
  2711. date The relevant date, like 2007-2-14
  2712. time The time, like 15:00-16:50
  2713. extra Sting with extra planning info
  2714. priority-l The priority letter if any was given
  2715. priority-n The computed numerical priority
  2716. agenda-day The day in the agenda where this is listed
  2717. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2718. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2719. (defun org-fix-agenda-info (props)
  2720. "Make sure all properties on an agenda item have a canonical form.
  2721. This ensures the export commands can easily use it."
  2722. (let (tmp re)
  2723. (when (setq tmp (plist-get props 'tags))
  2724. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2725. (when (setq tmp (plist-get props 'date))
  2726. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2727. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2728. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2729. (setq tmp (calendar-date-string tmp)))
  2730. (setq props (plist-put props 'date tmp)))
  2731. (when (setq tmp (plist-get props 'day))
  2732. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2733. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2734. (setq tmp (calendar-date-string tmp)))
  2735. (setq props (plist-put props 'day tmp))
  2736. (setq props (plist-put props 'agenda-day tmp)))
  2737. (when (setq tmp (plist-get props 'txt))
  2738. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2739. (plist-put props 'priority-letter (match-string 1 tmp))
  2740. (setq tmp (replace-match "" t t tmp)))
  2741. (when (and (setq re (plist-get props 'org-todo-regexp))
  2742. (setq re (concat "\\`\\.*" re " ?"))
  2743. (string-match re tmp))
  2744. (plist-put props 'todo (match-string 1 tmp))
  2745. (setq tmp (replace-match "" t t tmp)))
  2746. (plist-put props 'txt tmp)))
  2747. props)
  2748. (defun org-agenda-export-csv-mapper (prop)
  2749. (let ((res (plist-get org-agenda-info prop)))
  2750. (setq res
  2751. (cond
  2752. ((not res) "")
  2753. ((stringp res) res)
  2754. (t (prin1-to-string res))))
  2755. (while (string-match "," res)
  2756. (setq res (replace-match ";" t t res)))
  2757. (org-trim res)))
  2758. ;;;###autoload
  2759. (defun org-store-agenda-views (&rest parameters)
  2760. (interactive)
  2761. (eval (list 'org-batch-store-agenda-views)))
  2762. (autoload 'org-store-agenda-views "org-agenda" "\
  2763. \(fn &rest PARAMETERS)" t nil)
  2764. ;;;###autoload
  2765. (defmacro org-batch-store-agenda-views (&rest parameters)
  2766. "Run all custom agenda commands that have a file argument."
  2767. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2768. (pop-up-frames nil)
  2769. (dir default-directory)
  2770. (pars (org-make-parameter-alist parameters))
  2771. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2772. (save-window-excursion
  2773. (while cmds
  2774. (setq cmd (pop cmds)
  2775. thiscmdkey (car cmd)
  2776. thiscmdcmd (cdr cmd)
  2777. match (nth 2 thiscmdcmd)
  2778. bufname (if org-agenda-sticky
  2779. (or (and (stringp match)
  2780. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2781. (format "*Org Agenda(%s)*" thiscmdkey))
  2782. org-agenda-buffer-name)
  2783. cmd-or-set (nth 2 cmd)
  2784. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2785. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2786. (if (stringp files) (setq files (list files)))
  2787. (when files
  2788. (org-eval-in-environment (append org-agenda-exporter-settings
  2789. opts pars)
  2790. (org-agenda nil thiscmdkey))
  2791. (set-buffer bufname)
  2792. (while files
  2793. (org-eval-in-environment (append org-agenda-exporter-settings
  2794. opts pars)
  2795. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2796. (and (get-buffer bufname)
  2797. (kill-buffer bufname)))))))
  2798. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2799. Run all custom agenda commands that have a file argument.
  2800. \(fn &rest PARAMETERS)" nil t)
  2801. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2802. (defvar org-agenda-current-span nil
  2803. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2804. (defun org-agenda-mark-header-line (pos)
  2805. "Mark the line at POS as an agenda structure header."
  2806. (save-excursion
  2807. (goto-char pos)
  2808. (put-text-property (point-at-bol) (point-at-eol)
  2809. 'org-agenda-structural-header t)
  2810. (when org-agenda-title-append
  2811. (put-text-property (point-at-bol) (point-at-eol)
  2812. 'org-agenda-title-append org-agenda-title-append))))
  2813. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2814. (defvar org-agenda-write-buffer-name "Agenda View")
  2815. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2816. "Write the current buffer (an agenda view) as a file.
  2817. Depending on the extension of the file name, plain text (.txt),
  2818. HTML (.html or .htm) or Postscript (.ps) is produced.
  2819. If the extension is .ics, run icalendar export over all files used
  2820. to construct the agenda and limit the export to entries listed in the
  2821. agenda now.
  2822. With prefix argument OPEN, open the new file immediately.
  2823. If NOSETTINGS is given, do not scope the settings of
  2824. `org-agenda-exporter-settings' into the export commands. This is used when
  2825. the settings have already been scoped and we do not wish to overrule other,
  2826. higher priority settings.
  2827. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2828. (interactive "FWrite agenda to file: \nP")
  2829. (if (not (file-writable-p file))
  2830. (error "Cannot write agenda to file %s" file))
  2831. (org-let (if nosettings nil org-agenda-exporter-settings)
  2832. '(save-excursion
  2833. (save-window-excursion
  2834. (org-agenda-mark-filtered-text)
  2835. (let ((bs (copy-sequence (buffer-string))) beg)
  2836. (org-agenda-unmark-filtered-text)
  2837. (with-temp-buffer
  2838. (rename-buffer org-agenda-write-buffer-name t)
  2839. (set-buffer-modified-p nil)
  2840. (insert bs)
  2841. (org-agenda-remove-marked-text 'org-filtered)
  2842. (while (setq beg (text-property-any (point-min) (point-max)
  2843. 'org-filtered t))
  2844. (delete-region
  2845. beg (or (next-single-property-change beg 'org-filtered)
  2846. (point-max))))
  2847. (run-hooks 'org-agenda-before-write-hook)
  2848. (cond
  2849. ((org-bound-and-true-p org-mobile-creating-agendas)
  2850. (org-mobile-write-agenda-for-mobile file))
  2851. ((string-match "\\.html?\\'" file)
  2852. (require 'htmlize)
  2853. (set-buffer (htmlize-buffer (current-buffer)))
  2854. (when org-agenda-export-html-style
  2855. ;; replace <style> section with org-agenda-export-html-style
  2856. (goto-char (point-min))
  2857. (kill-region (- (search-forward "<style") 6)
  2858. (search-forward "</style>"))
  2859. (insert org-agenda-export-html-style))
  2860. (write-file file)
  2861. (kill-buffer (current-buffer))
  2862. (message "HTML written to %s" file))
  2863. ((string-match "\\.ps\\'" file)
  2864. (require 'ps-print)
  2865. (ps-print-buffer-with-faces file)
  2866. (message "Postscript written to %s" file))
  2867. ((string-match "\\.pdf\\'" file)
  2868. (require 'ps-print)
  2869. (ps-print-buffer-with-faces
  2870. (concat (file-name-sans-extension file) ".ps"))
  2871. (call-process "ps2pdf" nil nil nil
  2872. (expand-file-name
  2873. (concat (file-name-sans-extension file) ".ps"))
  2874. (expand-file-name file))
  2875. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2876. (message "PDF written to %s" file))
  2877. ((string-match "\\.ics\\'" file)
  2878. (require 'org-icalendar)
  2879. (let ((org-agenda-marker-table
  2880. (org-create-marker-find-array
  2881. (org-agenda-collect-markers)))
  2882. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2883. (org-combined-agenda-icalendar-file file))
  2884. (apply 'org-export-icalendar 'combine
  2885. (org-agenda-files nil 'ifmode))))
  2886. (t
  2887. (let ((bs (buffer-string)))
  2888. (find-file file)
  2889. (erase-buffer)
  2890. (insert bs)
  2891. (save-buffer 0)
  2892. (kill-buffer (current-buffer))
  2893. (message "Plain text written to %s" file))))))))
  2894. (set-buffer (or agenda-bufname
  2895. (and (called-interactively-p 'any) (buffer-name))
  2896. org-agenda-buffer-name)))
  2897. (when open (org-open-file file)))
  2898. (defvar org-agenda-tag-filter-overlays nil)
  2899. (defvar org-agenda-cat-filter-overlays nil)
  2900. (defun org-agenda-mark-filtered-text ()
  2901. "Mark all text hidden by filtering with a text property."
  2902. (let ((inhibit-read-only t))
  2903. (mapc
  2904. (lambda (o)
  2905. (when (equal (overlay-buffer o) (current-buffer))
  2906. (put-text-property
  2907. (overlay-start o) (overlay-end o)
  2908. 'org-filtered t)))
  2909. (append org-agenda-tag-filter-overlays
  2910. org-agenda-cat-filter-overlays))))
  2911. (defun org-agenda-unmark-filtered-text ()
  2912. "Remove the filtering text property."
  2913. (let ((inhibit-read-only t))
  2914. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2915. (defun org-agenda-remove-marked-text (property &optional value)
  2916. "Delete all text marked with VALUE of PROPERTY.
  2917. VALUE defaults to t."
  2918. (let (beg)
  2919. (setq value (or value t))
  2920. (while (setq beg (text-property-any (point-min) (point-max)
  2921. property value))
  2922. (delete-region
  2923. beg (or (next-single-property-change beg 'org-filtered)
  2924. (point-max))))))
  2925. (defun org-agenda-add-entry-text ()
  2926. "Add entry text to agenda lines.
  2927. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2928. entry text following headings shown in the agenda.
  2929. Drawers will be excluded, also the line with scheduling/deadline info."
  2930. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2931. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2932. (let (m txt)
  2933. (goto-char (point-min))
  2934. (while (not (eobp))
  2935. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2936. (beginning-of-line 2)
  2937. (setq txt (org-agenda-get-some-entry-text
  2938. m org-agenda-add-entry-text-maxlines " > "))
  2939. (end-of-line 1)
  2940. (if (string-match "\\S-" txt)
  2941. (insert "\n" txt)
  2942. (or (eobp) (forward-char 1))))))))
  2943. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2944. &rest keep)
  2945. "Extract entry text from MARKER, at most N-LINES lines.
  2946. This will ignore drawers etc, just get the text.
  2947. If INDENT is given, prefix every line with this string. If KEEP is
  2948. given, it is a list of symbols, defining stuff that should not be
  2949. removed from the entry content. Currently only `planning' is allowed here."
  2950. (let (txt drawer-re kwd-time-re ind)
  2951. (save-excursion
  2952. (with-current-buffer (marker-buffer marker)
  2953. (if (not (derived-mode-p 'org-mode))
  2954. (setq txt "")
  2955. (save-excursion
  2956. (save-restriction
  2957. (widen)
  2958. (goto-char marker)
  2959. (end-of-line 1)
  2960. (setq txt (buffer-substring
  2961. (min (1+ (point)) (point-max))
  2962. (progn (outline-next-heading) (point)))
  2963. drawer-re org-drawer-regexp
  2964. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2965. ".*\n?"))
  2966. (with-temp-buffer
  2967. (insert txt)
  2968. (when org-agenda-add-entry-text-descriptive-links
  2969. (goto-char (point-min))
  2970. (while (org-activate-bracket-links (point-max))
  2971. (add-text-properties (match-beginning 0) (match-end 0)
  2972. '(face org-link))))
  2973. (goto-char (point-min))
  2974. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2975. (set-text-properties (match-beginning 0) (match-end 0)
  2976. nil))
  2977. (goto-char (point-min))
  2978. (while (re-search-forward drawer-re nil t)
  2979. (delete-region
  2980. (match-beginning 0)
  2981. (progn (re-search-forward
  2982. "^[ \t]*:END:.*\n?" nil 'move)
  2983. (point))))
  2984. (unless (member 'planning keep)
  2985. (goto-char (point-min))
  2986. (while (re-search-forward kwd-time-re nil t)
  2987. (replace-match "")))
  2988. (goto-char (point-min))
  2989. (when org-agenda-entry-text-exclude-regexps
  2990. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2991. (while (setq re (pop re-list))
  2992. (goto-char (point-min))
  2993. (while (re-search-forward re nil t)
  2994. (replace-match "")))))
  2995. (goto-char (point-max))
  2996. (skip-chars-backward " \t\n")
  2997. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2998. ;; find and remove min common indentation
  2999. (goto-char (point-min))
  3000. (untabify (point-min) (point-max))
  3001. (setq ind (org-get-indentation))
  3002. (while (not (eobp))
  3003. (unless (looking-at "[ \t]*$")
  3004. (setq ind (min ind (org-get-indentation))))
  3005. (beginning-of-line 2))
  3006. (goto-char (point-min))
  3007. (while (not (eobp))
  3008. (unless (looking-at "[ \t]*$")
  3009. (move-to-column ind)
  3010. (delete-region (point-at-bol) (point)))
  3011. (beginning-of-line 2))
  3012. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3013. (goto-char (point-min))
  3014. (when indent
  3015. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3016. (replace-match indent t t)))
  3017. (goto-char (point-min))
  3018. (while (looking-at "[ \t]*\n") (replace-match ""))
  3019. (goto-char (point-max))
  3020. (when (> (org-current-line)
  3021. n-lines)
  3022. (org-goto-line (1+ n-lines))
  3023. (backward-char 1))
  3024. (setq txt (buffer-substring (point-min) (point)))))))))
  3025. txt))
  3026. (defun org-agenda-collect-markers ()
  3027. "Collect the markers pointing to entries in the agenda buffer."
  3028. (let (m markers)
  3029. (save-excursion
  3030. (goto-char (point-min))
  3031. (while (not (eobp))
  3032. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3033. (org-get-at-bol 'org-marker)))
  3034. (push m markers))
  3035. (beginning-of-line 2)))
  3036. (nreverse markers)))
  3037. (defun org-create-marker-find-array (marker-list)
  3038. "Create a alist of files names with all marker positions in that file."
  3039. (let (f tbl m a p)
  3040. (while (setq m (pop marker-list))
  3041. (setq p (marker-position m)
  3042. f (buffer-file-name (or (buffer-base-buffer
  3043. (marker-buffer m))
  3044. (marker-buffer m))))
  3045. (if (setq a (assoc f tbl))
  3046. (push (marker-position m) (cdr a))
  3047. (push (list f p) tbl)))
  3048. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3049. tbl)))
  3050. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3051. (defun org-check-agenda-marker-table ()
  3052. "Check of the current entry is on the marker list."
  3053. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3054. a)
  3055. (and (setq a (assoc file org-agenda-marker-table))
  3056. (save-match-data
  3057. (save-excursion
  3058. (org-back-to-heading t)
  3059. (member (point) (cdr a)))))))
  3060. (defun org-check-for-org-mode ()
  3061. "Make sure current buffer is in org-mode. Error if not."
  3062. (or (derived-mode-p 'org-mode)
  3063. (error "Cannot execute org-mode agenda command on buffer in %s"
  3064. major-mode)))
  3065. ;;; Agenda prepare and finalize
  3066. (defvar org-agenda-multi nil) ; dynamically scoped
  3067. (defvar org-agenda-pre-window-conf nil)
  3068. (defvar org-agenda-columns-active nil)
  3069. (defvar org-agenda-name nil)
  3070. (defvar org-agenda-tag-filter nil)
  3071. (defvar org-agenda-category-filter nil)
  3072. (defvar org-agenda-top-category-filter nil)
  3073. (defvar org-agenda-tag-filter-while-redo nil)
  3074. (defvar org-agenda-tag-filter-preset nil
  3075. "A preset of the tags filter used for secondary agenda filtering.
  3076. This must be a list of strings, each string must be a single tag preceded
  3077. by \"+\" or \"-\".
  3078. This variable should not be set directly, but agenda custom commands can
  3079. bind it in the options section. The preset filter is a global property of
  3080. the entire agenda view. In a block agenda, it will not work reliably to
  3081. define a filter for one of the individual blocks. You need to set it in
  3082. the global options and expect it to be applied to the entire view.")
  3083. (defvar org-agenda-category-filter-preset nil
  3084. "A preset of the category filter used for secondary agenda filtering.
  3085. This must be a list of strings, each string must be a single category
  3086. preceded by \"+\" or \"-\".
  3087. This variable should not be set directly, but agenda custom commands can
  3088. bind it in the options section. The preset filter is a global property of
  3089. the entire agenda view. In a block agenda, it will not work reliably to
  3090. define a filter for one of the individual blocks. You need to set it in
  3091. the global options and expect it to be applied to the entire view.")
  3092. (defun org-agenda-use-sticky-p ()
  3093. "Return non-nil if an agenda buffer named
  3094. `org-agenda-buffer-name' exists and should be shown instead of
  3095. generating a new one."
  3096. (and
  3097. ;; turned off by user
  3098. org-agenda-sticky
  3099. ;; For multi-agenda buffer already exists
  3100. (not org-agenda-multi)
  3101. ;; buffer found
  3102. (get-buffer org-agenda-buffer-name)
  3103. ;; C-u parameter is same as last call
  3104. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3105. (and
  3106. (equal current-prefix-arg
  3107. org-agenda-last-prefix-arg)
  3108. ;; In case user turned stickiness on, while having existing
  3109. ;; Agenda buffer active, don't reuse that buffer, because it
  3110. ;; does not have org variables local
  3111. org-agenda-this-buffer-is-sticky))))
  3112. (defun org-agenda-prepare-window (abuf)
  3113. "Setup agenda buffer in the window."
  3114. (let* ((awin (get-buffer-window abuf))
  3115. wconf)
  3116. (cond
  3117. ((equal (current-buffer) abuf) nil)
  3118. (awin (select-window awin))
  3119. ((not (setq wconf (current-window-configuration))))
  3120. ((equal org-agenda-window-setup 'current-window)
  3121. (org-pop-to-buffer-same-window abuf))
  3122. ((equal org-agenda-window-setup 'other-window)
  3123. (org-switch-to-buffer-other-window abuf))
  3124. ((equal org-agenda-window-setup 'other-frame)
  3125. (switch-to-buffer-other-frame abuf))
  3126. ((equal org-agenda-window-setup 'reorganize-frame)
  3127. (delete-other-windows)
  3128. (org-switch-to-buffer-other-window abuf)))
  3129. ;; additional test in case agenda is invoked from within agenda
  3130. ;; buffer via elisp link
  3131. (unless (equal (current-buffer) abuf)
  3132. (org-pop-to-buffer-same-window abuf))
  3133. (setq org-agenda-pre-window-conf
  3134. (or org-agenda-pre-window-conf wconf))))
  3135. (defun org-agenda-prepare (&optional name)
  3136. (if (org-agenda-use-sticky-p)
  3137. (progn
  3138. ;; Popup existing buffer
  3139. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3140. (message "Sticky Agenda buffer, use `r' to refresh")
  3141. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3142. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3143. (setq org-todo-keywords-for-agenda nil)
  3144. (setq org-drawers-for-agenda nil)
  3145. (unless org-agenda-persistent-filter
  3146. (setq org-agenda-tag-filter nil
  3147. org-agenda-category-filter nil))
  3148. (put 'org-agenda-tag-filter :preset-filter
  3149. org-agenda-tag-filter-preset)
  3150. (put 'org-agenda-category-filter :preset-filter
  3151. org-agenda-category-filter-preset)
  3152. (if org-agenda-multi
  3153. (progn
  3154. (setq buffer-read-only nil)
  3155. (goto-char (point-max))
  3156. (unless (or (bobp) org-agenda-compact-blocks
  3157. (not org-agenda-block-separator))
  3158. (insert "\n"
  3159. (if (stringp org-agenda-block-separator)
  3160. org-agenda-block-separator
  3161. (make-string (window-width) org-agenda-block-separator))
  3162. "\n"))
  3163. (narrow-to-region (point) (point-max)))
  3164. (setq org-done-keywords-for-agenda nil)
  3165. ;; Setting any org variables that are in org-agenda-local-vars
  3166. ;; list need to be done after the prepare call
  3167. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3168. (setq buffer-read-only nil)
  3169. (org-agenda-reset-markers)
  3170. (let ((inhibit-read-only t)) (erase-buffer))
  3171. (org-agenda-mode)
  3172. (setq org-agenda-buffer (current-buffer))
  3173. (setq org-agenda-contributing-files nil)
  3174. (setq org-agenda-columns-active nil)
  3175. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3176. (setq org-todo-keywords-for-agenda
  3177. (org-uniquify org-todo-keywords-for-agenda))
  3178. (setq org-done-keywords-for-agenda
  3179. (org-uniquify org-done-keywords-for-agenda))
  3180. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3181. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3182. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3183. (and name (not org-agenda-name)
  3184. (org-set-local 'org-agenda-name name)))
  3185. (setq buffer-read-only nil)))
  3186. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3187. (defun org-agenda-finalize ()
  3188. "Finishing touch for the agenda buffer, called just before displaying it."
  3189. (unless org-agenda-multi
  3190. (save-excursion
  3191. (let ((inhibit-read-only t))
  3192. (goto-char (point-min))
  3193. (while (org-activate-bracket-links (point-max))
  3194. (add-text-properties (match-beginning 0) (match-end 0)
  3195. '(face org-link)))
  3196. (org-agenda-align-tags)
  3197. (unless org-agenda-with-colors
  3198. (remove-text-properties (point-min) (point-max) '(face nil))))
  3199. (if (and (boundp 'org-agenda-overriding-columns-format)
  3200. org-agenda-overriding-columns-format)
  3201. (org-set-local 'org-agenda-overriding-columns-format
  3202. org-agenda-overriding-columns-format))
  3203. (if (and (boundp 'org-agenda-view-columns-initially)
  3204. org-agenda-view-columns-initially)
  3205. (org-agenda-columns))
  3206. (when org-agenda-fontify-priorities
  3207. (org-agenda-fontify-priorities))
  3208. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3209. (org-agenda-dim-blocked-tasks))
  3210. (org-agenda-mark-clocking-task)
  3211. (when org-agenda-entry-text-mode
  3212. (org-agenda-entry-text-hide)
  3213. (org-agenda-entry-text-show))
  3214. (if (functionp 'org-habit-insert-consistency-graphs)
  3215. (org-habit-insert-consistency-graphs))
  3216. (let ((inhibit-read-only t))
  3217. (run-hooks 'org-agenda-finalize-hook))
  3218. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3219. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3220. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3221. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3222. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3223. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3224. (defun org-agenda-mark-clocking-task ()
  3225. "Mark the current clock entry in the agenda if it is present."
  3226. (mapc (lambda (o)
  3227. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3228. (delete-overlay o)))
  3229. (overlays-in (point-min) (point-max)))
  3230. (when (marker-buffer org-clock-hd-marker)
  3231. (save-excursion
  3232. (goto-char (point-min))
  3233. (let (s ov)
  3234. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3235. (goto-char s)
  3236. (when (equal (org-get-at-bol 'org-hd-marker)
  3237. org-clock-hd-marker)
  3238. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3239. (overlay-put ov 'type 'org-agenda-clocking)
  3240. (overlay-put ov 'face 'org-agenda-clocking)
  3241. (overlay-put ov 'help-echo
  3242. "The clock is running in this item")))))))
  3243. (defun org-agenda-fontify-priorities ()
  3244. "Make highest priority lines bold, and lowest italic."
  3245. (interactive)
  3246. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3247. (delete-overlay o)))
  3248. (overlays-in (point-min) (point-max)))
  3249. (save-excursion
  3250. (let ((inhibit-read-only t)
  3251. b e p ov h l)
  3252. (goto-char (point-min))
  3253. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3254. (setq h (or (get-char-property (point) 'org-highest-priority)
  3255. org-highest-priority)
  3256. l (or (get-char-property (point) 'org-lowest-priority)
  3257. org-lowest-priority)
  3258. p (string-to-char (match-string 1))
  3259. b (match-beginning 0)
  3260. e (if (eq org-agenda-fontify-priorities 'cookies)
  3261. (match-end 0)
  3262. (point-at-eol))
  3263. ov (make-overlay b e))
  3264. (overlay-put
  3265. ov 'face
  3266. (cond ((org-face-from-face-or-color
  3267. 'priority nil
  3268. (cdr (assoc p org-priority-faces))))
  3269. ((and (listp org-agenda-fontify-priorities)
  3270. (org-face-from-face-or-color
  3271. 'priority nil
  3272. (cdr (assoc p org-agenda-fontify-priorities)))))
  3273. ((equal p l) 'italic)
  3274. ((equal p h) 'bold)))
  3275. (overlay-put ov 'org-type 'org-priority)))))
  3276. (defun org-agenda-dim-blocked-tasks ()
  3277. "Dim currently blocked TODO's in the agenda display."
  3278. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3279. (delete-overlay o)))
  3280. (overlays-in (point-min) (point-max)))
  3281. (save-excursion
  3282. (let ((inhibit-read-only t)
  3283. (org-depend-tag-blocked nil)
  3284. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3285. org-blocked-by-checkboxes
  3286. invis1 b e p ov h l)
  3287. (goto-char (point-min))
  3288. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3289. (and pos (goto-char (1+ pos))))
  3290. (setq org-blocked-by-checkboxes nil invis1 invis)
  3291. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3292. (when (and marker
  3293. (with-current-buffer (marker-buffer marker)
  3294. (save-excursion (goto-char marker)
  3295. (org-entry-blocked-p))))
  3296. (if org-blocked-by-checkboxes (setq invis1 nil))
  3297. (setq b (if invis1
  3298. (max (point-min) (1- (point-at-bol)))
  3299. (point-at-bol))
  3300. e (point-at-eol)
  3301. ov (make-overlay b e))
  3302. (if invis1
  3303. (overlay-put ov 'invisible t)
  3304. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3305. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3306. (defvar org-agenda-skip-function nil
  3307. "Function to be called at each match during agenda construction.
  3308. If this function returns nil, the current match should not be skipped.
  3309. Otherwise, the function must return a position from where the search
  3310. should be continued.
  3311. This may also be a Lisp form, it will be evaluated.
  3312. Never set this variable using `setq' or so, because then it will apply
  3313. to all future agenda commands. If you do want a global skipping condition,
  3314. use the option `org-agenda-skip-function-global' instead.
  3315. The correct usage for `org-agenda-skip-function' is to bind it with
  3316. `let' to scope it dynamically into the agenda-constructing command.
  3317. A good way to set it is through options in `org-agenda-custom-commands'.")
  3318. (defun org-agenda-skip ()
  3319. "Throw to `:skip' in places that should be skipped.
  3320. Also moves point to the end of the skipped region, so that search can
  3321. continue from there."
  3322. (let ((p (point-at-bol)) to)
  3323. (when (org-in-src-block-p) (throw :skip t))
  3324. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3325. (get-text-property p :org-archived)
  3326. (org-end-of-subtree t)
  3327. (throw :skip t))
  3328. (and org-agenda-skip-comment-trees
  3329. (get-text-property p :org-comment)
  3330. (org-end-of-subtree t)
  3331. (throw :skip t))
  3332. (if (equal (char-after p) ?#) (throw :skip t))
  3333. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3334. (org-agenda-skip-eval org-agenda-skip-function)))
  3335. (goto-char to)
  3336. (throw :skip t))))
  3337. (defun org-agenda-skip-eval (form)
  3338. "If FORM is a function or a list, call (or eval) is and return result.
  3339. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3340. and match data are returned to the previous state no matter what these
  3341. functions do."
  3342. (let (fp)
  3343. (and form
  3344. (or (setq fp (functionp form))
  3345. (consp form))
  3346. (save-excursion
  3347. (save-match-data
  3348. (if fp
  3349. (funcall form)
  3350. (eval form)))))))
  3351. (defvar org-agenda-markers nil
  3352. "List of all currently active markers created by `org-agenda'.")
  3353. (defvar org-agenda-last-marker-time (org-float-time)
  3354. "Creation time of the last agenda marker.")
  3355. (defun org-agenda-new-marker (&optional pos)
  3356. "Return a new agenda marker.
  3357. Org-mode keeps a list of these markers and resets them when they are
  3358. no longer in use."
  3359. (let ((m (copy-marker (or pos (point)))))
  3360. (setq org-agenda-last-marker-time (org-float-time))
  3361. (if org-agenda-buffer
  3362. (with-current-buffer org-agenda-buffer
  3363. (push m org-agenda-markers))
  3364. (push m org-agenda-markers))
  3365. m))
  3366. (defun org-agenda-reset-markers ()
  3367. "Reset markers created by `org-agenda'."
  3368. (while org-agenda-markers
  3369. (move-marker (pop org-agenda-markers) nil)))
  3370. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3371. "Save relative positions of markers in region.
  3372. This check for agenda markers in all agenda buffers currently active."
  3373. (dolist (buf (buffer-list))
  3374. (with-current-buffer buf
  3375. (when (eq major-mode 'org-agenda-mode)
  3376. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3377. org-agenda-markers)))))
  3378. ;;; Entry text mode
  3379. (defun org-agenda-entry-text-show-here ()
  3380. "Add some text from the entry as context to the current line."
  3381. (let (m txt o)
  3382. (setq m (org-get-at-bol 'org-hd-marker))
  3383. (unless (marker-buffer m)
  3384. (error "No marker points to an entry here"))
  3385. (setq txt (concat "\n" (org-no-properties
  3386. (org-agenda-get-some-entry-text
  3387. m org-agenda-entry-text-maxlines " > "))))
  3388. (when (string-match "\\S-" txt)
  3389. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3390. (overlay-put o 'evaporate t)
  3391. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3392. (overlay-put o 'after-string txt))))
  3393. (defun org-agenda-entry-text-show ()
  3394. "Add entry context for all agenda lines."
  3395. (interactive)
  3396. (save-excursion
  3397. (goto-char (point-max))
  3398. (beginning-of-line 1)
  3399. (while (not (bobp))
  3400. (when (org-get-at-bol 'org-hd-marker)
  3401. (org-agenda-entry-text-show-here))
  3402. (beginning-of-line 0))))
  3403. (defun org-agenda-entry-text-hide ()
  3404. "Remove any shown entry context."
  3405. (delq nil
  3406. (mapcar (lambda (o)
  3407. (if (eq (overlay-get o 'org-overlay-type)
  3408. 'agenda-entry-content)
  3409. (progn (delete-overlay o) t)))
  3410. (overlays-in (point-min) (point-max)))))
  3411. (defun org-agenda-get-day-face (date)
  3412. "Return the face DATE should be displayed with."
  3413. (or (and (functionp org-agenda-day-face-function)
  3414. (funcall org-agenda-day-face-function date))
  3415. (cond ((org-agenda-todayp date)
  3416. 'org-agenda-date-today)
  3417. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3418. 'org-agenda-date-weekend)
  3419. (t 'org-agenda-date))))
  3420. ;;; Agenda timeline
  3421. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3422. (defun org-timeline (&optional dotodo)
  3423. "Show a time-sorted view of the entries in the current org file.
  3424. Only entries with a time stamp of today or later will be listed. With
  3425. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3426. under the current date.
  3427. If the buffer contains an active region, only check the region for
  3428. dates."
  3429. (interactive "P")
  3430. (let* ((dopast t)
  3431. (org-agenda-show-log-scoped org-agenda-show-log)
  3432. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3433. (current-buffer))))
  3434. (date (calendar-current-date))
  3435. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3436. (end (if (org-region-active-p) (region-end) (point-max)))
  3437. (day-numbers (org-get-all-dates
  3438. beg end 'no-ranges
  3439. t org-agenda-show-log-scoped ; always include today
  3440. org-timeline-show-empty-dates))
  3441. (org-deadline-warning-days 0)
  3442. (org-agenda-only-exact-dates t)
  3443. (today (org-today))
  3444. (past t)
  3445. args
  3446. s e rtn d emptyp)
  3447. (setq org-agenda-redo-command
  3448. (list 'progn
  3449. (list 'org-switch-to-buffer-other-window (current-buffer))
  3450. (list 'org-timeline (list 'quote dotodo))))
  3451. (if (not dopast)
  3452. ;; Remove past dates from the list of dates.
  3453. (setq day-numbers (delq nil (mapcar (lambda(x)
  3454. (if (>= x today) x nil))
  3455. day-numbers))))
  3456. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3457. (org-compile-prefix-format 'timeline)
  3458. (org-set-sorting-strategy 'timeline)
  3459. (if org-agenda-show-log-scoped (push :closed args))
  3460. (push :timestamp args)
  3461. (push :deadline args)
  3462. (push :scheduled args)
  3463. (push :sexp args)
  3464. (if dotodo (push :todo args))
  3465. (insert "Timeline of file " entry "\n")
  3466. (add-text-properties (point-min) (point)
  3467. (list 'face 'org-agenda-structure))
  3468. (org-agenda-mark-header-line (point-min))
  3469. (while (setq d (pop day-numbers))
  3470. (if (and (listp d) (eq (car d) :omitted))
  3471. (progn
  3472. (setq s (point))
  3473. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3474. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3475. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3476. (if (and (>= d today)
  3477. dopast
  3478. past)
  3479. (progn
  3480. (setq past nil)
  3481. (insert (make-string 79 ?-) "\n")))
  3482. (setq date (calendar-gregorian-from-absolute d))
  3483. (setq s (point))
  3484. (setq rtn (and (not emptyp)
  3485. (apply 'org-agenda-get-day-entries entry
  3486. date args)))
  3487. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3488. (progn
  3489. (insert
  3490. (if (stringp org-agenda-format-date)
  3491. (format-time-string org-agenda-format-date
  3492. (org-time-from-absolute date))
  3493. (funcall org-agenda-format-date date))
  3494. "\n")
  3495. (put-text-property s (1- (point)) 'face
  3496. (org-agenda-get-day-face date))
  3497. (put-text-property s (1- (point)) 'org-date-line t)
  3498. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3499. (if (equal d today)
  3500. (put-text-property s (1- (point)) 'org-today t))
  3501. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3502. (put-text-property s (1- (point)) 'day d)))))
  3503. (goto-char (point-min))
  3504. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3505. (point-min)))
  3506. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3507. (org-agenda-finalize)
  3508. (setq buffer-read-only t)))
  3509. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3510. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3511. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3512. not every single day in the range. If FORCE-TODAY is non-nil, make
  3513. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3514. inactive time stamps (those in square brackets) are included.
  3515. When EMPTY is non-nil, also include days without any entries."
  3516. (let ((re (concat
  3517. (if pre-re pre-re "")
  3518. (if inactive org-ts-regexp-both org-ts-regexp)))
  3519. dates dates1 date day day1 day2 ts1 ts2 pos)
  3520. (if force-today
  3521. (setq dates (list (org-today))))
  3522. (save-excursion
  3523. (goto-char beg)
  3524. (while (re-search-forward re end t)
  3525. (setq day (time-to-days (org-time-string-to-time
  3526. (substring (match-string 1) 0 10)
  3527. (current-buffer) (match-beginning 0))))
  3528. (or (memq day dates) (push day dates)))
  3529. (unless no-ranges
  3530. (goto-char beg)
  3531. (while (re-search-forward org-tr-regexp end t)
  3532. (setq pos (match-beginning 0))
  3533. (setq ts1 (substring (match-string 1) 0 10)
  3534. ts2 (substring (match-string 2) 0 10)
  3535. day1 (time-to-days (org-time-string-to-time
  3536. ts1 (current-buffer) pos))
  3537. day2 (time-to-days (org-time-string-to-time
  3538. ts2 (current-buffer) pos)))
  3539. (while (< (setq day1 (1+ day1)) day2)
  3540. (or (memq day1 dates) (push day1 dates)))))
  3541. (setq dates (sort dates '<))
  3542. (when empty
  3543. (while (setq day (pop dates))
  3544. (setq day2 (car dates))
  3545. (push day dates1)
  3546. (when (and day2 empty)
  3547. (if (or (eq empty t)
  3548. (and (numberp empty) (<= (- day2 day) empty)))
  3549. (while (< (setq day (1+ day)) day2)
  3550. (push (list day) dates1))
  3551. (push (cons :omitted (- day2 day)) dates1))))
  3552. (setq dates (nreverse dates1)))
  3553. dates)))
  3554. ;;; Agenda Daily/Weekly
  3555. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3556. "Start day for the agenda view.
  3557. Custom commands can set this variable in the options section.")
  3558. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3559. (defvar org-arg-loc nil) ; local variable
  3560. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3561. "List of types searched for when creating the daily/weekly agenda.
  3562. This variable is a list of symbols that controls the types of
  3563. items that appear in the daily/weekly agenda. Allowed symbols in this
  3564. list are are
  3565. :timestamp List items containing a date stamp or date range matching
  3566. the selected date. This includes sexp entries in
  3567. angular brackets.
  3568. :sexp List entries resulting from plain diary-like sexps.
  3569. :deadline List deadline due on that date. When the date is today,
  3570. also list any deadlines past due, or due within
  3571. `org-deadline-warning-days'. `:deadline' must appear before
  3572. `:scheduled' if the setting of
  3573. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3574. any effect.
  3575. :scheduled List all items which are scheduled for the given date.
  3576. The diary for *today* also contains items which were
  3577. scheduled earlier and are not yet marked DONE.
  3578. By default, all four types are turned on.
  3579. Never set this variable globally using `setq', because then it
  3580. will apply to all future agenda commands. Instead, bind it with
  3581. `let' to scope it dynamically into the agenda-constructing
  3582. command. A good way to set it is through options in
  3583. `org-agenda-custom-commands'. For a more flexible (though
  3584. somewhat less efficient) way of determining what is included in
  3585. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3586. (defvar org-agenda-buffer-tmp-name nil)
  3587. ;;;###autoload
  3588. (defun org-agenda-list (&optional arg start-day span)
  3589. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3590. The view will be for the current day or week, but from the overview buffer
  3591. you will be able to go to other days/weeks.
  3592. With a numeric prefix argument in an interactive call, the agenda will
  3593. span ARG days. Lisp programs should instead specify SPAN to change
  3594. the number of days. SPAN defaults to `org-agenda-span'.
  3595. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3596. given in `org-agenda-start-on-weekday'."
  3597. (interactive "P")
  3598. (if org-agenda-overriding-arguments
  3599. (setq arg (car org-agenda-overriding-arguments)
  3600. start-day (nth 1 org-agenda-overriding-arguments)
  3601. span (nth 2 org-agenda-overriding-arguments)))
  3602. (if (and (integerp arg) (> arg 0))
  3603. (setq span arg arg nil))
  3604. (catch 'exit
  3605. (setq org-agenda-buffer-name
  3606. (or org-agenda-buffer-tmp-name
  3607. (if org-agenda-sticky
  3608. (cond ((and org-keys (stringp org-match))
  3609. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3610. (org-keys
  3611. (format "*Org Agenda(%s)*" org-keys))
  3612. (t "*Org Agenda(a)*")))
  3613. org-agenda-buffer-name))
  3614. (org-agenda-prepare "Day/Week")
  3615. (setq start-day (or start-day org-agenda-start-day))
  3616. (if (stringp start-day)
  3617. ;; Convert to an absolute day number
  3618. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3619. (org-compile-prefix-format 'agenda)
  3620. (org-set-sorting-strategy 'agenda)
  3621. (let* ((span (org-agenda-ndays-to-span
  3622. (or span org-agenda-ndays org-agenda-span)))
  3623. (today (org-today))
  3624. (sd (or start-day today))
  3625. (ndays (org-agenda-span-to-ndays span sd))
  3626. (org-agenda-start-on-weekday
  3627. (if (eq ndays 7)
  3628. org-agenda-start-on-weekday))
  3629. (thefiles (org-agenda-files nil 'ifmode))
  3630. (files thefiles)
  3631. (start (if (or (null org-agenda-start-on-weekday)
  3632. (< ndays 7))
  3633. sd
  3634. (let* ((nt (calendar-day-of-week
  3635. (calendar-gregorian-from-absolute sd)))
  3636. (n1 org-agenda-start-on-weekday)
  3637. (d (- nt n1)))
  3638. (- sd (+ (if (< d 0) 7 0) d)))))
  3639. (day-numbers (list start))
  3640. (day-cnt 0)
  3641. (inhibit-redisplay (not debug-on-error))
  3642. (org-agenda-show-log-scoped org-agenda-show-log)
  3643. s e rtn rtnall file date d start-pos end-pos todayp
  3644. clocktable-start clocktable-end filter)
  3645. (setq org-agenda-redo-command
  3646. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3647. (dotimes (n (1- ndays))
  3648. (push (1+ (car day-numbers)) day-numbers))
  3649. (setq day-numbers (nreverse day-numbers))
  3650. (setq clocktable-start (car day-numbers)
  3651. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3652. (org-set-local 'org-starting-day (car day-numbers))
  3653. (org-set-local 'org-arg-loc arg)
  3654. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3655. (unless org-agenda-compact-blocks
  3656. (let* ((d1 (car day-numbers))
  3657. (d2 (org-last day-numbers))
  3658. (w1 (org-days-to-iso-week d1))
  3659. (w2 (org-days-to-iso-week d2)))
  3660. (setq s (point))
  3661. (if org-agenda-overriding-header
  3662. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3663. nil 'face 'org-agenda-structure) "\n")
  3664. (insert (org-agenda-span-name span)
  3665. "-agenda"
  3666. (if (< (- d2 d1) 350)
  3667. (if (= w1 w2)
  3668. (format " (W%02d)" w1)
  3669. (format " (W%02d-W%02d)" w1 w2))
  3670. "")
  3671. ":\n")))
  3672. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3673. 'org-date-line t))
  3674. (org-agenda-mark-header-line s))
  3675. (while (setq d (pop day-numbers))
  3676. (setq date (calendar-gregorian-from-absolute d)
  3677. s (point))
  3678. (if (or (setq todayp (= d today))
  3679. (and (not start-pos) (= d sd)))
  3680. (setq start-pos (point))
  3681. (if (and start-pos (not end-pos))
  3682. (setq end-pos (point))))
  3683. (setq files thefiles
  3684. rtnall nil)
  3685. (while (setq file (pop files))
  3686. (catch 'nextfile
  3687. (org-check-agenda-file file)
  3688. (let ((org-agenda-entry-types org-agenda-entry-types))
  3689. (unless org-agenda-include-deadlines
  3690. (setq org-agenda-entry-types
  3691. (delq :deadline org-agenda-entry-types)))
  3692. (cond
  3693. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3694. (setq rtn (org-agenda-get-day-entries
  3695. file date :closed)))
  3696. (org-agenda-show-log-scoped
  3697. (setq rtn (apply 'org-agenda-get-day-entries
  3698. file date
  3699. (append '(:closed) org-agenda-entry-types))))
  3700. (t
  3701. (setq rtn (apply 'org-agenda-get-day-entries
  3702. file date
  3703. org-agenda-entry-types)))))
  3704. (setq rtnall (append rtnall rtn)))) ;; all entries
  3705. (if org-agenda-include-diary
  3706. (let ((org-agenda-search-headline-for-time t))
  3707. (require 'diary-lib)
  3708. (setq rtn (org-get-entries-from-diary date))
  3709. (setq rtnall (append rtnall rtn))))
  3710. (if (or rtnall org-agenda-show-all-dates)
  3711. (progn
  3712. (setq day-cnt (1+ day-cnt))
  3713. (insert
  3714. (if (stringp org-agenda-format-date)
  3715. (format-time-string org-agenda-format-date
  3716. (org-time-from-absolute date))
  3717. (funcall org-agenda-format-date date))
  3718. "\n")
  3719. (put-text-property s (1- (point)) 'face
  3720. (org-agenda-get-day-face date))
  3721. (put-text-property s (1- (point)) 'org-date-line t)
  3722. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3723. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3724. (when todayp
  3725. (put-text-property s (1- (point)) 'org-today t))
  3726. (setq rtnall
  3727. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3728. (if rtnall (insert ;; all entries
  3729. (org-agenda-finalize-entries rtnall)
  3730. "\n"))
  3731. (put-text-property s (1- (point)) 'day d)
  3732. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3733. (when (and org-agenda-clockreport-mode clocktable-start)
  3734. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3735. ;; the above line is to ensure the restricted range!
  3736. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3737. tbl)
  3738. (setq p (org-plist-delete p :block))
  3739. (setq p (plist-put p :tstart clocktable-start))
  3740. (setq p (plist-put p :tend clocktable-end))
  3741. (setq p (plist-put p :scope 'agenda))
  3742. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3743. (setq filter (or org-agenda-tag-filter-while-redo
  3744. (get 'org-agenda-tag-filter :preset-filter))))
  3745. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3746. (if (string-match "[<>=]" x)
  3747. ""
  3748. x))
  3749. filter ""))))
  3750. (setq tbl (apply 'org-clock-get-clocktable p))
  3751. (insert tbl)))
  3752. (goto-char (point-min))
  3753. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3754. (unless (and (pos-visible-in-window-p (point-min))
  3755. (pos-visible-in-window-p (point-max)))
  3756. (goto-char (1- (point-max)))
  3757. (recenter -1)
  3758. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3759. (progn
  3760. (goto-char (or start-pos 1))
  3761. (recenter 1))))
  3762. (goto-char (or start-pos 1))
  3763. (add-text-properties (point-min) (point-max)
  3764. `(org-agenda-type agenda
  3765. org-last-args (,arg ,start-day ,span)
  3766. org-redo-cmd ,org-agenda-redo-command
  3767. org-serie-cmd ,org-cmd))
  3768. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3769. (org-agenda-show-clocking-issues))
  3770. (org-agenda-finalize)
  3771. (setq buffer-read-only t)
  3772. (message ""))))
  3773. (autoload 'org-agenda-list "org-agenda" "\
  3774. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3775. The view will be for the current day or week, but from the overview buffer
  3776. you will be able to go to other days/weeks.
  3777. With a numeric prefix argument in an interactive call, the agenda will
  3778. span ARG days. Lisp programs should instead specify SPAN to change
  3779. the number of days. SPAN defaults to `org-agenda-span'.
  3780. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3781. given in `org-agenda-start-on-weekday'.
  3782. \(fn &optional ARG START-DAY SPAN)" t nil)
  3783. (defun org-agenda-ndays-to-span (n)
  3784. "Return a span symbol for a span of N days, or N if none matches."
  3785. (cond ((symbolp n) n)
  3786. ((= n 1) 'day)
  3787. ((= n 7) 'week)
  3788. (t n)))
  3789. (defun org-agenda-span-to-ndays (span &optional start-day)
  3790. "Return ndays from SPAN, possibly starting at START-DAY."
  3791. (cond ((numberp span) span)
  3792. ((eq span 'day) 1)
  3793. ((eq span 'week) 7)
  3794. ((eq span 'month)
  3795. (let ((date (calendar-gregorian-from-absolute start-day)))
  3796. (calendar-last-day-of-month (car date) (caddr date))))
  3797. ((eq span 'year)
  3798. (let ((date (calendar-gregorian-from-absolute start-day)))
  3799. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3800. (defun org-agenda-span-name (span)
  3801. "Return a SPAN name."
  3802. (if (null span)
  3803. ""
  3804. (if (symbolp span)
  3805. (capitalize (symbol-name span))
  3806. (format "%d days" span))))
  3807. ;;; Agenda word search
  3808. (defvar org-agenda-search-history nil)
  3809. (defvar org-search-syntax-table nil
  3810. "Special syntax table for org-mode search.
  3811. In this table, we have single quotes not as word constituents, to
  3812. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3813. (defvar org-mode-syntax-table) ; From org.el
  3814. (defun org-search-syntax-table ()
  3815. (unless org-search-syntax-table
  3816. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3817. (modify-syntax-entry ?' "." org-search-syntax-table)
  3818. (modify-syntax-entry ?` "." org-search-syntax-table))
  3819. org-search-syntax-table)
  3820. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3821. ;;;###autoload
  3822. (defun org-search-view (&optional todo-only string edit-at)
  3823. "Show all entries that contain a phrase or words or regular expressions.
  3824. With optional prefix argument TODO-ONLY, only consider entries that are
  3825. TODO entries. The argument STRING can be used to pass a default search
  3826. string into this function. If EDIT-AT is non-nil, it means that the
  3827. user should get a chance to edit this string, with cursor at position
  3828. EDIT-AT.
  3829. The search string can be viewed either as a phrase that should be found as
  3830. is, or it can be broken into a number of snippets, each of which must match
  3831. in a Boolean way to select an entry. The default depends on the variable
  3832. `org-agenda-search-view-always-boolean'.
  3833. Even if this is turned off (the default) you can always switch to
  3834. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3835. The default is a direct search of the whole phrase, where each space in
  3836. the search string can expand to an arbitrary amount of whitespace,
  3837. including newlines.
  3838. If using a Boolean search, the search string is split on whitespace and
  3839. each snippet is searched separately, with logical AND to select an entry.
  3840. Words prefixed with a minus must *not* occur in the entry. Words without
  3841. a prefix or prefixed with a plus must occur in the entry. Matching is
  3842. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3843. match whole words, not parts of a word) if
  3844. `org-agenda-search-view-force-full-words' is set (default is nil).
  3845. Boolean search snippets enclosed by curly braces are interpreted as
  3846. regular expressions that must or (when preceded with \"-\") must not
  3847. match in the entry. Snippets enclosed into double quotes will be taken
  3848. as a whole, to include whitespace.
  3849. - If the search string starts with an asterisk, search only in headlines.
  3850. - If (possibly after the leading star) the search string starts with an
  3851. exclamation mark, this also means to look at TODO entries only, an effect
  3852. that can also be achieved with a prefix argument.
  3853. - If (possibly after star and exclamation mark) the search string starts
  3854. with a colon, this will mean that the (non-regexp) snippets of the
  3855. Boolean search must match as full words.
  3856. This command searches the agenda files, and in addition the files listed
  3857. in `org-agenda-text-search-extra-files'."
  3858. (interactive "P")
  3859. (if org-agenda-overriding-arguments
  3860. (setq todo-only (car org-agenda-overriding-arguments)
  3861. string (nth 1 org-agenda-overriding-arguments)
  3862. edit-at (nth 2 org-agenda-overriding-arguments)))
  3863. (let* ((props (list 'face nil
  3864. 'done-face 'org-agenda-done
  3865. 'org-not-done-regexp org-not-done-regexp
  3866. 'org-todo-regexp org-todo-regexp
  3867. 'org-complex-heading-regexp org-complex-heading-regexp
  3868. 'mouse-face 'highlight
  3869. 'help-echo (format "mouse-2 or RET jump to location")))
  3870. (full-words org-agenda-search-view-force-full-words)
  3871. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3872. regexp rtn rtnall files file pos
  3873. marker category category-pos tags c neg re boolean
  3874. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3875. (unless (and (not edit-at)
  3876. (stringp string)
  3877. (string-match "\\S-" string))
  3878. (setq string (read-string
  3879. (if org-agenda-search-view-always-boolean
  3880. "[+-]Word/{Regexp} ...: "
  3881. "Phrase or [+-]Word/{Regexp} ...: ")
  3882. (cond
  3883. ((integerp edit-at) (cons string edit-at))
  3884. (edit-at string))
  3885. 'org-agenda-search-history)))
  3886. (catch 'exit
  3887. (if org-agenda-sticky
  3888. (setq org-agenda-buffer-name
  3889. (if (stringp string)
  3890. (format "*Org Agenda(%s:%s)*"
  3891. (or org-keys (or (and todo-only "S") "s")) string)
  3892. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3893. (org-agenda-prepare "SEARCH")
  3894. (org-compile-prefix-format 'search)
  3895. (org-set-sorting-strategy 'search)
  3896. (setq org-agenda-redo-command
  3897. (list 'org-search-view (if todo-only t nil)
  3898. (list 'if 'current-prefix-arg nil string)))
  3899. (setq org-agenda-query-string string)
  3900. (if (equal (string-to-char string) ?*)
  3901. (setq hdl-only t
  3902. words (substring string 1))
  3903. (setq words string))
  3904. (when (equal (string-to-char words) ?!)
  3905. (setq todo-only t
  3906. words (substring words 1)))
  3907. (when (equal (string-to-char words) ?:)
  3908. (setq full-words t
  3909. words (substring words 1)))
  3910. (if (or org-agenda-search-view-always-boolean
  3911. (member (string-to-char words) '(?- ?+ ?\{)))
  3912. (setq boolean t))
  3913. (setq words (org-split-string words))
  3914. (let (www w)
  3915. (while (setq w (pop words))
  3916. (while (and (string-match "\\\\\\'" w) words)
  3917. (setq w (concat (substring w 0 -1) " " (pop words))))
  3918. (push w www))
  3919. (setq words (nreverse www) www nil)
  3920. (while (setq w (pop words))
  3921. (when (and (string-match "\\`[-+]?{" w)
  3922. (not (string-match "}\\'" w)))
  3923. (while (and words (not (string-match "}\\'" (car words))))
  3924. (setq w (concat w " " (pop words))))
  3925. (setq w (concat w " " (pop words))))
  3926. (push w www))
  3927. (setq words (nreverse www)))
  3928. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3929. (when boolean
  3930. (let (wds w)
  3931. (while (setq w (pop words))
  3932. (if (or (equal (substring w 0 1) "\"")
  3933. (and (> (length w) 1)
  3934. (member (substring w 0 1) '("+" "-"))
  3935. (equal (substring w 1 2) "\"")))
  3936. (while (and words (not (equal (substring w -1) "\"")))
  3937. (setq w (concat w " " (pop words)))))
  3938. (and (string-match "\\`\\([-+]?\\)\"" w)
  3939. (setq w (replace-match "\\1" nil nil w)))
  3940. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3941. (push w wds))
  3942. (setq words (nreverse wds))))
  3943. (if boolean
  3944. (mapc (lambda (w)
  3945. (setq c (string-to-char w))
  3946. (if (equal c ?-)
  3947. (setq neg t w (substring w 1))
  3948. (if (equal c ?+)
  3949. (setq neg nil w (substring w 1))
  3950. (setq neg nil)))
  3951. (if (string-match "\\`{.*}\\'" w)
  3952. (setq re (substring w 1 -1))
  3953. (if full-words
  3954. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3955. (setq re (regexp-quote (downcase w)))))
  3956. (if neg (push re regexps-) (push re regexps+)))
  3957. words)
  3958. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3959. regexps+))
  3960. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3961. (if (not regexps+)
  3962. (setq regexp org-outline-regexp-bol)
  3963. (setq regexp (pop regexps+))
  3964. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3965. regexp))))
  3966. (setq files (org-agenda-files nil 'ifmode))
  3967. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3968. (pop org-agenda-text-search-extra-files)
  3969. (setq files (org-add-archive-files files)))
  3970. (setq files (append files org-agenda-text-search-extra-files)
  3971. rtnall nil)
  3972. (while (setq file (pop files))
  3973. (setq ee nil)
  3974. (catch 'nextfile
  3975. (org-check-agenda-file file)
  3976. (setq buffer (if (file-exists-p file)
  3977. (org-get-agenda-file-buffer file)
  3978. (error "No such file %s" file)))
  3979. (if (not buffer)
  3980. ;; If file does not exist, make sure an error message is sent
  3981. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3982. file))))
  3983. (with-current-buffer buffer
  3984. (with-syntax-table (org-search-syntax-table)
  3985. (unless (derived-mode-p 'org-mode)
  3986. (error "Agenda file %s is not in `org-mode'" file))
  3987. (let ((case-fold-search t))
  3988. (save-excursion
  3989. (save-restriction
  3990. (if org-agenda-restrict
  3991. (narrow-to-region org-agenda-restrict-begin
  3992. org-agenda-restrict-end)
  3993. (widen))
  3994. (goto-char (point-min))
  3995. (unless (or (org-at-heading-p)
  3996. (outline-next-heading))
  3997. (throw 'nextfile t))
  3998. (goto-char (max (point-min) (1- (point))))
  3999. (while (re-search-forward regexp nil t)
  4000. (org-back-to-heading t)
  4001. (skip-chars-forward "* ")
  4002. (setq beg (point-at-bol)
  4003. beg1 (point)
  4004. end (progn (outline-next-heading) (point)))
  4005. (catch :skip
  4006. (goto-char beg)
  4007. (org-agenda-skip)
  4008. (setq str (buffer-substring-no-properties
  4009. (point-at-bol)
  4010. (if hdl-only (point-at-eol) end)))
  4011. (mapc (lambda (wr) (when (string-match wr str)
  4012. (goto-char (1- end))
  4013. (throw :skip t)))
  4014. regexps-)
  4015. (mapc (lambda (wr) (unless (string-match wr str)
  4016. (goto-char (1- end))
  4017. (throw :skip t)))
  4018. (if todo-only
  4019. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4020. regexps+)
  4021. regexps+))
  4022. (goto-char beg)
  4023. (setq marker (org-agenda-new-marker (point))
  4024. category (org-get-category)
  4025. category-pos (get-text-property (point) 'org-category-position)
  4026. tags (org-get-tags-at (point))
  4027. txt (org-agenda-format-item
  4028. ""
  4029. (buffer-substring-no-properties
  4030. beg1 (point-at-eol))
  4031. category tags t))
  4032. (org-add-props txt props
  4033. 'org-marker marker 'org-hd-marker marker
  4034. 'org-todo-regexp org-todo-regexp
  4035. 'org-complex-heading-regexp org-complex-heading-regexp
  4036. 'priority 1000 'org-category category
  4037. 'org-category-position category-pos
  4038. 'type "search")
  4039. (push txt ee)
  4040. (goto-char (1- end))))))))))
  4041. (setq rtn (nreverse ee))
  4042. (setq rtnall (append rtnall rtn)))
  4043. (if org-agenda-overriding-header
  4044. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4045. nil 'face 'org-agenda-structure) "\n")
  4046. (insert "Search words: ")
  4047. (add-text-properties (point-min) (1- (point))
  4048. (list 'face 'org-agenda-structure))
  4049. (setq pos (point))
  4050. (insert string "\n")
  4051. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4052. (setq pos (point))
  4053. (unless org-agenda-multi
  4054. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4055. (add-text-properties pos (1- (point))
  4056. (list 'face 'org-agenda-structure))))
  4057. (org-agenda-mark-header-line (point-min))
  4058. (when rtnall
  4059. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4060. (goto-char (point-min))
  4061. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4062. (add-text-properties (point-min) (point-max)
  4063. `(org-agenda-type search
  4064. org-last-args (,todo-only ,string ,edit-at)
  4065. org-redo-cmd ,org-agenda-redo-command
  4066. org-serie-cmd ,org-cmd))
  4067. (org-agenda-finalize)
  4068. (setq buffer-read-only t))))
  4069. (autoload 'org-search-view "org-agenda" "\
  4070. Show all entries that contain a phrase or words or regular expressions.
  4071. With optional prefix argument TODO-ONLY, only consider entries that are
  4072. TODO entries. The argument STRING can be used to pass a default search
  4073. string into this function. If EDIT-AT is non-nil, it means that the
  4074. user should get a chance to edit this string, with cursor at position
  4075. EDIT-AT.
  4076. The search string can be viewed either as a phrase that should be found as
  4077. is, or it can be broken into a number of snippets, each of which must match
  4078. in a Boolean way to select an entry. The default depends on the variable
  4079. `org-agenda-search-view-always-boolean'.
  4080. Even if this is turned off (the default) you can always switch to
  4081. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4082. The default is a direct search of the whole phrase, where each space in
  4083. the search string can expand to an arbitrary amount of whitespace,
  4084. including newlines.
  4085. If using a Boolean search, the search string is split on whitespace and
  4086. each snippet is searched separately, with logical AND to select an entry.
  4087. Words prefixed with a minus must *not* occur in the entry. Words without
  4088. a prefix or prefixed with a plus must occur in the entry. Matching is
  4089. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4090. match whole words, not parts of a word) if
  4091. `org-agenda-search-view-force-full-words' is set (default is nil).
  4092. Boolean search snippets enclosed by curly braces are interpreted as
  4093. regular expressions that must or (when preceded with \"-\") must not
  4094. match in the entry. Snippets enclosed into double quotes will be taken
  4095. as a whole, to include whitespace.
  4096. - If the search string starts with an asterisk, search only in headlines.
  4097. - If (possibly after the leading star) the search string starts with an
  4098. exclamation mark, this also means to look at TODO entries only, an effect
  4099. that can also be achieved with a prefix argument.
  4100. - If (possibly after star and exclamation mark) the search string starts
  4101. with a colon, this will mean that the (non-regexp) snippets of the
  4102. Boolean search must match as full words.
  4103. This command searches the agenda files, and in addition the files listed
  4104. in `org-agenda-text-search-extra-files'.
  4105. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4106. ;;; Agenda TODO list
  4107. (defvar org-select-this-todo-keyword nil)
  4108. (defvar org-last-arg nil)
  4109. ;;;###autoload
  4110. (defun org-todo-list (&optional arg)
  4111. "Show all (not done) TODO entries from all agenda file in a single list.
  4112. The prefix arg can be used to select a specific TODO keyword and limit
  4113. the list to these. When using \\[universal-argument], you will be prompted
  4114. for a keyword. A numeric prefix directly selects the Nth keyword in
  4115. `org-todo-keywords-1'."
  4116. (interactive "P")
  4117. (if org-agenda-overriding-arguments
  4118. (setq arg org-agenda-overriding-arguments))
  4119. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4120. (let* ((today (org-today))
  4121. (date (calendar-gregorian-from-absolute today))
  4122. (kwds org-todo-keywords-for-agenda)
  4123. (completion-ignore-case t)
  4124. (org-select-this-todo-keyword
  4125. (if (stringp arg) arg
  4126. (and arg (integerp arg) (> arg 0)
  4127. (nth (1- arg) kwds))))
  4128. rtn rtnall files file pos)
  4129. (when (equal arg '(4))
  4130. (setq org-select-this-todo-keyword
  4131. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4132. (mapcar 'list kwds) nil nil)))
  4133. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4134. (catch 'exit
  4135. (if org-agenda-sticky
  4136. (setq org-agenda-buffer-name
  4137. (if (stringp org-select-this-todo-keyword)
  4138. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4139. org-select-this-todo-keyword)
  4140. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4141. (org-agenda-prepare "TODO")
  4142. (org-compile-prefix-format 'todo)
  4143. (org-set-sorting-strategy 'todo)
  4144. (setq org-agenda-redo-command
  4145. `(org-todo-list (or (and (numberp current-prefix-arg)
  4146. current-prefix-arg)
  4147. ,org-select-this-todo-keyword
  4148. current-prefix-arg ,arg)))
  4149. (setq files (org-agenda-files nil 'ifmode)
  4150. rtnall nil)
  4151. (while (setq file (pop files))
  4152. (catch 'nextfile
  4153. (org-check-agenda-file file)
  4154. (setq rtn (org-agenda-get-day-entries file date :todo))
  4155. (setq rtnall (append rtnall rtn))))
  4156. (if org-agenda-overriding-header
  4157. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4158. nil 'face 'org-agenda-structure) "\n")
  4159. (insert "Global list of TODO items of type: ")
  4160. (add-text-properties (point-min) (1- (point))
  4161. (list 'face 'org-agenda-structure
  4162. 'short-heading
  4163. (concat "ToDo: "
  4164. (or org-select-this-todo-keyword "ALL"))))
  4165. (org-agenda-mark-header-line (point-min))
  4166. (setq pos (point))
  4167. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4168. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4169. (setq pos (point))
  4170. (unless org-agenda-multi
  4171. (insert "Available with `N r': (0)[ALL]")
  4172. (let ((n 0) s)
  4173. (mapc (lambda (x)
  4174. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4175. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4176. (insert "\n "))
  4177. (insert " " s))
  4178. kwds))
  4179. (insert "\n"))
  4180. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4181. (org-agenda-mark-header-line (point-min))
  4182. (when rtnall
  4183. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4184. (goto-char (point-min))
  4185. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4186. (add-text-properties (point-min) (point-max)
  4187. `(org-agenda-type todo
  4188. org-last-args ,arg
  4189. org-redo-cmd ,org-agenda-redo-command
  4190. org-serie-cmd ,org-cmd))
  4191. (org-agenda-finalize)
  4192. (setq buffer-read-only t))))
  4193. (autoload 'org-todo-list "org-agenda" "\
  4194. Show all (not done) TODO entries from all agenda file in a single list.
  4195. The prefix arg can be used to select a specific TODO keyword and limit
  4196. the list to these. When using \\[universal-argument], you will be prompted
  4197. for a keyword. A numeric prefix directly selects the Nth keyword in
  4198. `org-todo-keywords-1'.
  4199. \(fn &optional ARG)" t nil)
  4200. ;;; Agenda tags match
  4201. ;;;###autoload
  4202. (defun org-tags-view (&optional todo-only match)
  4203. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4204. The prefix arg TODO-ONLY limits the search to TODO entries."
  4205. (interactive "P")
  4206. (if org-agenda-overriding-arguments
  4207. (setq todo-only (car org-agenda-overriding-arguments)
  4208. match (nth 1 org-agenda-overriding-arguments)))
  4209. (let* ((org-tags-match-list-sublevels
  4210. org-tags-match-list-sublevels)
  4211. (completion-ignore-case t)
  4212. rtn rtnall files file pos matcher
  4213. buffer)
  4214. (when (and (stringp match) (not (string-match "\\S-" match)))
  4215. (setq match nil))
  4216. (setq matcher (org-make-tags-matcher match)
  4217. match (car matcher) matcher (cdr matcher))
  4218. (catch 'exit
  4219. (if org-agenda-sticky
  4220. (setq org-agenda-buffer-name
  4221. (if (stringp match)
  4222. (format "*Org Agenda(%s:%s)*"
  4223. (or org-keys (or (and todo-only "M") "m")) match)
  4224. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4225. (org-agenda-prepare (concat "TAGS " match))
  4226. (org-compile-prefix-format 'tags)
  4227. (org-set-sorting-strategy 'tags)
  4228. (setq org-agenda-query-string match)
  4229. (setq org-agenda-redo-command
  4230. (list 'org-tags-view `(quote ,todo-only)
  4231. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4232. (setq files (org-agenda-files nil 'ifmode)
  4233. rtnall nil)
  4234. (while (setq file (pop files))
  4235. (catch 'nextfile
  4236. (org-check-agenda-file file)
  4237. (setq buffer (if (file-exists-p file)
  4238. (org-get-agenda-file-buffer file)
  4239. (error "No such file %s" file)))
  4240. (if (not buffer)
  4241. ;; If file does not exist, error message to agenda
  4242. (setq rtn (list
  4243. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4244. rtnall (append rtnall rtn))
  4245. (with-current-buffer buffer
  4246. (unless (derived-mode-p 'org-mode)
  4247. (error "Agenda file %s is not in `org-mode'" file))
  4248. (save-excursion
  4249. (save-restriction
  4250. (if org-agenda-restrict
  4251. (narrow-to-region org-agenda-restrict-begin
  4252. org-agenda-restrict-end)
  4253. (widen))
  4254. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4255. (setq rtnall (append rtnall rtn))))))))
  4256. (if org-agenda-overriding-header
  4257. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4258. nil 'face 'org-agenda-structure) "\n")
  4259. (insert "Headlines with TAGS match: ")
  4260. (add-text-properties (point-min) (1- (point))
  4261. (list 'face 'org-agenda-structure
  4262. 'short-heading
  4263. (concat "Match: " match)))
  4264. (setq pos (point))
  4265. (insert match "\n")
  4266. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4267. (setq pos (point))
  4268. (unless org-agenda-multi
  4269. (insert "Press `C-u r' to search again with new search string\n"))
  4270. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4271. (org-agenda-mark-header-line (point-min))
  4272. (when rtnall
  4273. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4274. (goto-char (point-min))
  4275. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4276. (add-text-properties (point-min) (point-max)
  4277. `(org-agenda-type tags
  4278. org-last-args (,todo-only ,match)
  4279. org-redo-cmd ,org-agenda-redo-command
  4280. org-serie-cmd ,org-cmd))
  4281. (org-agenda-finalize)
  4282. (setq buffer-read-only t))))
  4283. (autoload 'org-tags-view "org-agenda" "\
  4284. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4285. The prefix arg TODO-ONLY limits the search to TODO entries.
  4286. \(fn &optional TODO-ONLY MATCH)" t nil)
  4287. ;;; Agenda Finding stuck projects
  4288. (defvar org-agenda-skip-regexp nil
  4289. "Regular expression used in skipping subtrees for the agenda.
  4290. This is basically a temporary global variable that can be set and then
  4291. used by user-defined selections using `org-agenda-skip-function'.")
  4292. (defvar org-agenda-overriding-header nil
  4293. "When set during agenda, todo and tags searches it replaces the header.
  4294. This variable should not be set directly, but custom commands can bind it
  4295. in the options section.")
  4296. (defun org-agenda-skip-entry-when-regexp-matches ()
  4297. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4298. If yes, it returns the end position of this entry, causing agenda commands
  4299. to skip the entry but continuing the search in the subtree. This is a
  4300. function that can be put into `org-agenda-skip-function' for the duration
  4301. of a command."
  4302. (let ((end (save-excursion (org-end-of-subtree t)))
  4303. skip)
  4304. (save-excursion
  4305. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4306. (and skip end)))
  4307. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4308. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4309. If yes, it returns the end position of this tree, causing agenda commands
  4310. to skip this subtree. This is a function that can be put into
  4311. `org-agenda-skip-function' for the duration of a command."
  4312. (let ((end (save-excursion (org-end-of-subtree t)))
  4313. skip)
  4314. (save-excursion
  4315. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4316. (and skip end)))
  4317. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4318. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4319. If yes, it returns the end position of the current entry (NOT the tree),
  4320. causing agenda commands to skip the entry but continuing the search in
  4321. the subtree. This is a function that can be put into
  4322. `org-agenda-skip-function' for the duration of a command. An important
  4323. use of this function is for the stuck project list."
  4324. (let ((end (save-excursion (org-end-of-subtree t)))
  4325. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4326. skip)
  4327. (save-excursion
  4328. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4329. (and skip entry-end)))
  4330. (defun org-agenda-skip-entry-if (&rest conditions)
  4331. "Skip entry if any of CONDITIONS is true.
  4332. See `org-agenda-skip-if' for details."
  4333. (org-agenda-skip-if nil conditions))
  4334. (defun org-agenda-skip-subtree-if (&rest conditions)
  4335. "Skip entry if any of CONDITIONS is true.
  4336. See `org-agenda-skip-if' for details."
  4337. (org-agenda-skip-if t conditions))
  4338. (defun org-agenda-skip-if (subtree conditions)
  4339. "Checks current entity for CONDITIONS.
  4340. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4341. the entry (i.e. the text before the next heading) is checked.
  4342. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4343. from different tests. Valid conditions are:
  4344. scheduled Check if there is a scheduled cookie
  4345. notscheduled Check if there is no scheduled cookie
  4346. deadline Check if there is a deadline
  4347. notdeadline Check if there is no deadline
  4348. timestamp Check if there is a timestamp (also deadline or scheduled)
  4349. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4350. regexp Check if regexp matches
  4351. notregexp Check if regexp does not match.
  4352. todo Check if TODO keyword matches
  4353. nottodo Check if TODO keyword does not match
  4354. The regexp is taken from the conditions list, it must come right after
  4355. the `regexp' or `notregexp' element.
  4356. `todo' and `nottodo' accept as an argument a list of todo
  4357. keywords, which may include \"*\" to match any todo keyword.
  4358. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4359. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4360. Instead of a list, a keyword class may be given. For example:
  4361. (org-agenda-skip-entry-if 'nottodo 'done)
  4362. would skip entries that haven't been marked with any of \"DONE\"
  4363. keywords. Possible classes are: `todo', `done', `any'.
  4364. If any of these conditions is met, this function returns the end point of
  4365. the entity, causing the search to continue from there. This is a function
  4366. that can be put into `org-agenda-skip-function' for the duration of a command."
  4367. (let (beg end m)
  4368. (org-back-to-heading t)
  4369. (setq beg (point)
  4370. end (if subtree
  4371. (progn (org-end-of-subtree t) (point))
  4372. (progn (outline-next-heading) (1- (point)))))
  4373. (goto-char beg)
  4374. (and
  4375. (or
  4376. (and (memq 'scheduled conditions)
  4377. (re-search-forward org-scheduled-time-regexp end t))
  4378. (and (memq 'notscheduled conditions)
  4379. (not (re-search-forward org-scheduled-time-regexp end t)))
  4380. (and (memq 'deadline conditions)
  4381. (re-search-forward org-deadline-time-regexp end t))
  4382. (and (memq 'notdeadline conditions)
  4383. (not (re-search-forward org-deadline-time-regexp end t)))
  4384. (and (memq 'timestamp conditions)
  4385. (re-search-forward org-ts-regexp end t))
  4386. (and (memq 'nottimestamp conditions)
  4387. (not (re-search-forward org-ts-regexp end t)))
  4388. (and (setq m (memq 'regexp conditions))
  4389. (stringp (nth 1 m))
  4390. (re-search-forward (nth 1 m) end t))
  4391. (and (setq m (memq 'notregexp conditions))
  4392. (stringp (nth 1 m))
  4393. (not (re-search-forward (nth 1 m) end t)))
  4394. (and (or
  4395. (setq m (memq 'nottodo conditions))
  4396. (setq m (memq 'todo-unblocked conditions))
  4397. (setq m (memq 'nottodo-unblocked conditions))
  4398. (setq m (memq 'todo conditions)))
  4399. (org-agenda-skip-if-todo m end)))
  4400. end)))
  4401. (defun org-agenda-skip-if-todo (args end)
  4402. "Helper function for `org-agenda-skip-if', do not use it directly.
  4403. ARGS is a list with first element either `todo', `nottodo',
  4404. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4405. a list of TODO keywords, or a state symbol `todo' or `done' or
  4406. `any'."
  4407. (let ((kw (car args))
  4408. (arg (cadr args))
  4409. todo-wds todo-re)
  4410. (setq todo-wds
  4411. (org-uniquify
  4412. (cond
  4413. ((listp arg) ;; list of keywords
  4414. (if (member "*" arg)
  4415. (mapcar 'substring-no-properties org-todo-keywords-1)
  4416. arg))
  4417. ((symbolp arg) ;; keyword class name
  4418. (cond
  4419. ((eq arg 'todo)
  4420. (org-delete-all org-done-keywords
  4421. (mapcar 'substring-no-properties
  4422. org-todo-keywords-1)))
  4423. ((eq arg 'done) org-done-keywords)
  4424. ((eq arg 'any)
  4425. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4426. (setq todo-re
  4427. (concat "^\\*+[ \t]+\\<\\("
  4428. (mapconcat 'identity todo-wds "\\|")
  4429. "\\)\\>"))
  4430. (cond
  4431. ((eq kw 'todo) (re-search-forward todo-re end t))
  4432. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4433. ((eq kw 'todo-unblocked)
  4434. (catch 'unblocked
  4435. (while (re-search-forward todo-re end t)
  4436. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4437. nil))
  4438. ((eq kw 'nottodo-unblocked)
  4439. (catch 'unblocked
  4440. (while (re-search-forward todo-re end t)
  4441. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4442. t))
  4443. )))
  4444. ;;;###autoload
  4445. (defun org-agenda-list-stuck-projects (&rest ignore)
  4446. "Create agenda view for projects that are stuck.
  4447. Stuck projects are project that have no next actions. For the definitions
  4448. of what a project is and how to check if it stuck, customize the variable
  4449. `org-stuck-projects'."
  4450. (interactive)
  4451. (let* ((org-agenda-skip-function
  4452. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4453. ;; We could have used org-agenda-skip-if here.
  4454. (org-agenda-overriding-header
  4455. (or org-agenda-overriding-header "List of stuck projects: "))
  4456. (matcher (nth 0 org-stuck-projects))
  4457. (todo (nth 1 org-stuck-projects))
  4458. (todo-wds (if (member "*" todo)
  4459. (progn
  4460. (org-agenda-prepare-buffers (org-agenda-files
  4461. nil 'ifmode))
  4462. (org-delete-all
  4463. org-done-keywords-for-agenda
  4464. (copy-sequence org-todo-keywords-for-agenda)))
  4465. todo))
  4466. (todo-re (concat "^\\*+[ \t]+\\("
  4467. (mapconcat 'identity todo-wds "\\|")
  4468. "\\)\\>"))
  4469. (tags (nth 2 org-stuck-projects))
  4470. (tags-re (if (member "*" tags)
  4471. (concat org-outline-regexp-bol
  4472. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4473. (if tags
  4474. (concat org-outline-regexp-bol
  4475. ".*:\\("
  4476. (mapconcat 'identity tags "\\|")
  4477. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4478. (gen-re (nth 3 org-stuck-projects))
  4479. (re-list
  4480. (delq nil
  4481. (list
  4482. (if todo todo-re)
  4483. (if tags tags-re)
  4484. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4485. gen-re)))))
  4486. (setq org-agenda-skip-regexp
  4487. (if re-list
  4488. (mapconcat 'identity re-list "\\|")
  4489. (error "No information how to identify unstuck projects")))
  4490. (org-tags-view nil matcher)
  4491. (with-current-buffer org-agenda-buffer-name
  4492. (setq org-agenda-redo-command
  4493. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4494. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4495. Create agenda view for projects that are stuck.
  4496. Stuck projects are project that have no next actions. For the definitions
  4497. of what a project is and how to check if it stuck, customize the variable
  4498. `org-stuck-projects'.
  4499. \(fn &rest IGNORE)" t nil)
  4500. ;;; Diary integration
  4501. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4502. (defvar diary-list-entries-hook)
  4503. (defvar diary-time-regexp)
  4504. (defun org-get-entries-from-diary (date)
  4505. "Get the (Emacs Calendar) diary entries for DATE."
  4506. (require 'diary-lib)
  4507. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4508. (diary-display-hook '(fancy-diary-display))
  4509. (diary-display-function 'fancy-diary-display)
  4510. (pop-up-frames nil)
  4511. (diary-list-entries-hook
  4512. (cons 'org-diary-default-entry diary-list-entries-hook))
  4513. (diary-file-name-prefix-function nil) ; turn this feature off
  4514. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4515. entries
  4516. (org-disable-agenda-to-diary t))
  4517. (save-excursion
  4518. (save-window-excursion
  4519. (funcall (if (fboundp 'diary-list-entries)
  4520. 'diary-list-entries 'list-diary-entries)
  4521. date 1)))
  4522. (if (not (get-buffer diary-fancy-buffer))
  4523. (setq entries nil)
  4524. (with-current-buffer diary-fancy-buffer
  4525. (setq buffer-read-only nil)
  4526. (if (zerop (buffer-size))
  4527. ;; No entries
  4528. (setq entries nil)
  4529. ;; Omit the date and other unnecessary stuff
  4530. (org-agenda-cleanup-fancy-diary)
  4531. ;; Add prefix to each line and extend the text properties
  4532. (if (zerop (buffer-size))
  4533. (setq entries nil)
  4534. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4535. (setq entries
  4536. (with-temp-buffer
  4537. (insert entries) (goto-char (point-min))
  4538. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4539. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4540. (replace-match (concat "; " (match-string 1)))))
  4541. (buffer-string)))))
  4542. (set-buffer-modified-p nil)
  4543. (kill-buffer diary-fancy-buffer)))
  4544. (when entries
  4545. (setq entries (org-split-string entries "\n"))
  4546. (setq entries
  4547. (mapcar
  4548. (lambda (x)
  4549. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4550. ;; Extend the text properties to the beginning of the line
  4551. (org-add-props x (text-properties-at (1- (length x)) x)
  4552. 'type "diary" 'date date 'face 'org-agenda-diary))
  4553. entries)))))
  4554. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4555. "Hook run when the fancy diary buffer is cleaned up.")
  4556. (defun org-agenda-cleanup-fancy-diary ()
  4557. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4558. This gets rid of the date, the underline under the date, and
  4559. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4560. date. It also removes lines that contain only whitespace."
  4561. (goto-char (point-min))
  4562. (if (looking-at ".*?:[ \t]*")
  4563. (progn
  4564. (replace-match "")
  4565. (re-search-forward "\n=+$" nil t)
  4566. (replace-match "")
  4567. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4568. (re-search-forward "\n=+$" nil t)
  4569. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4570. (goto-char (point-min))
  4571. (while (re-search-forward "^ +\n" nil t)
  4572. (replace-match ""))
  4573. (goto-char (point-min))
  4574. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4575. (replace-match ""))
  4576. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4577. ;; Make sure entries from the diary have the right text properties.
  4578. (eval-after-load "diary-lib"
  4579. '(if (boundp 'diary-modify-entry-list-string-function)
  4580. ;; We can rely on the hook, nothing to do
  4581. nil
  4582. ;; Hook not available, must use advice to make this work
  4583. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4584. "Make the position visible."
  4585. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4586. (stringp string)
  4587. buffer-file-name)
  4588. (setq string (org-modify-diary-entry-string string))))))
  4589. (defun org-modify-diary-entry-string (string)
  4590. "Add text properties to string, allowing org-mode to act on it."
  4591. (org-add-props string nil
  4592. 'mouse-face 'highlight
  4593. 'help-echo (if buffer-file-name
  4594. (format "mouse-2 or RET jump to diary file %s"
  4595. (abbreviate-file-name buffer-file-name))
  4596. "")
  4597. 'org-agenda-diary-link t
  4598. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4599. (defun org-diary-default-entry ()
  4600. "Add a dummy entry to the diary.
  4601. Needed to avoid empty dates which mess up holiday display."
  4602. ;; Catch the error if dealing with the new add-to-diary-alist
  4603. (when org-disable-agenda-to-diary
  4604. (condition-case nil
  4605. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4606. (error
  4607. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4608. (defun org-add-to-diary-list (&rest args)
  4609. (if (fboundp 'diary-add-to-list)
  4610. (apply 'diary-add-to-list args)
  4611. (apply 'add-to-diary-list args)))
  4612. (defvar org-diary-last-run-time nil)
  4613. ;;;###autoload
  4614. (defun org-diary (&rest args)
  4615. "Return diary information from org files.
  4616. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4617. It accesses org files and extracts information from those files to be
  4618. listed in the diary. The function accepts arguments specifying what
  4619. items should be listed. For a list of arguments allowed here, see the
  4620. variable `org-agenda-entry-types'.
  4621. The call in the diary file should look like this:
  4622. &%%(org-diary) ~/path/to/some/orgfile.org
  4623. Use a separate line for each org file to check. Or, if you omit the file name,
  4624. all files listed in `org-agenda-files' will be checked automatically:
  4625. &%%(org-diary)
  4626. If you don't give any arguments (as in the example above), the default
  4627. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4628. So the example above may also be written as
  4629. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4630. The function expects the lisp variables `entry' and `date' to be provided
  4631. by the caller, because this is how the calendar works. Don't use this
  4632. function from a program - use `org-agenda-get-day-entries' instead."
  4633. (when (> (- (org-float-time)
  4634. org-agenda-last-marker-time)
  4635. 5)
  4636. ;; I am not sure if this works with sticky agendas, because the marker
  4637. ;; list is then no longer a global variable.
  4638. (org-agenda-reset-markers))
  4639. (org-compile-prefix-format 'agenda)
  4640. (org-set-sorting-strategy 'agenda)
  4641. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4642. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4643. (list entry)
  4644. (org-agenda-files t)))
  4645. (time (org-float-time))
  4646. file rtn results)
  4647. (when (or (not org-diary-last-run-time)
  4648. (> (- time
  4649. org-diary-last-run-time)
  4650. 3))
  4651. (org-agenda-prepare-buffers files))
  4652. (setq org-diary-last-run-time time)
  4653. ;; If this is called during org-agenda, don't return any entries to
  4654. ;; the calendar. Org Agenda will list these entries itself.
  4655. (if org-disable-agenda-to-diary (setq files nil))
  4656. (while (setq file (pop files))
  4657. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4658. (setq results (append results rtn)))
  4659. (if results
  4660. (concat (org-agenda-finalize-entries results) "\n"))))
  4661. (autoload 'org-diary "org-agenda" "\
  4662. Return diary information from org files.
  4663. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4664. It accesses org files and extracts information from those files to be
  4665. listed in the diary. The function accepts arguments specifying what
  4666. items should be listed. For a list of arguments allowed here, see the
  4667. variable `org-agenda-entry-types'.
  4668. The call in the diary file should look like this:
  4669. &%%(org-diary) ~/path/to/some/orgfile.org
  4670. Use a separate line for each org file to check. Or, if you omit the file name,
  4671. all files listed in `org-agenda-files' will be checked automatically:
  4672. &%%(org-diary)
  4673. If you don't give any arguments (as in the example above), the default
  4674. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4675. So the example above may also be written as
  4676. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4677. The function expects the lisp variables `entry' and `date' to be provided
  4678. by the caller, because this is how the calendar works. Don't use this
  4679. function from a program - use `org-agenda-get-day-entries' instead.
  4680. \(fn &rest ARGS)" nil nil)
  4681. ;;; Agenda entry finders
  4682. (defun org-agenda-get-day-entries (file date &rest args)
  4683. "Does the work for `org-diary' and `org-agenda'.
  4684. FILE is the path to a file to be checked for entries. DATE is date like
  4685. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4686. which kind of entries should be extracted. For details about these, see
  4687. the documentation of `org-diary'."
  4688. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4689. (let* ((org-startup-folded nil)
  4690. (org-startup-align-all-tables nil)
  4691. (buffer (if (file-exists-p file)
  4692. (org-get-agenda-file-buffer file)
  4693. (error "No such file %s" file)))
  4694. arg results rtn deadline-results)
  4695. (if (not buffer)
  4696. ;; If file does not exist, make sure an error message ends up in diary
  4697. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4698. (with-current-buffer buffer
  4699. (unless (derived-mode-p 'org-mode)
  4700. (error "Agenda file %s is not in `org-mode'" file))
  4701. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4702. (let ((case-fold-search nil))
  4703. (save-excursion
  4704. (save-restriction
  4705. (if org-agenda-restrict
  4706. (narrow-to-region org-agenda-restrict-begin
  4707. org-agenda-restrict-end)
  4708. (widen))
  4709. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4710. (while (setq arg (pop args))
  4711. (cond
  4712. ((and (eq arg :todo)
  4713. (equal date (calendar-gregorian-from-absolute
  4714. (org-today))))
  4715. (setq rtn (org-agenda-get-todos))
  4716. (setq results (append results rtn)))
  4717. ((eq arg :timestamp)
  4718. (setq rtn (org-agenda-get-blocks))
  4719. (setq results (append results rtn))
  4720. (setq rtn (org-agenda-get-timestamps deadline-results))
  4721. (setq results (append results rtn)))
  4722. ((eq arg :sexp)
  4723. (setq rtn (org-agenda-get-sexps))
  4724. (setq results (append results rtn)))
  4725. ((eq arg :scheduled)
  4726. (setq rtn (org-agenda-get-scheduled deadline-results))
  4727. (setq results (append results rtn)))
  4728. ((eq arg :closed)
  4729. (setq rtn (org-agenda-get-progress))
  4730. (setq results (append results rtn)))
  4731. ((eq arg :deadline)
  4732. (setq rtn (org-agenda-get-deadlines))
  4733. (setq deadline-results (copy-sequence rtn))
  4734. (setq results (append results rtn))))))))
  4735. results))))
  4736. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4737. (defun org-agenda-get-todos ()
  4738. "Return the TODO information for agenda display."
  4739. (let* ((props (list 'face nil
  4740. 'done-face 'org-agenda-done
  4741. 'org-not-done-regexp org-not-done-regexp
  4742. 'org-todo-regexp org-todo-regexp
  4743. 'org-complex-heading-regexp org-complex-heading-regexp
  4744. 'mouse-face 'highlight
  4745. 'help-echo
  4746. (format "mouse-2 or RET jump to org file %s"
  4747. (abbreviate-file-name buffer-file-name))))
  4748. (regexp (format org-heading-keyword-regexp-format
  4749. (cond
  4750. ((and org-select-this-todo-keyword
  4751. (equal org-select-this-todo-keyword "*"))
  4752. org-todo-regexp)
  4753. (org-select-this-todo-keyword
  4754. (concat "\\("
  4755. (mapconcat 'identity
  4756. (org-split-string
  4757. org-select-this-todo-keyword
  4758. "|")
  4759. "\\|") "\\)"))
  4760. (t org-not-done-regexp))))
  4761. marker priority category category-pos tags todo-state
  4762. ee txt beg end)
  4763. (goto-char (point-min))
  4764. (while (re-search-forward regexp nil t)
  4765. (catch :skip
  4766. (save-match-data
  4767. (beginning-of-line)
  4768. (org-agenda-skip)
  4769. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4770. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4771. (goto-char (1+ beg))
  4772. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4773. (throw :skip nil)))
  4774. (goto-char (match-beginning 2))
  4775. (setq marker (org-agenda-new-marker (match-beginning 0))
  4776. category (org-get-category)
  4777. category-pos (get-text-property (point) 'org-category-position)
  4778. txt (org-trim
  4779. (buffer-substring (match-beginning 2) (match-end 0)))
  4780. tags (org-get-tags-at (point))
  4781. txt (org-agenda-format-item "" txt category tags t)
  4782. priority (1+ (org-get-priority txt))
  4783. todo-state (org-get-todo-state))
  4784. (org-add-props txt props
  4785. 'org-marker marker 'org-hd-marker marker
  4786. 'priority priority 'org-category category
  4787. 'org-category-position category-pos
  4788. 'type "todo" 'todo-state todo-state)
  4789. (push txt ee)
  4790. (if org-agenda-todo-list-sublevels
  4791. (goto-char (match-end 2))
  4792. (org-end-of-subtree 'invisible))))
  4793. (nreverse ee)))
  4794. (defun org-agenda-todo-custom-ignore-p (time n)
  4795. "Check whether timestamp is farther away than n number of days.
  4796. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4797. `org-agenda-todo-ignore-scheduled' or
  4798. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4799. (let ((days (org-days-to-time time)))
  4800. (if (>= n 0)
  4801. (>= days n)
  4802. (<= days n))))
  4803. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4804. (&optional end)
  4805. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4806. (when (or org-agenda-todo-ignore-with-date
  4807. org-agenda-todo-ignore-scheduled
  4808. org-agenda-todo-ignore-deadlines
  4809. org-agenda-todo-ignore-timestamp)
  4810. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4811. (save-excursion
  4812. (or (and org-agenda-todo-ignore-with-date
  4813. (re-search-forward org-ts-regexp end t))
  4814. (and org-agenda-todo-ignore-scheduled
  4815. (re-search-forward org-scheduled-time-regexp end t)
  4816. (cond
  4817. ((eq org-agenda-todo-ignore-scheduled 'future)
  4818. (> (org-days-to-time (match-string 1)) 0))
  4819. ((eq org-agenda-todo-ignore-scheduled 'past)
  4820. (<= (org-days-to-time (match-string 1)) 0))
  4821. ((numberp org-agenda-todo-ignore-scheduled)
  4822. (org-agenda-todo-custom-ignore-p
  4823. (match-string 1) org-agenda-todo-ignore-scheduled))
  4824. (t)))
  4825. (and org-agenda-todo-ignore-deadlines
  4826. (re-search-forward org-deadline-time-regexp end t)
  4827. (cond
  4828. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4829. ((eq org-agenda-todo-ignore-deadlines 'far)
  4830. (not (org-deadline-close (match-string 1))))
  4831. ((eq org-agenda-todo-ignore-deadlines 'future)
  4832. (> (org-days-to-time (match-string 1)) 0))
  4833. ((eq org-agenda-todo-ignore-deadlines 'past)
  4834. (<= (org-days-to-time (match-string 1)) 0))
  4835. ((numberp org-agenda-todo-ignore-deadlines)
  4836. (org-agenda-todo-custom-ignore-p
  4837. (match-string 1) org-agenda-todo-ignore-deadlines))
  4838. (t (org-deadline-close (match-string 1)))))
  4839. (and org-agenda-todo-ignore-timestamp
  4840. (let ((buffer (current-buffer))
  4841. (regexp
  4842. (concat
  4843. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4844. (start (point)))
  4845. ;; Copy current buffer into a temporary one
  4846. (with-temp-buffer
  4847. (insert-buffer-substring buffer start end)
  4848. (goto-char (point-min))
  4849. ;; Delete SCHEDULED and DEADLINE items
  4850. (while (re-search-forward regexp end t)
  4851. (delete-region (match-beginning 0) (match-end 0)))
  4852. (goto-char (point-min))
  4853. ;; No search for timestamp left
  4854. (when (re-search-forward org-ts-regexp nil t)
  4855. (cond
  4856. ((eq org-agenda-todo-ignore-timestamp 'future)
  4857. (> (org-days-to-time (match-string 1)) 0))
  4858. ((eq org-agenda-todo-ignore-timestamp 'past)
  4859. (<= (org-days-to-time (match-string 1)) 0))
  4860. ((numberp org-agenda-todo-ignore-timestamp)
  4861. (org-agenda-todo-custom-ignore-p
  4862. (match-string 1) org-agenda-todo-ignore-timestamp))
  4863. (t))))))))))
  4864. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4865. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4866. \(fn &optional END)" nil nil)
  4867. (defconst org-agenda-no-heading-message
  4868. "No heading for this item in buffer or region.")
  4869. (defun org-agenda-get-timestamps (&optional deadline-results)
  4870. "Return the date stamp information for agenda display."
  4871. (let* ((props (list 'face 'org-agenda-calendar-event
  4872. 'org-not-done-regexp org-not-done-regexp
  4873. 'org-todo-regexp org-todo-regexp
  4874. 'org-complex-heading-regexp org-complex-heading-regexp
  4875. 'mouse-face 'highlight
  4876. 'help-echo
  4877. (format "mouse-2 or RET jump to org file %s"
  4878. (abbreviate-file-name buffer-file-name))))
  4879. (d1 (calendar-absolute-from-gregorian date))
  4880. mm
  4881. (deadline-position-alist
  4882. (mapcar (lambda (a) (and (setq mm (get-text-property
  4883. 0 'org-hd-marker a))
  4884. (cons (marker-position mm) a)))
  4885. deadline-results))
  4886. (remove-re org-ts-regexp)
  4887. (regexp
  4888. (concat
  4889. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4890. (regexp-quote
  4891. (substring
  4892. (format-time-string
  4893. (car org-time-stamp-formats)
  4894. (apply 'encode-time ; DATE bound by calendar
  4895. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4896. 1 11))
  4897. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4898. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4899. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4900. donep tmp priority category category-pos ee txt timestr tags
  4901. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  4902. (goto-char (point-min))
  4903. (while (setq end-of-match (re-search-forward regexp nil t))
  4904. (setq b0 (match-beginning 0)
  4905. b3 (match-beginning 3) e3 (match-end 3)
  4906. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4907. habitp (and (functionp 'org-is-habit-p) (org-is-habit-p))
  4908. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4909. (member todo-state
  4910. org-agenda-repeating-timestamp-show-all)))
  4911. (catch :skip
  4912. (and (org-at-date-range-p) (throw :skip nil))
  4913. (org-agenda-skip)
  4914. (if (and (match-end 1)
  4915. (not (= d1 (org-time-string-to-absolute
  4916. (match-string 1) d1 nil show-all
  4917. (current-buffer) b0))))
  4918. (throw :skip nil))
  4919. (if (and e3
  4920. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4921. (throw :skip nil))
  4922. (setq tmp (buffer-substring (max (point-min)
  4923. (- b0 org-ds-keyword-length))
  4924. b0)
  4925. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4926. inactivep (= (char-after b0) ?\[)
  4927. deadlinep (string-match org-deadline-regexp tmp)
  4928. scheduledp (string-match org-scheduled-regexp tmp)
  4929. closedp (and org-agenda-include-inactive-timestamps
  4930. (string-match org-closed-string tmp))
  4931. clockp (and org-agenda-include-inactive-timestamps
  4932. (or (string-match org-clock-string tmp)
  4933. (string-match "]-+\\'" tmp)))
  4934. warntime (org-entry-get (point) "APPT_WARNTIME")
  4935. donep (member todo-state org-done-keywords))
  4936. (if (or scheduledp deadlinep closedp clockp
  4937. (and donep org-agenda-skip-timestamp-if-done))
  4938. (throw :skip t))
  4939. (if (string-match ">" timestr)
  4940. ;; substring should only run to end of time stamp
  4941. (setq timestr (substring timestr 0 (match-end 0))))
  4942. (setq marker (org-agenda-new-marker b0)
  4943. category (org-get-category b0)
  4944. category-pos (get-text-property b0 'org-category-position))
  4945. (save-excursion
  4946. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4947. (setq txt org-agenda-no-heading-message)
  4948. (goto-char (match-beginning 0))
  4949. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4950. (assoc (point) deadline-position-alist))
  4951. (throw :skip nil))
  4952. (setq hdmarker (org-agenda-new-marker)
  4953. tags (org-get-tags-at))
  4954. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4955. (setq head (or (match-string 1) ""))
  4956. (setq txt (org-agenda-format-item
  4957. (if inactivep org-agenda-inactive-leader nil)
  4958. head category tags timestr
  4959. remove-re habitp)))
  4960. (setq priority (org-get-priority txt))
  4961. (org-add-props txt props
  4962. 'org-marker marker 'org-hd-marker hdmarker)
  4963. (org-add-props txt nil 'priority priority
  4964. 'org-category category 'date date
  4965. 'org-category-position category-pos
  4966. 'todo-state todo-state
  4967. 'warntime warntime
  4968. 'type "timestamp")
  4969. (push txt ee))
  4970. (if org-agenda-skip-additional-timestamps-same-entry
  4971. (outline-next-heading)
  4972. (goto-char end-of-match))))
  4973. (nreverse ee)))
  4974. (defun org-agenda-get-sexps ()
  4975. "Return the sexp information for agenda display."
  4976. (require 'diary-lib)
  4977. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4978. 'mouse-face 'highlight
  4979. 'help-echo
  4980. (format "mouse-2 or RET jump to org file %s"
  4981. (abbreviate-file-name buffer-file-name))))
  4982. (regexp "^&?%%(")
  4983. marker category extra category-pos ee txt tags entry
  4984. result beg b sexp sexp-entry todo-state warntime)
  4985. (goto-char (point-min))
  4986. (while (re-search-forward regexp nil t)
  4987. (catch :skip
  4988. (org-agenda-skip)
  4989. (setq beg (match-beginning 0))
  4990. (goto-char (1- (match-end 0)))
  4991. (setq b (point))
  4992. (forward-sexp 1)
  4993. (setq sexp (buffer-substring b (point)))
  4994. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4995. (org-trim (match-string 1))
  4996. ""))
  4997. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4998. (when result
  4999. (setq marker (org-agenda-new-marker beg)
  5000. category (org-get-category beg)
  5001. category-pos (get-text-property beg 'org-category-position)
  5002. tags (save-excursion (org-backward-heading-same-level 0)
  5003. (org-get-tags-at))
  5004. todo-state (org-get-todo-state)
  5005. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5006. (dolist (r (if (stringp result)
  5007. (list result)
  5008. result)) ;; we expect a list here
  5009. (when (and org-agenda-diary-sexp-prefix
  5010. (string-match org-agenda-diary-sexp-prefix r))
  5011. (setq extra (match-string 0 r)
  5012. r (replace-match "" nil nil r)))
  5013. (if (string-match "\\S-" r)
  5014. (setq txt r)
  5015. (setq txt "SEXP entry returned empty string"))
  5016. (setq txt (org-agenda-format-item
  5017. extra txt category tags 'time))
  5018. (org-add-props txt props 'org-marker marker)
  5019. (org-add-props txt nil
  5020. 'org-category category 'date date 'todo-state todo-state
  5021. 'org-category-position category-pos 'tags tags
  5022. 'type "sexp" 'warntime warntime)
  5023. (push txt ee)))))
  5024. (nreverse ee)))
  5025. ;; Calendar sanity: define some functions that are independent of
  5026. ;; `calendar-date-style'.
  5027. ;; Normally I would like to use ISO format when calling the diary functions,
  5028. ;; but to make sure we still have Emacs 22 compatibility we bind
  5029. ;; also `european-calendar-style' and use european format
  5030. (defun org-anniversary (year month day &optional mark)
  5031. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5032. (org-no-warnings
  5033. (let ((calendar-date-style 'european) (european-calendar-style t))
  5034. (diary-anniversary day month year mark))))
  5035. (defun org-cyclic (N year month day &optional mark)
  5036. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5037. (org-no-warnings
  5038. (let ((calendar-date-style 'european) (european-calendar-style t))
  5039. (diary-cyclic N day month year mark))))
  5040. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5041. "Like `diary-block', but with fixed (ISO) order of arguments."
  5042. (org-no-warnings
  5043. (let ((calendar-date-style 'european) (european-calendar-style t))
  5044. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5045. (defun org-date (year month day &optional mark)
  5046. "Like `diary-date', but with fixed (ISO) order of arguments."
  5047. (org-no-warnings
  5048. (let ((calendar-date-style 'european) (european-calendar-style t))
  5049. (diary-date day month year mark))))
  5050. (defalias 'org-float 'diary-float)
  5051. ;; Define the` org-class' function
  5052. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5053. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5054. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5055. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5056. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5057. `holidays', then any date that is known by the Emacs calendar to be a
  5058. holiday will also be skipped."
  5059. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5060. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5061. (d (calendar-absolute-from-gregorian date)))
  5062. (and
  5063. (<= date1 d)
  5064. (<= d date2)
  5065. (= (calendar-day-of-week date) dayname)
  5066. (or (not skip-weeks)
  5067. (progn
  5068. (require 'cal-iso)
  5069. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5070. (not (and (memq 'holidays skip-weeks)
  5071. (calendar-check-holidays date)))
  5072. entry)))
  5073. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5074. "Like `org-class', but honor `calendar-date-style'.
  5075. The order of the first 2 times 3 arguments depends on the variable
  5076. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5077. So for American calendars, give this as MONTH DAY YEAR, for European as
  5078. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5079. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5080. is any number of ISO weeks in the block period for which the item should
  5081. be skipped.
  5082. This function is here only for backward compatibility and it is deprecated,
  5083. please use `org-class' instead."
  5084. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5085. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5086. (org-class
  5087. (nth 2 date1) (car date1) (nth 1 date1)
  5088. (nth 2 date2) (car date2) (nth 1 date2)
  5089. dayname skip-weeks)))
  5090. (make-obsolete 'org-diary-class 'org-class "")
  5091. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5092. (defalias 'org-get-closed 'org-agenda-get-progress)
  5093. (defun org-agenda-get-progress ()
  5094. "Return the logged TODO entries for agenda display."
  5095. (let* ((props (list 'mouse-face 'highlight
  5096. 'org-not-done-regexp org-not-done-regexp
  5097. 'org-todo-regexp org-todo-regexp
  5098. 'org-complex-heading-regexp org-complex-heading-regexp
  5099. 'help-echo
  5100. (format "mouse-2 or RET jump to org file %s"
  5101. (abbreviate-file-name buffer-file-name))))
  5102. (items (if (consp org-agenda-show-log-scoped)
  5103. org-agenda-show-log-scoped
  5104. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5105. '(clock)
  5106. org-agenda-log-mode-items)))
  5107. (parts
  5108. (delq nil
  5109. (list
  5110. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5111. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5112. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5113. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5114. (error "`org-agenda-log-mode-items' is empty")))
  5115. (regexp (concat
  5116. "\\(" parts-re "\\)"
  5117. " *\\["
  5118. (regexp-quote
  5119. (substring
  5120. (format-time-string
  5121. (car org-time-stamp-formats)
  5122. (apply 'encode-time ; DATE bound by calendar
  5123. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5124. 1 11))))
  5125. (org-agenda-search-headline-for-time nil)
  5126. marker hdmarker priority category category-pos tags closedp
  5127. statep clockp state ee txt extra timestr rest clocked)
  5128. (goto-char (point-min))
  5129. (while (re-search-forward regexp nil t)
  5130. (catch :skip
  5131. (org-agenda-skip)
  5132. (setq marker (org-agenda-new-marker (match-beginning 0))
  5133. closedp (equal (match-string 1) org-closed-string)
  5134. statep (equal (string-to-char (match-string 1)) ?-)
  5135. clockp (not (or closedp statep))
  5136. state (and statep (match-string 2))
  5137. category (org-get-category (match-beginning 0))
  5138. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5139. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5140. (when (string-match "\\]" timestr)
  5141. ;; substring should only run to end of time stamp
  5142. (setq rest (substring timestr (match-end 0))
  5143. timestr (substring timestr 0 (match-end 0)))
  5144. (if (and (not closedp) (not statep)
  5145. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5146. rest))
  5147. (progn (setq timestr (concat (substring timestr 0 -1)
  5148. "-" (match-string 1 rest) "]"))
  5149. (setq clocked (match-string 2 rest)))
  5150. (setq clocked "-")))
  5151. (save-excursion
  5152. (setq extra
  5153. (cond
  5154. ((not org-agenda-log-mode-add-notes) nil)
  5155. (statep
  5156. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5157. (match-string 1)))
  5158. (clockp
  5159. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5160. (match-string 1)))))
  5161. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5162. (setq txt org-agenda-no-heading-message)
  5163. (goto-char (match-beginning 0))
  5164. (setq hdmarker (org-agenda-new-marker)
  5165. tags (org-get-tags-at))
  5166. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5167. (setq txt (match-string 1))
  5168. (when extra
  5169. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5170. (setq txt (concat (substring txt 0 (match-beginning 1))
  5171. " - " extra " " (match-string 2 txt)))
  5172. (setq txt (concat txt " - " extra))))
  5173. (setq txt (org-agenda-format-item
  5174. (cond
  5175. (closedp "Closed: ")
  5176. (statep (concat "State: (" state ")"))
  5177. (t (concat "Clocked: (" clocked ")")))
  5178. txt category tags timestr)))
  5179. (setq priority 100000)
  5180. (org-add-props txt props
  5181. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5182. 'priority priority 'org-category category
  5183. 'org-category-position category-pos
  5184. 'type "closed" 'date date
  5185. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5186. (push txt ee))
  5187. (goto-char (point-at-eol))))
  5188. (nreverse ee)))
  5189. (defun org-agenda-show-clocking-issues ()
  5190. "Add overlays, showing issues with clocking.
  5191. See also the user option `org-agenda-clock-consistency-checks'."
  5192. (interactive)
  5193. (let* ((pl org-agenda-clock-consistency-checks)
  5194. (re (concat "^[ \t]*"
  5195. org-clock-string
  5196. "[ \t]+"
  5197. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5198. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5199. (tlstart 0.)
  5200. (tlend 0.)
  5201. (maxtime (org-hh:mm-string-to-minutes
  5202. (or (plist-get pl :max-duration) "24:00")))
  5203. (mintime (org-hh:mm-string-to-minutes
  5204. (or (plist-get pl :min-duration) 0)))
  5205. (maxgap (org-hh:mm-string-to-minutes
  5206. ;; default 30:00 means never complain
  5207. (or (plist-get pl :max-gap) "30:00")))
  5208. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5209. (plist-get pl :gap-ok-around)))
  5210. (def-face (or (plist-get pl :default-face)
  5211. '((:background "DarkRed") (:foreground "white"))))
  5212. issue face m te ts dt ov)
  5213. (goto-char (point-min))
  5214. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5215. (setq issue nil face def-face)
  5216. (catch 'next
  5217. (setq m (org-get-at-bol 'org-marker)
  5218. te nil ts nil)
  5219. (unless (and m (markerp m))
  5220. (setq issue "No valid clock line") (throw 'next t))
  5221. (org-with-point-at m
  5222. (save-excursion
  5223. (goto-char (point-at-bol))
  5224. (unless (looking-at re)
  5225. (error "No valid Clock line")
  5226. (throw 'next t))
  5227. (unless (match-end 3)
  5228. (setq issue "No end time"
  5229. face (or (plist-get pl :no-end-time-face) face))
  5230. (throw 'next t))
  5231. (setq ts (match-string 1)
  5232. te (match-string 3)
  5233. ts (org-float-time
  5234. (apply 'encode-time (org-parse-time-string ts)))
  5235. te (org-float-time
  5236. (apply 'encode-time (org-parse-time-string te)))
  5237. dt (- te ts))))
  5238. (cond
  5239. ((> dt (* 60 maxtime))
  5240. ;; a very long clocking chunk
  5241. (setq issue (format "Clocking interval is very long: %s"
  5242. (org-minutes-to-hh:mm-string
  5243. (floor (/ (float dt) 60.))))
  5244. face (or (plist-get pl :long-face) face)))
  5245. ((< dt (* 60 mintime))
  5246. ;; a very short clocking chunk
  5247. (setq issue (format "Clocking interval is very short: %s"
  5248. (org-minutes-to-hh:mm-string
  5249. (floor (/ (float dt) 60.))))
  5250. face (or (plist-get pl :short-face) face)))
  5251. ((and (> tlend 0) (< ts tlend))
  5252. ;; Two clock entries are overlapping
  5253. (setq issue (format "Clocking overlap: %d minutes"
  5254. (/ (- tlend ts) 60))
  5255. face (or (plist-get pl :overlap-face) face)))
  5256. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5257. ;; There is a gap, lets see if we need to report it
  5258. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5259. (setq issue (format "Clocking gap: %d minutes"
  5260. (/ (- ts tlend) 60))
  5261. face (or (plist-get pl :gap-face) face))))
  5262. (t nil)))
  5263. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5264. (when issue
  5265. ;; OK, there was some issue, add an overlay to show the issue
  5266. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5267. (overlay-put ov 'before-string
  5268. (concat
  5269. (org-add-props
  5270. (format "%-43s" (concat " " issue))
  5271. nil
  5272. 'face face)
  5273. "\n"))
  5274. (overlay-put ov 'evaporate t)))))
  5275. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5276. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5277. (catch 'exit
  5278. (unless ok-list
  5279. ;; there are no OK times for gaps...
  5280. (throw 'exit nil))
  5281. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5282. ;; This is more than 24 hours, so it is OK.
  5283. ;; because we have at least one OK time, that must be in the
  5284. ;; 24 hour interval.
  5285. (throw 'exit t))
  5286. ;; We have a shorter gap.
  5287. ;; Now we have to get the minute of the day when these times are
  5288. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5289. (t2dec (decode-time (seconds-to-time t2)))
  5290. ;; compute the minute on the day
  5291. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5292. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5293. (when (< min2 min1)
  5294. ;; if min2 is smaller than min1, this means it is on the next day.
  5295. ;; Wrap it to after midnight.
  5296. (setq min2 (+ min2 1440)))
  5297. ;; Now check if any of the OK times is in the gap
  5298. (mapc (lambda (x)
  5299. ;; Wrap the time to after midnight if necessary
  5300. (if (< x min1) (setq x (+ x 1440)))
  5301. ;; Check if in interval
  5302. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5303. ok-list)
  5304. ;; Nope, this gap is not OK
  5305. nil)))
  5306. (defun org-agenda-get-deadlines ()
  5307. "Return the deadline information for agenda display."
  5308. (let* ((props (list 'mouse-face 'highlight
  5309. 'org-not-done-regexp org-not-done-regexp
  5310. 'org-todo-regexp org-todo-regexp
  5311. 'org-complex-heading-regexp org-complex-heading-regexp
  5312. 'help-echo
  5313. (format "mouse-2 or RET jump to org file %s"
  5314. (abbreviate-file-name buffer-file-name))))
  5315. (regexp org-deadline-time-regexp)
  5316. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5317. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5318. d2 diff dfrac wdays pos pos1 category category-pos
  5319. tags suppress-prewarning ee txt head face s todo-state
  5320. show-all upcomingp donep timestr warntime)
  5321. (goto-char (point-min))
  5322. (while (re-search-forward regexp nil t)
  5323. (setq suppress-prewarning nil)
  5324. (catch :skip
  5325. (org-agenda-skip)
  5326. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5327. (save-match-data
  5328. (string-match org-scheduled-time-regexp
  5329. (buffer-substring (point-at-bol)
  5330. (point-at-eol)))))
  5331. (setq suppress-prewarning
  5332. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5333. org-agenda-skip-deadline-prewarning-if-scheduled
  5334. 0)))
  5335. (setq s (match-string 1)
  5336. txt nil
  5337. pos (1- (match-beginning 1))
  5338. todo-state (save-match-data (org-get-todo-state))
  5339. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5340. (member todo-state
  5341. org-agenda-repeating-timestamp-show-all))
  5342. d2 (org-time-string-to-absolute
  5343. (match-string 1) d1 'past show-all
  5344. (current-buffer) pos)
  5345. diff (- d2 d1)
  5346. wdays (if suppress-prewarning
  5347. (let ((org-deadline-warning-days suppress-prewarning))
  5348. (org-get-wdays s))
  5349. (org-get-wdays s))
  5350. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5351. upcomingp (and todayp (> diff 0)))
  5352. ;; When to show a deadline in the calendar:
  5353. ;; If the expiration is within wdays warning time.
  5354. ;; Past-due deadlines are only shown on the current date
  5355. (if (and (or (and (<= diff wdays)
  5356. (and todayp (not org-agenda-only-exact-dates)))
  5357. (= diff 0)))
  5358. (save-excursion
  5359. ;; (setq todo-state (org-get-todo-state))
  5360. (setq donep (member todo-state org-done-keywords))
  5361. (if (and donep
  5362. (or org-agenda-skip-deadline-if-done
  5363. (not (= diff 0))))
  5364. (setq txt nil)
  5365. (setq category (org-get-category)
  5366. warntime (org-entry-get (point) "APPT_WARNTIME")
  5367. category-pos (get-text-property (point) 'org-category-position))
  5368. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5369. (setq txt org-agenda-no-heading-message)
  5370. (goto-char (match-end 0))
  5371. (setq pos1 (match-beginning 0))
  5372. (setq tags (org-get-tags-at pos1))
  5373. (setq head (buffer-substring-no-properties
  5374. (point)
  5375. (progn (skip-chars-forward "^\r\n")
  5376. (point))))
  5377. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5378. (setq timestr
  5379. (concat (substring s (match-beginning 1)) " "))
  5380. (setq timestr 'time))
  5381. (setq txt (org-agenda-format-item
  5382. (if (= diff 0)
  5383. (car org-agenda-deadline-leaders)
  5384. (if (functionp
  5385. (nth 1 org-agenda-deadline-leaders))
  5386. (funcall
  5387. (nth 1 org-agenda-deadline-leaders)
  5388. diff date)
  5389. (format (nth 1 org-agenda-deadline-leaders)
  5390. diff)))
  5391. head category tags
  5392. (if (not (= diff 0)) nil timestr)))))
  5393. (when txt
  5394. (setq face (org-agenda-deadline-face dfrac))
  5395. (org-add-props txt props
  5396. 'org-marker (org-agenda-new-marker pos)
  5397. 'warntime warntime
  5398. 'org-hd-marker (org-agenda-new-marker pos1)
  5399. 'priority (+ (- diff)
  5400. (org-get-priority txt))
  5401. 'org-category category
  5402. 'org-category-position category-pos
  5403. 'todo-state todo-state
  5404. 'type (if upcomingp "upcoming-deadline" "deadline")
  5405. 'date (if upcomingp date d2)
  5406. 'face (if donep 'org-agenda-done face)
  5407. 'undone-face face 'done-face 'org-agenda-done)
  5408. (push txt ee))))))
  5409. (nreverse ee)))
  5410. (defun org-agenda-deadline-face (fraction)
  5411. "Return the face to displaying a deadline item.
  5412. FRACTION is what fraction of the head-warning time has passed."
  5413. (let ((faces org-agenda-deadline-faces) f)
  5414. (catch 'exit
  5415. (while (setq f (pop faces))
  5416. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5417. (defun org-agenda-get-scheduled (&optional deadline-results)
  5418. "Return the scheduled information for agenda display."
  5419. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5420. 'org-todo-regexp org-todo-regexp
  5421. 'org-complex-heading-regexp org-complex-heading-regexp
  5422. 'done-face 'org-agenda-done
  5423. 'mouse-face 'highlight
  5424. 'help-echo
  5425. (format "mouse-2 or RET jump to org file %s"
  5426. (abbreviate-file-name buffer-file-name))))
  5427. (regexp org-scheduled-time-regexp)
  5428. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5429. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5430. mm
  5431. (deadline-position-alist
  5432. (mapcar (lambda (a) (and (setq mm (get-text-property
  5433. 0 'org-hd-marker a))
  5434. (cons (marker-position mm) a)))
  5435. deadline-results))
  5436. d2 diff pos pos1 category category-pos tags donep
  5437. ee txt head pastschedp todo-state face timestr s habitp show-all
  5438. did-habit-check-p warntime)
  5439. (goto-char (point-min))
  5440. (while (re-search-forward regexp nil t)
  5441. (catch :skip
  5442. (org-agenda-skip)
  5443. (setq s (match-string 1)
  5444. txt nil
  5445. pos (1- (match-beginning 1))
  5446. todo-state (save-match-data (org-get-todo-state))
  5447. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5448. (member todo-state
  5449. org-agenda-repeating-timestamp-show-all))
  5450. d2 (org-time-string-to-absolute
  5451. (match-string 1) d1 'past show-all
  5452. (current-buffer) pos)
  5453. diff (- d2 d1)
  5454. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5455. (setq pastschedp (and todayp (< diff 0)))
  5456. (setq did-habit-check-p nil)
  5457. ;; When to show a scheduled item in the calendar:
  5458. ;; If it is on or past the date.
  5459. (when (or (and (< diff 0)
  5460. (< (abs diff) org-scheduled-past-days)
  5461. (and todayp (not org-agenda-only-exact-dates)))
  5462. (= diff 0)
  5463. ;; org-is-habit-p uses org-entry-get, which is expansive
  5464. ;; so we go extra mile to only call it once
  5465. (and todayp
  5466. (boundp 'org-habit-show-all-today)
  5467. org-habit-show-all-today
  5468. (setq did-habit-check-p t)
  5469. (setq habitp (and (functionp 'org-is-habit-p)
  5470. (org-is-habit-p)))))
  5471. (save-excursion
  5472. (setq donep (member todo-state org-done-keywords))
  5473. (if (and donep
  5474. (or org-agenda-skip-scheduled-if-done
  5475. (not (= diff 0))
  5476. (and (functionp 'org-is-habit-p)
  5477. (org-is-habit-p))))
  5478. (setq txt nil)
  5479. (setq habitp (if did-habit-check-p habitp
  5480. (and (functionp 'org-is-habit-p)
  5481. (org-is-habit-p))))
  5482. (setq category (org-get-category)
  5483. category-pos (get-text-property (point) 'org-category-position))
  5484. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5485. (setq txt org-agenda-no-heading-message)
  5486. (goto-char (match-end 0))
  5487. (setq pos1 (match-beginning 0))
  5488. (if habitp
  5489. (if (or (not org-habit-show-habits)
  5490. (and (not todayp)
  5491. (boundp 'org-habit-show-habits-only-for-today)
  5492. org-habit-show-habits-only-for-today))
  5493. (throw :skip nil))
  5494. (if (and
  5495. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5496. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5497. pastschedp))
  5498. (setq mm (assoc pos1 deadline-position-alist)))
  5499. (throw :skip nil)))
  5500. (setq tags (org-get-tags-at))
  5501. (setq head (buffer-substring-no-properties
  5502. (point)
  5503. (progn (skip-chars-forward "^\r\n") (point))))
  5504. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5505. (setq timestr
  5506. (concat (substring s (match-beginning 1)) " "))
  5507. (setq timestr 'time))
  5508. (setq txt (org-agenda-format-item
  5509. (if (= diff 0)
  5510. (car org-agenda-scheduled-leaders)
  5511. (format (nth 1 org-agenda-scheduled-leaders)
  5512. (- 1 diff)))
  5513. head category tags
  5514. (if (not (= diff 0)) nil timestr)
  5515. nil habitp))))
  5516. (when txt
  5517. (setq face
  5518. (cond
  5519. ((and (not habitp) pastschedp)
  5520. 'org-scheduled-previously)
  5521. (todayp 'org-scheduled-today)
  5522. (t 'org-scheduled))
  5523. habitp (and habitp (org-habit-parse-todo)))
  5524. (org-add-props txt props
  5525. 'undone-face face
  5526. 'face (if donep 'org-agenda-done face)
  5527. 'org-marker (org-agenda-new-marker pos)
  5528. 'org-hd-marker (org-agenda-new-marker pos1)
  5529. 'type (if pastschedp "past-scheduled" "scheduled")
  5530. 'date (if pastschedp d2 date)
  5531. 'warntime warntime
  5532. 'priority (if habitp
  5533. (org-habit-get-priority habitp)
  5534. (+ 94 (- 5 diff) (org-get-priority txt)))
  5535. 'org-category category
  5536. 'category-position category-pos
  5537. 'org-habit-p habitp
  5538. 'todo-state todo-state)
  5539. (push txt ee))))))
  5540. (nreverse ee)))
  5541. (defun org-agenda-get-blocks ()
  5542. "Return the date-range information for agenda display."
  5543. (let* ((props (list 'face nil
  5544. 'org-not-done-regexp org-not-done-regexp
  5545. 'org-todo-regexp org-todo-regexp
  5546. 'org-complex-heading-regexp org-complex-heading-regexp
  5547. 'mouse-face 'highlight
  5548. 'help-echo
  5549. (format "mouse-2 or RET jump to org file %s"
  5550. (abbreviate-file-name buffer-file-name))))
  5551. (regexp org-tr-regexp)
  5552. (d0 (calendar-absolute-from-gregorian date))
  5553. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5554. todo-state tags pos head donep)
  5555. (goto-char (point-min))
  5556. (while (re-search-forward regexp nil t)
  5557. (catch :skip
  5558. (org-agenda-skip)
  5559. (setq pos (point))
  5560. (let ((start-time (match-string 1))
  5561. (end-time (match-string 2)))
  5562. (setq s1 (match-string 1)
  5563. s2 (match-string 2)
  5564. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5565. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5566. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5567. ;; Only allow days between the limits, because the normal
  5568. ;; date stamps will catch the limits.
  5569. (save-excursion
  5570. (setq todo-state (org-get-todo-state))
  5571. (setq donep (member todo-state org-done-keywords))
  5572. (if (and donep org-agenda-skip-timestamp-if-done)
  5573. (throw :skip t))
  5574. (setq marker (org-agenda-new-marker (point)))
  5575. (setq category (org-get-category)
  5576. category-pos (get-text-property (point) 'org-category-position))
  5577. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5578. (setq txt org-agenda-no-heading-message)
  5579. (goto-char (match-beginning 0))
  5580. (setq hdmarker (org-agenda-new-marker (point)))
  5581. (setq tags (org-get-tags-at))
  5582. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5583. (setq head (match-string 1))
  5584. (let ((remove-re
  5585. (if org-agenda-remove-timeranges-from-blocks
  5586. (concat
  5587. "<" (regexp-quote s1) ".*?>"
  5588. "--"
  5589. "<" (regexp-quote s2) ".*?>")
  5590. nil)))
  5591. (setq txt (org-agenda-format-item
  5592. (format
  5593. (nth (if (= d1 d2) 0 1)
  5594. org-agenda-timerange-leaders)
  5595. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5596. head category tags
  5597. (cond ((and (= d1 d0) (= d2 d0))
  5598. (concat "<" start-time ">--<" end-time ">"))
  5599. ((= d1 d0)
  5600. (concat "<" start-time ">"))
  5601. ((= d2 d0)
  5602. (concat "<" end-time ">")))
  5603. remove-re))))
  5604. (org-add-props txt props
  5605. 'org-marker marker 'org-hd-marker hdmarker
  5606. 'type "block" 'date date
  5607. 'todo-state todo-state
  5608. 'priority (org-get-priority txt) 'org-category category
  5609. 'org-category-position category-pos)
  5610. (push txt ee))))
  5611. (goto-char pos)))
  5612. ;; Sort the entries by expiration date.
  5613. (nreverse ee)))
  5614. ;;; Agenda presentation and sorting
  5615. (defvar org-prefix-has-time nil
  5616. "A flag, set by `org-compile-prefix-format'.
  5617. The flag is set if the currently compiled format contains a `%t'.")
  5618. (defvar org-prefix-has-tag nil
  5619. "A flag, set by `org-compile-prefix-format'.
  5620. The flag is set if the currently compiled format contains a `%T'.")
  5621. (defvar org-prefix-has-effort nil
  5622. "A flag, set by `org-compile-prefix-format'.
  5623. The flag is set if the currently compiled format contains a `%e'.")
  5624. (defvar org-prefix-category-length nil
  5625. "Used by `org-compile-prefix-format' to remember the category field width.")
  5626. (defvar org-prefix-category-max-length nil
  5627. "Used by `org-compile-prefix-format' to remember the category field width.")
  5628. (defun org-agenda-get-category-icon (category)
  5629. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5630. (dolist (entry org-agenda-category-icon-alist)
  5631. (when (org-string-match-p (car entry) category)
  5632. (if (listp (cadr entry))
  5633. (return (cadr entry))
  5634. (return (apply 'create-image (cdr entry)))))))
  5635. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5636. remove-re habitp)
  5637. "Format TXT to be inserted into the agenda buffer.
  5638. In particular, it adds the prefix and corresponding text properties. EXTRA
  5639. must be a string and replaces the `%s' specifier in the prefix format.
  5640. CATEGORY (string, symbol or nil) may be used to overrule the default
  5641. category taken from local variable or file name. It will replace the `%c'
  5642. specifier in the format. DOTIME, when non-nil, indicates that a
  5643. time-of-day should be extracted from TXT for sorting of this entry, and for
  5644. the `%t' specifier in the format. When DOTIME is a string, this string is
  5645. searched for a time before TXT is. TAGS can be the tags of the headline.
  5646. Any match of REMOVE-RE will be removed from TXT."
  5647. ;; We keep the org-prefix-* variable values along with a compiled
  5648. ;; formatter, so that multiple agendas existing at the same time, do
  5649. ;; not step on each other toes.
  5650. ;;
  5651. ;; It was inconvenient to make these variables buffer local in
  5652. ;; Agenda buffers, because this function expects to be called with
  5653. ;; the buffer where item comes from being current, and not agenda
  5654. ;; buffer
  5655. (let* ((bindings (car org-prefix-format-compiled))
  5656. (formatter (cadr org-prefix-format-compiled)))
  5657. (loop for (var value) in bindings
  5658. do (set var value))
  5659. (save-match-data
  5660. ;; Diary entries sometimes have extra whitespace at the beginning
  5661. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5662. ;; Fix the tags part in txt
  5663. (setq txt (org-agenda-fix-displayed-tags
  5664. txt tags
  5665. org-agenda-show-inherited-tags
  5666. org-agenda-hide-tags-regexp))
  5667. (let* ((category (or category
  5668. (if (stringp org-category)
  5669. org-category
  5670. (and org-category (symbol-name org-category)))
  5671. (if buffer-file-name
  5672. (file-name-sans-extension
  5673. (file-name-nondirectory buffer-file-name))
  5674. "")))
  5675. (category-icon (org-agenda-get-category-icon category))
  5676. (category-icon (if category-icon
  5677. (propertize " " 'display category-icon)
  5678. ""))
  5679. ;; time, tag, effort are needed for the eval of the prefix format
  5680. (tag (if tags (nth (1- (length tags)) tags) ""))
  5681. time effort neffort
  5682. (ts (if dotime (concat
  5683. (if (stringp dotime) dotime "")
  5684. (and org-agenda-search-headline-for-time txt))))
  5685. (time-of-day (and dotime (org-get-time-of-day ts)))
  5686. stamp plain s0 s1 s2 rtn srp l
  5687. duration thecategory)
  5688. (and (derived-mode-p 'org-mode) buffer-file-name
  5689. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5690. (when (and dotime time-of-day)
  5691. ;; Extract starting and ending time and move them to prefix
  5692. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5693. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5694. (setq s0 (match-string 0 ts)
  5695. srp (and stamp (match-end 3))
  5696. s1 (match-string (if plain 1 2) ts)
  5697. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5698. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5699. ;; them, we might want to remove them there to avoid duplication.
  5700. ;; The user can turn this off with a variable.
  5701. (if (and org-prefix-has-time
  5702. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5703. (string-match (concat (regexp-quote s0) " *") txt)
  5704. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5705. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5706. (= (match-beginning 0) 0)
  5707. t))
  5708. (setq txt (replace-match "" nil nil txt))))
  5709. ;; Normalize the time(s) to 24 hour
  5710. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5711. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5712. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5713. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5714. (setq s2
  5715. (org-minutes-to-hh:mm-string
  5716. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5717. ;; Compute the duration
  5718. (when s2
  5719. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5720. (org-hh:mm-string-to-minutes s1)))))
  5721. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5722. txt)
  5723. ;; Tags are in the string
  5724. (if (or (eq org-agenda-remove-tags t)
  5725. (and org-agenda-remove-tags
  5726. org-prefix-has-tag))
  5727. (setq txt (replace-match "" t t txt))
  5728. (setq txt (replace-match
  5729. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5730. (match-string 2 txt))
  5731. t t txt))))
  5732. (when (derived-mode-p 'org-mode)
  5733. (setq effort
  5734. (condition-case nil
  5735. (org-get-effort
  5736. (or (get-text-property 0 'org-hd-marker txt)
  5737. (get-text-property 0 'org-marker txt)))
  5738. (error nil)))
  5739. (when effort
  5740. (setq neffort (org-duration-string-to-minutes effort)
  5741. effort (setq effort (concat "[" effort "]")))))
  5742. ;; prevent erroring out with %e format when there is no effort
  5743. (or effort (setq effort ""))
  5744. (when remove-re
  5745. (while (string-match remove-re txt)
  5746. (setq txt (replace-match "" t t txt))))
  5747. ;; Set org-heading property on `txt' to mark the start of the
  5748. ;; heading.
  5749. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5750. ;; Prepare the variables needed in the eval of the compiled format
  5751. (setq time (cond (s2 (concat
  5752. (org-agenda-time-of-day-to-ampm-maybe s1)
  5753. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5754. (if org-agenda-timegrid-use-ampm " ")))
  5755. (s1 (concat
  5756. (org-agenda-time-of-day-to-ampm-maybe s1)
  5757. (if org-agenda-timegrid-use-ampm
  5758. "........ "
  5759. "......")))
  5760. (t ""))
  5761. extra (or (and (not habitp) extra) "")
  5762. category (if (symbolp category) (symbol-name category) category)
  5763. thecategory (copy-sequence category))
  5764. (if (string-match org-bracket-link-regexp category)
  5765. (progn
  5766. (setq l (if (match-end 3)
  5767. (- (match-end 3) (match-beginning 3))
  5768. (- (match-end 1) (match-beginning 1))))
  5769. (when (< l (or org-prefix-category-length 0))
  5770. (setq category (copy-sequence category))
  5771. (org-add-props category nil
  5772. 'extra-space (make-string
  5773. (- org-prefix-category-length l 1) ?\ ))))
  5774. (if (and org-prefix-category-max-length
  5775. (>= (length category) org-prefix-category-max-length))
  5776. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5777. ;; Evaluate the compiled format
  5778. (setq rtn (concat (eval formatter) txt))
  5779. ;; And finally add the text properties
  5780. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5781. (org-add-props rtn nil
  5782. 'org-category (if thecategory (downcase thecategory) category)
  5783. 'tags (mapcar 'org-downcase-keep-props tags)
  5784. 'org-highest-priority org-highest-priority
  5785. 'org-lowest-priority org-lowest-priority
  5786. 'time-of-day time-of-day
  5787. 'duration duration
  5788. 'effort effort
  5789. 'effort-minutes neffort
  5790. 'txt txt
  5791. 'time time
  5792. 'extra extra
  5793. 'format org-prefix-format-compiled
  5794. 'dotime dotime)))))
  5795. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5796. "Remove tags string from TXT, and add a modified list of tags.
  5797. The modified list may contain inherited tags, and tags matched by
  5798. `org-agenda-hide-tags-regexp' will be removed."
  5799. (when (or add-inherited hide-re)
  5800. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5801. (setq txt (substring txt 0 (match-beginning 0))))
  5802. (setq tags
  5803. (delq nil
  5804. (mapcar (lambda (tg)
  5805. (if (or (and hide-re (string-match hide-re tg))
  5806. (and (not add-inherited)
  5807. (get-text-property 0 'inherited tg)))
  5808. nil
  5809. tg))
  5810. tags)))
  5811. (when tags
  5812. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5813. i)
  5814. (setq txt (concat txt " :"
  5815. (mapconcat
  5816. (lambda (x)
  5817. (setq i (get-text-property 0 'inherited x))
  5818. (if (and have-i (not i))
  5819. (progn
  5820. (setq have-i nil)
  5821. (concat ":" x))
  5822. x))
  5823. tags ":")
  5824. (if have-i "::" ":"))))))
  5825. txt)
  5826. (defun org-downcase-keep-props (s)
  5827. (let ((props (text-properties-at 0 s)))
  5828. (setq s (downcase s))
  5829. (add-text-properties 0 (length s) props s)
  5830. s))
  5831. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5832. (defvar org-agenda-sorting-strategy-selected nil)
  5833. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5834. (catch 'exit
  5835. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5836. ((and todayp (member 'today (car org-agenda-time-grid))))
  5837. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5838. ((member 'weekly (car org-agenda-time-grid)))
  5839. (t (throw 'exit list)))
  5840. (let* ((have (delq nil (mapcar
  5841. (lambda (x) (get-text-property 1 'time-of-day x))
  5842. list)))
  5843. (string (nth 1 org-agenda-time-grid))
  5844. (gridtimes (nth 2 org-agenda-time-grid))
  5845. (req (car org-agenda-time-grid))
  5846. (remove (member 'remove-match req))
  5847. new time)
  5848. (if (and (member 'require-timed req) (not have))
  5849. ;; don't show empty grid
  5850. (throw 'exit list))
  5851. (while (setq time (pop gridtimes))
  5852. (unless (and remove (member time have))
  5853. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5854. (push (org-agenda-format-item
  5855. nil string "" nil
  5856. (concat (substring time 0 -2) ":" (substring time -2)))
  5857. new)
  5858. (put-text-property
  5859. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5860. (when (and todayp org-agenda-show-current-time-in-grid)
  5861. (push (org-agenda-format-item
  5862. nil
  5863. org-agenda-current-time-string
  5864. "" nil
  5865. (format-time-string "%H:%M "))
  5866. new)
  5867. (put-text-property
  5868. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5869. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5870. (append new list)
  5871. (append list new)))))
  5872. (defun org-compile-prefix-format (key)
  5873. "Compile the prefix format into a Lisp form that can be evaluated.
  5874. The resulting form and associated variable bindings is returned
  5875. and stored in the variable `org-prefix-format-compiled'."
  5876. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5877. org-prefix-category-length nil
  5878. org-prefix-has-effort nil)
  5879. (let ((s (cond
  5880. ((stringp org-agenda-prefix-format)
  5881. org-agenda-prefix-format)
  5882. ((assq key org-agenda-prefix-format)
  5883. (cdr (assq key org-agenda-prefix-format)))
  5884. (t " %-12:c%?-12t% s")))
  5885. (start 0)
  5886. varform vars var e c f opt)
  5887. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5888. s start)
  5889. (setq var (or (cdr (assoc (match-string 4 s)
  5890. '(("c" . category) ("t" . time) ("s" . extra)
  5891. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5892. 'eval)
  5893. c (or (match-string 3 s) "")
  5894. opt (match-beginning 1)
  5895. start (1+ (match-beginning 0)))
  5896. (if (equal var 'time) (setq org-prefix-has-time t))
  5897. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5898. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5899. (setq f (concat "%" (match-string 2 s) "s"))
  5900. (when (equal var 'category)
  5901. (setq org-prefix-category-length
  5902. (floor (abs (string-to-number (match-string 2 s)))))
  5903. (setq org-prefix-category-max-length
  5904. (let ((x (match-string 2 s)))
  5905. (save-match-data
  5906. (if (string-match "\\.[0-9]+" x)
  5907. (string-to-number (substring (match-string 0 x) 1)))))))
  5908. (if (eq var 'eval)
  5909. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5910. (if opt
  5911. (setq varform
  5912. `(if (equal "" ,var)
  5913. ""
  5914. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5915. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5916. (setq s (replace-match "%s" t nil s))
  5917. (push varform vars))
  5918. (setq vars (nreverse vars))
  5919. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5920. (setq org-prefix-format-compiled
  5921. (list
  5922. `((org-prefix-has-time ,org-prefix-has-time)
  5923. (org-prefix-has-tag ,org-prefix-has-tag)
  5924. (org-prefix-category-length ,org-prefix-category-length)
  5925. (org-prefix-has-effort ,org-prefix-has-effort))
  5926. `(format ,s ,@vars))))))
  5927. (defun org-set-sorting-strategy (key)
  5928. (if (symbolp (car org-agenda-sorting-strategy))
  5929. ;; the old format
  5930. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5931. (setq org-agenda-sorting-strategy-selected
  5932. (or (cdr (assq key org-agenda-sorting-strategy))
  5933. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5934. '(time-up category-keep priority-down)))))
  5935. (defun org-get-time-of-day (s &optional string mod24)
  5936. "Check string S for a time of day.
  5937. If found, return it as a military time number between 0 and 2400.
  5938. If not found, return nil.
  5939. The optional STRING argument forces conversion into a 5 character wide string
  5940. HH:MM."
  5941. (save-match-data
  5942. (when
  5943. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5944. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5945. (let* ((h (string-to-number (match-string 1 s)))
  5946. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5947. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5948. (am-p (equal ampm "am"))
  5949. (h1 (cond ((not ampm) h)
  5950. ((= h 12) (if am-p 0 12))
  5951. (t (+ h (if am-p 0 12)))))
  5952. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5953. (mod h1 24) h1))
  5954. (t0 (+ (* 100 h2) m))
  5955. (t1 (concat (if (>= h1 24) "+" " ")
  5956. (if (and org-agenda-time-leading-zero
  5957. (< t0 1000)) "0" "")
  5958. (if (< t0 100) "0" "")
  5959. (if (< t0 10) "0" "")
  5960. (int-to-string t0))))
  5961. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5962. (defvar org-agenda-before-sorting-filter-function nil
  5963. "Function to be applied to agenda items prior to sorting.
  5964. Prior to sorting also means just before they are inserted into the agenda.
  5965. To aid sorting, you may revisit the original entries and add more text
  5966. properties which will later be used by the sorting functions.
  5967. The function should take a string argument, an agenda line.
  5968. It has access to the text properties in that line, which contain among
  5969. other things, the property `org-hd-marker' that points to the entry
  5970. where the line comes from. Note that not all lines going into the agenda
  5971. have this property, only most.
  5972. The function should return the modified string. It is probably best
  5973. to ONLY change text properties.
  5974. You can also use this function as a filter, by returning nil for lines
  5975. you don't want to have in the agenda at all. For this application, you
  5976. could bind the variable in the options section of a custom command.")
  5977. (defun org-agenda-finalize-entries (list &optional nosort)
  5978. "Sort and concatenate the agenda items."
  5979. (setq list (mapcar 'org-agenda-highlight-todo list))
  5980. (if nosort
  5981. list
  5982. (when org-agenda-before-sorting-filter-function
  5983. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5984. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5985. (defun org-agenda-highlight-todo (x)
  5986. (let ((org-done-keywords org-done-keywords-for-agenda)
  5987. (case-fold-search nil)
  5988. re)
  5989. (if (eq x 'line)
  5990. (save-excursion
  5991. (beginning-of-line 1)
  5992. (setq re (org-get-at-bol 'org-todo-regexp))
  5993. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5994. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5995. (add-text-properties (match-beginning 0) (match-end 1)
  5996. (list 'face (org-get-todo-face 1)))
  5997. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5998. (delete-region (match-beginning 1) (1- (match-end 0)))
  5999. (goto-char (match-beginning 1))
  6000. (insert (format org-agenda-todo-keyword-format s)))))
  6001. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6002. (setq re (get-text-property 0 'org-todo-regexp x))
  6003. (when (and re
  6004. ;; Test `pl' because if there's no heading content,
  6005. ;; there's no point matching to highlight. Note
  6006. ;; that if we didn't test `pl' first, and there
  6007. ;; happened to be no keyword from `org-todo-regexp'
  6008. ;; on this heading line, then the `equal' comparison
  6009. ;; afterwards would spuriously succeed in the case
  6010. ;; where `pl' is nil -- causing an args-out-of-range
  6011. ;; error when we try to add text properties to text
  6012. ;; that isn't there.
  6013. pl
  6014. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6015. x pl) pl))
  6016. (add-text-properties
  6017. (or (match-end 1) (match-end 0)) (match-end 0)
  6018. (list 'face (org-get-todo-face (match-string 2 x)))
  6019. x)
  6020. (when (match-end 1)
  6021. (setq x (concat (substring x 0 (match-end 1))
  6022. (format org-agenda-todo-keyword-format
  6023. (match-string 2 x))
  6024. (org-add-props " " (text-properties-at 0 x))
  6025. (substring x (match-end 3)))))))
  6026. x)))
  6027. (defsubst org-cmp-priority (a b)
  6028. "Compare the priorities of string A and B."
  6029. (let ((pa (or (get-text-property 1 'priority a) 0))
  6030. (pb (or (get-text-property 1 'priority b) 0)))
  6031. (cond ((> pa pb) +1)
  6032. ((< pa pb) -1))))
  6033. (defsubst org-cmp-effort (a b)
  6034. "Compare the effort values of string A and B."
  6035. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6036. (ea (or (get-text-property 1 'effort-minutes a) def))
  6037. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6038. (cond ((> ea eb) +1)
  6039. ((< ea eb) -1))))
  6040. (defsubst org-cmp-category (a b)
  6041. "Compare the string values of categories of strings A and B."
  6042. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6043. (cb (or (get-text-property 1 'org-category b) "")))
  6044. (cond ((string-lessp ca cb) -1)
  6045. ((string-lessp cb ca) +1))))
  6046. (defsubst org-cmp-todo-state (a b)
  6047. "Compare the todo states of strings A and B."
  6048. (let* ((ma (or (get-text-property 1 'org-marker a)
  6049. (get-text-property 1 'org-hd-marker a)))
  6050. (mb (or (get-text-property 1 'org-marker b)
  6051. (get-text-property 1 'org-hd-marker b)))
  6052. (fa (and ma (marker-buffer ma)))
  6053. (fb (and mb (marker-buffer mb)))
  6054. (todo-kwds
  6055. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6056. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6057. (ta (or (get-text-property 1 'todo-state a) ""))
  6058. (tb (or (get-text-property 1 'todo-state b) ""))
  6059. (la (- (length (member ta todo-kwds))))
  6060. (lb (- (length (member tb todo-kwds))))
  6061. (donepa (member ta org-done-keywords-for-agenda))
  6062. (donepb (member tb org-done-keywords-for-agenda)))
  6063. (cond ((and donepa (not donepb)) -1)
  6064. ((and (not donepa) donepb) +1)
  6065. ((< la lb) -1)
  6066. ((< lb la) +1))))
  6067. (defsubst org-cmp-alpha (a b)
  6068. "Compare the headlines, alphabetically."
  6069. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6070. (plb (text-property-any 0 (length b) 'org-heading t b))
  6071. (ta (and pla (substring a pla)))
  6072. (tb (and plb (substring b plb))))
  6073. (when pla
  6074. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6075. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6076. (setq ta (substring ta (match-end 0))))
  6077. (setq ta (downcase ta)))
  6078. (when plb
  6079. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6080. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6081. (setq tb (substring tb (match-end 0))))
  6082. (setq tb (downcase tb)))
  6083. (cond ((not ta) +1)
  6084. ((not tb) -1)
  6085. ((string-lessp ta tb) -1)
  6086. ((string-lessp tb ta) +1))))
  6087. (defsubst org-cmp-tag (a b)
  6088. "Compare the string values of the first tags of A and B."
  6089. (let ((ta (car (last (get-text-property 1 'tags a))))
  6090. (tb (car (last (get-text-property 1 'tags b)))))
  6091. (cond ((not ta) +1)
  6092. ((not tb) -1)
  6093. ((string-lessp ta tb) -1)
  6094. ((string-lessp tb ta) +1))))
  6095. (defsubst org-cmp-time (a b)
  6096. "Compare the time-of-day values of strings A and B."
  6097. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6098. (ta (or (get-text-property 1 'time-of-day a) def))
  6099. (tb (or (get-text-property 1 'time-of-day b) def)))
  6100. (cond ((< ta tb) -1)
  6101. ((< tb ta) +1))))
  6102. (defsubst org-cmp-habit-p (a b)
  6103. "Compare the todo states of strings A and B."
  6104. (let ((ha (get-text-property 1 'org-habit-p a))
  6105. (hb (get-text-property 1 'org-habit-p b)))
  6106. (cond ((and ha (not hb)) -1)
  6107. ((and (not ha) hb) +1))))
  6108. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6109. (defun org-entries-lessp (a b)
  6110. "Predicate for sorting agenda entries."
  6111. ;; The following variables will be used when the form is evaluated.
  6112. ;; So even though the compiler complains, keep them.
  6113. (let* ((ss org-agenda-sorting-strategy-selected)
  6114. (time-up (and (org-em 'time-up 'time-down ss)
  6115. (org-cmp-time a b)))
  6116. (time-down (if time-up (- time-up) nil))
  6117. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6118. (org-cmp-priority a b)))
  6119. (priority-down (if priority-up (- priority-up) nil))
  6120. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6121. (org-cmp-effort a b)))
  6122. (effort-down (if effort-up (- effort-up) nil))
  6123. (category-up (and (or (org-em 'category-up 'category-down ss)
  6124. (memq 'category-keep ss))
  6125. (org-cmp-category a b)))
  6126. (category-down (if category-up (- category-up) nil))
  6127. (category-keep (if category-up +1 nil))
  6128. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6129. (org-cmp-tag a b)))
  6130. (tag-down (if tag-up (- tag-up) nil))
  6131. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6132. (org-cmp-todo-state a b)))
  6133. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6134. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6135. (org-cmp-habit-p a b)))
  6136. (habit-down (if habit-up (- habit-up) nil))
  6137. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6138. (org-cmp-alpha a b)))
  6139. (alpha-down (if alpha-up (- alpha-up) nil))
  6140. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6141. user-defined-up user-defined-down)
  6142. (if (and need-user-cmp org-agenda-cmp-user-defined
  6143. (functionp org-agenda-cmp-user-defined))
  6144. (setq user-defined-up
  6145. (funcall org-agenda-cmp-user-defined a b)
  6146. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6147. (cdr (assoc
  6148. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6149. '((-1 . t) (1 . nil) (nil . nil))))))
  6150. ;;; Agenda restriction lock
  6151. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6152. "Overlay to mark the headline to which agenda commands are restricted.")
  6153. (overlay-put org-agenda-restriction-lock-overlay
  6154. 'face 'org-agenda-restriction-lock)
  6155. (overlay-put org-agenda-restriction-lock-overlay
  6156. 'help-echo "Agendas are currently limited to this subtree.")
  6157. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6158. (defun org-agenda-set-restriction-lock (&optional type)
  6159. "Set restriction lock for agenda, to current subtree or file.
  6160. Restriction will be the file if TYPE is `file', or if type is the
  6161. universal prefix '(4), or if the cursor is before the first headline
  6162. in the file. Otherwise, restriction will be to the current subtree."
  6163. (interactive "P")
  6164. (and (equal type '(4)) (setq type 'file))
  6165. (setq type (cond
  6166. (type type)
  6167. ((org-at-heading-p) 'subtree)
  6168. ((condition-case nil (org-back-to-heading t) (error nil))
  6169. 'subtree)
  6170. (t 'file)))
  6171. (if (eq type 'subtree)
  6172. (progn
  6173. (setq org-agenda-restrict t)
  6174. (setq org-agenda-overriding-restriction 'subtree)
  6175. (put 'org-agenda-files 'org-restrict
  6176. (list (buffer-file-name (buffer-base-buffer))))
  6177. (org-back-to-heading t)
  6178. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6179. (move-marker org-agenda-restrict-begin (point))
  6180. (move-marker org-agenda-restrict-end
  6181. (save-excursion (org-end-of-subtree t)))
  6182. (message "Locking agenda restriction to subtree"))
  6183. (put 'org-agenda-files 'org-restrict
  6184. (list (buffer-file-name (buffer-base-buffer))))
  6185. (setq org-agenda-restrict nil)
  6186. (setq org-agenda-overriding-restriction 'file)
  6187. (move-marker org-agenda-restrict-begin nil)
  6188. (move-marker org-agenda-restrict-end nil)
  6189. (message "Locking agenda restriction to file"))
  6190. (setq current-prefix-arg nil)
  6191. (org-agenda-maybe-redo))
  6192. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6193. "Remove the agenda restriction lock."
  6194. (interactive "P")
  6195. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6196. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6197. (setq org-agenda-overriding-restriction nil)
  6198. (setq org-agenda-restrict nil)
  6199. (put 'org-agenda-files 'org-restrict nil)
  6200. (move-marker org-agenda-restrict-begin nil)
  6201. (move-marker org-agenda-restrict-end nil)
  6202. (setq current-prefix-arg nil)
  6203. (message "Agenda restriction lock removed")
  6204. (or noupdate (org-agenda-maybe-redo)))
  6205. (defun org-agenda-maybe-redo ()
  6206. "If there is any window showing the agenda view, update it."
  6207. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6208. (w0 (selected-window)))
  6209. (when w
  6210. (select-window w)
  6211. (org-agenda-redo)
  6212. (select-window w0)
  6213. (if org-agenda-overriding-restriction
  6214. (message "Agenda view shifted to new %s restriction"
  6215. org-agenda-overriding-restriction)
  6216. (message "Agenda restriction lock removed")))))
  6217. ;;; Agenda commands
  6218. (defun org-agenda-check-type (error &rest types)
  6219. "Check if agenda buffer is of allowed type.
  6220. If ERROR is non-nil, throw an error, otherwise just return nil."
  6221. (if (not org-agenda-type)
  6222. (error "No Org agenda currently displayed")
  6223. (if (memq org-agenda-type types)
  6224. t
  6225. (if error
  6226. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6227. nil))))
  6228. (defun org-agenda-Quit (&optional arg)
  6229. "Exit agenda by removing the window or the buffer."
  6230. (interactive)
  6231. (if org-agenda-columns-active
  6232. (org-columns-quit)
  6233. (let ((buf (current-buffer)))
  6234. (if (eq org-agenda-window-setup 'other-frame)
  6235. (progn
  6236. (org-agenda-reset-markers)
  6237. (kill-buffer buf)
  6238. (org-columns-remove-overlays)
  6239. (setq org-agenda-archives-mode nil)
  6240. (delete-frame))
  6241. (and (not (eq org-agenda-window-setup 'current-window))
  6242. (not (one-window-p))
  6243. (delete-window))
  6244. (org-agenda-reset-markers)
  6245. (kill-buffer buf)
  6246. (org-columns-remove-overlays)
  6247. (setq org-agenda-archives-mode nil)))
  6248. ;; Maybe restore the pre-agenda window configuration.
  6249. (and org-agenda-restore-windows-after-quit
  6250. (not (eq org-agenda-window-setup 'other-frame))
  6251. org-agenda-pre-window-conf
  6252. (set-window-configuration org-agenda-pre-window-conf)
  6253. (setq org-agenda-pre-window-conf nil))))
  6254. (defun org-agenda-quit ()
  6255. "Exit agenda by killing agenda buffer or burying it when
  6256. `org-agenda-sticky' is non-NIL"
  6257. (interactive)
  6258. (if (and (eq org-indirect-buffer-display 'other-window)
  6259. org-last-indirect-buffer)
  6260. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6261. (if org-agenda-columns-active
  6262. (org-columns-quit)
  6263. (if org-agenda-sticky
  6264. (let ((buf (current-buffer)))
  6265. (if (eq org-agenda-window-setup 'other-frame)
  6266. (progn
  6267. (delete-frame))
  6268. (and (not (eq org-agenda-window-setup 'current-window))
  6269. (not (one-window-p))
  6270. (delete-window)))
  6271. (with-current-buffer buf
  6272. (bury-buffer)
  6273. ;; Maybe restore the pre-agenda window configuration.
  6274. (and org-agenda-restore-windows-after-quit
  6275. (not (eq org-agenda-window-setup 'other-frame))
  6276. org-agenda-pre-window-conf
  6277. (set-window-configuration org-agenda-pre-window-conf)
  6278. (setq org-agenda-pre-window-conf nil))))
  6279. (org-agenda-Quit))))
  6280. (defun org-agenda-exit ()
  6281. "Exit agenda by removing the window or the buffer.
  6282. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6283. Org-mode buffers visited directly by the user will not be touched."
  6284. (interactive)
  6285. (org-release-buffers org-agenda-new-buffers)
  6286. (setq org-agenda-new-buffers nil)
  6287. (org-agenda-Quit))
  6288. (defun org-agenda-kill-all-agenda-buffers ()
  6289. "Kill all buffers in `org-agena-mode'.
  6290. This is used when toggling sticky agendas. You can also explicitly invoke it
  6291. with `C-c a C-k'."
  6292. (interactive)
  6293. (let (blist)
  6294. (dolist (buf (buffer-list))
  6295. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6296. (push buf blist)))
  6297. (mapc 'kill-buffer blist)))
  6298. (defun org-agenda-execute (arg)
  6299. "Execute another agenda command, keeping same window.
  6300. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6301. in the agenda."
  6302. (interactive "P")
  6303. (let ((org-agenda-window-setup 'current-window))
  6304. (org-agenda arg)))
  6305. (defun org-agenda-redo (&optional all)
  6306. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6307. (interactive "P")
  6308. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6309. (cpa (unless (eq all t) current-prefix-arg))
  6310. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6311. (org-agenda-sticky nil)
  6312. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6313. org-agenda-buffer-name))
  6314. (org-agenda-keep-modes t)
  6315. (tag-filter org-agenda-tag-filter)
  6316. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6317. (top-cat-filter org-agenda-top-category-filter)
  6318. (cat-filter org-agenda-category-filter)
  6319. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6320. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6321. (cols org-agenda-columns-active)
  6322. (line (org-current-line))
  6323. (window-line (- line (org-current-line (window-start))))
  6324. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6325. (redo-cmd (get-text-property p 'org-redo-cmd))
  6326. (last-args (get-text-property p 'org-last-args))
  6327. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6328. (org-agenda-overriding-cmd-arguments
  6329. (unless (eq all t)
  6330. (cond ((listp last-args)
  6331. (cons (or cpa (car last-args)) (cdr last-args)))
  6332. ((stringp last-args)
  6333. last-args))))
  6334. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6335. (put 'org-agenda-tag-filter :preset-filter nil)
  6336. (put 'org-agenda-category-filter :preset-filter nil)
  6337. (and cols (org-columns-quit))
  6338. (message "Rebuilding agenda buffer...")
  6339. (if serie-redo-cmd
  6340. (eval serie-redo-cmd)
  6341. (org-let lprops '(eval redo-cmd)))
  6342. (setq org-agenda-undo-list nil
  6343. org-agenda-pending-undo-list nil)
  6344. (message "Rebuilding agenda buffer...done")
  6345. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6346. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6347. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6348. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6349. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6350. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6351. (org-goto-line line)
  6352. (recenter window-line)))
  6353. (defvar org-global-tags-completion-table nil)
  6354. (defvar org-agenda-filter-form nil)
  6355. (defvar org-agenda-filtered-by-category nil)
  6356. (defun org-agenda-filter-by-category (strip)
  6357. "Keep only those lines in the agenda buffer that have a specific category.
  6358. The category is that of the current line."
  6359. (interactive "P")
  6360. (if (and org-agenda-filtered-by-category
  6361. org-agenda-category-filter)
  6362. (org-agenda-filter-show-all-cat)
  6363. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6364. (if cat (org-agenda-filter-apply
  6365. (list (concat (if strip "-" "+") cat)) 'category)
  6366. (error "No category at point")))))
  6367. (defun org-find-top-category (&optional pos)
  6368. (save-excursion
  6369. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6370. (if pos (goto-char pos))
  6371. ;; Skip up to the topmost parent
  6372. (while (ignore-errors (outline-up-heading 1) t))
  6373. (ignore-errors
  6374. (nth 4 (org-heading-components))))))
  6375. (defvar org-agenda-filtered-by-top-category nil)
  6376. (defun org-agenda-filter-by-top-category (strip)
  6377. "Keep only those lines in the agenda buffer that have a specific category.
  6378. The category is that of the current line."
  6379. (interactive "P")
  6380. (if org-agenda-filtered-by-top-category
  6381. (progn
  6382. (setq org-agenda-filtered-by-top-category nil
  6383. org-agenda-top-category-filter nil)
  6384. (org-agenda-filter-show-all-cat))
  6385. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6386. (if cat (org-agenda-filter-top-category-apply cat strip)
  6387. (error "No top-level category at point")))))
  6388. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6389. "Keep only those lines in the agenda buffer that have a specific tag.
  6390. The tag is selected with its fast selection letter, as configured.
  6391. With prefix argument STRIP, remove all lines that do have the tag.
  6392. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6393. used to narrow the search - the interactive user can also press `-' or `+'
  6394. to switch to narrowing."
  6395. (interactive "P")
  6396. (let* ((alist org-tag-alist-for-agenda)
  6397. (tag-chars (mapconcat
  6398. (lambda (x) (if (and (not (symbolp (car x)))
  6399. (cdr x))
  6400. (char-to-string (cdr x))
  6401. ""))
  6402. alist ""))
  6403. (efforts (org-split-string
  6404. (or (cdr (assoc (concat org-effort-property "_ALL")
  6405. org-global-properties))
  6406. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6407. "")))
  6408. (effort-op org-agenda-filter-effort-default-operator)
  6409. (effort-prompt "")
  6410. (inhibit-read-only t)
  6411. (current org-agenda-tag-filter)
  6412. maybe-refresh a n tag)
  6413. (unless char
  6414. (message
  6415. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6416. (if narrow "Narrow" "Filter") tag-chars
  6417. (if org-agenda-auto-exclude-function "[RET], " ""))
  6418. (setq char (read-char-exclusive)))
  6419. (when (member char '(?+ ?-))
  6420. ;; Narrowing down
  6421. (cond ((equal char ?-) (setq strip t narrow t))
  6422. ((equal char ?+) (setq strip nil narrow t)))
  6423. (message
  6424. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6425. (setq char (read-char-exclusive)))
  6426. (when (member char '(?< ?> ?= ??))
  6427. ;; An effort operator
  6428. (setq effort-op (char-to-string char))
  6429. (setq alist nil) ; to make sure it will be interpreted as effort.
  6430. (unless (equal char ??)
  6431. (loop for i from 0 to 9 do
  6432. (setq effort-prompt
  6433. (concat
  6434. effort-prompt " ["
  6435. (if (= i 9) "0" (int-to-string (1+ i)))
  6436. "]" (nth i efforts))))
  6437. (message "Effort%s: %s " effort-op effort-prompt)
  6438. (setq char (read-char-exclusive))
  6439. (when (or (< char ?0) (> char ?9))
  6440. (error "Need 1-9,0 to select effort"))))
  6441. (when (equal char ?\t)
  6442. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6443. (org-set-local 'org-global-tags-completion-table
  6444. (org-global-tags-completion-table)))
  6445. (let ((completion-ignore-case t))
  6446. (setq tag (org-icompleting-read
  6447. "Tag: " org-global-tags-completion-table))))
  6448. (cond
  6449. ((equal char ?\r)
  6450. (org-agenda-filter-show-all-tag)
  6451. (when org-agenda-auto-exclude-function
  6452. (setq org-agenda-tag-filter '())
  6453. (dolist (tag (org-agenda-get-represented-tags))
  6454. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6455. (if modifier
  6456. (push modifier org-agenda-tag-filter))))
  6457. (if (not (null org-agenda-tag-filter))
  6458. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6459. (setq maybe-refresh t))
  6460. ((equal char ?/)
  6461. (org-agenda-filter-show-all-tag)
  6462. (when (get 'org-agenda-tag-filter :preset-filter)
  6463. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6464. (setq maybe-refresh t))
  6465. ((equal char ?. )
  6466. (setq org-agenda-tag-filter
  6467. (mapcar (lambda(tag) (concat "+" tag))
  6468. (org-get-at-bol 'tags)))
  6469. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6470. (setq maybe-refresh t))
  6471. ((or (equal char ?\ )
  6472. (setq a (rassoc char alist))
  6473. (and (>= char ?0) (<= char ?9)
  6474. (setq n (if (= char ?0) 9 (- char ?0 1))
  6475. tag (concat effort-op (nth n efforts))
  6476. a (cons tag nil)))
  6477. (and (= char ??)
  6478. (setq tag "?eff")
  6479. a (cons tag nil))
  6480. (and tag (setq a (cons tag nil))))
  6481. (org-agenda-filter-show-all-tag)
  6482. (setq tag (car a))
  6483. (setq org-agenda-tag-filter
  6484. (cons (concat (if strip "-" "+") tag)
  6485. (if narrow current nil)))
  6486. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6487. (setq maybe-refresh t))
  6488. (t (error "Invalid tag selection character %c" char)))
  6489. (when (and maybe-refresh
  6490. (eq org-agenda-clockreport-mode 'with-filter))
  6491. (org-agenda-redo))))
  6492. (defun org-agenda-get-represented-tags ()
  6493. "Get a list of all tags currently represented in the agenda."
  6494. (let (p tags)
  6495. (save-excursion
  6496. (goto-char (point-min))
  6497. (while (setq p (next-single-property-change (point) 'tags))
  6498. (goto-char p)
  6499. (mapc (lambda (x) (add-to-list 'tags x))
  6500. (get-text-property (point) 'tags))))
  6501. tags))
  6502. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6503. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6504. (interactive "P")
  6505. (org-agenda-filter-by-tag strip char 'refine))
  6506. (defun org-agenda-filter-make-matcher ()
  6507. "Create the form that tests a line for agenda filter."
  6508. (let (f f1)
  6509. ;; first compute the tag-filter matcher
  6510. (dolist (x (delete-dups
  6511. (append (get 'org-agenda-tag-filter
  6512. :preset-filter) org-agenda-tag-filter)))
  6513. (if (member x '("-" "+"))
  6514. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6515. (if (string-match "[<=>?]" x)
  6516. (setq f1 (org-agenda-filter-effort-form x))
  6517. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6518. (if (equal (string-to-char x) ?-)
  6519. (setq f1 (list 'not f1))))
  6520. (push f1 f))
  6521. ;; then compute the category-filter matcher
  6522. (dolist (x (delete-dups
  6523. (append (get 'org-agenda-category-filter
  6524. :preset-filter) org-agenda-category-filter)))
  6525. (if (equal "-" (substring x 0 1))
  6526. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6527. (setq f1 (list 'equal (substring x 1) 'cat)))
  6528. (push f1 f))
  6529. (cons 'and (nreverse f))))
  6530. (defun org-agenda-filter-effort-form (e)
  6531. "Return the form to compare the effort of the current line with what E says.
  6532. E looks like \"+<2:25\"."
  6533. (let (op)
  6534. (setq e (substring e 1))
  6535. (setq op (string-to-char e) e (substring e 1))
  6536. (setq op (cond ((equal op ?<) '<=)
  6537. ((equal op ?>) '>=)
  6538. ((equal op ??) op)
  6539. (t '=)))
  6540. (list 'org-agenda-compare-effort (list 'quote op)
  6541. (org-duration-string-to-minutes e))))
  6542. (defun org-agenda-compare-effort (op value)
  6543. "Compare the effort of the current line with VALUE, using OP.
  6544. If the line does not have an effort defined, return nil."
  6545. (let ((eff (org-get-at-bol 'effort-minutes)))
  6546. (if (equal op ??)
  6547. (not eff)
  6548. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6549. value))))
  6550. (defun org-agenda-filter-apply (filter type)
  6551. "Set FILTER as the new agenda filter and apply it."
  6552. (let (tags cat)
  6553. (if (eq type 'tag)
  6554. (setq org-agenda-tag-filter filter)
  6555. (setq org-agenda-category-filter filter))
  6556. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6557. (if (and (eq type 'category)
  6558. (not (equal (substring (car filter) 0 1) "-")))
  6559. ;; Only set `org-agenda-filtered-by-category' to t
  6560. ;; when a unique category is used as the filter
  6561. (setq org-agenda-filtered-by-category t))
  6562. (org-agenda-set-mode-name)
  6563. (save-excursion
  6564. (goto-char (point-min))
  6565. (while (not (eobp))
  6566. (if (org-get-at-bol 'org-marker)
  6567. (progn
  6568. (setq tags (org-get-at-bol 'tags) ; used in eval
  6569. cat (get-text-property (point) 'org-category))
  6570. (if (not (eval org-agenda-filter-form))
  6571. (org-agenda-filter-hide-line type))
  6572. (beginning-of-line 2))
  6573. (beginning-of-line 2))))
  6574. (if (get-char-property (point) 'invisible)
  6575. (ignore-errors (org-agenda-previous-line)))))
  6576. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6577. "Set FILTER as the new agenda filter and apply it."
  6578. (org-agenda-set-mode-name)
  6579. (save-excursion
  6580. (goto-char (point-min))
  6581. (while (not (eobp))
  6582. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6583. (topcat (and pos (org-find-top-category pos))))
  6584. (if (and topcat (funcall (if negative 'identity 'not)
  6585. (string= category topcat)))
  6586. (org-agenda-filter-hide-line 'category)))
  6587. (beginning-of-line 2)))
  6588. (if (get-char-property (point) 'invisible)
  6589. (org-agenda-previous-line))
  6590. (setq org-agenda-top-category-filter category
  6591. org-agenda-filtered-by-top-category t))
  6592. (defun org-agenda-filter-hide-line (type)
  6593. (let (ov)
  6594. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6595. (point-at-eol)))
  6596. (overlay-put ov 'invisible t)
  6597. (overlay-put ov 'type type)
  6598. (if (eq type 'tag)
  6599. (push ov org-agenda-tag-filter-overlays)
  6600. (push ov org-agenda-cat-filter-overlays))))
  6601. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6602. (setq pos (or pos (point)))
  6603. (save-excursion
  6604. (dolist (ov (overlays-at pos))
  6605. (when (and (overlay-get ov 'invisible)
  6606. (eq (overlay-get ov 'type) 'tag))
  6607. (goto-char pos)
  6608. (if (< (overlay-start ov) (point-at-eol))
  6609. (move-overlay ov (point-at-eol)
  6610. (overlay-end ov)))))))
  6611. (defun org-agenda-filter-show-all-tag nil
  6612. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6613. (setq org-agenda-tag-filter-overlays nil
  6614. org-agenda-tag-filter nil
  6615. org-agenda-filter-form nil)
  6616. (org-agenda-set-mode-name))
  6617. (defun org-agenda-filter-show-all-cat nil
  6618. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6619. (setq org-agenda-cat-filter-overlays nil
  6620. org-agenda-filtered-by-category nil
  6621. org-agenda-category-filter nil
  6622. org-agenda-filter-form nil)
  6623. (org-agenda-set-mode-name))
  6624. (defun org-agenda-manipulate-query-add ()
  6625. "Manipulate the query by adding a search term with positive selection.
  6626. Positive selection means the term must be matched for selection of an entry."
  6627. (interactive)
  6628. (org-agenda-manipulate-query ?\[))
  6629. (defun org-agenda-manipulate-query-subtract ()
  6630. "Manipulate the query by adding a search term with negative selection.
  6631. Negative selection means term must not be matched for selection of an entry."
  6632. (interactive)
  6633. (org-agenda-manipulate-query ?\]))
  6634. (defun org-agenda-manipulate-query-add-re ()
  6635. "Manipulate the query by adding a search regexp with positive selection.
  6636. Positive selection means the regexp must match for selection of an entry."
  6637. (interactive)
  6638. (org-agenda-manipulate-query ?\{))
  6639. (defun org-agenda-manipulate-query-subtract-re ()
  6640. "Manipulate the query by adding a search regexp with negative selection.
  6641. Negative selection means regexp must not match for selection of an entry."
  6642. (interactive)
  6643. (org-agenda-manipulate-query ?\}))
  6644. (defun org-agenda-manipulate-query (char)
  6645. (cond
  6646. ((memq org-agenda-type '(timeline agenda))
  6647. (let ((org-agenda-include-inactive-timestamps t))
  6648. (org-agenda-redo))
  6649. (message "Display now includes inactive timestamps as well"))
  6650. ((eq org-agenda-type 'search)
  6651. (org-add-to-string
  6652. 'org-agenda-query-string
  6653. (if org-agenda-last-search-view-search-was-boolean
  6654. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6655. (?\{ . " +{}") (?\} . " -{}"))))
  6656. " "))
  6657. (setq org-agenda-redo-command
  6658. (list 'org-search-view
  6659. (car (get-text-property (min (1- (point-max)) (point))
  6660. 'org-last-args))
  6661. org-agenda-query-string
  6662. (+ (length org-agenda-query-string)
  6663. (if (member char '(?\{ ?\})) 0 1))))
  6664. (set-register org-agenda-query-register org-agenda-query-string)
  6665. (let ((org-agenda-overriding-arguments
  6666. (cdr org-agenda-redo-command)))
  6667. (org-agenda-redo)))
  6668. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6669. org-agenda-type))))
  6670. (defun org-add-to-string (var string)
  6671. (set var (concat (symbol-value var) string)))
  6672. (defun org-agenda-goto-date (span)
  6673. "Jump to DATE in agenda."
  6674. (interactive "P")
  6675. (let* ((org-read-date-prefer-future
  6676. (eval org-agenda-jump-prefer-future))
  6677. (date (org-read-date))
  6678. (org-agenda-sticky-orig org-agenda-sticky)
  6679. (org-agenda-buffer-tmp-name (buffer-name))
  6680. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6681. (0-arg (or current-prefix-arg (car args)))
  6682. (2-arg (nth 2 args))
  6683. (newcmd (list 'org-agenda-list 0-arg date
  6684. (org-agenda-span-to-ndays 2-arg)))
  6685. (newargs (cdr newcmd))
  6686. (inhibit-read-only t)
  6687. org-agenda-sticky)
  6688. (if (not (org-agenda-check-type t 'agenda))
  6689. (error "Not available in non-agenda blocks")
  6690. (add-text-properties (point-min) (point-max)
  6691. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6692. (org-agenda-redo)
  6693. (setq org-agenda-sticky org-agenda-sticky-orig
  6694. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6695. (defun org-agenda-goto-today ()
  6696. "Go to today."
  6697. (interactive)
  6698. (org-agenda-check-type t 'timeline 'agenda)
  6699. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6700. (curspan (nth 2 args))
  6701. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6702. (cond
  6703. (tdpos (goto-char tdpos))
  6704. ((eq org-agenda-type 'agenda)
  6705. (let* ((sd (org-agenda-compute-starting-span
  6706. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6707. (org-agenda-overriding-arguments args))
  6708. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6709. (org-agenda-redo)
  6710. (org-agenda-find-same-or-today-or-agenda)))
  6711. (t (error "Cannot find today")))))
  6712. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6713. (goto-char
  6714. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6715. (text-property-any (point-min) (point-max) 'org-today t)
  6716. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6717. (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
  6718. (org-agenda-goto-block-beginning))
  6719. (point-min))))
  6720. (defun org-agenda-goto-block-beginning ()
  6721. "Go the agenda block beginning."
  6722. (interactive)
  6723. (if (not (derived-mode-p 'org-agenda-mode))
  6724. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6725. (let (dest)
  6726. (save-excursion
  6727. (unless (looking-at "\\'")
  6728. (forward-char))
  6729. (let* ((prop 'org-agenda-structural-header)
  6730. (p (previous-single-property-change (point) prop))
  6731. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6732. (1- (point))) prop)))
  6733. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6734. (if (not dest)
  6735. (error "Cannot find the beginning of the blog")
  6736. (goto-char dest)
  6737. (move-beginning-of-line 1)))))
  6738. (defun org-agenda-later (arg)
  6739. "Go forward in time by thee current span.
  6740. With prefix ARG, go forward that many times the current span."
  6741. (interactive "p")
  6742. (org-agenda-check-type t 'agenda)
  6743. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6744. (span (or (nth 2 args) org-agenda-current-span))
  6745. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6746. (greg (calendar-gregorian-from-absolute sd))
  6747. (cnt (org-get-at-bol 'org-day-cnt))
  6748. greg2)
  6749. (cond
  6750. ((numberp span)
  6751. (setq sd (+ span sd)))
  6752. ((eq span 'day)
  6753. (setq sd (+ arg sd)))
  6754. ((eq span 'week)
  6755. (setq sd (+ (* 7 arg) sd)))
  6756. ((eq span 'month)
  6757. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6758. sd (calendar-absolute-from-gregorian greg2))
  6759. (setcar greg2 (1+ (car greg2))))
  6760. ((eq span 'year)
  6761. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6762. sd (calendar-absolute-from-gregorian greg2))
  6763. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6764. (t
  6765. (setq sd (+ (* span arg) sd))))
  6766. (let ((org-agenda-overriding-cmd
  6767. ;; `cmd' may have been set by `org-agenda-run-series' which
  6768. ;; uses `org-agenda-overriding-cmd' to decide whether
  6769. ;; overriding is allowed for `cmd'
  6770. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6771. (org-agenda-overriding-arguments
  6772. (list (car args) sd span)))
  6773. (org-agenda-redo)
  6774. (org-agenda-find-same-or-today-or-agenda cnt))))
  6775. (defun org-agenda-earlier (arg)
  6776. "Go backward in time by the current span.
  6777. With prefix ARG, go backward that many times the current span."
  6778. (interactive "p")
  6779. (org-agenda-later (- arg)))
  6780. (defun org-agenda-view-mode-dispatch ()
  6781. "Call one of the view mode commands."
  6782. (interactive)
  6783. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6784. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6785. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6786. (let ((a (read-char-exclusive)))
  6787. (case a
  6788. (?\ (call-interactively 'org-agenda-reset-view))
  6789. (?d (call-interactively 'org-agenda-day-view))
  6790. (?w (call-interactively 'org-agenda-week-view))
  6791. (?m (call-interactively 'org-agenda-month-view))
  6792. (?y (call-interactively 'org-agenda-year-view))
  6793. (?l (call-interactively 'org-agenda-log-mode))
  6794. (?L (org-agenda-log-mode '(4)))
  6795. (?c (org-agenda-log-mode 'clockcheck))
  6796. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6797. (?a (call-interactively 'org-agenda-archives-mode))
  6798. (?A (org-agenda-archives-mode 'files))
  6799. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6800. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6801. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6802. (?D (call-interactively 'org-agenda-toggle-diary))
  6803. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6804. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6805. (org-agenda-check-type t 'timeline 'agenda)
  6806. (org-agenda-redo))
  6807. (message "Display now includes inactive timestamps as well"))
  6808. (?q (message "Abort"))
  6809. (otherwise (error "Invalid key" )))))
  6810. (defun org-agenda-reset-view ()
  6811. "Switch to default view for agenda."
  6812. (interactive)
  6813. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6814. (defun org-agenda-day-view (&optional day-of-year)
  6815. "Switch to daily view for agenda.
  6816. With argument DAY-OF-YEAR, switch to that day of the year."
  6817. (interactive "P")
  6818. (org-agenda-change-time-span 'day day-of-year))
  6819. (defun org-agenda-week-view (&optional iso-week)
  6820. "Switch to daily view for agenda.
  6821. With argument ISO-WEEK, switch to the corresponding ISO week.
  6822. If ISO-WEEK has more then 2 digits, only the last two encode the
  6823. week. Any digits before this encode a year. So 200712 means
  6824. week 12 of year 2007. Years in the range 1938-2037 can also be
  6825. written as 2-digit years."
  6826. (interactive "P")
  6827. (org-agenda-change-time-span 'week iso-week))
  6828. (defun org-agenda-month-view (&optional month)
  6829. "Switch to monthly view for agenda.
  6830. With argument MONTH, switch to that month."
  6831. (interactive "P")
  6832. (org-agenda-change-time-span 'month month))
  6833. (defun org-agenda-year-view (&optional year)
  6834. "Switch to yearly view for agenda.
  6835. With argument YEAR, switch to that year.
  6836. If MONTH has more then 2 digits, only the last two encode the
  6837. month. Any digits before this encode a year. So 200712 means
  6838. December year 2007. Years in the range 1938-2037 can also be
  6839. written as 2-digit years."
  6840. (interactive "P")
  6841. (when year
  6842. (setq year (org-small-year-to-year year)))
  6843. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6844. (org-agenda-change-time-span 'year year)
  6845. (error "Abort")))
  6846. (defun org-agenda-change-time-span (span &optional n)
  6847. "Change the agenda view to SPAN.
  6848. SPAN may be `day', `week', `month', `year'."
  6849. (org-agenda-check-type t 'agenda)
  6850. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6851. (curspan (nth 2 args)))
  6852. (if (and (not n) (equal curspan span))
  6853. (error "Viewing span is already \"%s\"" span))
  6854. (let* ((sd (or (org-get-at-bol 'day)
  6855. (nth 1 args)
  6856. org-starting-day))
  6857. (sd (org-agenda-compute-starting-span sd span n))
  6858. (org-agenda-overriding-cmd
  6859. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6860. (org-agenda-overriding-arguments
  6861. (list (car args) sd span)))
  6862. (org-agenda-redo)
  6863. (org-agenda-find-same-or-today-or-agenda))
  6864. (org-agenda-set-mode-name)
  6865. (message "Switched to %s view" span)))
  6866. (defun org-agenda-compute-starting-span (sd span &optional n)
  6867. "Compute starting date for agenda.
  6868. SPAN may be `day', `week', `month', `year'. The return value
  6869. is a cons cell with the starting date and the number of days,
  6870. so that the date SD will be in that range."
  6871. (let* ((greg (calendar-gregorian-from-absolute sd))
  6872. (dg (nth 1 greg))
  6873. (mg (car greg))
  6874. (yg (nth 2 greg)))
  6875. (cond
  6876. ((eq span 'day)
  6877. (when n
  6878. (setq sd (+ (calendar-absolute-from-gregorian
  6879. (list mg 1 yg))
  6880. n -1))))
  6881. ((eq span 'week)
  6882. (let* ((nt (calendar-day-of-week
  6883. (calendar-gregorian-from-absolute sd)))
  6884. (d (if org-agenda-start-on-weekday
  6885. (- nt org-agenda-start-on-weekday)
  6886. 0))
  6887. y1)
  6888. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6889. (when n
  6890. (require 'cal-iso)
  6891. (when (> n 99)
  6892. (setq y1 (org-small-year-to-year (/ n 100))
  6893. n (mod n 100)))
  6894. (setq sd
  6895. (calendar-absolute-from-iso
  6896. (list n 1
  6897. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6898. ((eq span 'month)
  6899. (let (y1)
  6900. (when (and n (> n 99))
  6901. (setq y1 (org-small-year-to-year (/ n 100))
  6902. n (mod n 100)))
  6903. (setq sd (calendar-absolute-from-gregorian
  6904. (list (or n mg) 1 (or y1 yg))))))
  6905. ((eq span 'year)
  6906. (setq sd (calendar-absolute-from-gregorian
  6907. (list 1 1 (or n yg))))))
  6908. sd))
  6909. (defun org-agenda-next-date-line (&optional arg)
  6910. "Jump to the next line indicating a date in agenda buffer."
  6911. (interactive "p")
  6912. (org-agenda-check-type t 'agenda 'timeline)
  6913. (beginning-of-line 1)
  6914. ;; This does not work if user makes date format that starts with a blank
  6915. (if (looking-at "^\\S-") (forward-char 1))
  6916. (if (not (re-search-forward "^\\S-" nil t arg))
  6917. (progn
  6918. (backward-char 1)
  6919. (error "No next date after this line in this buffer")))
  6920. (goto-char (match-beginning 0)))
  6921. (defun org-agenda-previous-date-line (&optional arg)
  6922. "Jump to the previous line indicating a date in agenda buffer."
  6923. (interactive "p")
  6924. (org-agenda-check-type t 'agenda 'timeline)
  6925. (beginning-of-line 1)
  6926. (if (not (re-search-backward "^\\S-" nil t arg))
  6927. (error "No previous date before this line in this buffer")))
  6928. ;; Initialize the highlight
  6929. (defvar org-hl (make-overlay 1 1))
  6930. (overlay-put org-hl 'face 'highlight)
  6931. (defun org-highlight (begin end &optional buffer)
  6932. "Highlight a region with overlay."
  6933. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6934. (defun org-unhighlight ()
  6935. "Detach overlay INDEX."
  6936. (org-detach-overlay org-hl))
  6937. (defun org-unhighlight-once ()
  6938. "Remove the highlight from its position, and this function from the hook."
  6939. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6940. (org-unhighlight))
  6941. (defvar org-agenda-pre-follow-window-conf nil)
  6942. (defun org-agenda-follow-mode ()
  6943. "Toggle follow mode in an agenda buffer."
  6944. (interactive)
  6945. (unless org-agenda-follow-mode
  6946. (setq org-agenda-pre-follow-window-conf
  6947. (current-window-configuration)))
  6948. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6949. (unless org-agenda-follow-mode
  6950. (set-window-configuration org-agenda-pre-follow-window-conf))
  6951. (org-agenda-set-mode-name)
  6952. (org-agenda-do-context-action)
  6953. (message "Follow mode is %s"
  6954. (if org-agenda-follow-mode "on" "off")))
  6955. (defun org-agenda-entry-text-mode (&optional arg)
  6956. "Toggle entry text mode in an agenda buffer."
  6957. (interactive "P")
  6958. (setq org-agenda-entry-text-mode (or (integerp arg)
  6959. (not org-agenda-entry-text-mode)))
  6960. (org-agenda-entry-text-hide)
  6961. (and org-agenda-entry-text-mode
  6962. (let ((org-agenda-entry-text-maxlines
  6963. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6964. (org-agenda-entry-text-show)))
  6965. (org-agenda-set-mode-name)
  6966. (message "Entry text mode is %s. Maximum number of lines is %d"
  6967. (if org-agenda-entry-text-mode "on" "off")
  6968. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6969. (defun org-agenda-clockreport-mode (&optional with-filter)
  6970. "Toggle clocktable mode in an agenda buffer.
  6971. With prefix arg WITH-FILTER, make the clocktable respect the current
  6972. agenda filter."
  6973. (interactive "P")
  6974. (org-agenda-check-type t 'agenda)
  6975. (if with-filter
  6976. (setq org-agenda-clockreport-mode 'with-filter)
  6977. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6978. (org-agenda-set-mode-name)
  6979. (org-agenda-redo)
  6980. (message "Clocktable mode is %s"
  6981. (if org-agenda-clockreport-mode "on" "off")))
  6982. (defun org-agenda-log-mode (&optional special)
  6983. "Toggle log mode in an agenda buffer.
  6984. With argument SPECIAL, show all possible log items, not only the ones
  6985. configured in `org-agenda-log-mode-items'.
  6986. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6987. (interactive "P")
  6988. (org-agenda-check-type t 'agenda 'timeline)
  6989. (setq org-agenda-show-log
  6990. (cond
  6991. ((equal special '(16)) 'only)
  6992. ((eq special 'clockcheck)
  6993. (if (eq org-agenda-show-log 'clockcheck)
  6994. nil 'clockcheck))
  6995. (special '(closed clock state))
  6996. (t (not org-agenda-show-log))))
  6997. (org-agenda-set-mode-name)
  6998. (org-agenda-redo)
  6999. (message "Log mode is %s"
  7000. (if org-agenda-show-log "on" "off")))
  7001. (defun org-agenda-archives-mode (&optional with-files)
  7002. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7003. When called with a prefix argument, include all archive files as well."
  7004. (interactive "P")
  7005. (setq org-agenda-archives-mode
  7006. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7007. (org-agenda-set-mode-name)
  7008. (org-agenda-redo)
  7009. (message
  7010. "%s"
  7011. (cond
  7012. ((eq org-agenda-archives-mode nil)
  7013. "No archives are included")
  7014. ((eq org-agenda-archives-mode 'trees)
  7015. (format "Trees with :%s: tag are included" org-archive-tag))
  7016. ((eq org-agenda-archives-mode t)
  7017. (format "Trees with :%s: tag and all active archive files are included"
  7018. org-archive-tag)))))
  7019. (defun org-agenda-toggle-diary ()
  7020. "Toggle diary inclusion in an agenda buffer."
  7021. (interactive)
  7022. (org-agenda-check-type t 'agenda)
  7023. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7024. (org-agenda-redo)
  7025. (org-agenda-set-mode-name)
  7026. (message "Diary inclusion turned %s"
  7027. (if org-agenda-include-diary "on" "off")))
  7028. (defun org-agenda-toggle-deadlines ()
  7029. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7030. (interactive)
  7031. (org-agenda-check-type t 'agenda)
  7032. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7033. (org-agenda-redo)
  7034. (org-agenda-set-mode-name)
  7035. (message "Deadlines inclusion turned %s"
  7036. (if org-agenda-include-deadlines "on" "off")))
  7037. (defun org-agenda-toggle-time-grid ()
  7038. "Toggle time grid in an agenda buffer."
  7039. (interactive)
  7040. (org-agenda-check-type t 'agenda)
  7041. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7042. (org-agenda-redo)
  7043. (org-agenda-set-mode-name)
  7044. (message "Time-grid turned %s"
  7045. (if org-agenda-use-time-grid "on" "off")))
  7046. (defun org-agenda-set-mode-name ()
  7047. "Set the mode name to indicate all the small mode settings."
  7048. (setq mode-name
  7049. (list "Org-Agenda"
  7050. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7051. " "
  7052. '(:eval (org-agenda-span-name org-agenda-current-span))
  7053. (if org-agenda-follow-mode " Follow" "")
  7054. (if org-agenda-entry-text-mode " ETxt" "")
  7055. (if org-agenda-include-diary " Diary" "")
  7056. (if org-agenda-include-deadlines " Ddl" "")
  7057. (if org-agenda-use-time-grid " Grid" "")
  7058. (if (and (boundp 'org-habit-show-habits)
  7059. org-habit-show-habits) " Habit" "")
  7060. (cond
  7061. ((consp org-agenda-show-log) " LogAll")
  7062. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7063. (org-agenda-show-log " Log")
  7064. (t ""))
  7065. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7066. :preset-filter))
  7067. '(:eval (org-propertize
  7068. (concat " <"
  7069. (mapconcat
  7070. 'identity
  7071. (append
  7072. (get 'org-agenda-category-filter :preset-filter)
  7073. org-agenda-category-filter)
  7074. "")
  7075. ">")
  7076. 'face 'org-agenda-filter-category
  7077. 'help-echo "Category used in filtering"))
  7078. "")
  7079. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7080. :preset-filter))
  7081. '(:eval (org-propertize
  7082. (concat " {"
  7083. (mapconcat
  7084. 'identity
  7085. (append
  7086. (get 'org-agenda-tag-filter :preset-filter)
  7087. org-agenda-tag-filter)
  7088. "")
  7089. "}")
  7090. 'face 'org-agenda-filter-tags
  7091. 'help-echo "Tags used in filtering"))
  7092. "")
  7093. (if org-agenda-archives-mode
  7094. (if (eq org-agenda-archives-mode t)
  7095. " Archives"
  7096. (format " :%s:" org-archive-tag))
  7097. "")
  7098. (if org-agenda-clockreport-mode
  7099. (if (eq org-agenda-clockreport-mode 'with-filter)
  7100. " Clock{}" " Clock")
  7101. "")))
  7102. (force-mode-line-update))
  7103. (define-obsolete-function-alias
  7104. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7105. (defun org-agenda-update-agenda-type ()
  7106. "Update the agenda type after each command."
  7107. (setq org-agenda-type
  7108. (or (get-text-property (point) 'org-agenda-type)
  7109. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7110. (defun org-agenda-next-line ()
  7111. "Move cursor to the next line, and show if follow mode is active."
  7112. (interactive)
  7113. (call-interactively 'next-line)
  7114. (org-agenda-do-context-action))
  7115. (defun org-agenda-previous-line ()
  7116. "Move cursor to the previous line, and show if follow-mode is active."
  7117. (interactive)
  7118. (call-interactively 'previous-line)
  7119. (org-agenda-do-context-action))
  7120. (defun org-agenda-next-item (n)
  7121. "Move cursor to next agenda item."
  7122. (interactive "p")
  7123. (let ((col (current-column)))
  7124. (dotimes (c n)
  7125. (when (next-single-property-change (point-at-eol) 'org-marker)
  7126. (move-end-of-line 1)
  7127. (goto-char (next-single-property-change (point) 'org-marker))))
  7128. (org-move-to-column col))
  7129. (org-agenda-do-context-action))
  7130. (defun org-agenda-previous-item (n)
  7131. "Move cursor to next agenda item."
  7132. (interactive "p")
  7133. (dotimes (c n)
  7134. (let ((col (current-column))
  7135. (goto (save-excursion
  7136. (move-end-of-line 0)
  7137. (previous-single-property-change (point) 'org-marker))))
  7138. (if goto (goto-char goto))
  7139. (org-move-to-column col)))
  7140. (org-agenda-do-context-action))
  7141. (defun org-agenda-do-context-action ()
  7142. "Show outline path and, maybe, follow mode window."
  7143. (let ((m (org-get-at-bol 'org-marker)))
  7144. (when (and (markerp m) (marker-buffer m))
  7145. (and org-agenda-follow-mode
  7146. (if org-agenda-follow-indirect
  7147. (org-agenda-tree-to-indirect-buffer nil)
  7148. (org-agenda-show)))
  7149. (and org-agenda-show-outline-path
  7150. (org-with-point-at m (org-display-outline-path t))))))
  7151. (defun org-agenda-show-tags ()
  7152. "Show the tags applicable to the current item."
  7153. (interactive)
  7154. (let* ((tags (org-get-at-bol 'tags)))
  7155. (if tags
  7156. (message "Tags are :%s:"
  7157. (org-no-properties (mapconcat 'identity tags ":")))
  7158. (message "No tags associated with this line"))))
  7159. (defun org-agenda-goto (&optional highlight)
  7160. "Go to the Org-mode file which contains the item at point."
  7161. (interactive)
  7162. (let* ((marker (or (org-get-at-bol 'org-marker)
  7163. (org-agenda-error)))
  7164. (buffer (marker-buffer marker))
  7165. (pos (marker-position marker)))
  7166. (switch-to-buffer-other-window buffer)
  7167. (widen)
  7168. (push-mark)
  7169. (goto-char pos)
  7170. (when (derived-mode-p 'org-mode)
  7171. (org-show-context 'agenda)
  7172. (save-excursion
  7173. (and (outline-next-heading)
  7174. (org-flag-heading nil)))) ; show the next heading
  7175. (when (outline-invisible-p)
  7176. (show-entry)) ; display invisible text
  7177. (recenter (/ (window-height) 2))
  7178. (run-hooks 'org-agenda-after-show-hook)
  7179. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7180. (defvar org-agenda-after-show-hook nil
  7181. "Normal hook run after an item has been shown from the agenda.
  7182. Point is in the buffer where the item originated.")
  7183. (defun org-agenda-kill ()
  7184. "Kill the entry or subtree belonging to the current agenda entry."
  7185. (interactive)
  7186. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7187. (let* ((bufname-orig (buffer-name))
  7188. (marker (or (org-get-at-bol 'org-marker)
  7189. (org-agenda-error)))
  7190. (buffer (marker-buffer marker))
  7191. (pos (marker-position marker))
  7192. (type (org-get-at-bol 'type))
  7193. dbeg dend (n 0) conf)
  7194. (org-with-remote-undo buffer
  7195. (with-current-buffer buffer
  7196. (save-excursion
  7197. (goto-char pos)
  7198. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7199. (setq dbeg (progn (org-back-to-heading t) (point))
  7200. dend (org-end-of-subtree t t))
  7201. (setq dbeg (point-at-bol)
  7202. dend (min (point-max) (1+ (point-at-eol)))))
  7203. (goto-char dbeg)
  7204. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7205. (setq conf (or (eq t org-agenda-confirm-kill)
  7206. (and (numberp org-agenda-confirm-kill)
  7207. (> n org-agenda-confirm-kill))))
  7208. (and conf
  7209. (not (y-or-n-p
  7210. (format "Delete entry with %d lines in buffer \"%s\"? "
  7211. n (buffer-name buffer))))
  7212. (error "Abort"))
  7213. (let ((org-agenda-buffer-name bufname-orig))
  7214. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7215. (with-current-buffer buffer (delete-region dbeg dend))
  7216. (message "Agenda item and source killed"))))
  7217. (defvar org-archive-default-command) ; defined in org-archive.el
  7218. (defun org-agenda-archive-default ()
  7219. "Archive the entry or subtree belonging to the current agenda entry."
  7220. (interactive)
  7221. (require 'org-archive)
  7222. (org-agenda-archive-with org-archive-default-command))
  7223. (defun org-agenda-archive-default-with-confirmation ()
  7224. "Archive the entry or subtree belonging to the current agenda entry."
  7225. (interactive)
  7226. (require 'org-archive)
  7227. (org-agenda-archive-with org-archive-default-command 'confirm))
  7228. (defun org-agenda-archive ()
  7229. "Archive the entry or subtree belonging to the current agenda entry."
  7230. (interactive)
  7231. (org-agenda-archive-with 'org-archive-subtree))
  7232. (defun org-agenda-archive-to-archive-sibling ()
  7233. "Move the entry to the archive sibling."
  7234. (interactive)
  7235. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7236. (defun org-agenda-archive-with (cmd &optional confirm)
  7237. "Move the entry to the archive sibling."
  7238. (interactive)
  7239. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7240. (let* ((bufname-orig (buffer-name))
  7241. (marker (or (org-get-at-bol 'org-marker)
  7242. (org-agenda-error)))
  7243. (buffer (marker-buffer marker))
  7244. (pos (marker-position marker)))
  7245. (org-with-remote-undo buffer
  7246. (with-current-buffer buffer
  7247. (if (derived-mode-p 'org-mode)
  7248. (if (and confirm
  7249. (not (y-or-n-p "Archive this subtree or entry? ")))
  7250. (error "Abort")
  7251. (save-excursion
  7252. (goto-char pos)
  7253. (let ((org-agenda-buffer-name bufname-orig))
  7254. (org-remove-subtree-entries-from-agenda))
  7255. (org-back-to-heading t)
  7256. (funcall cmd)))
  7257. (error "Archiving works only in Org-mode files"))))))
  7258. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7259. "Remove all lines in the agenda that correspond to a given subtree.
  7260. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7261. If this information is not given, the function uses the tree at point."
  7262. (let ((buf (or buf (current-buffer))) m p)
  7263. (save-excursion
  7264. (unless (and beg end)
  7265. (org-back-to-heading t)
  7266. (setq beg (point))
  7267. (org-end-of-subtree t)
  7268. (setq end (point)))
  7269. (set-buffer (get-buffer org-agenda-buffer-name))
  7270. (save-excursion
  7271. (goto-char (point-max))
  7272. (beginning-of-line 1)
  7273. (while (not (bobp))
  7274. (when (and (setq m (org-get-at-bol 'org-marker))
  7275. (equal buf (marker-buffer m))
  7276. (setq p (marker-position m))
  7277. (>= p beg)
  7278. (< p end))
  7279. (let ((inhibit-read-only t))
  7280. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7281. (beginning-of-line 0))))))
  7282. (defun org-agenda-refile (&optional goto rfloc no-update)
  7283. "Refile the item at point."
  7284. (interactive "P")
  7285. (if (equal goto '(16))
  7286. (org-refile-goto-last-stored)
  7287. (let* ((buffer-orig (buffer-name))
  7288. (marker (or (org-get-at-bol 'org-hd-marker)
  7289. (org-agenda-error)))
  7290. (buffer (marker-buffer marker))
  7291. (pos (marker-position marker))
  7292. (rfloc (or rfloc
  7293. (org-refile-get-location
  7294. (if goto "Goto" "Refile to") buffer
  7295. org-refile-allow-creating-parent-nodes))))
  7296. (with-current-buffer buffer
  7297. (save-excursion
  7298. (save-restriction
  7299. (widen)
  7300. (goto-char marker)
  7301. (let ((org-agenda-buffer-name buffer-orig))
  7302. (org-remove-subtree-entries-from-agenda))
  7303. (org-refile goto buffer rfloc)))))
  7304. (unless no-update (org-agenda-redo))))
  7305. (defun org-agenda-open-link (&optional arg)
  7306. "Follow the link in the current line, if any.
  7307. This looks for a link in the displayed line in the agenda. It also looks
  7308. at the text of the entry itself."
  7309. (interactive "P")
  7310. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7311. (org-get-at-bol 'org-marker)))
  7312. (buffer (and marker (marker-buffer marker)))
  7313. (prefix (buffer-substring
  7314. (point-at-bol) (point-at-eol))))
  7315. (cond
  7316. (buffer
  7317. (with-current-buffer buffer
  7318. (save-excursion
  7319. (save-restriction
  7320. (widen)
  7321. (goto-char marker)
  7322. (org-offer-links-in-entry arg prefix)))))
  7323. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7324. (save-excursion
  7325. (beginning-of-line 1)
  7326. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7327. (org-open-link-from-string (match-string 1)))
  7328. (t (error "No link to open here")))))
  7329. (defun org-agenda-copy-local-variable (var)
  7330. "Get a variable from a referenced buffer and install it here."
  7331. (let ((m (org-get-at-bol 'org-marker)))
  7332. (when (and m (buffer-live-p (marker-buffer m)))
  7333. (org-set-local var (with-current-buffer (marker-buffer m)
  7334. (symbol-value var))))))
  7335. (defun org-agenda-switch-to (&optional delete-other-windows)
  7336. "Go to the Org-mode file which contains the item at point."
  7337. (interactive)
  7338. (if (and org-return-follows-link
  7339. (not (org-get-at-bol 'org-marker))
  7340. (org-in-regexp org-bracket-link-regexp))
  7341. (org-open-link-from-string (match-string 0))
  7342. (let* ((marker (or (org-get-at-bol 'org-marker)
  7343. (org-agenda-error)))
  7344. (buffer (marker-buffer marker))
  7345. (pos (marker-position marker)))
  7346. (org-pop-to-buffer-same-window buffer)
  7347. (and delete-other-windows (delete-other-windows))
  7348. (widen)
  7349. (goto-char pos)
  7350. (when (derived-mode-p 'org-mode)
  7351. (org-show-context 'agenda)
  7352. (save-excursion
  7353. (and (outline-next-heading)
  7354. (org-flag-heading nil))) ; show the next heading
  7355. (when (outline-invisible-p)
  7356. (show-entry)) ; display invisible text
  7357. (run-hooks 'org-agenda-after-show-hook)))))
  7358. (defun org-agenda-goto-mouse (ev)
  7359. "Go to the Org-mode file which contains the item at the mouse click."
  7360. (interactive "e")
  7361. (mouse-set-point ev)
  7362. (org-agenda-goto))
  7363. (defun org-agenda-show (&optional full-entry)
  7364. "Display the Org-mode file which contains the item at point.
  7365. With prefix argument FULL-ENTRY, make the entire entry visible
  7366. if it was hidden in the outline."
  7367. (interactive "P")
  7368. (let ((win (selected-window)))
  7369. (if full-entry
  7370. (let ((org-show-entry-below t))
  7371. (org-agenda-goto t))
  7372. (org-agenda-goto t))
  7373. (select-window win)))
  7374. (defvar org-agenda-show-window nil)
  7375. (defun org-agenda-show-and-scroll-up (&optional arg)
  7376. "Display the Org-mode file which contains the item at point.
  7377. When called repeatedly, scroll the window that is displaying the buffer.
  7378. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7379. `show-subtree' to display the item, so that drawers and logbooks stay
  7380. folded."
  7381. (interactive "P")
  7382. (let ((win (selected-window)))
  7383. (if (and (window-live-p org-agenda-show-window)
  7384. (eq this-command last-command))
  7385. (progn
  7386. (select-window org-agenda-show-window)
  7387. (ignore-errors (scroll-up)))
  7388. (org-agenda-goto t)
  7389. (if arg (org-show-entry) (show-subtree))
  7390. (setq org-agenda-show-window (selected-window)))
  7391. (select-window win)))
  7392. (defun org-agenda-show-scroll-down ()
  7393. "Scroll down the window showing the agenda."
  7394. (interactive)
  7395. (let ((win (selected-window)))
  7396. (when (window-live-p org-agenda-show-window)
  7397. (select-window org-agenda-show-window)
  7398. (ignore-errors (scroll-down))
  7399. (select-window win))))
  7400. (defun org-agenda-show-1 (&optional more)
  7401. "Display the Org-mode file which contains the item at point.
  7402. The prefix arg selects the amount of information to display:
  7403. 0 hide the subtree
  7404. 1 just show the entry according to defaults.
  7405. 2 show the children view
  7406. 3 show the subtree view
  7407. 4 show the entire subtree and any LOGBOOK drawers
  7408. 5 show the entire subtree and any drawers
  7409. With prefix argument FULL-ENTRY, make the entire entry visible
  7410. if it was hidden in the outline."
  7411. (interactive "p")
  7412. (let ((win (selected-window)))
  7413. (org-agenda-goto t)
  7414. (org-recenter-heading 1)
  7415. (cond
  7416. ((= more 0)
  7417. (hide-subtree)
  7418. (save-excursion
  7419. (org-back-to-heading)
  7420. (run-hook-with-args 'org-cycle-hook 'folded))
  7421. (message "Remote: FOLDED"))
  7422. ((and (org-called-interactively-p 'any) (= more 1))
  7423. (message "Remote: show with default settings"))
  7424. ((= more 2)
  7425. (show-entry)
  7426. (show-children)
  7427. (save-excursion
  7428. (org-back-to-heading)
  7429. (run-hook-with-args 'org-cycle-hook 'children))
  7430. (message "Remote: CHILDREN"))
  7431. ((= more 3)
  7432. (show-subtree)
  7433. (save-excursion
  7434. (org-back-to-heading)
  7435. (run-hook-with-args 'org-cycle-hook 'subtree))
  7436. (message "Remote: SUBTREE"))
  7437. ((= more 4)
  7438. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7439. (org-drawer-regexp
  7440. (concat "^[ \t]*:\\("
  7441. (mapconcat 'regexp-quote org-drawers "\\|")
  7442. "\\):[ \t]*$")))
  7443. (show-subtree)
  7444. (save-excursion
  7445. (org-back-to-heading)
  7446. (org-cycle-hide-drawers 'subtree)))
  7447. (message "Remote: SUBTREE AND LOGBOOK"))
  7448. ((> more 4)
  7449. (show-subtree)
  7450. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7451. (select-window win)))
  7452. (defun org-recenter-heading (n)
  7453. (save-excursion
  7454. (org-back-to-heading)
  7455. (recenter n)))
  7456. (defvar org-agenda-cycle-counter nil)
  7457. (defun org-agenda-cycle-show (&optional n)
  7458. "Show the current entry in another window, with default settings.
  7459. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7460. When use repeatedly in immediate succession, the remote entry will cycle
  7461. through visibility
  7462. children -> subtree -> folded
  7463. When called with a numeric prefix arg, that arg will be passed through to
  7464. `org-agenda-show-1'. For the interpretation of that argument, see the
  7465. docstring of `org-agenda-show-1'."
  7466. (interactive "P")
  7467. (if (integerp n)
  7468. (setq org-agenda-cycle-counter n)
  7469. (if (not (eq last-command this-command))
  7470. (setq org-agenda-cycle-counter 1)
  7471. (if (equal org-agenda-cycle-counter 0)
  7472. (setq org-agenda-cycle-counter 2)
  7473. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7474. (if (> org-agenda-cycle-counter 3)
  7475. (setq org-agenda-cycle-counter 0)))))
  7476. (org-agenda-show-1 org-agenda-cycle-counter))
  7477. (defun org-agenda-recenter (arg)
  7478. "Display the Org-mode file which contains the item at point and recenter."
  7479. (interactive "P")
  7480. (let ((win (selected-window)))
  7481. (org-agenda-goto t)
  7482. (recenter arg)
  7483. (select-window win)))
  7484. (defun org-agenda-show-mouse (ev)
  7485. "Display the Org-mode file which contains the item at the mouse click."
  7486. (interactive "e")
  7487. (mouse-set-point ev)
  7488. (org-agenda-show))
  7489. (defun org-agenda-check-no-diary ()
  7490. "Check if the entry is a diary link and abort if yes."
  7491. (if (org-get-at-bol 'org-agenda-diary-link)
  7492. (org-agenda-error)))
  7493. (defun org-agenda-error ()
  7494. (error "Command not allowed in this line"))
  7495. (defun org-agenda-tree-to-indirect-buffer (arg)
  7496. "Show the subtree corresponding to the current entry in an indirect buffer.
  7497. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7498. With a numerical prefix ARG, go up to this level and then take that tree.
  7499. With a negative numeric ARG, go up by this number of levels.
  7500. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7501. use the dedicated frame)."
  7502. (interactive "P")
  7503. (if current-prefix-arg
  7504. (org-agenda-do-tree-to-indirect-buffer arg)
  7505. (let ((agenda-buffer (buffer-name))
  7506. (agenda-window (selected-window))
  7507. (indirect-window
  7508. (and org-last-indirect-buffer
  7509. (get-buffer-window org-last-indirect-buffer))))
  7510. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7511. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7512. (eq org-indirect-buffer-display 'dedicated-frame))
  7513. (unwind-protect
  7514. (unless (and indirect-window (window-live-p indirect-window))
  7515. (setq indirect-window (split-window agenda-window)))
  7516. (and indirect-window (select-window indirect-window))
  7517. (switch-to-buffer org-last-indirect-buffer :norecord)
  7518. (fit-window-to-buffer indirect-window)))
  7519. (select-window (get-buffer-window agenda-buffer)))))
  7520. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7521. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7522. (org-agenda-check-no-diary)
  7523. (let* ((marker (or (org-get-at-bol 'org-marker)
  7524. (org-agenda-error)))
  7525. (buffer (marker-buffer marker))
  7526. (pos (marker-position marker)))
  7527. (with-current-buffer buffer
  7528. (save-excursion
  7529. (goto-char pos)
  7530. (funcall 'org-tree-to-indirect-buffer arg)))))
  7531. (defvar org-last-heading-marker (make-marker)
  7532. "Marker pointing to the headline that last changed its TODO state
  7533. by a remote command from the agenda.")
  7534. (defun org-agenda-todo-nextset ()
  7535. "Switch TODO entry to next sequence."
  7536. (interactive)
  7537. (org-agenda-todo 'nextset))
  7538. (defun org-agenda-todo-previousset ()
  7539. "Switch TODO entry to previous sequence."
  7540. (interactive)
  7541. (org-agenda-todo 'previousset))
  7542. (defun org-agenda-todo (&optional arg)
  7543. "Cycle TODO state of line at point, also in Org-mode file.
  7544. This changes the line at point, all other lines in the agenda referring to
  7545. the same tree node, and the headline of the tree node in the Org-mode file."
  7546. (interactive "P")
  7547. (org-agenda-check-no-diary)
  7548. (let* ((col (current-column))
  7549. (marker (or (org-get-at-bol 'org-marker)
  7550. (org-agenda-error)))
  7551. (buffer (marker-buffer marker))
  7552. (pos (marker-position marker))
  7553. (hdmarker (org-get-at-bol 'org-hd-marker))
  7554. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7555. (inhibit-read-only t)
  7556. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7557. (org-with-remote-undo buffer
  7558. (with-current-buffer buffer
  7559. (widen)
  7560. (goto-char pos)
  7561. (org-show-context 'agenda)
  7562. (save-excursion
  7563. (and (outline-next-heading)
  7564. (org-flag-heading nil))) ; show the next heading
  7565. (let ((current-prefix-arg arg))
  7566. (call-interactively 'org-todo))
  7567. (and (bolp) (forward-char 1))
  7568. (setq newhead (org-get-heading))
  7569. (when (and (org-bound-and-true-p
  7570. org-agenda-headline-snapshot-before-repeat)
  7571. (not (equal org-agenda-headline-snapshot-before-repeat
  7572. newhead))
  7573. todayp)
  7574. (setq newhead org-agenda-headline-snapshot-before-repeat
  7575. just-one t))
  7576. (save-excursion
  7577. (org-back-to-heading)
  7578. (move-marker org-last-heading-marker (point))))
  7579. (beginning-of-line 1)
  7580. (save-excursion
  7581. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7582. (org-move-to-column col))))
  7583. (defun org-agenda-add-note (&optional arg)
  7584. "Add a time-stamped note to the entry at point."
  7585. (interactive "P")
  7586. (org-agenda-check-no-diary)
  7587. (let* ((marker (or (org-get-at-bol 'org-marker)
  7588. (org-agenda-error)))
  7589. (buffer (marker-buffer marker))
  7590. (pos (marker-position marker))
  7591. (hdmarker (org-get-at-bol 'org-hd-marker))
  7592. (inhibit-read-only t))
  7593. (with-current-buffer buffer
  7594. (widen)
  7595. (goto-char pos)
  7596. (org-show-context 'agenda)
  7597. (save-excursion
  7598. (and (outline-next-heading)
  7599. (org-flag-heading nil))) ; show the next heading
  7600. (org-add-note))))
  7601. (defun org-agenda-change-all-lines (newhead hdmarker
  7602. &optional fixface just-this)
  7603. "Change all lines in the agenda buffer which match HDMARKER.
  7604. The new content of the line will be NEWHEAD (as modified by
  7605. `org-agenda-format-item'). HDMARKER is checked with
  7606. `equal' against all `org-hd-marker' text properties in the file.
  7607. If FIXFACE is non-nil, the face of each item is modified according to
  7608. the new TODO state.
  7609. If JUST-THIS is non-nil, change just the current line, not all.
  7610. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7611. (let* ((inhibit-read-only t)
  7612. (line (org-current-line))
  7613. (org-agenda-buffer (current-buffer))
  7614. (thetags (with-current-buffer (marker-buffer hdmarker)
  7615. (save-excursion (save-restriction (widen)
  7616. (goto-char hdmarker)
  7617. (org-get-tags-at)))))
  7618. props m pl undone-face done-face finish new dotime cat tags)
  7619. (save-excursion
  7620. (goto-char (point-max))
  7621. (beginning-of-line 1)
  7622. (while (not finish)
  7623. (setq finish (bobp))
  7624. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7625. (or (not just-this) (= (org-current-line) line))
  7626. (equal m hdmarker))
  7627. (setq props (text-properties-at (point))
  7628. dotime (org-get-at-bol 'dotime)
  7629. cat (org-get-at-bol 'org-category)
  7630. tags thetags
  7631. new
  7632. (let ((org-prefix-format-compiled
  7633. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7634. org-prefix-format-compiled))
  7635. (extra (org-get-at-bol 'extra)))
  7636. (with-current-buffer (marker-buffer hdmarker)
  7637. (save-excursion
  7638. (save-restriction
  7639. (widen)
  7640. (org-agenda-format-item extra newhead cat tags dotime)))))
  7641. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7642. undone-face (org-get-at-bol 'undone-face)
  7643. done-face (org-get-at-bol 'done-face))
  7644. (beginning-of-line 1)
  7645. (cond
  7646. ((equal new "")
  7647. (and (looking-at ".*\n?") (replace-match "")))
  7648. ((looking-at ".*")
  7649. (replace-match new t t)
  7650. (beginning-of-line 1)
  7651. (add-text-properties (point-at-bol) (point-at-eol) props)
  7652. (when fixface
  7653. (add-text-properties
  7654. (point-at-bol) (point-at-eol)
  7655. (list 'face
  7656. (if org-last-todo-state-is-todo
  7657. undone-face done-face))))
  7658. (org-agenda-highlight-todo 'line)
  7659. (beginning-of-line 1))
  7660. (t (error "Line update did not work")))
  7661. (save-restriction
  7662. (narrow-to-region (point-at-bol) (point-at-eol))
  7663. (org-agenda-finalize)))
  7664. (beginning-of-line 0)))))
  7665. (defun org-agenda-align-tags (&optional line)
  7666. "Align all tags in agenda items to `org-agenda-tags-column'."
  7667. (let ((inhibit-read-only t) l c)
  7668. (save-excursion
  7669. (goto-char (if line (point-at-bol) (point-min)))
  7670. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7671. (if line (point-at-eol) nil) t)
  7672. (add-text-properties
  7673. (match-beginning 2) (match-end 2)
  7674. (list 'face (delq nil (let ((prop (get-text-property
  7675. (match-beginning 2) 'face)))
  7676. (or (listp prop) (setq prop (list prop)))
  7677. (if (memq 'org-tag prop)
  7678. prop
  7679. (cons 'org-tag prop))))))
  7680. (setq l (- (match-end 2) (match-beginning 2))
  7681. c (if (< org-agenda-tags-column 0)
  7682. (- (abs org-agenda-tags-column) l)
  7683. org-agenda-tags-column))
  7684. (delete-region (match-beginning 1) (match-end 1))
  7685. (goto-char (match-beginning 1))
  7686. (insert (org-add-props
  7687. (make-string (max 1 (- c (current-column))) ?\ )
  7688. (plist-put (copy-sequence (text-properties-at (point)))
  7689. 'face nil))))
  7690. (goto-char (point-min))
  7691. (org-font-lock-add-tag-faces (point-max)))))
  7692. (defun org-agenda-priority-up ()
  7693. "Increase the priority of line at point, also in Org-mode file."
  7694. (interactive)
  7695. (org-agenda-priority 'up))
  7696. (defun org-agenda-priority-down ()
  7697. "Decrease the priority of line at point, also in Org-mode file."
  7698. (interactive)
  7699. (org-agenda-priority 'down))
  7700. (defun org-agenda-priority (&optional force-direction show)
  7701. "Set the priority of line at point, also in Org-mode file.
  7702. This changes the line at point, all other lines in the agenda referring to
  7703. the same tree node, and the headline of the tree node in the Org-mode file."
  7704. (interactive "P")
  7705. (if (equal force-direction '(4)) (setq show t))
  7706. (unless org-enable-priority-commands
  7707. (error "Priority commands are disabled"))
  7708. (org-agenda-check-no-diary)
  7709. (let* ((marker (or (org-get-at-bol 'org-marker)
  7710. (org-agenda-error)))
  7711. (hdmarker (org-get-at-bol 'org-hd-marker))
  7712. (buffer (marker-buffer hdmarker))
  7713. (pos (marker-position hdmarker))
  7714. (inhibit-read-only t)
  7715. newhead)
  7716. (org-with-remote-undo buffer
  7717. (with-current-buffer buffer
  7718. (widen)
  7719. (goto-char pos)
  7720. (org-show-context 'agenda)
  7721. (save-excursion
  7722. (and (outline-next-heading)
  7723. (org-flag-heading nil))) ; show the next heading
  7724. (funcall 'org-priority force-direction show)
  7725. (end-of-line 1)
  7726. (setq newhead (org-get-heading)))
  7727. (org-agenda-change-all-lines newhead hdmarker)
  7728. (beginning-of-line 1))))
  7729. ;; FIXME: should fix the tags property of the agenda line.
  7730. (defun org-agenda-set-tags (&optional tag onoff)
  7731. "Set tags for the current headline."
  7732. (interactive)
  7733. (org-agenda-check-no-diary)
  7734. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7735. (call-interactively 'org-change-tag-in-region)
  7736. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7737. (org-agenda-error)))
  7738. (buffer (marker-buffer hdmarker))
  7739. (pos (marker-position hdmarker))
  7740. (inhibit-read-only t)
  7741. newhead)
  7742. (org-with-remote-undo buffer
  7743. (with-current-buffer buffer
  7744. (widen)
  7745. (goto-char pos)
  7746. (save-excursion
  7747. (org-show-context 'agenda))
  7748. (save-excursion
  7749. (and (outline-next-heading)
  7750. (org-flag-heading nil))) ; show the next heading
  7751. (goto-char pos)
  7752. (if tag
  7753. (org-toggle-tag tag onoff)
  7754. (call-interactively 'org-set-tags))
  7755. (end-of-line 1)
  7756. (setq newhead (org-get-heading)))
  7757. (org-agenda-change-all-lines newhead hdmarker)
  7758. (beginning-of-line 1)))))
  7759. (defun org-agenda-set-property ()
  7760. "Set a property for the current headline."
  7761. (interactive)
  7762. (org-agenda-check-no-diary)
  7763. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7764. (org-agenda-error)))
  7765. (buffer (marker-buffer hdmarker))
  7766. (pos (marker-position hdmarker))
  7767. (inhibit-read-only t)
  7768. newhead)
  7769. (org-with-remote-undo buffer
  7770. (with-current-buffer buffer
  7771. (widen)
  7772. (goto-char pos)
  7773. (save-excursion
  7774. (org-show-context 'agenda))
  7775. (save-excursion
  7776. (and (outline-next-heading)
  7777. (org-flag-heading nil))) ; show the next heading
  7778. (goto-char pos)
  7779. (call-interactively 'org-set-property)))))
  7780. (defun org-agenda-set-effort ()
  7781. "Set the effort property for the current headline."
  7782. (interactive)
  7783. (org-agenda-check-no-diary)
  7784. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7785. (org-agenda-error)))
  7786. (buffer (marker-buffer hdmarker))
  7787. (pos (marker-position hdmarker))
  7788. (inhibit-read-only t)
  7789. newhead)
  7790. (org-with-remote-undo buffer
  7791. (with-current-buffer buffer
  7792. (widen)
  7793. (goto-char pos)
  7794. (save-excursion
  7795. (org-show-context 'agenda))
  7796. (save-excursion
  7797. (and (outline-next-heading)
  7798. (org-flag-heading nil))) ; show the next heading
  7799. (goto-char pos)
  7800. (call-interactively 'org-set-effort)
  7801. (end-of-line 1)
  7802. (setq newhead (org-get-heading)))
  7803. (org-agenda-change-all-lines newhead hdmarker))))
  7804. (defun org-agenda-toggle-archive-tag ()
  7805. "Toggle the archive tag for the current entry."
  7806. (interactive)
  7807. (org-agenda-check-no-diary)
  7808. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7809. (org-agenda-error)))
  7810. (buffer (marker-buffer hdmarker))
  7811. (pos (marker-position hdmarker))
  7812. (inhibit-read-only t)
  7813. newhead)
  7814. (org-with-remote-undo buffer
  7815. (with-current-buffer buffer
  7816. (widen)
  7817. (goto-char pos)
  7818. (org-show-context 'agenda)
  7819. (save-excursion
  7820. (and (outline-next-heading)
  7821. (org-flag-heading nil))) ; show the next heading
  7822. (call-interactively 'org-toggle-archive-tag)
  7823. (end-of-line 1)
  7824. (setq newhead (org-get-heading)))
  7825. (org-agenda-change-all-lines newhead hdmarker)
  7826. (beginning-of-line 1))))
  7827. (defun org-agenda-do-date-later (arg)
  7828. (interactive "P")
  7829. (cond
  7830. ((or (equal arg '(16))
  7831. (memq last-command
  7832. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7833. (setq this-command 'org-agenda-date-later-minutes)
  7834. (org-agenda-date-later-minutes 1))
  7835. ((or (equal arg '(4))
  7836. (memq last-command
  7837. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7838. (setq this-command 'org-agenda-date-later-hours)
  7839. (org-agenda-date-later-hours 1))
  7840. (t
  7841. (org-agenda-date-later (prefix-numeric-value arg)))))
  7842. (defun org-agenda-do-date-earlier (arg)
  7843. (interactive "P")
  7844. (cond
  7845. ((or (equal arg '(16))
  7846. (memq last-command
  7847. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7848. (setq this-command 'org-agenda-date-earlier-minutes)
  7849. (org-agenda-date-earlier-minutes 1))
  7850. ((or (equal arg '(4))
  7851. (memq last-command
  7852. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7853. (setq this-command 'org-agenda-date-earlier-hours)
  7854. (org-agenda-date-earlier-hours 1))
  7855. (t
  7856. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7857. (defun org-agenda-date-later (arg &optional what)
  7858. "Change the date of this item to ARG day(s) later."
  7859. (interactive "p")
  7860. (org-agenda-check-type t 'agenda 'timeline)
  7861. (org-agenda-check-no-diary)
  7862. (let* ((marker (or (org-get-at-bol 'org-marker)
  7863. (org-agenda-error)))
  7864. (buffer (marker-buffer marker))
  7865. (pos (marker-position marker))
  7866. cdate today)
  7867. (org-with-remote-undo buffer
  7868. (with-current-buffer buffer
  7869. (widen)
  7870. (goto-char pos)
  7871. (if (not (org-at-timestamp-p))
  7872. (error "Cannot find time stamp"))
  7873. (when (and org-agenda-move-date-from-past-immediately-to-today
  7874. (equal arg 1)
  7875. (or (not what) (eq what 'day))
  7876. (not (save-match-data (org-at-date-range-p))))
  7877. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7878. cdate (calendar-absolute-from-gregorian
  7879. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7880. today (org-today))
  7881. (if (> today cdate)
  7882. ;; immediately shift to today
  7883. (setq arg (- today cdate))))
  7884. (org-timestamp-change arg (or what 'day))
  7885. (when (and (org-at-date-range-p)
  7886. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7887. (let ((end org-last-changed-timestamp))
  7888. (org-timestamp-change arg (or what 'day))
  7889. (setq org-last-changed-timestamp
  7890. (concat org-last-changed-timestamp "--" end)))))
  7891. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7892. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7893. (defun org-agenda-date-earlier (arg &optional what)
  7894. "Change the date of this item to ARG day(s) earlier."
  7895. (interactive "p")
  7896. (org-agenda-date-later (- arg) what))
  7897. (defun org-agenda-date-later-minutes (arg)
  7898. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7899. (interactive "p")
  7900. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7901. (org-agenda-date-later arg 'minute))
  7902. (defun org-agenda-date-earlier-minutes (arg)
  7903. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7904. (interactive "p")
  7905. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7906. (org-agenda-date-earlier arg 'minute))
  7907. (defun org-agenda-date-later-hours (arg)
  7908. "Change the time of this item, in hour steps."
  7909. (interactive "p")
  7910. (org-agenda-date-later arg 'hour))
  7911. (defun org-agenda-date-earlier-hours (arg)
  7912. "Change the time of this item, in hour steps."
  7913. (interactive "p")
  7914. (org-agenda-date-earlier arg 'hour))
  7915. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7916. "Show new date stamp via text properties."
  7917. ;; We use text properties to make this undoable
  7918. (let ((inhibit-read-only t)
  7919. (buffer-invisibility-spec))
  7920. (setq stamp (concat " " prefix " => " stamp))
  7921. (save-excursion
  7922. (goto-char (point-max))
  7923. (while (not (bobp))
  7924. (when (equal marker (org-get-at-bol 'org-marker))
  7925. (org-move-to-column (- (window-width) (length stamp)) t)
  7926. (org-agenda-fix-tags-filter-overlays-at (point))
  7927. (if (featurep 'xemacs)
  7928. ;; Use `duplicable' property to trigger undo recording
  7929. (let ((ex (make-extent nil nil))
  7930. (gl (make-glyph stamp)))
  7931. (set-glyph-face gl 'secondary-selection)
  7932. (set-extent-properties
  7933. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7934. (insert-extent ex (1- (point)) (point-at-eol)))
  7935. (add-text-properties
  7936. (1- (point)) (point-at-eol)
  7937. (list 'display (org-add-props stamp nil
  7938. 'face 'secondary-selection))))
  7939. (beginning-of-line 1))
  7940. (beginning-of-line 0)))))
  7941. (defun org-agenda-date-prompt (arg)
  7942. "Change the date of this item. Date is prompted for, with default today.
  7943. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7944. be used to request time specification in the time stamp."
  7945. (interactive "P")
  7946. (org-agenda-check-type t 'agenda 'timeline)
  7947. (org-agenda-check-no-diary)
  7948. (let* ((marker (or (org-get-at-bol 'org-marker)
  7949. (org-agenda-error)))
  7950. (buffer (marker-buffer marker))
  7951. (pos (marker-position marker)))
  7952. (org-with-remote-undo buffer
  7953. (with-current-buffer buffer
  7954. (widen)
  7955. (goto-char pos)
  7956. (if (not (org-at-timestamp-p t))
  7957. (error "Cannot find time stamp"))
  7958. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7959. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7960. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7961. (defun org-agenda-schedule (arg &optional time)
  7962. "Schedule the item at point.
  7963. ARG is passed through to `org-schedule'."
  7964. (interactive "P")
  7965. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7966. (org-agenda-check-no-diary)
  7967. (let* ((marker (or (org-get-at-bol 'org-marker)
  7968. (org-agenda-error)))
  7969. (type (marker-insertion-type marker))
  7970. (buffer (marker-buffer marker))
  7971. (pos (marker-position marker))
  7972. (org-insert-labeled-timestamps-at-point nil)
  7973. ts)
  7974. (set-marker-insertion-type marker t)
  7975. (org-with-remote-undo buffer
  7976. (with-current-buffer buffer
  7977. (widen)
  7978. (goto-char pos)
  7979. (setq ts (org-schedule arg time)))
  7980. (org-agenda-show-new-time marker ts "S"))
  7981. (message "Item scheduled for %s" ts)))
  7982. (defun org-agenda-deadline (arg &optional time)
  7983. "Schedule the item at point.
  7984. ARG is passed through to `org-deadline'."
  7985. (interactive "P")
  7986. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7987. (org-agenda-check-no-diary)
  7988. (let* ((marker (or (org-get-at-bol 'org-marker)
  7989. (org-agenda-error)))
  7990. (buffer (marker-buffer marker))
  7991. (pos (marker-position marker))
  7992. (org-insert-labeled-timestamps-at-point nil)
  7993. ts)
  7994. (org-with-remote-undo buffer
  7995. (with-current-buffer buffer
  7996. (widen)
  7997. (goto-char pos)
  7998. (setq ts (org-deadline arg time)))
  7999. (org-agenda-show-new-time marker ts "D"))
  8000. (message "Deadline for this item set to %s" ts)))
  8001. (defun org-agenda-clock-in (&optional arg)
  8002. "Start the clock on the currently selected item."
  8003. (interactive "P")
  8004. (org-agenda-check-no-diary)
  8005. (if (equal arg '(4))
  8006. (org-clock-in arg)
  8007. (let* ((marker (or (org-get-at-bol 'org-marker)
  8008. (org-agenda-error)))
  8009. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8010. marker))
  8011. (pos (marker-position marker))
  8012. newhead)
  8013. (org-with-remote-undo (marker-buffer marker)
  8014. (with-current-buffer (marker-buffer marker)
  8015. (widen)
  8016. (goto-char pos)
  8017. (org-show-context 'agenda)
  8018. (org-show-entry)
  8019. (org-cycle-hide-drawers 'children)
  8020. (org-clock-in arg)
  8021. (setq newhead (org-get-heading)))
  8022. (org-agenda-change-all-lines newhead hdmarker)))))
  8023. (defun org-agenda-clock-out ()
  8024. "Stop the currently running clock."
  8025. (interactive)
  8026. (unless (marker-buffer org-clock-marker)
  8027. (error "No running clock"))
  8028. (let ((marker (make-marker)) newhead)
  8029. (org-with-remote-undo (marker-buffer org-clock-marker)
  8030. (with-current-buffer (marker-buffer org-clock-marker)
  8031. (save-excursion
  8032. (save-restriction
  8033. (widen)
  8034. (goto-char org-clock-marker)
  8035. (org-back-to-heading t)
  8036. (move-marker marker (point))
  8037. (org-clock-out)
  8038. (setq newhead (org-get-heading))))))
  8039. (org-agenda-change-all-lines newhead marker)
  8040. (move-marker marker nil)))
  8041. (defun org-agenda-clock-cancel (&optional arg)
  8042. "Cancel the currently running clock."
  8043. (interactive "P")
  8044. (unless (marker-buffer org-clock-marker)
  8045. (error "No running clock"))
  8046. (org-with-remote-undo (marker-buffer org-clock-marker)
  8047. (org-clock-cancel)))
  8048. (defun org-agenda-clock-goto ()
  8049. "Jump to the currently clocked in task within the agenda.
  8050. If the currently clocked in task is not listed in the agenda
  8051. buffer, display it in another window."
  8052. (interactive)
  8053. (let (pos)
  8054. (mapc (lambda (o)
  8055. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8056. (setq pos (overlay-start o))))
  8057. (overlays-in (point-min) (point-max)))
  8058. (cond (pos (goto-char pos))
  8059. ;; If the currently clocked entry is not in the agenda
  8060. ;; buffer, we visit it in another window:
  8061. (org-clock-current-task
  8062. (org-switch-to-buffer-other-window (org-clock-goto)))
  8063. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8064. (defun org-agenda-diary-entry-in-org-file ()
  8065. "Make a diary entry in the file `org-agenda-diary-file'."
  8066. (let (d1 d2 char (text "") dp1 dp2)
  8067. (if (equal (buffer-name) "*Calendar*")
  8068. (setq d1 (calendar-cursor-to-date t)
  8069. d2 (car calendar-mark-ring))
  8070. (setq dp1 (get-text-property (point-at-bol) 'day))
  8071. (unless dp1 (error "No date defined in current line"))
  8072. (setq d1 (calendar-gregorian-from-absolute dp1)
  8073. d2 (and (ignore-errors (mark))
  8074. (save-excursion
  8075. (goto-char (mark))
  8076. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8077. (calendar-gregorian-from-absolute dp2))))
  8078. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8079. (setq char (read-char-exclusive))
  8080. (cond
  8081. ((equal char ?d)
  8082. (setq text (read-string "Day entry: "))
  8083. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8084. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8085. ((equal char ?a)
  8086. (setq d1 (list (car d1) (nth 1 d1)
  8087. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8088. (nth 2 d1))))
  8089. (setq text (read-string "Anniversary (use %d to show years): "))
  8090. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8091. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8092. ((equal char ?b)
  8093. (setq text (read-string "Block entry: "))
  8094. (unless (and d1 d2 (not (equal d1 d2)))
  8095. (error "No block of days selected"))
  8096. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8097. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8098. ((equal char ?j)
  8099. (org-switch-to-buffer-other-window
  8100. (find-file-noselect org-agenda-diary-file))
  8101. (require 'org-datetree)
  8102. (org-datetree-find-date-create d1)
  8103. (org-reveal t))
  8104. (t (error "Invalid selection character `%c'" char)))))
  8105. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8106. "Where in `org-agenda-diary-file' should new entries be added?
  8107. Valid values:
  8108. date-tree in the date tree, as child of the date
  8109. top-level as top-level entries at the end of the file."
  8110. :group 'org-agenda
  8111. :type '(choice
  8112. (const :tag "in a date tree" date-tree)
  8113. (const :tag "as top level at end of file" top-level)))
  8114. (defcustom org-agenda-insert-diary-extract-time nil
  8115. "Non-nil means extract any time specification from the diary entry."
  8116. :group 'org-agenda
  8117. :version "24.1"
  8118. :type 'boolean)
  8119. (defcustom org-agenda-bulk-mark-char ">"
  8120. "A single-character string to be used as the bulk mark."
  8121. :group 'org-agenda
  8122. :version "24.1"
  8123. :type 'string)
  8124. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8125. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8126. If TEXT is not empty, it will become the headline of the new entry, and
  8127. the resulting entry will not be shown. When TEXT is empty, switch to
  8128. `org-agenda-diary-file' and let the user finish the entry there."
  8129. (let ((cw (current-window-configuration)))
  8130. (org-switch-to-buffer-other-window
  8131. (find-file-noselect org-agenda-diary-file))
  8132. (widen)
  8133. (goto-char (point-min))
  8134. (cond
  8135. ((eq type 'anniversary)
  8136. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8137. (progn
  8138. (or (org-at-heading-p t)
  8139. (progn
  8140. (outline-next-heading)
  8141. (insert "* Anniversaries\n\n")
  8142. (beginning-of-line -1)))))
  8143. (outline-next-heading)
  8144. (org-back-over-empty-lines)
  8145. (backward-char 1)
  8146. (insert "\n")
  8147. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8148. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8149. ((eq type 'day)
  8150. (let ((org-prefix-has-time t)
  8151. (org-agenda-time-leading-zero t)
  8152. fmt time time2)
  8153. (if org-agenda-insert-diary-extract-time
  8154. ;; Use org-agenda-format-item to parse text for a time-range and
  8155. ;; remove it. FIXME: This is a hack, we should refactor
  8156. ;; that function to make time extraction available separately
  8157. (setq fmt (org-agenda-format-item nil text nil nil t)
  8158. time (get-text-property 0 'time fmt)
  8159. time2 (if (> (length time) 0)
  8160. ;; split-string removes trailing ...... if
  8161. ;; no end time given. First space
  8162. ;; separates time from date.
  8163. (concat " " (car (split-string time "\\.")))
  8164. nil)
  8165. text (get-text-property 0 'txt fmt)))
  8166. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8167. (org-agenda-insert-diary-as-top-level text)
  8168. (require 'org-datetree)
  8169. (org-datetree-find-date-create d1)
  8170. (org-agenda-insert-diary-make-new-entry text))
  8171. (org-insert-time-stamp (org-time-from-absolute
  8172. (calendar-absolute-from-gregorian d1))
  8173. nil nil nil nil time2))
  8174. (end-of-line 0))
  8175. ((eq type 'block)
  8176. (if (> (calendar-absolute-from-gregorian d1)
  8177. (calendar-absolute-from-gregorian d2))
  8178. (setq d1 (prog1 d2 (setq d2 d1))))
  8179. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8180. (org-agenda-insert-diary-as-top-level text)
  8181. (require 'org-datetree)
  8182. (org-datetree-find-date-create d1)
  8183. (org-agenda-insert-diary-make-new-entry text))
  8184. (org-insert-time-stamp (org-time-from-absolute
  8185. (calendar-absolute-from-gregorian d1)))
  8186. (insert "--")
  8187. (org-insert-time-stamp (org-time-from-absolute
  8188. (calendar-absolute-from-gregorian d2)))
  8189. (end-of-line 0)))
  8190. (if (string-match "\\S-" text)
  8191. (progn
  8192. (set-window-configuration cw)
  8193. (message "%s entry added to %s"
  8194. (capitalize (symbol-name type))
  8195. (abbreviate-file-name org-agenda-diary-file)))
  8196. (org-reveal t)
  8197. (message "Please finish entry here"))))
  8198. (defun org-agenda-insert-diary-as-top-level (text)
  8199. "Make new entry as a top-level entry at the end of the file.
  8200. Add TEXT as headline, and position the cursor in the second line so that
  8201. a timestamp can be added there."
  8202. (widen)
  8203. (goto-char (point-max))
  8204. (or (bolp) (insert "\n"))
  8205. (insert "* " text "\n")
  8206. (if org-adapt-indentation (org-indent-to-column 2)))
  8207. (defun org-agenda-insert-diary-make-new-entry (text)
  8208. "Make new entry as last child of current entry.
  8209. Add TEXT as headline, and position the cursor in the second line so that
  8210. a timestamp can be added there."
  8211. (let ((org-show-following-heading t)
  8212. (org-show-siblings t)
  8213. (org-show-hierarchy-above t)
  8214. (org-show-entry-below t)
  8215. col)
  8216. (outline-next-heading)
  8217. (org-back-over-empty-lines)
  8218. (or (looking-at "[ \t]*$")
  8219. (progn (insert "\n") (backward-char 1)))
  8220. (org-insert-heading nil t)
  8221. (org-do-demote)
  8222. (setq col (current-column))
  8223. (insert text "\n")
  8224. (if org-adapt-indentation (org-indent-to-column col))
  8225. (let ((org-show-following-heading t)
  8226. (org-show-siblings t)
  8227. (org-show-hierarchy-above t)
  8228. (org-show-entry-below t))
  8229. (org-show-context))))
  8230. (defun org-agenda-diary-entry ()
  8231. "Make a diary entry, like the `i' command from the calendar.
  8232. All the standard commands work: block, weekly etc.
  8233. When `org-agenda-diary-file' points to a file,
  8234. `org-agenda-diary-entry-in-org-file' is called instead to create
  8235. entries in that Org-mode file."
  8236. (interactive)
  8237. (if (not (eq org-agenda-diary-file 'diary-file))
  8238. (org-agenda-diary-entry-in-org-file)
  8239. (require 'diary-lib)
  8240. (let* ((char (progn
  8241. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8242. (read-char-exclusive)))
  8243. (cmd (cdr (assoc char
  8244. '((?d . insert-diary-entry)
  8245. (?w . insert-weekly-diary-entry)
  8246. (?m . insert-monthly-diary-entry)
  8247. (?y . insert-yearly-diary-entry)
  8248. (?a . insert-anniversary-diary-entry)
  8249. (?b . insert-block-diary-entry)
  8250. (?c . insert-cyclic-diary-entry)))))
  8251. (oldf (symbol-function 'calendar-cursor-to-date))
  8252. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8253. (point (point))
  8254. (mark (or (mark t) (point))))
  8255. (unless cmd
  8256. (error "No command associated with <%c>" char))
  8257. (unless (and (get-text-property point 'day)
  8258. (or (not (equal ?b char))
  8259. (get-text-property mark 'day)))
  8260. (error "Don't know which date to use for diary entry"))
  8261. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8262. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8263. (let ((calendar-mark-ring
  8264. (list (calendar-gregorian-from-absolute
  8265. (or (get-text-property mark 'day)
  8266. (get-text-property point 'day))))))
  8267. (unwind-protect
  8268. (progn
  8269. (fset 'calendar-cursor-to-date
  8270. (lambda (&optional error dummy)
  8271. (calendar-gregorian-from-absolute
  8272. (get-text-property point 'day))))
  8273. (call-interactively cmd))
  8274. (fset 'calendar-cursor-to-date oldf))))))
  8275. (defun org-agenda-execute-calendar-command (cmd)
  8276. "Execute a calendar command from the agenda with date from cursor."
  8277. (org-agenda-check-type t 'agenda 'timeline)
  8278. (require 'diary-lib)
  8279. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8280. (error "Don't know which date to use for the calendar command"))
  8281. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8282. (point (point))
  8283. (date (calendar-gregorian-from-absolute
  8284. (get-text-property point 'day)))
  8285. ;; the following 2 vars are needed in the calendar
  8286. (displayed-month (car date))
  8287. (displayed-year (nth 2 date)))
  8288. (unwind-protect
  8289. (progn
  8290. (fset 'calendar-cursor-to-date
  8291. (lambda (&optional error dummy)
  8292. (calendar-gregorian-from-absolute
  8293. (get-text-property point 'day))))
  8294. (call-interactively cmd))
  8295. (fset 'calendar-cursor-to-date oldf))))
  8296. (defun org-agenda-phases-of-moon ()
  8297. "Display the phases of the moon for the 3 months around the cursor date."
  8298. (interactive)
  8299. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8300. (defun org-agenda-holidays ()
  8301. "Display the holidays for the 3 months around the cursor date."
  8302. (interactive)
  8303. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8304. (defvar calendar-longitude) ; defined in calendar.el
  8305. (defvar calendar-latitude) ; defined in calendar.el
  8306. (defvar calendar-location-name) ; defined in calendar.el
  8307. (defun org-agenda-sunrise-sunset (arg)
  8308. "Display sunrise and sunset for the cursor date.
  8309. Latitude and longitude can be specified with the variables
  8310. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8311. argument, latitude and longitude will be prompted for."
  8312. (interactive "P")
  8313. (require 'solar)
  8314. (let ((calendar-longitude (if arg nil calendar-longitude))
  8315. (calendar-latitude (if arg nil calendar-latitude))
  8316. (calendar-location-name
  8317. (if arg "the given coordinates" calendar-location-name)))
  8318. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8319. (defun org-agenda-goto-calendar ()
  8320. "Open the Emacs calendar with the date at the cursor."
  8321. (interactive)
  8322. (org-agenda-check-type t 'agenda 'timeline)
  8323. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8324. (error "Don't know which date to open in calendar")))
  8325. (date (calendar-gregorian-from-absolute day))
  8326. (calendar-move-hook nil)
  8327. (calendar-view-holidays-initially-flag nil)
  8328. (calendar-view-diary-initially-flag nil))
  8329. (calendar)
  8330. (calendar-goto-date date)))
  8331. ;;;###autoload
  8332. (defun org-calendar-goto-agenda ()
  8333. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8334. This is a command that has to be installed in `calendar-mode-map'."
  8335. (interactive)
  8336. (org-agenda-list nil (calendar-absolute-from-gregorian
  8337. (calendar-cursor-to-date))
  8338. nil))
  8339. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8340. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8341. This is a command that has to be installed in `calendar-mode-map'.
  8342. \(fn)" t nil)
  8343. (defun org-agenda-convert-date ()
  8344. (interactive)
  8345. (org-agenda-check-type t 'agenda 'timeline)
  8346. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8347. date s)
  8348. (unless day
  8349. (error "Don't know which date to convert"))
  8350. (setq date (calendar-gregorian-from-absolute day))
  8351. (setq s (concat
  8352. "Gregorian: " (calendar-date-string date) "\n"
  8353. "ISO: " (calendar-iso-date-string date) "\n"
  8354. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8355. "Julian: " (calendar-julian-date-string date) "\n"
  8356. "Astron. JD: " (calendar-astro-date-string date)
  8357. " (Julian date number at noon UTC)\n"
  8358. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8359. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8360. "French: " (calendar-french-date-string date) "\n"
  8361. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8362. "Mayan: " (calendar-mayan-date-string date) "\n"
  8363. "Coptic: " (calendar-coptic-date-string date) "\n"
  8364. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8365. "Persian: " (calendar-persian-date-string date) "\n"
  8366. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8367. (with-output-to-temp-buffer "*Dates*"
  8368. (princ s))
  8369. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8370. ;;; Bulk commands
  8371. (defun org-agenda-bulk-marked-p ()
  8372. (eq (get-char-property (point-at-bol) 'type)
  8373. 'org-marked-entry-overlay))
  8374. (defun org-agenda-bulk-mark (&optional arg)
  8375. "Mark the entry at point for future bulk action."
  8376. (interactive "p")
  8377. (dotimes (i (or arg 1))
  8378. (unless (org-get-at-bol 'org-agenda-diary-link)
  8379. (let* ((m (org-get-at-bol 'org-hd-marker))
  8380. ov)
  8381. (unless (org-agenda-bulk-marked-p)
  8382. (unless m (error "Nothing to mark at point"))
  8383. (push m org-agenda-bulk-marked-entries)
  8384. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8385. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8386. (org-get-todo-face "TODO")
  8387. 'evaporate)
  8388. (overlay-put ov 'type 'org-marked-entry-overlay))
  8389. (beginning-of-line 2)
  8390. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8391. (beginning-of-line 2))
  8392. (message "%d entries marked for bulk action"
  8393. (length org-agenda-bulk-marked-entries))))))
  8394. (defun org-agenda-bulk-mark-all ()
  8395. "Mark all entries for future agenda bulk action."
  8396. (interactive)
  8397. (org-agenda-bulk-mark-regexp "."))
  8398. (defun org-agenda-bulk-mark-regexp (regexp)
  8399. "Mark entries matching REGEXP for future agenda bulk action."
  8400. (interactive "sMark entries matching regexp: ")
  8401. (let ((entries-marked 0))
  8402. (save-excursion
  8403. (goto-char (point-min))
  8404. (goto-char (next-single-property-change (point) 'txt))
  8405. (while (re-search-forward regexp nil t)
  8406. (when (string-match regexp (get-text-property (point) 'txt))
  8407. (setq entries-marked (1+ entries-marked))
  8408. (call-interactively 'org-agenda-bulk-mark))))
  8409. (if (not entries-marked)
  8410. (message "No entry matching this regexp."))))
  8411. (defun org-agenda-bulk-unmark (&optional arg)
  8412. "Unmark the entry at point for future bulk action."
  8413. (interactive "P")
  8414. (if arg
  8415. (org-agenda-bulk-unmark-all)
  8416. (cond ((org-agenda-bulk-marked-p)
  8417. (org-agenda-bulk-remove-overlays
  8418. (point-at-bol) (+ 2 (point-at-bol)))
  8419. (setq org-agenda-bulk-marked-entries
  8420. (delete (org-get-at-bol 'org-hd-marker)
  8421. org-agenda-bulk-marked-entries))
  8422. (beginning-of-line 2)
  8423. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8424. (beginning-of-line 2))
  8425. (message "%d entries left marked for bulk action"
  8426. (length org-agenda-bulk-marked-entries)))
  8427. (t (message "No entry to unmark here")))))
  8428. (defun org-agenda-bulk-toggle ()
  8429. "Toggle marking the entry at point for bulk action."
  8430. (interactive)
  8431. (if (org-agenda-bulk-marked-p)
  8432. (org-agenda-bulk-unmark)
  8433. (org-agenda-bulk-mark)))
  8434. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8435. "Remove the mark overlays between BEG and END in the agenda buffer.
  8436. BEG and END default to the buffer limits.
  8437. This only removes the overlays, it does not remove the markers
  8438. from the list in `org-agenda-bulk-marked-entries'."
  8439. (interactive)
  8440. (mapc (lambda (ov)
  8441. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8442. (delete-overlay ov)))
  8443. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8444. (defun org-agenda-bulk-unmark-all ()
  8445. "Remove all marks in the agenda buffer.
  8446. This will remove the markers and the overlays."
  8447. (interactive)
  8448. (if (null org-agenda-bulk-marked-entries)
  8449. (message "No entry to unmark")
  8450. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8451. (setq org-agenda-bulk-marked-entries nil)
  8452. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8453. (defcustom org-agenda-persistent-marks nil
  8454. "Non-nil means marked items will stay marked after a bulk action.
  8455. You can toggle this interactively by typing `p' when prompted for a
  8456. bulk action."
  8457. :group 'org-agenda
  8458. :version "24.1"
  8459. :type 'boolean)
  8460. (defun org-agenda-bulk-action (&optional arg)
  8461. "Execute an remote-editing action on all marked entries.
  8462. The prefix arg is passed through to the command if possible."
  8463. (interactive "P")
  8464. ;; Make sure we have markers, and only valid ones
  8465. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8466. (mapc
  8467. (lambda (m)
  8468. (unless (and (markerp m)
  8469. (marker-buffer m)
  8470. (buffer-live-p (marker-buffer m))
  8471. (marker-position m))
  8472. (error "Marker %s for bulk command is invalid" m)))
  8473. org-agenda-bulk-marked-entries)
  8474. ;; Prompt for the bulk command
  8475. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8476. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8477. "[S]catter [f]unction "
  8478. (when org-agenda-bulk-custom-functions
  8479. (concat " Custom: ["
  8480. (mapconcat (lambda(f) (char-to-string (car f)))
  8481. org-agenda-bulk-custom-functions "")
  8482. "]"))))
  8483. (catch 'exit
  8484. (let* ((action (read-char-exclusive))
  8485. (org-log-refile (if org-log-refile 'time nil))
  8486. (entries (reverse org-agenda-bulk-marked-entries))
  8487. (org-overriding-default-time
  8488. (if (get-text-property (point) 'org-agenda-date-header)
  8489. (org-get-cursor-date)))
  8490. redo-at-end
  8491. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8492. (cond
  8493. ((equal action ?p)
  8494. (let ((org-agenda-persistent-marks
  8495. (not org-agenda-persistent-marks)))
  8496. (org-agenda-bulk-action)
  8497. (throw 'exit nil)))
  8498. ((equal action ?$)
  8499. (setq cmd '(org-agenda-archive)))
  8500. ((equal action ?A)
  8501. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8502. ((member action '(?r ?w))
  8503. (setq rfloc (org-refile-get-location
  8504. "Refile to"
  8505. (marker-buffer (car entries))
  8506. org-refile-allow-creating-parent-nodes))
  8507. (if (nth 3 rfloc)
  8508. (setcar (nthcdr 3 rfloc)
  8509. (move-marker (make-marker) (nth 3 rfloc)
  8510. (or (get-file-buffer (nth 1 rfloc))
  8511. (find-buffer-visiting (nth 1 rfloc))
  8512. (error "This should not happen")))))
  8513. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8514. redo-at-end t))
  8515. ((equal action ?t)
  8516. (setq state (org-icompleting-read
  8517. "Todo state: "
  8518. (with-current-buffer (marker-buffer (car entries))
  8519. (mapcar 'list org-todo-keywords-1))))
  8520. (setq cmd `(let ((org-inhibit-blocking t)
  8521. (org-inhibit-logging 'note))
  8522. (org-agenda-todo ,state))))
  8523. ((memq action '(?- ?+))
  8524. (setq tag (org-icompleting-read
  8525. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8526. (with-current-buffer (marker-buffer (car entries))
  8527. (delq nil
  8528. (mapcar (lambda (x)
  8529. (if (stringp (car x)) x)) org-tag-alist)))))
  8530. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8531. ((memq action '(?s ?d))
  8532. (let* ((time
  8533. (unless arg
  8534. (org-read-date
  8535. nil nil nil
  8536. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8537. org-overriding-default-time)))
  8538. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8539. (setq cmd `(eval '(,c1 arg ,time)))))
  8540. ((equal action ?S)
  8541. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8542. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8543. (let ((days (read-number
  8544. (format "Scatter tasks across how many %sdays: "
  8545. (if arg "week" "")) 7)))
  8546. (setq cmd
  8547. `(let ((distance (1+ (random ,days))))
  8548. (if arg
  8549. (let ((dist distance)
  8550. (day-of-week
  8551. (calendar-day-of-week
  8552. (calendar-gregorian-from-absolute (org-today)))))
  8553. (dotimes (i (1+ dist))
  8554. (while (member day-of-week org-agenda-weekend-days)
  8555. (incf distance)
  8556. (incf day-of-week)
  8557. (if (= day-of-week 7)
  8558. (setq day-of-week 0)))
  8559. (incf day-of-week)
  8560. (if (= day-of-week 7)
  8561. (setq day-of-week 0)))))
  8562. ;; silently fail when try to replan a sexp entry
  8563. (condition-case nil
  8564. (let* ((date (calendar-gregorian-from-absolute
  8565. (+ (org-today) distance)))
  8566. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8567. (nth 2 date))))
  8568. (org-agenda-schedule nil time))
  8569. (error nil)))))))
  8570. ((assoc action org-agenda-bulk-custom-functions)
  8571. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8572. redo-at-end t))
  8573. ((equal action ?f)
  8574. (setq cmd (list (intern
  8575. (org-icompleting-read "Function: "
  8576. obarray 'fboundp t nil nil)))))
  8577. (t (error "Invalid bulk action")))
  8578. ;; Sort the markers, to make sure that parents are handled before children
  8579. (setq entries (sort entries
  8580. (lambda (a b)
  8581. (cond
  8582. ((equal (marker-buffer a) (marker-buffer b))
  8583. (< (marker-position a) (marker-position b)))
  8584. (t
  8585. (string< (buffer-name (marker-buffer a))
  8586. (buffer-name (marker-buffer b))))))))
  8587. ;; Now loop over all markers and apply cmd
  8588. (while (setq e (pop entries))
  8589. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8590. (if (not pos)
  8591. (progn (message "Skipping removed entry at %s" e)
  8592. (setq cntskip (1+ cntskip)))
  8593. (goto-char pos)
  8594. (let (org-loop-over-headlines-in-active-region)
  8595. (eval cmd))
  8596. (setq cnt (1+ cnt))))
  8597. (when redo-at-end (org-agenda-redo))
  8598. (unless org-agenda-persistent-marks
  8599. (org-agenda-bulk-unmark-all))
  8600. (message "Acted on %d entries%s%s"
  8601. cnt
  8602. (if (= cntskip 0)
  8603. ""
  8604. (format ", skipped %d (disappeared before their turn)"
  8605. cntskip))
  8606. (if (not org-agenda-persistent-marks)
  8607. "" " (kept marked)"))))))
  8608. (defun org-agenda-capture ()
  8609. "Call `org-capture' with the date at point."
  8610. (interactive)
  8611. (if (not (eq major-mode 'org-agenda-mode))
  8612. (error "You cannot do this outside of agenda buffers")
  8613. (let ((org-overriding-default-time
  8614. (org-get-cursor-date)))
  8615. (call-interactively 'org-capture))))
  8616. ;;; Flagging notes
  8617. (defun org-agenda-show-the-flagging-note ()
  8618. "Display the flagging note in the other window.
  8619. When called a second time in direct sequence, offer to remove the FLAGGING
  8620. tag and (if present) the flagging note."
  8621. (interactive)
  8622. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8623. (win (selected-window))
  8624. note heading newhead)
  8625. (unless hdmarker
  8626. (error "No linked entry at point"))
  8627. (if (and (eq this-command last-command)
  8628. (y-or-n-p "Unflag and remove any flagging note? "))
  8629. (progn
  8630. (org-agenda-remove-flag hdmarker)
  8631. (let ((win (get-buffer-window "*Flagging Note*")))
  8632. (and win (delete-window win)))
  8633. (message "Entry unflagged"))
  8634. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8635. (unless note
  8636. (error "No flagging note"))
  8637. (org-kill-new note)
  8638. (org-switch-to-buffer-other-window "*Flagging Note*")
  8639. (erase-buffer)
  8640. (insert note)
  8641. (goto-char (point-min))
  8642. (while (re-search-forward "\\\\n" nil t)
  8643. (replace-match "\n" t t))
  8644. (goto-char (point-min))
  8645. (select-window win)
  8646. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8647. (defun org-agenda-remove-flag (marker)
  8648. "Remove the FLAGGED tag and any flagging note in the entry."
  8649. (let (newhead)
  8650. (org-with-point-at marker
  8651. (org-toggle-tag "FLAGGED" 'off)
  8652. (org-entry-delete nil "THEFLAGGINGNOTE")
  8653. (setq newhead (org-get-heading)))
  8654. (org-agenda-change-all-lines newhead marker)
  8655. (message "Entry unflagged")))
  8656. (defun org-agenda-get-any-marker (&optional pos)
  8657. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8658. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8659. ;;; Appointment reminders
  8660. (defvar appt-time-msg-list) ; defined in appt.el
  8661. ;;;###autoload
  8662. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8663. "Activate appointments found in `org-agenda-files'.
  8664. With a \\[universal-argument] prefix, refresh the list of
  8665. appointments.
  8666. If FILTER is t, interactively prompt the user for a regular
  8667. expression, and filter out entries that don't match it.
  8668. If FILTER is a string, use this string as a regular expression
  8669. for filtering entries out.
  8670. If FILTER is a function, filter out entries against which
  8671. calling the function returns nil. This function takes one
  8672. argument: an entry from `org-agenda-get-day-entries'.
  8673. FILTER can also be an alist with the car of each cell being
  8674. either 'headline or 'category. For example:
  8675. '((headline \"IMPORTANT\")
  8676. (category \"Work\"))
  8677. will only add headlines containing IMPORTANT or headlines
  8678. belonging to the \"Work\" category.
  8679. ARGS are symbols indicating what kind of entries to consider.
  8680. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8681. and :timestamp entries. See the docstring of `org-diary' for
  8682. details and examples.
  8683. If an entry as a APPT_WARNTIME property, its value will be used
  8684. to override `appt-message-warning-time'."
  8685. (interactive "P")
  8686. (if refresh (setq appt-time-msg-list nil))
  8687. (if (eq filter t)
  8688. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8689. (let* ((cnt 0) ; count added events
  8690. (scope (or args '(:deadline :scheduled :timestamp)))
  8691. (org-agenda-new-buffers nil)
  8692. (org-deadline-warning-days 0)
  8693. ;; Do not use `org-today' here because appt only takes
  8694. ;; time and without date as argument, so it may pass wrong
  8695. ;; information otherwise
  8696. (today (org-date-to-gregorian
  8697. (time-to-days (current-time))))
  8698. (org-agenda-restrict nil)
  8699. (files (org-agenda-files 'unrestricted)) entries file
  8700. (org-agenda-buffer nil))
  8701. ;; Get all entries which may contain an appt
  8702. (org-agenda-prepare-buffers files)
  8703. (while (setq file (pop files))
  8704. (setq entries
  8705. (delq nil
  8706. (append entries
  8707. (apply 'org-agenda-get-day-entries
  8708. file today scope)))))
  8709. ;; Map thru entries and find if we should filter them out
  8710. (mapc
  8711. (lambda(x)
  8712. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8713. (cat (get-text-property 1 'org-category x))
  8714. (tod (get-text-property 1 'time-of-day x))
  8715. (ok (or (null filter)
  8716. (and (stringp filter) (string-match filter evt))
  8717. (and (functionp filter) (funcall filter x))
  8718. (and (listp filter)
  8719. (let ((cat-filter (cadr (assoc 'category filter)))
  8720. (evt-filter (cadr (assoc 'headline filter))))
  8721. (or (and (stringp cat-filter)
  8722. (string-match cat-filter cat))
  8723. (and (stringp evt-filter)
  8724. (string-match evt-filter evt)))))))
  8725. (wrn (get-text-property 1 'warntime x)))
  8726. ;; FIXME: Shall we remove text-properties for the appt text?
  8727. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8728. (when (and ok tod)
  8729. (setq tod (concat "00" (number-to-string tod))
  8730. tod (when (string-match
  8731. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8732. (concat (match-string 1 tod) ":"
  8733. (match-string 2 tod))))
  8734. (if (version< emacs-version "23.3")
  8735. (appt-add tod evt)
  8736. (appt-add tod evt wrn))
  8737. (setq cnt (1+ cnt))))) entries)
  8738. (org-release-buffers org-agenda-new-buffers)
  8739. (if (eq cnt 0)
  8740. (message "No event to add")
  8741. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8742. (autoload 'org-agenda-to-appt "org-agenda" "\
  8743. Activate appointments found in `org-agenda-files'.
  8744. With a \\[universal-argument] prefix, refresh the list of
  8745. appointments.
  8746. If FILTER is t, interactively prompt the user for a regular
  8747. expression, and filter out entries that don't match it.
  8748. If FILTER is a string, use this string as a regular expression
  8749. for filtering entries out.
  8750. If FILTER is a function, filter out entries against which
  8751. calling the function returns nil. This function takes one
  8752. argument: an entry from `org-agenda-get-day-entries'.
  8753. FILTER can also be an alist with the car of each cell being
  8754. either 'headline or 'category. For example:
  8755. '((headline \"IMPORTANT\")
  8756. (category \"Work\"))
  8757. will only add headlines containing IMPORTANT or headlines
  8758. belonging to the \"Work\" category.
  8759. ARGS are symbols indicating what kind of entries to consider.
  8760. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8761. and :timestamp entries. See the docstring of `org-diary' for
  8762. details and examples.
  8763. If an entry as a APPT_WARNTIME property, its value will be used
  8764. to override `appt-message-warning-time'.
  8765. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8766. (defun org-agenda-todayp (date)
  8767. "Does DATE mean today, when considering `org-extend-today-until'?"
  8768. (let ((today (org-today))
  8769. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8770. date)))
  8771. (eq date today)))
  8772. (defun org-agenda-todo-yesterday (&optional arg)
  8773. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8774. (interactive "P")
  8775. (let* ((hour (third (decode-time
  8776. (org-current-time))))
  8777. (org-extend-today-until (1+ hour)))
  8778. (org-agenda-todo arg)))
  8779. (provide 'org-agenda)
  8780. ;;; org-agenda.el ends here