org-agenda.el 366 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495
  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. ;;;### (autoloads (org-agenda-to-appt org-calendar-goto-agenda org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  1648. ;;;;;; org-diary org-agenda-list-stuck-projects org-tags-view org-todo-list
  1649. ;;;;;; org-search-view org-agenda-list org-batch-store-agenda-views
  1650. ;;;;;; org-store-agenda-views org-batch-agenda-csv org-batch-agenda
  1651. ;;;;;; org-agenda org-toggle-sticky-agenda) "org-agenda" "org-agenda.el"
  1652. ;;;;;; (20586 34302 212927 775000))
  1653. ;;; Generated autoloads from org-agenda.el
  1654. ;;;###autoload
  1655. (defun org-toggle-sticky-agenda (&optional arg)
  1656. "Toggle `org-agenda-sticky'."
  1657. (interactive "P")
  1658. (let ((new-value (if arg
  1659. (> (prefix-numeric-value arg) 0)
  1660. (not org-agenda-sticky))))
  1661. (if (equal new-value org-agenda-sticky)
  1662. (and (org-called-interactively-p 'interactive)
  1663. (message "Sticky agenda was already %s"
  1664. (if org-agenda-sticky "enabled" "disabled")))
  1665. (setq org-agenda-sticky new-value)
  1666. (org-agenda-kill-all-agenda-buffers)
  1667. (and (org-called-interactively-p 'interactive)
  1668. (message "Sticky agenda was %s"
  1669. (if org-agenda-sticky "enabled" "disabled"))))))
  1670. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1671. Toggle `org-agenda-sticky'.
  1672. \(fn &optional ARG)" t nil)
  1673. (defvar org-agenda-buffer nil
  1674. "Agenda buffer currently being generated.")
  1675. (defvar org-agenda-last-prefix-arg nil)
  1676. (defvar org-agenda-this-buffer-name nil)
  1677. (defvar org-agenda-doing-sticky-redo nil)
  1678. (defvar org-agenda-this-buffer-is-sticky nil)
  1679. (defconst org-agenda-local-vars
  1680. '(org-agenda-this-buffer-name
  1681. org-agenda-undo-list
  1682. org-agenda-pending-undo-list
  1683. org-agenda-follow-mode
  1684. org-agenda-entry-text-mode
  1685. org-agenda-clockreport-mode
  1686. org-agenda-show-log
  1687. org-agenda-redo-command
  1688. org-agenda-query-string
  1689. org-agenda-type
  1690. org-agenda-bulk-marked-entries
  1691. org-agenda-undo-has-started-in
  1692. org-agenda-info
  1693. org-agenda-tag-filter-overlays
  1694. org-agenda-cat-filter-overlays
  1695. org-agenda-pre-window-conf
  1696. org-agenda-columns-active
  1697. org-agenda-tag-filter
  1698. org-agenda-category-filter
  1699. org-agenda-markers
  1700. org-agenda-last-search-view-search-was-boolean
  1701. org-agenda-filtered-by-category
  1702. org-agenda-filter-form
  1703. org-agenda-show-window
  1704. org-agenda-cycle-counter
  1705. org-agenda-last-prefix-arg)
  1706. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1707. (defun org-agenda-mode ()
  1708. "Mode for time-sorted view on action items in Org-mode files.
  1709. The following commands are available:
  1710. \\{org-agenda-mode-map}"
  1711. (interactive)
  1712. (cond (org-agenda-doing-sticky-redo
  1713. ;; Refreshing sticky agenda-buffer
  1714. ;;
  1715. ;; Preserve the value of `org-agenda-local-vars' variables,
  1716. ;; while letting `kill-all-local-variables' kill the rest
  1717. (let ((save (buffer-local-variables)))
  1718. (kill-all-local-variables)
  1719. (mapc 'make-local-variable org-agenda-local-vars)
  1720. (dolist (elem save)
  1721. (let ((var (car elem))
  1722. (val (cdr elem)))
  1723. (when (and val
  1724. (member var org-agenda-local-vars))
  1725. (set var val)))))
  1726. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1727. (org-agenda-sticky
  1728. ;; Creating a sticky Agenda buffer for the first time
  1729. (kill-all-local-variables)
  1730. (mapc 'make-local-variable org-agenda-local-vars)
  1731. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1732. (t
  1733. ;; Creating a non-sticky agenda buffer
  1734. (kill-all-local-variables)
  1735. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1736. (setq org-agenda-undo-list nil
  1737. org-agenda-pending-undo-list nil
  1738. org-agenda-bulk-marked-entries nil)
  1739. (setq major-mode 'org-agenda-mode)
  1740. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1741. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1742. (setq mode-name "Org-Agenda")
  1743. (use-local-map org-agenda-mode-map)
  1744. (easy-menu-add org-agenda-menu)
  1745. (if org-startup-truncated (setq truncate-lines t))
  1746. (org-set-local 'line-move-visual nil)
  1747. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1748. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1749. ;; Make sure properties are removed when copying text
  1750. (make-local-variable 'filter-buffer-substring-functions)
  1751. (add-hook 'filter-buffer-substring-functions
  1752. (lambda (fun start end delete)
  1753. (substring-no-properties (funcall fun start end delete))))
  1754. (unless org-agenda-keep-modes
  1755. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1756. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1757. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1758. org-agenda-show-log org-agenda-start-with-log-mode))
  1759. (easy-menu-change
  1760. '("Agenda") "Agenda Files"
  1761. (append
  1762. (list
  1763. (vector
  1764. (if (get 'org-agenda-files 'org-restrict)
  1765. "Restricted to single file"
  1766. "Edit File List")
  1767. '(org-edit-agenda-file-list)
  1768. (not (get 'org-agenda-files 'org-restrict)))
  1769. "--")
  1770. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1771. (org-agenda-set-mode-name)
  1772. (apply
  1773. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1774. (list 'org-agenda-mode-hook)))
  1775. (substitute-key-definition 'undo 'org-agenda-undo
  1776. org-agenda-mode-map global-map)
  1777. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1778. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1779. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1780. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1782. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1783. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1784. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1785. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1786. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1787. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1788. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1789. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1791. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1792. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1794. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1795. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1796. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1797. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1798. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1799. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1800. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1801. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1802. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1804. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1805. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1806. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1807. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1808. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1809. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1811. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1812. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1813. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1814. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1815. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1816. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1817. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1818. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1819. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1820. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1821. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1822. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1823. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1825. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1826. (while l (org-defkey org-agenda-mode-map
  1827. (int-to-string (pop l)) 'digit-argument)))
  1828. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1829. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1830. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1831. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1832. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1833. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1834. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1835. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1836. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1837. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1838. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1839. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1840. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1841. 'org-clock-modify-effort-estimate)
  1842. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1843. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1844. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1845. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1846. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1847. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1848. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1849. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1850. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1851. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1852. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1853. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1854. (substitute-key-definition 'next-line 'org-agenda-next-line
  1855. org-agenda-mode-map global-map)
  1856. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1857. org-agenda-mode-map global-map)
  1858. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1859. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1861. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1862. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1863. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1864. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1865. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1866. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1867. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1868. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1869. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1870. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1871. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1872. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1873. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1874. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1875. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1877. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1878. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1879. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1880. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1881. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1882. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1883. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1884. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1885. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1886. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1887. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1888. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1889. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1890. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1891. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1892. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1893. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1894. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1895. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1896. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1897. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1898. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1899. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1900. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1901. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1902. (when org-agenda-mouse-1-follows-link
  1903. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1904. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1905. '("Agenda"
  1906. ("Agenda Files")
  1907. "--"
  1908. ("Agenda Dates"
  1909. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1910. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1911. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1912. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1913. "--"
  1914. ("View"
  1915. ["Day View" org-agenda-day-view
  1916. :active (org-agenda-check-type nil 'agenda)
  1917. :style radio :selected (eq org-agenda-current-span 'day)
  1918. :keys "v d (or just d)"]
  1919. ["Week View" org-agenda-week-view
  1920. :active (org-agenda-check-type nil 'agenda)
  1921. :style radio :selected (eq org-agenda-current-span 'week)
  1922. :keys "v w (or just w)"]
  1923. ["Month View" org-agenda-month-view
  1924. :active (org-agenda-check-type nil 'agenda)
  1925. :style radio :selected (eq org-agenda-current-span 'month)
  1926. :keys "v m"]
  1927. ["Year View" org-agenda-year-view
  1928. :active (org-agenda-check-type nil 'agenda)
  1929. :style radio :selected (eq org-agenda-current-span 'year)
  1930. :keys "v y"]
  1931. "--"
  1932. ["Include Diary" org-agenda-toggle-diary
  1933. :style toggle :selected org-agenda-include-diary
  1934. :active (org-agenda-check-type nil 'agenda)]
  1935. ["Include Deadlines" org-agenda-toggle-deadlines
  1936. :style toggle :selected org-agenda-include-deadlines
  1937. :active (org-agenda-check-type nil 'agenda)]
  1938. ["Use Time Grid" org-agenda-toggle-time-grid
  1939. :style toggle :selected org-agenda-use-time-grid
  1940. :active (org-agenda-check-type nil 'agenda)]
  1941. "--"
  1942. ["Show clock report" org-agenda-clockreport-mode
  1943. :style toggle :selected org-agenda-clockreport-mode
  1944. :active (org-agenda-check-type nil 'agenda)]
  1945. ["Show some entry text" org-agenda-entry-text-mode
  1946. :style toggle :selected org-agenda-entry-text-mode
  1947. :active t]
  1948. "--"
  1949. ["Show Logbook entries" org-agenda-log-mode
  1950. :style toggle :selected org-agenda-show-log
  1951. :active (org-agenda-check-type nil 'agenda 'timeline)
  1952. :keys "v l (or just l)"]
  1953. ["Include archived trees" org-agenda-archives-mode
  1954. :style toggle :selected org-agenda-archives-mode :active t
  1955. :keys "v a"]
  1956. ["Include archive files" (org-agenda-archives-mode t)
  1957. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1958. :keys "v A"]
  1959. "--"
  1960. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1961. ["Write view to file" org-agenda-write t]
  1962. ["Rebuild buffer" org-agenda-redo t]
  1963. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1964. "--"
  1965. ["Show original entry" org-agenda-show t]
  1966. ["Go To (other window)" org-agenda-goto t]
  1967. ["Go To (this window)" org-agenda-switch-to t]
  1968. ["Capture with cursor date" org-agenda-capture t]
  1969. ["Follow Mode" org-agenda-follow-mode
  1970. :style toggle :selected org-agenda-follow-mode :active t]
  1971. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1972. "--"
  1973. ("TODO"
  1974. ["Cycle TODO" org-agenda-todo t]
  1975. ["Next TODO set" org-agenda-todo-nextset t]
  1976. ["Previous TODO set" org-agenda-todo-previousset t]
  1977. ["Add note" org-agenda-add-note t])
  1978. ("Archive/Refile/Delete"
  1979. ["Archive default" org-agenda-archive-default t]
  1980. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1981. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1982. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1983. ["Archive subtree" org-agenda-archive t]
  1984. "--"
  1985. ["Refile" org-agenda-refile t]
  1986. "--"
  1987. ["Delete subtree" org-agenda-kill t])
  1988. ("Bulk action"
  1989. ["Mark entry" org-agenda-bulk-mark t]
  1990. ["Mark all" org-agenda-bulk-mark-all t]
  1991. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1992. ["Unmark entry" org-agenda-bulk-unmark t]
  1993. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1994. ["Act on all marked" org-agenda-bulk-action t]
  1995. "--"
  1996. ("Tags and Properties"
  1997. ["Show all Tags" org-agenda-show-tags t]
  1998. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1999. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2000. "--"
  2001. ["Column View" org-columns t])
  2002. ("Deadline/Schedule"
  2003. ["Schedule" org-agenda-schedule t]
  2004. ["Set Deadline" org-agenda-deadline t]
  2005. "--"
  2006. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2007. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2008. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2009. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2010. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2011. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2012. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2013. ("Clock and Effort"
  2014. ["Clock in" org-agenda-clock-in t]
  2015. ["Clock out" org-agenda-clock-out t]
  2016. ["Clock cancel" org-agenda-clock-cancel t]
  2017. ["Goto running clock" org-clock-goto t]
  2018. "--"
  2019. ["Set Effort" org-agenda-set-effort t]
  2020. ["Change clocked effort" org-clock-modify-effort-estimate
  2021. (org-clock-is-active)])
  2022. ("Priority"
  2023. ["Set Priority" org-agenda-priority t]
  2024. ["Increase Priority" org-agenda-priority-up t]
  2025. ["Decrease Priority" org-agenda-priority-down t]
  2026. ["Show Priority" org-show-priority t])
  2027. ("Calendar/Diary"
  2028. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2029. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2030. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2031. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2032. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2033. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2034. "--"
  2035. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2036. "--"
  2037. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2038. "--"
  2039. ("MobileOrg"
  2040. ["Push Files and Views" org-mobile-push t]
  2041. ["Get Captured and Flagged" org-mobile-pull t]
  2042. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2043. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2044. "--"
  2045. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2046. "--"
  2047. ["Quit" org-agenda-quit t]
  2048. ["Exit and Release Buffers" org-agenda-exit t]
  2049. ))
  2050. ;;; Agenda undo
  2051. (defvar org-agenda-allow-remote-undo t
  2052. "Non-nil means allow remote undo from the agenda buffer.")
  2053. (defvar org-agenda-undo-has-started-in nil
  2054. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2055. (defun org-agenda-undo ()
  2056. "Undo a remote editing step in the agenda.
  2057. This undoes changes both in the agenda buffer and in the remote buffer
  2058. that have been changed along."
  2059. (interactive)
  2060. (or org-agenda-allow-remote-undo
  2061. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2062. (if (not (eq this-command last-command))
  2063. (setq org-agenda-undo-has-started-in nil
  2064. org-agenda-pending-undo-list org-agenda-undo-list))
  2065. (if (not org-agenda-pending-undo-list)
  2066. (error "No further undo information"))
  2067. (let* ((entry (pop org-agenda-pending-undo-list))
  2068. buf line cmd rembuf)
  2069. (setq cmd (pop entry) line (pop entry))
  2070. (setq rembuf (nth 2 entry))
  2071. (org-with-remote-undo rembuf
  2072. (while (bufferp (setq buf (pop entry)))
  2073. (if (pop entry)
  2074. (with-current-buffer buf
  2075. (let ((last-undo-buffer buf)
  2076. (inhibit-read-only t))
  2077. (unless (memq buf org-agenda-undo-has-started-in)
  2078. (push buf org-agenda-undo-has-started-in)
  2079. (make-local-variable 'pending-undo-list)
  2080. (undo-start))
  2081. (while (and pending-undo-list
  2082. (listp pending-undo-list)
  2083. (not (car pending-undo-list)))
  2084. (pop pending-undo-list))
  2085. (undo-more 1))))))
  2086. (org-goto-line line)
  2087. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2088. (defun org-verify-change-for-undo (l1 l2)
  2089. "Verify that a real change occurred between the undo lists L1 and L2."
  2090. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2091. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2092. (not (eq l1 l2)))
  2093. ;;; Agenda dispatch
  2094. (defvar org-agenda-restrict-begin (make-marker))
  2095. (defvar org-agenda-restrict-end (make-marker))
  2096. (defvar org-agenda-last-dispatch-buffer nil)
  2097. (defvar org-agenda-overriding-restriction nil)
  2098. (defcustom org-agenda-custom-commands-contexts nil
  2099. "Alist of custom agenda keys and contextual rules.
  2100. For example, if you have a custom agenda command \"p\" and you
  2101. want this command to be accessible only from plain text files,
  2102. use this:
  2103. '((\"p\" (in-file . \"\\.txt\")))
  2104. Here are the available contexts definitions:
  2105. in-file: command displayed only in matching files
  2106. in-mode: command displayed only in matching modes
  2107. not-in-file: command not displayed in matching files
  2108. not-in-mode: command not displayed in matching modes
  2109. [function]: a custom function taking no argument
  2110. If you define several checks, the agenda command will be
  2111. accessible if there is at least one valid check.
  2112. You can also bind a key to another agenda custom command
  2113. depending on contextual rules.
  2114. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2115. Here it means: in .txt files, use \"p\" as the key for the
  2116. agenda command otherwise associated with \"q\". (The command
  2117. originally associated with \"q\" is not displayed to avoid
  2118. duplicates.)"
  2119. :version "24.3"
  2120. :group 'org-agenda-custom-commands
  2121. :type '(repeat (list :tag "Rule"
  2122. (string :tag " Agenda key")
  2123. (string :tag "Replace by command")
  2124. (repeat :tag "Available when"
  2125. (choice
  2126. (cons :tag "Condition"
  2127. (choice
  2128. (const :tag "In file" in-file)
  2129. (const :tag "Not in file" not-in-file)
  2130. (const :tag "In mode" in-mode)
  2131. (const :tag "Not in mode" not-in-mode))
  2132. (regexp))
  2133. (function :tag "Custom function"))))))
  2134. (defvar org-keys nil)
  2135. (defvar org-match nil)
  2136. ;;;###autoload
  2137. (defun org-agenda (&optional arg org-keys restriction)
  2138. "Dispatch agenda commands to collect entries to the agenda buffer.
  2139. Prompts for a command to execute. Any prefix arg will be passed
  2140. on to the selected command. The default selections are:
  2141. a Call `org-agenda-list' to display the agenda for current day or week.
  2142. t Call `org-todo-list' to display the global todo list.
  2143. T Call `org-todo-list' to display the global todo list, select only
  2144. entries with a specific TODO keyword (the user gets a prompt).
  2145. m Call `org-tags-view' to display headlines with tags matching
  2146. a condition (the user is prompted for the condition).
  2147. M Like `m', but select only TODO entries, no ordinary headlines.
  2148. L Create a timeline for the current buffer.
  2149. e Export views to associated files.
  2150. s Search entries for keywords.
  2151. S Search entries for keywords, only with TODO keywords.
  2152. / Multi occur across all agenda files and also files listed
  2153. in `org-agenda-text-search-extra-files'.
  2154. < Restrict agenda commands to buffer, subtree, or region.
  2155. Press several times to get the desired effect.
  2156. > Remove a previous restriction.
  2157. # List \"stuck\" projects.
  2158. ! Configure what \"stuck\" means.
  2159. C Configure custom agenda commands.
  2160. More commands can be added by configuring the variable
  2161. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2162. searches can be pre-defined in this way.
  2163. If the current buffer is in Org-mode and visiting a file, you can also
  2164. first press `<' once to indicate that the agenda should be temporarily
  2165. \(until the next use of \\[org-agenda]) restricted to the current file.
  2166. Pressing `<' twice means to restrict to the current subtree or region
  2167. \(if active)."
  2168. (interactive "P")
  2169. (catch 'exit
  2170. (let* ((prefix-descriptions nil)
  2171. (org-agenda-buffer-name org-agenda-buffer-name)
  2172. (org-agenda-window-setup (if (equal (buffer-name)
  2173. org-agenda-buffer-name)
  2174. 'current-window
  2175. org-agenda-window-setup))
  2176. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2177. (org-agenda-custom-commands
  2178. ;; normalize different versions
  2179. (delq nil
  2180. (mapcar
  2181. (lambda (x)
  2182. (cond ((stringp (cdr x))
  2183. (push x prefix-descriptions)
  2184. nil)
  2185. ((stringp (nth 1 x)) x)
  2186. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2187. (t (cons (car x) (cons "" (cdr x))))))
  2188. org-agenda-custom-commands)))
  2189. (org-agenda-custom-commands
  2190. (org-contextualize-keys
  2191. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2192. (buf (current-buffer))
  2193. (bfn (buffer-file-name (buffer-base-buffer)))
  2194. entry key type org-match lprops ans)
  2195. ;; Turn off restriction unless there is an overriding one,
  2196. (unless org-agenda-overriding-restriction
  2197. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2198. ;; There is a request to keep the file list in place
  2199. (put 'org-agenda-files 'org-restrict nil))
  2200. (setq org-agenda-restrict nil)
  2201. (move-marker org-agenda-restrict-begin nil)
  2202. (move-marker org-agenda-restrict-end nil))
  2203. ;; Delete old local properties
  2204. (put 'org-agenda-redo-command 'org-lprops nil)
  2205. ;; Delete previously set last-arguments
  2206. (put 'org-agenda-redo-command 'last-args nil)
  2207. ;; Remember where this call originated
  2208. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2209. (unless org-keys
  2210. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2211. org-keys (car ans)
  2212. restriction (cdr ans)))
  2213. ;; If we have sticky agenda buffers, set a name for the buffer,
  2214. ;; depending on the invoking keys. The user may still set this
  2215. ;; as a command option, which will overwrite what we do here.
  2216. (if org-agenda-sticky
  2217. (setq org-agenda-buffer-name
  2218. (format "*Org Agenda(%s)*" org-keys)))
  2219. ;; Establish the restriction, if any
  2220. (when (and (not org-agenda-overriding-restriction) restriction)
  2221. (put 'org-agenda-files 'org-restrict (list bfn))
  2222. (cond
  2223. ((eq restriction 'region)
  2224. (setq org-agenda-restrict t)
  2225. (move-marker org-agenda-restrict-begin (region-beginning))
  2226. (move-marker org-agenda-restrict-end (region-end)))
  2227. ((eq restriction 'subtree)
  2228. (save-excursion
  2229. (setq org-agenda-restrict t)
  2230. (org-back-to-heading t)
  2231. (move-marker org-agenda-restrict-begin (point))
  2232. (move-marker org-agenda-restrict-end
  2233. (progn (org-end-of-subtree t)))))))
  2234. ;; For example the todo list should not need it (but does...)
  2235. (cond
  2236. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2237. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2238. (progn
  2239. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2240. lprops (nth 4 entry))
  2241. (if org-agenda-sticky
  2242. (setq org-agenda-buffer-name
  2243. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2244. (format "*Org Agenda(%s)*" org-keys))))
  2245. (put 'org-agenda-redo-command 'org-lprops lprops)
  2246. (cond
  2247. ((eq type 'agenda)
  2248. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2249. ((eq type 'alltodo)
  2250. (org-let lprops '(org-todo-list current-prefix-arg)))
  2251. ((eq type 'search)
  2252. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2253. ((eq type 'stuck)
  2254. (org-let lprops '(org-agenda-list-stuck-projects
  2255. current-prefix-arg)))
  2256. ((eq type 'tags)
  2257. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2258. ((eq type 'tags-todo)
  2259. (org-let lprops '(org-tags-view '(4) org-match)))
  2260. ((eq type 'todo)
  2261. (org-let lprops '(org-todo-list org-match)))
  2262. ((eq type 'tags-tree)
  2263. (org-check-for-org-mode)
  2264. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2265. ((eq type 'todo-tree)
  2266. (org-check-for-org-mode)
  2267. (org-let lprops
  2268. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2269. (regexp-quote org-match) "\\>"))))
  2270. ((eq type 'occur-tree)
  2271. (org-check-for-org-mode)
  2272. (org-let lprops '(org-occur org-match)))
  2273. ((functionp type)
  2274. (org-let lprops '(funcall type org-match)))
  2275. ((fboundp type)
  2276. (org-let lprops '(funcall type org-match)))
  2277. (t (error "Invalid custom agenda command type %s" type))))
  2278. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2279. ((equal org-keys "C")
  2280. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2281. (customize-variable 'org-agenda-custom-commands))
  2282. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2283. ((equal org-keys "s") (call-interactively 'org-search-view))
  2284. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2285. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2286. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2287. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2288. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2289. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2290. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2291. (org-add-hook
  2292. 'post-command-hook
  2293. (lambda ()
  2294. (unless (current-message)
  2295. (let* ((m (org-agenda-get-any-marker))
  2296. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2297. (when note
  2298. (message (concat
  2299. "FLAGGING-NOTE ([?] for more info): "
  2300. (org-add-props
  2301. (replace-regexp-in-string
  2302. "\\\\n" "//"
  2303. (copy-sequence note))
  2304. nil 'face 'org-warning)))))))
  2305. t t))
  2306. ((equal org-keys "L")
  2307. (unless (derived-mode-p 'org-mode)
  2308. (error "This is not an Org-mode file"))
  2309. (unless restriction
  2310. (put 'org-agenda-files 'org-restrict (list bfn))
  2311. (org-call-with-arg 'org-timeline arg)))
  2312. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2313. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2314. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2315. (t (error "Invalid agenda key"))))))
  2316. (autoload 'org-agenda "org-agenda" "\
  2317. Dispatch agenda commands to collect entries to the agenda buffer.
  2318. Prompts for a command to execute. Any prefix arg will be passed
  2319. on to the selected command. The default selections are:
  2320. a Call `org-agenda-list' to display the agenda for current day or week.
  2321. t Call `org-todo-list' to display the global todo list.
  2322. T Call `org-todo-list' to display the global todo list, select only
  2323. entries with a specific TODO keyword (the user gets a prompt).
  2324. m Call `org-tags-view' to display headlines with tags matching
  2325. a condition (the user is prompted for the condition).
  2326. M Like `m', but select only TODO entries, no ordinary headlines.
  2327. L Create a timeline for the current buffer.
  2328. e Export views to associated files.
  2329. s Search entries for keywords.
  2330. S Search entries for keywords, only with TODO keywords.
  2331. / Multi occur across all agenda files and also files listed
  2332. in `org-agenda-text-search-extra-files'.
  2333. < Restrict agenda commands to buffer, subtree, or region.
  2334. Press several times to get the desired effect.
  2335. > Remove a previous restriction.
  2336. # List \"stuck\" projects.
  2337. ! Configure what \"stuck\" means.
  2338. C Configure custom agenda commands.
  2339. More commands can be added by configuring the variable
  2340. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2341. searches can be pre-defined in this way.
  2342. If the current buffer is in Org-mode and visiting a file, you can also
  2343. first press `<' once to indicate that the agenda should be temporarily
  2344. \(until the next use of \\[org-agenda]) restricted to the current file.
  2345. Pressing `<' twice means to restrict to the current subtree or region
  2346. \(if active).
  2347. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2348. (defun org-agenda-append-agenda ()
  2349. "Append another agenda view to the current one.
  2350. This function allows interactive building of block agendas.
  2351. Agenda views are separated by `org-agenda-block-separator'."
  2352. (interactive)
  2353. (unless (derived-mode-p 'org-agenda-mode)
  2354. (error "Can only append from within agenda buffer"))
  2355. (let ((org-agenda-multi t))
  2356. (org-agenda)
  2357. (widen)
  2358. (org-agenda-finalize)
  2359. (org-agenda-fit-window-to-buffer)))
  2360. (defun org-agenda-normalize-custom-commands (cmds)
  2361. (delq nil
  2362. (mapcar
  2363. (lambda (x)
  2364. (cond ((stringp (cdr x)) nil)
  2365. ((stringp (nth 1 x)) x)
  2366. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2367. (t (cons (car x) (cons "" (cdr x))))))
  2368. cmds)))
  2369. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2370. "The user interface for selecting an agenda command."
  2371. (catch 'exit
  2372. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2373. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2374. (region-p (org-region-active-p))
  2375. (custom org-agenda-custom-commands)
  2376. (selstring "")
  2377. restriction second-time
  2378. c entry key type match prefixes rmheader header-end custom1 desc
  2379. line lines left right n n1)
  2380. (save-window-excursion
  2381. (delete-other-windows)
  2382. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2383. (erase-buffer)
  2384. (insert (eval-when-compile
  2385. (let ((header
  2386. "Press key for an agenda command: < Buffer, subtree/region restriction
  2387. -------------------------------- > Remove restriction
  2388. a Agenda for current week or day e Export agenda views
  2389. t List of all TODO entries T Entries with special TODO kwd
  2390. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2391. s Search for keywords S Like s, but only TODO entries
  2392. L Timeline for current buffer # List stuck projects (!=configure)
  2393. / Multi-occur C Configure custom agenda commands
  2394. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2395. ")
  2396. (start 0))
  2397. (while (string-match
  2398. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2399. header start)
  2400. (setq start (match-end 0))
  2401. (add-text-properties (match-beginning 2) (match-end 2)
  2402. '(face bold) header))
  2403. header)))
  2404. (setq header-end (move-marker (make-marker) (point)))
  2405. (while t
  2406. (setq custom1 custom)
  2407. (when (eq rmheader t)
  2408. (org-goto-line 1)
  2409. (re-search-forward ":" nil t)
  2410. (delete-region (match-end 0) (point-at-eol))
  2411. (forward-char 1)
  2412. (looking-at "-+")
  2413. (delete-region (match-end 0) (point-at-eol))
  2414. (move-marker header-end (match-end 0)))
  2415. (goto-char header-end)
  2416. (delete-region (point) (point-max))
  2417. ;; Produce all the lines that describe custom commands and prefixes
  2418. (setq lines nil)
  2419. (while (setq entry (pop custom1))
  2420. (setq key (car entry) desc (nth 1 entry)
  2421. type (nth 2 entry)
  2422. match (nth 3 entry))
  2423. (if (> (length key) 1)
  2424. (add-to-list 'prefixes (string-to-char key))
  2425. (setq line
  2426. (format
  2427. "%-4s%-14s"
  2428. (org-add-props (copy-sequence key)
  2429. '(face bold))
  2430. (cond
  2431. ((string-match "\\S-" desc) desc)
  2432. ((eq type 'agenda) "Agenda for current week or day")
  2433. ((eq type 'alltodo) "List of all TODO entries")
  2434. ((eq type 'search) "Word search")
  2435. ((eq type 'stuck) "List of stuck projects")
  2436. ((eq type 'todo) "TODO keyword")
  2437. ((eq type 'tags) "Tags query")
  2438. ((eq type 'tags-todo) "Tags (TODO)")
  2439. ((eq type 'tags-tree) "Tags tree")
  2440. ((eq type 'todo-tree) "TODO kwd tree")
  2441. ((eq type 'occur-tree) "Occur tree")
  2442. ((functionp type) (if (symbolp type)
  2443. (symbol-name type)
  2444. "Lambda expression"))
  2445. (t "???"))))
  2446. (if org-agenda-menu-show-matcher
  2447. (setq line
  2448. (concat line ": "
  2449. (cond
  2450. ((stringp match)
  2451. (setq match (copy-sequence match))
  2452. (org-add-props match nil 'face 'org-warning))
  2453. ((listp type)
  2454. (format "set of %d commands" (length type))))))
  2455. (if (org-string-nw-p match)
  2456. (add-text-properties
  2457. 0 (length line) (list 'help-echo
  2458. (concat "Matcher: " match)) line)))
  2459. (push line lines)))
  2460. (setq lines (nreverse lines))
  2461. (when prefixes
  2462. (mapc (lambda (x)
  2463. (push
  2464. (format "%s %s"
  2465. (org-add-props (char-to-string x)
  2466. nil 'face 'bold)
  2467. (or (cdr (assoc (concat selstring
  2468. (char-to-string x))
  2469. prefix-descriptions))
  2470. "Prefix key"))
  2471. lines))
  2472. prefixes))
  2473. ;; Check if we should display in two columns
  2474. (if org-agenda-menu-two-columns
  2475. (progn
  2476. (setq n (length lines)
  2477. n1 (+ (/ n 2) (mod n 2))
  2478. right (nthcdr n1 lines)
  2479. left (copy-sequence lines))
  2480. (setcdr (nthcdr (1- n1) left) nil))
  2481. (setq left lines right nil))
  2482. (while left
  2483. (insert "\n" (pop left))
  2484. (when right
  2485. (if (< (current-column) 40)
  2486. (move-to-column 40 t)
  2487. (insert " "))
  2488. (insert (pop right))))
  2489. ;; Make the window the right size
  2490. (goto-char (point-min))
  2491. (if second-time
  2492. (if (not (pos-visible-in-window-p (point-max)))
  2493. (org-fit-window-to-buffer))
  2494. (setq second-time t)
  2495. (org-fit-window-to-buffer))
  2496. ;; Ask for selection
  2497. (message "Press key for agenda command%s:"
  2498. (if (or restrict-ok org-agenda-overriding-restriction)
  2499. (if org-agenda-overriding-restriction
  2500. " (restriction lock active)"
  2501. (if restriction
  2502. (format " (restricted to %s)" restriction)
  2503. " (unrestricted)"))
  2504. ""))
  2505. (setq c (read-char-exclusive))
  2506. (message "")
  2507. (cond
  2508. ((assoc (char-to-string c) custom)
  2509. (setq selstring (concat selstring (char-to-string c)))
  2510. (throw 'exit (cons selstring restriction)))
  2511. ((memq c prefixes)
  2512. (setq selstring (concat selstring (char-to-string c))
  2513. prefixes nil
  2514. rmheader (or rmheader t)
  2515. custom (delq nil (mapcar
  2516. (lambda (x)
  2517. (if (or (= (length (car x)) 1)
  2518. (/= (string-to-char (car x)) c))
  2519. nil
  2520. (cons (substring (car x) 1) (cdr x))))
  2521. custom))))
  2522. ((eq c ?*)
  2523. (call-interactively 'org-toggle-sticky-agenda)
  2524. (sit-for 2))
  2525. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2526. (message "Restriction is only possible in Org-mode buffers")
  2527. (ding) (sit-for 1))
  2528. ((eq c ?1)
  2529. (org-agenda-remove-restriction-lock 'noupdate)
  2530. (setq restriction 'buffer))
  2531. ((eq c ?0)
  2532. (org-agenda-remove-restriction-lock 'noupdate)
  2533. (setq restriction (if region-p 'region 'subtree)))
  2534. ((eq c ?<)
  2535. (org-agenda-remove-restriction-lock 'noupdate)
  2536. (setq restriction
  2537. (cond
  2538. ((eq restriction 'buffer)
  2539. (if region-p 'region 'subtree))
  2540. ((memq restriction '(subtree region))
  2541. nil)
  2542. (t 'buffer))))
  2543. ((eq c ?>)
  2544. (org-agenda-remove-restriction-lock 'noupdate)
  2545. (setq restriction nil))
  2546. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2547. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2548. ((and (> (length selstring) 0) (eq c ?\d))
  2549. (delete-window)
  2550. (org-agenda-get-restriction-and-command prefix-descriptions))
  2551. ((equal c ?q) (error "Abort"))
  2552. (t (error "Invalid key %c" c))))))))
  2553. (defun org-agenda-fit-window-to-buffer ()
  2554. "Fit the window to the buffer size."
  2555. (and (memq org-agenda-window-setup '(reorganize-frame))
  2556. (fboundp 'fit-window-to-buffer)
  2557. (org-fit-window-to-buffer
  2558. nil
  2559. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2560. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2561. (defvar org-cmd nil)
  2562. (defvar org-agenda-overriding-cmd nil)
  2563. (defvar org-agenda-overriding-arguments nil)
  2564. (defvar org-agenda-overriding-cmd-arguments nil)
  2565. (defun org-agenda-run-series (name series)
  2566. (org-let (nth 1 series) '(org-agenda-prepare name))
  2567. ;; We need to reset agenda markers here, because when constructing a
  2568. ;; block agenda, the individual blocks do not do that.
  2569. (org-agenda-reset-markers)
  2570. (let* ((org-agenda-multi t)
  2571. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2572. (cmds (car series))
  2573. (gprops (nth 1 series))
  2574. match ;; The byte compiler incorrectly complains about this. Keep it!
  2575. org-cmd type lprops)
  2576. (while (setq org-cmd (pop cmds))
  2577. (setq type (car org-cmd)
  2578. match (eval (nth 1 org-cmd))
  2579. lprops (nth 2 org-cmd))
  2580. (let ((org-agenda-overriding-arguments
  2581. (if (eq org-agenda-overriding-cmd org-cmd)
  2582. (or org-agenda-overriding-arguments
  2583. org-agenda-overriding-cmd-arguments))))
  2584. (cond
  2585. ((eq type 'agenda)
  2586. (org-let2 gprops lprops
  2587. '(call-interactively 'org-agenda-list)))
  2588. ((eq type 'alltodo)
  2589. (org-let2 gprops lprops
  2590. '(call-interactively 'org-todo-list)))
  2591. ((eq type 'search)
  2592. (org-let2 gprops lprops
  2593. '(org-search-view current-prefix-arg match nil)))
  2594. ((eq type 'stuck)
  2595. (org-let2 gprops lprops
  2596. '(call-interactively 'org-agenda-list-stuck-projects)))
  2597. ((eq type 'tags)
  2598. (org-let2 gprops lprops
  2599. '(org-tags-view current-prefix-arg match)))
  2600. ((eq type 'tags-todo)
  2601. (org-let2 gprops lprops
  2602. '(org-tags-view '(4) match)))
  2603. ((eq type 'todo)
  2604. (org-let2 gprops lprops
  2605. '(org-todo-list match)))
  2606. ((fboundp type)
  2607. (org-let2 gprops lprops
  2608. '(funcall type match)))
  2609. (t (error "Invalid type in command series")))))
  2610. (widen)
  2611. (let ((inhibit-read-only t))
  2612. (add-text-properties (point-min) (point-max)
  2613. `(org-serie t org-serie-redo-cmd ,redo)))
  2614. (setq org-agenda-redo-command redo)
  2615. (goto-char (point-min)))
  2616. (org-agenda-fit-window-to-buffer)
  2617. (org-let (nth 1 series) '(org-agenda-finalize)))
  2618. ;;;###autoload
  2619. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2620. "Run an agenda command in batch mode and send the result to STDOUT.
  2621. If CMD-KEY is a string of length 1, it is used as a key in
  2622. `org-agenda-custom-commands' and triggers this command. If it is a
  2623. longer string it is used as a tags/todo match string.
  2624. Parameters are alternating variable names and values that will be bound
  2625. before running the agenda command."
  2626. (org-eval-in-environment (org-make-parameter-alist parameters)
  2627. (if (> (length cmd-key) 2)
  2628. (org-tags-view nil cmd-key)
  2629. (org-agenda nil cmd-key)))
  2630. (set-buffer org-agenda-buffer-name)
  2631. (princ (buffer-string)))
  2632. (autoload 'org-batch-agenda "org-agenda" "\
  2633. Run an agenda command in batch mode and send the result to STDOUT.
  2634. If CMD-KEY is a string of length 1, it is used as a key in
  2635. `org-agenda-custom-commands' and triggers this command. If it is a
  2636. longer string it is used as a tags/todo match string.
  2637. Parameters are alternating variable names and values that will be bound
  2638. before running the agenda command.
  2639. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2640. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2641. (defvar org-agenda-info nil)
  2642. ;;;###autoload
  2643. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2644. "Run an agenda command in batch mode and send the result to STDOUT.
  2645. If CMD-KEY is a string of length 1, it is used as a key in
  2646. `org-agenda-custom-commands' and triggers this command. If it is a
  2647. longer string it is used as a tags/todo match string.
  2648. Parameters are alternating variable names and values that will be bound
  2649. before running the agenda command.
  2650. The output gives a line for each selected agenda item. Each
  2651. item is a list of comma-separated values, like this:
  2652. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2653. category The category of the item
  2654. head The headline, without TODO kwd, TAGS and PRIORITY
  2655. type The type of the agenda entry, can be
  2656. todo selected in TODO match
  2657. tagsmatch selected in tags match
  2658. diary imported from diary
  2659. deadline a deadline on given date
  2660. scheduled scheduled on given date
  2661. timestamp entry has timestamp on given date
  2662. closed entry was closed on given date
  2663. upcoming-deadline warning about deadline
  2664. past-scheduled forwarded scheduled item
  2665. block entry has date block including g. date
  2666. todo The todo keyword, if any
  2667. tags All tags including inherited ones, separated by colons
  2668. date The relevant date, like 2007-2-14
  2669. time The time, like 15:00-16:50
  2670. extra Sting with extra planning info
  2671. priority-l The priority letter if any was given
  2672. priority-n The computed numerical priority
  2673. agenda-day The day in the agenda where this is listed"
  2674. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2675. (org-make-parameter-alist parameters))
  2676. (if (> (length cmd-key) 2)
  2677. (org-tags-view nil cmd-key)
  2678. (org-agenda nil cmd-key)))
  2679. (set-buffer org-agenda-buffer-name)
  2680. (let* ((lines (org-split-string (buffer-string) "\n"))
  2681. line)
  2682. (while (setq line (pop lines))
  2683. (catch 'next
  2684. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2685. (setq org-agenda-info
  2686. (org-fix-agenda-info (text-properties-at 0 line)))
  2687. (princ
  2688. (mapconcat 'org-agenda-export-csv-mapper
  2689. '(org-category txt type todo tags date time extra
  2690. priority-letter priority agenda-day)
  2691. ","))
  2692. (princ "\n")))))
  2693. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2694. Run an agenda command in batch mode and send the result to STDOUT.
  2695. If CMD-KEY is a string of length 1, it is used as a key in
  2696. `org-agenda-custom-commands' and triggers this command. If it is a
  2697. longer string it is used as a tags/todo match string.
  2698. Parameters are alternating variable names and values that will be bound
  2699. before running the agenda command.
  2700. The output gives a line for each selected agenda item. Each
  2701. item is a list of comma-separated values, like this:
  2702. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2703. category The category of the item
  2704. head The headline, without TODO kwd, TAGS and PRIORITY
  2705. type The type of the agenda entry, can be
  2706. todo selected in TODO match
  2707. tagsmatch selected in tags match
  2708. diary imported from diary
  2709. deadline a deadline on given date
  2710. scheduled scheduled on given date
  2711. timestamp entry has timestamp on given date
  2712. closed entry was closed on given date
  2713. upcoming-deadline warning about deadline
  2714. past-scheduled forwarded scheduled item
  2715. block entry has date block including g. date
  2716. todo The todo keyword, if any
  2717. tags All tags including inherited ones, separated by colons
  2718. date The relevant date, like 2007-2-14
  2719. time The time, like 15:00-16:50
  2720. extra Sting with extra planning info
  2721. priority-l The priority letter if any was given
  2722. priority-n The computed numerical priority
  2723. agenda-day The day in the agenda where this is listed
  2724. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2725. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2726. (defun org-fix-agenda-info (props)
  2727. "Make sure all properties on an agenda item have a canonical form.
  2728. This ensures the export commands can easily use it."
  2729. (let (tmp re)
  2730. (when (setq tmp (plist-get props 'tags))
  2731. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2732. (when (setq tmp (plist-get props 'date))
  2733. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2734. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2735. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2736. (setq tmp (calendar-date-string tmp)))
  2737. (setq props (plist-put props 'date tmp)))
  2738. (when (setq tmp (plist-get props 'day))
  2739. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2740. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2741. (setq tmp (calendar-date-string tmp)))
  2742. (setq props (plist-put props 'day tmp))
  2743. (setq props (plist-put props 'agenda-day tmp)))
  2744. (when (setq tmp (plist-get props 'txt))
  2745. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2746. (plist-put props 'priority-letter (match-string 1 tmp))
  2747. (setq tmp (replace-match "" t t tmp)))
  2748. (when (and (setq re (plist-get props 'org-todo-regexp))
  2749. (setq re (concat "\\`\\.*" re " ?"))
  2750. (string-match re tmp))
  2751. (plist-put props 'todo (match-string 1 tmp))
  2752. (setq tmp (replace-match "" t t tmp)))
  2753. (plist-put props 'txt tmp)))
  2754. props)
  2755. (defun org-agenda-export-csv-mapper (prop)
  2756. (let ((res (plist-get org-agenda-info prop)))
  2757. (setq res
  2758. (cond
  2759. ((not res) "")
  2760. ((stringp res) res)
  2761. (t (prin1-to-string res))))
  2762. (while (string-match "," res)
  2763. (setq res (replace-match ";" t t res)))
  2764. (org-trim res)))
  2765. ;;;###autoload
  2766. (defun org-store-agenda-views (&rest parameters)
  2767. (interactive)
  2768. (eval (list 'org-batch-store-agenda-views)))
  2769. (autoload 'org-store-agenda-views "org-agenda" "\
  2770. \(fn &rest PARAMETERS)" t nil)
  2771. ;;;###autoload
  2772. (defmacro org-batch-store-agenda-views (&rest parameters)
  2773. "Run all custom agenda commands that have a file argument."
  2774. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2775. (pop-up-frames nil)
  2776. (dir default-directory)
  2777. (pars (org-make-parameter-alist parameters))
  2778. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2779. (save-window-excursion
  2780. (while cmds
  2781. (setq cmd (pop cmds)
  2782. thiscmdkey (car cmd)
  2783. thiscmdcmd (cdr cmd)
  2784. match (nth 2 thiscmdcmd)
  2785. bufname (if org-agenda-sticky
  2786. (or (and (stringp match)
  2787. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2788. (format "*Org Agenda(%s)*" thiscmdkey))
  2789. org-agenda-buffer-name)
  2790. cmd-or-set (nth 2 cmd)
  2791. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2792. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2793. (if (stringp files) (setq files (list files)))
  2794. (when files
  2795. (org-eval-in-environment (append org-agenda-exporter-settings
  2796. opts pars)
  2797. (org-agenda nil thiscmdkey))
  2798. (set-buffer bufname)
  2799. (while files
  2800. (org-eval-in-environment (append org-agenda-exporter-settings
  2801. opts pars)
  2802. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2803. (and (get-buffer bufname)
  2804. (kill-buffer bufname)))))))
  2805. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2806. Run all custom agenda commands that have a file argument.
  2807. \(fn &rest PARAMETERS)" nil t)
  2808. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2809. (defvar org-agenda-current-span nil
  2810. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2811. (defun org-agenda-mark-header-line (pos)
  2812. "Mark the line at POS as an agenda structure header."
  2813. (save-excursion
  2814. (goto-char pos)
  2815. (put-text-property (point-at-bol) (point-at-eol)
  2816. 'org-agenda-structural-header t)
  2817. (when org-agenda-title-append
  2818. (put-text-property (point-at-bol) (point-at-eol)
  2819. 'org-agenda-title-append org-agenda-title-append))))
  2820. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2821. (defvar org-agenda-write-buffer-name "Agenda View")
  2822. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2823. "Write the current buffer (an agenda view) as a file.
  2824. Depending on the extension of the file name, plain text (.txt),
  2825. HTML (.html or .htm) or Postscript (.ps) is produced.
  2826. If the extension is .ics, run icalendar export over all files used
  2827. to construct the agenda and limit the export to entries listed in the
  2828. agenda now.
  2829. With prefix argument OPEN, open the new file immediately.
  2830. If NOSETTINGS is given, do not scope the settings of
  2831. `org-agenda-exporter-settings' into the export commands. This is used when
  2832. the settings have already been scoped and we do not wish to overrule other,
  2833. higher priority settings.
  2834. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2835. (interactive "FWrite agenda to file: \nP")
  2836. (if (not (file-writable-p file))
  2837. (error "Cannot write agenda to file %s" file))
  2838. (org-let (if nosettings nil org-agenda-exporter-settings)
  2839. '(save-excursion
  2840. (save-window-excursion
  2841. (org-agenda-mark-filtered-text)
  2842. (let ((bs (copy-sequence (buffer-string))) beg)
  2843. (org-agenda-unmark-filtered-text)
  2844. (with-temp-buffer
  2845. (rename-buffer org-agenda-write-buffer-name t)
  2846. (set-buffer-modified-p nil)
  2847. (insert bs)
  2848. (org-agenda-remove-marked-text 'org-filtered)
  2849. (while (setq beg (text-property-any (point-min) (point-max)
  2850. 'org-filtered t))
  2851. (delete-region
  2852. beg (or (next-single-property-change beg 'org-filtered)
  2853. (point-max))))
  2854. (run-hooks 'org-agenda-before-write-hook)
  2855. (cond
  2856. ((org-bound-and-true-p org-mobile-creating-agendas)
  2857. (org-mobile-write-agenda-for-mobile file))
  2858. ((string-match "\\.html?\\'" file)
  2859. (require 'htmlize)
  2860. (set-buffer (htmlize-buffer (current-buffer)))
  2861. (when org-agenda-export-html-style
  2862. ;; replace <style> section with org-agenda-export-html-style
  2863. (goto-char (point-min))
  2864. (kill-region (- (search-forward "<style") 6)
  2865. (search-forward "</style>"))
  2866. (insert org-agenda-export-html-style))
  2867. (write-file file)
  2868. (kill-buffer (current-buffer))
  2869. (message "HTML written to %s" file))
  2870. ((string-match "\\.ps\\'" file)
  2871. (require 'ps-print)
  2872. (ps-print-buffer-with-faces file)
  2873. (message "Postscript written to %s" file))
  2874. ((string-match "\\.pdf\\'" file)
  2875. (require 'ps-print)
  2876. (ps-print-buffer-with-faces
  2877. (concat (file-name-sans-extension file) ".ps"))
  2878. (call-process "ps2pdf" nil nil nil
  2879. (expand-file-name
  2880. (concat (file-name-sans-extension file) ".ps"))
  2881. (expand-file-name file))
  2882. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2883. (message "PDF written to %s" file))
  2884. ((string-match "\\.ics\\'" file)
  2885. (require 'org-icalendar)
  2886. (let ((org-agenda-marker-table
  2887. (org-create-marker-find-array
  2888. (org-agenda-collect-markers)))
  2889. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2890. (org-combined-agenda-icalendar-file file))
  2891. (apply 'org-export-icalendar 'combine
  2892. (org-agenda-files nil 'ifmode))))
  2893. (t
  2894. (let ((bs (buffer-string)))
  2895. (find-file file)
  2896. (erase-buffer)
  2897. (insert bs)
  2898. (save-buffer 0)
  2899. (kill-buffer (current-buffer))
  2900. (message "Plain text written to %s" file))))))))
  2901. (set-buffer (or agenda-bufname
  2902. (and (called-interactively-p 'any) (buffer-name))
  2903. org-agenda-buffer-name)))
  2904. (when open (org-open-file file)))
  2905. (defvar org-agenda-tag-filter-overlays nil)
  2906. (defvar org-agenda-cat-filter-overlays nil)
  2907. (defun org-agenda-mark-filtered-text ()
  2908. "Mark all text hidden by filtering with a text property."
  2909. (let ((inhibit-read-only t))
  2910. (mapc
  2911. (lambda (o)
  2912. (when (equal (overlay-buffer o) (current-buffer))
  2913. (put-text-property
  2914. (overlay-start o) (overlay-end o)
  2915. 'org-filtered t)))
  2916. (append org-agenda-tag-filter-overlays
  2917. org-agenda-cat-filter-overlays))))
  2918. (defun org-agenda-unmark-filtered-text ()
  2919. "Remove the filtering text property."
  2920. (let ((inhibit-read-only t))
  2921. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2922. (defun org-agenda-remove-marked-text (property &optional value)
  2923. "Delete all text marked with VALUE of PROPERTY.
  2924. VALUE defaults to t."
  2925. (let (beg)
  2926. (setq value (or value t))
  2927. (while (setq beg (text-property-any (point-min) (point-max)
  2928. property value))
  2929. (delete-region
  2930. beg (or (next-single-property-change beg 'org-filtered)
  2931. (point-max))))))
  2932. (defun org-agenda-add-entry-text ()
  2933. "Add entry text to agenda lines.
  2934. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2935. entry text following headings shown in the agenda.
  2936. Drawers will be excluded, also the line with scheduling/deadline info."
  2937. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2938. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2939. (let (m txt)
  2940. (goto-char (point-min))
  2941. (while (not (eobp))
  2942. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2943. (beginning-of-line 2)
  2944. (setq txt (org-agenda-get-some-entry-text
  2945. m org-agenda-add-entry-text-maxlines " > "))
  2946. (end-of-line 1)
  2947. (if (string-match "\\S-" txt)
  2948. (insert "\n" txt)
  2949. (or (eobp) (forward-char 1))))))))
  2950. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2951. &rest keep)
  2952. "Extract entry text from MARKER, at most N-LINES lines.
  2953. This will ignore drawers etc, just get the text.
  2954. If INDENT is given, prefix every line with this string. If KEEP is
  2955. given, it is a list of symbols, defining stuff that should not be
  2956. removed from the entry content. Currently only `planning' is allowed here."
  2957. (let (txt drawer-re kwd-time-re ind)
  2958. (save-excursion
  2959. (with-current-buffer (marker-buffer marker)
  2960. (if (not (derived-mode-p 'org-mode))
  2961. (setq txt "")
  2962. (save-excursion
  2963. (save-restriction
  2964. (widen)
  2965. (goto-char marker)
  2966. (end-of-line 1)
  2967. (setq txt (buffer-substring
  2968. (min (1+ (point)) (point-max))
  2969. (progn (outline-next-heading) (point)))
  2970. drawer-re org-drawer-regexp
  2971. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2972. ".*\n?"))
  2973. (with-temp-buffer
  2974. (insert txt)
  2975. (when org-agenda-add-entry-text-descriptive-links
  2976. (goto-char (point-min))
  2977. (while (org-activate-bracket-links (point-max))
  2978. (add-text-properties (match-beginning 0) (match-end 0)
  2979. '(face org-link))))
  2980. (goto-char (point-min))
  2981. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2982. (set-text-properties (match-beginning 0) (match-end 0)
  2983. nil))
  2984. (goto-char (point-min))
  2985. (while (re-search-forward drawer-re nil t)
  2986. (delete-region
  2987. (match-beginning 0)
  2988. (progn (re-search-forward
  2989. "^[ \t]*:END:.*\n?" nil 'move)
  2990. (point))))
  2991. (unless (member 'planning keep)
  2992. (goto-char (point-min))
  2993. (while (re-search-forward kwd-time-re nil t)
  2994. (replace-match "")))
  2995. (goto-char (point-min))
  2996. (when org-agenda-entry-text-exclude-regexps
  2997. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2998. (while (setq re (pop re-list))
  2999. (goto-char (point-min))
  3000. (while (re-search-forward re nil t)
  3001. (replace-match "")))))
  3002. (goto-char (point-max))
  3003. (skip-chars-backward " \t\n")
  3004. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3005. ;; find and remove min common indentation
  3006. (goto-char (point-min))
  3007. (untabify (point-min) (point-max))
  3008. (setq ind (org-get-indentation))
  3009. (while (not (eobp))
  3010. (unless (looking-at "[ \t]*$")
  3011. (setq ind (min ind (org-get-indentation))))
  3012. (beginning-of-line 2))
  3013. (goto-char (point-min))
  3014. (while (not (eobp))
  3015. (unless (looking-at "[ \t]*$")
  3016. (move-to-column ind)
  3017. (delete-region (point-at-bol) (point)))
  3018. (beginning-of-line 2))
  3019. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3020. (goto-char (point-min))
  3021. (when indent
  3022. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3023. (replace-match indent t t)))
  3024. (goto-char (point-min))
  3025. (while (looking-at "[ \t]*\n") (replace-match ""))
  3026. (goto-char (point-max))
  3027. (when (> (org-current-line)
  3028. n-lines)
  3029. (org-goto-line (1+ n-lines))
  3030. (backward-char 1))
  3031. (setq txt (buffer-substring (point-min) (point)))))))))
  3032. txt))
  3033. (defun org-agenda-collect-markers ()
  3034. "Collect the markers pointing to entries in the agenda buffer."
  3035. (let (m markers)
  3036. (save-excursion
  3037. (goto-char (point-min))
  3038. (while (not (eobp))
  3039. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3040. (org-get-at-bol 'org-marker)))
  3041. (push m markers))
  3042. (beginning-of-line 2)))
  3043. (nreverse markers)))
  3044. (defun org-create-marker-find-array (marker-list)
  3045. "Create a alist of files names with all marker positions in that file."
  3046. (let (f tbl m a p)
  3047. (while (setq m (pop marker-list))
  3048. (setq p (marker-position m)
  3049. f (buffer-file-name (or (buffer-base-buffer
  3050. (marker-buffer m))
  3051. (marker-buffer m))))
  3052. (if (setq a (assoc f tbl))
  3053. (push (marker-position m) (cdr a))
  3054. (push (list f p) tbl)))
  3055. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3056. tbl)))
  3057. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3058. (defun org-check-agenda-marker-table ()
  3059. "Check of the current entry is on the marker list."
  3060. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3061. a)
  3062. (and (setq a (assoc file org-agenda-marker-table))
  3063. (save-match-data
  3064. (save-excursion
  3065. (org-back-to-heading t)
  3066. (member (point) (cdr a)))))))
  3067. (defun org-check-for-org-mode ()
  3068. "Make sure current buffer is in org-mode. Error if not."
  3069. (or (derived-mode-p 'org-mode)
  3070. (error "Cannot execute org-mode agenda command on buffer in %s"
  3071. major-mode)))
  3072. ;;; Agenda prepare and finalize
  3073. (defvar org-agenda-multi nil) ; dynamically scoped
  3074. (defvar org-agenda-pre-window-conf nil)
  3075. (defvar org-agenda-columns-active nil)
  3076. (defvar org-agenda-name nil)
  3077. (defvar org-agenda-tag-filter nil)
  3078. (defvar org-agenda-category-filter nil)
  3079. (defvar org-agenda-top-category-filter nil)
  3080. (defvar org-agenda-tag-filter-while-redo nil)
  3081. (defvar org-agenda-tag-filter-preset nil
  3082. "A preset of the tags filter used for secondary agenda filtering.
  3083. This must be a list of strings, each string must be a single tag preceded
  3084. by \"+\" or \"-\".
  3085. This variable should not be set directly, but agenda custom commands can
  3086. bind it in the options section. The preset filter is a global property of
  3087. the entire agenda view. In a block agenda, it will not work reliably to
  3088. define a filter for one of the individual blocks. You need to set it in
  3089. the global options and expect it to be applied to the entire view.")
  3090. (defvar org-agenda-category-filter-preset nil
  3091. "A preset of the category filter used for secondary agenda filtering.
  3092. This must be a list of strings, each string must be a single category
  3093. preceded by \"+\" or \"-\".
  3094. This variable should not be set directly, but agenda custom commands can
  3095. bind it in the options section. The preset filter is a global property of
  3096. the entire agenda view. In a block agenda, it will not work reliably to
  3097. define a filter for one of the individual blocks. You need to set it in
  3098. the global options and expect it to be applied to the entire view.")
  3099. (defun org-agenda-use-sticky-p ()
  3100. "Return non-nil if an agenda buffer named
  3101. `org-agenda-buffer-name' exists and should be shown instead of
  3102. generating a new one."
  3103. (and
  3104. ;; turned off by user
  3105. org-agenda-sticky
  3106. ;; For multi-agenda buffer already exists
  3107. (not org-agenda-multi)
  3108. ;; buffer found
  3109. (get-buffer org-agenda-buffer-name)
  3110. ;; C-u parameter is same as last call
  3111. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3112. (and
  3113. (equal current-prefix-arg
  3114. org-agenda-last-prefix-arg)
  3115. ;; In case user turned stickiness on, while having existing
  3116. ;; Agenda buffer active, don't reuse that buffer, because it
  3117. ;; does not have org variables local
  3118. org-agenda-this-buffer-is-sticky))))
  3119. (defun org-agenda-prepare-window (abuf)
  3120. "Setup agenda buffer in the window."
  3121. (let* ((awin (get-buffer-window abuf))
  3122. wconf)
  3123. (cond
  3124. ((equal (current-buffer) abuf) nil)
  3125. (awin (select-window awin))
  3126. ((not (setq wconf (current-window-configuration))))
  3127. ((equal org-agenda-window-setup 'current-window)
  3128. (org-pop-to-buffer-same-window abuf))
  3129. ((equal org-agenda-window-setup 'other-window)
  3130. (org-switch-to-buffer-other-window abuf))
  3131. ((equal org-agenda-window-setup 'other-frame)
  3132. (switch-to-buffer-other-frame abuf))
  3133. ((equal org-agenda-window-setup 'reorganize-frame)
  3134. (delete-other-windows)
  3135. (org-switch-to-buffer-other-window abuf)))
  3136. ;; additional test in case agenda is invoked from within agenda
  3137. ;; buffer via elisp link
  3138. (unless (equal (current-buffer) abuf)
  3139. (org-pop-to-buffer-same-window abuf))
  3140. (setq org-agenda-pre-window-conf
  3141. (or org-agenda-pre-window-conf wconf))))
  3142. (defun org-agenda-prepare (&optional name)
  3143. (if (org-agenda-use-sticky-p)
  3144. (progn
  3145. ;; Popup existing buffer
  3146. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3147. (message "Sticky Agenda buffer, use `r' to refresh")
  3148. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3149. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3150. (setq org-todo-keywords-for-agenda nil)
  3151. (setq org-drawers-for-agenda nil)
  3152. (unless org-agenda-persistent-filter
  3153. (setq org-agenda-tag-filter nil
  3154. org-agenda-category-filter nil))
  3155. (put 'org-agenda-tag-filter :preset-filter
  3156. org-agenda-tag-filter-preset)
  3157. (put 'org-agenda-category-filter :preset-filter
  3158. org-agenda-category-filter-preset)
  3159. (if org-agenda-multi
  3160. (progn
  3161. (setq buffer-read-only nil)
  3162. (goto-char (point-max))
  3163. (unless (or (bobp) org-agenda-compact-blocks
  3164. (not org-agenda-block-separator))
  3165. (insert "\n"
  3166. (if (stringp org-agenda-block-separator)
  3167. org-agenda-block-separator
  3168. (make-string (window-width) org-agenda-block-separator))
  3169. "\n"))
  3170. (narrow-to-region (point) (point-max)))
  3171. (setq org-done-keywords-for-agenda nil)
  3172. ;; Setting any org variables that are in org-agenda-local-vars
  3173. ;; list need to be done after the prepare call
  3174. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3175. (setq buffer-read-only nil)
  3176. (org-agenda-reset-markers)
  3177. (let ((inhibit-read-only t)) (erase-buffer))
  3178. (org-agenda-mode)
  3179. (setq org-agenda-buffer (current-buffer))
  3180. (setq org-agenda-contributing-files nil)
  3181. (setq org-agenda-columns-active nil)
  3182. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3183. (setq org-todo-keywords-for-agenda
  3184. (org-uniquify org-todo-keywords-for-agenda))
  3185. (setq org-done-keywords-for-agenda
  3186. (org-uniquify org-done-keywords-for-agenda))
  3187. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3188. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3189. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3190. (and name (not org-agenda-name)
  3191. (org-set-local 'org-agenda-name name)))
  3192. (setq buffer-read-only nil)))
  3193. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3194. (defun org-agenda-finalize ()
  3195. "Finishing touch for the agenda buffer, called just before displaying it."
  3196. (unless org-agenda-multi
  3197. (save-excursion
  3198. (let ((inhibit-read-only t))
  3199. (goto-char (point-min))
  3200. (while (org-activate-bracket-links (point-max))
  3201. (add-text-properties (match-beginning 0) (match-end 0)
  3202. '(face org-link)))
  3203. (org-agenda-align-tags)
  3204. (unless org-agenda-with-colors
  3205. (remove-text-properties (point-min) (point-max) '(face nil))))
  3206. (if (and (boundp 'org-agenda-overriding-columns-format)
  3207. org-agenda-overriding-columns-format)
  3208. (org-set-local 'org-agenda-overriding-columns-format
  3209. org-agenda-overriding-columns-format))
  3210. (if (and (boundp 'org-agenda-view-columns-initially)
  3211. org-agenda-view-columns-initially)
  3212. (org-agenda-columns))
  3213. (when org-agenda-fontify-priorities
  3214. (org-agenda-fontify-priorities))
  3215. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3216. (org-agenda-dim-blocked-tasks))
  3217. (org-agenda-mark-clocking-task)
  3218. (when org-agenda-entry-text-mode
  3219. (org-agenda-entry-text-hide)
  3220. (org-agenda-entry-text-show))
  3221. (if (functionp 'org-habit-insert-consistency-graphs)
  3222. (org-habit-insert-consistency-graphs))
  3223. (let ((inhibit-read-only t))
  3224. (run-hooks 'org-agenda-finalize-hook))
  3225. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3226. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3227. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3228. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3229. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3230. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3231. (defun org-agenda-mark-clocking-task ()
  3232. "Mark the current clock entry in the agenda if it is present."
  3233. (mapc (lambda (o)
  3234. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3235. (delete-overlay o)))
  3236. (overlays-in (point-min) (point-max)))
  3237. (when (marker-buffer org-clock-hd-marker)
  3238. (save-excursion
  3239. (goto-char (point-min))
  3240. (let (s ov)
  3241. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3242. (goto-char s)
  3243. (when (equal (org-get-at-bol 'org-hd-marker)
  3244. org-clock-hd-marker)
  3245. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3246. (overlay-put ov 'type 'org-agenda-clocking)
  3247. (overlay-put ov 'face 'org-agenda-clocking)
  3248. (overlay-put ov 'help-echo
  3249. "The clock is running in this item")))))))
  3250. (defun org-agenda-fontify-priorities ()
  3251. "Make highest priority lines bold, and lowest italic."
  3252. (interactive)
  3253. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3254. (delete-overlay o)))
  3255. (overlays-in (point-min) (point-max)))
  3256. (save-excursion
  3257. (let ((inhibit-read-only t)
  3258. b e p ov h l)
  3259. (goto-char (point-min))
  3260. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3261. (setq h (or (get-char-property (point) 'org-highest-priority)
  3262. org-highest-priority)
  3263. l (or (get-char-property (point) 'org-lowest-priority)
  3264. org-lowest-priority)
  3265. p (string-to-char (match-string 1))
  3266. b (match-beginning 0)
  3267. e (if (eq org-agenda-fontify-priorities 'cookies)
  3268. (match-end 0)
  3269. (point-at-eol))
  3270. ov (make-overlay b e))
  3271. (overlay-put
  3272. ov 'face
  3273. (cond ((org-face-from-face-or-color
  3274. 'priority nil
  3275. (cdr (assoc p org-priority-faces))))
  3276. ((and (listp org-agenda-fontify-priorities)
  3277. (org-face-from-face-or-color
  3278. 'priority nil
  3279. (cdr (assoc p org-agenda-fontify-priorities)))))
  3280. ((equal p l) 'italic)
  3281. ((equal p h) 'bold)))
  3282. (overlay-put ov 'org-type 'org-priority)))))
  3283. (defun org-agenda-dim-blocked-tasks ()
  3284. "Dim currently blocked TODO's in the agenda display."
  3285. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3286. (delete-overlay o)))
  3287. (overlays-in (point-min) (point-max)))
  3288. (save-excursion
  3289. (let ((inhibit-read-only t)
  3290. (org-depend-tag-blocked nil)
  3291. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3292. org-blocked-by-checkboxes
  3293. invis1 b e p ov h l)
  3294. (goto-char (point-min))
  3295. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3296. (and pos (goto-char (1+ pos))))
  3297. (setq org-blocked-by-checkboxes nil invis1 invis)
  3298. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3299. (when (and marker
  3300. (with-current-buffer (marker-buffer marker)
  3301. (save-excursion (goto-char marker)
  3302. (org-entry-blocked-p))))
  3303. (if org-blocked-by-checkboxes (setq invis1 nil))
  3304. (setq b (if invis1
  3305. (max (point-min) (1- (point-at-bol)))
  3306. (point-at-bol))
  3307. e (point-at-eol)
  3308. ov (make-overlay b e))
  3309. (if invis1
  3310. (overlay-put ov 'invisible t)
  3311. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3312. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3313. (defvar org-agenda-skip-function nil
  3314. "Function to be called at each match during agenda construction.
  3315. If this function returns nil, the current match should not be skipped.
  3316. Otherwise, the function must return a position from where the search
  3317. should be continued.
  3318. This may also be a Lisp form, it will be evaluated.
  3319. Never set this variable using `setq' or so, because then it will apply
  3320. to all future agenda commands. If you do want a global skipping condition,
  3321. use the option `org-agenda-skip-function-global' instead.
  3322. The correct usage for `org-agenda-skip-function' is to bind it with
  3323. `let' to scope it dynamically into the agenda-constructing command.
  3324. A good way to set it is through options in `org-agenda-custom-commands'.")
  3325. (defun org-agenda-skip ()
  3326. "Throw to `:skip' in places that should be skipped.
  3327. Also moves point to the end of the skipped region, so that search can
  3328. continue from there."
  3329. (let ((p (point-at-bol)) to)
  3330. (when (org-in-src-block-p) (throw :skip t))
  3331. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3332. (get-text-property p :org-archived)
  3333. (org-end-of-subtree t)
  3334. (throw :skip t))
  3335. (and org-agenda-skip-comment-trees
  3336. (get-text-property p :org-comment)
  3337. (org-end-of-subtree t)
  3338. (throw :skip t))
  3339. (if (equal (char-after p) ?#) (throw :skip t))
  3340. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3341. (org-agenda-skip-eval org-agenda-skip-function)))
  3342. (goto-char to)
  3343. (throw :skip t))))
  3344. (defun org-agenda-skip-eval (form)
  3345. "If FORM is a function or a list, call (or eval) is and return result.
  3346. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3347. and match data are returned to the previous state no matter what these
  3348. functions do."
  3349. (let (fp)
  3350. (and form
  3351. (or (setq fp (functionp form))
  3352. (consp form))
  3353. (save-excursion
  3354. (save-match-data
  3355. (if fp
  3356. (funcall form)
  3357. (eval form)))))))
  3358. (defvar org-agenda-markers nil
  3359. "List of all currently active markers created by `org-agenda'.")
  3360. (defvar org-agenda-last-marker-time (org-float-time)
  3361. "Creation time of the last agenda marker.")
  3362. (defun org-agenda-new-marker (&optional pos)
  3363. "Return a new agenda marker.
  3364. Org-mode keeps a list of these markers and resets them when they are
  3365. no longer in use."
  3366. (let ((m (copy-marker (or pos (point)))))
  3367. (setq org-agenda-last-marker-time (org-float-time))
  3368. (if org-agenda-buffer
  3369. (with-current-buffer org-agenda-buffer
  3370. (push m org-agenda-markers))
  3371. (push m org-agenda-markers))
  3372. m))
  3373. (defun org-agenda-reset-markers ()
  3374. "Reset markers created by `org-agenda'."
  3375. (while org-agenda-markers
  3376. (move-marker (pop org-agenda-markers) nil)))
  3377. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3378. "Save relative positions of markers in region.
  3379. This check for agenda markers in all agenda buffers currently active."
  3380. (dolist (buf (buffer-list))
  3381. (with-current-buffer buf
  3382. (when (eq major-mode 'org-agenda-mode)
  3383. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3384. org-agenda-markers)))))
  3385. ;;; Entry text mode
  3386. (defun org-agenda-entry-text-show-here ()
  3387. "Add some text from the entry as context to the current line."
  3388. (let (m txt o)
  3389. (setq m (org-get-at-bol 'org-hd-marker))
  3390. (unless (marker-buffer m)
  3391. (error "No marker points to an entry here"))
  3392. (setq txt (concat "\n" (org-no-properties
  3393. (org-agenda-get-some-entry-text
  3394. m org-agenda-entry-text-maxlines " > "))))
  3395. (when (string-match "\\S-" txt)
  3396. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3397. (overlay-put o 'evaporate t)
  3398. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3399. (overlay-put o 'after-string txt))))
  3400. (defun org-agenda-entry-text-show ()
  3401. "Add entry context for all agenda lines."
  3402. (interactive)
  3403. (save-excursion
  3404. (goto-char (point-max))
  3405. (beginning-of-line 1)
  3406. (while (not (bobp))
  3407. (when (org-get-at-bol 'org-hd-marker)
  3408. (org-agenda-entry-text-show-here))
  3409. (beginning-of-line 0))))
  3410. (defun org-agenda-entry-text-hide ()
  3411. "Remove any shown entry context."
  3412. (delq nil
  3413. (mapcar (lambda (o)
  3414. (if (eq (overlay-get o 'org-overlay-type)
  3415. 'agenda-entry-content)
  3416. (progn (delete-overlay o) t)))
  3417. (overlays-in (point-min) (point-max)))))
  3418. (defun org-agenda-get-day-face (date)
  3419. "Return the face DATE should be displayed with."
  3420. (or (and (functionp org-agenda-day-face-function)
  3421. (funcall org-agenda-day-face-function date))
  3422. (cond ((org-agenda-todayp date)
  3423. 'org-agenda-date-today)
  3424. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3425. 'org-agenda-date-weekend)
  3426. (t 'org-agenda-date))))
  3427. ;;; Agenda timeline
  3428. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3429. (defun org-timeline (&optional dotodo)
  3430. "Show a time-sorted view of the entries in the current org file.
  3431. Only entries with a time stamp of today or later will be listed. With
  3432. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3433. under the current date.
  3434. If the buffer contains an active region, only check the region for
  3435. dates."
  3436. (interactive "P")
  3437. (let* ((dopast t)
  3438. (org-agenda-show-log-scoped org-agenda-show-log)
  3439. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3440. (current-buffer))))
  3441. (date (calendar-current-date))
  3442. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3443. (end (if (org-region-active-p) (region-end) (point-max)))
  3444. (day-numbers (org-get-all-dates
  3445. beg end 'no-ranges
  3446. t org-agenda-show-log-scoped ; always include today
  3447. org-timeline-show-empty-dates))
  3448. (org-deadline-warning-days 0)
  3449. (org-agenda-only-exact-dates t)
  3450. (today (org-today))
  3451. (past t)
  3452. args
  3453. s e rtn d emptyp)
  3454. (setq org-agenda-redo-command
  3455. (list 'progn
  3456. (list 'org-switch-to-buffer-other-window (current-buffer))
  3457. (list 'org-timeline (list 'quote dotodo))))
  3458. (if (not dopast)
  3459. ;; Remove past dates from the list of dates.
  3460. (setq day-numbers (delq nil (mapcar (lambda(x)
  3461. (if (>= x today) x nil))
  3462. day-numbers))))
  3463. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3464. (org-compile-prefix-format 'timeline)
  3465. (org-set-sorting-strategy 'timeline)
  3466. (if org-agenda-show-log-scoped (push :closed args))
  3467. (push :timestamp args)
  3468. (push :deadline args)
  3469. (push :scheduled args)
  3470. (push :sexp args)
  3471. (if dotodo (push :todo args))
  3472. (insert "Timeline of file " entry "\n")
  3473. (add-text-properties (point-min) (point)
  3474. (list 'face 'org-agenda-structure))
  3475. (org-agenda-mark-header-line (point-min))
  3476. (while (setq d (pop day-numbers))
  3477. (if (and (listp d) (eq (car d) :omitted))
  3478. (progn
  3479. (setq s (point))
  3480. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3481. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3482. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3483. (if (and (>= d today)
  3484. dopast
  3485. past)
  3486. (progn
  3487. (setq past nil)
  3488. (insert (make-string 79 ?-) "\n")))
  3489. (setq date (calendar-gregorian-from-absolute d))
  3490. (setq s (point))
  3491. (setq rtn (and (not emptyp)
  3492. (apply 'org-agenda-get-day-entries entry
  3493. date args)))
  3494. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3495. (progn
  3496. (insert
  3497. (if (stringp org-agenda-format-date)
  3498. (format-time-string org-agenda-format-date
  3499. (org-time-from-absolute date))
  3500. (funcall org-agenda-format-date date))
  3501. "\n")
  3502. (put-text-property s (1- (point)) 'face
  3503. (org-agenda-get-day-face date))
  3504. (put-text-property s (1- (point)) 'org-date-line t)
  3505. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3506. (if (equal d today)
  3507. (put-text-property s (1- (point)) 'org-today t))
  3508. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3509. (put-text-property s (1- (point)) 'day d)))))
  3510. (goto-char (point-min))
  3511. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3512. (point-min)))
  3513. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3514. (org-agenda-finalize)
  3515. (setq buffer-read-only t)))
  3516. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3517. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3518. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3519. not every single day in the range. If FORCE-TODAY is non-nil, make
  3520. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3521. inactive time stamps (those in square brackets) are included.
  3522. When EMPTY is non-nil, also include days without any entries."
  3523. (let ((re (concat
  3524. (if pre-re pre-re "")
  3525. (if inactive org-ts-regexp-both org-ts-regexp)))
  3526. dates dates1 date day day1 day2 ts1 ts2 pos)
  3527. (if force-today
  3528. (setq dates (list (org-today))))
  3529. (save-excursion
  3530. (goto-char beg)
  3531. (while (re-search-forward re end t)
  3532. (setq day (time-to-days (org-time-string-to-time
  3533. (substring (match-string 1) 0 10)
  3534. (current-buffer) (match-beginning 0))))
  3535. (or (memq day dates) (push day dates)))
  3536. (unless no-ranges
  3537. (goto-char beg)
  3538. (while (re-search-forward org-tr-regexp end t)
  3539. (setq pos (match-beginning 0))
  3540. (setq ts1 (substring (match-string 1) 0 10)
  3541. ts2 (substring (match-string 2) 0 10)
  3542. day1 (time-to-days (org-time-string-to-time
  3543. ts1 (current-buffer) pos))
  3544. day2 (time-to-days (org-time-string-to-time
  3545. ts2 (current-buffer) pos)))
  3546. (while (< (setq day1 (1+ day1)) day2)
  3547. (or (memq day1 dates) (push day1 dates)))))
  3548. (setq dates (sort dates '<))
  3549. (when empty
  3550. (while (setq day (pop dates))
  3551. (setq day2 (car dates))
  3552. (push day dates1)
  3553. (when (and day2 empty)
  3554. (if (or (eq empty t)
  3555. (and (numberp empty) (<= (- day2 day) empty)))
  3556. (while (< (setq day (1+ day)) day2)
  3557. (push (list day) dates1))
  3558. (push (cons :omitted (- day2 day)) dates1))))
  3559. (setq dates (nreverse dates1)))
  3560. dates)))
  3561. ;;; Agenda Daily/Weekly
  3562. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3563. "Start day for the agenda view.
  3564. Custom commands can set this variable in the options section.")
  3565. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3566. (defvar org-arg-loc nil) ; local variable
  3567. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3568. "List of types searched for when creating the daily/weekly agenda.
  3569. This variable is a list of symbols that controls the types of
  3570. items that appear in the daily/weekly agenda. Allowed symbols in this
  3571. list are are
  3572. :timestamp List items containing a date stamp or date range matching
  3573. the selected date. This includes sexp entries in
  3574. angular brackets.
  3575. :sexp List entries resulting from plain diary-like sexps.
  3576. :deadline List deadline due on that date. When the date is today,
  3577. also list any deadlines past due, or due within
  3578. `org-deadline-warning-days'. `:deadline' must appear before
  3579. `:scheduled' if the setting of
  3580. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3581. any effect.
  3582. :scheduled List all items which are scheduled for the given date.
  3583. The diary for *today* also contains items which were
  3584. scheduled earlier and are not yet marked DONE.
  3585. By default, all four types are turned on.
  3586. Never set this variable globally using `setq', because then it
  3587. will apply to all future agenda commands. Instead, bind it with
  3588. `let' to scope it dynamically into the agenda-constructing
  3589. command. A good way to set it is through options in
  3590. `org-agenda-custom-commands'. For a more flexible (though
  3591. somewhat less efficient) way of determining what is included in
  3592. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3593. (defvar org-agenda-buffer-tmp-name nil)
  3594. ;;;###autoload
  3595. (defun org-agenda-list (&optional arg start-day span)
  3596. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3597. The view will be for the current day or week, but from the overview buffer
  3598. you will be able to go to other days/weeks.
  3599. With a numeric prefix argument in an interactive call, the agenda will
  3600. span ARG days. Lisp programs should instead specify SPAN to change
  3601. the number of days. SPAN defaults to `org-agenda-span'.
  3602. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3603. given in `org-agenda-start-on-weekday'."
  3604. (interactive "P")
  3605. (if org-agenda-overriding-arguments
  3606. (setq arg (car org-agenda-overriding-arguments)
  3607. start-day (nth 1 org-agenda-overriding-arguments)
  3608. span (nth 2 org-agenda-overriding-arguments)))
  3609. (if (and (integerp arg) (> arg 0))
  3610. (setq span arg arg nil))
  3611. (catch 'exit
  3612. (setq org-agenda-buffer-name
  3613. (or org-agenda-buffer-tmp-name
  3614. (if org-agenda-sticky
  3615. (cond ((and org-keys (stringp org-match))
  3616. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3617. (org-keys
  3618. (format "*Org Agenda(%s)*" org-keys))
  3619. (t "*Org Agenda(a)*")))
  3620. org-agenda-buffer-name))
  3621. (org-agenda-prepare "Day/Week")
  3622. (setq start-day (or start-day org-agenda-start-day))
  3623. (if (stringp start-day)
  3624. ;; Convert to an absolute day number
  3625. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3626. (org-compile-prefix-format 'agenda)
  3627. (org-set-sorting-strategy 'agenda)
  3628. (let* ((span (org-agenda-ndays-to-span
  3629. (or span org-agenda-ndays org-agenda-span)))
  3630. (today (org-today))
  3631. (sd (or start-day today))
  3632. (ndays (org-agenda-span-to-ndays span sd))
  3633. (org-agenda-start-on-weekday
  3634. (if (eq ndays 7)
  3635. org-agenda-start-on-weekday))
  3636. (thefiles (org-agenda-files nil 'ifmode))
  3637. (files thefiles)
  3638. (start (if (or (null org-agenda-start-on-weekday)
  3639. (< ndays 7))
  3640. sd
  3641. (let* ((nt (calendar-day-of-week
  3642. (calendar-gregorian-from-absolute sd)))
  3643. (n1 org-agenda-start-on-weekday)
  3644. (d (- nt n1)))
  3645. (- sd (+ (if (< d 0) 7 0) d)))))
  3646. (day-numbers (list start))
  3647. (day-cnt 0)
  3648. (inhibit-redisplay (not debug-on-error))
  3649. (org-agenda-show-log-scoped org-agenda-show-log)
  3650. s e rtn rtnall file date d start-pos end-pos todayp
  3651. clocktable-start clocktable-end filter)
  3652. (setq org-agenda-redo-command
  3653. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3654. (dotimes (n (1- ndays))
  3655. (push (1+ (car day-numbers)) day-numbers))
  3656. (setq day-numbers (nreverse day-numbers))
  3657. (setq clocktable-start (car day-numbers)
  3658. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3659. (org-set-local 'org-starting-day (car day-numbers))
  3660. (org-set-local 'org-arg-loc arg)
  3661. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3662. (unless org-agenda-compact-blocks
  3663. (let* ((d1 (car day-numbers))
  3664. (d2 (org-last day-numbers))
  3665. (w1 (org-days-to-iso-week d1))
  3666. (w2 (org-days-to-iso-week d2)))
  3667. (setq s (point))
  3668. (if org-agenda-overriding-header
  3669. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3670. nil 'face 'org-agenda-structure) "\n")
  3671. (insert (org-agenda-span-name span)
  3672. "-agenda"
  3673. (if (< (- d2 d1) 350)
  3674. (if (= w1 w2)
  3675. (format " (W%02d)" w1)
  3676. (format " (W%02d-W%02d)" w1 w2))
  3677. "")
  3678. ":\n")))
  3679. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3680. 'org-date-line t))
  3681. (org-agenda-mark-header-line s))
  3682. (while (setq d (pop day-numbers))
  3683. (setq date (calendar-gregorian-from-absolute d)
  3684. s (point))
  3685. (if (or (setq todayp (= d today))
  3686. (and (not start-pos) (= d sd)))
  3687. (setq start-pos (point))
  3688. (if (and start-pos (not end-pos))
  3689. (setq end-pos (point))))
  3690. (setq files thefiles
  3691. rtnall nil)
  3692. (while (setq file (pop files))
  3693. (catch 'nextfile
  3694. (org-check-agenda-file file)
  3695. (let ((org-agenda-entry-types org-agenda-entry-types))
  3696. (unless org-agenda-include-deadlines
  3697. (setq org-agenda-entry-types
  3698. (delq :deadline org-agenda-entry-types)))
  3699. (cond
  3700. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3701. (setq rtn (org-agenda-get-day-entries
  3702. file date :closed)))
  3703. (org-agenda-show-log-scoped
  3704. (setq rtn (apply 'org-agenda-get-day-entries
  3705. file date
  3706. (append '(:closed) org-agenda-entry-types))))
  3707. (t
  3708. (setq rtn (apply 'org-agenda-get-day-entries
  3709. file date
  3710. org-agenda-entry-types)))))
  3711. (setq rtnall (append rtnall rtn)))) ;; all entries
  3712. (if org-agenda-include-diary
  3713. (let ((org-agenda-search-headline-for-time t))
  3714. (require 'diary-lib)
  3715. (setq rtn (org-get-entries-from-diary date))
  3716. (setq rtnall (append rtnall rtn))))
  3717. (if (or rtnall org-agenda-show-all-dates)
  3718. (progn
  3719. (setq day-cnt (1+ day-cnt))
  3720. (insert
  3721. (if (stringp org-agenda-format-date)
  3722. (format-time-string org-agenda-format-date
  3723. (org-time-from-absolute date))
  3724. (funcall org-agenda-format-date date))
  3725. "\n")
  3726. (put-text-property s (1- (point)) 'face
  3727. (org-agenda-get-day-face date))
  3728. (put-text-property s (1- (point)) 'org-date-line t)
  3729. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3730. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3731. (when todayp
  3732. (put-text-property s (1- (point)) 'org-today t))
  3733. (setq rtnall
  3734. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3735. (if rtnall (insert ;; all entries
  3736. (org-agenda-finalize-entries rtnall)
  3737. "\n"))
  3738. (put-text-property s (1- (point)) 'day d)
  3739. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3740. (when (and org-agenda-clockreport-mode clocktable-start)
  3741. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3742. ;; the above line is to ensure the restricted range!
  3743. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3744. tbl)
  3745. (setq p (org-plist-delete p :block))
  3746. (setq p (plist-put p :tstart clocktable-start))
  3747. (setq p (plist-put p :tend clocktable-end))
  3748. (setq p (plist-put p :scope 'agenda))
  3749. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3750. (setq filter (or org-agenda-tag-filter-while-redo
  3751. (get 'org-agenda-tag-filter :preset-filter))))
  3752. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3753. (if (string-match "[<>=]" x)
  3754. ""
  3755. x))
  3756. filter ""))))
  3757. (setq tbl (apply 'org-get-clocktable p))
  3758. (insert tbl)))
  3759. (goto-char (point-min))
  3760. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3761. (unless (and (pos-visible-in-window-p (point-min))
  3762. (pos-visible-in-window-p (point-max)))
  3763. (goto-char (1- (point-max)))
  3764. (recenter -1)
  3765. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3766. (progn
  3767. (goto-char (or start-pos 1))
  3768. (recenter 1))))
  3769. (goto-char (or start-pos 1))
  3770. (add-text-properties (point-min) (point-max)
  3771. `(org-agenda-type agenda
  3772. org-last-args (,arg ,start-day ,span)
  3773. org-redo-cmd ,org-agenda-redo-command
  3774. org-serie-cmd ,org-cmd))
  3775. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3776. (org-agenda-show-clocking-issues))
  3777. (org-agenda-finalize)
  3778. (setq buffer-read-only t)
  3779. (message ""))))
  3780. (autoload 'org-agenda-list "org-agenda" "\
  3781. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3782. The view will be for the current day or week, but from the overview buffer
  3783. you will be able to go to other days/weeks.
  3784. With a numeric prefix argument in an interactive call, the agenda will
  3785. span ARG days. Lisp programs should instead specify SPAN to change
  3786. the number of days. SPAN defaults to `org-agenda-span'.
  3787. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3788. given in `org-agenda-start-on-weekday'.
  3789. \(fn &optional ARG START-DAY SPAN)" t nil)
  3790. (defun org-agenda-ndays-to-span (n)
  3791. "Return a span symbol for a span of N days, or N if none matches."
  3792. (cond ((symbolp n) n)
  3793. ((= n 1) 'day)
  3794. ((= n 7) 'week)
  3795. (t n)))
  3796. (defun org-agenda-span-to-ndays (span &optional start-day)
  3797. "Return ndays from SPAN, possibly starting at START-DAY."
  3798. (cond ((numberp span) span)
  3799. ((eq span 'day) 1)
  3800. ((eq span 'week) 7)
  3801. ((eq span 'month)
  3802. (let ((date (calendar-gregorian-from-absolute start-day)))
  3803. (calendar-last-day-of-month (car date) (caddr date))))
  3804. ((eq span 'year)
  3805. (let ((date (calendar-gregorian-from-absolute start-day)))
  3806. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3807. (defun org-agenda-span-name (span)
  3808. "Return a SPAN name."
  3809. (if (null span)
  3810. ""
  3811. (if (symbolp span)
  3812. (capitalize (symbol-name span))
  3813. (format "%d days" span))))
  3814. ;;; Agenda word search
  3815. (defvar org-agenda-search-history nil)
  3816. (defvar org-search-syntax-table nil
  3817. "Special syntax table for org-mode search.
  3818. In this table, we have single quotes not as word constituents, to
  3819. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3820. (defvar org-mode-syntax-table) ; From org.el
  3821. (defun org-search-syntax-table ()
  3822. (unless org-search-syntax-table
  3823. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3824. (modify-syntax-entry ?' "." org-search-syntax-table)
  3825. (modify-syntax-entry ?` "." org-search-syntax-table))
  3826. org-search-syntax-table)
  3827. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3828. ;;;###autoload
  3829. (defun org-search-view (&optional todo-only string edit-at)
  3830. "Show all entries that contain a phrase or words or regular expressions.
  3831. With optional prefix argument TODO-ONLY, only consider entries that are
  3832. TODO entries. The argument STRING can be used to pass a default search
  3833. string into this function. If EDIT-AT is non-nil, it means that the
  3834. user should get a chance to edit this string, with cursor at position
  3835. EDIT-AT.
  3836. The search string can be viewed either as a phrase that should be found as
  3837. is, or it can be broken into a number of snippets, each of which must match
  3838. in a Boolean way to select an entry. The default depends on the variable
  3839. `org-agenda-search-view-always-boolean'.
  3840. Even if this is turned off (the default) you can always switch to
  3841. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3842. The default is a direct search of the whole phrase, where each space in
  3843. the search string can expand to an arbitrary amount of whitespace,
  3844. including newlines.
  3845. If using a Boolean search, the search string is split on whitespace and
  3846. each snippet is searched separately, with logical AND to select an entry.
  3847. Words prefixed with a minus must *not* occur in the entry. Words without
  3848. a prefix or prefixed with a plus must occur in the entry. Matching is
  3849. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3850. match whole words, not parts of a word) if
  3851. `org-agenda-search-view-force-full-words' is set (default is nil).
  3852. Boolean search snippets enclosed by curly braces are interpreted as
  3853. regular expressions that must or (when preceded with \"-\") must not
  3854. match in the entry. Snippets enclosed into double quotes will be taken
  3855. as a whole, to include whitespace.
  3856. - If the search string starts with an asterisk, search only in headlines.
  3857. - If (possibly after the leading star) the search string starts with an
  3858. exclamation mark, this also means to look at TODO entries only, an effect
  3859. that can also be achieved with a prefix argument.
  3860. - If (possibly after star and exclamation mark) the search string starts
  3861. with a colon, this will mean that the (non-regexp) snippets of the
  3862. Boolean search must match as full words.
  3863. This command searches the agenda files, and in addition the files listed
  3864. in `org-agenda-text-search-extra-files'."
  3865. (interactive "P")
  3866. (if org-agenda-overriding-arguments
  3867. (setq todo-only (car org-agenda-overriding-arguments)
  3868. string (nth 1 org-agenda-overriding-arguments)
  3869. edit-at (nth 2 org-agenda-overriding-arguments)))
  3870. (let* ((props (list 'face nil
  3871. 'done-face 'org-agenda-done
  3872. 'org-not-done-regexp org-not-done-regexp
  3873. 'org-todo-regexp org-todo-regexp
  3874. 'org-complex-heading-regexp org-complex-heading-regexp
  3875. 'mouse-face 'highlight
  3876. 'help-echo (format "mouse-2 or RET jump to location")))
  3877. (full-words org-agenda-search-view-force-full-words)
  3878. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3879. regexp rtn rtnall files file pos
  3880. marker category category-pos tags c neg re boolean
  3881. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3882. (unless (and (not edit-at)
  3883. (stringp string)
  3884. (string-match "\\S-" string))
  3885. (setq string (read-string
  3886. (if org-agenda-search-view-always-boolean
  3887. "[+-]Word/{Regexp} ...: "
  3888. "Phrase or [+-]Word/{Regexp} ...: ")
  3889. (cond
  3890. ((integerp edit-at) (cons string edit-at))
  3891. (edit-at string))
  3892. 'org-agenda-search-history)))
  3893. (catch 'exit
  3894. (if org-agenda-sticky
  3895. (setq org-agenda-buffer-name
  3896. (if (stringp string)
  3897. (format "*Org Agenda(%s:%s)*"
  3898. (or org-keys (or (and todo-only "S") "s")) string)
  3899. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3900. (org-agenda-prepare "SEARCH")
  3901. (org-compile-prefix-format 'search)
  3902. (org-set-sorting-strategy 'search)
  3903. (setq org-agenda-redo-command
  3904. (list 'org-search-view (if todo-only t nil)
  3905. (list 'if 'current-prefix-arg nil string)))
  3906. (setq org-agenda-query-string string)
  3907. (if (equal (string-to-char string) ?*)
  3908. (setq hdl-only t
  3909. words (substring string 1))
  3910. (setq words string))
  3911. (when (equal (string-to-char words) ?!)
  3912. (setq todo-only t
  3913. words (substring words 1)))
  3914. (when (equal (string-to-char words) ?:)
  3915. (setq full-words t
  3916. words (substring words 1)))
  3917. (if (or org-agenda-search-view-always-boolean
  3918. (member (string-to-char words) '(?- ?+ ?\{)))
  3919. (setq boolean t))
  3920. (setq words (org-split-string words))
  3921. (let (www w)
  3922. (while (setq w (pop words))
  3923. (while (and (string-match "\\\\\\'" w) words)
  3924. (setq w (concat (substring w 0 -1) " " (pop words))))
  3925. (push w www))
  3926. (setq words (nreverse www) www nil)
  3927. (while (setq w (pop words))
  3928. (when (and (string-match "\\`[-+]?{" w)
  3929. (not (string-match "}\\'" w)))
  3930. (while (and words (not (string-match "}\\'" (car words))))
  3931. (setq w (concat w " " (pop words))))
  3932. (setq w (concat w " " (pop words))))
  3933. (push w www))
  3934. (setq words (nreverse www)))
  3935. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3936. (when boolean
  3937. (let (wds w)
  3938. (while (setq w (pop words))
  3939. (if (or (equal (substring w 0 1) "\"")
  3940. (and (> (length w) 1)
  3941. (member (substring w 0 1) '("+" "-"))
  3942. (equal (substring w 1 2) "\"")))
  3943. (while (and words (not (equal (substring w -1) "\"")))
  3944. (setq w (concat w " " (pop words)))))
  3945. (and (string-match "\\`\\([-+]?\\)\"" w)
  3946. (setq w (replace-match "\\1" nil nil w)))
  3947. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3948. (push w wds))
  3949. (setq words (nreverse wds))))
  3950. (if boolean
  3951. (mapc (lambda (w)
  3952. (setq c (string-to-char w))
  3953. (if (equal c ?-)
  3954. (setq neg t w (substring w 1))
  3955. (if (equal c ?+)
  3956. (setq neg nil w (substring w 1))
  3957. (setq neg nil)))
  3958. (if (string-match "\\`{.*}\\'" w)
  3959. (setq re (substring w 1 -1))
  3960. (if full-words
  3961. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3962. (setq re (regexp-quote (downcase w)))))
  3963. (if neg (push re regexps-) (push re regexps+)))
  3964. words)
  3965. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3966. regexps+))
  3967. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3968. (if (not regexps+)
  3969. (setq regexp org-outline-regexp-bol)
  3970. (setq regexp (pop regexps+))
  3971. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3972. regexp))))
  3973. (setq files (org-agenda-files nil 'ifmode))
  3974. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3975. (pop org-agenda-text-search-extra-files)
  3976. (setq files (org-add-archive-files files)))
  3977. (setq files (append files org-agenda-text-search-extra-files)
  3978. rtnall nil)
  3979. (while (setq file (pop files))
  3980. (setq ee nil)
  3981. (catch 'nextfile
  3982. (org-check-agenda-file file)
  3983. (setq buffer (if (file-exists-p file)
  3984. (org-get-agenda-file-buffer file)
  3985. (error "No such file %s" file)))
  3986. (if (not buffer)
  3987. ;; If file does not exist, make sure an error message is sent
  3988. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3989. file))))
  3990. (with-current-buffer buffer
  3991. (with-syntax-table (org-search-syntax-table)
  3992. (unless (derived-mode-p 'org-mode)
  3993. (error "Agenda file %s is not in `org-mode'" file))
  3994. (let ((case-fold-search t))
  3995. (save-excursion
  3996. (save-restriction
  3997. (if org-agenda-restrict
  3998. (narrow-to-region org-agenda-restrict-begin
  3999. org-agenda-restrict-end)
  4000. (widen))
  4001. (goto-char (point-min))
  4002. (unless (or (org-at-heading-p)
  4003. (outline-next-heading))
  4004. (throw 'nextfile t))
  4005. (goto-char (max (point-min) (1- (point))))
  4006. (while (re-search-forward regexp nil t)
  4007. (org-back-to-heading t)
  4008. (skip-chars-forward "* ")
  4009. (setq beg (point-at-bol)
  4010. beg1 (point)
  4011. end (progn (outline-next-heading) (point)))
  4012. (catch :skip
  4013. (goto-char beg)
  4014. (org-agenda-skip)
  4015. (setq str (buffer-substring-no-properties
  4016. (point-at-bol)
  4017. (if hdl-only (point-at-eol) end)))
  4018. (mapc (lambda (wr) (when (string-match wr str)
  4019. (goto-char (1- end))
  4020. (throw :skip t)))
  4021. regexps-)
  4022. (mapc (lambda (wr) (unless (string-match wr str)
  4023. (goto-char (1- end))
  4024. (throw :skip t)))
  4025. (if todo-only
  4026. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4027. regexps+)
  4028. regexps+))
  4029. (goto-char beg)
  4030. (setq marker (org-agenda-new-marker (point))
  4031. category (org-get-category)
  4032. category-pos (get-text-property (point) 'org-category-position)
  4033. tags (org-get-tags-at (point))
  4034. txt (org-agenda-format-item
  4035. ""
  4036. (buffer-substring-no-properties
  4037. beg1 (point-at-eol))
  4038. category tags t))
  4039. (org-add-props txt props
  4040. 'org-marker marker 'org-hd-marker marker
  4041. 'org-todo-regexp org-todo-regexp
  4042. 'org-complex-heading-regexp org-complex-heading-regexp
  4043. 'priority 1000 'org-category category
  4044. 'org-category-position category-pos
  4045. 'type "search")
  4046. (push txt ee)
  4047. (goto-char (1- end))))))))))
  4048. (setq rtn (nreverse ee))
  4049. (setq rtnall (append rtnall rtn)))
  4050. (if org-agenda-overriding-header
  4051. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4052. nil 'face 'org-agenda-structure) "\n")
  4053. (insert "Search words: ")
  4054. (add-text-properties (point-min) (1- (point))
  4055. (list 'face 'org-agenda-structure))
  4056. (setq pos (point))
  4057. (insert string "\n")
  4058. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4059. (setq pos (point))
  4060. (unless org-agenda-multi
  4061. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4062. (add-text-properties pos (1- (point))
  4063. (list 'face 'org-agenda-structure))))
  4064. (org-agenda-mark-header-line (point-min))
  4065. (when rtnall
  4066. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4067. (goto-char (point-min))
  4068. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4069. (add-text-properties (point-min) (point-max)
  4070. `(org-agenda-type search
  4071. org-last-args (,todo-only ,string ,edit-at)
  4072. org-redo-cmd ,org-agenda-redo-command
  4073. org-serie-cmd ,org-cmd))
  4074. (org-agenda-finalize)
  4075. (setq buffer-read-only t))))
  4076. (autoload 'org-search-view "org-agenda" "\
  4077. Show all entries that contain a phrase or words or regular expressions.
  4078. With optional prefix argument TODO-ONLY, only consider entries that are
  4079. TODO entries. The argument STRING can be used to pass a default search
  4080. string into this function. If EDIT-AT is non-nil, it means that the
  4081. user should get a chance to edit this string, with cursor at position
  4082. EDIT-AT.
  4083. The search string can be viewed either as a phrase that should be found as
  4084. is, or it can be broken into a number of snippets, each of which must match
  4085. in a Boolean way to select an entry. The default depends on the variable
  4086. `org-agenda-search-view-always-boolean'.
  4087. Even if this is turned off (the default) you can always switch to
  4088. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4089. The default is a direct search of the whole phrase, where each space in
  4090. the search string can expand to an arbitrary amount of whitespace,
  4091. including newlines.
  4092. If using a Boolean search, the search string is split on whitespace and
  4093. each snippet is searched separately, with logical AND to select an entry.
  4094. Words prefixed with a minus must *not* occur in the entry. Words without
  4095. a prefix or prefixed with a plus must occur in the entry. Matching is
  4096. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4097. match whole words, not parts of a word) if
  4098. `org-agenda-search-view-force-full-words' is set (default is nil).
  4099. Boolean search snippets enclosed by curly braces are interpreted as
  4100. regular expressions that must or (when preceded with \"-\") must not
  4101. match in the entry. Snippets enclosed into double quotes will be taken
  4102. as a whole, to include whitespace.
  4103. - If the search string starts with an asterisk, search only in headlines.
  4104. - If (possibly after the leading star) the search string starts with an
  4105. exclamation mark, this also means to look at TODO entries only, an effect
  4106. that can also be achieved with a prefix argument.
  4107. - If (possibly after star and exclamation mark) the search string starts
  4108. with a colon, this will mean that the (non-regexp) snippets of the
  4109. Boolean search must match as full words.
  4110. This command searches the agenda files, and in addition the files listed
  4111. in `org-agenda-text-search-extra-files'.
  4112. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4113. ;;; Agenda TODO list
  4114. (defvar org-select-this-todo-keyword nil)
  4115. (defvar org-last-arg nil)
  4116. ;;;###autoload
  4117. (defun org-todo-list (&optional arg)
  4118. "Show all (not done) TODO entries from all agenda file in a single list.
  4119. The prefix arg can be used to select a specific TODO keyword and limit
  4120. the list to these. When using \\[universal-argument], you will be prompted
  4121. for a keyword. A numeric prefix directly selects the Nth keyword in
  4122. `org-todo-keywords-1'."
  4123. (interactive "P")
  4124. (if org-agenda-overriding-arguments
  4125. (setq arg org-agenda-overriding-arguments))
  4126. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4127. (let* ((today (org-today))
  4128. (date (calendar-gregorian-from-absolute today))
  4129. (kwds org-todo-keywords-for-agenda)
  4130. (completion-ignore-case t)
  4131. (org-select-this-todo-keyword
  4132. (if (stringp arg) arg
  4133. (and arg (integerp arg) (> arg 0)
  4134. (nth (1- arg) kwds))))
  4135. rtn rtnall files file pos)
  4136. (when (equal arg '(4))
  4137. (setq org-select-this-todo-keyword
  4138. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4139. (mapcar 'list kwds) nil nil)))
  4140. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4141. (catch 'exit
  4142. (if org-agenda-sticky
  4143. (setq org-agenda-buffer-name
  4144. (if (stringp org-select-this-todo-keyword)
  4145. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4146. org-select-this-todo-keyword)
  4147. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4148. (org-agenda-prepare "TODO")
  4149. (org-compile-prefix-format 'todo)
  4150. (org-set-sorting-strategy 'todo)
  4151. (setq org-agenda-redo-command
  4152. `(org-todo-list (or (and (numberp current-prefix-arg)
  4153. current-prefix-arg)
  4154. ,org-select-this-todo-keyword
  4155. current-prefix-arg ,arg)))
  4156. (setq files (org-agenda-files nil 'ifmode)
  4157. rtnall nil)
  4158. (while (setq file (pop files))
  4159. (catch 'nextfile
  4160. (org-check-agenda-file file)
  4161. (setq rtn (org-agenda-get-day-entries file date :todo))
  4162. (setq rtnall (append rtnall rtn))))
  4163. (if org-agenda-overriding-header
  4164. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4165. nil 'face 'org-agenda-structure) "\n")
  4166. (insert "Global list of TODO items of type: ")
  4167. (add-text-properties (point-min) (1- (point))
  4168. (list 'face 'org-agenda-structure
  4169. 'short-heading
  4170. (concat "ToDo: "
  4171. (or org-select-this-todo-keyword "ALL"))))
  4172. (org-agenda-mark-header-line (point-min))
  4173. (setq pos (point))
  4174. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4175. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4176. (setq pos (point))
  4177. (unless org-agenda-multi
  4178. (insert "Available with `N r': (0)[ALL]")
  4179. (let ((n 0) s)
  4180. (mapc (lambda (x)
  4181. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4182. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4183. (insert "\n "))
  4184. (insert " " s))
  4185. kwds))
  4186. (insert "\n"))
  4187. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4188. (org-agenda-mark-header-line (point-min))
  4189. (when rtnall
  4190. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4191. (goto-char (point-min))
  4192. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4193. (add-text-properties (point-min) (point-max)
  4194. `(org-agenda-type todo
  4195. org-last-args ,arg
  4196. org-redo-cmd ,org-agenda-redo-command
  4197. org-serie-cmd ,org-cmd))
  4198. (org-agenda-finalize)
  4199. (setq buffer-read-only t))))
  4200. (autoload 'org-todo-list "org-agenda" "\
  4201. Show all (not done) TODO entries from all agenda file in a single list.
  4202. The prefix arg can be used to select a specific TODO keyword and limit
  4203. the list to these. When using \\[universal-argument], you will be prompted
  4204. for a keyword. A numeric prefix directly selects the Nth keyword in
  4205. `org-todo-keywords-1'.
  4206. \(fn &optional ARG)" t nil)
  4207. ;;; Agenda tags match
  4208. ;;;###autoload
  4209. (defun org-tags-view (&optional todo-only match)
  4210. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4211. The prefix arg TODO-ONLY limits the search to TODO entries."
  4212. (interactive "P")
  4213. (if org-agenda-overriding-arguments
  4214. (setq todo-only (car org-agenda-overriding-arguments)
  4215. match (nth 1 org-agenda-overriding-arguments)))
  4216. (let* ((org-tags-match-list-sublevels
  4217. org-tags-match-list-sublevels)
  4218. (completion-ignore-case t)
  4219. rtn rtnall files file pos matcher
  4220. buffer)
  4221. (when (and (stringp match) (not (string-match "\\S-" match)))
  4222. (setq match nil))
  4223. (setq matcher (org-make-tags-matcher match)
  4224. match (car matcher) matcher (cdr matcher))
  4225. (catch 'exit
  4226. (if org-agenda-sticky
  4227. (setq org-agenda-buffer-name
  4228. (if (stringp match)
  4229. (format "*Org Agenda(%s:%s)*"
  4230. (or org-keys (or (and todo-only "M") "m")) match)
  4231. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4232. (org-agenda-prepare (concat "TAGS " match))
  4233. (org-compile-prefix-format 'tags)
  4234. (org-set-sorting-strategy 'tags)
  4235. (setq org-agenda-query-string match)
  4236. (setq org-agenda-redo-command
  4237. (list 'org-tags-view `(quote ,todo-only)
  4238. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4239. (setq files (org-agenda-files nil 'ifmode)
  4240. rtnall nil)
  4241. (while (setq file (pop files))
  4242. (catch 'nextfile
  4243. (org-check-agenda-file file)
  4244. (setq buffer (if (file-exists-p file)
  4245. (org-get-agenda-file-buffer file)
  4246. (error "No such file %s" file)))
  4247. (if (not buffer)
  4248. ;; If file does not exist, error message to agenda
  4249. (setq rtn (list
  4250. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4251. rtnall (append rtnall rtn))
  4252. (with-current-buffer buffer
  4253. (unless (derived-mode-p 'org-mode)
  4254. (error "Agenda file %s is not in `org-mode'" file))
  4255. (save-excursion
  4256. (save-restriction
  4257. (if org-agenda-restrict
  4258. (narrow-to-region org-agenda-restrict-begin
  4259. org-agenda-restrict-end)
  4260. (widen))
  4261. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4262. (setq rtnall (append rtnall rtn))))))))
  4263. (if org-agenda-overriding-header
  4264. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4265. nil 'face 'org-agenda-structure) "\n")
  4266. (insert "Headlines with TAGS match: ")
  4267. (add-text-properties (point-min) (1- (point))
  4268. (list 'face 'org-agenda-structure
  4269. 'short-heading
  4270. (concat "Match: " match)))
  4271. (setq pos (point))
  4272. (insert match "\n")
  4273. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4274. (setq pos (point))
  4275. (unless org-agenda-multi
  4276. (insert "Press `C-u r' to search again with new search string\n"))
  4277. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4278. (org-agenda-mark-header-line (point-min))
  4279. (when rtnall
  4280. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4281. (goto-char (point-min))
  4282. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4283. (add-text-properties (point-min) (point-max)
  4284. `(org-agenda-type tags
  4285. org-last-args (,todo-only ,match)
  4286. org-redo-cmd ,org-agenda-redo-command
  4287. org-serie-cmd ,org-cmd))
  4288. (org-agenda-finalize)
  4289. (setq buffer-read-only t))))
  4290. (autoload 'org-tags-view "org-agenda" "\
  4291. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4292. The prefix arg TODO-ONLY limits the search to TODO entries.
  4293. \(fn &optional TODO-ONLY MATCH)" t nil)
  4294. ;;; Agenda Finding stuck projects
  4295. (defvar org-agenda-skip-regexp nil
  4296. "Regular expression used in skipping subtrees for the agenda.
  4297. This is basically a temporary global variable that can be set and then
  4298. used by user-defined selections using `org-agenda-skip-function'.")
  4299. (defvar org-agenda-overriding-header nil
  4300. "When set during agenda, todo and tags searches it replaces the header.
  4301. This variable should not be set directly, but custom commands can bind it
  4302. in the options section.")
  4303. (defun org-agenda-skip-entry-when-regexp-matches ()
  4304. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4305. If yes, it returns the end position of this entry, causing agenda commands
  4306. to skip the entry but continuing the search in the subtree. This is a
  4307. function that can be put into `org-agenda-skip-function' for the duration
  4308. of a command."
  4309. (let ((end (save-excursion (org-end-of-subtree t)))
  4310. skip)
  4311. (save-excursion
  4312. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4313. (and skip end)))
  4314. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4315. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4316. If yes, it returns the end position of this tree, causing agenda commands
  4317. to skip this subtree. This is a function that can be put into
  4318. `org-agenda-skip-function' for the duration of a command."
  4319. (let ((end (save-excursion (org-end-of-subtree t)))
  4320. skip)
  4321. (save-excursion
  4322. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4323. (and skip end)))
  4324. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4325. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4326. If yes, it returns the end position of the current entry (NOT the tree),
  4327. causing agenda commands to skip the entry but continuing the search in
  4328. the subtree. This is a function that can be put into
  4329. `org-agenda-skip-function' for the duration of a command. An important
  4330. use of this function is for the stuck project list."
  4331. (let ((end (save-excursion (org-end-of-subtree t)))
  4332. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4333. skip)
  4334. (save-excursion
  4335. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4336. (and skip entry-end)))
  4337. (defun org-agenda-skip-entry-if (&rest conditions)
  4338. "Skip entry if any of CONDITIONS is true.
  4339. See `org-agenda-skip-if' for details."
  4340. (org-agenda-skip-if nil conditions))
  4341. (defun org-agenda-skip-subtree-if (&rest conditions)
  4342. "Skip entry if any of CONDITIONS is true.
  4343. See `org-agenda-skip-if' for details."
  4344. (org-agenda-skip-if t conditions))
  4345. (defun org-agenda-skip-if (subtree conditions)
  4346. "Checks current entity for CONDITIONS.
  4347. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4348. the entry (i.e. the text before the next heading) is checked.
  4349. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4350. from different tests. Valid conditions are:
  4351. scheduled Check if there is a scheduled cookie
  4352. notscheduled Check if there is no scheduled cookie
  4353. deadline Check if there is a deadline
  4354. notdeadline Check if there is no deadline
  4355. timestamp Check if there is a timestamp (also deadline or scheduled)
  4356. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4357. regexp Check if regexp matches
  4358. notregexp Check if regexp does not match.
  4359. todo Check if TODO keyword matches
  4360. nottodo Check if TODO keyword does not match
  4361. The regexp is taken from the conditions list, it must come right after
  4362. the `regexp' or `notregexp' element.
  4363. `todo' and `nottodo' accept as an argument a list of todo
  4364. keywords, which may include \"*\" to match any todo keyword.
  4365. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4366. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4367. Instead of a list, a keyword class may be given. For example:
  4368. (org-agenda-skip-entry-if 'nottodo 'done)
  4369. would skip entries that haven't been marked with any of \"DONE\"
  4370. keywords. Possible classes are: `todo', `done', `any'.
  4371. If any of these conditions is met, this function returns the end point of
  4372. the entity, causing the search to continue from there. This is a function
  4373. that can be put into `org-agenda-skip-function' for the duration of a command."
  4374. (let (beg end m)
  4375. (org-back-to-heading t)
  4376. (setq beg (point)
  4377. end (if subtree
  4378. (progn (org-end-of-subtree t) (point))
  4379. (progn (outline-next-heading) (1- (point)))))
  4380. (goto-char beg)
  4381. (and
  4382. (or
  4383. (and (memq 'scheduled conditions)
  4384. (re-search-forward org-scheduled-time-regexp end t))
  4385. (and (memq 'notscheduled conditions)
  4386. (not (re-search-forward org-scheduled-time-regexp end t)))
  4387. (and (memq 'deadline conditions)
  4388. (re-search-forward org-deadline-time-regexp end t))
  4389. (and (memq 'notdeadline conditions)
  4390. (not (re-search-forward org-deadline-time-regexp end t)))
  4391. (and (memq 'timestamp conditions)
  4392. (re-search-forward org-ts-regexp end t))
  4393. (and (memq 'nottimestamp conditions)
  4394. (not (re-search-forward org-ts-regexp end t)))
  4395. (and (setq m (memq 'regexp conditions))
  4396. (stringp (nth 1 m))
  4397. (re-search-forward (nth 1 m) end t))
  4398. (and (setq m (memq 'notregexp conditions))
  4399. (stringp (nth 1 m))
  4400. (not (re-search-forward (nth 1 m) end t)))
  4401. (and (or
  4402. (setq m (memq 'nottodo conditions))
  4403. (setq m (memq 'todo-unblocked conditions))
  4404. (setq m (memq 'nottodo-unblocked conditions))
  4405. (setq m (memq 'todo conditions)))
  4406. (org-agenda-skip-if-todo m end)))
  4407. end)))
  4408. (defun org-agenda-skip-if-todo (args end)
  4409. "Helper function for `org-agenda-skip-if', do not use it directly.
  4410. ARGS is a list with first element either `todo', `nottodo',
  4411. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4412. a list of TODO keywords, or a state symbol `todo' or `done' or
  4413. `any'."
  4414. (let ((kw (car args))
  4415. (arg (cadr args))
  4416. todo-wds todo-re)
  4417. (setq todo-wds
  4418. (org-uniquify
  4419. (cond
  4420. ((listp arg) ;; list of keywords
  4421. (if (member "*" arg)
  4422. (mapcar 'substring-no-properties org-todo-keywords-1)
  4423. arg))
  4424. ((symbolp arg) ;; keyword class name
  4425. (cond
  4426. ((eq arg 'todo)
  4427. (org-delete-all org-done-keywords
  4428. (mapcar 'substring-no-properties
  4429. org-todo-keywords-1)))
  4430. ((eq arg 'done) org-done-keywords)
  4431. ((eq arg 'any)
  4432. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4433. (setq todo-re
  4434. (concat "^\\*+[ \t]+\\<\\("
  4435. (mapconcat 'identity todo-wds "\\|")
  4436. "\\)\\>"))
  4437. (cond
  4438. ((eq kw 'todo) (re-search-forward todo-re end t))
  4439. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4440. ((eq kw 'todo-unblocked)
  4441. (catch 'unblocked
  4442. (while (re-search-forward todo-re end t)
  4443. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4444. nil))
  4445. ((eq kw 'nottodo-unblocked)
  4446. (catch 'unblocked
  4447. (while (re-search-forward todo-re end t)
  4448. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4449. t))
  4450. )))
  4451. ;;;###autoload
  4452. (defun org-agenda-list-stuck-projects (&rest ignore)
  4453. "Create agenda view for projects that are stuck.
  4454. Stuck projects are project that have no next actions. For the definitions
  4455. of what a project is and how to check if it stuck, customize the variable
  4456. `org-stuck-projects'."
  4457. (interactive)
  4458. (let* ((org-agenda-skip-function
  4459. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4460. ;; We could have used org-agenda-skip-if here.
  4461. (org-agenda-overriding-header
  4462. (or org-agenda-overriding-header "List of stuck projects: "))
  4463. (matcher (nth 0 org-stuck-projects))
  4464. (todo (nth 1 org-stuck-projects))
  4465. (todo-wds (if (member "*" todo)
  4466. (progn
  4467. (org-agenda-prepare-buffers (org-agenda-files
  4468. nil 'ifmode))
  4469. (org-delete-all
  4470. org-done-keywords-for-agenda
  4471. (copy-sequence org-todo-keywords-for-agenda)))
  4472. todo))
  4473. (todo-re (concat "^\\*+[ \t]+\\("
  4474. (mapconcat 'identity todo-wds "\\|")
  4475. "\\)\\>"))
  4476. (tags (nth 2 org-stuck-projects))
  4477. (tags-re (if (member "*" tags)
  4478. (concat org-outline-regexp-bol
  4479. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4480. (if tags
  4481. (concat org-outline-regexp-bol
  4482. ".*:\\("
  4483. (mapconcat 'identity tags "\\|")
  4484. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4485. (gen-re (nth 3 org-stuck-projects))
  4486. (re-list
  4487. (delq nil
  4488. (list
  4489. (if todo todo-re)
  4490. (if tags tags-re)
  4491. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4492. gen-re)))))
  4493. (setq org-agenda-skip-regexp
  4494. (if re-list
  4495. (mapconcat 'identity re-list "\\|")
  4496. (error "No information how to identify unstuck projects")))
  4497. (org-tags-view nil matcher)
  4498. (with-current-buffer org-agenda-buffer-name
  4499. (setq org-agenda-redo-command
  4500. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4501. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4502. Create agenda view for projects that are stuck.
  4503. Stuck projects are project that have no next actions. For the definitions
  4504. of what a project is and how to check if it stuck, customize the variable
  4505. `org-stuck-projects'.
  4506. \(fn &rest IGNORE)" t nil)
  4507. ;;; Diary integration
  4508. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4509. (defvar diary-list-entries-hook)
  4510. (defvar diary-time-regexp)
  4511. (defun org-get-entries-from-diary (date)
  4512. "Get the (Emacs Calendar) diary entries for DATE."
  4513. (require 'diary-lib)
  4514. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4515. (diary-display-hook '(fancy-diary-display))
  4516. (diary-display-function 'fancy-diary-display)
  4517. (pop-up-frames nil)
  4518. (diary-list-entries-hook
  4519. (cons 'org-diary-default-entry diary-list-entries-hook))
  4520. (diary-file-name-prefix-function nil) ; turn this feature off
  4521. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4522. entries
  4523. (org-disable-agenda-to-diary t))
  4524. (save-excursion
  4525. (save-window-excursion
  4526. (funcall (if (fboundp 'diary-list-entries)
  4527. 'diary-list-entries 'list-diary-entries)
  4528. date 1)))
  4529. (if (not (get-buffer diary-fancy-buffer))
  4530. (setq entries nil)
  4531. (with-current-buffer diary-fancy-buffer
  4532. (setq buffer-read-only nil)
  4533. (if (zerop (buffer-size))
  4534. ;; No entries
  4535. (setq entries nil)
  4536. ;; Omit the date and other unnecessary stuff
  4537. (org-agenda-cleanup-fancy-diary)
  4538. ;; Add prefix to each line and extend the text properties
  4539. (if (zerop (buffer-size))
  4540. (setq entries nil)
  4541. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4542. (setq entries
  4543. (with-temp-buffer
  4544. (insert entries) (goto-char (point-min))
  4545. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4546. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4547. (replace-match (concat "; " (match-string 1)))))
  4548. (buffer-string)))))
  4549. (set-buffer-modified-p nil)
  4550. (kill-buffer diary-fancy-buffer)))
  4551. (when entries
  4552. (setq entries (org-split-string entries "\n"))
  4553. (setq entries
  4554. (mapcar
  4555. (lambda (x)
  4556. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4557. ;; Extend the text properties to the beginning of the line
  4558. (org-add-props x (text-properties-at (1- (length x)) x)
  4559. 'type "diary" 'date date 'face 'org-agenda-diary))
  4560. entries)))))
  4561. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4562. "Hook run when the fancy diary buffer is cleaned up.")
  4563. (defun org-agenda-cleanup-fancy-diary ()
  4564. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4565. This gets rid of the date, the underline under the date, and
  4566. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4567. date. It also removes lines that contain only whitespace."
  4568. (goto-char (point-min))
  4569. (if (looking-at ".*?:[ \t]*")
  4570. (progn
  4571. (replace-match "")
  4572. (re-search-forward "\n=+$" nil t)
  4573. (replace-match "")
  4574. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4575. (re-search-forward "\n=+$" nil t)
  4576. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4577. (goto-char (point-min))
  4578. (while (re-search-forward "^ +\n" nil t)
  4579. (replace-match ""))
  4580. (goto-char (point-min))
  4581. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4582. (replace-match ""))
  4583. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4584. ;; Make sure entries from the diary have the right text properties.
  4585. (eval-after-load "diary-lib"
  4586. '(if (boundp 'diary-modify-entry-list-string-function)
  4587. ;; We can rely on the hook, nothing to do
  4588. nil
  4589. ;; Hook not available, must use advice to make this work
  4590. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4591. "Make the position visible."
  4592. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4593. (stringp string)
  4594. buffer-file-name)
  4595. (setq string (org-modify-diary-entry-string string))))))
  4596. (defun org-modify-diary-entry-string (string)
  4597. "Add text properties to string, allowing org-mode to act on it."
  4598. (org-add-props string nil
  4599. 'mouse-face 'highlight
  4600. 'help-echo (if buffer-file-name
  4601. (format "mouse-2 or RET jump to diary file %s"
  4602. (abbreviate-file-name buffer-file-name))
  4603. "")
  4604. 'org-agenda-diary-link t
  4605. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4606. (defun org-diary-default-entry ()
  4607. "Add a dummy entry to the diary.
  4608. Needed to avoid empty dates which mess up holiday display."
  4609. ;; Catch the error if dealing with the new add-to-diary-alist
  4610. (when org-disable-agenda-to-diary
  4611. (condition-case nil
  4612. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4613. (error
  4614. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4615. (defun org-add-to-diary-list (&rest args)
  4616. (if (fboundp 'diary-add-to-list)
  4617. (apply 'diary-add-to-list args)
  4618. (apply 'add-to-diary-list args)))
  4619. (defvar org-diary-last-run-time nil)
  4620. ;;;###autoload
  4621. (defun org-diary (&rest args)
  4622. "Return diary information from org files.
  4623. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4624. It accesses org files and extracts information from those files to be
  4625. listed in the diary. The function accepts arguments specifying what
  4626. items should be listed. For a list of arguments allowed here, see the
  4627. variable `org-agenda-entry-types'.
  4628. The call in the diary file should look like this:
  4629. &%%(org-diary) ~/path/to/some/orgfile.org
  4630. Use a separate line for each org file to check. Or, if you omit the file name,
  4631. all files listed in `org-agenda-files' will be checked automatically:
  4632. &%%(org-diary)
  4633. If you don't give any arguments (as in the example above), the default
  4634. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4635. So the example above may also be written as
  4636. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4637. The function expects the lisp variables `entry' and `date' to be provided
  4638. by the caller, because this is how the calendar works. Don't use this
  4639. function from a program - use `org-agenda-get-day-entries' instead."
  4640. (when (> (- (org-float-time)
  4641. org-agenda-last-marker-time)
  4642. 5)
  4643. ;; I am not sure if this works with sticky agendas, because the marker
  4644. ;; list is then no longer a global variable.
  4645. (org-agenda-reset-markers))
  4646. (org-compile-prefix-format 'agenda)
  4647. (org-set-sorting-strategy 'agenda)
  4648. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4649. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4650. (list entry)
  4651. (org-agenda-files t)))
  4652. (time (org-float-time))
  4653. file rtn results)
  4654. (when (or (not org-diary-last-run-time)
  4655. (> (- time
  4656. org-diary-last-run-time)
  4657. 3))
  4658. (org-agenda-prepare-buffers files))
  4659. (setq org-diary-last-run-time time)
  4660. ;; If this is called during org-agenda, don't return any entries to
  4661. ;; the calendar. Org Agenda will list these entries itself.
  4662. (if org-disable-agenda-to-diary (setq files nil))
  4663. (while (setq file (pop files))
  4664. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4665. (setq results (append results rtn)))
  4666. (if results
  4667. (concat (org-agenda-finalize-entries results) "\n"))))
  4668. (autoload 'org-diary "org-agenda" "\
  4669. Return diary information from org files.
  4670. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4671. It accesses org files and extracts information from those files to be
  4672. listed in the diary. The function accepts arguments specifying what
  4673. items should be listed. For a list of arguments allowed here, see the
  4674. variable `org-agenda-entry-types'.
  4675. The call in the diary file should look like this:
  4676. &%%(org-diary) ~/path/to/some/orgfile.org
  4677. Use a separate line for each org file to check. Or, if you omit the file name,
  4678. all files listed in `org-agenda-files' will be checked automatically:
  4679. &%%(org-diary)
  4680. If you don't give any arguments (as in the example above), the default
  4681. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4682. So the example above may also be written as
  4683. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4684. The function expects the lisp variables `entry' and `date' to be provided
  4685. by the caller, because this is how the calendar works. Don't use this
  4686. function from a program - use `org-agenda-get-day-entries' instead.
  4687. \(fn &rest ARGS)" nil nil)
  4688. ;;; Agenda entry finders
  4689. (defun org-agenda-get-day-entries (file date &rest args)
  4690. "Does the work for `org-diary' and `org-agenda'.
  4691. FILE is the path to a file to be checked for entries. DATE is date like
  4692. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4693. which kind of entries should be extracted. For details about these, see
  4694. the documentation of `org-diary'."
  4695. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4696. (let* ((org-startup-folded nil)
  4697. (org-startup-align-all-tables nil)
  4698. (buffer (if (file-exists-p file)
  4699. (org-get-agenda-file-buffer file)
  4700. (error "No such file %s" file)))
  4701. arg results rtn deadline-results)
  4702. (if (not buffer)
  4703. ;; If file does not exist, make sure an error message ends up in diary
  4704. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4705. (with-current-buffer buffer
  4706. (unless (derived-mode-p 'org-mode)
  4707. (error "Agenda file %s is not in `org-mode'" file))
  4708. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4709. (let ((case-fold-search nil))
  4710. (save-excursion
  4711. (save-restriction
  4712. (if org-agenda-restrict
  4713. (narrow-to-region org-agenda-restrict-begin
  4714. org-agenda-restrict-end)
  4715. (widen))
  4716. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4717. (while (setq arg (pop args))
  4718. (cond
  4719. ((and (eq arg :todo)
  4720. (equal date (calendar-gregorian-from-absolute
  4721. (org-today))))
  4722. (setq rtn (org-agenda-get-todos))
  4723. (setq results (append results rtn)))
  4724. ((eq arg :timestamp)
  4725. (setq rtn (org-agenda-get-blocks))
  4726. (setq results (append results rtn))
  4727. (setq rtn (org-agenda-get-timestamps deadline-results))
  4728. (setq results (append results rtn)))
  4729. ((eq arg :sexp)
  4730. (setq rtn (org-agenda-get-sexps))
  4731. (setq results (append results rtn)))
  4732. ((eq arg :scheduled)
  4733. (setq rtn (org-agenda-get-scheduled deadline-results))
  4734. (setq results (append results rtn)))
  4735. ((eq arg :closed)
  4736. (setq rtn (org-agenda-get-progress))
  4737. (setq results (append results rtn)))
  4738. ((eq arg :deadline)
  4739. (setq rtn (org-agenda-get-deadlines))
  4740. (setq deadline-results (copy-sequence rtn))
  4741. (setq results (append results rtn))))))))
  4742. results))))
  4743. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4744. (defun org-agenda-get-todos ()
  4745. "Return the TODO information for agenda display."
  4746. (let* ((props (list 'face nil
  4747. 'done-face 'org-agenda-done
  4748. 'org-not-done-regexp org-not-done-regexp
  4749. 'org-todo-regexp org-todo-regexp
  4750. 'org-complex-heading-regexp org-complex-heading-regexp
  4751. 'mouse-face 'highlight
  4752. 'help-echo
  4753. (format "mouse-2 or RET jump to org file %s"
  4754. (abbreviate-file-name buffer-file-name))))
  4755. (regexp (format org-heading-keyword-regexp-format
  4756. (cond
  4757. ((and org-select-this-todo-keyword
  4758. (equal org-select-this-todo-keyword "*"))
  4759. org-todo-regexp)
  4760. (org-select-this-todo-keyword
  4761. (concat "\\("
  4762. (mapconcat 'identity
  4763. (org-split-string
  4764. org-select-this-todo-keyword
  4765. "|")
  4766. "\\|") "\\)"))
  4767. (t org-not-done-regexp))))
  4768. marker priority category category-pos tags todo-state
  4769. ee txt beg end)
  4770. (goto-char (point-min))
  4771. (while (re-search-forward regexp nil t)
  4772. (catch :skip
  4773. (save-match-data
  4774. (beginning-of-line)
  4775. (org-agenda-skip)
  4776. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4777. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4778. (goto-char (1+ beg))
  4779. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4780. (throw :skip nil)))
  4781. (goto-char (match-beginning 2))
  4782. (setq marker (org-agenda-new-marker (match-beginning 0))
  4783. category (org-get-category)
  4784. category-pos (get-text-property (point) 'org-category-position)
  4785. txt (org-trim
  4786. (buffer-substring (match-beginning 2) (match-end 0)))
  4787. tags (org-get-tags-at (point))
  4788. txt (org-agenda-format-item "" txt category tags t)
  4789. priority (1+ (org-get-priority txt))
  4790. todo-state (org-get-todo-state))
  4791. (org-add-props txt props
  4792. 'org-marker marker 'org-hd-marker marker
  4793. 'priority priority 'org-category category
  4794. 'org-category-position category-pos
  4795. 'type "todo" 'todo-state todo-state)
  4796. (push txt ee)
  4797. (if org-agenda-todo-list-sublevels
  4798. (goto-char (match-end 2))
  4799. (org-end-of-subtree 'invisible))))
  4800. (nreverse ee)))
  4801. (defun org-agenda-todo-custom-ignore-p (time n)
  4802. "Check whether timestamp is farther away than n number of days.
  4803. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4804. `org-agenda-todo-ignore-scheduled' or
  4805. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4806. (let ((days (org-days-to-time time)))
  4807. (if (>= n 0)
  4808. (>= days n)
  4809. (<= days n))))
  4810. ;;;###autoload
  4811. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4812. (&optional end)
  4813. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4814. (when (or org-agenda-todo-ignore-with-date
  4815. org-agenda-todo-ignore-scheduled
  4816. org-agenda-todo-ignore-deadlines
  4817. org-agenda-todo-ignore-timestamp)
  4818. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4819. (save-excursion
  4820. (or (and org-agenda-todo-ignore-with-date
  4821. (re-search-forward org-ts-regexp end t))
  4822. (and org-agenda-todo-ignore-scheduled
  4823. (re-search-forward org-scheduled-time-regexp end t)
  4824. (cond
  4825. ((eq org-agenda-todo-ignore-scheduled 'future)
  4826. (> (org-days-to-time (match-string 1)) 0))
  4827. ((eq org-agenda-todo-ignore-scheduled 'past)
  4828. (<= (org-days-to-time (match-string 1)) 0))
  4829. ((numberp org-agenda-todo-ignore-scheduled)
  4830. (org-agenda-todo-custom-ignore-p
  4831. (match-string 1) org-agenda-todo-ignore-scheduled))
  4832. (t)))
  4833. (and org-agenda-todo-ignore-deadlines
  4834. (re-search-forward org-deadline-time-regexp end t)
  4835. (cond
  4836. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4837. ((eq org-agenda-todo-ignore-deadlines 'far)
  4838. (not (org-deadline-close (match-string 1))))
  4839. ((eq org-agenda-todo-ignore-deadlines 'future)
  4840. (> (org-days-to-time (match-string 1)) 0))
  4841. ((eq org-agenda-todo-ignore-deadlines 'past)
  4842. (<= (org-days-to-time (match-string 1)) 0))
  4843. ((numberp org-agenda-todo-ignore-deadlines)
  4844. (org-agenda-todo-custom-ignore-p
  4845. (match-string 1) org-agenda-todo-ignore-deadlines))
  4846. (t (org-deadline-close (match-string 1)))))
  4847. (and org-agenda-todo-ignore-timestamp
  4848. (let ((buffer (current-buffer))
  4849. (regexp
  4850. (concat
  4851. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4852. (start (point)))
  4853. ;; Copy current buffer into a temporary one
  4854. (with-temp-buffer
  4855. (insert-buffer-substring buffer start end)
  4856. (goto-char (point-min))
  4857. ;; Delete SCHEDULED and DEADLINE items
  4858. (while (re-search-forward regexp end t)
  4859. (delete-region (match-beginning 0) (match-end 0)))
  4860. (goto-char (point-min))
  4861. ;; No search for timestamp left
  4862. (when (re-search-forward org-ts-regexp nil t)
  4863. (cond
  4864. ((eq org-agenda-todo-ignore-timestamp 'future)
  4865. (> (org-days-to-time (match-string 1)) 0))
  4866. ((eq org-agenda-todo-ignore-timestamp 'past)
  4867. (<= (org-days-to-time (match-string 1)) 0))
  4868. ((numberp org-agenda-todo-ignore-timestamp)
  4869. (org-agenda-todo-custom-ignore-p
  4870. (match-string 1) org-agenda-todo-ignore-timestamp))
  4871. (t))))))))))
  4872. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4873. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4874. \(fn &optional END)" nil nil)
  4875. (defconst org-agenda-no-heading-message
  4876. "No heading for this item in buffer or region.")
  4877. (defun org-agenda-get-timestamps (&optional deadline-results)
  4878. "Return the date stamp information for agenda display."
  4879. (let* ((props (list 'face 'org-agenda-calendar-event
  4880. 'org-not-done-regexp org-not-done-regexp
  4881. 'org-todo-regexp org-todo-regexp
  4882. 'org-complex-heading-regexp org-complex-heading-regexp
  4883. 'mouse-face 'highlight
  4884. 'help-echo
  4885. (format "mouse-2 or RET jump to org file %s"
  4886. (abbreviate-file-name buffer-file-name))))
  4887. (d1 (calendar-absolute-from-gregorian date))
  4888. mm
  4889. (deadline-position-alist
  4890. (mapcar (lambda (a) (and (setq mm (get-text-property
  4891. 0 'org-hd-marker a))
  4892. (cons (marker-position mm) a)))
  4893. deadline-results))
  4894. (remove-re org-ts-regexp)
  4895. (regexp
  4896. (concat
  4897. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4898. (regexp-quote
  4899. (substring
  4900. (format-time-string
  4901. (car org-time-stamp-formats)
  4902. (apply 'encode-time ; DATE bound by calendar
  4903. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4904. 1 11))
  4905. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4906. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4907. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4908. donep tmp priority category category-pos ee txt timestr tags
  4909. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  4910. (goto-char (point-min))
  4911. (while (setq end-of-match (re-search-forward regexp nil t))
  4912. (setq b0 (match-beginning 0)
  4913. b3 (match-beginning 3) e3 (match-end 3)
  4914. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4915. habitp (and (functionp 'org-is-habit-p) (org-is-habit-p))
  4916. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4917. (member todo-state
  4918. org-agenda-repeating-timestamp-show-all)))
  4919. (catch :skip
  4920. (and (org-at-date-range-p) (throw :skip nil))
  4921. (org-agenda-skip)
  4922. (if (and (match-end 1)
  4923. (not (= d1 (org-time-string-to-absolute
  4924. (match-string 1) d1 nil show-all
  4925. (current-buffer) b0))))
  4926. (throw :skip nil))
  4927. (if (and e3
  4928. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4929. (throw :skip nil))
  4930. (setq tmp (buffer-substring (max (point-min)
  4931. (- b0 org-ds-keyword-length))
  4932. b0)
  4933. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4934. inactivep (= (char-after b0) ?\[)
  4935. deadlinep (string-match org-deadline-regexp tmp)
  4936. scheduledp (string-match org-scheduled-regexp tmp)
  4937. closedp (and org-agenda-include-inactive-timestamps
  4938. (string-match org-closed-string tmp))
  4939. clockp (and org-agenda-include-inactive-timestamps
  4940. (or (string-match org-clock-string tmp)
  4941. (string-match "]-+\\'" tmp)))
  4942. warntime (org-entry-get (point) "APPT_WARNTIME")
  4943. donep (member todo-state org-done-keywords))
  4944. (if (or scheduledp deadlinep closedp clockp
  4945. (and donep org-agenda-skip-timestamp-if-done))
  4946. (throw :skip t))
  4947. (if (string-match ">" timestr)
  4948. ;; substring should only run to end of time stamp
  4949. (setq timestr (substring timestr 0 (match-end 0))))
  4950. (setq marker (org-agenda-new-marker b0)
  4951. category (org-get-category b0)
  4952. category-pos (get-text-property b0 'org-category-position))
  4953. (save-excursion
  4954. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4955. (setq txt org-agenda-no-heading-message)
  4956. (goto-char (match-beginning 0))
  4957. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4958. (assoc (point) deadline-position-alist))
  4959. (throw :skip nil))
  4960. (setq hdmarker (org-agenda-new-marker)
  4961. tags (org-get-tags-at))
  4962. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4963. (setq head (or (match-string 1) ""))
  4964. (setq txt (org-agenda-format-item
  4965. (if inactivep org-agenda-inactive-leader nil)
  4966. head category tags timestr
  4967. remove-re habitp)))
  4968. (setq priority (org-get-priority txt))
  4969. (org-add-props txt props
  4970. 'org-marker marker 'org-hd-marker hdmarker)
  4971. (org-add-props txt nil 'priority priority
  4972. 'org-category category 'date date
  4973. 'org-category-position category-pos
  4974. 'todo-state todo-state
  4975. 'warntime warntime
  4976. 'type "timestamp")
  4977. (push txt ee))
  4978. (if org-agenda-skip-additional-timestamps-same-entry
  4979. (outline-next-heading)
  4980. (goto-char end-of-match))))
  4981. (nreverse ee)))
  4982. (defun org-agenda-get-sexps ()
  4983. "Return the sexp information for agenda display."
  4984. (require 'diary-lib)
  4985. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4986. 'mouse-face 'highlight
  4987. 'help-echo
  4988. (format "mouse-2 or RET jump to org file %s"
  4989. (abbreviate-file-name buffer-file-name))))
  4990. (regexp "^&?%%(")
  4991. marker category extra category-pos ee txt tags entry
  4992. result beg b sexp sexp-entry todo-state warntime)
  4993. (goto-char (point-min))
  4994. (while (re-search-forward regexp nil t)
  4995. (catch :skip
  4996. (org-agenda-skip)
  4997. (setq beg (match-beginning 0))
  4998. (goto-char (1- (match-end 0)))
  4999. (setq b (point))
  5000. (forward-sexp 1)
  5001. (setq sexp (buffer-substring b (point)))
  5002. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5003. (org-trim (match-string 1))
  5004. ""))
  5005. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5006. (when result
  5007. (setq marker (org-agenda-new-marker beg)
  5008. category (org-get-category beg)
  5009. category-pos (get-text-property beg 'org-category-position)
  5010. tags (save-excursion (org-backward-heading-same-level 0)
  5011. (org-get-tags-at))
  5012. todo-state (org-get-todo-state)
  5013. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5014. (dolist (r (if (stringp result)
  5015. (list result)
  5016. result)) ;; we expect a list here
  5017. (when (and org-agenda-diary-sexp-prefix
  5018. (string-match org-agenda-diary-sexp-prefix r))
  5019. (setq extra (match-string 0 r)
  5020. r (replace-match "" nil nil r)))
  5021. (if (string-match "\\S-" r)
  5022. (setq txt r)
  5023. (setq txt "SEXP entry returned empty string"))
  5024. (setq txt (org-agenda-format-item
  5025. extra txt category tags 'time))
  5026. (org-add-props txt props 'org-marker marker)
  5027. (org-add-props txt nil
  5028. 'org-category category 'date date 'todo-state todo-state
  5029. 'org-category-position category-pos 'tags tags
  5030. 'type "sexp" 'warntime warntime)
  5031. (push txt ee)))))
  5032. (nreverse ee)))
  5033. ;; Calendar sanity: define some functions that are independent of
  5034. ;; `calendar-date-style'.
  5035. ;; Normally I would like to use ISO format when calling the diary functions,
  5036. ;; but to make sure we still have Emacs 22 compatibility we bind
  5037. ;; also `european-calendar-style' and use european format
  5038. (defun org-anniversary (year month day &optional mark)
  5039. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5040. (org-no-warnings
  5041. (let ((calendar-date-style 'european) (european-calendar-style t))
  5042. (diary-anniversary day month year mark))))
  5043. (defun org-cyclic (N year month day &optional mark)
  5044. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5045. (org-no-warnings
  5046. (let ((calendar-date-style 'european) (european-calendar-style t))
  5047. (diary-cyclic N day month year mark))))
  5048. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5049. "Like `diary-block', but with fixed (ISO) order of arguments."
  5050. (org-no-warnings
  5051. (let ((calendar-date-style 'european) (european-calendar-style t))
  5052. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5053. (defun org-date (year month day &optional mark)
  5054. "Like `diary-date', but with fixed (ISO) order of arguments."
  5055. (org-no-warnings
  5056. (let ((calendar-date-style 'european) (european-calendar-style t))
  5057. (diary-date day month year mark))))
  5058. (defalias 'org-float 'diary-float)
  5059. ;; Define the` org-class' function
  5060. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5061. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5062. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5063. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5064. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5065. `holidays', then any date that is known by the Emacs calendar to be a
  5066. holiday will also be skipped."
  5067. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5068. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5069. (d (calendar-absolute-from-gregorian date)))
  5070. (and
  5071. (<= date1 d)
  5072. (<= d date2)
  5073. (= (calendar-day-of-week date) dayname)
  5074. (or (not skip-weeks)
  5075. (progn
  5076. (require 'cal-iso)
  5077. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5078. (not (and (memq 'holidays skip-weeks)
  5079. (calendar-check-holidays date)))
  5080. entry)))
  5081. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5082. "Like `org-class', but honor `calendar-date-style'.
  5083. The order of the first 2 times 3 arguments depends on the variable
  5084. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5085. So for American calendars, give this as MONTH DAY YEAR, for European as
  5086. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5087. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5088. is any number of ISO weeks in the block period for which the item should
  5089. be skipped.
  5090. This function is here only for backward compatibility and it is deprecated,
  5091. please use `org-class' instead."
  5092. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5093. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5094. (org-class
  5095. (nth 2 date1) (car date1) (nth 1 date1)
  5096. (nth 2 date2) (car date2) (nth 1 date2)
  5097. dayname skip-weeks)))
  5098. (make-obsolete 'org-diary-class 'org-class "")
  5099. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5100. (defalias 'org-get-closed 'org-agenda-get-progress)
  5101. (defun org-agenda-get-progress ()
  5102. "Return the logged TODO entries for agenda display."
  5103. (let* ((props (list 'mouse-face 'highlight
  5104. 'org-not-done-regexp org-not-done-regexp
  5105. 'org-todo-regexp org-todo-regexp
  5106. 'org-complex-heading-regexp org-complex-heading-regexp
  5107. 'help-echo
  5108. (format "mouse-2 or RET jump to org file %s"
  5109. (abbreviate-file-name buffer-file-name))))
  5110. (items (if (consp org-agenda-show-log-scoped)
  5111. org-agenda-show-log-scoped
  5112. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5113. '(clock)
  5114. org-agenda-log-mode-items)))
  5115. (parts
  5116. (delq nil
  5117. (list
  5118. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5119. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5120. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5121. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5122. (error "`org-agenda-log-mode-items' is empty")))
  5123. (regexp (concat
  5124. "\\(" parts-re "\\)"
  5125. " *\\["
  5126. (regexp-quote
  5127. (substring
  5128. (format-time-string
  5129. (car org-time-stamp-formats)
  5130. (apply 'encode-time ; DATE bound by calendar
  5131. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5132. 1 11))))
  5133. (org-agenda-search-headline-for-time nil)
  5134. marker hdmarker priority category category-pos tags closedp
  5135. statep clockp state ee txt extra timestr rest clocked)
  5136. (goto-char (point-min))
  5137. (while (re-search-forward regexp nil t)
  5138. (catch :skip
  5139. (org-agenda-skip)
  5140. (setq marker (org-agenda-new-marker (match-beginning 0))
  5141. closedp (equal (match-string 1) org-closed-string)
  5142. statep (equal (string-to-char (match-string 1)) ?-)
  5143. clockp (not (or closedp statep))
  5144. state (and statep (match-string 2))
  5145. category (org-get-category (match-beginning 0))
  5146. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5147. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5148. (when (string-match "\\]" timestr)
  5149. ;; substring should only run to end of time stamp
  5150. (setq rest (substring timestr (match-end 0))
  5151. timestr (substring timestr 0 (match-end 0)))
  5152. (if (and (not closedp) (not statep)
  5153. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5154. rest))
  5155. (progn (setq timestr (concat (substring timestr 0 -1)
  5156. "-" (match-string 1 rest) "]"))
  5157. (setq clocked (match-string 2 rest)))
  5158. (setq clocked "-")))
  5159. (save-excursion
  5160. (setq extra
  5161. (cond
  5162. ((not org-agenda-log-mode-add-notes) nil)
  5163. (statep
  5164. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5165. (match-string 1)))
  5166. (clockp
  5167. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5168. (match-string 1)))))
  5169. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5170. (setq txt org-agenda-no-heading-message)
  5171. (goto-char (match-beginning 0))
  5172. (setq hdmarker (org-agenda-new-marker)
  5173. tags (org-get-tags-at))
  5174. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5175. (setq txt (match-string 1))
  5176. (when extra
  5177. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5178. (setq txt (concat (substring txt 0 (match-beginning 1))
  5179. " - " extra " " (match-string 2 txt)))
  5180. (setq txt (concat txt " - " extra))))
  5181. (setq txt (org-agenda-format-item
  5182. (cond
  5183. (closedp "Closed: ")
  5184. (statep (concat "State: (" state ")"))
  5185. (t (concat "Clocked: (" clocked ")")))
  5186. txt category tags timestr)))
  5187. (setq priority 100000)
  5188. (org-add-props txt props
  5189. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5190. 'priority priority 'org-category category
  5191. 'org-category-position category-pos
  5192. 'type "closed" 'date date
  5193. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5194. (push txt ee))
  5195. (goto-char (point-at-eol))))
  5196. (nreverse ee)))
  5197. (defun org-agenda-show-clocking-issues ()
  5198. "Add overlays, showing issues with clocking.
  5199. See also the user option `org-agenda-clock-consistency-checks'."
  5200. (interactive)
  5201. (let* ((pl org-agenda-clock-consistency-checks)
  5202. (re (concat "^[ \t]*"
  5203. org-clock-string
  5204. "[ \t]+"
  5205. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5206. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5207. (tlstart 0.)
  5208. (tlend 0.)
  5209. (maxtime (org-hh:mm-string-to-minutes
  5210. (or (plist-get pl :max-duration) "24:00")))
  5211. (mintime (org-hh:mm-string-to-minutes
  5212. (or (plist-get pl :min-duration) 0)))
  5213. (maxgap (org-hh:mm-string-to-minutes
  5214. ;; default 30:00 means never complain
  5215. (or (plist-get pl :max-gap) "30:00")))
  5216. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5217. (plist-get pl :gap-ok-around)))
  5218. (def-face (or (plist-get pl :default-face)
  5219. '((:background "DarkRed") (:foreground "white"))))
  5220. issue face m te ts dt ov)
  5221. (goto-char (point-min))
  5222. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5223. (setq issue nil face def-face)
  5224. (catch 'next
  5225. (setq m (org-get-at-bol 'org-marker)
  5226. te nil ts nil)
  5227. (unless (and m (markerp m))
  5228. (setq issue "No valid clock line") (throw 'next t))
  5229. (org-with-point-at m
  5230. (save-excursion
  5231. (goto-char (point-at-bol))
  5232. (unless (looking-at re)
  5233. (error "No valid Clock line")
  5234. (throw 'next t))
  5235. (unless (match-end 3)
  5236. (setq issue "No end time"
  5237. face (or (plist-get pl :no-end-time-face) face))
  5238. (throw 'next t))
  5239. (setq ts (match-string 1)
  5240. te (match-string 3)
  5241. ts (org-float-time
  5242. (apply 'encode-time (org-parse-time-string ts)))
  5243. te (org-float-time
  5244. (apply 'encode-time (org-parse-time-string te)))
  5245. dt (- te ts))))
  5246. (cond
  5247. ((> dt (* 60 maxtime))
  5248. ;; a very long clocking chunk
  5249. (setq issue (format "Clocking interval is very long: %s"
  5250. (org-minutes-to-hh:mm-string
  5251. (floor (/ (float dt) 60.))))
  5252. face (or (plist-get pl :long-face) face)))
  5253. ((< dt (* 60 mintime))
  5254. ;; a very short clocking chunk
  5255. (setq issue (format "Clocking interval is very short: %s"
  5256. (org-minutes-to-hh:mm-string
  5257. (floor (/ (float dt) 60.))))
  5258. face (or (plist-get pl :short-face) face)))
  5259. ((and (> tlend 0) (< ts tlend))
  5260. ;; Two clock entries are overlapping
  5261. (setq issue (format "Clocking overlap: %d minutes"
  5262. (/ (- tlend ts) 60))
  5263. face (or (plist-get pl :overlap-face) face)))
  5264. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5265. ;; There is a gap, lets see if we need to report it
  5266. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5267. (setq issue (format "Clocking gap: %d minutes"
  5268. (/ (- ts tlend) 60))
  5269. face (or (plist-get pl :gap-face) face))))
  5270. (t nil)))
  5271. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5272. (when issue
  5273. ;; OK, there was some issue, add an overlay to show the issue
  5274. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5275. (overlay-put ov 'before-string
  5276. (concat
  5277. (org-add-props
  5278. (format "%-43s" (concat " " issue))
  5279. nil
  5280. 'face face)
  5281. "\n"))
  5282. (overlay-put ov 'evaporate t)))))
  5283. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5284. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5285. (catch 'exit
  5286. (unless ok-list
  5287. ;; there are no OK times for gaps...
  5288. (throw 'exit nil))
  5289. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5290. ;; This is more than 24 hours, so it is OK.
  5291. ;; because we have at least one OK time, that must be in the
  5292. ;; 24 hour interval.
  5293. (throw 'exit t))
  5294. ;; We have a shorter gap.
  5295. ;; Now we have to get the minute of the day when these times are
  5296. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5297. (t2dec (decode-time (seconds-to-time t2)))
  5298. ;; compute the minute on the day
  5299. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5300. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5301. (when (< min2 min1)
  5302. ;; if min2 is smaller than min1, this means it is on the next day.
  5303. ;; Wrap it to after midnight.
  5304. (setq min2 (+ min2 1440)))
  5305. ;; Now check if any of the OK times is in the gap
  5306. (mapc (lambda (x)
  5307. ;; Wrap the time to after midnight if necessary
  5308. (if (< x min1) (setq x (+ x 1440)))
  5309. ;; Check if in interval
  5310. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5311. ok-list)
  5312. ;; Nope, this gap is not OK
  5313. nil)))
  5314. (defun org-agenda-get-deadlines ()
  5315. "Return the deadline information for agenda display."
  5316. (let* ((props (list 'mouse-face 'highlight
  5317. 'org-not-done-regexp org-not-done-regexp
  5318. 'org-todo-regexp org-todo-regexp
  5319. 'org-complex-heading-regexp org-complex-heading-regexp
  5320. 'help-echo
  5321. (format "mouse-2 or RET jump to org file %s"
  5322. (abbreviate-file-name buffer-file-name))))
  5323. (regexp org-deadline-time-regexp)
  5324. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5325. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5326. d2 diff dfrac wdays pos pos1 category category-pos
  5327. tags suppress-prewarning ee txt head face s todo-state
  5328. show-all upcomingp donep timestr warntime)
  5329. (goto-char (point-min))
  5330. (while (re-search-forward regexp nil t)
  5331. (setq suppress-prewarning nil)
  5332. (catch :skip
  5333. (org-agenda-skip)
  5334. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5335. (save-match-data
  5336. (string-match org-scheduled-time-regexp
  5337. (buffer-substring (point-at-bol)
  5338. (point-at-eol)))))
  5339. (setq suppress-prewarning
  5340. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5341. org-agenda-skip-deadline-prewarning-if-scheduled
  5342. 0)))
  5343. (setq s (match-string 1)
  5344. txt nil
  5345. pos (1- (match-beginning 1))
  5346. todo-state (save-match-data (org-get-todo-state))
  5347. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5348. (member todo-state
  5349. org-agenda-repeating-timestamp-show-all))
  5350. d2 (org-time-string-to-absolute
  5351. (match-string 1) d1 'past show-all
  5352. (current-buffer) pos)
  5353. diff (- d2 d1)
  5354. wdays (if suppress-prewarning
  5355. (let ((org-deadline-warning-days suppress-prewarning))
  5356. (org-get-wdays s))
  5357. (org-get-wdays s))
  5358. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5359. upcomingp (and todayp (> diff 0)))
  5360. ;; When to show a deadline in the calendar:
  5361. ;; If the expiration is within wdays warning time.
  5362. ;; Past-due deadlines are only shown on the current date
  5363. (if (and (or (and (<= diff wdays)
  5364. (and todayp (not org-agenda-only-exact-dates)))
  5365. (= diff 0)))
  5366. (save-excursion
  5367. ;; (setq todo-state (org-get-todo-state))
  5368. (setq donep (member todo-state org-done-keywords))
  5369. (if (and donep
  5370. (or org-agenda-skip-deadline-if-done
  5371. (not (= diff 0))))
  5372. (setq txt nil)
  5373. (setq category (org-get-category)
  5374. warntime (org-entry-get (point) "APPT_WARNTIME")
  5375. category-pos (get-text-property (point) 'org-category-position))
  5376. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5377. (setq txt org-agenda-no-heading-message)
  5378. (goto-char (match-end 0))
  5379. (setq pos1 (match-beginning 0))
  5380. (setq tags (org-get-tags-at pos1))
  5381. (setq head (buffer-substring-no-properties
  5382. (point)
  5383. (progn (skip-chars-forward "^\r\n")
  5384. (point))))
  5385. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5386. (setq timestr
  5387. (concat (substring s (match-beginning 1)) " "))
  5388. (setq timestr 'time))
  5389. (setq txt (org-agenda-format-item
  5390. (if (= diff 0)
  5391. (car org-agenda-deadline-leaders)
  5392. (if (functionp
  5393. (nth 1 org-agenda-deadline-leaders))
  5394. (funcall
  5395. (nth 1 org-agenda-deadline-leaders)
  5396. diff date)
  5397. (format (nth 1 org-agenda-deadline-leaders)
  5398. diff)))
  5399. head category tags
  5400. (if (not (= diff 0)) nil timestr)))))
  5401. (when txt
  5402. (setq face (org-agenda-deadline-face dfrac))
  5403. (org-add-props txt props
  5404. 'org-marker (org-agenda-new-marker pos)
  5405. 'warntime warntime
  5406. 'org-hd-marker (org-agenda-new-marker pos1)
  5407. 'priority (+ (- diff)
  5408. (org-get-priority txt))
  5409. 'org-category category
  5410. 'org-category-position category-pos
  5411. 'todo-state todo-state
  5412. 'type (if upcomingp "upcoming-deadline" "deadline")
  5413. 'date (if upcomingp date d2)
  5414. 'face (if donep 'org-agenda-done face)
  5415. 'undone-face face 'done-face 'org-agenda-done)
  5416. (push txt ee))))))
  5417. (nreverse ee)))
  5418. (defun org-agenda-deadline-face (fraction)
  5419. "Return the face to displaying a deadline item.
  5420. FRACTION is what fraction of the head-warning time has passed."
  5421. (let ((faces org-agenda-deadline-faces) f)
  5422. (catch 'exit
  5423. (while (setq f (pop faces))
  5424. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5425. (defun org-agenda-get-scheduled (&optional deadline-results)
  5426. "Return the scheduled information for agenda display."
  5427. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5428. 'org-todo-regexp org-todo-regexp
  5429. 'org-complex-heading-regexp org-complex-heading-regexp
  5430. 'done-face 'org-agenda-done
  5431. 'mouse-face 'highlight
  5432. 'help-echo
  5433. (format "mouse-2 or RET jump to org file %s"
  5434. (abbreviate-file-name buffer-file-name))))
  5435. (regexp org-scheduled-time-regexp)
  5436. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5437. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5438. mm
  5439. (deadline-position-alist
  5440. (mapcar (lambda (a) (and (setq mm (get-text-property
  5441. 0 'org-hd-marker a))
  5442. (cons (marker-position mm) a)))
  5443. deadline-results))
  5444. d2 diff pos pos1 category category-pos tags donep
  5445. ee txt head pastschedp todo-state face timestr s habitp show-all
  5446. did-habit-check-p warntime)
  5447. (goto-char (point-min))
  5448. (while (re-search-forward regexp nil t)
  5449. (catch :skip
  5450. (org-agenda-skip)
  5451. (setq s (match-string 1)
  5452. txt nil
  5453. pos (1- (match-beginning 1))
  5454. todo-state (save-match-data (org-get-todo-state))
  5455. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5456. (member todo-state
  5457. org-agenda-repeating-timestamp-show-all))
  5458. d2 (org-time-string-to-absolute
  5459. (match-string 1) d1 'past show-all
  5460. (current-buffer) pos)
  5461. diff (- d2 d1)
  5462. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5463. (setq pastschedp (and todayp (< diff 0)))
  5464. (setq did-habit-check-p nil)
  5465. ;; When to show a scheduled item in the calendar:
  5466. ;; If it is on or past the date.
  5467. (when (or (and (< diff 0)
  5468. (< (abs diff) org-scheduled-past-days)
  5469. (and todayp (not org-agenda-only-exact-dates)))
  5470. (= diff 0)
  5471. ;; org-is-habit-p uses org-entry-get, which is expansive
  5472. ;; so we go extra mile to only call it once
  5473. (and todayp
  5474. (boundp 'org-habit-show-all-today)
  5475. org-habit-show-all-today
  5476. (setq did-habit-check-p t)
  5477. (setq habitp (and (functionp 'org-is-habit-p)
  5478. (org-is-habit-p)))))
  5479. (save-excursion
  5480. (setq donep (member todo-state org-done-keywords))
  5481. (if (and donep
  5482. (or org-agenda-skip-scheduled-if-done
  5483. (not (= diff 0))
  5484. (and (functionp 'org-is-habit-p)
  5485. (org-is-habit-p))))
  5486. (setq txt nil)
  5487. (setq habitp (if did-habit-check-p habitp
  5488. (and (functionp 'org-is-habit-p)
  5489. (org-is-habit-p))))
  5490. (setq category (org-get-category)
  5491. category-pos (get-text-property (point) 'org-category-position))
  5492. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5493. (setq txt org-agenda-no-heading-message)
  5494. (goto-char (match-end 0))
  5495. (setq pos1 (match-beginning 0))
  5496. (if habitp
  5497. (if (or (not org-habit-show-habits)
  5498. (and (not todayp)
  5499. (boundp 'org-habit-show-habits-only-for-today)
  5500. org-habit-show-habits-only-for-today))
  5501. (throw :skip nil))
  5502. (if (and
  5503. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5504. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5505. pastschedp))
  5506. (setq mm (assoc pos1 deadline-position-alist)))
  5507. (throw :skip nil)))
  5508. (setq tags (org-get-tags-at))
  5509. (setq head (buffer-substring-no-properties
  5510. (point)
  5511. (progn (skip-chars-forward "^\r\n") (point))))
  5512. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5513. (setq timestr
  5514. (concat (substring s (match-beginning 1)) " "))
  5515. (setq timestr 'time))
  5516. (setq txt (org-agenda-format-item
  5517. (if (= diff 0)
  5518. (car org-agenda-scheduled-leaders)
  5519. (format (nth 1 org-agenda-scheduled-leaders)
  5520. (- 1 diff)))
  5521. head category tags
  5522. (if (not (= diff 0)) nil timestr)
  5523. nil habitp))))
  5524. (when txt
  5525. (setq face
  5526. (cond
  5527. ((and (not habitp) pastschedp)
  5528. 'org-scheduled-previously)
  5529. (todayp 'org-scheduled-today)
  5530. (t 'org-scheduled))
  5531. habitp (and habitp (org-habit-parse-todo)))
  5532. (org-add-props txt props
  5533. 'undone-face face
  5534. 'face (if donep 'org-agenda-done face)
  5535. 'org-marker (org-agenda-new-marker pos)
  5536. 'org-hd-marker (org-agenda-new-marker pos1)
  5537. 'type (if pastschedp "past-scheduled" "scheduled")
  5538. 'date (if pastschedp d2 date)
  5539. 'warntime warntime
  5540. 'priority (if habitp
  5541. (org-habit-get-priority habitp)
  5542. (+ 94 (- 5 diff) (org-get-priority txt)))
  5543. 'org-category category
  5544. 'category-position category-pos
  5545. 'org-habit-p habitp
  5546. 'todo-state todo-state)
  5547. (push txt ee))))))
  5548. (nreverse ee)))
  5549. (defun org-agenda-get-blocks ()
  5550. "Return the date-range information for agenda display."
  5551. (let* ((props (list 'face nil
  5552. 'org-not-done-regexp org-not-done-regexp
  5553. 'org-todo-regexp org-todo-regexp
  5554. 'org-complex-heading-regexp org-complex-heading-regexp
  5555. 'mouse-face 'highlight
  5556. 'help-echo
  5557. (format "mouse-2 or RET jump to org file %s"
  5558. (abbreviate-file-name buffer-file-name))))
  5559. (regexp org-tr-regexp)
  5560. (d0 (calendar-absolute-from-gregorian date))
  5561. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5562. todo-state tags pos head donep)
  5563. (goto-char (point-min))
  5564. (while (re-search-forward regexp nil t)
  5565. (catch :skip
  5566. (org-agenda-skip)
  5567. (setq pos (point))
  5568. (let ((start-time (match-string 1))
  5569. (end-time (match-string 2)))
  5570. (setq s1 (match-string 1)
  5571. s2 (match-string 2)
  5572. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5573. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5574. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5575. ;; Only allow days between the limits, because the normal
  5576. ;; date stamps will catch the limits.
  5577. (save-excursion
  5578. (setq todo-state (org-get-todo-state))
  5579. (setq donep (member todo-state org-done-keywords))
  5580. (if (and donep org-agenda-skip-timestamp-if-done)
  5581. (throw :skip t))
  5582. (setq marker (org-agenda-new-marker (point)))
  5583. (setq category (org-get-category)
  5584. category-pos (get-text-property (point) 'org-category-position))
  5585. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5586. (setq txt org-agenda-no-heading-message)
  5587. (goto-char (match-beginning 0))
  5588. (setq hdmarker (org-agenda-new-marker (point)))
  5589. (setq tags (org-get-tags-at))
  5590. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5591. (setq head (match-string 1))
  5592. (let ((remove-re
  5593. (if org-agenda-remove-timeranges-from-blocks
  5594. (concat
  5595. "<" (regexp-quote s1) ".*?>"
  5596. "--"
  5597. "<" (regexp-quote s2) ".*?>")
  5598. nil)))
  5599. (setq txt (org-agenda-format-item
  5600. (format
  5601. (nth (if (= d1 d2) 0 1)
  5602. org-agenda-timerange-leaders)
  5603. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5604. head category tags
  5605. (cond ((and (= d1 d0) (= d2 d0))
  5606. (concat "<" start-time ">--<" end-time ">"))
  5607. ((= d1 d0)
  5608. (concat "<" start-time ">"))
  5609. ((= d2 d0)
  5610. (concat "<" end-time ">")))
  5611. remove-re))))
  5612. (org-add-props txt props
  5613. 'org-marker marker 'org-hd-marker hdmarker
  5614. 'type "block" 'date date
  5615. 'todo-state todo-state
  5616. 'priority (org-get-priority txt) 'org-category category
  5617. 'org-category-position category-pos)
  5618. (push txt ee))))
  5619. (goto-char pos)))
  5620. ;; Sort the entries by expiration date.
  5621. (nreverse ee)))
  5622. ;;; Agenda presentation and sorting
  5623. (defvar org-prefix-has-time nil
  5624. "A flag, set by `org-compile-prefix-format'.
  5625. The flag is set if the currently compiled format contains a `%t'.")
  5626. (defvar org-prefix-has-tag nil
  5627. "A flag, set by `org-compile-prefix-format'.
  5628. The flag is set if the currently compiled format contains a `%T'.")
  5629. (defvar org-prefix-has-effort nil
  5630. "A flag, set by `org-compile-prefix-format'.
  5631. The flag is set if the currently compiled format contains a `%e'.")
  5632. (defvar org-prefix-category-length nil
  5633. "Used by `org-compile-prefix-format' to remember the category field width.")
  5634. (defvar org-prefix-category-max-length nil
  5635. "Used by `org-compile-prefix-format' to remember the category field width.")
  5636. (defun org-agenda-get-category-icon (category)
  5637. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5638. (dolist (entry org-agenda-category-icon-alist)
  5639. (when (org-string-match-p (car entry) category)
  5640. (if (listp (cadr entry))
  5641. (return (cadr entry))
  5642. (return (apply 'create-image (cdr entry)))))))
  5643. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5644. remove-re habitp)
  5645. "Format TXT to be inserted into the agenda buffer.
  5646. In particular, it adds the prefix and corresponding text properties. EXTRA
  5647. must be a string and replaces the `%s' specifier in the prefix format.
  5648. CATEGORY (string, symbol or nil) may be used to overrule the default
  5649. category taken from local variable or file name. It will replace the `%c'
  5650. specifier in the format. DOTIME, when non-nil, indicates that a
  5651. time-of-day should be extracted from TXT for sorting of this entry, and for
  5652. the `%t' specifier in the format. When DOTIME is a string, this string is
  5653. searched for a time before TXT is. TAGS can be the tags of the headline.
  5654. Any match of REMOVE-RE will be removed from TXT."
  5655. ;; We keep the org-prefix-* variable values along with a compiled
  5656. ;; formatter, so that multiple agendas existing at the same time, do
  5657. ;; not step on each other toes.
  5658. ;;
  5659. ;; It was inconvenient to make these variables buffer local in
  5660. ;; Agenda buffers, because this function expects to be called with
  5661. ;; the buffer where item comes from being current, and not agenda
  5662. ;; buffer
  5663. (let* ((bindings (car org-prefix-format-compiled))
  5664. (formatter (cadr org-prefix-format-compiled)))
  5665. (loop for (var value) in bindings
  5666. do (set var value))
  5667. (save-match-data
  5668. ;; Diary entries sometimes have extra whitespace at the beginning
  5669. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5670. ;; Fix the tags part in txt
  5671. (setq txt (org-agenda-fix-displayed-tags
  5672. txt tags
  5673. org-agenda-show-inherited-tags
  5674. org-agenda-hide-tags-regexp))
  5675. (let* ((category (or category
  5676. (if (stringp org-category)
  5677. org-category
  5678. (and org-category (symbol-name org-category)))
  5679. (if buffer-file-name
  5680. (file-name-sans-extension
  5681. (file-name-nondirectory buffer-file-name))
  5682. "")))
  5683. (category-icon (org-agenda-get-category-icon category))
  5684. (category-icon (if category-icon
  5685. (propertize " " 'display category-icon)
  5686. ""))
  5687. ;; time, tag, effort are needed for the eval of the prefix format
  5688. (tag (if tags (nth (1- (length tags)) tags) ""))
  5689. time effort neffort
  5690. (ts (if dotime (concat
  5691. (if (stringp dotime) dotime "")
  5692. (and org-agenda-search-headline-for-time txt))))
  5693. (time-of-day (and dotime (org-get-time-of-day ts)))
  5694. stamp plain s0 s1 s2 rtn srp l
  5695. duration thecategory)
  5696. (and (derived-mode-p 'org-mode) buffer-file-name
  5697. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5698. (when (and dotime time-of-day)
  5699. ;; Extract starting and ending time and move them to prefix
  5700. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5701. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5702. (setq s0 (match-string 0 ts)
  5703. srp (and stamp (match-end 3))
  5704. s1 (match-string (if plain 1 2) ts)
  5705. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5706. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5707. ;; them, we might want to remove them there to avoid duplication.
  5708. ;; The user can turn this off with a variable.
  5709. (if (and org-prefix-has-time
  5710. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5711. (string-match (concat (regexp-quote s0) " *") txt)
  5712. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5713. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5714. (= (match-beginning 0) 0)
  5715. t))
  5716. (setq txt (replace-match "" nil nil txt))))
  5717. ;; Normalize the time(s) to 24 hour
  5718. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5719. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5720. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5721. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5722. (setq s2
  5723. (org-minutes-to-hh:mm-string
  5724. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5725. ;; Compute the duration
  5726. (when s2
  5727. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5728. (org-hh:mm-string-to-minutes s1)))))
  5729. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5730. txt)
  5731. ;; Tags are in the string
  5732. (if (or (eq org-agenda-remove-tags t)
  5733. (and org-agenda-remove-tags
  5734. org-prefix-has-tag))
  5735. (setq txt (replace-match "" t t txt))
  5736. (setq txt (replace-match
  5737. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5738. (match-string 2 txt))
  5739. t t txt))))
  5740. (when (derived-mode-p 'org-mode)
  5741. (setq effort
  5742. (condition-case nil
  5743. (org-get-effort
  5744. (or (get-text-property 0 'org-hd-marker txt)
  5745. (get-text-property 0 'org-marker txt)))
  5746. (error nil)))
  5747. (when effort
  5748. (setq neffort (org-duration-string-to-minutes effort)
  5749. effort (setq effort (concat "[" effort "]")))))
  5750. ;; prevent erroring out with %e format when there is no effort
  5751. (or effort (setq effort ""))
  5752. (when remove-re
  5753. (while (string-match remove-re txt)
  5754. (setq txt (replace-match "" t t txt))))
  5755. ;; Set org-heading property on `txt' to mark the start of the
  5756. ;; heading.
  5757. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5758. ;; Prepare the variables needed in the eval of the compiled format
  5759. (setq time (cond (s2 (concat
  5760. (org-agenda-time-of-day-to-ampm-maybe s1)
  5761. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5762. (if org-agenda-timegrid-use-ampm " ")))
  5763. (s1 (concat
  5764. (org-agenda-time-of-day-to-ampm-maybe s1)
  5765. (if org-agenda-timegrid-use-ampm
  5766. "........ "
  5767. "......")))
  5768. (t ""))
  5769. extra (or (and (not habitp) extra) "")
  5770. category (if (symbolp category) (symbol-name category) category)
  5771. thecategory (copy-sequence category))
  5772. (if (string-match org-bracket-link-regexp category)
  5773. (progn
  5774. (setq l (if (match-end 3)
  5775. (- (match-end 3) (match-beginning 3))
  5776. (- (match-end 1) (match-beginning 1))))
  5777. (when (< l (or org-prefix-category-length 0))
  5778. (setq category (copy-sequence category))
  5779. (org-add-props category nil
  5780. 'extra-space (make-string
  5781. (- org-prefix-category-length l 1) ?\ ))))
  5782. (if (and org-prefix-category-max-length
  5783. (>= (length category) org-prefix-category-max-length))
  5784. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5785. ;; Evaluate the compiled format
  5786. (setq rtn (concat (eval formatter) txt))
  5787. ;; And finally add the text properties
  5788. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5789. (org-add-props rtn nil
  5790. 'org-category (if thecategory (downcase thecategory) category)
  5791. 'tags (mapcar 'org-downcase-keep-props tags)
  5792. 'org-highest-priority org-highest-priority
  5793. 'org-lowest-priority org-lowest-priority
  5794. 'time-of-day time-of-day
  5795. 'duration duration
  5796. 'effort effort
  5797. 'effort-minutes neffort
  5798. 'txt txt
  5799. 'time time
  5800. 'extra extra
  5801. 'format org-prefix-format-compiled
  5802. 'dotime dotime)))))
  5803. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5804. "Remove tags string from TXT, and add a modified list of tags.
  5805. The modified list may contain inherited tags, and tags matched by
  5806. `org-agenda-hide-tags-regexp' will be removed."
  5807. (when (or add-inherited hide-re)
  5808. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5809. (setq txt (substring txt 0 (match-beginning 0))))
  5810. (setq tags
  5811. (delq nil
  5812. (mapcar (lambda (tg)
  5813. (if (or (and hide-re (string-match hide-re tg))
  5814. (and (not add-inherited)
  5815. (get-text-property 0 'inherited tg)))
  5816. nil
  5817. tg))
  5818. tags)))
  5819. (when tags
  5820. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5821. i)
  5822. (setq txt (concat txt " :"
  5823. (mapconcat
  5824. (lambda (x)
  5825. (setq i (get-text-property 0 'inherited x))
  5826. (if (and have-i (not i))
  5827. (progn
  5828. (setq have-i nil)
  5829. (concat ":" x))
  5830. x))
  5831. tags ":")
  5832. (if have-i "::" ":"))))))
  5833. txt)
  5834. (defun org-downcase-keep-props (s)
  5835. (let ((props (text-properties-at 0 s)))
  5836. (setq s (downcase s))
  5837. (add-text-properties 0 (length s) props s)
  5838. s))
  5839. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5840. (defvar org-agenda-sorting-strategy-selected nil)
  5841. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5842. (catch 'exit
  5843. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5844. ((and todayp (member 'today (car org-agenda-time-grid))))
  5845. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5846. ((member 'weekly (car org-agenda-time-grid)))
  5847. (t (throw 'exit list)))
  5848. (let* ((have (delq nil (mapcar
  5849. (lambda (x) (get-text-property 1 'time-of-day x))
  5850. list)))
  5851. (string (nth 1 org-agenda-time-grid))
  5852. (gridtimes (nth 2 org-agenda-time-grid))
  5853. (req (car org-agenda-time-grid))
  5854. (remove (member 'remove-match req))
  5855. new time)
  5856. (if (and (member 'require-timed req) (not have))
  5857. ;; don't show empty grid
  5858. (throw 'exit list))
  5859. (while (setq time (pop gridtimes))
  5860. (unless (and remove (member time have))
  5861. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5862. (push (org-agenda-format-item
  5863. nil string "" nil
  5864. (concat (substring time 0 -2) ":" (substring time -2)))
  5865. new)
  5866. (put-text-property
  5867. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5868. (when (and todayp org-agenda-show-current-time-in-grid)
  5869. (push (org-agenda-format-item
  5870. nil
  5871. org-agenda-current-time-string
  5872. "" nil
  5873. (format-time-string "%H:%M "))
  5874. new)
  5875. (put-text-property
  5876. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5877. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5878. (append new list)
  5879. (append list new)))))
  5880. (defun org-compile-prefix-format (key)
  5881. "Compile the prefix format into a Lisp form that can be evaluated.
  5882. The resulting form and associated variable bindings is returned
  5883. and stored in the variable `org-prefix-format-compiled'."
  5884. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5885. org-prefix-category-length nil
  5886. org-prefix-has-effort nil)
  5887. (let ((s (cond
  5888. ((stringp org-agenda-prefix-format)
  5889. org-agenda-prefix-format)
  5890. ((assq key org-agenda-prefix-format)
  5891. (cdr (assq key org-agenda-prefix-format)))
  5892. (t " %-12:c%?-12t% s")))
  5893. (start 0)
  5894. varform vars var e c f opt)
  5895. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5896. s start)
  5897. (setq var (or (cdr (assoc (match-string 4 s)
  5898. '(("c" . category) ("t" . time) ("s" . extra)
  5899. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5900. 'eval)
  5901. c (or (match-string 3 s) "")
  5902. opt (match-beginning 1)
  5903. start (1+ (match-beginning 0)))
  5904. (if (equal var 'time) (setq org-prefix-has-time t))
  5905. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5906. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5907. (setq f (concat "%" (match-string 2 s) "s"))
  5908. (when (equal var 'category)
  5909. (setq org-prefix-category-length
  5910. (floor (abs (string-to-number (match-string 2 s)))))
  5911. (setq org-prefix-category-max-length
  5912. (let ((x (match-string 2 s)))
  5913. (save-match-data
  5914. (if (string-match "\\.[0-9]+" x)
  5915. (string-to-number (substring (match-string 0 x) 1)))))))
  5916. (if (eq var 'eval)
  5917. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5918. (if opt
  5919. (setq varform
  5920. `(if (equal "" ,var)
  5921. ""
  5922. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5923. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5924. (setq s (replace-match "%s" t nil s))
  5925. (push varform vars))
  5926. (setq vars (nreverse vars))
  5927. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5928. (setq org-prefix-format-compiled
  5929. (list
  5930. `((org-prefix-has-time ,org-prefix-has-time)
  5931. (org-prefix-has-tag ,org-prefix-has-tag)
  5932. (org-prefix-category-length ,org-prefix-category-length)
  5933. (org-prefix-has-effort ,org-prefix-has-effort))
  5934. `(format ,s ,@vars))))))
  5935. (defun org-set-sorting-strategy (key)
  5936. (if (symbolp (car org-agenda-sorting-strategy))
  5937. ;; the old format
  5938. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5939. (setq org-agenda-sorting-strategy-selected
  5940. (or (cdr (assq key org-agenda-sorting-strategy))
  5941. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5942. '(time-up category-keep priority-down)))))
  5943. (defun org-get-time-of-day (s &optional string mod24)
  5944. "Check string S for a time of day.
  5945. If found, return it as a military time number between 0 and 2400.
  5946. If not found, return nil.
  5947. The optional STRING argument forces conversion into a 5 character wide string
  5948. HH:MM."
  5949. (save-match-data
  5950. (when
  5951. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5952. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5953. (let* ((h (string-to-number (match-string 1 s)))
  5954. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5955. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5956. (am-p (equal ampm "am"))
  5957. (h1 (cond ((not ampm) h)
  5958. ((= h 12) (if am-p 0 12))
  5959. (t (+ h (if am-p 0 12)))))
  5960. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5961. (mod h1 24) h1))
  5962. (t0 (+ (* 100 h2) m))
  5963. (t1 (concat (if (>= h1 24) "+" " ")
  5964. (if (and org-agenda-time-leading-zero
  5965. (< t0 1000)) "0" "")
  5966. (if (< t0 100) "0" "")
  5967. (if (< t0 10) "0" "")
  5968. (int-to-string t0))))
  5969. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5970. (defvar org-agenda-before-sorting-filter-function nil
  5971. "Function to be applied to agenda items prior to sorting.
  5972. Prior to sorting also means just before they are inserted into the agenda.
  5973. To aid sorting, you may revisit the original entries and add more text
  5974. properties which will later be used by the sorting functions.
  5975. The function should take a string argument, an agenda line.
  5976. It has access to the text properties in that line, which contain among
  5977. other things, the property `org-hd-marker' that points to the entry
  5978. where the line comes from. Note that not all lines going into the agenda
  5979. have this property, only most.
  5980. The function should return the modified string. It is probably best
  5981. to ONLY change text properties.
  5982. You can also use this function as a filter, by returning nil for lines
  5983. you don't want to have in the agenda at all. For this application, you
  5984. could bind the variable in the options section of a custom command.")
  5985. (defun org-agenda-finalize-entries (list &optional nosort)
  5986. "Sort and concatenate the agenda items."
  5987. (setq list (mapcar 'org-agenda-highlight-todo list))
  5988. (if nosort
  5989. list
  5990. (when org-agenda-before-sorting-filter-function
  5991. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5992. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5993. (defun org-agenda-highlight-todo (x)
  5994. (let ((org-done-keywords org-done-keywords-for-agenda)
  5995. (case-fold-search nil)
  5996. re)
  5997. (if (eq x 'line)
  5998. (save-excursion
  5999. (beginning-of-line 1)
  6000. (setq re (org-get-at-bol 'org-todo-regexp))
  6001. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6002. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6003. (add-text-properties (match-beginning 0) (match-end 1)
  6004. (list 'face (org-get-todo-face 1)))
  6005. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6006. (delete-region (match-beginning 1) (1- (match-end 0)))
  6007. (goto-char (match-beginning 1))
  6008. (insert (format org-agenda-todo-keyword-format s)))))
  6009. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6010. (setq re (get-text-property 0 'org-todo-regexp x))
  6011. (when (and re
  6012. ;; Test `pl' because if there's no heading content,
  6013. ;; there's no point matching to highlight. Note
  6014. ;; that if we didn't test `pl' first, and there
  6015. ;; happened to be no keyword from `org-todo-regexp'
  6016. ;; on this heading line, then the `equal' comparison
  6017. ;; afterwards would spuriously succeed in the case
  6018. ;; where `pl' is nil -- causing an args-out-of-range
  6019. ;; error when we try to add text properties to text
  6020. ;; that isn't there.
  6021. pl
  6022. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6023. x pl) pl))
  6024. (add-text-properties
  6025. (or (match-end 1) (match-end 0)) (match-end 0)
  6026. (list 'face (org-get-todo-face (match-string 2 x)))
  6027. x)
  6028. (when (match-end 1)
  6029. (setq x (concat (substring x 0 (match-end 1))
  6030. (format org-agenda-todo-keyword-format
  6031. (match-string 2 x))
  6032. (org-add-props " " (text-properties-at 0 x))
  6033. (substring x (match-end 3)))))))
  6034. x)))
  6035. (defsubst org-cmp-priority (a b)
  6036. "Compare the priorities of string A and B."
  6037. (let ((pa (or (get-text-property 1 'priority a) 0))
  6038. (pb (or (get-text-property 1 'priority b) 0)))
  6039. (cond ((> pa pb) +1)
  6040. ((< pa pb) -1))))
  6041. (defsubst org-cmp-effort (a b)
  6042. "Compare the effort values of string A and B."
  6043. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6044. (ea (or (get-text-property 1 'effort-minutes a) def))
  6045. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6046. (cond ((> ea eb) +1)
  6047. ((< ea eb) -1))))
  6048. (defsubst org-cmp-category (a b)
  6049. "Compare the string values of categories of strings A and B."
  6050. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6051. (cb (or (get-text-property 1 'org-category b) "")))
  6052. (cond ((string-lessp ca cb) -1)
  6053. ((string-lessp cb ca) +1))))
  6054. (defsubst org-cmp-todo-state (a b)
  6055. "Compare the todo states of strings A and B."
  6056. (let* ((ma (or (get-text-property 1 'org-marker a)
  6057. (get-text-property 1 'org-hd-marker a)))
  6058. (mb (or (get-text-property 1 'org-marker b)
  6059. (get-text-property 1 'org-hd-marker b)))
  6060. (fa (and ma (marker-buffer ma)))
  6061. (fb (and mb (marker-buffer mb)))
  6062. (todo-kwds
  6063. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6064. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6065. (ta (or (get-text-property 1 'todo-state a) ""))
  6066. (tb (or (get-text-property 1 'todo-state b) ""))
  6067. (la (- (length (member ta todo-kwds))))
  6068. (lb (- (length (member tb todo-kwds))))
  6069. (donepa (member ta org-done-keywords-for-agenda))
  6070. (donepb (member tb org-done-keywords-for-agenda)))
  6071. (cond ((and donepa (not donepb)) -1)
  6072. ((and (not donepa) donepb) +1)
  6073. ((< la lb) -1)
  6074. ((< lb la) +1))))
  6075. (defsubst org-cmp-alpha (a b)
  6076. "Compare the headlines, alphabetically."
  6077. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6078. (plb (text-property-any 0 (length b) 'org-heading t b))
  6079. (ta (and pla (substring a pla)))
  6080. (tb (and plb (substring b plb))))
  6081. (when pla
  6082. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6083. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6084. (setq ta (substring ta (match-end 0))))
  6085. (setq ta (downcase ta)))
  6086. (when plb
  6087. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6088. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6089. (setq tb (substring tb (match-end 0))))
  6090. (setq tb (downcase tb)))
  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-tag (a b)
  6096. "Compare the string values of the first tags of A and B."
  6097. (let ((ta (car (last (get-text-property 1 'tags a))))
  6098. (tb (car (last (get-text-property 1 'tags b)))))
  6099. (cond ((not ta) +1)
  6100. ((not tb) -1)
  6101. ((string-lessp ta tb) -1)
  6102. ((string-lessp tb ta) +1))))
  6103. (defsubst org-cmp-time (a b)
  6104. "Compare the time-of-day values of strings A and B."
  6105. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6106. (ta (or (get-text-property 1 'time-of-day a) def))
  6107. (tb (or (get-text-property 1 'time-of-day b) def)))
  6108. (cond ((< ta tb) -1)
  6109. ((< tb ta) +1))))
  6110. (defsubst org-cmp-habit-p (a b)
  6111. "Compare the todo states of strings A and B."
  6112. (let ((ha (get-text-property 1 'org-habit-p a))
  6113. (hb (get-text-property 1 'org-habit-p b)))
  6114. (cond ((and ha (not hb)) -1)
  6115. ((and (not ha) hb) +1))))
  6116. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6117. (defun org-entries-lessp (a b)
  6118. "Predicate for sorting agenda entries."
  6119. ;; The following variables will be used when the form is evaluated.
  6120. ;; So even though the compiler complains, keep them.
  6121. (let* ((ss org-agenda-sorting-strategy-selected)
  6122. (time-up (and (org-em 'time-up 'time-down ss)
  6123. (org-cmp-time a b)))
  6124. (time-down (if time-up (- time-up) nil))
  6125. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6126. (org-cmp-priority a b)))
  6127. (priority-down (if priority-up (- priority-up) nil))
  6128. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6129. (org-cmp-effort a b)))
  6130. (effort-down (if effort-up (- effort-up) nil))
  6131. (category-up (and (or (org-em 'category-up 'category-down ss)
  6132. (memq 'category-keep ss))
  6133. (org-cmp-category a b)))
  6134. (category-down (if category-up (- category-up) nil))
  6135. (category-keep (if category-up +1 nil))
  6136. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6137. (org-cmp-tag a b)))
  6138. (tag-down (if tag-up (- tag-up) nil))
  6139. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6140. (org-cmp-todo-state a b)))
  6141. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6142. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6143. (org-cmp-habit-p a b)))
  6144. (habit-down (if habit-up (- habit-up) nil))
  6145. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6146. (org-cmp-alpha a b)))
  6147. (alpha-down (if alpha-up (- alpha-up) nil))
  6148. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6149. user-defined-up user-defined-down)
  6150. (if (and need-user-cmp org-agenda-cmp-user-defined
  6151. (functionp org-agenda-cmp-user-defined))
  6152. (setq user-defined-up
  6153. (funcall org-agenda-cmp-user-defined a b)
  6154. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6155. (cdr (assoc
  6156. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6157. '((-1 . t) (1 . nil) (nil . nil))))))
  6158. ;;; Agenda restriction lock
  6159. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6160. "Overlay to mark the headline to which agenda commands are restricted.")
  6161. (overlay-put org-agenda-restriction-lock-overlay
  6162. 'face 'org-agenda-restriction-lock)
  6163. (overlay-put org-agenda-restriction-lock-overlay
  6164. 'help-echo "Agendas are currently limited to this subtree.")
  6165. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6166. (defun org-agenda-set-restriction-lock (&optional type)
  6167. "Set restriction lock for agenda, to current subtree or file.
  6168. Restriction will be the file if TYPE is `file', or if type is the
  6169. universal prefix '(4), or if the cursor is before the first headline
  6170. in the file. Otherwise, restriction will be to the current subtree."
  6171. (interactive "P")
  6172. (and (equal type '(4)) (setq type 'file))
  6173. (setq type (cond
  6174. (type type)
  6175. ((org-at-heading-p) 'subtree)
  6176. ((condition-case nil (org-back-to-heading t) (error nil))
  6177. 'subtree)
  6178. (t 'file)))
  6179. (if (eq type 'subtree)
  6180. (progn
  6181. (setq org-agenda-restrict t)
  6182. (setq org-agenda-overriding-restriction 'subtree)
  6183. (put 'org-agenda-files 'org-restrict
  6184. (list (buffer-file-name (buffer-base-buffer))))
  6185. (org-back-to-heading t)
  6186. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6187. (move-marker org-agenda-restrict-begin (point))
  6188. (move-marker org-agenda-restrict-end
  6189. (save-excursion (org-end-of-subtree t)))
  6190. (message "Locking agenda restriction to subtree"))
  6191. (put 'org-agenda-files 'org-restrict
  6192. (list (buffer-file-name (buffer-base-buffer))))
  6193. (setq org-agenda-restrict nil)
  6194. (setq org-agenda-overriding-restriction 'file)
  6195. (move-marker org-agenda-restrict-begin nil)
  6196. (move-marker org-agenda-restrict-end nil)
  6197. (message "Locking agenda restriction to file"))
  6198. (setq current-prefix-arg nil)
  6199. (org-agenda-maybe-redo))
  6200. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6201. "Remove the agenda restriction lock."
  6202. (interactive "P")
  6203. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6204. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6205. (setq org-agenda-overriding-restriction nil)
  6206. (setq org-agenda-restrict nil)
  6207. (put 'org-agenda-files 'org-restrict nil)
  6208. (move-marker org-agenda-restrict-begin nil)
  6209. (move-marker org-agenda-restrict-end nil)
  6210. (setq current-prefix-arg nil)
  6211. (message "Agenda restriction lock removed")
  6212. (or noupdate (org-agenda-maybe-redo)))
  6213. (defun org-agenda-maybe-redo ()
  6214. "If there is any window showing the agenda view, update it."
  6215. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6216. (w0 (selected-window)))
  6217. (when w
  6218. (select-window w)
  6219. (org-agenda-redo)
  6220. (select-window w0)
  6221. (if org-agenda-overriding-restriction
  6222. (message "Agenda view shifted to new %s restriction"
  6223. org-agenda-overriding-restriction)
  6224. (message "Agenda restriction lock removed")))))
  6225. ;;; Agenda commands
  6226. (defun org-agenda-check-type (error &rest types)
  6227. "Check if agenda buffer is of allowed type.
  6228. If ERROR is non-nil, throw an error, otherwise just return nil."
  6229. (if (not org-agenda-type)
  6230. (error "No Org agenda currently displayed")
  6231. (if (memq org-agenda-type types)
  6232. t
  6233. (if error
  6234. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6235. nil))))
  6236. (defun org-agenda-Quit (&optional arg)
  6237. "Exit agenda by removing the window or the buffer."
  6238. (interactive)
  6239. (if org-agenda-columns-active
  6240. (org-columns-quit)
  6241. (let ((buf (current-buffer)))
  6242. (if (eq org-agenda-window-setup 'other-frame)
  6243. (progn
  6244. (org-agenda-reset-markers)
  6245. (kill-buffer buf)
  6246. (org-columns-remove-overlays)
  6247. (setq org-agenda-archives-mode nil)
  6248. (delete-frame))
  6249. (and (not (eq org-agenda-window-setup 'current-window))
  6250. (not (one-window-p))
  6251. (delete-window))
  6252. (org-agenda-reset-markers)
  6253. (kill-buffer buf)
  6254. (org-columns-remove-overlays)
  6255. (setq org-agenda-archives-mode nil)))
  6256. ;; Maybe restore the pre-agenda window configuration.
  6257. (and org-agenda-restore-windows-after-quit
  6258. (not (eq org-agenda-window-setup 'other-frame))
  6259. org-agenda-pre-window-conf
  6260. (set-window-configuration org-agenda-pre-window-conf)
  6261. (setq org-agenda-pre-window-conf nil))))
  6262. (defun org-agenda-quit ()
  6263. "Exit agenda by killing agenda buffer or burying it when
  6264. `org-agenda-sticky' is non-NIL"
  6265. (interactive)
  6266. (if (and (eq org-indirect-buffer-display 'other-window)
  6267. org-last-indirect-buffer)
  6268. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6269. (if org-agenda-columns-active
  6270. (org-columns-quit)
  6271. (if org-agenda-sticky
  6272. (let ((buf (current-buffer)))
  6273. (if (eq org-agenda-window-setup 'other-frame)
  6274. (progn
  6275. (delete-frame))
  6276. (and (not (eq org-agenda-window-setup 'current-window))
  6277. (not (one-window-p))
  6278. (delete-window)))
  6279. (with-current-buffer buf
  6280. (bury-buffer)
  6281. ;; Maybe restore the pre-agenda window configuration.
  6282. (and org-agenda-restore-windows-after-quit
  6283. (not (eq org-agenda-window-setup 'other-frame))
  6284. org-agenda-pre-window-conf
  6285. (set-window-configuration org-agenda-pre-window-conf)
  6286. (setq org-agenda-pre-window-conf nil))))
  6287. (org-agenda-Quit))))
  6288. (defun org-agenda-exit ()
  6289. "Exit agenda by removing the window or the buffer.
  6290. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6291. Org-mode buffers visited directly by the user will not be touched."
  6292. (interactive)
  6293. (org-release-buffers org-agenda-new-buffers)
  6294. (setq org-agenda-new-buffers nil)
  6295. (org-agenda-Quit))
  6296. (defun org-agenda-kill-all-agenda-buffers ()
  6297. "Kill all buffers in `org-agena-mode'.
  6298. This is used when toggling sticky agendas. You can also explicitly invoke it
  6299. with `C-c a C-k'."
  6300. (interactive)
  6301. (let (blist)
  6302. (dolist (buf (buffer-list))
  6303. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6304. (push buf blist)))
  6305. (mapc 'kill-buffer blist)))
  6306. (defun org-agenda-execute (arg)
  6307. "Execute another agenda command, keeping same window.
  6308. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6309. in the agenda."
  6310. (interactive "P")
  6311. (let ((org-agenda-window-setup 'current-window))
  6312. (org-agenda arg)))
  6313. (defun org-agenda-redo (&optional all)
  6314. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6315. (interactive "P")
  6316. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6317. (cpa (unless (eq all t) current-prefix-arg))
  6318. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6319. (org-agenda-sticky nil)
  6320. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6321. org-agenda-buffer-name))
  6322. (org-agenda-keep-modes t)
  6323. (tag-filter org-agenda-tag-filter)
  6324. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6325. (top-cat-filter org-agenda-top-category-filter)
  6326. (cat-filter org-agenda-category-filter)
  6327. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6328. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6329. (cols org-agenda-columns-active)
  6330. (line (org-current-line))
  6331. (window-line (- line (org-current-line (window-start))))
  6332. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6333. (redo-cmd (get-text-property p 'org-redo-cmd))
  6334. (last-args (get-text-property p 'org-last-args))
  6335. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6336. (org-agenda-overriding-cmd-arguments
  6337. (unless (eq all t)
  6338. (cond ((listp last-args)
  6339. (cons (or cpa (car last-args)) (cdr last-args)))
  6340. ((stringp last-args)
  6341. last-args))))
  6342. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6343. (put 'org-agenda-tag-filter :preset-filter nil)
  6344. (put 'org-agenda-category-filter :preset-filter nil)
  6345. (and cols (org-columns-quit))
  6346. (message "Rebuilding agenda buffer...")
  6347. (if serie-redo-cmd
  6348. (eval serie-redo-cmd)
  6349. (org-let lprops '(eval redo-cmd)))
  6350. (setq org-agenda-undo-list nil
  6351. org-agenda-pending-undo-list nil)
  6352. (message "Rebuilding agenda buffer...done")
  6353. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6354. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6355. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6356. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6357. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6358. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6359. (org-goto-line line)
  6360. (recenter window-line)))
  6361. (defvar org-global-tags-completion-table nil)
  6362. (defvar org-agenda-filter-form nil)
  6363. (defvar org-agenda-filtered-by-category nil)
  6364. (defun org-agenda-filter-by-category (strip)
  6365. "Keep only those lines in the agenda buffer that have a specific category.
  6366. The category is that of the current line."
  6367. (interactive "P")
  6368. (if (and org-agenda-filtered-by-category
  6369. org-agenda-category-filter)
  6370. (org-agenda-filter-show-all-cat)
  6371. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6372. (if cat (org-agenda-filter-apply
  6373. (list (concat (if strip "-" "+") cat)) 'category)
  6374. (error "No category at point")))))
  6375. (defun org-find-top-category (&optional pos)
  6376. (save-excursion
  6377. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6378. (if pos (goto-char pos))
  6379. ;; Skip up to the topmost parent
  6380. (while (ignore-errors (outline-up-heading 1) t))
  6381. (ignore-errors
  6382. (nth 4 (org-heading-components))))))
  6383. (defvar org-agenda-filtered-by-top-category nil)
  6384. (defun org-agenda-filter-by-top-category (strip)
  6385. "Keep only those lines in the agenda buffer that have a specific category.
  6386. The category is that of the current line."
  6387. (interactive "P")
  6388. (if org-agenda-filtered-by-top-category
  6389. (progn
  6390. (setq org-agenda-filtered-by-top-category nil
  6391. org-agenda-top-category-filter nil)
  6392. (org-agenda-filter-show-all-cat))
  6393. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6394. (if cat (org-agenda-filter-top-category-apply cat strip)
  6395. (error "No top-level category at point")))))
  6396. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6397. "Keep only those lines in the agenda buffer that have a specific tag.
  6398. The tag is selected with its fast selection letter, as configured.
  6399. With prefix argument STRIP, remove all lines that do have the tag.
  6400. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6401. used to narrow the search - the interactive user can also press `-' or `+'
  6402. to switch to narrowing."
  6403. (interactive "P")
  6404. (let* ((alist org-tag-alist-for-agenda)
  6405. (tag-chars (mapconcat
  6406. (lambda (x) (if (and (not (symbolp (car x)))
  6407. (cdr x))
  6408. (char-to-string (cdr x))
  6409. ""))
  6410. alist ""))
  6411. (efforts (org-split-string
  6412. (or (cdr (assoc (concat org-effort-property "_ALL")
  6413. org-global-properties))
  6414. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6415. "")))
  6416. (effort-op org-agenda-filter-effort-default-operator)
  6417. (effort-prompt "")
  6418. (inhibit-read-only t)
  6419. (current org-agenda-tag-filter)
  6420. maybe-refresh a n tag)
  6421. (unless char
  6422. (message
  6423. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6424. (if narrow "Narrow" "Filter") tag-chars
  6425. (if org-agenda-auto-exclude-function "[RET], " ""))
  6426. (setq char (read-char-exclusive)))
  6427. (when (member char '(?+ ?-))
  6428. ;; Narrowing down
  6429. (cond ((equal char ?-) (setq strip t narrow t))
  6430. ((equal char ?+) (setq strip nil narrow t)))
  6431. (message
  6432. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6433. (setq char (read-char-exclusive)))
  6434. (when (member char '(?< ?> ?= ??))
  6435. ;; An effort operator
  6436. (setq effort-op (char-to-string char))
  6437. (setq alist nil) ; to make sure it will be interpreted as effort.
  6438. (unless (equal char ??)
  6439. (loop for i from 0 to 9 do
  6440. (setq effort-prompt
  6441. (concat
  6442. effort-prompt " ["
  6443. (if (= i 9) "0" (int-to-string (1+ i)))
  6444. "]" (nth i efforts))))
  6445. (message "Effort%s: %s " effort-op effort-prompt)
  6446. (setq char (read-char-exclusive))
  6447. (when (or (< char ?0) (> char ?9))
  6448. (error "Need 1-9,0 to select effort"))))
  6449. (when (equal char ?\t)
  6450. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6451. (org-set-local 'org-global-tags-completion-table
  6452. (org-global-tags-completion-table)))
  6453. (let ((completion-ignore-case t))
  6454. (setq tag (org-icompleting-read
  6455. "Tag: " org-global-tags-completion-table))))
  6456. (cond
  6457. ((equal char ?\r)
  6458. (org-agenda-filter-show-all-tag)
  6459. (when org-agenda-auto-exclude-function
  6460. (setq org-agenda-tag-filter '())
  6461. (dolist (tag (org-agenda-get-represented-tags))
  6462. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6463. (if modifier
  6464. (push modifier org-agenda-tag-filter))))
  6465. (if (not (null org-agenda-tag-filter))
  6466. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6467. (setq maybe-refresh t))
  6468. ((equal char ?/)
  6469. (org-agenda-filter-show-all-tag)
  6470. (when (get 'org-agenda-tag-filter :preset-filter)
  6471. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6472. (setq maybe-refresh t))
  6473. ((equal char ?. )
  6474. (setq org-agenda-tag-filter
  6475. (mapcar (lambda(tag) (concat "+" tag))
  6476. (org-get-at-bol 'tags)))
  6477. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6478. (setq maybe-refresh t))
  6479. ((or (equal char ?\ )
  6480. (setq a (rassoc char alist))
  6481. (and (>= char ?0) (<= char ?9)
  6482. (setq n (if (= char ?0) 9 (- char ?0 1))
  6483. tag (concat effort-op (nth n efforts))
  6484. a (cons tag nil)))
  6485. (and (= char ??)
  6486. (setq tag "?eff")
  6487. a (cons tag nil))
  6488. (and tag (setq a (cons tag nil))))
  6489. (org-agenda-filter-show-all-tag)
  6490. (setq tag (car a))
  6491. (setq org-agenda-tag-filter
  6492. (cons (concat (if strip "-" "+") tag)
  6493. (if narrow current nil)))
  6494. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6495. (setq maybe-refresh t))
  6496. (t (error "Invalid tag selection character %c" char)))
  6497. (when (and maybe-refresh
  6498. (eq org-agenda-clockreport-mode 'with-filter))
  6499. (org-agenda-redo))))
  6500. (defun org-agenda-get-represented-tags ()
  6501. "Get a list of all tags currently represented in the agenda."
  6502. (let (p tags)
  6503. (save-excursion
  6504. (goto-char (point-min))
  6505. (while (setq p (next-single-property-change (point) 'tags))
  6506. (goto-char p)
  6507. (mapc (lambda (x) (add-to-list 'tags x))
  6508. (get-text-property (point) 'tags))))
  6509. tags))
  6510. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6511. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6512. (interactive "P")
  6513. (org-agenda-filter-by-tag strip char 'refine))
  6514. (defun org-agenda-filter-make-matcher ()
  6515. "Create the form that tests a line for agenda filter."
  6516. (let (f f1)
  6517. ;; first compute the tag-filter matcher
  6518. (dolist (x (delete-dups
  6519. (append (get 'org-agenda-tag-filter
  6520. :preset-filter) org-agenda-tag-filter)))
  6521. (if (member x '("-" "+"))
  6522. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6523. (if (string-match "[<=>?]" x)
  6524. (setq f1 (org-agenda-filter-effort-form x))
  6525. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6526. (if (equal (string-to-char x) ?-)
  6527. (setq f1 (list 'not f1))))
  6528. (push f1 f))
  6529. ;; then compute the category-filter matcher
  6530. (dolist (x (delete-dups
  6531. (append (get 'org-agenda-category-filter
  6532. :preset-filter) org-agenda-category-filter)))
  6533. (if (equal "-" (substring x 0 1))
  6534. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6535. (setq f1 (list 'equal (substring x 1) 'cat)))
  6536. (push f1 f))
  6537. (cons 'and (nreverse f))))
  6538. (defun org-agenda-filter-effort-form (e)
  6539. "Return the form to compare the effort of the current line with what E says.
  6540. E looks like \"+<2:25\"."
  6541. (let (op)
  6542. (setq e (substring e 1))
  6543. (setq op (string-to-char e) e (substring e 1))
  6544. (setq op (cond ((equal op ?<) '<=)
  6545. ((equal op ?>) '>=)
  6546. ((equal op ??) op)
  6547. (t '=)))
  6548. (list 'org-agenda-compare-effort (list 'quote op)
  6549. (org-duration-string-to-minutes e))))
  6550. (defun org-agenda-compare-effort (op value)
  6551. "Compare the effort of the current line with VALUE, using OP.
  6552. If the line does not have an effort defined, return nil."
  6553. (let ((eff (org-get-at-bol 'effort-minutes)))
  6554. (if (equal op ??)
  6555. (not eff)
  6556. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6557. value))))
  6558. (defun org-agenda-filter-apply (filter type)
  6559. "Set FILTER as the new agenda filter and apply it."
  6560. (let (tags cat)
  6561. (if (eq type 'tag)
  6562. (setq org-agenda-tag-filter filter)
  6563. (setq org-agenda-category-filter filter))
  6564. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6565. (if (and (eq type 'category)
  6566. (not (equal (substring (car filter) 0 1) "-")))
  6567. ;; Only set `org-agenda-filtered-by-category' to t
  6568. ;; when a unique category is used as the filter
  6569. (setq org-agenda-filtered-by-category t))
  6570. (org-agenda-set-mode-name)
  6571. (save-excursion
  6572. (goto-char (point-min))
  6573. (while (not (eobp))
  6574. (if (org-get-at-bol 'org-marker)
  6575. (progn
  6576. (setq tags (org-get-at-bol 'tags) ; used in eval
  6577. cat (get-text-property (point) 'org-category))
  6578. (if (not (eval org-agenda-filter-form))
  6579. (org-agenda-filter-hide-line type))
  6580. (beginning-of-line 2))
  6581. (beginning-of-line 2))))
  6582. (if (get-char-property (point) 'invisible)
  6583. (ignore-errors (org-agenda-previous-line)))))
  6584. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6585. "Set FILTER as the new agenda filter and apply it."
  6586. (org-agenda-set-mode-name)
  6587. (save-excursion
  6588. (goto-char (point-min))
  6589. (while (not (eobp))
  6590. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6591. (topcat (and pos (org-find-top-category pos))))
  6592. (if (and topcat (funcall (if negative 'identity 'not)
  6593. (string= category topcat)))
  6594. (org-agenda-filter-hide-line 'category)))
  6595. (beginning-of-line 2)))
  6596. (if (get-char-property (point) 'invisible)
  6597. (org-agenda-previous-line))
  6598. (setq org-agenda-top-category-filter category
  6599. org-agenda-filtered-by-top-category t))
  6600. (defun org-agenda-filter-hide-line (type)
  6601. (let (ov)
  6602. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6603. (point-at-eol)))
  6604. (overlay-put ov 'invisible t)
  6605. (overlay-put ov 'type type)
  6606. (if (eq type 'tag)
  6607. (push ov org-agenda-tag-filter-overlays)
  6608. (push ov org-agenda-cat-filter-overlays))))
  6609. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6610. (setq pos (or pos (point)))
  6611. (save-excursion
  6612. (dolist (ov (overlays-at pos))
  6613. (when (and (overlay-get ov 'invisible)
  6614. (eq (overlay-get ov 'type) 'tag))
  6615. (goto-char pos)
  6616. (if (< (overlay-start ov) (point-at-eol))
  6617. (move-overlay ov (point-at-eol)
  6618. (overlay-end ov)))))))
  6619. (defun org-agenda-filter-show-all-tag nil
  6620. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6621. (setq org-agenda-tag-filter-overlays nil
  6622. org-agenda-tag-filter nil
  6623. org-agenda-filter-form nil)
  6624. (org-agenda-set-mode-name))
  6625. (defun org-agenda-filter-show-all-cat nil
  6626. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6627. (setq org-agenda-cat-filter-overlays nil
  6628. org-agenda-filtered-by-category nil
  6629. org-agenda-category-filter nil
  6630. org-agenda-filter-form nil)
  6631. (org-agenda-set-mode-name))
  6632. (defun org-agenda-manipulate-query-add ()
  6633. "Manipulate the query by adding a search term with positive selection.
  6634. Positive selection means the term must be matched for selection of an entry."
  6635. (interactive)
  6636. (org-agenda-manipulate-query ?\[))
  6637. (defun org-agenda-manipulate-query-subtract ()
  6638. "Manipulate the query by adding a search term with negative selection.
  6639. Negative selection means term must not be matched for selection of an entry."
  6640. (interactive)
  6641. (org-agenda-manipulate-query ?\]))
  6642. (defun org-agenda-manipulate-query-add-re ()
  6643. "Manipulate the query by adding a search regexp with positive selection.
  6644. Positive selection means the regexp must match for selection of an entry."
  6645. (interactive)
  6646. (org-agenda-manipulate-query ?\{))
  6647. (defun org-agenda-manipulate-query-subtract-re ()
  6648. "Manipulate the query by adding a search regexp with negative selection.
  6649. Negative selection means regexp must not match for selection of an entry."
  6650. (interactive)
  6651. (org-agenda-manipulate-query ?\}))
  6652. (defun org-agenda-manipulate-query (char)
  6653. (cond
  6654. ((memq org-agenda-type '(timeline agenda))
  6655. (let ((org-agenda-include-inactive-timestamps t))
  6656. (org-agenda-redo))
  6657. (message "Display now includes inactive timestamps as well"))
  6658. ((eq org-agenda-type 'search)
  6659. (org-add-to-string
  6660. 'org-agenda-query-string
  6661. (if org-agenda-last-search-view-search-was-boolean
  6662. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6663. (?\{ . " +{}") (?\} . " -{}"))))
  6664. " "))
  6665. (setq org-agenda-redo-command
  6666. (list 'org-search-view
  6667. (car (get-text-property (min (1- (point-max)) (point))
  6668. 'org-last-args))
  6669. org-agenda-query-string
  6670. (+ (length org-agenda-query-string)
  6671. (if (member char '(?\{ ?\})) 0 1))))
  6672. (set-register org-agenda-query-register org-agenda-query-string)
  6673. (let ((org-agenda-overriding-arguments
  6674. (cdr org-agenda-redo-command)))
  6675. (org-agenda-redo)))
  6676. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6677. org-agenda-type))))
  6678. (defun org-add-to-string (var string)
  6679. (set var (concat (symbol-value var) string)))
  6680. (defun org-agenda-goto-date (span)
  6681. "Jump to DATE in agenda."
  6682. (interactive "P")
  6683. (let* ((org-read-date-prefer-future
  6684. (eval org-agenda-jump-prefer-future))
  6685. (date (org-read-date))
  6686. (org-agenda-sticky-orig org-agenda-sticky)
  6687. (org-agenda-buffer-tmp-name (buffer-name))
  6688. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6689. (0-arg (or current-prefix-arg (car args)))
  6690. (2-arg (nth 2 args))
  6691. (newcmd (list 'org-agenda-list 0-arg date
  6692. (org-agenda-span-to-ndays 2-arg)))
  6693. (newargs (cdr newcmd))
  6694. (inhibit-read-only t)
  6695. org-agenda-sticky)
  6696. (if (not (org-agenda-check-type t 'agenda))
  6697. (error "Not available in non-agenda blocks")
  6698. (add-text-properties (point-min) (point-max)
  6699. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6700. (org-agenda-redo)
  6701. (setq org-agenda-sticky org-agenda-sticky-orig
  6702. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6703. (defun org-agenda-goto-today ()
  6704. "Go to today."
  6705. (interactive)
  6706. (org-agenda-check-type t 'timeline 'agenda)
  6707. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6708. (curspan (nth 2 args))
  6709. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6710. (cond
  6711. (tdpos (goto-char tdpos))
  6712. ((eq org-agenda-type 'agenda)
  6713. (let* ((sd (org-agenda-compute-starting-span
  6714. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6715. (org-agenda-overriding-arguments args))
  6716. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6717. (org-agenda-redo)
  6718. (org-agenda-find-same-or-today-or-agenda)))
  6719. (t (error "Cannot find today")))))
  6720. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6721. (goto-char
  6722. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6723. (text-property-any (point-min) (point-max) 'org-today t)
  6724. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6725. (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
  6726. (org-agenda-goto-block-beginning))
  6727. (point-min))))
  6728. (defun org-agenda-goto-block-beginning ()
  6729. "Go the agenda block beginning."
  6730. (interactive)
  6731. (if (not (derived-mode-p 'org-agenda-mode))
  6732. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6733. (let (dest)
  6734. (save-excursion
  6735. (unless (looking-at "\\'")
  6736. (forward-char))
  6737. (let* ((prop 'org-agenda-structural-header)
  6738. (p (previous-single-property-change (point) prop))
  6739. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6740. (1- (point))) prop)))
  6741. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6742. (if (not dest)
  6743. (error "Cannot find the beginning of the blog")
  6744. (goto-char dest)
  6745. (move-beginning-of-line 1)))))
  6746. (defun org-agenda-later (arg)
  6747. "Go forward in time by thee current span.
  6748. With prefix ARG, go forward that many times the current span."
  6749. (interactive "p")
  6750. (org-agenda-check-type t 'agenda)
  6751. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6752. (span (or (nth 2 args) org-agenda-current-span))
  6753. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6754. (greg (calendar-gregorian-from-absolute sd))
  6755. (cnt (org-get-at-bol 'org-day-cnt))
  6756. greg2)
  6757. (cond
  6758. ((numberp span)
  6759. (setq sd (+ span sd)))
  6760. ((eq span 'day)
  6761. (setq sd (+ arg sd)))
  6762. ((eq span 'week)
  6763. (setq sd (+ (* 7 arg) sd)))
  6764. ((eq span 'month)
  6765. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6766. sd (calendar-absolute-from-gregorian greg2))
  6767. (setcar greg2 (1+ (car greg2))))
  6768. ((eq span 'year)
  6769. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6770. sd (calendar-absolute-from-gregorian greg2))
  6771. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6772. (t
  6773. (setq sd (+ (* span arg) sd))))
  6774. (let ((org-agenda-overriding-cmd
  6775. ;; `cmd' may have been set by `org-agenda-run-series' which
  6776. ;; uses `org-agenda-overriding-cmd' to decide whether
  6777. ;; overriding is allowed for `cmd'
  6778. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6779. (org-agenda-overriding-arguments
  6780. (list (car args) sd span)))
  6781. (org-agenda-redo)
  6782. (org-agenda-find-same-or-today-or-agenda cnt))))
  6783. (defun org-agenda-earlier (arg)
  6784. "Go backward in time by the current span.
  6785. With prefix ARG, go backward that many times the current span."
  6786. (interactive "p")
  6787. (org-agenda-later (- arg)))
  6788. (defun org-agenda-view-mode-dispatch ()
  6789. "Call one of the view mode commands."
  6790. (interactive)
  6791. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6792. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6793. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6794. (let ((a (read-char-exclusive)))
  6795. (case a
  6796. (?\ (call-interactively 'org-agenda-reset-view))
  6797. (?d (call-interactively 'org-agenda-day-view))
  6798. (?w (call-interactively 'org-agenda-week-view))
  6799. (?m (call-interactively 'org-agenda-month-view))
  6800. (?y (call-interactively 'org-agenda-year-view))
  6801. (?l (call-interactively 'org-agenda-log-mode))
  6802. (?L (org-agenda-log-mode '(4)))
  6803. (?c (org-agenda-log-mode 'clockcheck))
  6804. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6805. (?a (call-interactively 'org-agenda-archives-mode))
  6806. (?A (org-agenda-archives-mode 'files))
  6807. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6808. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6809. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6810. (?D (call-interactively 'org-agenda-toggle-diary))
  6811. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6812. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6813. (org-agenda-check-type t 'timeline 'agenda)
  6814. (org-agenda-redo))
  6815. (message "Display now includes inactive timestamps as well"))
  6816. (?q (message "Abort"))
  6817. (otherwise (error "Invalid key" )))))
  6818. (defun org-agenda-reset-view ()
  6819. "Switch to default view for agenda."
  6820. (interactive)
  6821. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6822. (defun org-agenda-day-view (&optional day-of-year)
  6823. "Switch to daily view for agenda.
  6824. With argument DAY-OF-YEAR, switch to that day of the year."
  6825. (interactive "P")
  6826. (org-agenda-change-time-span 'day day-of-year))
  6827. (defun org-agenda-week-view (&optional iso-week)
  6828. "Switch to daily view for agenda.
  6829. With argument ISO-WEEK, switch to the corresponding ISO week.
  6830. If ISO-WEEK has more then 2 digits, only the last two encode the
  6831. week. Any digits before this encode a year. So 200712 means
  6832. week 12 of year 2007. Years in the range 1938-2037 can also be
  6833. written as 2-digit years."
  6834. (interactive "P")
  6835. (org-agenda-change-time-span 'week iso-week))
  6836. (defun org-agenda-month-view (&optional month)
  6837. "Switch to monthly view for agenda.
  6838. With argument MONTH, switch to that month."
  6839. (interactive "P")
  6840. (org-agenda-change-time-span 'month month))
  6841. (defun org-agenda-year-view (&optional year)
  6842. "Switch to yearly view for agenda.
  6843. With argument YEAR, switch to that year.
  6844. If MONTH has more then 2 digits, only the last two encode the
  6845. month. Any digits before this encode a year. So 200712 means
  6846. December year 2007. Years in the range 1938-2037 can also be
  6847. written as 2-digit years."
  6848. (interactive "P")
  6849. (when year
  6850. (setq year (org-small-year-to-year year)))
  6851. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6852. (org-agenda-change-time-span 'year year)
  6853. (error "Abort")))
  6854. (defun org-agenda-change-time-span (span &optional n)
  6855. "Change the agenda view to SPAN.
  6856. SPAN may be `day', `week', `month', `year'."
  6857. (org-agenda-check-type t 'agenda)
  6858. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6859. (curspan (nth 2 args)))
  6860. (if (and (not n) (equal curspan span))
  6861. (error "Viewing span is already \"%s\"" span))
  6862. (let* ((sd (or (org-get-at-bol 'day)
  6863. (nth 1 args)
  6864. org-starting-day))
  6865. (sd (org-agenda-compute-starting-span sd span n))
  6866. (org-agenda-overriding-cmd
  6867. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6868. (org-agenda-overriding-arguments
  6869. (list (car args) sd span)))
  6870. (org-agenda-redo)
  6871. (org-agenda-find-same-or-today-or-agenda))
  6872. (org-agenda-set-mode-name)
  6873. (message "Switched to %s view" span)))
  6874. (defun org-agenda-compute-starting-span (sd span &optional n)
  6875. "Compute starting date for agenda.
  6876. SPAN may be `day', `week', `month', `year'. The return value
  6877. is a cons cell with the starting date and the number of days,
  6878. so that the date SD will be in that range."
  6879. (let* ((greg (calendar-gregorian-from-absolute sd))
  6880. (dg (nth 1 greg))
  6881. (mg (car greg))
  6882. (yg (nth 2 greg)))
  6883. (cond
  6884. ((eq span 'day)
  6885. (when n
  6886. (setq sd (+ (calendar-absolute-from-gregorian
  6887. (list mg 1 yg))
  6888. n -1))))
  6889. ((eq span 'week)
  6890. (let* ((nt (calendar-day-of-week
  6891. (calendar-gregorian-from-absolute sd)))
  6892. (d (if org-agenda-start-on-weekday
  6893. (- nt org-agenda-start-on-weekday)
  6894. 0))
  6895. y1)
  6896. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6897. (when n
  6898. (require 'cal-iso)
  6899. (when (> n 99)
  6900. (setq y1 (org-small-year-to-year (/ n 100))
  6901. n (mod n 100)))
  6902. (setq sd
  6903. (calendar-absolute-from-iso
  6904. (list n 1
  6905. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6906. ((eq span 'month)
  6907. (let (y1)
  6908. (when (and n (> n 99))
  6909. (setq y1 (org-small-year-to-year (/ n 100))
  6910. n (mod n 100)))
  6911. (setq sd (calendar-absolute-from-gregorian
  6912. (list (or n mg) 1 (or y1 yg))))))
  6913. ((eq span 'year)
  6914. (setq sd (calendar-absolute-from-gregorian
  6915. (list 1 1 (or n yg))))))
  6916. sd))
  6917. (defun org-agenda-next-date-line (&optional arg)
  6918. "Jump to the next line indicating a date in agenda buffer."
  6919. (interactive "p")
  6920. (org-agenda-check-type t 'agenda 'timeline)
  6921. (beginning-of-line 1)
  6922. ;; This does not work if user makes date format that starts with a blank
  6923. (if (looking-at "^\\S-") (forward-char 1))
  6924. (if (not (re-search-forward "^\\S-" nil t arg))
  6925. (progn
  6926. (backward-char 1)
  6927. (error "No next date after this line in this buffer")))
  6928. (goto-char (match-beginning 0)))
  6929. (defun org-agenda-previous-date-line (&optional arg)
  6930. "Jump to the previous line indicating a date in agenda buffer."
  6931. (interactive "p")
  6932. (org-agenda-check-type t 'agenda 'timeline)
  6933. (beginning-of-line 1)
  6934. (if (not (re-search-backward "^\\S-" nil t arg))
  6935. (error "No previous date before this line in this buffer")))
  6936. ;; Initialize the highlight
  6937. (defvar org-hl (make-overlay 1 1))
  6938. (overlay-put org-hl 'face 'highlight)
  6939. (defun org-highlight (begin end &optional buffer)
  6940. "Highlight a region with overlay."
  6941. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6942. (defun org-unhighlight ()
  6943. "Detach overlay INDEX."
  6944. (org-detach-overlay org-hl))
  6945. (defun org-unhighlight-once ()
  6946. "Remove the highlight from its position, and this function from the hook."
  6947. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6948. (org-unhighlight))
  6949. (defvar org-agenda-pre-follow-window-conf nil)
  6950. (defun org-agenda-follow-mode ()
  6951. "Toggle follow mode in an agenda buffer."
  6952. (interactive)
  6953. (unless org-agenda-follow-mode
  6954. (setq org-agenda-pre-follow-window-conf
  6955. (current-window-configuration)))
  6956. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6957. (unless org-agenda-follow-mode
  6958. (set-window-configuration org-agenda-pre-follow-window-conf))
  6959. (org-agenda-set-mode-name)
  6960. (org-agenda-do-context-action)
  6961. (message "Follow mode is %s"
  6962. (if org-agenda-follow-mode "on" "off")))
  6963. (defun org-agenda-entry-text-mode (&optional arg)
  6964. "Toggle entry text mode in an agenda buffer."
  6965. (interactive "P")
  6966. (setq org-agenda-entry-text-mode (or (integerp arg)
  6967. (not org-agenda-entry-text-mode)))
  6968. (org-agenda-entry-text-hide)
  6969. (and org-agenda-entry-text-mode
  6970. (let ((org-agenda-entry-text-maxlines
  6971. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6972. (org-agenda-entry-text-show)))
  6973. (org-agenda-set-mode-name)
  6974. (message "Entry text mode is %s. Maximum number of lines is %d"
  6975. (if org-agenda-entry-text-mode "on" "off")
  6976. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6977. (defun org-agenda-clockreport-mode (&optional with-filter)
  6978. "Toggle clocktable mode in an agenda buffer.
  6979. With prefix arg WITH-FILTER, make the clocktable respect the current
  6980. agenda filter."
  6981. (interactive "P")
  6982. (org-agenda-check-type t 'agenda)
  6983. (if with-filter
  6984. (setq org-agenda-clockreport-mode 'with-filter)
  6985. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6986. (org-agenda-set-mode-name)
  6987. (org-agenda-redo)
  6988. (message "Clocktable mode is %s"
  6989. (if org-agenda-clockreport-mode "on" "off")))
  6990. (defun org-agenda-log-mode (&optional special)
  6991. "Toggle log mode in an agenda buffer.
  6992. With argument SPECIAL, show all possible log items, not only the ones
  6993. configured in `org-agenda-log-mode-items'.
  6994. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6995. (interactive "P")
  6996. (org-agenda-check-type t 'agenda 'timeline)
  6997. (setq org-agenda-show-log
  6998. (cond
  6999. ((equal special '(16)) 'only)
  7000. ((eq special 'clockcheck)
  7001. (if (eq org-agenda-show-log 'clockcheck)
  7002. nil 'clockcheck))
  7003. (special '(closed clock state))
  7004. (t (not org-agenda-show-log))))
  7005. (org-agenda-set-mode-name)
  7006. (org-agenda-redo)
  7007. (message "Log mode is %s"
  7008. (if org-agenda-show-log "on" "off")))
  7009. (defun org-agenda-archives-mode (&optional with-files)
  7010. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7011. When called with a prefix argument, include all archive files as well."
  7012. (interactive "P")
  7013. (setq org-agenda-archives-mode
  7014. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7015. (org-agenda-set-mode-name)
  7016. (org-agenda-redo)
  7017. (message
  7018. "%s"
  7019. (cond
  7020. ((eq org-agenda-archives-mode nil)
  7021. "No archives are included")
  7022. ((eq org-agenda-archives-mode 'trees)
  7023. (format "Trees with :%s: tag are included" org-archive-tag))
  7024. ((eq org-agenda-archives-mode t)
  7025. (format "Trees with :%s: tag and all active archive files are included"
  7026. org-archive-tag)))))
  7027. (defun org-agenda-toggle-diary ()
  7028. "Toggle diary inclusion in an agenda buffer."
  7029. (interactive)
  7030. (org-agenda-check-type t 'agenda)
  7031. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7032. (org-agenda-redo)
  7033. (org-agenda-set-mode-name)
  7034. (message "Diary inclusion turned %s"
  7035. (if org-agenda-include-diary "on" "off")))
  7036. (defun org-agenda-toggle-deadlines ()
  7037. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7038. (interactive)
  7039. (org-agenda-check-type t 'agenda)
  7040. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7041. (org-agenda-redo)
  7042. (org-agenda-set-mode-name)
  7043. (message "Deadlines inclusion turned %s"
  7044. (if org-agenda-include-deadlines "on" "off")))
  7045. (defun org-agenda-toggle-time-grid ()
  7046. "Toggle time grid in an agenda buffer."
  7047. (interactive)
  7048. (org-agenda-check-type t 'agenda)
  7049. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7050. (org-agenda-redo)
  7051. (org-agenda-set-mode-name)
  7052. (message "Time-grid turned %s"
  7053. (if org-agenda-use-time-grid "on" "off")))
  7054. (defun org-agenda-set-mode-name ()
  7055. "Set the mode name to indicate all the small mode settings."
  7056. (setq mode-name
  7057. (list "Org-Agenda"
  7058. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7059. " "
  7060. '(:eval (org-agenda-span-name org-agenda-current-span))
  7061. (if org-agenda-follow-mode " Follow" "")
  7062. (if org-agenda-entry-text-mode " ETxt" "")
  7063. (if org-agenda-include-diary " Diary" "")
  7064. (if org-agenda-include-deadlines " Ddl" "")
  7065. (if org-agenda-use-time-grid " Grid" "")
  7066. (if (and (boundp 'org-habit-show-habits)
  7067. org-habit-show-habits) " Habit" "")
  7068. (cond
  7069. ((consp org-agenda-show-log) " LogAll")
  7070. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7071. (org-agenda-show-log " Log")
  7072. (t ""))
  7073. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7074. :preset-filter))
  7075. '(:eval (org-propertize
  7076. (concat " <"
  7077. (mapconcat
  7078. 'identity
  7079. (append
  7080. (get 'org-agenda-category-filter :preset-filter)
  7081. org-agenda-category-filter)
  7082. "")
  7083. ">")
  7084. 'face 'org-agenda-filter-category
  7085. 'help-echo "Category used in filtering"))
  7086. "")
  7087. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7088. :preset-filter))
  7089. '(:eval (org-propertize
  7090. (concat " {"
  7091. (mapconcat
  7092. 'identity
  7093. (append
  7094. (get 'org-agenda-tag-filter :preset-filter)
  7095. org-agenda-tag-filter)
  7096. "")
  7097. "}")
  7098. 'face 'org-agenda-filter-tags
  7099. 'help-echo "Tags used in filtering"))
  7100. "")
  7101. (if org-agenda-archives-mode
  7102. (if (eq org-agenda-archives-mode t)
  7103. " Archives"
  7104. (format " :%s:" org-archive-tag))
  7105. "")
  7106. (if org-agenda-clockreport-mode
  7107. (if (eq org-agenda-clockreport-mode 'with-filter)
  7108. " Clock{}" " Clock")
  7109. "")))
  7110. (force-mode-line-update))
  7111. (define-obsolete-function-alias
  7112. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7113. (defun org-agenda-update-agenda-type ()
  7114. "Update the agenda type after each command."
  7115. (setq org-agenda-type
  7116. (or (get-text-property (point) 'org-agenda-type)
  7117. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7118. (defun org-agenda-next-line ()
  7119. "Move cursor to the next line, and show if follow mode is active."
  7120. (interactive)
  7121. (call-interactively 'next-line)
  7122. (org-agenda-do-context-action))
  7123. (defun org-agenda-previous-line ()
  7124. "Move cursor to the previous line, and show if follow-mode is active."
  7125. (interactive)
  7126. (call-interactively 'previous-line)
  7127. (org-agenda-do-context-action))
  7128. (defun org-agenda-next-item (n)
  7129. "Move cursor to next agenda item."
  7130. (interactive "p")
  7131. (let ((col (current-column)))
  7132. (dotimes (c n)
  7133. (when (next-single-property-change (point-at-eol) 'org-marker)
  7134. (move-end-of-line 1)
  7135. (goto-char (next-single-property-change (point) 'org-marker))))
  7136. (org-move-to-column col))
  7137. (org-agenda-do-context-action))
  7138. (defun org-agenda-previous-item (n)
  7139. "Move cursor to next agenda item."
  7140. (interactive "p")
  7141. (dotimes (c n)
  7142. (let ((col (current-column))
  7143. (goto (save-excursion
  7144. (move-end-of-line 0)
  7145. (previous-single-property-change (point) 'org-marker))))
  7146. (if goto (goto-char goto))
  7147. (org-move-to-column col)))
  7148. (org-agenda-do-context-action))
  7149. (defun org-agenda-do-context-action ()
  7150. "Show outline path and, maybe, follow mode window."
  7151. (let ((m (org-get-at-bol 'org-marker)))
  7152. (when (and (markerp m) (marker-buffer m))
  7153. (and org-agenda-follow-mode
  7154. (if org-agenda-follow-indirect
  7155. (org-agenda-tree-to-indirect-buffer nil)
  7156. (org-agenda-show)))
  7157. (and org-agenda-show-outline-path
  7158. (org-with-point-at m (org-display-outline-path t))))))
  7159. (defun org-agenda-show-tags ()
  7160. "Show the tags applicable to the current item."
  7161. (interactive)
  7162. (let* ((tags (org-get-at-bol 'tags)))
  7163. (if tags
  7164. (message "Tags are :%s:"
  7165. (org-no-properties (mapconcat 'identity tags ":")))
  7166. (message "No tags associated with this line"))))
  7167. (defun org-agenda-goto (&optional highlight)
  7168. "Go to the Org-mode file which contains the item at point."
  7169. (interactive)
  7170. (let* ((marker (or (org-get-at-bol 'org-marker)
  7171. (org-agenda-error)))
  7172. (buffer (marker-buffer marker))
  7173. (pos (marker-position marker)))
  7174. (switch-to-buffer-other-window buffer)
  7175. (widen)
  7176. (push-mark)
  7177. (goto-char pos)
  7178. (when (derived-mode-p 'org-mode)
  7179. (org-show-context 'agenda)
  7180. (save-excursion
  7181. (and (outline-next-heading)
  7182. (org-flag-heading nil)))) ; show the next heading
  7183. (when (outline-invisible-p)
  7184. (show-entry)) ; display invisible text
  7185. (recenter (/ (window-height) 2))
  7186. (run-hooks 'org-agenda-after-show-hook)
  7187. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7188. (defvar org-agenda-after-show-hook nil
  7189. "Normal hook run after an item has been shown from the agenda.
  7190. Point is in the buffer where the item originated.")
  7191. (defun org-agenda-kill ()
  7192. "Kill the entry or subtree belonging to the current agenda entry."
  7193. (interactive)
  7194. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7195. (let* ((bufname-orig (buffer-name))
  7196. (marker (or (org-get-at-bol 'org-marker)
  7197. (org-agenda-error)))
  7198. (buffer (marker-buffer marker))
  7199. (pos (marker-position marker))
  7200. (type (org-get-at-bol 'type))
  7201. dbeg dend (n 0) conf)
  7202. (org-with-remote-undo buffer
  7203. (with-current-buffer buffer
  7204. (save-excursion
  7205. (goto-char pos)
  7206. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7207. (setq dbeg (progn (org-back-to-heading t) (point))
  7208. dend (org-end-of-subtree t t))
  7209. (setq dbeg (point-at-bol)
  7210. dend (min (point-max) (1+ (point-at-eol)))))
  7211. (goto-char dbeg)
  7212. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7213. (setq conf (or (eq t org-agenda-confirm-kill)
  7214. (and (numberp org-agenda-confirm-kill)
  7215. (> n org-agenda-confirm-kill))))
  7216. (and conf
  7217. (not (y-or-n-p
  7218. (format "Delete entry with %d lines in buffer \"%s\"? "
  7219. n (buffer-name buffer))))
  7220. (error "Abort"))
  7221. (let ((org-agenda-buffer-name bufname-orig))
  7222. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7223. (with-current-buffer buffer (delete-region dbeg dend))
  7224. (message "Agenda item and source killed"))))
  7225. (defvar org-archive-default-command) ; defined in org-archive.el
  7226. (defun org-agenda-archive-default ()
  7227. "Archive the entry or subtree belonging to the current agenda entry."
  7228. (interactive)
  7229. (require 'org-archive)
  7230. (org-agenda-archive-with org-archive-default-command))
  7231. (defun org-agenda-archive-default-with-confirmation ()
  7232. "Archive the entry or subtree belonging to the current agenda entry."
  7233. (interactive)
  7234. (require 'org-archive)
  7235. (org-agenda-archive-with org-archive-default-command 'confirm))
  7236. (defun org-agenda-archive ()
  7237. "Archive the entry or subtree belonging to the current agenda entry."
  7238. (interactive)
  7239. (org-agenda-archive-with 'org-archive-subtree))
  7240. (defun org-agenda-archive-to-archive-sibling ()
  7241. "Move the entry to the archive sibling."
  7242. (interactive)
  7243. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7244. (defun org-agenda-archive-with (cmd &optional confirm)
  7245. "Move the entry to the archive sibling."
  7246. (interactive)
  7247. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7248. (let* ((bufname-orig (buffer-name))
  7249. (marker (or (org-get-at-bol 'org-marker)
  7250. (org-agenda-error)))
  7251. (buffer (marker-buffer marker))
  7252. (pos (marker-position marker)))
  7253. (org-with-remote-undo buffer
  7254. (with-current-buffer buffer
  7255. (if (derived-mode-p 'org-mode)
  7256. (if (and confirm
  7257. (not (y-or-n-p "Archive this subtree or entry? ")))
  7258. (error "Abort")
  7259. (save-excursion
  7260. (goto-char pos)
  7261. (let ((org-agenda-buffer-name bufname-orig))
  7262. (org-remove-subtree-entries-from-agenda))
  7263. (org-back-to-heading t)
  7264. (funcall cmd)))
  7265. (error "Archiving works only in Org-mode files"))))))
  7266. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7267. "Remove all lines in the agenda that correspond to a given subtree.
  7268. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7269. If this information is not given, the function uses the tree at point."
  7270. (let ((buf (or buf (current-buffer))) m p)
  7271. (save-excursion
  7272. (unless (and beg end)
  7273. (org-back-to-heading t)
  7274. (setq beg (point))
  7275. (org-end-of-subtree t)
  7276. (setq end (point)))
  7277. (set-buffer (get-buffer org-agenda-buffer-name))
  7278. (save-excursion
  7279. (goto-char (point-max))
  7280. (beginning-of-line 1)
  7281. (while (not (bobp))
  7282. (when (and (setq m (org-get-at-bol 'org-marker))
  7283. (equal buf (marker-buffer m))
  7284. (setq p (marker-position m))
  7285. (>= p beg)
  7286. (< p end))
  7287. (let ((inhibit-read-only t))
  7288. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7289. (beginning-of-line 0))))))
  7290. (defun org-agenda-refile (&optional goto rfloc no-update)
  7291. "Refile the item at point."
  7292. (interactive "P")
  7293. (if (equal goto '(16))
  7294. (org-refile-goto-last-stored)
  7295. (let* ((buffer-orig (buffer-name))
  7296. (marker (or (org-get-at-bol 'org-hd-marker)
  7297. (org-agenda-error)))
  7298. (buffer (marker-buffer marker))
  7299. (pos (marker-position marker))
  7300. (rfloc (or rfloc
  7301. (org-refile-get-location
  7302. (if goto "Goto" "Refile to") buffer
  7303. org-refile-allow-creating-parent-nodes))))
  7304. (with-current-buffer buffer
  7305. (save-excursion
  7306. (save-restriction
  7307. (widen)
  7308. (goto-char marker)
  7309. (let ((org-agenda-buffer-name buffer-orig))
  7310. (org-remove-subtree-entries-from-agenda))
  7311. (org-refile goto buffer rfloc)))))
  7312. (unless no-update (org-agenda-redo))))
  7313. (defun org-agenda-open-link (&optional arg)
  7314. "Follow the link in the current line, if any.
  7315. This looks for a link in the displayed line in the agenda. It also looks
  7316. at the text of the entry itself."
  7317. (interactive "P")
  7318. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7319. (org-get-at-bol 'org-marker)))
  7320. (buffer (and marker (marker-buffer marker)))
  7321. (prefix (buffer-substring
  7322. (point-at-bol) (point-at-eol))))
  7323. (cond
  7324. (buffer
  7325. (with-current-buffer buffer
  7326. (save-excursion
  7327. (save-restriction
  7328. (widen)
  7329. (goto-char marker)
  7330. (org-offer-links-in-entry arg prefix)))))
  7331. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7332. (save-excursion
  7333. (beginning-of-line 1)
  7334. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7335. (org-open-link-from-string (match-string 1)))
  7336. (t (error "No link to open here")))))
  7337. (defun org-agenda-copy-local-variable (var)
  7338. "Get a variable from a referenced buffer and install it here."
  7339. (let ((m (org-get-at-bol 'org-marker)))
  7340. (when (and m (buffer-live-p (marker-buffer m)))
  7341. (org-set-local var (with-current-buffer (marker-buffer m)
  7342. (symbol-value var))))))
  7343. (defun org-agenda-switch-to (&optional delete-other-windows)
  7344. "Go to the Org-mode file which contains the item at point."
  7345. (interactive)
  7346. (if (and org-return-follows-link
  7347. (not (org-get-at-bol 'org-marker))
  7348. (org-in-regexp org-bracket-link-regexp))
  7349. (org-open-link-from-string (match-string 0))
  7350. (let* ((marker (or (org-get-at-bol 'org-marker)
  7351. (org-agenda-error)))
  7352. (buffer (marker-buffer marker))
  7353. (pos (marker-position marker)))
  7354. (org-pop-to-buffer-same-window buffer)
  7355. (and delete-other-windows (delete-other-windows))
  7356. (widen)
  7357. (goto-char pos)
  7358. (when (derived-mode-p 'org-mode)
  7359. (org-show-context 'agenda)
  7360. (save-excursion
  7361. (and (outline-next-heading)
  7362. (org-flag-heading nil))) ; show the next heading
  7363. (when (outline-invisible-p)
  7364. (show-entry)) ; display invisible text
  7365. (run-hooks 'org-agenda-after-show-hook)))))
  7366. (defun org-agenda-goto-mouse (ev)
  7367. "Go to the Org-mode file which contains the item at the mouse click."
  7368. (interactive "e")
  7369. (mouse-set-point ev)
  7370. (org-agenda-goto))
  7371. (defun org-agenda-show (&optional full-entry)
  7372. "Display the Org-mode file which contains the item at point.
  7373. With prefix argument FULL-ENTRY, make the entire entry visible
  7374. if it was hidden in the outline."
  7375. (interactive "P")
  7376. (let ((win (selected-window)))
  7377. (if full-entry
  7378. (let ((org-show-entry-below t))
  7379. (org-agenda-goto t))
  7380. (org-agenda-goto t))
  7381. (select-window win)))
  7382. (defvar org-agenda-show-window nil)
  7383. (defun org-agenda-show-and-scroll-up (&optional arg)
  7384. "Display the Org-mode file which contains the item at point.
  7385. When called repeatedly, scroll the window that is displaying the buffer.
  7386. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7387. `show-subtree' to display the item, so that drawers and logbooks stay
  7388. folded."
  7389. (interactive "P")
  7390. (let ((win (selected-window)))
  7391. (if (and (window-live-p org-agenda-show-window)
  7392. (eq this-command last-command))
  7393. (progn
  7394. (select-window org-agenda-show-window)
  7395. (ignore-errors (scroll-up)))
  7396. (org-agenda-goto t)
  7397. (if arg (org-show-entry) (show-subtree))
  7398. (setq org-agenda-show-window (selected-window)))
  7399. (select-window win)))
  7400. (defun org-agenda-show-scroll-down ()
  7401. "Scroll down the window showing the agenda."
  7402. (interactive)
  7403. (let ((win (selected-window)))
  7404. (when (window-live-p org-agenda-show-window)
  7405. (select-window org-agenda-show-window)
  7406. (ignore-errors (scroll-down))
  7407. (select-window win))))
  7408. (defun org-agenda-show-1 (&optional more)
  7409. "Display the Org-mode file which contains the item at point.
  7410. The prefix arg selects the amount of information to display:
  7411. 0 hide the subtree
  7412. 1 just show the entry according to defaults.
  7413. 2 show the children view
  7414. 3 show the subtree view
  7415. 4 show the entire subtree and any LOGBOOK drawers
  7416. 5 show the entire subtree and any drawers
  7417. With prefix argument FULL-ENTRY, make the entire entry visible
  7418. if it was hidden in the outline."
  7419. (interactive "p")
  7420. (let ((win (selected-window)))
  7421. (org-agenda-goto t)
  7422. (org-recenter-heading 1)
  7423. (cond
  7424. ((= more 0)
  7425. (hide-subtree)
  7426. (save-excursion
  7427. (org-back-to-heading)
  7428. (run-hook-with-args 'org-cycle-hook 'folded))
  7429. (message "Remote: FOLDED"))
  7430. ((and (org-called-interactively-p 'any) (= more 1))
  7431. (message "Remote: show with default settings"))
  7432. ((= more 2)
  7433. (show-entry)
  7434. (show-children)
  7435. (save-excursion
  7436. (org-back-to-heading)
  7437. (run-hook-with-args 'org-cycle-hook 'children))
  7438. (message "Remote: CHILDREN"))
  7439. ((= more 3)
  7440. (show-subtree)
  7441. (save-excursion
  7442. (org-back-to-heading)
  7443. (run-hook-with-args 'org-cycle-hook 'subtree))
  7444. (message "Remote: SUBTREE"))
  7445. ((= more 4)
  7446. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7447. (org-drawer-regexp
  7448. (concat "^[ \t]*:\\("
  7449. (mapconcat 'regexp-quote org-drawers "\\|")
  7450. "\\):[ \t]*$")))
  7451. (show-subtree)
  7452. (save-excursion
  7453. (org-back-to-heading)
  7454. (org-cycle-hide-drawers 'subtree)))
  7455. (message "Remote: SUBTREE AND LOGBOOK"))
  7456. ((> more 4)
  7457. (show-subtree)
  7458. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7459. (select-window win)))
  7460. (defun org-recenter-heading (n)
  7461. (save-excursion
  7462. (org-back-to-heading)
  7463. (recenter n)))
  7464. (defvar org-agenda-cycle-counter nil)
  7465. (defun org-agenda-cycle-show (&optional n)
  7466. "Show the current entry in another window, with default settings.
  7467. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7468. When use repeatedly in immediate succession, the remote entry will cycle
  7469. through visibility
  7470. children -> subtree -> folded
  7471. When called with a numeric prefix arg, that arg will be passed through to
  7472. `org-agenda-show-1'. For the interpretation of that argument, see the
  7473. docstring of `org-agenda-show-1'."
  7474. (interactive "P")
  7475. (if (integerp n)
  7476. (setq org-agenda-cycle-counter n)
  7477. (if (not (eq last-command this-command))
  7478. (setq org-agenda-cycle-counter 1)
  7479. (if (equal org-agenda-cycle-counter 0)
  7480. (setq org-agenda-cycle-counter 2)
  7481. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7482. (if (> org-agenda-cycle-counter 3)
  7483. (setq org-agenda-cycle-counter 0)))))
  7484. (org-agenda-show-1 org-agenda-cycle-counter))
  7485. (defun org-agenda-recenter (arg)
  7486. "Display the Org-mode file which contains the item at point and recenter."
  7487. (interactive "P")
  7488. (let ((win (selected-window)))
  7489. (org-agenda-goto t)
  7490. (recenter arg)
  7491. (select-window win)))
  7492. (defun org-agenda-show-mouse (ev)
  7493. "Display the Org-mode file which contains the item at the mouse click."
  7494. (interactive "e")
  7495. (mouse-set-point ev)
  7496. (org-agenda-show))
  7497. (defun org-agenda-check-no-diary ()
  7498. "Check if the entry is a diary link and abort if yes."
  7499. (if (org-get-at-bol 'org-agenda-diary-link)
  7500. (org-agenda-error)))
  7501. (defun org-agenda-error ()
  7502. (error "Command not allowed in this line"))
  7503. (defun org-agenda-tree-to-indirect-buffer (arg)
  7504. "Show the subtree corresponding to the current entry in an indirect buffer.
  7505. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7506. With a numerical prefix ARG, go up to this level and then take that tree.
  7507. With a negative numeric ARG, go up by this number of levels.
  7508. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7509. use the dedicated frame)."
  7510. (interactive "P")
  7511. (if current-prefix-arg
  7512. (org-agenda-do-tree-to-indirect-buffer arg)
  7513. (let ((agenda-buffer (buffer-name))
  7514. (agenda-window (selected-window))
  7515. (indirect-window
  7516. (and org-last-indirect-buffer
  7517. (get-buffer-window org-last-indirect-buffer))))
  7518. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7519. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7520. (eq org-indirect-buffer-display 'dedicated-frame))
  7521. (unwind-protect
  7522. (unless (and indirect-window (window-live-p indirect-window))
  7523. (setq indirect-window (split-window agenda-window)))
  7524. (and indirect-window (select-window indirect-window))
  7525. (switch-to-buffer org-last-indirect-buffer :norecord)
  7526. (fit-window-to-buffer indirect-window)))
  7527. (select-window (get-buffer-window agenda-buffer)))))
  7528. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7529. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7530. (org-agenda-check-no-diary)
  7531. (let* ((marker (or (org-get-at-bol 'org-marker)
  7532. (org-agenda-error)))
  7533. (buffer (marker-buffer marker))
  7534. (pos (marker-position marker)))
  7535. (with-current-buffer buffer
  7536. (save-excursion
  7537. (goto-char pos)
  7538. (funcall 'org-tree-to-indirect-buffer arg)))))
  7539. (defvar org-last-heading-marker (make-marker)
  7540. "Marker pointing to the headline that last changed its TODO state
  7541. by a remote command from the agenda.")
  7542. (defun org-agenda-todo-nextset ()
  7543. "Switch TODO entry to next sequence."
  7544. (interactive)
  7545. (org-agenda-todo 'nextset))
  7546. (defun org-agenda-todo-previousset ()
  7547. "Switch TODO entry to previous sequence."
  7548. (interactive)
  7549. (org-agenda-todo 'previousset))
  7550. (defun org-agenda-todo (&optional arg)
  7551. "Cycle TODO state of line at point, also in Org-mode file.
  7552. This changes the line at point, all other lines in the agenda referring to
  7553. the same tree node, and the headline of the tree node in the Org-mode file."
  7554. (interactive "P")
  7555. (org-agenda-check-no-diary)
  7556. (let* ((col (current-column))
  7557. (marker (or (org-get-at-bol 'org-marker)
  7558. (org-agenda-error)))
  7559. (buffer (marker-buffer marker))
  7560. (pos (marker-position marker))
  7561. (hdmarker (org-get-at-bol 'org-hd-marker))
  7562. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7563. (inhibit-read-only t)
  7564. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7565. (org-with-remote-undo buffer
  7566. (with-current-buffer buffer
  7567. (widen)
  7568. (goto-char pos)
  7569. (org-show-context 'agenda)
  7570. (save-excursion
  7571. (and (outline-next-heading)
  7572. (org-flag-heading nil))) ; show the next heading
  7573. (let ((current-prefix-arg arg))
  7574. (call-interactively 'org-todo))
  7575. (and (bolp) (forward-char 1))
  7576. (setq newhead (org-get-heading))
  7577. (when (and (org-bound-and-true-p
  7578. org-agenda-headline-snapshot-before-repeat)
  7579. (not (equal org-agenda-headline-snapshot-before-repeat
  7580. newhead))
  7581. todayp)
  7582. (setq newhead org-agenda-headline-snapshot-before-repeat
  7583. just-one t))
  7584. (save-excursion
  7585. (org-back-to-heading)
  7586. (move-marker org-last-heading-marker (point))))
  7587. (beginning-of-line 1)
  7588. (save-excursion
  7589. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7590. (org-move-to-column col))))
  7591. (defun org-agenda-add-note (&optional arg)
  7592. "Add a time-stamped note to the entry at point."
  7593. (interactive "P")
  7594. (org-agenda-check-no-diary)
  7595. (let* ((marker (or (org-get-at-bol 'org-marker)
  7596. (org-agenda-error)))
  7597. (buffer (marker-buffer marker))
  7598. (pos (marker-position marker))
  7599. (hdmarker (org-get-at-bol 'org-hd-marker))
  7600. (inhibit-read-only t))
  7601. (with-current-buffer buffer
  7602. (widen)
  7603. (goto-char pos)
  7604. (org-show-context 'agenda)
  7605. (save-excursion
  7606. (and (outline-next-heading)
  7607. (org-flag-heading nil))) ; show the next heading
  7608. (org-add-note))))
  7609. (defun org-agenda-change-all-lines (newhead hdmarker
  7610. &optional fixface just-this)
  7611. "Change all lines in the agenda buffer which match HDMARKER.
  7612. The new content of the line will be NEWHEAD (as modified by
  7613. `org-agenda-format-item'). HDMARKER is checked with
  7614. `equal' against all `org-hd-marker' text properties in the file.
  7615. If FIXFACE is non-nil, the face of each item is modified according to
  7616. the new TODO state.
  7617. If JUST-THIS is non-nil, change just the current line, not all.
  7618. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7619. (let* ((inhibit-read-only t)
  7620. (line (org-current-line))
  7621. (org-agenda-buffer (current-buffer))
  7622. (thetags (with-current-buffer (marker-buffer hdmarker)
  7623. (save-excursion (save-restriction (widen)
  7624. (goto-char hdmarker)
  7625. (org-get-tags-at)))))
  7626. props m pl undone-face done-face finish new dotime cat tags)
  7627. (save-excursion
  7628. (goto-char (point-max))
  7629. (beginning-of-line 1)
  7630. (while (not finish)
  7631. (setq finish (bobp))
  7632. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7633. (or (not just-this) (= (org-current-line) line))
  7634. (equal m hdmarker))
  7635. (setq props (text-properties-at (point))
  7636. dotime (org-get-at-bol 'dotime)
  7637. cat (org-get-at-bol 'org-category)
  7638. tags thetags
  7639. new
  7640. (let ((org-prefix-format-compiled
  7641. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7642. org-prefix-format-compiled))
  7643. (extra (org-get-at-bol 'extra)))
  7644. (with-current-buffer (marker-buffer hdmarker)
  7645. (save-excursion
  7646. (save-restriction
  7647. (widen)
  7648. (org-agenda-format-item extra newhead cat tags dotime)))))
  7649. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7650. undone-face (org-get-at-bol 'undone-face)
  7651. done-face (org-get-at-bol 'done-face))
  7652. (beginning-of-line 1)
  7653. (cond
  7654. ((equal new "")
  7655. (and (looking-at ".*\n?") (replace-match "")))
  7656. ((looking-at ".*")
  7657. (replace-match new t t)
  7658. (beginning-of-line 1)
  7659. (add-text-properties (point-at-bol) (point-at-eol) props)
  7660. (when fixface
  7661. (add-text-properties
  7662. (point-at-bol) (point-at-eol)
  7663. (list 'face
  7664. (if org-last-todo-state-is-todo
  7665. undone-face done-face))))
  7666. (org-agenda-highlight-todo 'line)
  7667. (beginning-of-line 1))
  7668. (t (error "Line update did not work")))
  7669. (save-restriction
  7670. (narrow-to-region (point-at-bol) (point-at-eol))
  7671. (org-agenda-finalize)))
  7672. (beginning-of-line 0)))))
  7673. (defun org-agenda-align-tags (&optional line)
  7674. "Align all tags in agenda items to `org-agenda-tags-column'."
  7675. (let ((inhibit-read-only t) l c)
  7676. (save-excursion
  7677. (goto-char (if line (point-at-bol) (point-min)))
  7678. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7679. (if line (point-at-eol) nil) t)
  7680. (add-text-properties
  7681. (match-beginning 2) (match-end 2)
  7682. (list 'face (delq nil (let ((prop (get-text-property
  7683. (match-beginning 2) 'face)))
  7684. (or (listp prop) (setq prop (list prop)))
  7685. (if (memq 'org-tag prop)
  7686. prop
  7687. (cons 'org-tag prop))))))
  7688. (setq l (- (match-end 2) (match-beginning 2))
  7689. c (if (< org-agenda-tags-column 0)
  7690. (- (abs org-agenda-tags-column) l)
  7691. org-agenda-tags-column))
  7692. (delete-region (match-beginning 1) (match-end 1))
  7693. (goto-char (match-beginning 1))
  7694. (insert (org-add-props
  7695. (make-string (max 1 (- c (current-column))) ?\ )
  7696. (plist-put (copy-sequence (text-properties-at (point)))
  7697. 'face nil))))
  7698. (goto-char (point-min))
  7699. (org-font-lock-add-tag-faces (point-max)))))
  7700. (defun org-agenda-priority-up ()
  7701. "Increase the priority of line at point, also in Org-mode file."
  7702. (interactive)
  7703. (org-agenda-priority 'up))
  7704. (defun org-agenda-priority-down ()
  7705. "Decrease the priority of line at point, also in Org-mode file."
  7706. (interactive)
  7707. (org-agenda-priority 'down))
  7708. (defun org-agenda-priority (&optional force-direction show)
  7709. "Set the priority of line at point, also in Org-mode file.
  7710. This changes the line at point, all other lines in the agenda referring to
  7711. the same tree node, and the headline of the tree node in the Org-mode file."
  7712. (interactive "P")
  7713. (if (equal force-direction '(4)) (setq show t))
  7714. (unless org-enable-priority-commands
  7715. (error "Priority commands are disabled"))
  7716. (org-agenda-check-no-diary)
  7717. (let* ((marker (or (org-get-at-bol 'org-marker)
  7718. (org-agenda-error)))
  7719. (hdmarker (org-get-at-bol 'org-hd-marker))
  7720. (buffer (marker-buffer hdmarker))
  7721. (pos (marker-position hdmarker))
  7722. (inhibit-read-only t)
  7723. newhead)
  7724. (org-with-remote-undo buffer
  7725. (with-current-buffer buffer
  7726. (widen)
  7727. (goto-char pos)
  7728. (org-show-context 'agenda)
  7729. (save-excursion
  7730. (and (outline-next-heading)
  7731. (org-flag-heading nil))) ; show the next heading
  7732. (funcall 'org-priority force-direction show)
  7733. (end-of-line 1)
  7734. (setq newhead (org-get-heading)))
  7735. (org-agenda-change-all-lines newhead hdmarker)
  7736. (beginning-of-line 1))))
  7737. ;; FIXME: should fix the tags property of the agenda line.
  7738. (defun org-agenda-set-tags (&optional tag onoff)
  7739. "Set tags for the current headline."
  7740. (interactive)
  7741. (org-agenda-check-no-diary)
  7742. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7743. (call-interactively 'org-change-tag-in-region)
  7744. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7745. (org-agenda-error)))
  7746. (buffer (marker-buffer hdmarker))
  7747. (pos (marker-position hdmarker))
  7748. (inhibit-read-only t)
  7749. newhead)
  7750. (org-with-remote-undo buffer
  7751. (with-current-buffer buffer
  7752. (widen)
  7753. (goto-char pos)
  7754. (save-excursion
  7755. (org-show-context 'agenda))
  7756. (save-excursion
  7757. (and (outline-next-heading)
  7758. (org-flag-heading nil))) ; show the next heading
  7759. (goto-char pos)
  7760. (if tag
  7761. (org-toggle-tag tag onoff)
  7762. (call-interactively 'org-set-tags))
  7763. (end-of-line 1)
  7764. (setq newhead (org-get-heading)))
  7765. (org-agenda-change-all-lines newhead hdmarker)
  7766. (beginning-of-line 1)))))
  7767. (defun org-agenda-set-property ()
  7768. "Set a property for the current headline."
  7769. (interactive)
  7770. (org-agenda-check-no-diary)
  7771. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7772. (org-agenda-error)))
  7773. (buffer (marker-buffer hdmarker))
  7774. (pos (marker-position hdmarker))
  7775. (inhibit-read-only t)
  7776. newhead)
  7777. (org-with-remote-undo buffer
  7778. (with-current-buffer buffer
  7779. (widen)
  7780. (goto-char pos)
  7781. (save-excursion
  7782. (org-show-context 'agenda))
  7783. (save-excursion
  7784. (and (outline-next-heading)
  7785. (org-flag-heading nil))) ; show the next heading
  7786. (goto-char pos)
  7787. (call-interactively 'org-set-property)))))
  7788. (defun org-agenda-set-effort ()
  7789. "Set the effort property for the current headline."
  7790. (interactive)
  7791. (org-agenda-check-no-diary)
  7792. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7793. (org-agenda-error)))
  7794. (buffer (marker-buffer hdmarker))
  7795. (pos (marker-position hdmarker))
  7796. (inhibit-read-only t)
  7797. newhead)
  7798. (org-with-remote-undo buffer
  7799. (with-current-buffer buffer
  7800. (widen)
  7801. (goto-char pos)
  7802. (save-excursion
  7803. (org-show-context 'agenda))
  7804. (save-excursion
  7805. (and (outline-next-heading)
  7806. (org-flag-heading nil))) ; show the next heading
  7807. (goto-char pos)
  7808. (call-interactively 'org-set-effort)
  7809. (end-of-line 1)
  7810. (setq newhead (org-get-heading)))
  7811. (org-agenda-change-all-lines newhead hdmarker))))
  7812. (defun org-agenda-toggle-archive-tag ()
  7813. "Toggle the archive tag for the current entry."
  7814. (interactive)
  7815. (org-agenda-check-no-diary)
  7816. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7817. (org-agenda-error)))
  7818. (buffer (marker-buffer hdmarker))
  7819. (pos (marker-position hdmarker))
  7820. (inhibit-read-only t)
  7821. newhead)
  7822. (org-with-remote-undo buffer
  7823. (with-current-buffer buffer
  7824. (widen)
  7825. (goto-char pos)
  7826. (org-show-context 'agenda)
  7827. (save-excursion
  7828. (and (outline-next-heading)
  7829. (org-flag-heading nil))) ; show the next heading
  7830. (call-interactively 'org-toggle-archive-tag)
  7831. (end-of-line 1)
  7832. (setq newhead (org-get-heading)))
  7833. (org-agenda-change-all-lines newhead hdmarker)
  7834. (beginning-of-line 1))))
  7835. (defun org-agenda-do-date-later (arg)
  7836. (interactive "P")
  7837. (cond
  7838. ((or (equal arg '(16))
  7839. (memq last-command
  7840. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7841. (setq this-command 'org-agenda-date-later-minutes)
  7842. (org-agenda-date-later-minutes 1))
  7843. ((or (equal arg '(4))
  7844. (memq last-command
  7845. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7846. (setq this-command 'org-agenda-date-later-hours)
  7847. (org-agenda-date-later-hours 1))
  7848. (t
  7849. (org-agenda-date-later (prefix-numeric-value arg)))))
  7850. (defun org-agenda-do-date-earlier (arg)
  7851. (interactive "P")
  7852. (cond
  7853. ((or (equal arg '(16))
  7854. (memq last-command
  7855. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7856. (setq this-command 'org-agenda-date-earlier-minutes)
  7857. (org-agenda-date-earlier-minutes 1))
  7858. ((or (equal arg '(4))
  7859. (memq last-command
  7860. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7861. (setq this-command 'org-agenda-date-earlier-hours)
  7862. (org-agenda-date-earlier-hours 1))
  7863. (t
  7864. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7865. (defun org-agenda-date-later (arg &optional what)
  7866. "Change the date of this item to ARG day(s) later."
  7867. (interactive "p")
  7868. (org-agenda-check-type t 'agenda 'timeline)
  7869. (org-agenda-check-no-diary)
  7870. (let* ((marker (or (org-get-at-bol 'org-marker)
  7871. (org-agenda-error)))
  7872. (buffer (marker-buffer marker))
  7873. (pos (marker-position marker))
  7874. cdate today)
  7875. (org-with-remote-undo buffer
  7876. (with-current-buffer buffer
  7877. (widen)
  7878. (goto-char pos)
  7879. (if (not (org-at-timestamp-p))
  7880. (error "Cannot find time stamp"))
  7881. (when (and org-agenda-move-date-from-past-immediately-to-today
  7882. (equal arg 1)
  7883. (or (not what) (eq what 'day))
  7884. (not (save-match-data (org-at-date-range-p))))
  7885. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7886. cdate (calendar-absolute-from-gregorian
  7887. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7888. today (org-today))
  7889. (if (> today cdate)
  7890. ;; immediately shift to today
  7891. (setq arg (- today cdate))))
  7892. (org-timestamp-change arg (or what 'day))
  7893. (when (and (org-at-date-range-p)
  7894. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7895. (let ((end org-last-changed-timestamp))
  7896. (org-timestamp-change arg (or what 'day))
  7897. (setq org-last-changed-timestamp
  7898. (concat org-last-changed-timestamp "--" end)))))
  7899. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7900. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7901. (defun org-agenda-date-earlier (arg &optional what)
  7902. "Change the date of this item to ARG day(s) earlier."
  7903. (interactive "p")
  7904. (org-agenda-date-later (- arg) what))
  7905. (defun org-agenda-date-later-minutes (arg)
  7906. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7907. (interactive "p")
  7908. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7909. (org-agenda-date-later arg 'minute))
  7910. (defun org-agenda-date-earlier-minutes (arg)
  7911. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7912. (interactive "p")
  7913. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7914. (org-agenda-date-earlier arg 'minute))
  7915. (defun org-agenda-date-later-hours (arg)
  7916. "Change the time of this item, in hour steps."
  7917. (interactive "p")
  7918. (org-agenda-date-later arg 'hour))
  7919. (defun org-agenda-date-earlier-hours (arg)
  7920. "Change the time of this item, in hour steps."
  7921. (interactive "p")
  7922. (org-agenda-date-earlier arg 'hour))
  7923. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7924. "Show new date stamp via text properties."
  7925. ;; We use text properties to make this undoable
  7926. (let ((inhibit-read-only t)
  7927. (buffer-invisibility-spec))
  7928. (setq stamp (concat " " prefix " => " stamp))
  7929. (save-excursion
  7930. (goto-char (point-max))
  7931. (while (not (bobp))
  7932. (when (equal marker (org-get-at-bol 'org-marker))
  7933. (org-move-to-column (- (window-width) (length stamp)) t)
  7934. (org-agenda-fix-tags-filter-overlays-at (point))
  7935. (if (featurep 'xemacs)
  7936. ;; Use `duplicable' property to trigger undo recording
  7937. (let ((ex (make-extent nil nil))
  7938. (gl (make-glyph stamp)))
  7939. (set-glyph-face gl 'secondary-selection)
  7940. (set-extent-properties
  7941. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7942. (insert-extent ex (1- (point)) (point-at-eol)))
  7943. (add-text-properties
  7944. (1- (point)) (point-at-eol)
  7945. (list 'display (org-add-props stamp nil
  7946. 'face 'secondary-selection))))
  7947. (beginning-of-line 1))
  7948. (beginning-of-line 0)))))
  7949. (defun org-agenda-date-prompt (arg)
  7950. "Change the date of this item. Date is prompted for, with default today.
  7951. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7952. be used to request time specification in the time stamp."
  7953. (interactive "P")
  7954. (org-agenda-check-type t 'agenda 'timeline)
  7955. (org-agenda-check-no-diary)
  7956. (let* ((marker (or (org-get-at-bol 'org-marker)
  7957. (org-agenda-error)))
  7958. (buffer (marker-buffer marker))
  7959. (pos (marker-position marker)))
  7960. (org-with-remote-undo buffer
  7961. (with-current-buffer buffer
  7962. (widen)
  7963. (goto-char pos)
  7964. (if (not (org-at-timestamp-p t))
  7965. (error "Cannot find time stamp"))
  7966. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7967. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7968. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7969. (defun org-agenda-schedule (arg &optional time)
  7970. "Schedule the item at point.
  7971. ARG is passed through to `org-schedule'."
  7972. (interactive "P")
  7973. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7974. (org-agenda-check-no-diary)
  7975. (let* ((marker (or (org-get-at-bol 'org-marker)
  7976. (org-agenda-error)))
  7977. (type (marker-insertion-type marker))
  7978. (buffer (marker-buffer marker))
  7979. (pos (marker-position marker))
  7980. (org-insert-labeled-timestamps-at-point nil)
  7981. ts)
  7982. (set-marker-insertion-type marker t)
  7983. (org-with-remote-undo buffer
  7984. (with-current-buffer buffer
  7985. (widen)
  7986. (goto-char pos)
  7987. (setq ts (org-schedule arg time)))
  7988. (org-agenda-show-new-time marker ts "S"))
  7989. (message "Item scheduled for %s" ts)))
  7990. (defun org-agenda-deadline (arg &optional time)
  7991. "Schedule the item at point.
  7992. ARG is passed through to `org-deadline'."
  7993. (interactive "P")
  7994. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7995. (org-agenda-check-no-diary)
  7996. (let* ((marker (or (org-get-at-bol 'org-marker)
  7997. (org-agenda-error)))
  7998. (buffer (marker-buffer marker))
  7999. (pos (marker-position marker))
  8000. (org-insert-labeled-timestamps-at-point nil)
  8001. ts)
  8002. (org-with-remote-undo buffer
  8003. (with-current-buffer buffer
  8004. (widen)
  8005. (goto-char pos)
  8006. (setq ts (org-deadline arg time)))
  8007. (org-agenda-show-new-time marker ts "D"))
  8008. (message "Deadline for this item set to %s" ts)))
  8009. (defun org-agenda-clock-in (&optional arg)
  8010. "Start the clock on the currently selected item."
  8011. (interactive "P")
  8012. (org-agenda-check-no-diary)
  8013. (if (equal arg '(4))
  8014. (org-clock-in arg)
  8015. (let* ((marker (or (org-get-at-bol 'org-marker)
  8016. (org-agenda-error)))
  8017. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8018. marker))
  8019. (pos (marker-position marker))
  8020. newhead)
  8021. (org-with-remote-undo (marker-buffer marker)
  8022. (with-current-buffer (marker-buffer marker)
  8023. (widen)
  8024. (goto-char pos)
  8025. (org-show-context 'agenda)
  8026. (org-show-entry)
  8027. (org-cycle-hide-drawers 'children)
  8028. (org-clock-in arg)
  8029. (setq newhead (org-get-heading)))
  8030. (org-agenda-change-all-lines newhead hdmarker)))))
  8031. (defun org-agenda-clock-out ()
  8032. "Stop the currently running clock."
  8033. (interactive)
  8034. (unless (marker-buffer org-clock-marker)
  8035. (error "No running clock"))
  8036. (let ((marker (make-marker)) newhead)
  8037. (org-with-remote-undo (marker-buffer org-clock-marker)
  8038. (with-current-buffer (marker-buffer org-clock-marker)
  8039. (save-excursion
  8040. (save-restriction
  8041. (widen)
  8042. (goto-char org-clock-marker)
  8043. (org-back-to-heading t)
  8044. (move-marker marker (point))
  8045. (org-clock-out)
  8046. (setq newhead (org-get-heading))))))
  8047. (org-agenda-change-all-lines newhead marker)
  8048. (move-marker marker nil)))
  8049. (defun org-agenda-clock-cancel (&optional arg)
  8050. "Cancel the currently running clock."
  8051. (interactive "P")
  8052. (unless (marker-buffer org-clock-marker)
  8053. (error "No running clock"))
  8054. (org-with-remote-undo (marker-buffer org-clock-marker)
  8055. (org-clock-cancel)))
  8056. (defun org-agenda-clock-goto ()
  8057. "Jump to the currently clocked in task within the agenda.
  8058. If the currently clocked in task is not listed in the agenda
  8059. buffer, display it in another window."
  8060. (interactive)
  8061. (let (pos)
  8062. (mapc (lambda (o)
  8063. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8064. (setq pos (overlay-start o))))
  8065. (overlays-in (point-min) (point-max)))
  8066. (cond (pos (goto-char pos))
  8067. ;; If the currently clocked entry is not in the agenda
  8068. ;; buffer, we visit it in another window:
  8069. (org-clock-current-task
  8070. (org-switch-to-buffer-other-window (org-clock-goto)))
  8071. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8072. (defun org-agenda-diary-entry-in-org-file ()
  8073. "Make a diary entry in the file `org-agenda-diary-file'."
  8074. (let (d1 d2 char (text "") dp1 dp2)
  8075. (if (equal (buffer-name) "*Calendar*")
  8076. (setq d1 (calendar-cursor-to-date t)
  8077. d2 (car calendar-mark-ring))
  8078. (setq dp1 (get-text-property (point-at-bol) 'day))
  8079. (unless dp1 (error "No date defined in current line"))
  8080. (setq d1 (calendar-gregorian-from-absolute dp1)
  8081. d2 (and (ignore-errors (mark))
  8082. (save-excursion
  8083. (goto-char (mark))
  8084. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8085. (calendar-gregorian-from-absolute dp2))))
  8086. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8087. (setq char (read-char-exclusive))
  8088. (cond
  8089. ((equal char ?d)
  8090. (setq text (read-string "Day entry: "))
  8091. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8092. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8093. ((equal char ?a)
  8094. (setq d1 (list (car d1) (nth 1 d1)
  8095. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8096. (nth 2 d1))))
  8097. (setq text (read-string "Anniversary (use %d to show years): "))
  8098. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8099. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8100. ((equal char ?b)
  8101. (setq text (read-string "Block entry: "))
  8102. (unless (and d1 d2 (not (equal d1 d2)))
  8103. (error "No block of days selected"))
  8104. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8105. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8106. ((equal char ?j)
  8107. (org-switch-to-buffer-other-window
  8108. (find-file-noselect org-agenda-diary-file))
  8109. (require 'org-datetree)
  8110. (org-datetree-find-date-create d1)
  8111. (org-reveal t))
  8112. (t (error "Invalid selection character `%c'" char)))))
  8113. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8114. "Where in `org-agenda-diary-file' should new entries be added?
  8115. Valid values:
  8116. date-tree in the date tree, as child of the date
  8117. top-level as top-level entries at the end of the file."
  8118. :group 'org-agenda
  8119. :type '(choice
  8120. (const :tag "in a date tree" date-tree)
  8121. (const :tag "as top level at end of file" top-level)))
  8122. (defcustom org-agenda-insert-diary-extract-time nil
  8123. "Non-nil means extract any time specification from the diary entry."
  8124. :group 'org-agenda
  8125. :version "24.1"
  8126. :type 'boolean)
  8127. (defcustom org-agenda-bulk-mark-char ">"
  8128. "A single-character string to be used as the bulk mark."
  8129. :group 'org-agenda
  8130. :version "24.1"
  8131. :type 'string)
  8132. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8133. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8134. If TEXT is not empty, it will become the headline of the new entry, and
  8135. the resulting entry will not be shown. When TEXT is empty, switch to
  8136. `org-agenda-diary-file' and let the user finish the entry there."
  8137. (let ((cw (current-window-configuration)))
  8138. (org-switch-to-buffer-other-window
  8139. (find-file-noselect org-agenda-diary-file))
  8140. (widen)
  8141. (goto-char (point-min))
  8142. (cond
  8143. ((eq type 'anniversary)
  8144. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8145. (progn
  8146. (or (org-at-heading-p t)
  8147. (progn
  8148. (outline-next-heading)
  8149. (insert "* Anniversaries\n\n")
  8150. (beginning-of-line -1)))))
  8151. (outline-next-heading)
  8152. (org-back-over-empty-lines)
  8153. (backward-char 1)
  8154. (insert "\n")
  8155. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8156. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8157. ((eq type 'day)
  8158. (let ((org-prefix-has-time t)
  8159. (org-agenda-time-leading-zero t)
  8160. fmt time time2)
  8161. (if org-agenda-insert-diary-extract-time
  8162. ;; Use org-agenda-format-item to parse text for a time-range and
  8163. ;; remove it. FIXME: This is a hack, we should refactor
  8164. ;; that function to make time extraction available separately
  8165. (setq fmt (org-agenda-format-item nil text nil nil t)
  8166. time (get-text-property 0 'time fmt)
  8167. time2 (if (> (length time) 0)
  8168. ;; split-string removes trailing ...... if
  8169. ;; no end time given. First space
  8170. ;; separates time from date.
  8171. (concat " " (car (split-string time "\\.")))
  8172. nil)
  8173. text (get-text-property 0 'txt fmt)))
  8174. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8175. (org-agenda-insert-diary-as-top-level text)
  8176. (require 'org-datetree)
  8177. (org-datetree-find-date-create d1)
  8178. (org-agenda-insert-diary-make-new-entry text))
  8179. (org-insert-time-stamp (org-time-from-absolute
  8180. (calendar-absolute-from-gregorian d1))
  8181. nil nil nil nil time2))
  8182. (end-of-line 0))
  8183. ((eq type 'block)
  8184. (if (> (calendar-absolute-from-gregorian d1)
  8185. (calendar-absolute-from-gregorian d2))
  8186. (setq d1 (prog1 d2 (setq d2 d1))))
  8187. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8188. (org-agenda-insert-diary-as-top-level text)
  8189. (require 'org-datetree)
  8190. (org-datetree-find-date-create d1)
  8191. (org-agenda-insert-diary-make-new-entry text))
  8192. (org-insert-time-stamp (org-time-from-absolute
  8193. (calendar-absolute-from-gregorian d1)))
  8194. (insert "--")
  8195. (org-insert-time-stamp (org-time-from-absolute
  8196. (calendar-absolute-from-gregorian d2)))
  8197. (end-of-line 0)))
  8198. (if (string-match "\\S-" text)
  8199. (progn
  8200. (set-window-configuration cw)
  8201. (message "%s entry added to %s"
  8202. (capitalize (symbol-name type))
  8203. (abbreviate-file-name org-agenda-diary-file)))
  8204. (org-reveal t)
  8205. (message "Please finish entry here"))))
  8206. (defun org-agenda-insert-diary-as-top-level (text)
  8207. "Make new entry as a top-level entry at the end of the file.
  8208. Add TEXT as headline, and position the cursor in the second line so that
  8209. a timestamp can be added there."
  8210. (widen)
  8211. (goto-char (point-max))
  8212. (or (bolp) (insert "\n"))
  8213. (insert "* " text "\n")
  8214. (if org-adapt-indentation (org-indent-to-column 2)))
  8215. (defun org-agenda-insert-diary-make-new-entry (text)
  8216. "Make new entry as last child of current entry.
  8217. Add TEXT as headline, and position the cursor in the second line so that
  8218. a timestamp can be added there."
  8219. (let ((org-show-following-heading t)
  8220. (org-show-siblings t)
  8221. (org-show-hierarchy-above t)
  8222. (org-show-entry-below t)
  8223. col)
  8224. (outline-next-heading)
  8225. (org-back-over-empty-lines)
  8226. (or (looking-at "[ \t]*$")
  8227. (progn (insert "\n") (backward-char 1)))
  8228. (org-insert-heading nil t)
  8229. (org-do-demote)
  8230. (setq col (current-column))
  8231. (insert text "\n")
  8232. (if org-adapt-indentation (org-indent-to-column col))
  8233. (let ((org-show-following-heading t)
  8234. (org-show-siblings t)
  8235. (org-show-hierarchy-above t)
  8236. (org-show-entry-below t))
  8237. (org-show-context))))
  8238. (defun org-agenda-diary-entry ()
  8239. "Make a diary entry, like the `i' command from the calendar.
  8240. All the standard commands work: block, weekly etc.
  8241. When `org-agenda-diary-file' points to a file,
  8242. `org-agenda-diary-entry-in-org-file' is called instead to create
  8243. entries in that Org-mode file."
  8244. (interactive)
  8245. (if (not (eq org-agenda-diary-file 'diary-file))
  8246. (org-agenda-diary-entry-in-org-file)
  8247. (require 'diary-lib)
  8248. (let* ((char (progn
  8249. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8250. (read-char-exclusive)))
  8251. (cmd (cdr (assoc char
  8252. '((?d . insert-diary-entry)
  8253. (?w . insert-weekly-diary-entry)
  8254. (?m . insert-monthly-diary-entry)
  8255. (?y . insert-yearly-diary-entry)
  8256. (?a . insert-anniversary-diary-entry)
  8257. (?b . insert-block-diary-entry)
  8258. (?c . insert-cyclic-diary-entry)))))
  8259. (oldf (symbol-function 'calendar-cursor-to-date))
  8260. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8261. (point (point))
  8262. (mark (or (mark t) (point))))
  8263. (unless cmd
  8264. (error "No command associated with <%c>" char))
  8265. (unless (and (get-text-property point 'day)
  8266. (or (not (equal ?b char))
  8267. (get-text-property mark 'day)))
  8268. (error "Don't know which date to use for diary entry"))
  8269. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8270. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8271. (let ((calendar-mark-ring
  8272. (list (calendar-gregorian-from-absolute
  8273. (or (get-text-property mark 'day)
  8274. (get-text-property point 'day))))))
  8275. (unwind-protect
  8276. (progn
  8277. (fset 'calendar-cursor-to-date
  8278. (lambda (&optional error dummy)
  8279. (calendar-gregorian-from-absolute
  8280. (get-text-property point 'day))))
  8281. (call-interactively cmd))
  8282. (fset 'calendar-cursor-to-date oldf))))))
  8283. (defun org-agenda-execute-calendar-command (cmd)
  8284. "Execute a calendar command from the agenda with date from cursor."
  8285. (org-agenda-check-type t 'agenda 'timeline)
  8286. (require 'diary-lib)
  8287. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8288. (error "Don't know which date to use for the calendar command"))
  8289. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8290. (point (point))
  8291. (date (calendar-gregorian-from-absolute
  8292. (get-text-property point 'day)))
  8293. ;; the following 2 vars are needed in the calendar
  8294. (displayed-month (car date))
  8295. (displayed-year (nth 2 date)))
  8296. (unwind-protect
  8297. (progn
  8298. (fset 'calendar-cursor-to-date
  8299. (lambda (&optional error dummy)
  8300. (calendar-gregorian-from-absolute
  8301. (get-text-property point 'day))))
  8302. (call-interactively cmd))
  8303. (fset 'calendar-cursor-to-date oldf))))
  8304. (defun org-agenda-phases-of-moon ()
  8305. "Display the phases of the moon for the 3 months around the cursor date."
  8306. (interactive)
  8307. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8308. (defun org-agenda-holidays ()
  8309. "Display the holidays for the 3 months around the cursor date."
  8310. (interactive)
  8311. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8312. (defvar calendar-longitude) ; defined in calendar.el
  8313. (defvar calendar-latitude) ; defined in calendar.el
  8314. (defvar calendar-location-name) ; defined in calendar.el
  8315. (defun org-agenda-sunrise-sunset (arg)
  8316. "Display sunrise and sunset for the cursor date.
  8317. Latitude and longitude can be specified with the variables
  8318. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8319. argument, latitude and longitude will be prompted for."
  8320. (interactive "P")
  8321. (require 'solar)
  8322. (let ((calendar-longitude (if arg nil calendar-longitude))
  8323. (calendar-latitude (if arg nil calendar-latitude))
  8324. (calendar-location-name
  8325. (if arg "the given coordinates" calendar-location-name)))
  8326. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8327. (defun org-agenda-goto-calendar ()
  8328. "Open the Emacs calendar with the date at the cursor."
  8329. (interactive)
  8330. (org-agenda-check-type t 'agenda 'timeline)
  8331. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8332. (error "Don't know which date to open in calendar")))
  8333. (date (calendar-gregorian-from-absolute day))
  8334. (calendar-move-hook nil)
  8335. (calendar-view-holidays-initially-flag nil)
  8336. (calendar-view-diary-initially-flag nil))
  8337. (calendar)
  8338. (calendar-goto-date date)))
  8339. ;;;###autoload
  8340. (defun org-calendar-goto-agenda ()
  8341. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8342. This is a command that has to be installed in `calendar-mode-map'."
  8343. (interactive)
  8344. (org-agenda-list nil (calendar-absolute-from-gregorian
  8345. (calendar-cursor-to-date))
  8346. nil))
  8347. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8348. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8349. This is a command that has to be installed in `calendar-mode-map'.
  8350. \(fn)" t nil)
  8351. (defun org-agenda-convert-date ()
  8352. (interactive)
  8353. (org-agenda-check-type t 'agenda 'timeline)
  8354. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8355. date s)
  8356. (unless day
  8357. (error "Don't know which date to convert"))
  8358. (setq date (calendar-gregorian-from-absolute day))
  8359. (setq s (concat
  8360. "Gregorian: " (calendar-date-string date) "\n"
  8361. "ISO: " (calendar-iso-date-string date) "\n"
  8362. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8363. "Julian: " (calendar-julian-date-string date) "\n"
  8364. "Astron. JD: " (calendar-astro-date-string date)
  8365. " (Julian date number at noon UTC)\n"
  8366. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8367. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8368. "French: " (calendar-french-date-string date) "\n"
  8369. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8370. "Mayan: " (calendar-mayan-date-string date) "\n"
  8371. "Coptic: " (calendar-coptic-date-string date) "\n"
  8372. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8373. "Persian: " (calendar-persian-date-string date) "\n"
  8374. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8375. (with-output-to-temp-buffer "*Dates*"
  8376. (princ s))
  8377. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8378. ;;; Bulk commands
  8379. (defun org-agenda-bulk-marked-p ()
  8380. (eq (get-char-property (point-at-bol) 'type)
  8381. 'org-marked-entry-overlay))
  8382. (defun org-agenda-bulk-mark (&optional arg)
  8383. "Mark the entry at point for future bulk action."
  8384. (interactive "p")
  8385. (dotimes (i (or arg 1))
  8386. (unless (org-get-at-bol 'org-agenda-diary-link)
  8387. (let* ((m (org-get-at-bol 'org-hd-marker))
  8388. ov)
  8389. (unless (org-agenda-bulk-marked-p)
  8390. (unless m (error "Nothing to mark at point"))
  8391. (push m org-agenda-bulk-marked-entries)
  8392. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8393. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8394. (org-get-todo-face "TODO")
  8395. 'evaporate)
  8396. (overlay-put ov 'type 'org-marked-entry-overlay))
  8397. (beginning-of-line 2)
  8398. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8399. (beginning-of-line 2))
  8400. (message "%d entries marked for bulk action"
  8401. (length org-agenda-bulk-marked-entries))))))
  8402. (defun org-agenda-bulk-mark-all ()
  8403. "Mark all entries for future agenda bulk action."
  8404. (interactive)
  8405. (org-agenda-bulk-mark-regexp "."))
  8406. (defun org-agenda-bulk-mark-regexp (regexp)
  8407. "Mark entries matching REGEXP for future agenda bulk action."
  8408. (interactive "sMark entries matching regexp: ")
  8409. (let ((entries-marked 0))
  8410. (save-excursion
  8411. (goto-char (point-min))
  8412. (goto-char (next-single-property-change (point) 'txt))
  8413. (while (re-search-forward regexp nil t)
  8414. (when (string-match regexp (get-text-property (point) 'txt))
  8415. (setq entries-marked (1+ entries-marked))
  8416. (call-interactively 'org-agenda-bulk-mark))))
  8417. (if (not entries-marked)
  8418. (message "No entry matching this regexp."))))
  8419. (defun org-agenda-bulk-unmark (&optional arg)
  8420. "Unmark the entry at point for future bulk action."
  8421. (interactive "P")
  8422. (if arg
  8423. (org-agenda-bulk-unmark-all)
  8424. (cond ((org-agenda-bulk-marked-p)
  8425. (org-agenda-bulk-remove-overlays
  8426. (point-at-bol) (+ 2 (point-at-bol)))
  8427. (setq org-agenda-bulk-marked-entries
  8428. (delete (org-get-at-bol 'org-hd-marker)
  8429. org-agenda-bulk-marked-entries))
  8430. (beginning-of-line 2)
  8431. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8432. (beginning-of-line 2))
  8433. (message "%d entries left marked for bulk action"
  8434. (length org-agenda-bulk-marked-entries)))
  8435. (t (message "No entry to unmark here")))))
  8436. (defun org-agenda-bulk-toggle ()
  8437. "Toggle marking the entry at point for bulk action."
  8438. (interactive)
  8439. (if (org-agenda-bulk-marked-p)
  8440. (org-agenda-bulk-unmark)
  8441. (org-agenda-bulk-mark)))
  8442. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8443. "Remove the mark overlays between BEG and END in the agenda buffer.
  8444. BEG and END default to the buffer limits.
  8445. This only removes the overlays, it does not remove the markers
  8446. from the list in `org-agenda-bulk-marked-entries'."
  8447. (interactive)
  8448. (mapc (lambda (ov)
  8449. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8450. (delete-overlay ov)))
  8451. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8452. (defun org-agenda-bulk-unmark-all ()
  8453. "Remove all marks in the agenda buffer.
  8454. This will remove the markers and the overlays."
  8455. (interactive)
  8456. (if (null org-agenda-bulk-marked-entries)
  8457. (message "No entry to unmark")
  8458. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8459. (setq org-agenda-bulk-marked-entries nil)
  8460. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8461. (defcustom org-agenda-persistent-marks nil
  8462. "Non-nil means marked items will stay marked after a bulk action.
  8463. You can toggle this interactively by typing `p' when prompted for a
  8464. bulk action."
  8465. :group 'org-agenda
  8466. :version "24.1"
  8467. :type 'boolean)
  8468. (defun org-agenda-bulk-action (&optional arg)
  8469. "Execute an remote-editing action on all marked entries.
  8470. The prefix arg is passed through to the command if possible."
  8471. (interactive "P")
  8472. ;; Make sure we have markers, and only valid ones
  8473. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8474. (mapc
  8475. (lambda (m)
  8476. (unless (and (markerp m)
  8477. (marker-buffer m)
  8478. (buffer-live-p (marker-buffer m))
  8479. (marker-position m))
  8480. (error "Marker %s for bulk command is invalid" m)))
  8481. org-agenda-bulk-marked-entries)
  8482. ;; Prompt for the bulk command
  8483. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8484. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8485. "[S]catter [f]unction "
  8486. (when org-agenda-bulk-custom-functions
  8487. (concat " Custom: ["
  8488. (mapconcat (lambda(f) (char-to-string (car f)))
  8489. org-agenda-bulk-custom-functions "")
  8490. "]"))))
  8491. (catch 'exit
  8492. (let* ((action (read-char-exclusive))
  8493. (org-log-refile (if org-log-refile 'time nil))
  8494. (entries (reverse org-agenda-bulk-marked-entries))
  8495. (org-overriding-default-time
  8496. (if (get-text-property (point) 'org-agenda-date-header)
  8497. (org-get-cursor-date)))
  8498. redo-at-end
  8499. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8500. (cond
  8501. ((equal action ?p)
  8502. (let ((org-agenda-persistent-marks
  8503. (not org-agenda-persistent-marks)))
  8504. (org-agenda-bulk-action)
  8505. (throw 'exit nil)))
  8506. ((equal action ?$)
  8507. (setq cmd '(org-agenda-archive)))
  8508. ((equal action ?A)
  8509. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8510. ((member action '(?r ?w))
  8511. (setq rfloc (org-refile-get-location
  8512. "Refile to"
  8513. (marker-buffer (car entries))
  8514. org-refile-allow-creating-parent-nodes))
  8515. (if (nth 3 rfloc)
  8516. (setcar (nthcdr 3 rfloc)
  8517. (move-marker (make-marker) (nth 3 rfloc)
  8518. (or (get-file-buffer (nth 1 rfloc))
  8519. (find-buffer-visiting (nth 1 rfloc))
  8520. (error "This should not happen")))))
  8521. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8522. redo-at-end t))
  8523. ((equal action ?t)
  8524. (setq state (org-icompleting-read
  8525. "Todo state: "
  8526. (with-current-buffer (marker-buffer (car entries))
  8527. (mapcar 'list org-todo-keywords-1))))
  8528. (setq cmd `(let ((org-inhibit-blocking t)
  8529. (org-inhibit-logging 'note))
  8530. (org-agenda-todo ,state))))
  8531. ((memq action '(?- ?+))
  8532. (setq tag (org-icompleting-read
  8533. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8534. (with-current-buffer (marker-buffer (car entries))
  8535. (delq nil
  8536. (mapcar (lambda (x)
  8537. (if (stringp (car x)) x)) org-tag-alist)))))
  8538. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8539. ((memq action '(?s ?d))
  8540. (let* ((time
  8541. (unless arg
  8542. (org-read-date
  8543. nil nil nil
  8544. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8545. org-overriding-default-time)))
  8546. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8547. (setq cmd `(eval '(,c1 arg ,time)))))
  8548. ((equal action ?S)
  8549. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8550. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8551. (let ((days (read-number
  8552. (format "Scatter tasks across how many %sdays: "
  8553. (if arg "week" "")) 7)))
  8554. (setq cmd
  8555. `(let ((distance (1+ (random ,days))))
  8556. (if arg
  8557. (let ((dist distance)
  8558. (day-of-week
  8559. (calendar-day-of-week
  8560. (calendar-gregorian-from-absolute (org-today)))))
  8561. (dotimes (i (1+ dist))
  8562. (while (member day-of-week org-agenda-weekend-days)
  8563. (incf distance)
  8564. (incf day-of-week)
  8565. (if (= day-of-week 7)
  8566. (setq day-of-week 0)))
  8567. (incf day-of-week)
  8568. (if (= day-of-week 7)
  8569. (setq day-of-week 0)))))
  8570. ;; silently fail when try to replan a sexp entry
  8571. (condition-case nil
  8572. (let* ((date (calendar-gregorian-from-absolute
  8573. (+ (org-today) distance)))
  8574. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8575. (nth 2 date))))
  8576. (org-agenda-schedule nil time))
  8577. (error nil)))))))
  8578. ((assoc action org-agenda-bulk-custom-functions)
  8579. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8580. redo-at-end t))
  8581. ((equal action ?f)
  8582. (setq cmd (list (intern
  8583. (org-icompleting-read "Function: "
  8584. obarray 'fboundp t nil nil)))))
  8585. (t (error "Invalid bulk action")))
  8586. ;; Sort the markers, to make sure that parents are handled before children
  8587. (setq entries (sort entries
  8588. (lambda (a b)
  8589. (cond
  8590. ((equal (marker-buffer a) (marker-buffer b))
  8591. (< (marker-position a) (marker-position b)))
  8592. (t
  8593. (string< (buffer-name (marker-buffer a))
  8594. (buffer-name (marker-buffer b))))))))
  8595. ;; Now loop over all markers and apply cmd
  8596. (while (setq e (pop entries))
  8597. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8598. (if (not pos)
  8599. (progn (message "Skipping removed entry at %s" e)
  8600. (setq cntskip (1+ cntskip)))
  8601. (goto-char pos)
  8602. (let (org-loop-over-headlines-in-active-region)
  8603. (eval cmd))
  8604. (setq cnt (1+ cnt))))
  8605. (when redo-at-end (org-agenda-redo))
  8606. (unless org-agenda-persistent-marks
  8607. (org-agenda-bulk-unmark-all))
  8608. (message "Acted on %d entries%s%s"
  8609. cnt
  8610. (if (= cntskip 0)
  8611. ""
  8612. (format ", skipped %d (disappeared before their turn)"
  8613. cntskip))
  8614. (if (not org-agenda-persistent-marks)
  8615. "" " (kept marked)"))))))
  8616. (defun org-agenda-capture ()
  8617. "Call `org-capture' with the date at point."
  8618. (interactive)
  8619. (if (not (eq major-mode 'org-agenda-mode))
  8620. (error "You cannot do this outside of agenda buffers")
  8621. (let ((org-overriding-default-time
  8622. (org-get-cursor-date)))
  8623. (call-interactively 'org-capture))))
  8624. ;;; Flagging notes
  8625. (defun org-agenda-show-the-flagging-note ()
  8626. "Display the flagging note in the other window.
  8627. When called a second time in direct sequence, offer to remove the FLAGGING
  8628. tag and (if present) the flagging note."
  8629. (interactive)
  8630. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8631. (win (selected-window))
  8632. note heading newhead)
  8633. (unless hdmarker
  8634. (error "No linked entry at point"))
  8635. (if (and (eq this-command last-command)
  8636. (y-or-n-p "Unflag and remove any flagging note? "))
  8637. (progn
  8638. (org-agenda-remove-flag hdmarker)
  8639. (let ((win (get-buffer-window "*Flagging Note*")))
  8640. (and win (delete-window win)))
  8641. (message "Entry unflagged"))
  8642. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8643. (unless note
  8644. (error "No flagging note"))
  8645. (org-kill-new note)
  8646. (org-switch-to-buffer-other-window "*Flagging Note*")
  8647. (erase-buffer)
  8648. (insert note)
  8649. (goto-char (point-min))
  8650. (while (re-search-forward "\\\\n" nil t)
  8651. (replace-match "\n" t t))
  8652. (goto-char (point-min))
  8653. (select-window win)
  8654. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8655. (defun org-agenda-remove-flag (marker)
  8656. "Remove the FLAGGED tag and any flagging note in the entry."
  8657. (let (newhead)
  8658. (org-with-point-at marker
  8659. (org-toggle-tag "FLAGGED" 'off)
  8660. (org-entry-delete nil "THEFLAGGINGNOTE")
  8661. (setq newhead (org-get-heading)))
  8662. (org-agenda-change-all-lines newhead marker)
  8663. (message "Entry unflagged")))
  8664. (defun org-agenda-get-any-marker (&optional pos)
  8665. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8666. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8667. ;;; Appointment reminders
  8668. (defvar appt-time-msg-list) ; defined in appt.el
  8669. ;;;###autoload
  8670. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8671. "Activate appointments found in `org-agenda-files'.
  8672. With a \\[universal-argument] prefix, refresh the list of
  8673. appointments.
  8674. If FILTER is t, interactively prompt the user for a regular
  8675. expression, and filter out entries that don't match it.
  8676. If FILTER is a string, use this string as a regular expression
  8677. for filtering entries out.
  8678. If FILTER is a function, filter out entries against which
  8679. calling the function returns nil. This function takes one
  8680. argument: an entry from `org-agenda-get-day-entries'.
  8681. FILTER can also be an alist with the car of each cell being
  8682. either 'headline or 'category. For example:
  8683. '((headline \"IMPORTANT\")
  8684. (category \"Work\"))
  8685. will only add headlines containing IMPORTANT or headlines
  8686. belonging to the \"Work\" category.
  8687. ARGS are symbols indicating what kind of entries to consider.
  8688. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8689. and :timestamp entries. See the docstring of `org-diary' for
  8690. details and examples.
  8691. If an entry as a APPT_WARNTIME property, its value will be used
  8692. to override `appt-message-warning-time'."
  8693. (interactive "P")
  8694. (if refresh (setq appt-time-msg-list nil))
  8695. (if (eq filter t)
  8696. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8697. (let* ((cnt 0) ; count added events
  8698. (scope (or args '(:deadline :scheduled :timestamp)))
  8699. (org-agenda-new-buffers nil)
  8700. (org-deadline-warning-days 0)
  8701. ;; Do not use `org-today' here because appt only takes
  8702. ;; time and without date as argument, so it may pass wrong
  8703. ;; information otherwise
  8704. (today (org-date-to-gregorian
  8705. (time-to-days (current-time))))
  8706. (org-agenda-restrict nil)
  8707. (files (org-agenda-files 'unrestricted)) entries file
  8708. (org-agenda-buffer nil))
  8709. ;; Get all entries which may contain an appt
  8710. (org-agenda-prepare-buffers files)
  8711. (while (setq file (pop files))
  8712. (setq entries
  8713. (delq nil
  8714. (append entries
  8715. (apply 'org-agenda-get-day-entries
  8716. file today scope)))))
  8717. ;; Map thru entries and find if we should filter them out
  8718. (mapc
  8719. (lambda(x)
  8720. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8721. (cat (get-text-property 1 'org-category x))
  8722. (tod (get-text-property 1 'time-of-day x))
  8723. (ok (or (null filter)
  8724. (and (stringp filter) (string-match filter evt))
  8725. (and (functionp filter) (funcall filter x))
  8726. (and (listp filter)
  8727. (let ((cat-filter (cadr (assoc 'category filter)))
  8728. (evt-filter (cadr (assoc 'headline filter))))
  8729. (or (and (stringp cat-filter)
  8730. (string-match cat-filter cat))
  8731. (and (stringp evt-filter)
  8732. (string-match evt-filter evt)))))))
  8733. (wrn (get-text-property 1 'warntime x)))
  8734. ;; FIXME: Shall we remove text-properties for the appt text?
  8735. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8736. (when (and ok tod)
  8737. (setq tod (concat "00" (number-to-string tod))
  8738. tod (when (string-match
  8739. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8740. (concat (match-string 1 tod) ":"
  8741. (match-string 2 tod))))
  8742. (if (version< emacs-version "23.3")
  8743. (appt-add tod evt)
  8744. (appt-add tod evt wrn))
  8745. (setq cnt (1+ cnt))))) entries)
  8746. (org-release-buffers org-agenda-new-buffers)
  8747. (if (eq cnt 0)
  8748. (message "No event to add")
  8749. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8750. (autoload 'org-agenda-to-appt "org-agenda" "\
  8751. Activate appointments found in `org-agenda-files'.
  8752. With a \\[universal-argument] prefix, refresh the list of
  8753. appointments.
  8754. If FILTER is t, interactively prompt the user for a regular
  8755. expression, and filter out entries that don't match it.
  8756. If FILTER is a string, use this string as a regular expression
  8757. for filtering entries out.
  8758. If FILTER is a function, filter out entries against which
  8759. calling the function returns nil. This function takes one
  8760. argument: an entry from `org-agenda-get-day-entries'.
  8761. FILTER can also be an alist with the car of each cell being
  8762. either 'headline or 'category. For example:
  8763. '((headline \"IMPORTANT\")
  8764. (category \"Work\"))
  8765. will only add headlines containing IMPORTANT or headlines
  8766. belonging to the \"Work\" category.
  8767. ARGS are symbols indicating what kind of entries to consider.
  8768. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8769. and :timestamp entries. See the docstring of `org-diary' for
  8770. details and examples.
  8771. If an entry as a APPT_WARNTIME property, its value will be used
  8772. to override `appt-message-warning-time'.
  8773. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8774. (defun org-agenda-todayp (date)
  8775. "Does DATE mean today, when considering `org-extend-today-until'?"
  8776. (let ((today (org-today))
  8777. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8778. date)))
  8779. (eq date today)))
  8780. (defun org-agenda-todo-yesterday (&optional arg)
  8781. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8782. (interactive "P")
  8783. (let* ((hour (third (decode-time
  8784. (org-current-time))))
  8785. (org-extend-today-until (1+ hour)))
  8786. (org-agenda-todo arg)))
  8787. (provide 'org-agenda)
  8788. ;; Local variables:
  8789. ;; generated-autoload-file: "org-loaddefs.el"
  8790. ;; End:
  8791. ;;; org-agenda.el ends here