org-agenda.el 323 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.7
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;
  26. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  27. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  28. ;; a conveniant way for extracting agenda information from the command
  29. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  30. ;; it is not necessary to quote the parameters passed to one of those
  31. ;; functions. E.g. you can write:
  32. ;;
  33. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  34. ;;
  35. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  36. ;; have been implemented as a regular function you'd have to quote the
  37. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  38. ;; value you would have to double quote the symbol.
  39. ;;
  40. ;; This is a hack, but it works even when running Org byte-compiled.
  41. ;;
  42. ;;; Code:
  43. (require 'org)
  44. (eval-when-compile
  45. (require 'cl))
  46. (declare-function diary-add-to-list "diary-lib"
  47. (date string specifier &optional marker globcolor literal))
  48. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  49. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  50. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  51. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  52. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-french-date-string "cal-french" (&optional date))
  55. (declare-function calendar-goto-date "cal-move" (date))
  56. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  57. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  58. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  59. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  60. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  61. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  62. (declare-function calendar-persian-date-string "cal-persia" (&optional 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. (defvar calendar-mode-map)
  76. (defvar org-clock-current-task) ; defined in org-clock.el
  77. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  78. (defvar org-habit-show-habits)
  79. (defvar org-habit-show-habits-only-for-today)
  80. ;; Defined somewhere in this file, but used before definition.
  81. (defvar org-agenda-buffer-name)
  82. (defvar org-agenda-overriding-header)
  83. (defvar org-agenda-title-append nil)
  84. (defvar entry)
  85. (defvar date)
  86. (defvar org-agenda-undo-list)
  87. (defvar org-agenda-pending-undo-list)
  88. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  89. (defcustom org-agenda-confirm-kill 1
  90. "When set, remote killing from the agenda buffer needs confirmation.
  91. When t, a confirmation is always needed. When a number N, confirmation is
  92. only needed when the text to be killed contains more than N non-white lines."
  93. :group 'org-agenda
  94. :type '(choice
  95. (const :tag "Never" nil)
  96. (const :tag "Always" t)
  97. (integer :tag "When more than N lines")))
  98. (defcustom org-agenda-compact-blocks nil
  99. "Non-nil means make the block agenda more compact.
  100. This is done globally by leaving out lines like the agenda span
  101. name and week number or the separator lines."
  102. :group 'org-agenda
  103. :type 'boolean)
  104. (defcustom org-agenda-block-separator ?=
  105. "The separator between blocks in the agenda.
  106. If this is a string, it will be used as the separator, with a newline added.
  107. If it is a character, it will be repeated to fill the window width.
  108. If nil the separator is disabled. In `org-agenda-custom-commands' this
  109. addresses the separator between the current and the previous block."
  110. :group 'org-agenda
  111. :type '(choice
  112. (const :tag "Disabled" nil)
  113. (character)
  114. (string)))
  115. (defgroup org-agenda-export nil
  116. "Options concerning exporting agenda views in Org-mode."
  117. :tag "Org Agenda Export"
  118. :group 'org-agenda)
  119. (defcustom org-agenda-with-colors t
  120. "Non-nil means use colors in agenda views."
  121. :group 'org-agenda-export
  122. :type 'boolean)
  123. (defcustom org-agenda-exporter-settings nil
  124. "Alist of variable/value pairs that should be active during agenda export.
  125. This is a good place to set options for ps-print and for htmlize.
  126. Note that the way this is implemented, the values will be evaluated
  127. before assigned to the variables. So make sure to quote values you do
  128. *not* want evaluated, for example
  129. (setq org-agenda-exporter-settings
  130. '((ps-print-color-p 'black-white)))"
  131. :group 'org-agenda-export
  132. :type '(repeat
  133. (list
  134. (variable)
  135. (sexp :tag "Value"))))
  136. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  137. "Hook run in temporary buffer before writing it to an export file.
  138. A useful function is `org-agenda-add-entry-text'."
  139. :group 'org-agenda-export
  140. :type 'hook
  141. :options '(org-agenda-add-entry-text))
  142. (defcustom org-agenda-add-entry-text-maxlines 0
  143. "Maximum number of entry text lines to be added to agenda.
  144. This is only relevant when `org-agenda-add-entry-text' is part of
  145. `org-agenda-before-write-hook', which it is by default.
  146. When this is 0, nothing will happen. When it is greater than 0, it
  147. specifies the maximum number of lines that will be added for each entry
  148. that is listed in the agenda view.
  149. Note that this variable is not used during display, only when exporting
  150. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  151. and `org-agenda-entry-text-maxlines'."
  152. :group 'org-agenda
  153. :type 'integer)
  154. (defcustom org-agenda-add-entry-text-descriptive-links t
  155. "Non-nil means export org-links as descriptive links in agenda added text.
  156. This variable applies to the text added to the agenda when
  157. `org-agenda-add-entry-text-maxlines' is larger than 0.
  158. When this variable nil, the URL will (also) be shown."
  159. :group 'org-agenda
  160. :type 'boolean)
  161. (defcustom org-agenda-export-html-style ""
  162. "The style specification for exported HTML Agenda files.
  163. If this variable contains a string, it will replace the default <style>
  164. section as produced by `htmlize'.
  165. Since there are different ways of setting style information, this variable
  166. needs to contain the full HTML structure to provide a style, including the
  167. surrounding HTML tags. The style specifications should include definitions
  168. the fonts used by the agenda, here is an example:
  169. <style type=\"text/css\">
  170. p { font-weight: normal; color: gray; }
  171. .org-agenda-structure {
  172. font-size: 110%;
  173. color: #003399;
  174. font-weight: 600;
  175. }
  176. .org-todo {
  177. color: #cc6666;
  178. font-weight: bold;
  179. }
  180. .org-agenda-done {
  181. color: #339933;
  182. }
  183. .org-done {
  184. color: #339933;
  185. }
  186. .title { text-align: center; }
  187. .todo, .deadline { color: red; }
  188. .done { color: green; }
  189. </style>
  190. or, if you want to keep the style in a file,
  191. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  192. As the value of this option simply gets inserted into the HTML <head> header,
  193. you can \"misuse\" it to also add other text to the header. However,
  194. <style>...</style> is required, if not present the variable will be ignored."
  195. :group 'org-agenda-export
  196. :group 'org-export-html
  197. :type 'string)
  198. (defcustom org-agenda-persistent-filter nil
  199. "When set, keep filters from one agenda view to the next."
  200. :group 'org-agenda
  201. :type 'boolean)
  202. (defgroup org-agenda-custom-commands nil
  203. "Options concerning agenda views in Org-mode."
  204. :tag "Org Agenda Custom Commands"
  205. :group 'org-agenda)
  206. (defconst org-sorting-choice
  207. '(choice
  208. (const time-up) (const time-down)
  209. (const category-keep) (const category-up) (const category-down)
  210. (const tag-down) (const tag-up)
  211. (const priority-up) (const priority-down)
  212. (const todo-state-up) (const todo-state-down)
  213. (const effort-up) (const effort-down)
  214. (const habit-up) (const habit-down)
  215. (const alpha-up) (const alpha-down)
  216. (const user-defined-up) (const user-defined-down))
  217. "Sorting choices.")
  218. (defconst org-agenda-custom-commands-local-options
  219. `(repeat :tag "Local settings for this command. Remember to quote values"
  220. (choice :tag "Setting"
  221. (list :tag "Heading for this block"
  222. (const org-agenda-overriding-header)
  223. (string :tag "Headline"))
  224. (list :tag "Files to be searched"
  225. (const org-agenda-files)
  226. (list
  227. (const :format "" quote)
  228. (repeat (file))))
  229. (list :tag "Sorting strategy"
  230. (const org-agenda-sorting-strategy)
  231. (list
  232. (const :format "" quote)
  233. (repeat
  234. ,org-sorting-choice)))
  235. (list :tag "Prefix format"
  236. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  237. (string))
  238. (list :tag "Number of days in agenda"
  239. (const org-agenda-span)
  240. (choice (const :tag "Day" 'day)
  241. (const :tag "Week" 'week)
  242. (const :tag "Month" 'month)
  243. (const :tag "Year" 'year)
  244. (integer :tag "Custom")))
  245. (list :tag "Fixed starting date"
  246. (const org-agenda-start-day)
  247. (string :value "2007-11-01"))
  248. (list :tag "Start on day of week"
  249. (const org-agenda-start-on-weekday)
  250. (choice :value 1
  251. (const :tag "Today" nil)
  252. (integer :tag "Weekday No.")))
  253. (list :tag "Include data from diary"
  254. (const org-agenda-include-diary)
  255. (boolean))
  256. (list :tag "Deadline Warning days"
  257. (const org-deadline-warning-days)
  258. (integer :value 1))
  259. (list :tag "Tags filter preset"
  260. (const org-agenda-filter-preset)
  261. (list
  262. (const :format "" quote)
  263. (repeat
  264. (string :tag "+tag or -tag"))))
  265. (list :tag "Set daily/weekly entry types"
  266. (const org-agenda-entry-types)
  267. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  268. (const :deadline)
  269. (const :scheduled)
  270. (const :timestamp)
  271. (const :sexp)))
  272. (list :tag "Standard skipping condition"
  273. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  274. (const org-agenda-skip-function)
  275. (list
  276. (const :format "" quote)
  277. (list
  278. (choice
  279. :tag "Skipping range"
  280. (const :tag "Skip entry" org-agenda-skip-entry-if)
  281. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  282. (repeat :inline t :tag "Conditions for skipping"
  283. (choice
  284. :tag "Condition type"
  285. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  286. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  287. (list :tag "TODO state is" :inline t
  288. (const 'todo)
  289. (choice
  290. (const :tag "any not-done state" 'todo)
  291. (const :tag "any done state" 'done)
  292. (const :tag "any state" 'any)
  293. (list :tag "Keyword list"
  294. (const :format "" quote)
  295. (repeat (string :tag "Keyword")))))
  296. (list :tag "TODO state is not" :inline t
  297. (const 'nottodo)
  298. (choice
  299. (const :tag "any not-done state" 'todo)
  300. (const :tag "any done state" 'done)
  301. (const :tag "any state" 'any)
  302. (list :tag "Keyword list"
  303. (const :format "" quote)
  304. (repeat (string :tag "Keyword")))))
  305. (const :tag "scheduled" 'scheduled)
  306. (const :tag "not scheduled" 'notscheduled)
  307. (const :tag "deadline" 'deadline)
  308. (const :tag "no deadline" 'notdeadline)
  309. (const :tag "timestamp" 'timestamp)
  310. (const :tag "no timestamp" 'nottimestamp))))))
  311. (list :tag "Non-standard skipping condition"
  312. :value (org-agenda-skip-function)
  313. (const org-agenda-skip-function)
  314. (sexp :tag "Function or form (quoted!)"))
  315. (list :tag "Any variable"
  316. (variable :tag "Variable")
  317. (sexp :tag "Value (sexp)"))))
  318. "Selection of examples for agenda command settings.
  319. This will be spliced into the custom type of
  320. `org-agenda-custom-commands'.")
  321. (defcustom org-agenda-custom-commands nil
  322. "Custom commands for the agenda.
  323. These commands will be offered on the splash screen displayed by the
  324. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  325. (key desc type match settings files)
  326. key The key (one or more characters as a string) to be associated
  327. with the command.
  328. desc A description of the command, when omitted or nil, a default
  329. description is built using MATCH.
  330. type The command type, any of the following symbols:
  331. agenda The daily/weekly agenda.
  332. todo Entries with a specific TODO keyword, in all agenda files.
  333. search Entries containing search words entry or headline.
  334. tags Tags/Property/TODO match in all agenda files.
  335. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  336. todo-tree Sparse tree of specific TODO keyword in *current* file.
  337. tags-tree Sparse tree with all tags matches in *current* file.
  338. occur-tree Occur sparse tree for *current* file.
  339. ... A user-defined function.
  340. match What to search for:
  341. - a single keyword for TODO keyword searches
  342. - a tags match expression for tags searches
  343. - a word search expression for text searches.
  344. - a regular expression for occur searches
  345. For all other commands, this should be the empty string.
  346. settings A list of option settings, similar to that in a let form, so like
  347. this: ((opt1 val1) (opt2 val2) ...). The values will be
  348. evaluated at the moment of execution, so quote them when needed.
  349. files A list of files file to write the produced agenda buffer to
  350. with the command `org-store-agenda-views'.
  351. If a file name ends in \".html\", an HTML version of the buffer
  352. is written out. If it ends in \".ps\", a postscript version is
  353. produced. Otherwise, only the plain text is written to the file.
  354. You can also define a set of commands, to create a composite agenda buffer.
  355. In this case, an entry looks like this:
  356. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  357. where
  358. desc A description string to be displayed in the dispatcher menu.
  359. cmd An agenda command, similar to the above. However, tree commands
  360. are no allowed, but instead you can get agenda and global todo list.
  361. So valid commands for a set are:
  362. (agenda \"\" settings)
  363. (alltodo \"\" settings)
  364. (stuck \"\" settings)
  365. (todo \"match\" settings files)
  366. (search \"match\" settings files)
  367. (tags \"match\" settings files)
  368. (tags-todo \"match\" settings files)
  369. Each command can carry a list of options, and another set of options can be
  370. given for the whole set of commands. Individual command options take
  371. precedence over the general options.
  372. When using several characters as key to a command, the first characters
  373. are prefix commands. For the dispatcher to display useful information, you
  374. should provide a description for the prefix, like
  375. (setq org-agenda-custom-commands
  376. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  377. (\"hl\" tags \"+HOME+Lisa\")
  378. (\"hp\" tags \"+HOME+Peter\")
  379. (\"hk\" tags \"+HOME+Kim\")))"
  380. :group 'org-agenda-custom-commands
  381. :type `(repeat
  382. (choice :value ("x" "Describe command here" tags "" nil)
  383. (list :tag "Single command"
  384. (string :tag "Access Key(s) ")
  385. (option (string :tag "Description"))
  386. (choice
  387. (const :tag "Agenda" agenda)
  388. (const :tag "TODO list" alltodo)
  389. (const :tag "Search words" search)
  390. (const :tag "Stuck projects" stuck)
  391. (const :tag "Tags/Property match (all agenda files)" tags)
  392. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  393. (const :tag "TODO keyword search (all agenda files)" todo)
  394. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  395. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  396. (const :tag "Occur tree (current buffer)" occur-tree)
  397. (sexp :tag "Other, user-defined function"))
  398. (string :tag "Match (only for some commands)")
  399. ,org-agenda-custom-commands-local-options
  400. (option (repeat :tag "Export" (file :tag "Export to"))))
  401. (list :tag "Command series, all agenda files"
  402. (string :tag "Access Key(s)")
  403. (string :tag "Description ")
  404. (repeat :tag "Component"
  405. (choice
  406. (list :tag "Agenda"
  407. (const :format "" agenda)
  408. (const :tag "" :format "" "")
  409. ,org-agenda-custom-commands-local-options)
  410. (list :tag "TODO list (all keywords)"
  411. (const :format "" alltodo)
  412. (const :tag "" :format "" "")
  413. ,org-agenda-custom-commands-local-options)
  414. (list :tag "Search words"
  415. (const :format "" search)
  416. (string :tag "Match")
  417. ,org-agenda-custom-commands-local-options)
  418. (list :tag "Stuck projects"
  419. (const :format "" stuck)
  420. (const :tag "" :format "" "")
  421. ,org-agenda-custom-commands-local-options)
  422. (list :tag "Tags search"
  423. (const :format "" tags)
  424. (string :tag "Match")
  425. ,org-agenda-custom-commands-local-options)
  426. (list :tag "Tags search, TODO entries only"
  427. (const :format "" tags-todo)
  428. (string :tag "Match")
  429. ,org-agenda-custom-commands-local-options)
  430. (list :tag "TODO keyword search"
  431. (const :format "" todo)
  432. (string :tag "Match")
  433. ,org-agenda-custom-commands-local-options)
  434. (list :tag "Other, user-defined function"
  435. (symbol :tag "function")
  436. (string :tag "Match")
  437. ,org-agenda-custom-commands-local-options)))
  438. (repeat :tag "Settings for entire command set"
  439. (list (variable :tag "Any variable")
  440. (sexp :tag "Value")))
  441. (option (repeat :tag "Export" (file :tag "Export to"))))
  442. (cons :tag "Prefix key documentation"
  443. (string :tag "Access Key(s)")
  444. (string :tag "Description ")))))
  445. (defcustom org-agenda-query-register ?o
  446. "The register holding the current query string.
  447. The purpose of this is that if you construct a query string interactively,
  448. you can then use it to define a custom command."
  449. :group 'org-agenda-custom-commands
  450. :type 'character)
  451. (defcustom org-stuck-projects
  452. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  453. "How to identify stuck projects.
  454. This is a list of four items:
  455. 1. A tags/todo/property matcher string that is used to identify a project.
  456. See the manual for a description of tag and property searches.
  457. The entire tree below a headline matched by this is considered one project.
  458. 2. A list of TODO keywords identifying non-stuck projects.
  459. If the project subtree contains any headline with one of these todo
  460. keywords, the project is considered to be not stuck. If you specify
  461. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  462. 3. A list of tags identifying non-stuck projects.
  463. If the project subtree contains any headline with one of these tags,
  464. the project is considered to be not stuck. If you specify \"*\" as
  465. a tag, any tag will mark the project unstuck. Note that this is about
  466. the explicit presence of a tag somewhere in the subtree, inherited
  467. tags to not count here. If inherited tags make a project not stuck,
  468. use \"-TAG\" in the tags part of the matcher under (1.) above.
  469. 4. An arbitrary regular expression matching non-stuck projects.
  470. If the project turns out to be not stuck, search continues also in the
  471. subtree to see if any of the subtasks have project status.
  472. See also the variable `org-tags-match-list-sublevels' which applies
  473. to projects matched by this search as well.
  474. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  475. or `C-c a #' to produce the list."
  476. :group 'org-agenda-custom-commands
  477. :type '(list
  478. (string :tag "Tags/TODO match to identify a project")
  479. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  480. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  481. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  482. (defcustom org-agenda-filter-effort-default-operator "<"
  483. "The default operator for effort estimate filtering.
  484. If you select an effort estimate limit without first pressing an operator,
  485. this one will be used."
  486. :group 'org-agenda-custom-commands
  487. :type '(choice (const :tag "less or equal" "<")
  488. (const :tag "greater or equal"">")
  489. (const :tag "equal" "=")))
  490. (defgroup org-agenda-skip nil
  491. "Options concerning skipping parts of agenda files."
  492. :tag "Org Agenda Skip"
  493. :group 'org-agenda)
  494. (defcustom org-agenda-skip-function-global nil
  495. "Function to be called at each match during agenda construction.
  496. If this function returns nil, the current match should not be skipped.
  497. If the function decided to skip an agenda match, is must return the
  498. buffer position from which the search should be continued.
  499. This may also be a Lisp form, which will be evaluated.
  500. This variable will be applied to every agenda match, including
  501. tags/property searches and TODO lists. So try to make the test function
  502. do its checking as efficiently as possible. To implement a skipping
  503. condition just for specific agenda commands, use the variable
  504. `org-agenda-skip-function' which can be set in the options section
  505. of custom agenda commands."
  506. :group 'org-agenda-skip
  507. :type 'sexp)
  508. (defgroup org-agenda-daily/weekly nil
  509. "Options concerning the daily/weekly agenda."
  510. :tag "Org Agenda Daily/Weekly"
  511. :group 'org-agenda)
  512. (defgroup org-agenda-todo-list nil
  513. "Options concerning the global todo list agenda view."
  514. :tag "Org Agenda Todo List"
  515. :group 'org-agenda)
  516. (defgroup org-agenda-match-view nil
  517. "Options concerning the general tags/property/todo match agenda view."
  518. :tag "Org Agenda Match View"
  519. :group 'org-agenda)
  520. (defgroup org-agenda-search-view nil
  521. "Options concerning the general tags/property/todo match agenda view."
  522. :tag "Org Agenda Match View"
  523. :group 'org-agenda)
  524. (defvar org-agenda-archives-mode nil
  525. "Non-nil means the agenda will include archived items.
  526. If this is the symbol `trees', trees in the selected agenda scope
  527. that are marked with the ARCHIVE tag will be included anyway. When this is
  528. t, also all archive files associated with the current selection of agenda
  529. files will be included.")
  530. (defcustom org-agenda-skip-comment-trees t
  531. "Non-nil means skip trees that start with the COMMENT keyword.
  532. When nil, these trees are also scanned by agenda commands."
  533. :group 'org-agenda-skip
  534. :type 'boolean)
  535. (defcustom org-agenda-todo-list-sublevels t
  536. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  537. When nil, the sublevels of a TODO entry are not checked, resulting in
  538. potentially much shorter TODO lists."
  539. :group 'org-agenda-skip
  540. :group 'org-agenda-todo-list
  541. :type 'boolean)
  542. (defcustom org-agenda-todo-ignore-with-date nil
  543. "Non-nil means don't show entries with a date in the global todo list.
  544. You can use this if you prefer to mark mere appointments with a TODO keyword,
  545. but don't want them to show up in the TODO list.
  546. When this is set, it also covers deadlines and scheduled items, the settings
  547. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  548. will be ignored.
  549. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type 'boolean)
  553. (defcustom org-agenda-todo-ignore-timestamp nil
  554. "Non-nil means don't show entries with a timestamp.
  555. This applies when creating the global todo list.
  556. Valid values are:
  557. past Don't show entries for today or in the past.
  558. future Don't show entries with a timestamp in the future.
  559. The idea behind this is that if it has a future
  560. timestamp, you don't want to think about it until the
  561. date.
  562. all Don't show any entries with a timestamp in the global todo list.
  563. The idea behind this is that by setting a timestamp, you
  564. have already \"taken care\" of this item.
  565. This variable can also have an integer as a value. If positive (N),
  566. todos with a timestamp N or more days in the future will be ignored. If
  567. negative (-N), todos with a timestamp N or more days in the past will be
  568. ignored. If 0, todos with a timestamp either today or in the future will
  569. be ignored. For example, a value of -1 will exclude todos with a
  570. timestamp in the past (yesterday or earlier), while a value of 7 will
  571. exclude todos with a timestamp a week or more in the future.
  572. See also `org-agenda-todo-ignore-with-date'.
  573. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  574. to make his option also apply to the tags-todo list."
  575. :group 'org-agenda-skip
  576. :group 'org-agenda-todo-list
  577. :type '(choice
  578. (const :tag "Ignore future timestamp todos" future)
  579. (const :tag "Ignore past or present timestamp todos" past)
  580. (const :tag "Ignore all timestamp todos" all)
  581. (const :tag "Show timestamp todos" nil)
  582. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  583. (defcustom org-agenda-todo-ignore-scheduled nil
  584. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  585. This applies when creating the global todo list.
  586. Valid values are:
  587. past Don't show entries scheduled today or in the past.
  588. future Don't show entries scheduled in the future.
  589. The idea behind this is that by scheduling it, you don't want to
  590. think about it until the scheduled date.
  591. all Don't show any scheduled entries in the global todo list.
  592. The idea behind this is that by scheduling it, you have already
  593. \"taken care\" of this item.
  594. t Same as `all', for backward compatibility.
  595. This variable can also have an integer as a value. See
  596. `org-agenda-todo-ignore-timestamp' for more details.
  597. See also `org-agenda-todo-ignore-with-date'.
  598. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  599. to make his option also apply to the tags-todo list."
  600. :group 'org-agenda-skip
  601. :group 'org-agenda-todo-list
  602. :type '(choice
  603. (const :tag "Ignore future-scheduled todos" future)
  604. (const :tag "Ignore past- or present-scheduled todos" past)
  605. (const :tag "Ignore all scheduled todos" all)
  606. (const :tag "Ignore all scheduled todos (compatibility)" t)
  607. (const :tag "Show scheduled todos" nil)
  608. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  609. (defcustom org-agenda-todo-ignore-deadlines nil
  610. "Non-nil means ignore some deadlined TODO items when making TODO list.
  611. There are different motivations for using different values, please think
  612. carefully when configuring this variable.
  613. This applies when creating the global todo list.
  614. Valid values are:
  615. near Don't show near deadline entries. A deadline is near when it is
  616. closer than `org-deadline-warning-days' days. The idea behind this
  617. is that such items will appear in the agenda anyway.
  618. far Don't show TODO entries where a deadline has been defined, but
  619. the deadline is not near. This is useful if you don't want to
  620. use the todo list to figure out what to do now.
  621. past Don't show entries with a deadline timestamp for today or in the past.
  622. future Don't show entries with a deadline timestamp in the future, not even
  623. when they become `near' ones. Use it with caution.
  624. all Ignore all TODO entries that do have a deadline.
  625. t Same as `near', for backward compatibility.
  626. This variable can also have an integer as a value. See
  627. `org-agenda-todo-ignore-timestamp' for more details.
  628. See also `org-agenda-todo-ignore-with-date'.
  629. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  630. to make his option also apply to the tags-todo list."
  631. :group 'org-agenda-skip
  632. :group 'org-agenda-todo-list
  633. :type '(choice
  634. (const :tag "Ignore near deadlines" near)
  635. (const :tag "Ignore near deadlines (compatibility)" t)
  636. (const :tag "Ignore far deadlines" far)
  637. (const :tag "Ignore all TODOs with a deadlines" all)
  638. (const :tag "Show all TODOs, even if they have a deadline" nil)
  639. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  640. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  641. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  642. The variables
  643. `org-agenda-todo-ignore-with-date',
  644. `org-agenda-todo-ignore-timestamp',
  645. `org-agenda-todo-ignore-scheduled',
  646. `org-agenda-todo-ignore-deadlines'
  647. make the global TODO list skip entries that have time stamps of certain
  648. kinds. If this option is set, the same options will also apply for the
  649. tags-todo search, which is the general tags/property matcher
  650. restricted to unfinished TODO entries only."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :group 'org-agenda-match-view
  654. :type 'boolean)
  655. (defcustom org-agenda-skip-scheduled-if-done nil
  656. "Non-nil means don't show scheduled items in agenda when they are done.
  657. This is relevant for the daily/weekly agenda, not for the TODO list. And
  658. it applies only to the actual date of the scheduling. Warnings about
  659. an item with a past scheduling dates are always turned off when the item
  660. is DONE."
  661. :group 'org-agenda-skip
  662. :group 'org-agenda-daily/weekly
  663. :type 'boolean)
  664. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  665. "Non-nil means skip scheduling line if same entry shows because of deadline.
  666. In the agenda of today, an entry can show up multiple times because
  667. it is both scheduled and has a nearby deadline, and maybe a plain time
  668. stamp as well.
  669. When this variable is t, then only the deadline is shown and the fact that
  670. the entry is scheduled today or was scheduled previously is not shown.
  671. When this variable is nil, the entry will be shown several times. When
  672. the variable is the symbol `not-today', then skip scheduled previously,
  673. but not scheduled today."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-daily/weekly
  676. :type '(choice
  677. (const :tag "Never" nil)
  678. (const :tag "Always" t)
  679. (const :tag "Not when scheduled today" not-today)))
  680. (defcustom org-agenda-skip-deadline-if-done nil
  681. "Non-nil means don't show deadlines when the corresponding item is done.
  682. When nil, the deadline is still shown and should give you a happy feeling.
  683. This is relevant for the daily/weekly agenda. And it applied only to the
  684. actually date of the deadline. Warnings about approaching and past-due
  685. deadlines are always turned off when the item is DONE."
  686. :group 'org-agenda-skip
  687. :group 'org-agenda-daily/weekly
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  690. "Non-nil means skip deadline prewarning when entry is also scheduled.
  691. This will apply on all days where a prewarning for the deadline would
  692. be shown, but not at the day when the entry is actually due. On that day,
  693. the deadline will be shown anyway.
  694. This variable may be set to nil, t, or a number which will then give
  695. the number of days before the actual deadline when the prewarnings
  696. should resume.
  697. This can be used in a workflow where the first showing of the deadline will
  698. trigger you to schedule it, and then you don't want to be reminded of it
  699. because you will take care of it on the day when scheduled."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-daily/weekly
  702. :type '(choice
  703. (const :tag "Alwas show prewarning" nil)
  704. (const :tag "Remove prewarning if entry is scheduled" t)
  705. (integer :tag "Restart prewarning N days before deadline")))
  706. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  707. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  708. When non-nil, after the search for timestamps has matched once in an
  709. entry, the rest of the entry will not be searched."
  710. :group 'org-agenda-skip
  711. :type 'boolean)
  712. (defcustom org-agenda-skip-timestamp-if-done nil
  713. "Non-nil means don't select item by timestamp or -range if it is DONE."
  714. :group 'org-agenda-skip
  715. :group 'org-agenda-daily/weekly
  716. :type 'boolean)
  717. (defcustom org-agenda-dim-blocked-tasks t
  718. "Non-nil means dim blocked tasks in the agenda display.
  719. This causes some overhead during agenda construction, but if you
  720. have turned on `org-enforce-todo-dependencies',
  721. `org-enforce-todo-checkbox-dependencies', or any other blocking
  722. mechanism, this will create useful feedback in the agenda.
  723. Instead of t, this variable can also have the value `invisible'.
  724. Then blocked tasks will be invisible and only become visible when
  725. they become unblocked. An exemption to this behavior is when a task is
  726. blocked because of unchecked checkboxes below it. Since checkboxes do
  727. not show up in the agenda views, making this task invisible you remove any
  728. trace from agenda views that there is something to do. Therefore, a task
  729. that is blocked because of checkboxes will never be made invisible, it
  730. will only be dimmed."
  731. :group 'org-agenda-daily/weekly
  732. :group 'org-agenda-todo-list
  733. :type '(choice
  734. (const :tag "Do not dim" nil)
  735. (const :tag "Dim to a grey face" t)
  736. (const :tag "Make invisible" invisible)))
  737. (defcustom org-timeline-show-empty-dates 3
  738. "Non-nil means `org-timeline' also shows dates without an entry.
  739. When nil, only the days which actually have entries are shown.
  740. When t, all days between the first and the last date are shown.
  741. When an integer, show also empty dates, but if there is a gap of more than
  742. N days, just insert a special line indicating the size of the gap."
  743. :group 'org-agenda-skip
  744. :type '(choice
  745. (const :tag "None" nil)
  746. (const :tag "All" t)
  747. (integer :tag "at most")))
  748. (defgroup org-agenda-startup nil
  749. "Options concerning initial settings in the Agenda in Org Mode."
  750. :tag "Org Agenda Startup"
  751. :group 'org-agenda)
  752. (defcustom org-agenda-menu-show-matcher t
  753. "Non-nil means show the match string in the agenda dispatcher menu.
  754. When nil, the matcher string is not shown, but is put into the help-echo
  755. property so than moving the mouse over the command shows it.
  756. Setting it to nil is good if matcher strings are very long and/or if
  757. you want to use two-column display (see `org-agenda-menu-two-column')."
  758. :group 'org-agenda
  759. :type 'boolean)
  760. (defcustom org-agenda-menu-two-column nil
  761. "Non-nil means, use two columns to show custom commands in the dispatcher.
  762. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  763. to nil."
  764. :group 'org-agenda
  765. :type 'boolean)
  766. (defcustom org-finalize-agenda-hook nil
  767. "Hook run just before displaying an agenda buffer."
  768. :group 'org-agenda-startup
  769. :type 'hook)
  770. (defcustom org-agenda-mouse-1-follows-link nil
  771. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  772. A longer mouse click will still set point. Does not work on XEmacs.
  773. Needs to be set before org.el is loaded."
  774. :group 'org-agenda-startup
  775. :type 'boolean)
  776. (defcustom org-agenda-start-with-follow-mode nil
  777. "The initial value of follow mode in a newly created agenda window."
  778. :group 'org-agenda-startup
  779. :type 'boolean)
  780. (defcustom org-agenda-show-outline-path t
  781. "Non-nil means show outline path in echo area after line motion."
  782. :group 'org-agenda-startup
  783. :type 'boolean)
  784. (defcustom org-agenda-start-with-entry-text-mode nil
  785. "The initial value of entry-text-mode in a newly created agenda window."
  786. :group 'org-agenda-startup
  787. :type 'boolean)
  788. (defcustom org-agenda-entry-text-maxlines 5
  789. "Number of text lines to be added when `E' is pressed in the agenda.
  790. Note that this variable only used during agenda display. Add add entry text
  791. when exporting the agenda, configure the variable
  792. `org-agenda-add-entry-ext-maxlines'."
  793. :group 'org-agenda
  794. :type 'integer)
  795. (defcustom org-agenda-entry-text-exclude-regexps nil
  796. "List of regular expressions to clean up entry text.
  797. The complete matches of all regular expressions in this list will be
  798. removed from entry text before it is shown in the agenda."
  799. :group 'org-agenda
  800. :type '(repeat (regexp)))
  801. (defvar org-agenda-entry-text-cleanup-hook nil
  802. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  803. This cleanup is done in a temporary buffer, so the function may inspect and
  804. change the entire buffer.
  805. Some default stuff like drawers and scheduling/deadline dates will already
  806. have been removed when this is called, as will any matches for regular
  807. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  808. (defvar org-agenda-include-inactive-timestamps nil
  809. "Non-nil means include inactive time stamps in agenda and timeline.")
  810. (defgroup org-agenda-windows nil
  811. "Options concerning the windows used by the Agenda in Org Mode."
  812. :tag "Org Agenda Windows"
  813. :group 'org-agenda)
  814. (defcustom org-agenda-window-setup 'reorganize-frame
  815. "How the agenda buffer should be displayed.
  816. Possible values for this option are:
  817. current-window Show agenda in the current window, keeping all other windows.
  818. other-window Use `switch-to-buffer-other-window' to display agenda.
  819. reorganize-frame Show only two windows on the current frame, the current
  820. window and the agenda.
  821. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  822. Also, when exiting the agenda, kill that frame.
  823. See also the variable `org-agenda-restore-windows-after-quit'."
  824. :group 'org-agenda-windows
  825. :type '(choice
  826. (const current-window)
  827. (const other-frame)
  828. (const other-window)
  829. (const reorganize-frame)))
  830. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  831. "The min and max height of the agenda window as a fraction of frame height.
  832. The value of the variable is a cons cell with two numbers between 0 and 1.
  833. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  834. :group 'org-agenda-windows
  835. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  836. (defcustom org-agenda-restore-windows-after-quit nil
  837. "Non-nil means restore window configuration upon exiting agenda.
  838. Before the window configuration is changed for displaying the agenda,
  839. the current status is recorded. When the agenda is exited with
  840. `q' or `x' and this option is set, the old state is restored. If
  841. `org-agenda-window-setup' is `other-frame', the value of this
  842. option will be ignored."
  843. :group 'org-agenda-windows
  844. :type 'boolean)
  845. (defcustom org-agenda-ndays nil
  846. "Number of days to include in overview display.
  847. Should be 1 or 7.
  848. Obsolete, see `org-agenda-span'."
  849. :group 'org-agenda-daily/weekly
  850. :type 'integer)
  851. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  852. (defcustom org-agenda-span 'week
  853. "Number of days to include in overview display.
  854. Can be day, week, month, year, or any number of days.
  855. Custom commands can set this variable in the options section."
  856. :group 'org-agenda-daily/weekly
  857. :type '(choice (const :tag "Day" day)
  858. (const :tag "Week" week)
  859. (const :tag "Month" month)
  860. (const :tag "Year" year)
  861. (integer :tag "Custom")))
  862. (defcustom org-agenda-start-on-weekday 1
  863. "Non-nil means start the overview always on the specified weekday.
  864. 0 denotes Sunday, 1 denotes Monday etc.
  865. When nil, always start on the current day.
  866. Custom commands can set this variable in the options section."
  867. :group 'org-agenda-daily/weekly
  868. :type '(choice (const :tag "Today" nil)
  869. (integer :tag "Weekday No.")))
  870. (defcustom org-agenda-show-all-dates t
  871. "Non-nil means `org-agenda' shows every day in the selected range.
  872. When nil, only the days which actually have entries are shown."
  873. :group 'org-agenda-daily/weekly
  874. :type 'boolean)
  875. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  876. "Format string for displaying dates in the agenda.
  877. Used by the daily/weekly agenda and by the timeline. This should be
  878. a format string understood by `format-time-string', or a function returning
  879. the formatted date as a string. The function must take a single argument,
  880. a calendar-style date list like (month day year)."
  881. :group 'org-agenda-daily/weekly
  882. :type '(choice
  883. (string :tag "Format string")
  884. (function :tag "Function")))
  885. (defun org-agenda-format-date-aligned (date)
  886. "Format a date string for display in the daily/weekly agenda, or timeline.
  887. This function makes sure that dates are aligned for easy reading."
  888. (require 'cal-iso)
  889. (let* ((dayname (calendar-day-name date))
  890. (day (cadr date))
  891. (day-of-week (calendar-day-of-week date))
  892. (month (car date))
  893. (monthname (calendar-month-name month))
  894. (year (nth 2 date))
  895. (iso-week (org-days-to-iso-week
  896. (calendar-absolute-from-gregorian date)))
  897. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  898. (1- year))
  899. ((and (= month 12) (<= iso-week 1))
  900. (1+ year))
  901. (t year)))
  902. (weekstring (if (= day-of-week 1)
  903. (format " W%02d" iso-week)
  904. "")))
  905. (format "%-10s %2d %s %4d%s"
  906. dayname day monthname year weekstring)))
  907. (defcustom org-agenda-time-leading-zero nil
  908. "Non-nil means use leading zero for military times in agenda.
  909. For example, 9:30am would become 09:30 rather than 9:30."
  910. :group 'org-agenda-daily/weekly
  911. :type 'boolean)
  912. (defcustom org-agenda-timegrid-use-ampm nil
  913. "When set, show AM/PM style timestamps on the timegrid."
  914. :group 'org-agenda
  915. :type 'boolean)
  916. (defun org-agenda-time-of-day-to-ampm (time)
  917. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  918. (let* ((hour-number (string-to-number (substring time 0 -3)))
  919. (minute (substring time -2))
  920. (ampm "am"))
  921. (cond
  922. ((equal hour-number 12)
  923. (setq ampm "pm"))
  924. ((> hour-number 12)
  925. (setq ampm "pm")
  926. (setq hour-number (- hour-number 12))))
  927. (concat
  928. (if org-agenda-time-leading-zero
  929. (format "%02d" hour-number)
  930. (format "%02s" (number-to-string hour-number)))
  931. ":" minute ampm)))
  932. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  933. "Conditionally convert TIME to AM/PM format
  934. based on `org-agenda-timegrid-use-ampm'"
  935. (if org-agenda-timegrid-use-ampm
  936. (org-agenda-time-of-day-to-ampm time)
  937. time))
  938. (defcustom org-agenda-weekend-days '(6 0)
  939. "Which days are weekend?
  940. These days get the special face `org-agenda-date-weekend' in the agenda
  941. and timeline buffers."
  942. :group 'org-agenda-daily/weekly
  943. :type '(set :greedy t
  944. (const :tag "Monday" 1)
  945. (const :tag "Tuesday" 2)
  946. (const :tag "Wednesday" 3)
  947. (const :tag "Thursday" 4)
  948. (const :tag "Friday" 5)
  949. (const :tag "Saturday" 6)
  950. (const :tag "Sunday" 0)))
  951. (defcustom org-agenda-include-diary nil
  952. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  953. Custom commands can set this variable in the options section."
  954. :group 'org-agenda-daily/weekly
  955. :type 'boolean)
  956. (defcustom org-agenda-include-deadlines t
  957. "If non-nil, include entries within their deadline warning period.
  958. Custom commands can set this variable in the options section."
  959. :group 'org-agenda-daily/weekly
  960. :type 'boolean)
  961. (defcustom org-agenda-include-all-todo nil
  962. "Set means weekly/daily agenda will always contain all TODO entries.
  963. The TODO entries will be listed at the top of the agenda, before
  964. the entries for specific days.
  965. This option is deprecated, it is better to define a block agenda instead."
  966. :group 'org-agenda-daily/weekly
  967. :type 'boolean)
  968. (defcustom org-agenda-repeating-timestamp-show-all t
  969. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  970. When set to a list of strings, only show occurrences of repeating
  971. stamps for these TODO keywords. When nil, only one occurrence is
  972. shown, either today or the nearest into the future."
  973. :group 'org-agenda-daily/weekly
  974. :type '(choice
  975. (const :tag "Show repeating stamps" t)
  976. (repeat :tag "Show repeating stamps for these TODO keywords"
  977. (string :tag "TODO Keyword"))
  978. (const :tag "Don't show repeating stamps" nil)))
  979. (defcustom org-scheduled-past-days 10000
  980. "No. of days to continue listing scheduled items that are not marked DONE.
  981. When an item is scheduled on a date, it shows up in the agenda on this
  982. day and will be listed until it is marked done for the number of days
  983. given here."
  984. :group 'org-agenda-daily/weekly
  985. :type 'integer)
  986. (defcustom org-agenda-log-mode-items '(closed clock)
  987. "List of items that should be shown in agenda log mode.
  988. This list may contain the following symbols:
  989. closed Show entries that have been closed on that day.
  990. clock Show entries that have received clocked time on that day.
  991. state Show all logged state changes.
  992. Note that instead of changing this variable, you can also press `C-u l' in
  993. the agenda to display all available LOG items temporarily."
  994. :group 'org-agenda-daily/weekly
  995. :type '(set :greedy t (const closed) (const clock) (const state)))
  996. (defcustom org-agenda-clock-consistency-checks
  997. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  998. :gap-ok-around ("4:00")
  999. :default-face ((:background "DarkRed") (:foreground "white"))
  1000. :overlap-face nil :gap-face nil :no-end-time-face nil
  1001. :long-face nil :short-face nil)
  1002. "This is a property list, with the following keys:
  1003. :max-duration Mark clocking chunks that are longer than this time.
  1004. This is a time string like \"HH:MM\", or the number
  1005. of minutes as an integer.
  1006. :min-duration Mark clocking chunks that are shorter that this.
  1007. This is a time string like \"HH:MM\", or the number
  1008. of minutes as an integer.
  1009. :max-gap Mark gaps between clocking chunks that are longer than
  1010. this duration. A number of minutes, or a string
  1011. like \"HH:MM\".
  1012. :gap-ok-around List of times during the day which are usually not working
  1013. times. When a gap is detected, but the gap contains any
  1014. of these times, the gap is *not* reported. For example,
  1015. if this is (\"4:00\" \"13:00\") then gaps that contain
  1016. 4:00 in the morning (i.e. the night) and 13:00
  1017. (i.e. a typical lunch time) do not cause a warning.
  1018. You should have at least one time during the night in this
  1019. list, or otherwise the first task each morning will trigger
  1020. a warning because it follows a long gap.
  1021. Furthermore, the following properties can be used to define faces for
  1022. issue display.
  1023. :default-face the default face, if the specific face is undefined
  1024. :overlap-face face for overlapping clocks
  1025. :gap-face face for gaps between clocks
  1026. :no-end-time-face face for incomplete clocks
  1027. :long-face face for clock intervals that are too long
  1028. :short-face face for clock intervals that are too short"
  1029. :group 'org-agenda-daily/weekly
  1030. :group 'org-clock
  1031. :type 'plist)
  1032. (defcustom org-agenda-log-mode-add-notes t
  1033. "Non-nil means add first line of notes to log entries in agenda views.
  1034. If a log item like a state change or a clock entry is associated with
  1035. notes, the first line of these notes will be added to the entry in the
  1036. agenda display."
  1037. :group 'org-agenda-daily/weekly
  1038. :type 'boolean)
  1039. (defcustom org-agenda-start-with-log-mode nil
  1040. "The initial value of log-mode in a newly created agenda window."
  1041. :group 'org-agenda-startup
  1042. :group 'org-agenda-daily/weekly
  1043. :type 'boolean)
  1044. (defcustom org-agenda-start-with-clockreport-mode nil
  1045. "The initial value of clockreport-mode in a newly created agenda window."
  1046. :group 'org-agenda-startup
  1047. :group 'org-agenda-daily/weekly
  1048. :type 'boolean)
  1049. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1050. "Property list with parameters for the clocktable in clockreport mode.
  1051. This is the display mode that shows a clock table in the daily/weekly
  1052. agenda, the properties for this dynamic block can be set here.
  1053. The usual clocktable parameters are allowed here, but you cannot set
  1054. the properties :name, :tstart, :tend, :block, and :scope - these will
  1055. be overwritten to make sure the content accurately reflects the
  1056. current display in the agenda."
  1057. :group 'org-agenda-daily/weekly
  1058. :type 'plist)
  1059. (defcustom org-agenda-search-view-always-boolean nil
  1060. "Non-nil means the search string is interpreted as individual parts.
  1061. The search string for search view can either be interpreted as a phrase,
  1062. or as a list of snippets that define a boolean search for a number of
  1063. strings.
  1064. When this is non-nil, the string will be split on whitespace, and each
  1065. snippet will be searched individually, and all must match in order to
  1066. select an entry. A snippet is then a single string of non-white
  1067. characters, or a string in double quotes, or a regexp in {} braces.
  1068. If a snippet is preceded by \"-\", the snippet must *not* match.
  1069. \"+\" is syntactic sugar for positive selection. Each snippet may
  1070. be found as a full word or a partial word, but see the variable
  1071. `org-agenda-search-view-force-full-words'.
  1072. When this is nil, search will look for the entire search phrase as one,
  1073. with each space character matching any amount of whitespace, including
  1074. line breaks.
  1075. Even when this is nil, you can still switch to Boolean search dynamically
  1076. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1077. is a regexp marked with braces like \"{abc}\", this will also switch to
  1078. boolean search."
  1079. :group 'org-agenda-search-view
  1080. :type 'boolean)
  1081. (if (fboundp 'defvaralias)
  1082. (defvaralias 'org-agenda-search-view-search-words-only
  1083. 'org-agenda-search-view-always-boolean))
  1084. (defcustom org-agenda-search-view-force-full-words nil
  1085. "Non-nil means, search words must be matches as complete words.
  1086. When nil, they may also match part of a word."
  1087. :group 'org-agenda-search-view
  1088. :type 'boolean)
  1089. (defgroup org-agenda-time-grid nil
  1090. "Options concerning the time grid in the Org-mode Agenda."
  1091. :tag "Org Agenda Time Grid"
  1092. :group 'org-agenda)
  1093. (defcustom org-agenda-search-headline-for-time t
  1094. "Non-nil means search headline for a time-of-day.
  1095. If the headline contains a time-of-day in one format or another, it will
  1096. be used to sort the entry into the time sequence of items for a day.
  1097. Some people have time stamps in the headline that refer to the creation
  1098. time or so, and then this produces an unwanted side effect. If this is
  1099. the case for your, use this variable to turn off searching the headline
  1100. for a time."
  1101. :group 'org-agenda-time-grid
  1102. :type 'boolean)
  1103. (defcustom org-agenda-use-time-grid t
  1104. "Non-nil means show a time grid in the agenda schedule.
  1105. A time grid is a set of lines for specific times (like every two hours between
  1106. 8:00 and 20:00). The items scheduled for a day at specific times are
  1107. sorted in between these lines.
  1108. For details about when the grid will be shown, and what it will look like, see
  1109. the variable `org-agenda-time-grid'."
  1110. :group 'org-agenda-time-grid
  1111. :type 'boolean)
  1112. (defcustom org-agenda-time-grid
  1113. '((daily today require-timed)
  1114. "----------------"
  1115. (800 1000 1200 1400 1600 1800 2000))
  1116. "The settings for time grid for agenda display.
  1117. This is a list of three items. The first item is again a list. It contains
  1118. symbols specifying conditions when the grid should be displayed:
  1119. daily if the agenda shows a single day
  1120. weekly if the agenda shows an entire week
  1121. today show grid on current date, independent of daily/weekly display
  1122. require-timed show grid only if at least one item has a time specification
  1123. The second item is a string which will be placed behind the grid time.
  1124. The third item is a list of integers, indicating the times that should have
  1125. a grid line."
  1126. :group 'org-agenda-time-grid
  1127. :type
  1128. '(list
  1129. (set :greedy t :tag "Grid Display Options"
  1130. (const :tag "Show grid in single day agenda display" daily)
  1131. (const :tag "Show grid in weekly agenda display" weekly)
  1132. (const :tag "Always show grid for today" today)
  1133. (const :tag "Show grid only if any timed entries are present"
  1134. require-timed)
  1135. (const :tag "Skip grid times already present in an entry"
  1136. remove-match))
  1137. (string :tag "Grid String")
  1138. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1139. (defcustom org-agenda-show-current-time-in-grid t
  1140. "Non-nil means show the current time in the time grid."
  1141. :group 'org-agenda-time-grid
  1142. :type 'boolean)
  1143. (defcustom org-agenda-current-time-string
  1144. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1145. "The string for the current time marker in the agenda."
  1146. :group 'org-agenda-time-grid
  1147. :type 'string)
  1148. (defgroup org-agenda-sorting nil
  1149. "Options concerning sorting in the Org-mode Agenda."
  1150. :tag "Org Agenda Sorting"
  1151. :group 'org-agenda)
  1152. (defcustom org-agenda-sorting-strategy
  1153. '((agenda habit-down time-up priority-down category-keep)
  1154. (todo priority-down category-keep)
  1155. (tags priority-down category-keep)
  1156. (search category-keep))
  1157. "Sorting structure for the agenda items of a single day.
  1158. This is a list of symbols which will be used in sequence to determine
  1159. if an entry should be listed before another entry. The following
  1160. symbols are recognized:
  1161. time-up Put entries with time-of-day indications first, early first
  1162. time-down Put entries with time-of-day indications first, late first
  1163. category-keep Keep the default order of categories, corresponding to the
  1164. sequence in `org-agenda-files'.
  1165. category-up Sort alphabetically by category, A-Z.
  1166. category-down Sort alphabetically by category, Z-A.
  1167. tag-up Sort alphabetically by last tag, A-Z.
  1168. tag-down Sort alphabetically by last tag, Z-A.
  1169. priority-up Sort numerically by priority, high priority last.
  1170. priority-down Sort numerically by priority, high priority first.
  1171. todo-state-up Sort by todo state, tasks that are done last.
  1172. todo-state-down Sort by todo state, tasks that are done first.
  1173. effort-up Sort numerically by estimated effort, high effort last.
  1174. effort-down Sort numerically by estimated effort, high effort first.
  1175. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1176. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1177. habit-up Put entries that are habits first
  1178. habit-down Put entries that are habits last
  1179. alpha-up Sort headlines alphabetically
  1180. alpha-down Sort headlines alphabetically, reversed
  1181. The different possibilities will be tried in sequence, and testing stops
  1182. if one comparison returns a \"not-equal\". For example, the default
  1183. '(time-up category-keep priority-down)
  1184. means: Pull out all entries having a specified time of day and sort them,
  1185. in order to make a time schedule for the current day the first thing in the
  1186. agenda listing for the day. Of the entries without a time indication, keep
  1187. the grouped in categories, don't sort the categories, but keep them in
  1188. the sequence given in `org-agenda-files'. Within each category sort by
  1189. priority.
  1190. Leaving out `category-keep' would mean that items will be sorted across
  1191. categories by priority.
  1192. Instead of a single list, this can also be a set of list for specific
  1193. contents, with a context symbol in the car of the list, any of
  1194. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1195. Custom commands can bind this variable in the options section."
  1196. :group 'org-agenda-sorting
  1197. :type `(choice
  1198. (repeat :tag "General" ,org-sorting-choice)
  1199. (list :tag "Individually"
  1200. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1201. (repeat ,org-sorting-choice))
  1202. (cons (const :tag "Strategy for TODO lists" todo)
  1203. (repeat ,org-sorting-choice))
  1204. (cons (const :tag "Strategy for Tags matches" tags)
  1205. (repeat ,org-sorting-choice))
  1206. (cons (const :tag "Strategy for search matches" search)
  1207. (repeat ,org-sorting-choice)))))
  1208. (defcustom org-agenda-cmp-user-defined nil
  1209. "A function to define the comparison `user-defined'.
  1210. This function must receive two arguments, agenda entry a and b.
  1211. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1212. the user comparison, return nil.
  1213. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1214. part of an agenda sorting strategy."
  1215. :group 'org-agenda-sorting
  1216. :type 'symbol)
  1217. (defcustom org-sort-agenda-notime-is-late t
  1218. "Non-nil means items without time are considered late.
  1219. This is only relevant for sorting. When t, items which have no explicit
  1220. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1221. do have a time. When nil, the default time is before 0:00. You can use this
  1222. option to decide if the schedule for today should come before or after timeless
  1223. agenda entries."
  1224. :group 'org-agenda-sorting
  1225. :type 'boolean)
  1226. (defcustom org-sort-agenda-noeffort-is-high t
  1227. "Non-nil means items without effort estimate are sorted as high effort.
  1228. This also applies when filtering an agenda view with respect to the
  1229. < or > effort operator. Then, tasks with no effort defined will be treated
  1230. as tasks with high effort.
  1231. When nil, such items are sorted as 0 minutes effort."
  1232. :group 'org-agenda-sorting
  1233. :type 'boolean)
  1234. (defgroup org-agenda-line-format nil
  1235. "Options concerning the entry prefix in the Org-mode agenda display."
  1236. :tag "Org Agenda Line Format"
  1237. :group 'org-agenda)
  1238. (defcustom org-agenda-prefix-format
  1239. '((agenda . " %i %-12:c%?-12t% s")
  1240. (timeline . " % s")
  1241. (todo . " %i %-12:c")
  1242. (tags . " %i %-12:c")
  1243. (search . " %i %-12:c"))
  1244. "Format specifications for the prefix of items in the agenda views.
  1245. An alist with five entries, each for the different agenda types. The
  1246. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1247. The values are format strings.
  1248. This format works similar to a printf format, with the following meaning:
  1249. %c the category of the item, \"Diary\" for entries from the diary,
  1250. or as given by the CATEGORY keyword or derived from the file name
  1251. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1252. %T the last tag of the item (ignore inherited tags, which come first)
  1253. %t the HH:MM time-of-day specification if one applies to the entry
  1254. %s Scheduling/Deadline information, a short string
  1255. %(expression) Eval EXPRESSION and replace the control string
  1256. by the result
  1257. All specifiers work basically like the standard `%s' of printf, but may
  1258. contain two additional characters: a question mark just after the `%'
  1259. and a whitespace/punctuation character just before the final letter.
  1260. If the first character after `%' is a question mark, the entire field
  1261. will only be included if the corresponding value applies to the current
  1262. entry. This is useful for fields which should have fixed width when
  1263. present, but zero width when absent. For example, \"%?-12t\" will
  1264. result in a 12 character time field if a time of the day is specified,
  1265. but will completely disappear in entries which do not contain a time.
  1266. If there is punctuation or whitespace character just before the final
  1267. format letter, this character will be appended to the field value if
  1268. the value is not empty. For example, the format \"%-12:c\" leads to
  1269. \"Diary: \" if the category is \"Diary\". If the category were be
  1270. empty, no additional colon would be inserted.
  1271. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1272. which means:
  1273. - Indent the line with two space characters
  1274. - Give the category a 12 chars wide field, padded with whitespace on
  1275. the right (because of `-'). Append a colon if there is a category
  1276. (because of `:').
  1277. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1278. time, don't put in an empty field, just skip it (because of '?').
  1279. - Finally, put the scheduling information.
  1280. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1281. `org-agenda-remove-tags'.
  1282. Custom commands can set this variable in the options section."
  1283. :type '(choice
  1284. (string :tag "General format")
  1285. (list :greedy t :tag "View dependent"
  1286. (cons (const agenda) (string :tag "Format"))
  1287. (cons (const timeline) (string :tag "Format"))
  1288. (cons (const todo) (string :tag "Format"))
  1289. (cons (const tags) (string :tag "Format"))
  1290. (cons (const search) (string :tag "Format"))))
  1291. :group 'org-agenda-line-format)
  1292. (defvar org-prefix-format-compiled nil
  1293. "The compiled version of the most recently used prefix format.
  1294. See the variable `org-agenda-prefix-format'.")
  1295. (defcustom org-agenda-todo-keyword-format "%-1s"
  1296. "Format for the TODO keyword in agenda lines.
  1297. Set this to something like \"%-12s\" if you want all TODO keywords
  1298. to occupy a fixed space in the agenda display."
  1299. :group 'org-agenda-line-format
  1300. :type 'string)
  1301. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1302. "Text preceding timerange entries in the agenda view.
  1303. This is a list with two strings. The first applies when the range
  1304. is entirely on one day. The second applies if the range spans several days.
  1305. The strings may have two \"%d\" format specifiers which will be filled
  1306. with the sequence number of the days, and the total number of days in the
  1307. range, respectively."
  1308. :group 'org-agenda-line-format
  1309. :type '(list
  1310. (string :tag "Deadline today ")
  1311. (choice :tag "Deadline relative"
  1312. (string :tag "Format string")
  1313. (function))))
  1314. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1315. "Text preceding scheduled items in the agenda view.
  1316. This is a list with two strings. The first applies when the item is
  1317. scheduled on the current day. The second applies when it has been scheduled
  1318. previously, it may contain a %d indicating that this is the nth time that
  1319. this item is scheduled, due to automatic rescheduling of unfinished items
  1320. for the following day. So this number is one larger than the number of days
  1321. that passed since this item was scheduled first."
  1322. :group 'org-agenda-line-format
  1323. :type '(list
  1324. (string :tag "Scheduled today ")
  1325. (string :tag "Scheduled previously")))
  1326. (defcustom org-agenda-inactive-leader "["
  1327. "Text preceding item pulled into the agenda by inactive time stamps.
  1328. These entries are added to the agenda when pressing \"[\"."
  1329. :group 'org-agenda-line-format
  1330. :type '(list
  1331. (string :tag "Scheduled today ")
  1332. (string :tag "Scheduled previously")))
  1333. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1334. "Text preceding deadline items in the agenda view.
  1335. This is a list with two strings. The first applies when the item has its
  1336. deadline on the current day. The second applies when it is in the past or
  1337. in the future, it may contain %d to capture how many days away the deadline
  1338. is (was)."
  1339. :group 'org-agenda-line-format
  1340. :type '(list
  1341. (string :tag "Deadline today ")
  1342. (choice :tag "Deadline relative"
  1343. (string :tag "Format string")
  1344. (function))))
  1345. (defcustom org-agenda-remove-times-when-in-prefix t
  1346. "Non-nil means remove duplicate time specifications in agenda items.
  1347. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1348. time-of-day specification in a headline or diary entry is extracted and
  1349. placed into the prefix. If this option is non-nil, the original specification
  1350. \(a timestamp or -range, or just a plain time(range) specification like
  1351. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1352. cluttered.
  1353. The option can be t or nil. It may also be the symbol `beg', indicating
  1354. that the time should only be removed when it is located at the beginning of
  1355. the headline/diary entry."
  1356. :group 'org-agenda-line-format
  1357. :type '(choice
  1358. (const :tag "Always" t)
  1359. (const :tag "Never" nil)
  1360. (const :tag "When at beginning of entry" beg)))
  1361. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1362. "Non-nil means remove time ranges specifications in agenda
  1363. items that span on several days."
  1364. :group 'org-agenda-line-format
  1365. :type 'boolean)
  1366. (defcustom org-agenda-default-appointment-duration nil
  1367. "Default duration for appointments that only have a starting time.
  1368. When nil, no duration is specified in such cases.
  1369. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1370. :group 'org-agenda-line-format
  1371. :type '(choice
  1372. (integer :tag "Minutes")
  1373. (const :tag "No default duration")))
  1374. (defcustom org-agenda-show-inherited-tags t
  1375. "Non-nil means show inherited tags in each agenda line."
  1376. :group 'org-agenda-line-format
  1377. :type 'boolean)
  1378. (defcustom org-agenda-hide-tags-regexp nil
  1379. "Regular expression used to filter away specific tags in agenda views.
  1380. This means that these tags will be present, but not be shown in the agenda
  1381. line. Secondary filtering will still work on the hidden tags.
  1382. Nil means don't hide any tags."
  1383. :group 'org-agenda-line-format
  1384. :type '(choice
  1385. (const :tag "Hide none" nil)
  1386. (string :tag "Regexp ")))
  1387. (defcustom org-agenda-remove-tags nil
  1388. "Non-nil means remove the tags from the headline copy in the agenda.
  1389. When this is the symbol `prefix', only remove tags when
  1390. `org-agenda-prefix-format' contains a `%T' specifier."
  1391. :group 'org-agenda-line-format
  1392. :type '(choice
  1393. (const :tag "Always" t)
  1394. (const :tag "Never" nil)
  1395. (const :tag "When prefix format contains %T" prefix)))
  1396. (if (fboundp 'defvaralias)
  1397. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1398. 'org-agenda-remove-tags))
  1399. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1400. "Shift tags in agenda items to this column.
  1401. If this number is positive, it specifies the column. If it is negative,
  1402. it means that the tags should be flushright to that column. For example,
  1403. -80 works well for a normal 80 character screen."
  1404. :group 'org-agenda-line-format
  1405. :type 'integer)
  1406. (if (fboundp 'defvaralias)
  1407. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1408. (defcustom org-agenda-fontify-priorities 'cookies
  1409. "Non-nil means highlight low and high priorities in agenda.
  1410. When t, the highest priority entries are bold, lowest priority italic.
  1411. However, settings in `org-priority-faces' will overrule these faces.
  1412. When this variable is the symbol `cookies', only fontify the
  1413. cookies, not the entire task.
  1414. This may also be an association list of priority faces, whose
  1415. keys are the character values of `org-highest-priority',
  1416. `org-default-priority', and `org-lowest-priority' (the default values
  1417. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1418. color as a string, or a list like `(:background \"Red\")'.
  1419. If it is a color, the variable `org-faces-easy-properties'
  1420. determines if it is a foreground or a background color."
  1421. :group 'org-agenda-line-format
  1422. :type '(choice
  1423. (const :tag "Never" nil)
  1424. (const :tag "Defaults" t)
  1425. (const :tag "Cookies only" cookies)
  1426. (repeat :tag "Specify"
  1427. (list (character :tag "Priority" :value ?A)
  1428. (choice :tag "Face "
  1429. (string :tag "Color")
  1430. (sexp :tag "Face"))))))
  1431. (defcustom org-agenda-day-face-function nil
  1432. "Function called to determine what face should be used to display a day.
  1433. The only argument passed to that function is the day. It should
  1434. returns a face, or nil if does not want to specify a face and let
  1435. the normal rules apply."
  1436. :group 'org-agenda-line-format
  1437. :type 'function)
  1438. (defcustom org-agenda-category-icon-alist nil
  1439. "Alist of category icon to be displayed in agenda views.
  1440. Each entry should have the following format:
  1441. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1442. Where CATEGORY-REGEXP is a regexp matching the categories where
  1443. the icon should be displayed.
  1444. FILE-OR-DATA either a file path or a string containing image data.
  1445. The other fields can be omited safely if not needed:
  1446. TYPE indicates the image type.
  1447. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1448. image data.
  1449. PROPS are additional image attributes to assign to the image,
  1450. like, e.g. `:ascent center'.
  1451. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1452. If you want to set the display properties yourself, just put a
  1453. list as second element:
  1454. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1455. For example, to display a 16px horizontal space for Emacs
  1456. category, you can use:
  1457. (\"Emacs\" '(space . (:width (16))))"
  1458. :group 'org-agenda-line-format
  1459. :type '(alist :key-type (string :tag "Regexp matching category")
  1460. :value-type (choice (list :tag "Icon"
  1461. (string :tag "File or data")
  1462. (symbol :tag "Type")
  1463. (boolean :tag "Data?")
  1464. (repeat :tag "Extra image properties" :inline t symbol))
  1465. (list :tag "Display properties" sexp))))
  1466. (defgroup org-agenda-column-view nil
  1467. "Options concerning column view in the agenda."
  1468. :tag "Org Agenda Column View"
  1469. :group 'org-agenda)
  1470. (defcustom org-agenda-columns-show-summaries t
  1471. "Non-nil means show summaries for columns displayed in the agenda view."
  1472. :group 'org-agenda-column-view
  1473. :type 'boolean)
  1474. (defcustom org-agenda-columns-compute-summary-properties t
  1475. "Non-nil means recompute all summary properties before column view.
  1476. When column view in the agenda is listing properties that have a summary
  1477. operator, it can go to all relevant buffers and recompute the summaries
  1478. there. This can mean overhead for the agenda column view, but is necessary
  1479. to have thing up to date.
  1480. As a special case, a CLOCKSUM property also makes sure that the clock
  1481. computations are current."
  1482. :group 'org-agenda-column-view
  1483. :type 'boolean)
  1484. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1485. "Non-nil means the duration of an appointment will add to day effort.
  1486. The property to which appointment durations will be added is the one given
  1487. in the option `org-effort-property'. If an appointment does not have
  1488. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1489. is not set, an appointment without end time will not contribute to the time
  1490. estimate."
  1491. :group 'org-agenda-column-view
  1492. :type 'boolean)
  1493. (defcustom org-agenda-auto-exclude-function nil
  1494. "A function called with a tag to decide if it is filtered on '/ RET'.
  1495. The sole argument to the function, which is called once for each
  1496. possible tag, is a string giving the name of the tag. The
  1497. function should return either nil if the tag should be included
  1498. as normal, or \"-<TAG>\" to exclude the tag.
  1499. Note that for the purpose of tag filtering, only the lower-case version of
  1500. all tags will be considered, so that this function will only ever see
  1501. the lower-case version of all tags."
  1502. :group 'org-agenda
  1503. :type 'function)
  1504. (defcustom org-agenda-bulk-custom-functions nil
  1505. "Alist of characters and custom functions for bulk actions.
  1506. For example, this value makes those two functions available:
  1507. '((?R set-category)
  1508. (?C bulk-cut))
  1509. With selected entries in an agenda buffer, `B R' will call
  1510. the custom function `set-category' on the selected entries.
  1511. Note that functions in this alist don't need to be quoted."
  1512. :type 'alist
  1513. :group 'org-agenda)
  1514. (eval-when-compile
  1515. (require 'cl))
  1516. (require 'org)
  1517. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1518. "Execute BODY with point at location given by `org-hd-marker' property.
  1519. If STRING is non-nil, the text property will be fetched from position 0
  1520. in that string. If STRING is nil, it will be fetched from the beginning
  1521. of the current line."
  1522. (org-with-gensyms (marker)
  1523. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1524. 'org-hd-marker string)))
  1525. (with-current-buffer (marker-buffer ,marker)
  1526. (save-excursion
  1527. (goto-char ,marker)
  1528. ,@body)))))
  1529. (defun org-add-agenda-custom-command (entry)
  1530. "Replace or add a command in `org-agenda-custom-commands'.
  1531. This is mostly for hacking and trying a new command - once the command
  1532. works you probably want to add it to `org-agenda-custom-commands' for good."
  1533. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1534. (if ass
  1535. (setcdr ass (cdr entry))
  1536. (push entry org-agenda-custom-commands))))
  1537. ;;; Define the Org-agenda-mode
  1538. (defvar org-agenda-mode-map (make-sparse-keymap)
  1539. "Keymap for `org-agenda-mode'.")
  1540. (if (fboundp 'defvaralias)
  1541. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1542. (defvar org-agenda-menu) ; defined later in this file.
  1543. (defvar org-agenda-restrict) ; defined later in this file.
  1544. (defvar org-agenda-follow-mode nil)
  1545. (defvar org-agenda-entry-text-mode nil)
  1546. (defvar org-agenda-clockreport-mode nil)
  1547. (defvar org-agenda-show-log nil)
  1548. (defvar org-agenda-redo-command nil)
  1549. (defvar org-agenda-query-string nil)
  1550. (defvar org-agenda-mode-hook nil
  1551. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1552. (defvar org-agenda-type nil)
  1553. (defvar org-agenda-force-single-file nil)
  1554. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1555. (defun org-agenda-mode ()
  1556. "Mode for time-sorted view on action items in Org-mode files.
  1557. The following commands are available:
  1558. \\{org-agenda-mode-map}"
  1559. (interactive)
  1560. (kill-all-local-variables)
  1561. (setq org-agenda-undo-list nil
  1562. org-agenda-pending-undo-list nil
  1563. org-agenda-bulk-marked-entries nil)
  1564. (setq major-mode 'org-agenda-mode)
  1565. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1566. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1567. (setq mode-name "Org-Agenda")
  1568. (use-local-map org-agenda-mode-map)
  1569. (easy-menu-add org-agenda-menu)
  1570. (if org-startup-truncated (setq truncate-lines t))
  1571. (org-set-local 'line-move-visual nil)
  1572. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1573. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1574. ;; Make sure properties are removed when copying text
  1575. (when (boundp 'buffer-substring-filters)
  1576. (org-set-local 'buffer-substring-filters
  1577. (cons (lambda (x)
  1578. (set-text-properties 0 (length x) nil x) x)
  1579. buffer-substring-filters)))
  1580. (unless org-agenda-keep-modes
  1581. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1582. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1583. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1584. org-agenda-show-log org-agenda-start-with-log-mode))
  1585. (easy-menu-change
  1586. '("Agenda") "Agenda Files"
  1587. (append
  1588. (list
  1589. (vector
  1590. (if (get 'org-agenda-files 'org-restrict)
  1591. "Restricted to single file"
  1592. "Edit File List")
  1593. '(org-edit-agenda-file-list)
  1594. (not (get 'org-agenda-files 'org-restrict)))
  1595. "--")
  1596. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1597. (org-agenda-set-mode-name)
  1598. (apply
  1599. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1600. (list 'org-agenda-mode-hook)))
  1601. (substitute-key-definition 'undo 'org-agenda-undo
  1602. org-agenda-mode-map global-map)
  1603. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1604. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1605. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1606. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1607. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1608. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1609. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1610. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1611. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1612. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1613. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1614. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1615. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1617. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1618. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1619. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1620. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1621. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1622. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1623. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1624. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1625. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1626. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1628. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1629. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1630. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1631. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1632. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1633. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1634. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1635. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1636. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1637. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1638. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1639. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1640. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1641. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1642. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1643. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1644. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1645. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1646. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1647. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1648. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1649. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1650. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1651. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1652. (while l (org-defkey org-agenda-mode-map
  1653. (int-to-string (pop l)) 'digit-argument)))
  1654. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1655. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1656. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1657. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1658. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1659. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1660. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1661. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1662. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1663. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1664. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1667. 'org-clock-modify-effort-estimate)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1669. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1670. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1671. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1672. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1673. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1674. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1675. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1676. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1677. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1678. (substitute-key-definition 'next-line 'org-agenda-next-line
  1679. org-agenda-mode-map global-map)
  1680. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1681. org-agenda-mode-map global-map)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1683. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1684. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1685. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1686. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1687. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1688. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1689. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1690. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1691. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1692. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1693. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1694. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1695. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1696. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1697. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1698. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1699. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1700. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1701. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1702. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1703. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1704. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1705. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1706. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1707. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1708. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1709. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1710. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1711. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1712. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1713. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1714. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1715. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1716. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1717. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1718. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1719. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1720. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1721. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1722. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1723. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1724. (when org-agenda-mouse-1-follows-link
  1725. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1726. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1727. '("Agenda"
  1728. ("Agenda Files")
  1729. "--"
  1730. ("Agenda Dates"
  1731. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1732. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1733. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1734. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1735. "--"
  1736. ("View"
  1737. ["Day View" org-agenda-day-view
  1738. :active (org-agenda-check-type nil 'agenda)
  1739. :style radio :selected (eq org-agenda-current-span 'day)
  1740. :keys "v d (or just d)"]
  1741. ["Week View" org-agenda-week-view
  1742. :active (org-agenda-check-type nil 'agenda)
  1743. :style radio :selected (eq org-agenda-current-span 'week)
  1744. :keys "v w (or just w)"]
  1745. ["Month View" org-agenda-month-view
  1746. :active (org-agenda-check-type nil 'agenda)
  1747. :style radio :selected (eq org-agenda-current-span 'month)
  1748. :keys "v m"]
  1749. ["Year View" org-agenda-year-view
  1750. :active (org-agenda-check-type nil 'agenda)
  1751. :style radio :selected (eq org-agenda-current-span 'year)
  1752. :keys "v y"]
  1753. "--"
  1754. ["Include Diary" org-agenda-toggle-diary
  1755. :style toggle :selected org-agenda-include-diary
  1756. :active (org-agenda-check-type nil 'agenda)]
  1757. ["Include Deadlines" org-agenda-toggle-deadlines
  1758. :style toggle :selected org-agenda-include-deadlines
  1759. :active (org-agenda-check-type nil 'agenda)]
  1760. ["Use Time Grid" org-agenda-toggle-time-grid
  1761. :style toggle :selected org-agenda-use-time-grid
  1762. :active (org-agenda-check-type nil 'agenda)]
  1763. "--"
  1764. ["Show clock report" org-agenda-clockreport-mode
  1765. :style toggle :selected org-agenda-clockreport-mode
  1766. :active (org-agenda-check-type nil 'agenda)]
  1767. ["Show some entry text" org-agenda-entry-text-mode
  1768. :style toggle :selected org-agenda-entry-text-mode
  1769. :active t]
  1770. "--"
  1771. ["Show Logbook entries" org-agenda-log-mode
  1772. :style toggle :selected org-agenda-show-log
  1773. :active (org-agenda-check-type nil 'agenda 'timeline)
  1774. :keys "v l (or just l)"]
  1775. ["Include archived trees" org-agenda-archives-mode
  1776. :style toggle :selected org-agenda-archives-mode :active t
  1777. :keys "v a"]
  1778. ["Include archive files" (org-agenda-archives-mode t)
  1779. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1780. :keys "v A"]
  1781. "--"
  1782. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1783. ["Write view to file" org-write-agenda t]
  1784. ["Rebuild buffer" org-agenda-redo t]
  1785. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1786. "--"
  1787. ["Show original entry" org-agenda-show t]
  1788. ["Go To (other window)" org-agenda-goto t]
  1789. ["Go To (this window)" org-agenda-switch-to t]
  1790. ["Follow Mode" org-agenda-follow-mode
  1791. :style toggle :selected org-agenda-follow-mode :active t]
  1792. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1793. "--"
  1794. ("TODO"
  1795. ["Cycle TODO" org-agenda-todo t]
  1796. ["Next TODO set" org-agenda-todo-nextset t]
  1797. ["Previous TODO set" org-agenda-todo-previousset t]
  1798. ["Add note" org-agenda-add-note t])
  1799. ("Archive/Refile/Delete"
  1800. ["Archive default" org-agenda-archive-default t]
  1801. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1802. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1803. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1804. ["Archive subtree" org-agenda-archive t]
  1805. "--"
  1806. ["Refile" org-agenda-refile t]
  1807. "--"
  1808. ["Delete subtree" org-agenda-kill t])
  1809. ("Bulk action"
  1810. ["Mark entry" org-agenda-bulk-mark t]
  1811. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1812. ["Unmark entry" org-agenda-bulk-unmark t]
  1813. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1814. ["Act on all marked" org-agenda-bulk-action t]
  1815. "--"
  1816. ("Tags and Properties"
  1817. ["Show all Tags" org-agenda-show-tags t]
  1818. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1819. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1820. "--"
  1821. ["Column View" org-columns t])
  1822. ("Deadline/Schedule"
  1823. ["Schedule" org-agenda-schedule t]
  1824. ["Set Deadline" org-agenda-deadline t]
  1825. "--"
  1826. ["Mark item" org-agenda-action :active t :keys "k m"]
  1827. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1828. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1829. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1830. "--"
  1831. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1832. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1833. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1834. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1835. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1836. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1837. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1838. ("Clock and Effort"
  1839. ["Clock in" org-agenda-clock-in t]
  1840. ["Clock out" org-agenda-clock-out t]
  1841. ["Clock cancel" org-agenda-clock-cancel t]
  1842. ["Goto running clock" org-clock-goto t]
  1843. "--"
  1844. ["Set Effort" org-agenda-set-effort t]
  1845. ["Change clocked effort" org-clock-modify-effort-estimate
  1846. (org-clock-is-active)])
  1847. ("Priority"
  1848. ["Set Priority" org-agenda-priority t]
  1849. ["Increase Priority" org-agenda-priority-up t]
  1850. ["Decrease Priority" org-agenda-priority-down t]
  1851. ["Show Priority" org-agenda-show-priority t])
  1852. ("Calendar/Diary"
  1853. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1854. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1855. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1856. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1857. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1858. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1859. "--"
  1860. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1861. "--"
  1862. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1863. "--"
  1864. ("MobileOrg"
  1865. ["Push Files and Views" org-mobile-push t]
  1866. ["Get Captured and Flagged" org-mobile-pull t]
  1867. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1868. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1869. "--"
  1870. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1871. "--"
  1872. ["Quit" org-agenda-quit t]
  1873. ["Exit and Release Buffers" org-agenda-exit t]
  1874. ))
  1875. ;;; Agenda undo
  1876. (defvar org-agenda-allow-remote-undo t
  1877. "Non-nil means allow remote undo from the agenda buffer.")
  1878. (defvar org-agenda-undo-list nil
  1879. "List of undoable operations in the agenda since last refresh.")
  1880. (defvar org-agenda-undo-has-started-in nil
  1881. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1882. (defvar org-agenda-pending-undo-list nil
  1883. "In a series of undo commands, this is the list of remaining undo items.")
  1884. (defun org-agenda-undo ()
  1885. "Undo a remote editing step in the agenda.
  1886. This undoes changes both in the agenda buffer and in the remote buffer
  1887. that have been changed along."
  1888. (interactive)
  1889. (or org-agenda-allow-remote-undo
  1890. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1891. (if (not (eq this-command last-command))
  1892. (setq org-agenda-undo-has-started-in nil
  1893. org-agenda-pending-undo-list org-agenda-undo-list))
  1894. (if (not org-agenda-pending-undo-list)
  1895. (error "No further undo information"))
  1896. (let* ((entry (pop org-agenda-pending-undo-list))
  1897. buf line cmd rembuf)
  1898. (setq cmd (pop entry) line (pop entry))
  1899. (setq rembuf (nth 2 entry))
  1900. (org-with-remote-undo rembuf
  1901. (while (bufferp (setq buf (pop entry)))
  1902. (if (pop entry)
  1903. (with-current-buffer buf
  1904. (let ((last-undo-buffer buf)
  1905. (inhibit-read-only t))
  1906. (unless (memq buf org-agenda-undo-has-started-in)
  1907. (push buf org-agenda-undo-has-started-in)
  1908. (make-local-variable 'pending-undo-list)
  1909. (undo-start))
  1910. (while (and pending-undo-list
  1911. (listp pending-undo-list)
  1912. (not (car pending-undo-list)))
  1913. (pop pending-undo-list))
  1914. (undo-more 1))))))
  1915. (org-goto-line line)
  1916. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1917. (defun org-verify-change-for-undo (l1 l2)
  1918. "Verify that a real change occurred between the undo lists L1 and L2."
  1919. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1920. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1921. (not (eq l1 l2)))
  1922. ;;; Agenda dispatch
  1923. (defvar org-agenda-restrict nil)
  1924. (defvar org-agenda-restrict-begin (make-marker))
  1925. (defvar org-agenda-restrict-end (make-marker))
  1926. (defvar org-agenda-last-dispatch-buffer nil)
  1927. (defvar org-agenda-overriding-restriction nil)
  1928. ;;;###autoload
  1929. (defun org-agenda (&optional arg keys restriction)
  1930. "Dispatch agenda commands to collect entries to the agenda buffer.
  1931. Prompts for a command to execute. Any prefix arg will be passed
  1932. on to the selected command. The default selections are:
  1933. a Call `org-agenda-list' to display the agenda for current day or week.
  1934. t Call `org-todo-list' to display the global todo list.
  1935. T Call `org-todo-list' to display the global todo list, select only
  1936. entries with a specific TODO keyword (the user gets a prompt).
  1937. m Call `org-tags-view' to display headlines with tags matching
  1938. a condition (the user is prompted for the condition).
  1939. M Like `m', but select only TODO entries, no ordinary headlines.
  1940. L Create a timeline for the current buffer.
  1941. e Export views to associated files.
  1942. s Search entries for keywords.
  1943. / Multi occur across all agenda files and also files listed
  1944. in `org-agenda-text-search-extra-files'.
  1945. < Restrict agenda commands to buffer, subtree, or region.
  1946. Press several times to get the desired effect.
  1947. > Remove a previous restriction.
  1948. # List \"stuck\" projects.
  1949. ! Configure what \"stuck\" means.
  1950. C Configure custom agenda commands.
  1951. More commands can be added by configuring the variable
  1952. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1953. searches can be pre-defined in this way.
  1954. If the current buffer is in Org-mode and visiting a file, you can also
  1955. first press `<' once to indicate that the agenda should be temporarily
  1956. \(until the next use of \\[org-agenda]) restricted to the current file.
  1957. Pressing `<' twice means to restrict to the current subtree or region
  1958. \(if active)."
  1959. (interactive "P")
  1960. (catch 'exit
  1961. (let* ((prefix-descriptions nil)
  1962. (org-agenda-window-setup (if (equal (buffer-name)
  1963. org-agenda-buffer-name)
  1964. 'current-window
  1965. org-agenda-window-setup))
  1966. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1967. (org-agenda-custom-commands
  1968. ;; normalize different versions
  1969. (delq nil
  1970. (mapcar
  1971. (lambda (x)
  1972. (cond ((stringp (cdr x))
  1973. (push x prefix-descriptions)
  1974. nil)
  1975. ((stringp (nth 1 x)) x)
  1976. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1977. (t (cons (car x) (cons "" (cdr x))))))
  1978. org-agenda-custom-commands)))
  1979. (buf (current-buffer))
  1980. (bfn (buffer-file-name (buffer-base-buffer)))
  1981. entry key type match lprops ans)
  1982. ;; Turn off restriction unless there is an overriding one,
  1983. (unless org-agenda-overriding-restriction
  1984. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1985. ;; There is a request to keep the file list in place
  1986. (put 'org-agenda-files 'org-restrict nil))
  1987. (setq org-agenda-restrict nil)
  1988. (move-marker org-agenda-restrict-begin nil)
  1989. (move-marker org-agenda-restrict-end nil))
  1990. ;; Delete old local properties
  1991. (put 'org-agenda-redo-command 'org-lprops nil)
  1992. ;; Delete previously set last-arguments
  1993. (put 'org-agenda-redo-command 'last-args nil)
  1994. ;; Remember where this call originated
  1995. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1996. (unless keys
  1997. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1998. keys (car ans)
  1999. restriction (cdr ans)))
  2000. ;; Establish the restriction, if any
  2001. (when (and (not org-agenda-overriding-restriction) restriction)
  2002. (put 'org-agenda-files 'org-restrict (list bfn))
  2003. (cond
  2004. ((eq restriction 'region)
  2005. (setq org-agenda-restrict t)
  2006. (move-marker org-agenda-restrict-begin (region-beginning))
  2007. (move-marker org-agenda-restrict-end (region-end)))
  2008. ((eq restriction 'subtree)
  2009. (save-excursion
  2010. (setq org-agenda-restrict t)
  2011. (org-back-to-heading t)
  2012. (move-marker org-agenda-restrict-begin (point))
  2013. (move-marker org-agenda-restrict-end
  2014. (progn (org-end-of-subtree t)))))))
  2015. ;; For example the todo list should not need it (but does...)
  2016. (cond
  2017. ((setq entry (assoc keys org-agenda-custom-commands))
  2018. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2019. (progn
  2020. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2021. lprops (nth 4 entry))
  2022. (put 'org-agenda-redo-command 'org-lprops lprops)
  2023. (cond
  2024. ((eq type 'agenda)
  2025. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2026. ((eq type 'alltodo)
  2027. (org-let lprops '(org-todo-list current-prefix-arg)))
  2028. ((eq type 'search)
  2029. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2030. ((eq type 'stuck)
  2031. (org-let lprops '(org-agenda-list-stuck-projects
  2032. current-prefix-arg)))
  2033. ((eq type 'tags)
  2034. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2035. ((eq type 'tags-todo)
  2036. (org-let lprops '(org-tags-view '(4) match)))
  2037. ((eq type 'todo)
  2038. (org-let lprops '(org-todo-list match)))
  2039. ((eq type 'tags-tree)
  2040. (org-check-for-org-mode)
  2041. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2042. ((eq type 'todo-tree)
  2043. (org-check-for-org-mode)
  2044. (org-let lprops
  2045. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2046. (regexp-quote match) "\\>"))))
  2047. ((eq type 'occur-tree)
  2048. (org-check-for-org-mode)
  2049. (org-let lprops '(org-occur match)))
  2050. ((functionp type)
  2051. (org-let lprops '(funcall type match)))
  2052. ((fboundp type)
  2053. (org-let lprops '(funcall type match)))
  2054. (t (error "Invalid custom agenda command type %s" type))))
  2055. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2056. ((equal keys "C")
  2057. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2058. (customize-variable 'org-agenda-custom-commands))
  2059. ((equal keys "a") (call-interactively 'org-agenda-list))
  2060. ((equal keys "s") (call-interactively 'org-search-view))
  2061. ((equal keys "t") (call-interactively 'org-todo-list))
  2062. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2063. ((equal keys "m") (call-interactively 'org-tags-view))
  2064. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2065. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2066. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2067. (org-add-hook
  2068. 'post-command-hook
  2069. (lambda ()
  2070. (unless (current-message)
  2071. (let* ((m (org-agenda-get-any-marker))
  2072. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2073. (when note
  2074. (message (concat
  2075. "FLAGGING-NOTE ([?] for more info): "
  2076. (org-add-props
  2077. (replace-regexp-in-string
  2078. "\\\\n" "//"
  2079. (copy-sequence note))
  2080. nil 'face 'org-warning)))))))
  2081. t t))
  2082. ((equal keys "L")
  2083. (unless (org-mode-p)
  2084. (error "This is not an Org-mode file"))
  2085. (unless restriction
  2086. (put 'org-agenda-files 'org-restrict (list bfn))
  2087. (org-call-with-arg 'org-timeline arg)))
  2088. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2089. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2090. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2091. (t (error "Invalid agenda key"))))))
  2092. (defun org-agenda-append-agenda ()
  2093. "Append another agenda view to the current one.
  2094. This function allows interactive building of block agendas.
  2095. Agenda views are separated by `org-agenda-block-separator'."
  2096. (interactive)
  2097. (unless (string= (buffer-name) org-agenda-buffer-name)
  2098. (error "Can only append from within agenda buffer"))
  2099. (let ((org-agenda-multi t))
  2100. (org-agenda)
  2101. (widen)))
  2102. (defun org-agenda-normalize-custom-commands (cmds)
  2103. (delq nil
  2104. (mapcar
  2105. (lambda (x)
  2106. (cond ((stringp (cdr x)) nil)
  2107. ((stringp (nth 1 x)) x)
  2108. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2109. (t (cons (car x) (cons "" (cdr x))))))
  2110. cmds)))
  2111. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2112. "The user interface for selecting an agenda command."
  2113. (catch 'exit
  2114. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2115. (restrict-ok (and bfn (org-mode-p)))
  2116. (region-p (org-region-active-p))
  2117. (custom org-agenda-custom-commands)
  2118. (selstring "")
  2119. restriction second-time
  2120. c entry key type match prefixes rmheader header-end custom1 desc
  2121. line lines left right n n1)
  2122. (save-window-excursion
  2123. (delete-other-windows)
  2124. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2125. (erase-buffer)
  2126. (insert (eval-when-compile
  2127. (let ((header
  2128. "
  2129. Press key for an agenda command: < Buffer, subtree/region restriction
  2130. -------------------------------- > Remove restriction
  2131. a Agenda for current week or day e Export agenda views
  2132. t List of all TODO entries T Entries with special TODO kwd
  2133. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2134. L Timeline for current buffer # List stuck projects (!=configure)
  2135. s Search for keywords C Configure custom agenda commands
  2136. / Multi-occur ? Find :FLAGGED: entries
  2137. ")
  2138. (start 0))
  2139. (while (string-match
  2140. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2141. header start)
  2142. (setq start (match-end 0))
  2143. (add-text-properties (match-beginning 2) (match-end 2)
  2144. '(face bold) header))
  2145. header)))
  2146. (setq header-end (move-marker (make-marker) (point)))
  2147. (while t
  2148. (setq custom1 custom)
  2149. (when (eq rmheader t)
  2150. (org-goto-line 1)
  2151. (re-search-forward ":" nil t)
  2152. (delete-region (match-end 0) (point-at-eol))
  2153. (forward-char 1)
  2154. (looking-at "-+")
  2155. (delete-region (match-end 0) (point-at-eol))
  2156. (move-marker header-end (match-end 0)))
  2157. (goto-char header-end)
  2158. (delete-region (point) (point-max))
  2159. ;; Produce all the lines that describe custom commands and prefixes
  2160. (setq lines nil)
  2161. (while (setq entry (pop custom1))
  2162. (setq key (car entry) desc (nth 1 entry)
  2163. type (nth 2 entry)
  2164. match (nth 3 entry))
  2165. (if (> (length key) 1)
  2166. (add-to-list 'prefixes (string-to-char key))
  2167. (setq line
  2168. (format
  2169. "%-4s%-14s"
  2170. (org-add-props (copy-sequence key)
  2171. '(face bold))
  2172. (cond
  2173. ((string-match "\\S-" desc) desc)
  2174. ((eq type 'agenda) "Agenda for current week or day")
  2175. ((eq type 'alltodo) "List of all TODO entries")
  2176. ((eq type 'search) "Word search")
  2177. ((eq type 'stuck) "List of stuck projects")
  2178. ((eq type 'todo) "TODO keyword")
  2179. ((eq type 'tags) "Tags query")
  2180. ((eq type 'tags-todo) "Tags (TODO)")
  2181. ((eq type 'tags-tree) "Tags tree")
  2182. ((eq type 'todo-tree) "TODO kwd tree")
  2183. ((eq type 'occur-tree) "Occur tree")
  2184. ((functionp type) (if (symbolp type)
  2185. (symbol-name type)
  2186. "Lambda expression"))
  2187. (t "???"))))
  2188. (if org-agenda-menu-show-matcher
  2189. (setq line
  2190. (concat line ": "
  2191. (cond
  2192. ((stringp match)
  2193. (setq match (copy-sequence match))
  2194. (org-add-props match nil 'face 'org-warning))
  2195. (match
  2196. (format "set of %d commands" (length match)))
  2197. (t ""))))
  2198. (if (org-string-nw-p match)
  2199. (add-text-properties
  2200. 0 (length line) (list 'help-echo
  2201. (concat "Matcher: "match)) line)))
  2202. (push line lines)))
  2203. (setq lines (nreverse lines))
  2204. (when prefixes
  2205. (mapc (lambda (x)
  2206. (push
  2207. (format "%s %s"
  2208. (org-add-props (char-to-string x)
  2209. nil 'face 'bold)
  2210. (or (cdr (assoc (concat selstring
  2211. (char-to-string x))
  2212. prefix-descriptions))
  2213. "Prefix key"))
  2214. lines))
  2215. prefixes))
  2216. ;; Check if we should display in two columns
  2217. (if org-agenda-menu-two-column
  2218. (progn
  2219. (setq n (length lines)
  2220. n1 (+ (/ n 2) (mod n 2))
  2221. right (nthcdr n1 lines)
  2222. left (copy-sequence lines))
  2223. (setcdr (nthcdr (1- n1) left) nil))
  2224. (setq left lines right nil))
  2225. (while left
  2226. (insert "\n" (pop left))
  2227. (when right
  2228. (if (< (current-column) 40)
  2229. (move-to-column 40 t)
  2230. (insert " "))
  2231. (insert (pop right))))
  2232. ;; Make the window the right size
  2233. (goto-char (point-min))
  2234. (if second-time
  2235. (if (not (pos-visible-in-window-p (point-max)))
  2236. (org-fit-window-to-buffer))
  2237. (setq second-time t)
  2238. (org-fit-window-to-buffer))
  2239. ;; Ask for selection
  2240. (message "Press key for agenda command%s:"
  2241. (if (or restrict-ok org-agenda-overriding-restriction)
  2242. (if org-agenda-overriding-restriction
  2243. " (restriction lock active)"
  2244. (if restriction
  2245. (format " (restricted to %s)" restriction)
  2246. " (unrestricted)"))
  2247. ""))
  2248. (setq c (read-char-exclusive))
  2249. (message "")
  2250. (cond
  2251. ((assoc (char-to-string c) custom)
  2252. (setq selstring (concat selstring (char-to-string c)))
  2253. (throw 'exit (cons selstring restriction)))
  2254. ((memq c prefixes)
  2255. (setq selstring (concat selstring (char-to-string c))
  2256. prefixes nil
  2257. rmheader (or rmheader t)
  2258. custom (delq nil (mapcar
  2259. (lambda (x)
  2260. (if (or (= (length (car x)) 1)
  2261. (/= (string-to-char (car x)) c))
  2262. nil
  2263. (cons (substring (car x) 1) (cdr x))))
  2264. custom))))
  2265. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2266. (message "Restriction is only possible in Org-mode buffers")
  2267. (ding) (sit-for 1))
  2268. ((eq c ?1)
  2269. (org-agenda-remove-restriction-lock 'noupdate)
  2270. (setq restriction 'buffer))
  2271. ((eq c ?0)
  2272. (org-agenda-remove-restriction-lock 'noupdate)
  2273. (setq restriction (if region-p 'region 'subtree)))
  2274. ((eq c ?<)
  2275. (org-agenda-remove-restriction-lock 'noupdate)
  2276. (setq restriction
  2277. (cond
  2278. ((eq restriction 'buffer)
  2279. (if region-p 'region 'subtree))
  2280. ((memq restriction '(subtree region))
  2281. nil)
  2282. (t 'buffer))))
  2283. ((eq c ?>)
  2284. (org-agenda-remove-restriction-lock 'noupdate)
  2285. (setq restriction nil))
  2286. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2287. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2288. ((and (> (length selstring) 0) (eq c ?\d))
  2289. (delete-window)
  2290. (org-agenda-get-restriction-and-command prefix-descriptions))
  2291. ((equal c ?q) (error "Abort"))
  2292. (t (error "Invalid key %c" c))))))))
  2293. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2294. (defvar org-agenda-last-arguments nil
  2295. "The arguments of the previous call to `org-agenda'.")
  2296. (defun org-agenda-run-series (name series)
  2297. (org-let (nth 1 series) '(org-prepare-agenda name))
  2298. (let* ((org-agenda-multi t)
  2299. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2300. (org-agenda-overriding-arguments
  2301. (or org-agenda-overriding-arguments
  2302. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2303. (get 'org-agenda-redo-command 'last-args))))
  2304. (cmds (car series))
  2305. (gprops (nth 1 series))
  2306. match ;; The byte compiler incorrectly complains about this. Keep it!
  2307. cmd type lprops)
  2308. (while (setq cmd (pop cmds))
  2309. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2310. (cond
  2311. ((eq type 'agenda)
  2312. (org-let2 gprops lprops
  2313. '(call-interactively 'org-agenda-list)))
  2314. ((eq type 'alltodo)
  2315. (org-let2 gprops lprops
  2316. '(call-interactively 'org-todo-list)))
  2317. ((eq type 'search)
  2318. (org-let2 gprops lprops
  2319. '(org-search-view current-prefix-arg match nil)))
  2320. ((eq type 'stuck)
  2321. (org-let2 gprops lprops
  2322. '(call-interactively 'org-agenda-list-stuck-projects)))
  2323. ((eq type 'tags)
  2324. (org-let2 gprops lprops
  2325. '(org-tags-view current-prefix-arg match)))
  2326. ((eq type 'tags-todo)
  2327. (org-let2 gprops lprops
  2328. '(org-tags-view '(4) match)))
  2329. ((eq type 'todo)
  2330. (org-let2 gprops lprops
  2331. '(org-todo-list match)))
  2332. ((fboundp type)
  2333. (org-let2 gprops lprops
  2334. '(funcall type match)))
  2335. (t (error "Invalid type in command series"))))
  2336. (widen)
  2337. (setq org-agenda-redo-command redo)
  2338. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2339. (goto-char (point-min)))
  2340. (org-fit-agenda-window)
  2341. (org-let (nth 1 series) '(org-finalize-agenda)))
  2342. ;;;###autoload
  2343. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2344. "Run an agenda command in batch mode and send the result to STDOUT.
  2345. If CMD-KEY is a string of length 1, it is used as a key in
  2346. `org-agenda-custom-commands' and triggers this command. If it is a
  2347. longer string it is used as a tags/todo match string.
  2348. Parameters are alternating variable names and values that will be bound
  2349. before running the agenda command."
  2350. (org-eval-in-environment (org-make-parameter-alist parameters)
  2351. (if (> (length cmd-key) 2)
  2352. (org-tags-view nil cmd-key)
  2353. (org-agenda nil cmd-key)))
  2354. (set-buffer org-agenda-buffer-name)
  2355. (princ (org-encode-for-stdout (buffer-string))))
  2356. ;(defun org-encode-for-stdout (string)
  2357. ; (if (fboundp 'encode-coding-string)
  2358. ; (encode-coding-string string buffer-file-coding-system)
  2359. ; string))
  2360. (defun org-encode-for-stdout (string)
  2361. string)
  2362. (defvar org-agenda-info nil)
  2363. ;;;###autoload
  2364. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2365. "Run an agenda command in batch mode and send the result to STDOUT.
  2366. If CMD-KEY is a string of length 1, it is used as a key in
  2367. `org-agenda-custom-commands' and triggers this command. If it is a
  2368. longer string it is used as a tags/todo match string.
  2369. Parameters are alternating variable names and values that will be bound
  2370. before running the agenda command.
  2371. The output gives a line for each selected agenda item. Each
  2372. item is a list of comma-separated values, like this:
  2373. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2374. category The category of the item
  2375. head The headline, without TODO kwd, TAGS and PRIORITY
  2376. type The type of the agenda entry, can be
  2377. todo selected in TODO match
  2378. tagsmatch selected in tags match
  2379. diary imported from diary
  2380. deadline a deadline on given date
  2381. scheduled scheduled on given date
  2382. timestamp entry has timestamp on given date
  2383. closed entry was closed on given date
  2384. upcoming-deadline warning about deadline
  2385. past-scheduled forwarded scheduled item
  2386. block entry has date block including g. date
  2387. todo The todo keyword, if any
  2388. tags All tags including inherited ones, separated by colons
  2389. date The relevant date, like 2007-2-14
  2390. time The time, like 15:00-16:50
  2391. extra Sting with extra planning info
  2392. priority-l The priority letter if any was given
  2393. priority-n The computed numerical priority
  2394. agenda-day The day in the agenda where this is listed"
  2395. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2396. (org-make-parameter-alist parameters))
  2397. (if (> (length cmd-key) 2)
  2398. (org-tags-view nil cmd-key)
  2399. (org-agenda nil cmd-key)))
  2400. (set-buffer org-agenda-buffer-name)
  2401. (let* ((lines (org-split-string (buffer-string) "\n"))
  2402. line)
  2403. (while (setq line (pop lines))
  2404. (catch 'next
  2405. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2406. (setq org-agenda-info
  2407. (org-fix-agenda-info (text-properties-at 0 line)))
  2408. (princ
  2409. (org-encode-for-stdout
  2410. (mapconcat 'org-agenda-export-csv-mapper
  2411. '(org-category txt type todo tags date time extra
  2412. priority-letter priority agenda-day)
  2413. ",")))
  2414. (princ "\n")))))
  2415. (defun org-fix-agenda-info (props)
  2416. "Make sure all properties on an agenda item have a canonical form.
  2417. This ensures the export commands can easily use it."
  2418. (let (tmp re)
  2419. (when (setq tmp (plist-get props 'tags))
  2420. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2421. (when (setq tmp (plist-get props 'date))
  2422. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2423. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2424. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2425. (setq tmp (calendar-date-string tmp)))
  2426. (setq props (plist-put props 'date tmp)))
  2427. (when (setq tmp (plist-get props 'day))
  2428. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2429. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2430. (setq tmp (calendar-date-string tmp)))
  2431. (setq props (plist-put props 'day tmp))
  2432. (setq props (plist-put props 'agenda-day tmp)))
  2433. (when (setq tmp (plist-get props 'txt))
  2434. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2435. (plist-put props 'priority-letter (match-string 1 tmp))
  2436. (setq tmp (replace-match "" t t tmp)))
  2437. (when (and (setq re (plist-get props 'org-todo-regexp))
  2438. (setq re (concat "\\`\\.*" re " ?"))
  2439. (string-match re tmp))
  2440. (plist-put props 'todo (match-string 1 tmp))
  2441. (setq tmp (replace-match "" t t tmp)))
  2442. (plist-put props 'txt tmp)))
  2443. props)
  2444. (defun org-agenda-export-csv-mapper (prop)
  2445. (let ((res (plist-get org-agenda-info prop)))
  2446. (setq res
  2447. (cond
  2448. ((not res) "")
  2449. ((stringp res) res)
  2450. (t (prin1-to-string res))))
  2451. (while (string-match "," res)
  2452. (setq res (replace-match ";" t t res)))
  2453. (org-trim res)))
  2454. ;;;###autoload
  2455. (defun org-store-agenda-views (&rest parameters)
  2456. (interactive)
  2457. (eval (list 'org-batch-store-agenda-views)))
  2458. ;;;###autoload
  2459. (defmacro org-batch-store-agenda-views (&rest parameters)
  2460. "Run all custom agenda commands that have a file argument."
  2461. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2462. (pop-up-frames nil)
  2463. (dir default-directory)
  2464. (pars (org-make-parameter-alist parameters))
  2465. cmd thiscmdkey files opts cmd-or-set)
  2466. (save-window-excursion
  2467. (while cmds
  2468. (setq cmd (pop cmds)
  2469. thiscmdkey (car cmd)
  2470. cmd-or-set (nth 2 cmd)
  2471. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2472. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2473. (if (stringp files) (setq files (list files)))
  2474. (when files
  2475. (org-eval-in-environment (append org-agenda-exporter-settings
  2476. opts pars)
  2477. (org-agenda nil thiscmdkey))
  2478. (set-buffer org-agenda-buffer-name)
  2479. (while files
  2480. (org-eval-in-environment (append org-agenda-exporter-settings
  2481. opts pars)
  2482. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2483. (and (get-buffer org-agenda-buffer-name)
  2484. (kill-buffer org-agenda-buffer-name)))))))
  2485. (defun org-agenda-mark-header-line (pos)
  2486. "Mark the line at POS as an agenda structure header."
  2487. (save-excursion
  2488. (goto-char pos)
  2489. (put-text-property (point-at-bol) (point-at-eol)
  2490. 'org-agenda-structural-header t)
  2491. (when org-agenda-title-append
  2492. (put-text-property (point-at-bol) (point-at-eol)
  2493. 'org-agenda-title-append org-agenda-title-append))))
  2494. (defvar org-mobile-creating-agendas)
  2495. (defun org-write-agenda (file &optional open nosettings)
  2496. "Write the current buffer (an agenda view) as a file.
  2497. Depending on the extension of the file name, plain text (.txt),
  2498. HTML (.html or .htm) or Postscript (.ps) is produced.
  2499. If the extension is .ics, run icalendar export over all files used
  2500. to construct the agenda and limit the export to entries listed in the
  2501. agenda now.
  2502. With prefix argument OPEN, open the new file immediately.
  2503. If NOSETTINGS is given, do not scope the settings of
  2504. `org-agenda-exporter-settings' into the export commands. This is used when
  2505. the settings have already been scoped and we do not wish to overrule other,
  2506. higher priority settings."
  2507. (interactive "FWrite agenda to file: \nP")
  2508. (if (not (file-writable-p file))
  2509. (error "Cannot write agenda to file %s" file))
  2510. (org-let (if nosettings nil org-agenda-exporter-settings)
  2511. '(save-excursion
  2512. (save-window-excursion
  2513. (org-agenda-mark-filtered-text)
  2514. (let ((bs (copy-sequence (buffer-string))) beg)
  2515. (org-agenda-unmark-filtered-text)
  2516. (with-temp-buffer
  2517. (rename-buffer "Agenda View" t)
  2518. (set-buffer-modified-p nil)
  2519. (insert bs)
  2520. (org-agenda-remove-marked-text 'org-filtered)
  2521. (while (setq beg (text-property-any (point-min) (point-max)
  2522. 'org-filtered t))
  2523. (delete-region
  2524. beg (or (next-single-property-change beg 'org-filtered)
  2525. (point-max))))
  2526. (run-hooks 'org-agenda-before-write-hook)
  2527. (cond
  2528. ((org-bound-and-true-p org-mobile-creating-agendas)
  2529. (org-mobile-write-agenda-for-mobile file))
  2530. ((string-match "\\.html?\\'" file)
  2531. (require 'htmlize)
  2532. (set-buffer (htmlize-buffer (current-buffer)))
  2533. (when (and org-agenda-export-html-style
  2534. (string-match "<style>" org-agenda-export-html-style))
  2535. ;; replace <style> section with org-agenda-export-html-style
  2536. (goto-char (point-min))
  2537. (kill-region (- (search-forward "<style") 6)
  2538. (search-forward "</style>"))
  2539. (insert org-agenda-export-html-style))
  2540. (write-file file)
  2541. (kill-buffer (current-buffer))
  2542. (message "HTML written to %s" file))
  2543. ((string-match "\\.ps\\'" file)
  2544. (require 'ps-print)
  2545. (ps-print-buffer-with-faces file)
  2546. (message "Postscript written to %s" file))
  2547. ((string-match "\\.pdf\\'" file)
  2548. (require 'ps-print)
  2549. (ps-print-buffer-with-faces
  2550. (concat (file-name-sans-extension file) ".ps"))
  2551. (call-process "ps2pdf" nil nil nil
  2552. (expand-file-name
  2553. (concat (file-name-sans-extension file) ".ps"))
  2554. (expand-file-name file))
  2555. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2556. (message "PDF written to %s" file))
  2557. ((string-match "\\.ics\\'" file)
  2558. (require 'org-icalendar)
  2559. (let ((org-agenda-marker-table
  2560. (org-create-marker-find-array
  2561. (org-agenda-collect-markers)))
  2562. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2563. (org-combined-agenda-icalendar-file file))
  2564. (apply 'org-export-icalendar 'combine
  2565. (org-agenda-files nil 'ifmode))))
  2566. (t
  2567. (let ((bs (buffer-string)))
  2568. (find-file file)
  2569. (erase-buffer)
  2570. (insert bs)
  2571. (save-buffer 0)
  2572. (kill-buffer (current-buffer))
  2573. (message "Plain text written to %s" file))))))))
  2574. (set-buffer org-agenda-buffer-name))
  2575. (when open (org-open-file file)))
  2576. (defvar org-agenda-filter-overlays nil)
  2577. (defun org-agenda-mark-filtered-text ()
  2578. "Mark all text hidden by filtering with a text property."
  2579. (let ((inhibit-read-only t))
  2580. (mapc
  2581. (lambda (o)
  2582. (when (equal (overlay-buffer o) (current-buffer))
  2583. (put-text-property
  2584. (overlay-start o) (overlay-end o)
  2585. 'org-filtered t)))
  2586. org-agenda-filter-overlays)))
  2587. (defun org-agenda-unmark-filtered-text ()
  2588. "Remove the filtering text property."
  2589. (let ((inhibit-read-only t))
  2590. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2591. (defun org-agenda-remove-marked-text (property &optional value)
  2592. "Delete all text marked with VALUE of PROPERTY.
  2593. VALUE defaults to t."
  2594. (let (beg)
  2595. (setq value (or value t))
  2596. (while (setq beg (text-property-any (point-min) (point-max)
  2597. property value))
  2598. (delete-region
  2599. beg (or (next-single-property-change beg 'org-filtered)
  2600. (point-max))))))
  2601. (defun org-agenda-add-entry-text ()
  2602. "Add entry text to agenda lines.
  2603. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2604. entry text following headings shown in the agenda.
  2605. Drawers will be excluded, also the line with scheduling/deadline info."
  2606. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2607. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2608. (let (m txt)
  2609. (goto-char (point-min))
  2610. (while (not (eobp))
  2611. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2612. (beginning-of-line 2)
  2613. (setq txt (org-agenda-get-some-entry-text
  2614. m org-agenda-add-entry-text-maxlines " > "))
  2615. (end-of-line 1)
  2616. (if (string-match "\\S-" txt)
  2617. (insert "\n" txt)
  2618. (or (eobp) (forward-char 1))))))))
  2619. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2620. &rest keep)
  2621. "Extract entry text from MARKER, at most N-LINES lines.
  2622. This will ignore drawers etc, just get the text.
  2623. If INDENT is given, prefix every line with this string. If KEEP is
  2624. given, it is a list of symbols, defining stuff that should not be
  2625. removed from the entry content. Currently only `planning' is allowed here."
  2626. (let (txt drawer-re kwd-time-re ind)
  2627. (save-excursion
  2628. (with-current-buffer (marker-buffer marker)
  2629. (if (not (org-mode-p))
  2630. (setq txt "")
  2631. (save-excursion
  2632. (save-restriction
  2633. (widen)
  2634. (goto-char marker)
  2635. (end-of-line 1)
  2636. (setq txt (buffer-substring
  2637. (min (1+ (point)) (point-max))
  2638. (progn (outline-next-heading) (point)))
  2639. drawer-re org-drawer-regexp
  2640. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2641. ".*\n?"))
  2642. (with-temp-buffer
  2643. (insert txt)
  2644. (when org-agenda-add-entry-text-descriptive-links
  2645. (goto-char (point-min))
  2646. (while (org-activate-bracket-links (point-max))
  2647. (add-text-properties (match-beginning 0) (match-end 0)
  2648. '(face org-link))))
  2649. (goto-char (point-min))
  2650. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2651. (set-text-properties (match-beginning 0) (match-end 0)
  2652. nil))
  2653. (goto-char (point-min))
  2654. (while (re-search-forward drawer-re nil t)
  2655. (delete-region
  2656. (match-beginning 0)
  2657. (progn (re-search-forward
  2658. "^[ \t]*:END:.*\n?" nil 'move)
  2659. (point))))
  2660. (unless (member 'planning keep)
  2661. (goto-char (point-min))
  2662. (while (re-search-forward kwd-time-re nil t)
  2663. (replace-match "")))
  2664. (goto-char (point-min))
  2665. (when org-agenda-entry-text-exclude-regexps
  2666. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2667. (while (setq re (pop re-list))
  2668. (goto-char (point-min))
  2669. (while (re-search-forward re nil t)
  2670. (replace-match "")))))
  2671. (goto-char (point-max))
  2672. (skip-chars-backward " \t\n")
  2673. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2674. ;; find and remove min common indentation
  2675. (goto-char (point-min))
  2676. (untabify (point-min) (point-max))
  2677. (setq ind (org-get-indentation))
  2678. (while (not (eobp))
  2679. (unless (looking-at "[ \t]*$")
  2680. (setq ind (min ind (org-get-indentation))))
  2681. (beginning-of-line 2))
  2682. (goto-char (point-min))
  2683. (while (not (eobp))
  2684. (unless (looking-at "[ \t]*$")
  2685. (move-to-column ind)
  2686. (delete-region (point-at-bol) (point)))
  2687. (beginning-of-line 2))
  2688. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2689. (goto-char (point-min))
  2690. (when indent
  2691. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2692. (replace-match indent t t)))
  2693. (goto-char (point-min))
  2694. (while (looking-at "[ \t]*\n") (replace-match ""))
  2695. (goto-char (point-max))
  2696. (when (> (org-current-line)
  2697. n-lines)
  2698. (org-goto-line (1+ n-lines))
  2699. (backward-char 1))
  2700. (setq txt (buffer-substring (point-min) (point)))))))))
  2701. txt))
  2702. (defun org-agenda-collect-markers ()
  2703. "Collect the markers pointing to entries in the agenda buffer."
  2704. (let (m markers)
  2705. (save-excursion
  2706. (goto-char (point-min))
  2707. (while (not (eobp))
  2708. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2709. (org-get-at-bol 'org-marker)))
  2710. (push m markers))
  2711. (beginning-of-line 2)))
  2712. (nreverse markers)))
  2713. (defun org-create-marker-find-array (marker-list)
  2714. "Create a alist of files names with all marker positions in that file."
  2715. (let (f tbl m a p)
  2716. (while (setq m (pop marker-list))
  2717. (setq p (marker-position m)
  2718. f (buffer-file-name (or (buffer-base-buffer
  2719. (marker-buffer m))
  2720. (marker-buffer m))))
  2721. (if (setq a (assoc f tbl))
  2722. (push (marker-position m) (cdr a))
  2723. (push (list f p) tbl)))
  2724. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2725. tbl)))
  2726. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2727. (defun org-check-agenda-marker-table ()
  2728. "Check of the current entry is on the marker list."
  2729. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2730. a)
  2731. (and (setq a (assoc file org-agenda-marker-table))
  2732. (save-match-data
  2733. (save-excursion
  2734. (org-back-to-heading t)
  2735. (member (point) (cdr a)))))))
  2736. (defun org-check-for-org-mode ()
  2737. "Make sure current buffer is in org-mode. Error if not."
  2738. (or (org-mode-p)
  2739. (error "Cannot execute org-mode agenda command on buffer in %s"
  2740. major-mode)))
  2741. (defun org-fit-agenda-window ()
  2742. "Fit the window to the buffer size."
  2743. (and (memq org-agenda-window-setup '(reorganize-frame))
  2744. (fboundp 'fit-window-to-buffer)
  2745. (org-fit-window-to-buffer
  2746. nil
  2747. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2748. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2749. ;;; Agenda prepare and finalize
  2750. (defvar org-agenda-multi nil) ; dynamically scoped
  2751. (defvar org-agenda-buffer-name "*Org Agenda*")
  2752. (defvar org-pre-agenda-window-conf nil)
  2753. (defvar org-agenda-columns-active nil)
  2754. (defvar org-agenda-name nil)
  2755. (defvar org-agenda-filter nil)
  2756. (defvar org-agenda-filter-while-redo nil)
  2757. (defvar org-agenda-filter-preset nil
  2758. "A preset of the tags filter used for secondary agenda filtering.
  2759. This must be a list of strings, each string must be a single tag preceded
  2760. by \"+\" or \"-\".
  2761. This variable should not be set directly, but agenda custom commands can
  2762. bind it in the options section. The preset filter is a global property of
  2763. the entire agenda view. In a block agenda, it will not work reliably to
  2764. define a filter for one of the individual blocks. You need to set it in
  2765. the global options and expect it to be applied to the entire view.")
  2766. (defun org-prepare-agenda (&optional name)
  2767. (setq org-todo-keywords-for-agenda nil)
  2768. (setq org-done-keywords-for-agenda nil)
  2769. (setq org-drawers-for-agenda nil)
  2770. (unless org-agenda-persistent-filter
  2771. (setq org-agenda-filter nil))
  2772. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2773. (if org-agenda-multi
  2774. (progn
  2775. (setq buffer-read-only nil)
  2776. (goto-char (point-max))
  2777. (unless (or (bobp) org-agenda-compact-blocks
  2778. (not org-agenda-block-separator))
  2779. (insert "\n"
  2780. (if (stringp org-agenda-block-separator)
  2781. org-agenda-block-separator
  2782. (make-string (window-width) org-agenda-block-separator))
  2783. "\n"))
  2784. (narrow-to-region (point) (point-max)))
  2785. (org-agenda-reset-markers)
  2786. (setq org-agenda-contributing-files nil)
  2787. (setq org-agenda-columns-active nil)
  2788. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2789. (setq org-todo-keywords-for-agenda
  2790. (org-uniquify org-todo-keywords-for-agenda))
  2791. (setq org-done-keywords-for-agenda
  2792. (org-uniquify org-done-keywords-for-agenda))
  2793. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2794. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2795. (awin (get-buffer-window abuf)))
  2796. (cond
  2797. ((equal (current-buffer) abuf) nil)
  2798. (awin (select-window awin))
  2799. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2800. ((equal org-agenda-window-setup 'current-window)
  2801. (org-pop-to-buffer-same-window abuf))
  2802. ((equal org-agenda-window-setup 'other-window)
  2803. (org-switch-to-buffer-other-window abuf))
  2804. ((equal org-agenda-window-setup 'other-frame)
  2805. (switch-to-buffer-other-frame abuf))
  2806. ((equal org-agenda-window-setup 'reorganize-frame)
  2807. (delete-other-windows)
  2808. (org-switch-to-buffer-other-window abuf)))
  2809. ;; additional test in case agenda is invoked from within agenda
  2810. ;; buffer via elisp link
  2811. (unless (equal (current-buffer) abuf)
  2812. (org-pop-to-buffer-same-window abuf)))
  2813. (setq buffer-read-only nil)
  2814. (let ((inhibit-read-only t)) (erase-buffer))
  2815. (org-agenda-mode)
  2816. (and name (not org-agenda-name)
  2817. (org-set-local 'org-agenda-name name)))
  2818. (setq buffer-read-only nil))
  2819. (defun org-finalize-agenda ()
  2820. "Finishing touch for the agenda buffer, called just before displaying it."
  2821. (unless org-agenda-multi
  2822. (save-excursion
  2823. (let ((inhibit-read-only t))
  2824. (goto-char (point-min))
  2825. (while (org-activate-bracket-links (point-max))
  2826. (add-text-properties (match-beginning 0) (match-end 0)
  2827. '(face org-link)))
  2828. (org-agenda-align-tags)
  2829. (unless org-agenda-with-colors
  2830. (remove-text-properties (point-min) (point-max) '(face nil))))
  2831. (if (and (boundp 'org-agenda-overriding-columns-format)
  2832. org-agenda-overriding-columns-format)
  2833. (org-set-local 'org-agenda-overriding-columns-format
  2834. org-agenda-overriding-columns-format))
  2835. (if (and (boundp 'org-agenda-view-columns-initially)
  2836. org-agenda-view-columns-initially)
  2837. (org-agenda-columns))
  2838. (when org-agenda-fontify-priorities
  2839. (org-agenda-fontify-priorities))
  2840. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2841. (org-agenda-dim-blocked-tasks))
  2842. (org-agenda-mark-clocking-task)
  2843. (when org-agenda-entry-text-mode
  2844. (org-agenda-entry-text-hide)
  2845. (org-agenda-entry-text-show))
  2846. (if (functionp 'org-habit-insert-consistency-graphs)
  2847. (org-habit-insert-consistency-graphs))
  2848. (run-hooks 'org-finalize-agenda-hook)
  2849. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2850. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2851. (org-agenda-filter-apply org-agenda-filter))
  2852. )))
  2853. (defun org-agenda-mark-clocking-task ()
  2854. "Mark the current clock entry in the agenda if it is present."
  2855. (mapc (lambda (o)
  2856. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2857. (delete-overlay o)))
  2858. (overlays-in (point-min) (point-max)))
  2859. (when (marker-buffer org-clock-hd-marker)
  2860. (save-excursion
  2861. (goto-char (point-min))
  2862. (let (s ov)
  2863. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2864. (goto-char s)
  2865. (when (equal (org-get-at-bol 'org-hd-marker)
  2866. org-clock-hd-marker)
  2867. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2868. (overlay-put ov 'type 'org-agenda-clocking)
  2869. (overlay-put ov 'face 'org-agenda-clocking)
  2870. (overlay-put ov 'help-echo
  2871. "The clock is running in this item")))))))
  2872. (defun org-agenda-fontify-priorities ()
  2873. "Make highest priority lines bold, and lowest italic."
  2874. (interactive)
  2875. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2876. (delete-overlay o)))
  2877. (overlays-in (point-min) (point-max)))
  2878. (save-excursion
  2879. (let ((inhibit-read-only t)
  2880. b e p ov h l)
  2881. (goto-char (point-min))
  2882. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2883. (setq h (or (get-char-property (point) 'org-highest-priority)
  2884. org-highest-priority)
  2885. l (or (get-char-property (point) 'org-lowest-priority)
  2886. org-lowest-priority)
  2887. p (string-to-char (match-string 1))
  2888. b (match-beginning 0)
  2889. e (if (eq org-agenda-fontify-priorities 'cookies)
  2890. (match-end 0)
  2891. (point-at-eol))
  2892. ov (make-overlay b e))
  2893. (overlay-put
  2894. ov 'face
  2895. (cond ((org-face-from-face-or-color
  2896. 'priority nil
  2897. (cdr (assoc p org-priority-faces))))
  2898. ((and (listp org-agenda-fontify-priorities)
  2899. (org-face-from-face-or-color
  2900. 'priority nil
  2901. (cdr (assoc p org-agenda-fontify-priorities)))))
  2902. ((equal p l) 'italic)
  2903. ((equal p h) 'bold)))
  2904. (overlay-put ov 'org-type 'org-priority)))))
  2905. (defun org-agenda-dim-blocked-tasks ()
  2906. "Dim currently blocked TODO's in the agenda display."
  2907. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2908. (delete-overlay o)))
  2909. (overlays-in (point-min) (point-max)))
  2910. (save-excursion
  2911. (let ((inhibit-read-only t)
  2912. (org-depend-tag-blocked nil)
  2913. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2914. org-blocked-by-checkboxes
  2915. invis1 b e p ov h l)
  2916. (goto-char (point-min))
  2917. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2918. (and pos (goto-char (1+ pos))))
  2919. (setq org-blocked-by-checkboxes nil invis1 invis)
  2920. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2921. (when (and marker
  2922. (not (with-current-buffer (marker-buffer marker)
  2923. (save-excursion
  2924. (goto-char marker)
  2925. (if (org-entry-get nil "NOBLOCKING")
  2926. t ;; Never block this entry
  2927. (run-hook-with-args-until-failure
  2928. 'org-blocker-hook
  2929. (list :type 'todo-state-change
  2930. :position marker
  2931. :from 'todo
  2932. :to 'done)))))))
  2933. (if org-blocked-by-checkboxes (setq invis1 nil))
  2934. (setq b (if invis1
  2935. (max (point-min) (1- (point-at-bol)))
  2936. (point-at-bol))
  2937. e (point-at-eol)
  2938. ov (make-overlay b e))
  2939. (if invis1
  2940. (overlay-put ov 'invisible t)
  2941. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2942. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2943. (defvar org-agenda-skip-function nil
  2944. "Function to be called at each match during agenda construction.
  2945. If this function returns nil, the current match should not be skipped.
  2946. Otherwise, the function must return a position from where the search
  2947. should be continued.
  2948. This may also be a Lisp form, it will be evaluated.
  2949. Never set this variable using `setq' or so, because then it will apply
  2950. to all future agenda commands. If you do want a global skipping condition,
  2951. use the option `org-agenda-skip-function-global' instead.
  2952. The correct usage for `org-agenda-skip-function' is to bind it with
  2953. `let' to scope it dynamically into the agenda-constructing command.
  2954. A good way to set it is through options in `org-agenda-custom-commands'.")
  2955. (defun org-agenda-skip ()
  2956. "Throw to `:skip' in places that should be skipped.
  2957. Also moves point to the end of the skipped region, so that search can
  2958. continue from there."
  2959. (let ((p (point-at-bol)) to)
  2960. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2961. (get-text-property p :org-archived)
  2962. (org-end-of-subtree t)
  2963. (throw :skip t))
  2964. (and org-agenda-skip-comment-trees
  2965. (get-text-property p :org-comment)
  2966. (org-end-of-subtree t)
  2967. (throw :skip t))
  2968. (if (equal (char-after p) ?#) (throw :skip t))
  2969. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2970. (org-agenda-skip-eval org-agenda-skip-function)))
  2971. (goto-char to)
  2972. (throw :skip t))))
  2973. (defun org-agenda-skip-eval (form)
  2974. "If FORM is a function or a list, call (or eval) is and return result.
  2975. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2976. and match data are returned to the previous state no matter what these
  2977. functions do."
  2978. (let (fp)
  2979. (and form
  2980. (or (setq fp (functionp form))
  2981. (consp form))
  2982. (save-excursion
  2983. (save-match-data
  2984. (if fp
  2985. (funcall form)
  2986. (eval form)))))))
  2987. (defvar org-agenda-markers nil
  2988. "List of all currently active markers created by `org-agenda'.")
  2989. (defvar org-agenda-last-marker-time (org-float-time)
  2990. "Creation time of the last agenda marker.")
  2991. (defun org-agenda-new-marker (&optional pos)
  2992. "Return a new agenda marker.
  2993. Org-mode keeps a list of these markers and resets them when they are
  2994. no longer in use."
  2995. (let ((m (copy-marker (or pos (point)))))
  2996. (setq org-agenda-last-marker-time (org-float-time))
  2997. (push m org-agenda-markers)
  2998. m))
  2999. (defun org-agenda-reset-markers ()
  3000. "Reset markers created by `org-agenda'."
  3001. (while org-agenda-markers
  3002. (move-marker (pop org-agenda-markers) nil)))
  3003. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3004. "Save relative positions of markers in region."
  3005. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3006. org-agenda-markers))
  3007. ;;; Entry text mode
  3008. (defun org-agenda-entry-text-show-here ()
  3009. "Add some text from the entry as context to the current line."
  3010. (let (m txt o)
  3011. (setq m (org-get-at-bol 'org-hd-marker))
  3012. (unless (marker-buffer m)
  3013. (error "No marker points to an entry here"))
  3014. (setq txt (concat "\n" (org-no-properties
  3015. (org-agenda-get-some-entry-text
  3016. m org-agenda-entry-text-maxlines " > "))))
  3017. (when (string-match "\\S-" txt)
  3018. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3019. (overlay-put o 'evaporate t)
  3020. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3021. (overlay-put o 'after-string txt))))
  3022. (defun org-agenda-entry-text-show ()
  3023. "Add entry context for all agenda lines."
  3024. (interactive)
  3025. (save-excursion
  3026. (goto-char (point-max))
  3027. (beginning-of-line 1)
  3028. (while (not (bobp))
  3029. (when (org-get-at-bol 'org-hd-marker)
  3030. (org-agenda-entry-text-show-here))
  3031. (beginning-of-line 0))))
  3032. (defun org-agenda-entry-text-hide ()
  3033. "Remove any shown entry context."
  3034. (delq nil
  3035. (mapcar (lambda (o)
  3036. (if (eq (overlay-get o 'org-overlay-type)
  3037. 'agenda-entry-content)
  3038. (progn (delete-overlay o) t)))
  3039. (overlays-in (point-min) (point-max)))))
  3040. (defun org-agenda-get-day-face (date)
  3041. "Return the face DATE should be displayed with."
  3042. (or (and (functionp org-agenda-day-face-function)
  3043. (funcall org-agenda-day-face-function date))
  3044. (cond ((org-agenda-todayp date)
  3045. 'org-agenda-date-today)
  3046. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3047. 'org-agenda-date-weekend)
  3048. (t 'org-agenda-date))))
  3049. ;;; Agenda timeline
  3050. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3051. (defun org-timeline (&optional include-all)
  3052. "Show a time-sorted view of the entries in the current org file.
  3053. Only entries with a time stamp of today or later will be listed. With
  3054. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3055. under the current date.
  3056. If the buffer contains an active region, only check the region for
  3057. dates."
  3058. (interactive "P")
  3059. (org-compile-prefix-format 'timeline)
  3060. (org-set-sorting-strategy 'timeline)
  3061. (let* ((dopast t)
  3062. (dotodo include-all)
  3063. (doclosed org-agenda-show-log)
  3064. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3065. (current-buffer))))
  3066. (date (calendar-current-date))
  3067. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3068. (end (if (org-region-active-p) (region-end) (point-max)))
  3069. (day-numbers (org-get-all-dates beg end 'no-ranges
  3070. t doclosed ; always include today
  3071. org-timeline-show-empty-dates))
  3072. (org-deadline-warning-days 0)
  3073. (org-agenda-only-exact-dates t)
  3074. (today (org-today))
  3075. (past t)
  3076. args
  3077. s e rtn d emptyp)
  3078. (setq org-agenda-redo-command
  3079. (list 'progn
  3080. (list 'org-switch-to-buffer-other-window (current-buffer))
  3081. (list 'org-timeline (list 'quote include-all))))
  3082. (if (not dopast)
  3083. ;; Remove past dates from the list of dates.
  3084. (setq day-numbers (delq nil (mapcar (lambda(x)
  3085. (if (>= x today) x nil))
  3086. day-numbers))))
  3087. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3088. (if doclosed (push :closed args))
  3089. (push :timestamp args)
  3090. (push :deadline args)
  3091. (push :scheduled args)
  3092. (push :sexp args)
  3093. (if dotodo (push :todo args))
  3094. (insert "Timeline of file " entry "\n")
  3095. (add-text-properties (point-min) (point)
  3096. (list 'face 'org-agenda-structure))
  3097. (org-agenda-mark-header-line (point-min))
  3098. (while (setq d (pop day-numbers))
  3099. (if (and (listp d) (eq (car d) :omitted))
  3100. (progn
  3101. (setq s (point))
  3102. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3103. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3104. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3105. (if (and (>= d today)
  3106. dopast
  3107. past)
  3108. (progn
  3109. (setq past nil)
  3110. (insert (make-string 79 ?-) "\n")))
  3111. (setq date (calendar-gregorian-from-absolute d))
  3112. (setq s (point))
  3113. (setq rtn (and (not emptyp)
  3114. (apply 'org-agenda-get-day-entries entry
  3115. date args)))
  3116. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3117. (progn
  3118. (insert
  3119. (if (stringp org-agenda-format-date)
  3120. (format-time-string org-agenda-format-date
  3121. (org-time-from-absolute date))
  3122. (funcall org-agenda-format-date date))
  3123. "\n")
  3124. (put-text-property s (1- (point)) 'face
  3125. (org-agenda-get-day-face date))
  3126. (put-text-property s (1- (point)) 'org-date-line t)
  3127. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3128. (if (equal d today)
  3129. (put-text-property s (1- (point)) 'org-today t))
  3130. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3131. (put-text-property s (1- (point)) 'day d)))))
  3132. (goto-char (point-min))
  3133. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3134. (point-min)))
  3135. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3136. (org-finalize-agenda)
  3137. (setq buffer-read-only t)))
  3138. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3139. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3140. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3141. not every single day in the range. If FORCE-TODAY is non-nil, make
  3142. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3143. inactive time stamps (those in square brackets) are included.
  3144. When EMPTY is non-nil, also include days without any entries."
  3145. (let ((re (concat
  3146. (if pre-re pre-re "")
  3147. (if inactive org-ts-regexp-both org-ts-regexp)))
  3148. dates dates1 date day day1 day2 ts1 ts2)
  3149. (if force-today
  3150. (setq dates (list (org-today))))
  3151. (save-excursion
  3152. (goto-char beg)
  3153. (while (re-search-forward re end t)
  3154. (setq day (time-to-days (org-time-string-to-time
  3155. (substring (match-string 1) 0 10))))
  3156. (or (memq day dates) (push day dates)))
  3157. (unless no-ranges
  3158. (goto-char beg)
  3159. (while (re-search-forward org-tr-regexp end t)
  3160. (setq ts1 (substring (match-string 1) 0 10)
  3161. ts2 (substring (match-string 2) 0 10)
  3162. day1 (time-to-days (org-time-string-to-time ts1))
  3163. day2 (time-to-days (org-time-string-to-time ts2)))
  3164. (while (< (setq day1 (1+ day1)) day2)
  3165. (or (memq day1 dates) (push day1 dates)))))
  3166. (setq dates (sort dates '<))
  3167. (when empty
  3168. (while (setq day (pop dates))
  3169. (setq day2 (car dates))
  3170. (push day dates1)
  3171. (when (and day2 empty)
  3172. (if (or (eq empty t)
  3173. (and (numberp empty) (<= (- day2 day) empty)))
  3174. (while (< (setq day (1+ day)) day2)
  3175. (push (list day) dates1))
  3176. (push (cons :omitted (- day2 day)) dates1))))
  3177. (setq dates (nreverse dates1)))
  3178. dates)))
  3179. ;;; Agenda Daily/Weekly
  3180. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3181. "Start day for the agenda view.
  3182. Custom commands can set this variable in the options section.")
  3183. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3184. (defvar org-agenda-current-span nil
  3185. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3186. (defvar org-include-all-loc nil) ; local variable
  3187. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3188. "List of types searched for when creating the daily/weekly agenda.
  3189. This variable is a list of symbols that controls the types of
  3190. items that appear in the daily/weekly agenda. Allowed symbols in this
  3191. list are are
  3192. :timestamp List items containing a date stamp or date range matching
  3193. the selected date. This includes sexp entries in
  3194. angular brackets.
  3195. :sexp List entries resulting from plain diary-like sexps.
  3196. :deadline List deadline due on that date. When the date is today,
  3197. also list any deadlines past due, or due within
  3198. `org-deadline-warning-days'. `:deadline' must appear before
  3199. `:scheduled' if the setting of
  3200. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3201. any effect.
  3202. :scheduled List all items which are scheduled for the given date.
  3203. The diary for *today* also contains items which were
  3204. scheduled earlier and are not yet marked DONE.
  3205. By default, all four types are turned on.
  3206. Never set this variable globally using `setq', because then it
  3207. will apply to all future agenda commands. Instead, bind it with
  3208. `let' to scope it dynamically into the agenda-constructing
  3209. command. A good way to set it is through options in
  3210. `org-agenda-custom-commands'. For a more flexible (though
  3211. somewhat less efficient) way of determining what is included in
  3212. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3213. ;;;###autoload
  3214. (defun org-agenda-list (&optional include-all start-day span)
  3215. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3216. The view will be for the current day or week, but from the overview buffer
  3217. you will be able to go to other days/weeks.
  3218. With a numeric prefix argument in an interactive call, the agenda will
  3219. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3220. the number of days. SPAN defaults to `org-agenda-span'.
  3221. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3222. given in `org-agenda-start-on-weekday'."
  3223. (interactive "P")
  3224. (if (and (integerp include-all) (> include-all 0))
  3225. (setq span include-all include-all nil))
  3226. (setq start-day (or start-day org-agenda-start-day))
  3227. (if org-agenda-overriding-arguments
  3228. (setq include-all (car org-agenda-overriding-arguments)
  3229. start-day (nth 1 org-agenda-overriding-arguments)
  3230. span (nth 2 org-agenda-overriding-arguments)))
  3231. (if (stringp start-day)
  3232. ;; Convert to an absolute day number
  3233. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3234. (setq org-agenda-last-arguments (list include-all start-day span))
  3235. (org-compile-prefix-format 'agenda)
  3236. (org-set-sorting-strategy 'agenda)
  3237. (let* ((span (org-agenda-ndays-to-span
  3238. (or span org-agenda-ndays org-agenda-span)))
  3239. (today (org-today))
  3240. (sd (or start-day today))
  3241. (ndays (org-agenda-span-to-ndays span sd))
  3242. (org-agenda-start-on-weekday
  3243. (if (eq ndays 7)
  3244. org-agenda-start-on-weekday))
  3245. (thefiles (org-agenda-files nil 'ifmode))
  3246. (files thefiles)
  3247. (start (if (or (null org-agenda-start-on-weekday)
  3248. (< ndays 7))
  3249. sd
  3250. (let* ((nt (calendar-day-of-week
  3251. (calendar-gregorian-from-absolute sd)))
  3252. (n1 org-agenda-start-on-weekday)
  3253. (d (- nt n1)))
  3254. (- sd (+ (if (< d 0) 7 0) d)))))
  3255. (day-numbers (list start))
  3256. (day-cnt 0)
  3257. (inhibit-redisplay (not debug-on-error))
  3258. s e rtn rtnall file date d start-pos end-pos todayp
  3259. clocktable-start clocktable-end filter)
  3260. (setq org-agenda-redo-command
  3261. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3262. (dotimes (n (1- ndays))
  3263. (push (1+ (car day-numbers)) day-numbers))
  3264. (setq day-numbers (nreverse day-numbers))
  3265. (setq clocktable-start (car day-numbers)
  3266. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3267. (org-prepare-agenda "Day/Week")
  3268. (org-set-local 'org-starting-day (car day-numbers))
  3269. (org-set-local 'org-include-all-loc include-all)
  3270. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3271. (unless org-agenda-compact-blocks
  3272. (let* ((d1 (car day-numbers))
  3273. (d2 (org-last day-numbers))
  3274. (w1 (org-days-to-iso-week d1))
  3275. (w2 (org-days-to-iso-week d2)))
  3276. (setq s (point))
  3277. (if org-agenda-overriding-header
  3278. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3279. nil 'face 'org-agenda-structure) "\n")
  3280. (insert (org-agenda-span-name span)
  3281. "-agenda"
  3282. (if (< (- d2 d1) 350)
  3283. (if (= w1 w2)
  3284. (format " (W%02d)" w1)
  3285. (format " (W%02d-W%02d)" w1 w2))
  3286. "")
  3287. ":\n")))
  3288. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3289. 'org-date-line t))
  3290. (org-agenda-mark-header-line s))
  3291. (while (setq d (pop day-numbers))
  3292. (setq date (calendar-gregorian-from-absolute d)
  3293. s (point))
  3294. (if (or (setq todayp (= d today))
  3295. (and (not start-pos) (= d sd)))
  3296. (setq start-pos (point))
  3297. (if (and start-pos (not end-pos))
  3298. (setq end-pos (point))))
  3299. (setq files thefiles
  3300. rtnall nil)
  3301. (while (setq file (pop files))
  3302. (catch 'nextfile
  3303. (org-check-agenda-file file)
  3304. (let ((org-agenda-entry-types org-agenda-entry-types))
  3305. (unless org-agenda-include-deadlines
  3306. (setq org-agenda-entry-types
  3307. (delq :deadline org-agenda-entry-types)))
  3308. (cond
  3309. ((memq org-agenda-show-log '(only clockcheck))
  3310. (setq rtn (org-agenda-get-day-entries
  3311. file date :closed)))
  3312. (org-agenda-show-log
  3313. (setq rtn (apply 'org-agenda-get-day-entries
  3314. file date
  3315. (append '(:closed) org-agenda-entry-types))))
  3316. (t
  3317. (setq rtn (apply 'org-agenda-get-day-entries
  3318. file date
  3319. org-agenda-entry-types)))))
  3320. (setq rtnall (append rtnall rtn))))
  3321. (if org-agenda-include-diary
  3322. (let ((org-agenda-search-headline-for-time t))
  3323. (require 'diary-lib)
  3324. (setq rtn (org-get-entries-from-diary date))
  3325. (setq rtnall (append rtnall rtn))))
  3326. (if (or rtnall org-agenda-show-all-dates)
  3327. (progn
  3328. (setq day-cnt (1+ day-cnt))
  3329. (insert
  3330. (if (stringp org-agenda-format-date)
  3331. (format-time-string org-agenda-format-date
  3332. (org-time-from-absolute date))
  3333. (funcall org-agenda-format-date date))
  3334. "\n")
  3335. (put-text-property s (1- (point)) 'face
  3336. (org-agenda-get-day-face date))
  3337. (put-text-property s (1- (point)) 'org-date-line t)
  3338. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3339. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3340. (when todayp
  3341. (put-text-property s (1- (point)) 'org-today t))
  3342. (if rtnall (insert
  3343. (org-finalize-agenda-entries
  3344. (org-agenda-add-time-grid-maybe
  3345. rtnall ndays todayp))
  3346. "\n"))
  3347. (put-text-property s (1- (point)) 'day d)
  3348. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3349. (when (and org-agenda-clockreport-mode clocktable-start)
  3350. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3351. ;; the above line is to ensure the restricted range!
  3352. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3353. tbl)
  3354. (setq p (org-plist-delete p :block))
  3355. (setq p (plist-put p :tstart clocktable-start))
  3356. (setq p (plist-put p :tend clocktable-end))
  3357. (setq p (plist-put p :scope 'agenda))
  3358. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3359. (setq filter (or org-agenda-filter-while-redo
  3360. (get 'org-agenda-filter :preset-filter))))
  3361. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3362. (if (string-match "[<>=]" x)
  3363. ""
  3364. x))
  3365. filter ""))))
  3366. (setq tbl (apply 'org-get-clocktable p))
  3367. (insert tbl)))
  3368. (goto-char (point-min))
  3369. (or org-agenda-multi (org-fit-agenda-window))
  3370. (unless (and (pos-visible-in-window-p (point-min))
  3371. (pos-visible-in-window-p (point-max)))
  3372. (goto-char (1- (point-max)))
  3373. (recenter -1)
  3374. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3375. (progn
  3376. (goto-char (or start-pos 1))
  3377. (recenter 1))))
  3378. (goto-char (or start-pos 1))
  3379. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3380. (if (eq org-agenda-show-log 'clockcheck)
  3381. (org-agenda-show-clocking-issues))
  3382. (org-finalize-agenda)
  3383. (setq buffer-read-only t)
  3384. (message "")))
  3385. (defun org-agenda-ndays-to-span (n)
  3386. "Return a span symbol for a span of N days, or N if none matches."
  3387. (cond ((symbolp n) n)
  3388. ((= n 1) 'day)
  3389. ((= n 7) 'week)
  3390. (t n)))
  3391. (defun org-agenda-span-to-ndays (span start-day)
  3392. "Return ndays from SPAN starting at START-DAY."
  3393. (cond ((numberp span) span)
  3394. ((eq span 'day) 1)
  3395. ((eq span 'week) 7)
  3396. ((eq span 'month)
  3397. (let ((date (calendar-gregorian-from-absolute start-day)))
  3398. (calendar-last-day-of-month (car date) (caddr date))))
  3399. ((eq span 'year)
  3400. (let ((date (calendar-gregorian-from-absolute start-day)))
  3401. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3402. (defun org-agenda-span-name (span)
  3403. "Return a SPAN name."
  3404. (if (null span)
  3405. ""
  3406. (if (symbolp span)
  3407. (capitalize (symbol-name span))
  3408. (format "%d days" span))))
  3409. ;;; Agenda word search
  3410. (defvar org-agenda-search-history nil)
  3411. (defvar org-todo-only nil)
  3412. (defvar org-search-syntax-table nil
  3413. "Special syntax table for org-mode search.
  3414. In this table, we have single quotes not as word constituents, to
  3415. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3416. (defun org-search-syntax-table ()
  3417. (unless org-search-syntax-table
  3418. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3419. (modify-syntax-entry ?' "." org-search-syntax-table)
  3420. (modify-syntax-entry ?` "." org-search-syntax-table))
  3421. org-search-syntax-table)
  3422. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3423. ;;;###autoload
  3424. (defun org-search-view (&optional todo-only string edit-at)
  3425. "Show all entries that contain a phrase or words or regular expressions.
  3426. With optional prefix argument TODO-ONLY, only consider entries that are
  3427. TODO entries. The argument STRING can be used to pass a default search
  3428. string into this function. If EDIT-AT is non-nil, it means that the
  3429. user should get a chance to edit this string, with cursor at position
  3430. EDIT-AT.
  3431. The search string can be viewed either as a phrase that should be found as
  3432. is, or it can be broken into a number of snippets, each of which must match
  3433. in a Boolean way to select an entry. The default depends on the variable
  3434. `org-agenda-search-view-always-boolean'.
  3435. Even if this is turned off (the default) you can always switch to
  3436. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3437. The default is a direct search of the whole phrase, where each space in
  3438. the search string can expand to an arbitrary amount of whitespace,
  3439. including newlines.
  3440. If using a Boolean search, the search string is split on whitespace and
  3441. each snippet is searched separately, with logical AND to select an entry.
  3442. Words prefixed with a minus must *not* occur in the entry. Words without
  3443. a prefix or prefixed with a plus must occur in the entry. Matching is
  3444. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3445. match whole words, not parts of a word) if
  3446. `org-agenda-search-view-force-full-words' is set (default is nil).
  3447. Boolean search snippets enclosed by curly braces are interpreted as
  3448. regular expressions that must or (when preceded with \"-\") must not
  3449. match in the entry. Snippets enclosed into double quotes will be taken
  3450. as a whole, to include whitespace.
  3451. - If the search string starts with an asterisk, search only in headlines.
  3452. - If (possibly after the leading star) the search string starts with an
  3453. exclamation mark, this also means to look at TODO entries only, an effect
  3454. that can also be achieved with a prefix argument.
  3455. - If (possibly after star and exclamation mark) the search string starts
  3456. with a colon, this will mean that the (non-regexp) snippets of the
  3457. Boolean search must match as full words.
  3458. This command searches the agenda files, and in addition the files listed
  3459. in `org-agenda-text-search-extra-files'."
  3460. (interactive "P")
  3461. (org-compile-prefix-format 'search)
  3462. (org-set-sorting-strategy 'search)
  3463. (org-prepare-agenda "SEARCH")
  3464. (let* ((props (list 'face nil
  3465. 'done-face 'org-agenda-done
  3466. 'org-not-done-regexp org-not-done-regexp
  3467. 'org-todo-regexp org-todo-regexp
  3468. 'org-complex-heading-regexp org-complex-heading-regexp
  3469. 'mouse-face 'highlight
  3470. 'help-echo (format "mouse-2 or RET jump to location")))
  3471. (full-words org-agenda-search-view-force-full-words)
  3472. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3473. regexp rtn rtnall files file pos
  3474. marker category tags c neg re boolean
  3475. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3476. (unless (and (not edit-at)
  3477. (stringp string)
  3478. (string-match "\\S-" string))
  3479. (setq string (read-string
  3480. (if org-agenda-search-view-always-boolean
  3481. "[+-]Word/{Regexp} ...: "
  3482. "Phrase, or [+-]Word/{Regexp} ...: ")
  3483. (cond
  3484. ((integerp edit-at) (cons string edit-at))
  3485. (edit-at string))
  3486. 'org-agenda-search-history)))
  3487. (org-set-local 'org-todo-only todo-only)
  3488. (setq org-agenda-redo-command
  3489. (list 'org-search-view (if todo-only t nil) string
  3490. '(if current-prefix-arg 1 nil)))
  3491. (setq org-agenda-query-string string)
  3492. (if (equal (string-to-char string) ?*)
  3493. (setq hdl-only t
  3494. words (substring string 1))
  3495. (setq words string))
  3496. (when (equal (string-to-char words) ?!)
  3497. (setq todo-only t
  3498. words (substring words 1)))
  3499. (when (equal (string-to-char words) ?:)
  3500. (setq full-words t
  3501. words (substring words 1)))
  3502. (if (or org-agenda-search-view-always-boolean
  3503. (member (string-to-char words) '(?- ?+ ?\{)))
  3504. (setq boolean t))
  3505. (setq words (org-split-string words))
  3506. (let (www w)
  3507. (while (setq w (pop words))
  3508. (while (and (string-match "\\\\\\'" w) words)
  3509. (setq w (concat (substring w 0 -1) " " (pop words))))
  3510. (push w www))
  3511. (setq words (nreverse www) www nil)
  3512. (while (setq w (pop words))
  3513. (when (and (string-match "\\`[-+]?{" w)
  3514. (not (string-match "}\\'" w)))
  3515. (while (and words (not (string-match "}\\'" (car words))))
  3516. (setq w (concat w " " (pop words))))
  3517. (setq w (concat w " " (pop words))))
  3518. (push w www))
  3519. (setq words (nreverse www)))
  3520. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3521. (when boolean
  3522. (let (wds w)
  3523. (while (setq w (pop words))
  3524. (if (or (equal (substring w 0 1) "\"")
  3525. (and (> (length w) 1)
  3526. (member (substring w 0 1) '("+" "-"))
  3527. (equal (substring w 1 2) "\"")))
  3528. (while (and words (not (equal (substring w -1) "\"")))
  3529. (setq w (concat w " " (pop words)))))
  3530. (and (string-match "\\`\\([-+]?\\)\"" w)
  3531. (setq w (replace-match "\\1" nil nil w)))
  3532. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3533. (push w wds))
  3534. (setq words (nreverse wds))))
  3535. (if boolean
  3536. (mapc (lambda (w)
  3537. (setq c (string-to-char w))
  3538. (if (equal c ?-)
  3539. (setq neg t w (substring w 1))
  3540. (if (equal c ?+)
  3541. (setq neg nil w (substring w 1))
  3542. (setq neg nil)))
  3543. (if (string-match "\\`{.*}\\'" w)
  3544. (setq re (substring w 1 -1))
  3545. (if full-words
  3546. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3547. (setq re (regexp-quote (downcase w)))))
  3548. (if neg (push re regexps-) (push re regexps+)))
  3549. words)
  3550. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3551. regexps+))
  3552. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3553. (if (not regexps+)
  3554. (setq regexp org-outline-regexp-bol)
  3555. (setq regexp (pop regexps+))
  3556. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3557. regexp))))
  3558. (setq files (org-agenda-files nil 'ifmode))
  3559. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3560. (pop org-agenda-text-search-extra-files)
  3561. (setq files (org-add-archive-files files)))
  3562. (setq files (append files org-agenda-text-search-extra-files)
  3563. rtnall nil)
  3564. (while (setq file (pop files))
  3565. (setq ee nil)
  3566. (catch 'nextfile
  3567. (org-check-agenda-file file)
  3568. (setq buffer (if (file-exists-p file)
  3569. (org-get-agenda-file-buffer file)
  3570. (error "No such file %s" file)))
  3571. (if (not buffer)
  3572. ;; If file does not exist, make sure an error message is sent
  3573. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3574. file))))
  3575. (with-current-buffer buffer
  3576. (with-syntax-table (org-search-syntax-table)
  3577. (unless (org-mode-p)
  3578. (error "Agenda file %s is not in `org-mode'" file))
  3579. (let ((case-fold-search t))
  3580. (save-excursion
  3581. (save-restriction
  3582. (if org-agenda-restrict
  3583. (narrow-to-region org-agenda-restrict-begin
  3584. org-agenda-restrict-end)
  3585. (widen))
  3586. (goto-char (point-min))
  3587. (unless (or (org-on-heading-p)
  3588. (outline-next-heading))
  3589. (throw 'nextfile t))
  3590. (goto-char (max (point-min) (1- (point))))
  3591. (while (re-search-forward regexp nil t)
  3592. (org-back-to-heading t)
  3593. (skip-chars-forward "* ")
  3594. (setq beg (point-at-bol)
  3595. beg1 (point)
  3596. end (progn (outline-next-heading) (point)))
  3597. (catch :skip
  3598. (goto-char beg)
  3599. (org-agenda-skip)
  3600. (setq str (buffer-substring-no-properties
  3601. (point-at-bol)
  3602. (if hdl-only (point-at-eol) end)))
  3603. (mapc (lambda (wr) (when (string-match wr str)
  3604. (goto-char (1- end))
  3605. (throw :skip t)))
  3606. regexps-)
  3607. (mapc (lambda (wr) (unless (string-match wr str)
  3608. (goto-char (1- end))
  3609. (throw :skip t)))
  3610. (if todo-only
  3611. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3612. regexps+)
  3613. regexps+))
  3614. (goto-char beg)
  3615. (setq marker (org-agenda-new-marker (point))
  3616. category (org-get-category)
  3617. tags (org-get-tags-at (point))
  3618. txt (org-format-agenda-item
  3619. ""
  3620. (buffer-substring-no-properties
  3621. beg1 (point-at-eol))
  3622. category tags))
  3623. (org-add-props txt props
  3624. 'org-marker marker 'org-hd-marker marker
  3625. 'org-todo-regexp org-todo-regexp
  3626. 'org-complex-heading-regexp org-complex-heading-regexp
  3627. 'priority 1000 'org-category category
  3628. 'type "search")
  3629. (push txt ee)
  3630. (goto-char (1- end))))))))))
  3631. (setq rtn (nreverse ee))
  3632. (setq rtnall (append rtnall rtn)))
  3633. (if org-agenda-overriding-header
  3634. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3635. nil 'face 'org-agenda-structure) "\n")
  3636. (insert "Search words: ")
  3637. (add-text-properties (point-min) (1- (point))
  3638. (list 'face 'org-agenda-structure))
  3639. (setq pos (point))
  3640. (insert string "\n")
  3641. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3642. (setq pos (point))
  3643. (unless org-agenda-multi
  3644. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3645. (add-text-properties pos (1- (point))
  3646. (list 'face 'org-agenda-structure))))
  3647. (org-agenda-mark-header-line (point-min))
  3648. (when rtnall
  3649. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3650. (goto-char (point-min))
  3651. (or org-agenda-multi (org-fit-agenda-window))
  3652. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3653. (org-finalize-agenda)
  3654. (setq buffer-read-only t)))
  3655. ;;; Agenda TODO list
  3656. (defvar org-select-this-todo-keyword nil)
  3657. (defvar org-last-arg nil)
  3658. ;;;###autoload
  3659. (defun org-todo-list (arg)
  3660. "Show all (not done) TODO entries from all agenda file in a single list.
  3661. The prefix arg can be used to select a specific TODO keyword and limit
  3662. the list to these. When using \\[universal-argument], you will be prompted
  3663. for a keyword. A numeric prefix directly selects the Nth keyword in
  3664. `org-todo-keywords-1'."
  3665. (interactive "P")
  3666. (org-compile-prefix-format 'todo)
  3667. (org-set-sorting-strategy 'todo)
  3668. (org-prepare-agenda "TODO")
  3669. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3670. (let* ((today (org-today))
  3671. (date (calendar-gregorian-from-absolute today))
  3672. (kwds org-todo-keywords-for-agenda)
  3673. (completion-ignore-case t)
  3674. (org-select-this-todo-keyword
  3675. (if (stringp arg) arg
  3676. (and arg (integerp arg) (> arg 0)
  3677. (nth (1- arg) kwds))))
  3678. rtn rtnall files file pos)
  3679. (when (equal arg '(4))
  3680. (setq org-select-this-todo-keyword
  3681. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3682. (mapcar 'list kwds) nil nil)))
  3683. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3684. (org-set-local 'org-last-arg arg)
  3685. (setq org-agenda-redo-command
  3686. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3687. (setq files (org-agenda-files nil 'ifmode)
  3688. rtnall nil)
  3689. (while (setq file (pop files))
  3690. (catch 'nextfile
  3691. (org-check-agenda-file file)
  3692. (setq rtn (org-agenda-get-day-entries file date :todo))
  3693. (setq rtnall (append rtnall rtn))))
  3694. (if org-agenda-overriding-header
  3695. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3696. nil 'face 'org-agenda-structure) "\n")
  3697. (insert "Global list of TODO items of type: ")
  3698. (add-text-properties (point-min) (1- (point))
  3699. (list 'face 'org-agenda-structure
  3700. 'short-heading
  3701. (concat "ToDo: "
  3702. (or org-select-this-todo-keyword "ALL"))))
  3703. (org-agenda-mark-header-line (point-min))
  3704. (setq pos (point))
  3705. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3706. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3707. (setq pos (point))
  3708. (unless org-agenda-multi
  3709. (insert "Available with `N r': (0)ALL")
  3710. (let ((n 0) s)
  3711. (mapc (lambda (x)
  3712. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3713. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3714. (insert "\n "))
  3715. (insert " " s))
  3716. kwds))
  3717. (insert "\n"))
  3718. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3719. (org-agenda-mark-header-line (point-min))
  3720. (when rtnall
  3721. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3722. (goto-char (point-min))
  3723. (or org-agenda-multi (org-fit-agenda-window))
  3724. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3725. (org-finalize-agenda)
  3726. (setq buffer-read-only t)))
  3727. ;;; Agenda tags match
  3728. ;;;###autoload
  3729. (defun org-tags-view (&optional todo-only match)
  3730. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3731. The prefix arg TODO-ONLY limits the search to TODO entries."
  3732. (interactive "P")
  3733. (org-compile-prefix-format 'tags)
  3734. (org-set-sorting-strategy 'tags)
  3735. (let* ((org-tags-match-list-sublevels
  3736. org-tags-match-list-sublevels)
  3737. (completion-ignore-case t)
  3738. rtn rtnall files file pos matcher
  3739. buffer)
  3740. (when (and (stringp match) (not (string-match "\\S-" match)))
  3741. (setq match nil))
  3742. (setq matcher (org-make-tags-matcher match)
  3743. match (car matcher) matcher (cdr matcher))
  3744. (org-prepare-agenda (concat "TAGS " match))
  3745. (setq org-agenda-query-string match)
  3746. (setq org-agenda-redo-command
  3747. (list 'org-tags-view (list 'quote todo-only)
  3748. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3749. (setq files (org-agenda-files nil 'ifmode)
  3750. rtnall nil)
  3751. (while (setq file (pop files))
  3752. (catch 'nextfile
  3753. (org-check-agenda-file file)
  3754. (setq buffer (if (file-exists-p file)
  3755. (org-get-agenda-file-buffer file)
  3756. (error "No such file %s" file)))
  3757. (if (not buffer)
  3758. ;; If file does not exist, error message to agenda
  3759. (setq rtn (list
  3760. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3761. rtnall (append rtnall rtn))
  3762. (with-current-buffer buffer
  3763. (unless (org-mode-p)
  3764. (error "Agenda file %s is not in `org-mode'" file))
  3765. (save-excursion
  3766. (save-restriction
  3767. (if org-agenda-restrict
  3768. (narrow-to-region org-agenda-restrict-begin
  3769. org-agenda-restrict-end)
  3770. (widen))
  3771. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3772. (setq rtnall (append rtnall rtn))))))))
  3773. (if org-agenda-overriding-header
  3774. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3775. nil 'face 'org-agenda-structure) "\n")
  3776. (insert "Headlines with TAGS match: ")
  3777. (add-text-properties (point-min) (1- (point))
  3778. (list 'face 'org-agenda-structure
  3779. 'short-heading
  3780. (concat "Match: " match)))
  3781. (setq pos (point))
  3782. (insert match "\n")
  3783. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3784. (setq pos (point))
  3785. (unless org-agenda-multi
  3786. (insert "Press `C-u r' to search again with new search string\n"))
  3787. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3788. (org-agenda-mark-header-line (point-min))
  3789. (when rtnall
  3790. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3791. (goto-char (point-min))
  3792. (or org-agenda-multi (org-fit-agenda-window))
  3793. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3794. (org-finalize-agenda)
  3795. (setq buffer-read-only t)))
  3796. ;;; Agenda Finding stuck projects
  3797. (defvar org-agenda-skip-regexp nil
  3798. "Regular expression used in skipping subtrees for the agenda.
  3799. This is basically a temporary global variable that can be set and then
  3800. used by user-defined selections using `org-agenda-skip-function'.")
  3801. (defvar org-agenda-overriding-header nil
  3802. "When set during agenda, todo and tags searches it replaces the header.
  3803. This variable should not be set directly, but custom commands can bind it
  3804. in the options section.")
  3805. (defun org-agenda-skip-entry-when-regexp-matches ()
  3806. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3807. If yes, it returns the end position of this entry, causing agenda commands
  3808. to skip the entry but continuing the search in the subtree. This is a
  3809. function that can be put into `org-agenda-skip-function' for the duration
  3810. of a command."
  3811. (let ((end (save-excursion (org-end-of-subtree t)))
  3812. skip)
  3813. (save-excursion
  3814. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3815. (and skip end)))
  3816. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3817. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3818. If yes, it returns the end position of this tree, causing agenda commands
  3819. to skip this subtree. This is a function that can be put into
  3820. `org-agenda-skip-function' for the duration of a command."
  3821. (let ((end (save-excursion (org-end-of-subtree t)))
  3822. skip)
  3823. (save-excursion
  3824. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3825. (and skip end)))
  3826. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3827. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3828. If yes, it returns the end position of the current entry (NOT the tree),
  3829. causing agenda commands to skip the entry but continuing the search in
  3830. the subtree. This is a function that can be put into
  3831. `org-agenda-skip-function' for the duration of a command. An important
  3832. use of this function is for the stuck project list."
  3833. (let ((end (save-excursion (org-end-of-subtree t)))
  3834. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3835. skip)
  3836. (save-excursion
  3837. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3838. (and skip entry-end)))
  3839. (defun org-agenda-skip-entry-if (&rest conditions)
  3840. "Skip entry if any of CONDITIONS is true.
  3841. See `org-agenda-skip-if' for details."
  3842. (org-agenda-skip-if nil conditions))
  3843. (defun org-agenda-skip-subtree-if (&rest conditions)
  3844. "Skip entry if any of CONDITIONS is true.
  3845. See `org-agenda-skip-if' for details."
  3846. (org-agenda-skip-if t conditions))
  3847. (defun org-agenda-skip-if (subtree conditions)
  3848. "Checks current entity for CONDITIONS.
  3849. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3850. the entry, i.e. the text before the next heading is checked.
  3851. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3852. from different tests. Valid conditions are:
  3853. scheduled Check if there is a scheduled cookie
  3854. notscheduled Check if there is no scheduled cookie
  3855. deadline Check if there is a deadline
  3856. notdeadline Check if there is no deadline
  3857. timestamp Check if there is a timestamp (also deadline or scheduled)
  3858. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3859. regexp Check if regexp matches
  3860. notregexp Check if regexp does not match.
  3861. todo Check if TODO keyword matches
  3862. nottodo Check if TODO keyword does not match
  3863. The regexp is taken from the conditions list, it must come right after
  3864. the `regexp' or `notregexp' element.
  3865. `todo' and `nottodo' accept as an argument a list of todo
  3866. keywords, which may include \"*\" to match any todo keyword.
  3867. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3868. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3869. Instead of a list a keyword class may be given
  3870. (org-agenda-skip-entry-if 'nottodo 'done)
  3871. would skip entries that haven't been marked with any of \"DONE\"
  3872. keywords. Possible classes are: `todo', `done', `any'.
  3873. If any of these conditions is met, this function returns the end point of
  3874. the entity, causing the search to continue from there. This is a function
  3875. that can be put into `org-agenda-skip-function' for the duration of a command."
  3876. (let (beg end m)
  3877. (org-back-to-heading t)
  3878. (setq beg (point)
  3879. end (if subtree
  3880. (progn (org-end-of-subtree t) (point))
  3881. (progn (outline-next-heading) (1- (point)))))
  3882. (goto-char beg)
  3883. (and
  3884. (or
  3885. (and (memq 'scheduled conditions)
  3886. (re-search-forward org-scheduled-time-regexp end t))
  3887. (and (memq 'notscheduled conditions)
  3888. (not (re-search-forward org-scheduled-time-regexp end t)))
  3889. (and (memq 'deadline conditions)
  3890. (re-search-forward org-deadline-time-regexp end t))
  3891. (and (memq 'notdeadline conditions)
  3892. (not (re-search-forward org-deadline-time-regexp end t)))
  3893. (and (memq 'timestamp conditions)
  3894. (re-search-forward org-ts-regexp end t))
  3895. (and (memq 'nottimestamp conditions)
  3896. (not (re-search-forward org-ts-regexp end t)))
  3897. (and (setq m (memq 'regexp conditions))
  3898. (stringp (nth 1 m))
  3899. (re-search-forward (nth 1 m) end t))
  3900. (and (setq m (memq 'notregexp conditions))
  3901. (stringp (nth 1 m))
  3902. (not (re-search-forward (nth 1 m) end t)))
  3903. (and (or
  3904. (setq m (memq 'todo conditions))
  3905. (setq m (memq 'nottodo conditions)))
  3906. (org-agenda-skip-if-todo m end)))
  3907. end)))
  3908. (defun org-agenda-skip-if-todo (args end)
  3909. "Helper function for `org-agenda-skip-if', do not use it directly.
  3910. ARGS is a list with first element either `todo' or `nottodo'.
  3911. The remainder is either a list of TODO keywords, or a state symbol
  3912. `todo' or `done' or `any'."
  3913. (let ((kw (car args))
  3914. (arg (cadr args))
  3915. todo-wds todo-re)
  3916. (setq todo-wds
  3917. (org-uniquify
  3918. (cond
  3919. ((listp arg) ;; list of keywords
  3920. (if (member "*" arg)
  3921. (mapcar 'substring-no-properties org-todo-keywords-1)
  3922. arg))
  3923. ((symbolp arg) ;; keyword class name
  3924. (cond
  3925. ((eq arg 'todo)
  3926. (org-delete-all org-done-keywords
  3927. (mapcar 'substring-no-properties
  3928. org-todo-keywords-1)))
  3929. ((eq arg 'done) org-done-keywords)
  3930. ((eq arg 'any)
  3931. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3932. (setq todo-re
  3933. (concat "^\\*+[ \t]+\\<\\("
  3934. (mapconcat 'identity todo-wds "\\|")
  3935. "\\)\\>"))
  3936. (if (eq kw 'todo)
  3937. (re-search-forward todo-re end t)
  3938. (not (re-search-forward todo-re end t)))))
  3939. ;;;###autoload
  3940. (defun org-agenda-list-stuck-projects (&rest ignore)
  3941. "Create agenda view for projects that are stuck.
  3942. Stuck projects are project that have no next actions. For the definitions
  3943. of what a project is and how to check if it stuck, customize the variable
  3944. `org-stuck-projects'."
  3945. (interactive)
  3946. (let* ((org-agenda-skip-function
  3947. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3948. ;; We could have used org-agenda-skip-if here.
  3949. (org-agenda-overriding-header
  3950. (or org-agenda-overriding-header "List of stuck projects: "))
  3951. (matcher (nth 0 org-stuck-projects))
  3952. (todo (nth 1 org-stuck-projects))
  3953. (todo-wds (if (member "*" todo)
  3954. (progn
  3955. (org-prepare-agenda-buffers (org-agenda-files
  3956. nil 'ifmode))
  3957. (org-delete-all
  3958. org-done-keywords-for-agenda
  3959. (copy-sequence org-todo-keywords-for-agenda)))
  3960. todo))
  3961. (todo-re (concat "^\\*+[ \t]+\\("
  3962. (mapconcat 'identity todo-wds "\\|")
  3963. "\\)\\>"))
  3964. (tags (nth 2 org-stuck-projects))
  3965. (tags-re (if (member "*" tags)
  3966. (org-re (concat org-outline-regexp-bol
  3967. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3968. (if tags
  3969. (concat org-outline-regexp-bol
  3970. ".*:\\("
  3971. (mapconcat 'identity tags "\\|")
  3972. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3973. (gen-re (nth 3 org-stuck-projects))
  3974. (re-list
  3975. (delq nil
  3976. (list
  3977. (if todo todo-re)
  3978. (if tags tags-re)
  3979. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3980. gen-re)))))
  3981. (setq org-agenda-skip-regexp
  3982. (if re-list
  3983. (mapconcat 'identity re-list "\\|")
  3984. (error "No information how to identify unstuck projects")))
  3985. (org-tags-view nil matcher)
  3986. (with-current-buffer org-agenda-buffer-name
  3987. (setq org-agenda-redo-command
  3988. '(org-agenda-list-stuck-projects
  3989. (or current-prefix-arg org-last-arg))))))
  3990. ;;; Diary integration
  3991. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3992. (defvar list-diary-entries-hook)
  3993. (defvar diary-time-regexp)
  3994. (defun org-get-entries-from-diary (date)
  3995. "Get the (Emacs Calendar) diary entries for DATE."
  3996. (require 'diary-lib)
  3997. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3998. (diary-display-hook '(fancy-diary-display))
  3999. (diary-display-function 'fancy-diary-display)
  4000. (pop-up-frames nil)
  4001. (list-diary-entries-hook
  4002. (cons 'org-diary-default-entry list-diary-entries-hook))
  4003. (diary-file-name-prefix-function nil) ; turn this feature off
  4004. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4005. entries
  4006. (org-disable-agenda-to-diary t))
  4007. (save-excursion
  4008. (save-window-excursion
  4009. (funcall (if (fboundp 'diary-list-entries)
  4010. 'diary-list-entries 'list-diary-entries)
  4011. date 1)))
  4012. (if (not (get-buffer diary-fancy-buffer))
  4013. (setq entries nil)
  4014. (with-current-buffer diary-fancy-buffer
  4015. (setq buffer-read-only nil)
  4016. (if (zerop (buffer-size))
  4017. ;; No entries
  4018. (setq entries nil)
  4019. ;; Omit the date and other unnecessary stuff
  4020. (org-agenda-cleanup-fancy-diary)
  4021. ;; Add prefix to each line and extend the text properties
  4022. (if (zerop (buffer-size))
  4023. (setq entries nil)
  4024. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4025. (setq entries
  4026. (with-temp-buffer
  4027. (insert entries) (goto-char (point-min))
  4028. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4029. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4030. (replace-match (concat "; " (match-string 1)))))
  4031. (buffer-string)))))
  4032. (set-buffer-modified-p nil)
  4033. (kill-buffer diary-fancy-buffer)))
  4034. (when entries
  4035. (setq entries (org-split-string entries "\n"))
  4036. (setq entries
  4037. (mapcar
  4038. (lambda (x)
  4039. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4040. ;; Extend the text properties to the beginning of the line
  4041. (org-add-props x (text-properties-at (1- (length x)) x)
  4042. 'type "diary" 'date date 'face 'org-agenda-diary))
  4043. entries)))))
  4044. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4045. "Hook run when the fancy diary buffer is cleaned up.")
  4046. (defun org-agenda-cleanup-fancy-diary ()
  4047. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4048. This gets rid of the date, the underline under the date, and
  4049. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4050. date. It also removes lines that contain only whitespace."
  4051. (goto-char (point-min))
  4052. (if (looking-at ".*?:[ \t]*")
  4053. (progn
  4054. (replace-match "")
  4055. (re-search-forward "\n=+$" nil t)
  4056. (replace-match "")
  4057. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4058. (re-search-forward "\n=+$" nil t)
  4059. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4060. (goto-char (point-min))
  4061. (while (re-search-forward "^ +\n" nil t)
  4062. (replace-match ""))
  4063. (goto-char (point-min))
  4064. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4065. (replace-match ""))
  4066. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4067. ;; Make sure entries from the diary have the right text properties.
  4068. (eval-after-load "diary-lib"
  4069. '(if (boundp 'diary-modify-entry-list-string-function)
  4070. ;; We can rely on the hook, nothing to do
  4071. nil
  4072. ;; Hook not available, must use advice to make this work
  4073. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4074. "Make the position visible."
  4075. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4076. (stringp string)
  4077. buffer-file-name)
  4078. (setq string (org-modify-diary-entry-string string))))))
  4079. (defun org-modify-diary-entry-string (string)
  4080. "Add text properties to string, allowing org-mode to act on it."
  4081. (org-add-props string nil
  4082. 'mouse-face 'highlight
  4083. 'help-echo (if buffer-file-name
  4084. (format "mouse-2 or RET jump to diary file %s"
  4085. (abbreviate-file-name buffer-file-name))
  4086. "")
  4087. 'org-agenda-diary-link t
  4088. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4089. (defun org-diary-default-entry ()
  4090. "Add a dummy entry to the diary.
  4091. Needed to avoid empty dates which mess up holiday display."
  4092. ;; Catch the error if dealing with the new add-to-diary-alist
  4093. (when org-disable-agenda-to-diary
  4094. (condition-case nil
  4095. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4096. (error
  4097. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4098. (defun org-add-to-diary-list (&rest args)
  4099. (if (fboundp 'diary-add-to-list)
  4100. (apply 'diary-add-to-list args)
  4101. (apply 'add-to-diary-list args)))
  4102. (defvar org-diary-last-run-time nil)
  4103. ;;;###autoload
  4104. (defun org-diary (&rest args)
  4105. "Return diary information from org-files.
  4106. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4107. It accesses org files and extracts information from those files to be
  4108. listed in the diary. The function accepts arguments specifying what
  4109. items should be listed. For a list of arguments allowed here, see the
  4110. variable `org-agenda-entry-types'.
  4111. The call in the diary file should look like this:
  4112. &%%(org-diary) ~/path/to/some/orgfile.org
  4113. Use a separate line for each org file to check. Or, if you omit the file name,
  4114. all files listed in `org-agenda-files' will be checked automatically:
  4115. &%%(org-diary)
  4116. If you don't give any arguments (as in the example above), the default
  4117. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4118. So the example above may also be written as
  4119. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4120. The function expects the lisp variables `entry' and `date' to be provided
  4121. by the caller, because this is how the calendar works. Don't use this
  4122. function from a program - use `org-agenda-get-day-entries' instead."
  4123. (when (> (- (org-float-time)
  4124. org-agenda-last-marker-time)
  4125. 5)
  4126. (org-agenda-reset-markers))
  4127. (org-compile-prefix-format 'agenda)
  4128. (org-set-sorting-strategy 'agenda)
  4129. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4130. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4131. (list entry)
  4132. (org-agenda-files t)))
  4133. (time (org-float-time))
  4134. file rtn results)
  4135. (when (or (not org-diary-last-run-time)
  4136. (> (- time
  4137. org-diary-last-run-time)
  4138. 3))
  4139. (org-prepare-agenda-buffers files))
  4140. (setq org-diary-last-run-time time)
  4141. ;; If this is called during org-agenda, don't return any entries to
  4142. ;; the calendar. Org Agenda will list these entries itself.
  4143. (if org-disable-agenda-to-diary (setq files nil))
  4144. (while (setq file (pop files))
  4145. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4146. (setq results (append results rtn)))
  4147. (if results
  4148. (concat (org-finalize-agenda-entries results) "\n"))))
  4149. ;;; Agenda entry finders
  4150. (defun org-agenda-get-day-entries (file date &rest args)
  4151. "Does the work for `org-diary' and `org-agenda'.
  4152. FILE is the path to a file to be checked for entries. DATE is date like
  4153. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4154. which kind of entries should be extracted. For details about these, see
  4155. the documentation of `org-diary'."
  4156. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4157. (let* ((org-startup-folded nil)
  4158. (org-startup-align-all-tables nil)
  4159. (buffer (if (file-exists-p file)
  4160. (org-get-agenda-file-buffer file)
  4161. (error "No such file %s" file)))
  4162. arg results rtn deadline-results)
  4163. (if (not buffer)
  4164. ;; If file does not exist, make sure an error message ends up in diary
  4165. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4166. (with-current-buffer buffer
  4167. (unless (org-mode-p)
  4168. (error "Agenda file %s is not in `org-mode'" file))
  4169. (let ((case-fold-search nil))
  4170. (save-excursion
  4171. (save-restriction
  4172. (if org-agenda-restrict
  4173. (narrow-to-region org-agenda-restrict-begin
  4174. org-agenda-restrict-end)
  4175. (widen))
  4176. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4177. (while (setq arg (pop args))
  4178. (cond
  4179. ((and (eq arg :todo)
  4180. (equal date (calendar-gregorian-from-absolute
  4181. (org-today))))
  4182. (setq rtn (org-agenda-get-todos))
  4183. (setq results (append results rtn)))
  4184. ((eq arg :timestamp)
  4185. (setq rtn (org-agenda-get-blocks))
  4186. (setq results (append results rtn))
  4187. (setq rtn (org-agenda-get-timestamps))
  4188. (setq results (append results rtn)))
  4189. ((eq arg :sexp)
  4190. (setq rtn (org-agenda-get-sexps))
  4191. (setq results (append results rtn)))
  4192. ((eq arg :scheduled)
  4193. (setq rtn (org-agenda-get-scheduled deadline-results))
  4194. (setq results (append results rtn)))
  4195. ((eq arg :closed)
  4196. (setq rtn (org-agenda-get-progress))
  4197. (setq results (append results rtn)))
  4198. ((eq arg :deadline)
  4199. (setq rtn (org-agenda-get-deadlines))
  4200. (setq deadline-results (copy-sequence rtn))
  4201. (setq results (append results rtn))))))))
  4202. results))))
  4203. (defun org-agenda-get-todos ()
  4204. "Return the TODO information for agenda display."
  4205. (let* ((props (list 'face nil
  4206. 'done-face 'org-agenda-done
  4207. 'org-not-done-regexp org-not-done-regexp
  4208. 'org-todo-regexp org-todo-regexp
  4209. 'org-complex-heading-regexp org-complex-heading-regexp
  4210. 'mouse-face 'highlight
  4211. 'help-echo
  4212. (format "mouse-2 or RET jump to org file %s"
  4213. (abbreviate-file-name buffer-file-name))))
  4214. (regexp (concat "^\\*+[ \t]+\\("
  4215. (if org-select-this-todo-keyword
  4216. (if (equal org-select-this-todo-keyword "*")
  4217. org-todo-regexp
  4218. (concat "\\<\\("
  4219. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4220. "\\)\\>"))
  4221. org-not-done-regexp)
  4222. "[^\n\r]*\\)"))
  4223. marker priority category tags todo-state
  4224. ee txt beg end)
  4225. (goto-char (point-min))
  4226. (while (re-search-forward regexp nil t)
  4227. (catch :skip
  4228. (save-match-data
  4229. (beginning-of-line)
  4230. (org-agenda-skip)
  4231. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4232. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4233. (goto-char (1+ beg))
  4234. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4235. (throw :skip nil)))
  4236. (goto-char (match-beginning 1))
  4237. (setq marker (org-agenda-new-marker (match-beginning 0))
  4238. category (org-get-category)
  4239. txt (match-string 1)
  4240. tags (org-get-tags-at (point))
  4241. txt (org-format-agenda-item "" txt category tags)
  4242. priority (1+ (org-get-priority txt))
  4243. todo-state (org-get-todo-state))
  4244. (org-add-props txt props
  4245. 'org-marker marker 'org-hd-marker marker
  4246. 'priority priority 'org-category category
  4247. 'type "todo" 'todo-state todo-state)
  4248. (push txt ee)
  4249. (if org-agenda-todo-list-sublevels
  4250. (goto-char (match-end 1))
  4251. (org-end-of-subtree 'invisible))))
  4252. (nreverse ee)))
  4253. (defun org-agenda-todo-custom-ignore-p (time n)
  4254. "Check whether timestamp is farther away then n number of days.
  4255. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4256. `org-agenda-todo-ignore-scheduled' or
  4257. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4258. (let ((days (org-days-to-time time)))
  4259. (if (>= n 0)
  4260. (>= days n)
  4261. (<= days n))))
  4262. ;;;###autoload
  4263. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4264. (&optional end)
  4265. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4266. (when (or org-agenda-todo-ignore-with-date
  4267. org-agenda-todo-ignore-scheduled
  4268. org-agenda-todo-ignore-deadlines
  4269. org-agenda-todo-ignore-timestamp)
  4270. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4271. (save-excursion
  4272. (or (and org-agenda-todo-ignore-with-date
  4273. (re-search-forward org-ts-regexp end t))
  4274. (and org-agenda-todo-ignore-scheduled
  4275. (re-search-forward org-scheduled-time-regexp end t)
  4276. (cond
  4277. ((eq org-agenda-todo-ignore-scheduled 'future)
  4278. (> (org-days-to-time (match-string 1)) 0))
  4279. ((eq org-agenda-todo-ignore-scheduled 'past)
  4280. (<= (org-days-to-time (match-string 1)) 0))
  4281. ((numberp org-agenda-todo-ignore-scheduled)
  4282. (org-agenda-todo-custom-ignore-p
  4283. (match-string 1) org-agenda-todo-ignore-scheduled))
  4284. (t)))
  4285. (and org-agenda-todo-ignore-deadlines
  4286. (re-search-forward org-deadline-time-regexp end t)
  4287. (cond
  4288. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4289. ((eq org-agenda-todo-ignore-deadlines 'far)
  4290. (not (org-deadline-close (match-string 1))))
  4291. ((eq org-agenda-todo-ignore-deadlines 'future)
  4292. (> (org-days-to-time (match-string 1)) 0))
  4293. ((eq org-agenda-todo-ignore-deadlines 'past)
  4294. (<= (org-days-to-time (match-string 1)) 0))
  4295. ((numberp org-agenda-todo-ignore-deadlines)
  4296. (org-agenda-todo-custom-ignore-p
  4297. (match-string 1) org-agenda-todo-ignore-deadlines))
  4298. (t (org-deadline-close (match-string 1)))))
  4299. (and org-agenda-todo-ignore-timestamp
  4300. (let ((buffer (current-buffer))
  4301. (regexp
  4302. (concat
  4303. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4304. (start (point)))
  4305. ;; Copy current buffer into a temporary one
  4306. (with-temp-buffer
  4307. (insert-buffer-substring buffer start end)
  4308. (goto-char (point-min))
  4309. ;; Delete SCHEDULED and DEADLINE items
  4310. (while (re-search-forward regexp end t)
  4311. (delete-region (match-beginning 0) (match-end 0)))
  4312. (goto-char (point-min))
  4313. ;; No search for timestamp left
  4314. (when (re-search-forward org-ts-regexp nil t)
  4315. (cond
  4316. ((eq org-agenda-todo-ignore-timestamp 'future)
  4317. (> (org-days-to-time (match-string 1)) 0))
  4318. ((eq org-agenda-todo-ignore-timestamp 'past)
  4319. (<= (org-days-to-time (match-string 1)) 0))
  4320. ((numberp org-agenda-todo-ignore-timestamp)
  4321. (org-agenda-todo-custom-ignore-p
  4322. (match-string 1) org-agenda-todo-ignore-timestamp))
  4323. (t))))))))))
  4324. (defconst org-agenda-no-heading-message
  4325. "No heading for this item in buffer or region.")
  4326. (defun org-agenda-get-timestamps ()
  4327. "Return the date stamp information for agenda display."
  4328. (let* ((props (list 'face nil
  4329. 'org-not-done-regexp org-not-done-regexp
  4330. 'org-todo-regexp org-todo-regexp
  4331. 'org-complex-heading-regexp org-complex-heading-regexp
  4332. 'mouse-face 'highlight
  4333. 'help-echo
  4334. (format "mouse-2 or RET jump to org file %s"
  4335. (abbreviate-file-name buffer-file-name))))
  4336. (d1 (calendar-absolute-from-gregorian date))
  4337. (remove-re
  4338. (concat
  4339. (regexp-quote
  4340. (format-time-string
  4341. "<%Y-%m-%d"
  4342. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4343. ".*?>"))
  4344. (regexp
  4345. (concat
  4346. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4347. (regexp-quote
  4348. (substring
  4349. (format-time-string
  4350. (car org-time-stamp-formats)
  4351. (apply 'encode-time ; DATE bound by calendar
  4352. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4353. 1 11))
  4354. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4355. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4356. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4357. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4358. todo-state end-of-match show-all)
  4359. (goto-char (point-min))
  4360. (while (setq end-of-match (re-search-forward regexp nil t))
  4361. (setq b0 (match-beginning 0)
  4362. b3 (match-beginning 3) e3 (match-end 3)
  4363. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4364. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4365. (member todo-state
  4366. org-agenda-repeating-timestamp-show-all)))
  4367. (catch :skip
  4368. (and (org-at-date-range-p) (throw :skip nil))
  4369. (org-agenda-skip)
  4370. (if (and (match-end 1)
  4371. (not (= d1 (org-time-string-to-absolute
  4372. (match-string 1) d1 nil show-all))))
  4373. (throw :skip nil))
  4374. (if (and e3
  4375. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4376. (throw :skip nil))
  4377. (setq tmp (buffer-substring (max (point-min)
  4378. (- b0 org-ds-keyword-length))
  4379. b0)
  4380. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4381. inactivep (= (char-after b0) ?\[)
  4382. deadlinep (string-match org-deadline-regexp tmp)
  4383. scheduledp (string-match org-scheduled-regexp tmp)
  4384. closedp (and org-agenda-include-inactive-timestamps
  4385. (string-match org-closed-string tmp))
  4386. clockp (and org-agenda-include-inactive-timestamps
  4387. (or (string-match org-clock-string tmp)
  4388. (string-match "]-+\\'" tmp)))
  4389. donep (member todo-state org-done-keywords))
  4390. (if (or scheduledp deadlinep closedp clockp
  4391. (and donep org-agenda-skip-timestamp-if-done))
  4392. (throw :skip t))
  4393. (if (string-match ">" timestr)
  4394. ;; substring should only run to end of time stamp
  4395. (setq timestr (substring timestr 0 (match-end 0))))
  4396. (setq marker (org-agenda-new-marker b0)
  4397. category (org-get-category b0))
  4398. (save-excursion
  4399. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4400. (setq txt org-agenda-no-heading-message)
  4401. (goto-char (match-beginning 0))
  4402. (setq hdmarker (org-agenda-new-marker)
  4403. tags (org-get-tags-at))
  4404. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4405. (setq head (or (match-string 1) ""))
  4406. (setq txt (org-format-agenda-item
  4407. (if inactivep org-agenda-inactive-leader nil)
  4408. head category tags timestr
  4409. remove-re)))
  4410. (setq priority (org-get-priority txt))
  4411. (org-add-props txt props
  4412. 'org-marker marker 'org-hd-marker hdmarker)
  4413. (org-add-props txt nil 'priority priority
  4414. 'org-category category 'date date
  4415. 'todo-state todo-state
  4416. 'type "timestamp")
  4417. (push txt ee))
  4418. (if org-agenda-skip-additional-timestamps-same-entry
  4419. (outline-next-heading)
  4420. (goto-char end-of-match))))
  4421. (nreverse ee)))
  4422. (defun org-agenda-get-sexps ()
  4423. "Return the sexp information for agenda display."
  4424. (require 'diary-lib)
  4425. (let* ((props (list 'mouse-face 'highlight
  4426. 'help-echo
  4427. (format "mouse-2 or RET jump to org file %s"
  4428. (abbreviate-file-name buffer-file-name))))
  4429. (regexp "^&?%%(")
  4430. marker category ee txt tags entry result beg b sexp sexp-entry
  4431. todo-state)
  4432. (goto-char (point-min))
  4433. (while (re-search-forward regexp nil t)
  4434. (catch :skip
  4435. (org-agenda-skip)
  4436. (setq beg (match-beginning 0))
  4437. (goto-char (1- (match-end 0)))
  4438. (setq b (point))
  4439. (forward-sexp 1)
  4440. (setq sexp (buffer-substring b (point)))
  4441. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4442. (org-trim (match-string 1))
  4443. ""))
  4444. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4445. (when result
  4446. (setq marker (org-agenda-new-marker beg)
  4447. category (org-get-category beg)
  4448. todo-state (org-get-todo-state))
  4449. (dolist (r (if (stringp result)
  4450. (list result)
  4451. result)) ;; we expect a list here
  4452. (if (string-match "\\S-" r)
  4453. (setq txt r)
  4454. (setq txt "SEXP entry returned empty string"))
  4455. (setq txt (org-format-agenda-item
  4456. "" txt category tags 'time))
  4457. (org-add-props txt props 'org-marker marker)
  4458. (org-add-props txt nil
  4459. 'org-category category 'date date 'todo-state todo-state
  4460. 'type "sexp")
  4461. (push txt ee)))))
  4462. (nreverse ee)))
  4463. ;; Calendar sanity: define some functions that are independent of
  4464. ;; `calendar-date-style'.
  4465. ;; Normally I would like to use ISO format when calling the diary functions,
  4466. ;; but to make sure we still have Emacs 22 compatibility we bind
  4467. ;; also `european-calendar-style' and use european format
  4468. (defun org-anniversary (year month day &optional mark)
  4469. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4470. (org-no-warnings
  4471. (let ((calendar-date-style 'european) (european-calendar-style t))
  4472. (diary-anniversary day month year mark))))
  4473. (defun org-cyclic (N year month day &optional mark)
  4474. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4475. (org-no-warnings
  4476. (let ((calendar-date-style 'european) (european-calendar-style t))
  4477. (diary-cyclic N day month year mark))))
  4478. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4479. "Like `diary-block', but with fixed (ISO) order of arguments."
  4480. (org-no-warnings
  4481. (let ((calendar-date-style 'european) (european-calendar-style t))
  4482. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4483. (defun org-date (year month day &optional mark)
  4484. "Like `diary-date', but with fixed (ISO) order of arguments."
  4485. (org-no-warnings
  4486. (let ((calendar-date-style 'european) (european-calendar-style t))
  4487. (diary-date day month year mark))))
  4488. (defalias 'org-float 'diary-float)
  4489. ;; Define the` org-class' function
  4490. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4491. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4492. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4493. is any number of ISO weeks in the block period for which the item should
  4494. be skipped."
  4495. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4496. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4497. (d (calendar-absolute-from-gregorian date)))
  4498. (and
  4499. (<= date1 d)
  4500. (<= d date2)
  4501. (= (calendar-day-of-week date) dayname)
  4502. (or (not skip-weeks)
  4503. (progn
  4504. (require 'cal-iso)
  4505. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4506. entry)))
  4507. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4508. "Like `org-class', but honor `calendar-date-style'.
  4509. The order of the first 2 times 3 arguments depends on the variable
  4510. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4511. So for American calendars, give this as MONTH DAY YEAR, for European as
  4512. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4513. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4514. is any number of ISO weeks in the block period for which the item should
  4515. be skipped.
  4516. This function is here only for backward compatibility and it is deprecated,
  4517. please use `org-class' instead."
  4518. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4519. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4520. (org-class
  4521. (nth 2 date1) (car date1) (nth 1 date1)
  4522. (nth 2 date2) (car date2) (nth 1 date2)
  4523. dayname skip-weeks)))
  4524. (defalias 'org-get-closed 'org-agenda-get-progress)
  4525. (defun org-agenda-get-progress ()
  4526. "Return the logged TODO entries for agenda display."
  4527. (let* ((props (list 'mouse-face 'highlight
  4528. 'org-not-done-regexp org-not-done-regexp
  4529. 'org-todo-regexp org-todo-regexp
  4530. 'org-complex-heading-regexp org-complex-heading-regexp
  4531. 'help-echo
  4532. (format "mouse-2 or RET jump to org file %s"
  4533. (abbreviate-file-name buffer-file-name))))
  4534. (items (if (consp org-agenda-show-log)
  4535. org-agenda-show-log
  4536. (if (eq org-agenda-show-log 'clockcheck)
  4537. '(clock)
  4538. org-agenda-log-mode-items)))
  4539. (parts
  4540. (delq nil
  4541. (list
  4542. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4543. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4544. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4545. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4546. (error "`org-agenda-log-mode-items' is empty")))
  4547. (regexp (concat
  4548. "\\(" parts-re "\\)"
  4549. " *\\["
  4550. (regexp-quote
  4551. (substring
  4552. (format-time-string
  4553. (car org-time-stamp-formats)
  4554. (apply 'encode-time ; DATE bound by calendar
  4555. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4556. 1 11))))
  4557. (org-agenda-search-headline-for-time nil)
  4558. marker hdmarker priority category tags closedp statep clockp state
  4559. ee txt extra timestr rest clocked)
  4560. (goto-char (point-min))
  4561. (while (re-search-forward regexp nil t)
  4562. (catch :skip
  4563. (org-agenda-skip)
  4564. (setq marker (org-agenda-new-marker (match-beginning 0))
  4565. closedp (equal (match-string 1) org-closed-string)
  4566. statep (equal (string-to-char (match-string 1)) ?-)
  4567. clockp (not (or closedp statep))
  4568. state (and statep (match-string 2))
  4569. category (org-get-category (match-beginning 0))
  4570. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4571. )
  4572. (when (string-match "\\]" timestr)
  4573. ;; substring should only run to end of time stamp
  4574. (setq rest (substring timestr (match-end 0))
  4575. timestr (substring timestr 0 (match-end 0)))
  4576. (if (and (not closedp) (not statep)
  4577. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4578. (progn (setq timestr (concat (substring timestr 0 -1)
  4579. "-" (match-string 1 rest) "]"))
  4580. (setq clocked (match-string 2 rest)))
  4581. (setq clocked "-")))
  4582. (save-excursion
  4583. (setq extra
  4584. (cond
  4585. ((not org-agenda-log-mode-add-notes) nil)
  4586. (statep
  4587. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4588. (match-string 1)))
  4589. (clockp
  4590. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4591. (match-string 1)))))
  4592. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4593. (setq txt org-agenda-no-heading-message)
  4594. (goto-char (match-beginning 0))
  4595. (setq hdmarker (org-agenda-new-marker)
  4596. tags (org-get-tags-at))
  4597. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4598. (setq txt (match-string 1))
  4599. (when extra
  4600. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4601. (setq txt (concat (substring txt 0 (match-beginning 1))
  4602. " - " extra " " (match-string 2 txt)))
  4603. (setq txt (concat txt " - " extra))))
  4604. (setq txt (org-format-agenda-item
  4605. (cond
  4606. (closedp "Closed: ")
  4607. (statep (concat "State: (" state ")"))
  4608. (t (concat "Clocked: (" clocked ")")))
  4609. txt category tags timestr)))
  4610. (setq priority 100000)
  4611. (org-add-props txt props
  4612. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4613. 'priority priority 'org-category category
  4614. 'type "closed" 'date date
  4615. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4616. (push txt ee))
  4617. (goto-char (point-at-eol))))
  4618. (nreverse ee)))
  4619. (defun org-agenda-show-clocking-issues ()
  4620. "Add overlays, showing issues with clocking.
  4621. See also the user option `org-agenda-clock-consistency-checks'."
  4622. (interactive)
  4623. (let* ((pl org-agenda-clock-consistency-checks)
  4624. (re (concat "^[ \t]*"
  4625. org-clock-string
  4626. "[ \t]+"
  4627. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4628. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4629. (tlstart 0.)
  4630. (tlend 0.)
  4631. (maxtime (org-hh:mm-string-to-minutes
  4632. (or (plist-get pl :max-duration) "24:00")))
  4633. (mintime (org-hh:mm-string-to-minutes
  4634. (or (plist-get pl :min-duration) 0)))
  4635. (maxgap (org-hh:mm-string-to-minutes
  4636. ;; default 30:00 means never complain
  4637. (or (plist-get pl :max-gap) "30:00")))
  4638. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4639. (plist-get pl :gap-ok-around)))
  4640. (def-face (or (plist-get pl :default-face)
  4641. '((:background "DarkRed") (:foreground "white"))))
  4642. issue face m te ts dt ov)
  4643. (goto-char (point-min))
  4644. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4645. (setq issue nil face def-face)
  4646. (catch 'next
  4647. (setq m (org-get-at-bol 'org-marker)
  4648. te nil ts nil)
  4649. (unless (and m (markerp m))
  4650. (setq issue "No valid clock line") (throw 'next t))
  4651. (org-with-point-at m
  4652. (save-excursion
  4653. (goto-char (point-at-bol))
  4654. (unless (looking-at re)
  4655. (error "No valid Clock line")
  4656. (throw 'next t))
  4657. (unless (match-end 3)
  4658. (setq issue "No end time"
  4659. face (or (plist-get pl :no-end-time-face) face))
  4660. (throw 'next t))
  4661. (setq ts (match-string 1)
  4662. te (match-string 3)
  4663. ts (org-float-time
  4664. (apply 'encode-time (org-parse-time-string ts)))
  4665. te (org-float-time
  4666. (apply 'encode-time (org-parse-time-string te)))
  4667. dt (- te ts))))
  4668. (cond
  4669. ((> dt (* 60 maxtime))
  4670. ;; a very long clocking chunk
  4671. (setq issue (format "Clocking interval is very long: %s"
  4672. (org-minutes-to-hh:mm-string
  4673. (floor (/ (float dt) 60.))))
  4674. face (or (plist-get pl :long-face) face)))
  4675. ((< dt (* 60 mintime))
  4676. ;; a very short clocking chunk
  4677. (setq issue (format "Clocking interval is very short: %s"
  4678. (org-minutes-to-hh:mm-string
  4679. (floor (/ (float dt) 60.))))
  4680. face (or (plist-get pl :short-face) face)))
  4681. ((and (> tlend 0) (< ts tlend))
  4682. ;; Two clock entries are overlapping
  4683. (setq issue (format "Clocking overlap: %d minutes"
  4684. (/ (- tlend ts) 60))
  4685. face (or (plist-get pl :overlap-face) face)))
  4686. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4687. ;; There is a gap, lets see if we need to report it
  4688. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4689. (setq issue (format "Clocking gap: %d minutes"
  4690. (/ (- ts tlend) 60))
  4691. face (or (plist-get pl :gap-face) face))))
  4692. (t nil)))
  4693. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4694. (when issue
  4695. ;; OK, there was some issue, add an overlay to show the issue
  4696. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4697. (overlay-put ov 'before-string
  4698. (concat
  4699. (org-add-props
  4700. (format "%-43s" (concat " " issue))
  4701. nil
  4702. 'face face)
  4703. "\n"))
  4704. (overlay-put ov 'evaporate t)))))
  4705. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4706. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4707. (catch 'exit
  4708. (unless ok-list
  4709. ;; there are no OK times for gaps...
  4710. (throw 'exit nil))
  4711. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4712. ;; This is more than 24 hours, so it is OK.
  4713. ;; because we have at least one OK time, that must be in the
  4714. ;; 24 hour interval.
  4715. (throw 'exit t))
  4716. ;; We have a shorter gap.
  4717. ;; Now we have to get the minute of the day when these times are
  4718. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4719. (t2dec (decode-time (seconds-to-time t2)))
  4720. ;; compute the minute on the day
  4721. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4722. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4723. (when (< min2 min1)
  4724. ;; if min2 is smaller than min1, this means it is on the next day.
  4725. ;; Wrap it to after midnight.
  4726. (setq min2 (+ min2 1440)))
  4727. ;; Now check if any of the OK times is in the gap
  4728. (mapc (lambda (x)
  4729. ;; Wrap the time to after midnight if necessary
  4730. (if (< x min1) (setq x (+ x 1440)))
  4731. ;; Check if in interval
  4732. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4733. ok-list)
  4734. ;; Nope, this gap is not OK
  4735. nil)))
  4736. (defun org-agenda-get-deadlines ()
  4737. "Return the deadline information for agenda display."
  4738. (let* ((props (list 'mouse-face 'highlight
  4739. 'org-not-done-regexp org-not-done-regexp
  4740. 'org-todo-regexp org-todo-regexp
  4741. 'org-complex-heading-regexp org-complex-heading-regexp
  4742. 'help-echo
  4743. (format "mouse-2 or RET jump to org file %s"
  4744. (abbreviate-file-name buffer-file-name))))
  4745. (regexp org-deadline-time-regexp)
  4746. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4747. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4748. d2 diff dfrac wdays pos pos1 category tags
  4749. suppress-prewarning
  4750. ee txt head face s todo-state show-all upcomingp donep timestr)
  4751. (goto-char (point-min))
  4752. (while (re-search-forward regexp nil t)
  4753. (setq suppress-prewarning nil)
  4754. (catch :skip
  4755. (org-agenda-skip)
  4756. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4757. (save-match-data
  4758. (string-match org-scheduled-time-regexp
  4759. (buffer-substring (point-at-bol)
  4760. (point-at-eol)))))
  4761. (setq suppress-prewarning
  4762. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4763. org-agenda-skip-deadline-prewarning-if-scheduled
  4764. 0)))
  4765. (setq s (match-string 1)
  4766. txt nil
  4767. pos (1- (match-beginning 1))
  4768. todo-state (save-match-data (org-get-todo-state))
  4769. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4770. (member todo-state
  4771. org-agenda-repeating-timestamp-show-all))
  4772. d2 (org-time-string-to-absolute
  4773. (match-string 1) d1 'past show-all)
  4774. diff (- d2 d1)
  4775. wdays (if suppress-prewarning
  4776. (let ((org-deadline-warning-days suppress-prewarning))
  4777. (org-get-wdays s))
  4778. (org-get-wdays s))
  4779. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4780. upcomingp (and todayp (> diff 0)))
  4781. ;; When to show a deadline in the calendar:
  4782. ;; If the expiration is within wdays warning time.
  4783. ;; Past-due deadlines are only shown on the current date
  4784. (if (and (or (and (<= diff wdays)
  4785. (and todayp (not org-agenda-only-exact-dates)))
  4786. (= diff 0)))
  4787. (save-excursion
  4788. ;; (setq todo-state (org-get-todo-state))
  4789. (setq donep (member todo-state org-done-keywords))
  4790. (if (and donep
  4791. (or org-agenda-skip-deadline-if-done
  4792. (not (= diff 0))))
  4793. (setq txt nil)
  4794. (setq category (org-get-category))
  4795. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4796. (setq txt org-agenda-no-heading-message)
  4797. (goto-char (match-end 0))
  4798. (setq pos1 (match-beginning 0))
  4799. (setq tags (org-get-tags-at pos1))
  4800. (setq head (buffer-substring-no-properties
  4801. (point)
  4802. (progn (skip-chars-forward "^\r\n")
  4803. (point))))
  4804. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4805. (setq timestr
  4806. (concat (substring s (match-beginning 1)) " "))
  4807. (setq timestr 'time))
  4808. (setq txt (org-format-agenda-item
  4809. (if (= diff 0)
  4810. (car org-agenda-deadline-leaders)
  4811. (if (functionp
  4812. (nth 1 org-agenda-deadline-leaders))
  4813. (funcall
  4814. (nth 1 org-agenda-deadline-leaders)
  4815. diff date)
  4816. (format (nth 1 org-agenda-deadline-leaders)
  4817. diff)))
  4818. head category tags
  4819. (if (not (= diff 0)) nil timestr)))))
  4820. (when txt
  4821. (setq face (org-agenda-deadline-face dfrac wdays))
  4822. (org-add-props txt props
  4823. 'org-marker (org-agenda-new-marker pos)
  4824. 'org-hd-marker (org-agenda-new-marker pos1)
  4825. 'priority (+ (- diff)
  4826. (org-get-priority txt))
  4827. 'org-category category
  4828. 'todo-state todo-state
  4829. 'type (if upcomingp "upcoming-deadline" "deadline")
  4830. 'date (if upcomingp date d2)
  4831. 'face (if donep 'org-agenda-done face)
  4832. 'undone-face face 'done-face 'org-agenda-done)
  4833. (push txt ee))))))
  4834. (nreverse ee)))
  4835. (defun org-agenda-deadline-face (fraction &optional wdays)
  4836. "Return the face to displaying a deadline item.
  4837. FRACTION is what fraction of the head-warning time has passed."
  4838. (if (equal wdays 0) (setq fraction 1.))
  4839. (let ((faces org-agenda-deadline-faces) f)
  4840. (catch 'exit
  4841. (while (setq f (pop faces))
  4842. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4843. (defun org-agenda-get-scheduled (&optional deadline-results)
  4844. "Return the scheduled information for agenda display."
  4845. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4846. 'org-todo-regexp org-todo-regexp
  4847. 'org-complex-heading-regexp org-complex-heading-regexp
  4848. 'done-face 'org-agenda-done
  4849. 'mouse-face 'highlight
  4850. 'help-echo
  4851. (format "mouse-2 or RET jump to org file %s"
  4852. (abbreviate-file-name buffer-file-name))))
  4853. (regexp org-scheduled-time-regexp)
  4854. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4855. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4856. mm
  4857. (deadline-position-alist
  4858. (mapcar (lambda (a) (and (setq mm (get-text-property
  4859. 0 'org-hd-marker a))
  4860. (cons (marker-position mm) a)))
  4861. deadline-results))
  4862. d2 diff pos pos1 category tags donep
  4863. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4864. (goto-char (point-min))
  4865. (while (re-search-forward regexp nil t)
  4866. (catch :skip
  4867. (org-agenda-skip)
  4868. (setq s (match-string 1)
  4869. txt nil
  4870. pos (1- (match-beginning 1))
  4871. todo-state (save-match-data (org-get-todo-state))
  4872. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4873. (member todo-state
  4874. org-agenda-repeating-timestamp-show-all))
  4875. d2 (org-time-string-to-absolute
  4876. (match-string 1) d1 'past show-all)
  4877. diff (- d2 d1))
  4878. (setq pastschedp (and todayp (< diff 0)))
  4879. ;; When to show a scheduled item in the calendar:
  4880. ;; If it is on or past the date.
  4881. (when (or (and (< diff 0)
  4882. (< (abs diff) org-scheduled-past-days)
  4883. (and todayp (not org-agenda-only-exact-dates)))
  4884. (= diff 0))
  4885. (save-excursion
  4886. (setq donep (member todo-state org-done-keywords))
  4887. (if (and donep
  4888. (or org-agenda-skip-scheduled-if-done
  4889. (not (= diff 0))
  4890. (and (functionp 'org-is-habit-p)
  4891. (org-is-habit-p))))
  4892. (setq txt nil)
  4893. (setq habitp (and (functionp 'org-is-habit-p)
  4894. (org-is-habit-p)))
  4895. (setq category (org-get-category))
  4896. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4897. (setq txt org-agenda-no-heading-message)
  4898. (goto-char (match-end 0))
  4899. (setq pos1 (match-beginning 0))
  4900. (if habitp
  4901. (if (or (not org-habit-show-habits)
  4902. (and (not todayp)
  4903. org-habit-show-habits-only-for-today))
  4904. (throw :skip nil))
  4905. (if (and
  4906. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4907. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4908. pastschedp))
  4909. (setq mm (assoc pos1 deadline-position-alist)))
  4910. (throw :skip nil)))
  4911. (setq tags (org-get-tags-at))
  4912. (setq head (buffer-substring-no-properties
  4913. (point)
  4914. (progn (skip-chars-forward "^\r\n") (point))))
  4915. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4916. (setq timestr
  4917. (concat (substring s (match-beginning 1)) " "))
  4918. (setq timestr 'time))
  4919. (setq txt (org-format-agenda-item
  4920. (if (= diff 0)
  4921. (car org-agenda-scheduled-leaders)
  4922. (format (nth 1 org-agenda-scheduled-leaders)
  4923. (- 1 diff)))
  4924. head category tags
  4925. (if (not (= diff 0)) nil timestr)
  4926. nil habitp))))
  4927. (when txt
  4928. (setq face
  4929. (cond
  4930. ((and (not habitp) pastschedp)
  4931. 'org-scheduled-previously)
  4932. (todayp 'org-scheduled-today)
  4933. (t 'org-scheduled))
  4934. habitp (and habitp (org-habit-parse-todo)))
  4935. (org-add-props txt props
  4936. 'undone-face face
  4937. 'face (if donep 'org-agenda-done face)
  4938. 'org-marker (org-agenda-new-marker pos)
  4939. 'org-hd-marker (org-agenda-new-marker pos1)
  4940. 'type (if pastschedp "past-scheduled" "scheduled")
  4941. 'date (if pastschedp d2 date)
  4942. 'priority (if habitp
  4943. (org-habit-get-priority habitp)
  4944. (+ 94 (- 5 diff) (org-get-priority txt)))
  4945. 'org-category category
  4946. 'org-habit-p habitp
  4947. 'todo-state todo-state)
  4948. (push txt ee))))))
  4949. (nreverse ee)))
  4950. (defun org-agenda-get-blocks ()
  4951. "Return the date-range information for agenda display."
  4952. (let* ((props (list 'face nil
  4953. 'org-not-done-regexp org-not-done-regexp
  4954. 'org-todo-regexp org-todo-regexp
  4955. 'org-complex-heading-regexp org-complex-heading-regexp
  4956. 'mouse-face 'highlight
  4957. 'help-echo
  4958. (format "mouse-2 or RET jump to org file %s"
  4959. (abbreviate-file-name buffer-file-name))))
  4960. (regexp org-tr-regexp)
  4961. (d0 (calendar-absolute-from-gregorian date))
  4962. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4963. head donep)
  4964. (goto-char (point-min))
  4965. (while (re-search-forward regexp nil t)
  4966. (catch :skip
  4967. (org-agenda-skip)
  4968. (setq pos (point))
  4969. (let ((start-time (match-string 1))
  4970. (end-time (match-string 2)))
  4971. (setq s1 (match-string 1)
  4972. s2 (match-string 2)
  4973. d1 (time-to-days (org-time-string-to-time s1))
  4974. d2 (time-to-days (org-time-string-to-time s2)))
  4975. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4976. ;; Only allow days between the limits, because the normal
  4977. ;; date stamps will catch the limits.
  4978. (save-excursion
  4979. (setq todo-state (org-get-todo-state))
  4980. (setq donep (member todo-state org-done-keywords))
  4981. (if (and donep org-agenda-skip-timestamp-if-done)
  4982. (throw :skip t))
  4983. (setq marker (org-agenda-new-marker (point)))
  4984. (setq category (org-get-category))
  4985. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4986. (setq txt org-agenda-no-heading-message)
  4987. (goto-char (match-beginning 0))
  4988. (setq hdmarker (org-agenda-new-marker (point)))
  4989. (setq tags (org-get-tags-at))
  4990. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4991. (setq head (match-string 1))
  4992. (let ((remove-re
  4993. (if org-agenda-remove-timeranges-from-blocks
  4994. (concat
  4995. "<" (regexp-quote s1) ".*?>"
  4996. "--"
  4997. "<" (regexp-quote s2) ".*?>")
  4998. nil)))
  4999. (setq txt (org-format-agenda-item
  5000. (format
  5001. (nth (if (= d1 d2) 0 1)
  5002. org-agenda-timerange-leaders)
  5003. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5004. head category tags
  5005. (cond ((= d1 d0)
  5006. (concat "<" start-time ">"))
  5007. ((= d2 d0)
  5008. (concat "<" end-time ">"))
  5009. (t nil))
  5010. remove-re))))
  5011. (org-add-props txt props
  5012. 'org-marker marker 'org-hd-marker hdmarker
  5013. 'type "block" 'date date
  5014. 'todo-state todo-state
  5015. 'priority (org-get-priority txt) 'org-category category)
  5016. (push txt ee))))
  5017. (goto-char pos)))
  5018. ;; Sort the entries by expiration date.
  5019. (nreverse ee)))
  5020. ;;; Agenda presentation and sorting
  5021. (defvar org-prefix-has-time nil
  5022. "A flag, set by `org-compile-prefix-format'.
  5023. The flag is set if the currently compiled format contains a `%t'.")
  5024. (defvar org-prefix-has-tag nil
  5025. "A flag, set by `org-compile-prefix-format'.
  5026. The flag is set if the currently compiled format contains a `%T'.")
  5027. (defvar org-prefix-has-effort nil
  5028. "A flag, set by `org-compile-prefix-format'.
  5029. The flag is set if the currently compiled format contains a `%e'.")
  5030. (defvar org-prefix-category-length nil
  5031. "Used by `org-compile-prefix-format' to remember the category field width.")
  5032. (defvar org-prefix-category-max-length nil
  5033. "Used by `org-compile-prefix-format' to remember the category field width.")
  5034. (defun org-agenda-get-category-icon (category)
  5035. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5036. (dolist (entry org-agenda-category-icon-alist)
  5037. (when (org-string-match-p (car entry) category)
  5038. (if (listp (cadr entry))
  5039. (return (cadr entry))
  5040. (return (apply 'create-image (cdr entry)))))))
  5041. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5042. remove-re habitp)
  5043. "Format TXT to be inserted into the agenda buffer.
  5044. In particular, it adds the prefix and corresponding text properties. EXTRA
  5045. must be a string and replaces the `%s' specifier in the prefix format.
  5046. CATEGORY (string, symbol or nil) may be used to overrule the default
  5047. category taken from local variable or file name. It will replace the `%c'
  5048. specifier in the format. DOTIME, when non-nil, indicates that a
  5049. time-of-day should be extracted from TXT for sorting of this entry, and for
  5050. the `%t' specifier in the format. When DOTIME is a string, this string is
  5051. searched for a time before TXT is. TAGS can be the tags of the headline.
  5052. Any match of REMOVE-RE will be removed from TXT."
  5053. (save-match-data
  5054. ;; Diary entries sometimes have extra whitespace at the beginning
  5055. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5056. ;; Fix the tags part in txt
  5057. (setq txt (org-agenda-fix-displayed-tags
  5058. txt tags
  5059. org-agenda-show-inherited-tags
  5060. org-agenda-hide-tags-regexp))
  5061. (let* ((category (or category
  5062. (if (stringp org-category)
  5063. org-category
  5064. (and org-category (symbol-name org-category)))
  5065. (if buffer-file-name
  5066. (file-name-sans-extension
  5067. (file-name-nondirectory buffer-file-name))
  5068. "")))
  5069. (category-icon (org-agenda-get-category-icon category))
  5070. (category-icon (if category-icon
  5071. (propertize " " 'display category-icon)
  5072. ""))
  5073. ;; time, tag, effort are needed for the eval of the prefix format
  5074. (tag (if tags (nth (1- (length tags)) tags) ""))
  5075. time effort neffort
  5076. (ts (if dotime (concat
  5077. (if (stringp dotime) dotime "")
  5078. (and org-agenda-search-headline-for-time txt))))
  5079. (time-of-day (and dotime (org-get-time-of-day ts)))
  5080. stamp plain s0 s1 s2 rtn srp l
  5081. duration thecategory)
  5082. (and (org-mode-p) buffer-file-name
  5083. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5084. (when (and dotime time-of-day)
  5085. ;; Extract starting and ending time and move them to prefix
  5086. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5087. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5088. (setq s0 (match-string 0 ts)
  5089. srp (and stamp (match-end 3))
  5090. s1 (match-string (if plain 1 2) ts)
  5091. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5092. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5093. ;; them, we might want to remove them there to avoid duplication.
  5094. ;; The user can turn this off with a variable.
  5095. (if (and org-prefix-has-time
  5096. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5097. (string-match (concat (regexp-quote s0) " *") txt)
  5098. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5099. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5100. (= (match-beginning 0) 0)
  5101. t))
  5102. (setq txt (replace-match "" nil nil txt))))
  5103. ;; Normalize the time(s) to 24 hour
  5104. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5105. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5106. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5107. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5108. (setq s2
  5109. (org-minutes-to-hh:mm-string
  5110. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5111. ;; Compute the duration
  5112. (when s2
  5113. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5114. (org-hh:mm-string-to-minutes s1)))))
  5115. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5116. txt)
  5117. ;; Tags are in the string
  5118. (if (or (eq org-agenda-remove-tags t)
  5119. (and org-agenda-remove-tags
  5120. org-prefix-has-tag))
  5121. (setq txt (replace-match "" t t txt))
  5122. (setq txt (replace-match
  5123. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5124. (match-string 2 txt))
  5125. t t txt))))
  5126. (when (org-mode-p)
  5127. (setq effort
  5128. (condition-case nil
  5129. (org-get-effort
  5130. (or (get-text-property 0 'org-hd-marker txt)
  5131. (get-text-property 0 'org-marker txt)))
  5132. (error nil)))
  5133. (when effort
  5134. (setq neffort (org-duration-string-to-minutes effort)
  5135. effort (setq effort (concat "[" effort "]")))))
  5136. ;; prevent erroring out with %e format when there is no effort
  5137. (or effort (setq effort ""))
  5138. (when remove-re
  5139. (while (string-match remove-re txt)
  5140. (setq txt (replace-match "" t t txt))))
  5141. ;; Set org-heading property on `txt' to mark the start of the
  5142. ;; heading.
  5143. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5144. ;; Prepare the variables needed in the eval of the compiled format
  5145. (setq time (cond (s2 (concat
  5146. (org-agenda-time-of-day-to-ampm-maybe s1)
  5147. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5148. (if org-agenda-timegrid-use-ampm " ")))
  5149. (s1 (concat
  5150. (org-agenda-time-of-day-to-ampm-maybe s1)
  5151. (if org-agenda-timegrid-use-ampm
  5152. "........ "
  5153. "......")))
  5154. (t ""))
  5155. extra (or (and (not habitp) extra) "")
  5156. category (if (symbolp category) (symbol-name category) category)
  5157. thecategory (copy-sequence category))
  5158. (if (string-match org-bracket-link-regexp category)
  5159. (progn
  5160. (setq l (if (match-end 3)
  5161. (- (match-end 3) (match-beginning 3))
  5162. (- (match-end 1) (match-beginning 1))))
  5163. (when (< l (or org-prefix-category-length 0))
  5164. (setq category (copy-sequence category))
  5165. (org-add-props category nil
  5166. 'extra-space (make-string
  5167. (- org-prefix-category-length l 1) ?\ ))))
  5168. (if (and org-prefix-category-max-length
  5169. (>= (length category) org-prefix-category-max-length))
  5170. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5171. ;; Evaluate the compiled format
  5172. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5173. ;; And finally add the text properties
  5174. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5175. (org-add-props rtn nil
  5176. 'org-category (if thecategory (downcase thecategory) category)
  5177. 'tags (mapcar 'org-downcase-keep-props tags)
  5178. 'org-highest-priority org-highest-priority
  5179. 'org-lowest-priority org-lowest-priority
  5180. 'time-of-day time-of-day
  5181. 'duration duration
  5182. 'effort effort
  5183. 'effort-minutes neffort
  5184. 'txt txt
  5185. 'time time
  5186. 'extra extra
  5187. 'format org-prefix-format-compiled
  5188. 'dotime dotime))))
  5189. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5190. "Remove tags string from TXT, and add a modified list of tags.
  5191. The modified list may contain inherited tags, and tags matched by
  5192. `org-agenda-hide-tags-regexp' will be removed."
  5193. (when (or add-inherited hide-re)
  5194. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5195. (setq txt (substring txt 0 (match-beginning 0))))
  5196. (setq tags
  5197. (delq nil
  5198. (mapcar (lambda (tg)
  5199. (if (or (and hide-re (string-match hide-re tg))
  5200. (and (not add-inherited)
  5201. (get-text-property 0 'inherited tg)))
  5202. nil
  5203. tg))
  5204. tags)))
  5205. (when tags
  5206. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5207. i)
  5208. (setq txt (concat txt " :"
  5209. (mapconcat
  5210. (lambda (x)
  5211. (setq i (get-text-property 0 'inherited x))
  5212. (if (and have-i (not i))
  5213. (progn
  5214. (setq have-i nil)
  5215. (concat ":" x))
  5216. x))
  5217. tags ":")
  5218. (if have-i "::" ":"))))))
  5219. txt)
  5220. (defun org-downcase-keep-props (s)
  5221. (let ((props (text-properties-at 0 s)))
  5222. (setq s (downcase s))
  5223. (add-text-properties 0 (length s) props s)
  5224. s))
  5225. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5226. (defvar org-agenda-sorting-strategy-selected nil)
  5227. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5228. (catch 'exit
  5229. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5230. ((and todayp (member 'today (car org-agenda-time-grid))))
  5231. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5232. ((member 'weekly (car org-agenda-time-grid)))
  5233. (t (throw 'exit list)))
  5234. (let* ((have (delq nil (mapcar
  5235. (lambda (x) (get-text-property 1 'time-of-day x))
  5236. list)))
  5237. (string (nth 1 org-agenda-time-grid))
  5238. (gridtimes (nth 2 org-agenda-time-grid))
  5239. (req (car org-agenda-time-grid))
  5240. (remove (member 'remove-match req))
  5241. new time)
  5242. (if (and (member 'require-timed req) (not have))
  5243. ;; don't show empty grid
  5244. (throw 'exit list))
  5245. (while (setq time (pop gridtimes))
  5246. (unless (and remove (member time have))
  5247. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5248. (push (org-format-agenda-item
  5249. nil string "" nil
  5250. (concat (substring time 0 -2) ":" (substring time -2)))
  5251. new)
  5252. (put-text-property
  5253. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5254. (when (and todayp org-agenda-show-current-time-in-grid)
  5255. (push (org-format-agenda-item
  5256. nil
  5257. org-agenda-current-time-string
  5258. "" nil
  5259. (format-time-string "%H:%M "))
  5260. new)
  5261. (put-text-property
  5262. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5263. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5264. (append new list)
  5265. (append list new)))))
  5266. (defun org-compile-prefix-format (key)
  5267. "Compile the prefix format into a Lisp form that can be evaluated.
  5268. The resulting form is returned and stored in the variable
  5269. `org-prefix-format-compiled'."
  5270. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5271. org-prefix-category-length nil org-prefix-has-effort nil)
  5272. (let ((s (cond
  5273. ((stringp org-agenda-prefix-format)
  5274. org-agenda-prefix-format)
  5275. ((assq key org-agenda-prefix-format)
  5276. (cdr (assq key org-agenda-prefix-format)))
  5277. (t " %-12:c%?-12t% s")))
  5278. (start 0)
  5279. varform vars var e c f opt)
  5280. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5281. s start)
  5282. (setq var (or (cdr (assoc (match-string 4 s)
  5283. '(("c" . category) ("t" . time) ("s" . extra)
  5284. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5285. 'eval)
  5286. c (or (match-string 3 s) "")
  5287. opt (match-beginning 1)
  5288. start (1+ (match-beginning 0)))
  5289. (if (equal var 'time) (setq org-prefix-has-time t))
  5290. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5291. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5292. (setq f (concat "%" (match-string 2 s) "s"))
  5293. (when (equal var 'category)
  5294. (setq org-prefix-category-length
  5295. (floor (abs (string-to-number (match-string 2 s)))))
  5296. (setq org-prefix-category-max-length
  5297. (let ((x (match-string 2 s)))
  5298. (save-match-data
  5299. (if (string-match "\\.[0-9]+" x)
  5300. (string-to-number (substring (match-string 0 x) 1)))))))
  5301. (if (eq var 'eval)
  5302. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5303. (if opt
  5304. (setq varform
  5305. `(if (equal "" ,var)
  5306. ""
  5307. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5308. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5309. (setq s (replace-match "%s" t nil s))
  5310. (push varform vars))
  5311. (setq vars (nreverse vars))
  5312. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5313. (defun org-set-sorting-strategy (key)
  5314. (if (symbolp (car org-agenda-sorting-strategy))
  5315. ;; the old format
  5316. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5317. (setq org-agenda-sorting-strategy-selected
  5318. (or (cdr (assq key org-agenda-sorting-strategy))
  5319. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5320. '(time-up category-keep priority-down)))))
  5321. (defun org-get-time-of-day (s &optional string mod24)
  5322. "Check string S for a time of day.
  5323. If found, return it as a military time number between 0 and 2400.
  5324. If not found, return nil.
  5325. The optional STRING argument forces conversion into a 5 character wide string
  5326. HH:MM."
  5327. (save-match-data
  5328. (when
  5329. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5330. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5331. (let* ((h (string-to-number (match-string 1 s)))
  5332. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5333. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5334. (am-p (equal ampm "am"))
  5335. (h1 (cond ((not ampm) h)
  5336. ((= h 12) (if am-p 0 12))
  5337. (t (+ h (if am-p 0 12)))))
  5338. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5339. (mod h1 24) h1))
  5340. (t0 (+ (* 100 h2) m))
  5341. (t1 (concat (if (>= h1 24) "+" " ")
  5342. (if (and org-agenda-time-leading-zero
  5343. (< t0 1000)) "0" "")
  5344. (if (< t0 100) "0" "")
  5345. (if (< t0 10) "0" "")
  5346. (int-to-string t0))))
  5347. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5348. (defvar org-agenda-before-sorting-filter-function nil
  5349. "Function to be applied to agenda items prior to sorting.
  5350. Prior to sorting also means just before they are inserted into the agenda.
  5351. To aid sorting, you may revisit the original entries and add more text
  5352. properties which will later be used by the sorting functions.
  5353. The function should take a string argument, an agenda line.
  5354. It has access to the text properties in that line, which contain among
  5355. other things, the property `org-hd-marker' that points to the entry
  5356. where the line comes from. Note that not all lines going into the agenda
  5357. have this property, only most.
  5358. The function should return the modified string. It is probably best
  5359. to ONLY change text properties.
  5360. You can also use this function as a filter, by returning nil for lines
  5361. you don't want to have in the agenda at all. For this application, you
  5362. could bind the variable in the options section of a custom command.")
  5363. (defun org-finalize-agenda-entries (list &optional nosort)
  5364. "Sort and concatenate the agenda items."
  5365. (setq list (mapcar 'org-agenda-highlight-todo list))
  5366. (if nosort
  5367. list
  5368. (when org-agenda-before-sorting-filter-function
  5369. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5370. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5371. (defun org-agenda-highlight-todo (x)
  5372. (let ((org-done-keywords org-done-keywords-for-agenda)
  5373. (case-fold-search nil)
  5374. re)
  5375. (if (eq x 'line)
  5376. (save-excursion
  5377. (beginning-of-line 1)
  5378. (setq re (org-get-at-bol 'org-todo-regexp))
  5379. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5380. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5381. (add-text-properties (match-beginning 0) (match-end 1)
  5382. (list 'face (org-get-todo-face 1)))
  5383. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5384. (delete-region (match-beginning 1) (1- (match-end 0)))
  5385. (goto-char (match-beginning 1))
  5386. (insert (format org-agenda-todo-keyword-format s)))))
  5387. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5388. (setq re (get-text-property 0 'org-todo-regexp x))
  5389. (when (and re
  5390. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5391. x (or pl 0)) pl))
  5392. (add-text-properties
  5393. (or (match-end 1) (match-end 0)) (match-end 0)
  5394. (list 'face (org-get-todo-face (match-string 2 x)))
  5395. x)
  5396. (when (match-end 1)
  5397. (setq x (concat (substring x 0 (match-end 1))
  5398. (format org-agenda-todo-keyword-format
  5399. (match-string 2 x))
  5400. (org-add-props " " (text-properties-at 0 x))
  5401. (substring x (match-end 3)))))))
  5402. x)))
  5403. (defsubst org-cmp-priority (a b)
  5404. "Compare the priorities of string A and B."
  5405. (let ((pa (or (get-text-property 1 'priority a) 0))
  5406. (pb (or (get-text-property 1 'priority b) 0)))
  5407. (cond ((> pa pb) +1)
  5408. ((< pa pb) -1)
  5409. (t nil))))
  5410. (defsubst org-cmp-effort (a b)
  5411. "Compare the priorities of string A and B."
  5412. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5413. (ea (or (get-text-property 1 'effort-minutes a) def))
  5414. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5415. (cond ((> ea eb) +1)
  5416. ((< ea eb) -1)
  5417. (t nil))))
  5418. (defsubst org-cmp-category (a b)
  5419. "Compare the string values of categories of strings A and B."
  5420. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5421. (cb (or (get-text-property 1 'org-category b) "")))
  5422. (cond ((string-lessp ca cb) -1)
  5423. ((string-lessp cb ca) +1)
  5424. (t nil))))
  5425. (defsubst org-cmp-todo-state (a b)
  5426. "Compare the todo states of strings A and B."
  5427. (let* ((ma (or (get-text-property 1 'org-marker a)
  5428. (get-text-property 1 'org-hd-marker a)))
  5429. (mb (or (get-text-property 1 'org-marker b)
  5430. (get-text-property 1 'org-hd-marker b)))
  5431. (fa (and ma (marker-buffer ma)))
  5432. (fb (and mb (marker-buffer mb)))
  5433. (todo-kwds
  5434. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5435. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5436. (ta (or (get-text-property 1 'todo-state a) ""))
  5437. (tb (or (get-text-property 1 'todo-state b) ""))
  5438. (la (- (length (member ta todo-kwds))))
  5439. (lb (- (length (member tb todo-kwds))))
  5440. (donepa (member ta org-done-keywords-for-agenda))
  5441. (donepb (member tb org-done-keywords-for-agenda)))
  5442. (cond ((and donepa (not donepb)) -1)
  5443. ((and (not donepa) donepb) +1)
  5444. ((< la lb) -1)
  5445. ((< lb la) +1)
  5446. (t nil))))
  5447. (defsubst org-cmp-alpha (a b)
  5448. "Compare the headlines, alphabetically."
  5449. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5450. (plb (text-property-any 0 (length b) 'org-heading t b))
  5451. (ta (and pla (substring a pla)))
  5452. (tb (and plb (substring b plb))))
  5453. (when pla
  5454. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5455. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5456. (setq ta (substring ta (match-end 0))))
  5457. (setq ta (downcase ta)))
  5458. (when plb
  5459. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5460. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5461. (setq tb (substring tb (match-end 0))))
  5462. (setq tb (downcase tb)))
  5463. (cond ((not ta) +1)
  5464. ((not tb) -1)
  5465. ((string-lessp ta tb) -1)
  5466. ((string-lessp tb ta) +1)
  5467. (t nil))))
  5468. (defsubst org-cmp-tag (a b)
  5469. "Compare the string values of the first tags of A and B."
  5470. (let ((ta (car (last (get-text-property 1 'tags a))))
  5471. (tb (car (last (get-text-property 1 'tags b)))))
  5472. (cond ((not ta) +1)
  5473. ((not tb) -1)
  5474. ((string-lessp ta tb) -1)
  5475. ((string-lessp tb ta) +1)
  5476. (t nil))))
  5477. (defsubst org-cmp-time (a b)
  5478. "Compare the time-of-day values of strings A and B."
  5479. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5480. (ta (or (get-text-property 1 'time-of-day a) def))
  5481. (tb (or (get-text-property 1 'time-of-day b) def)))
  5482. (cond ((< ta tb) -1)
  5483. ((< tb ta) +1)
  5484. (t nil))))
  5485. (defsubst org-cmp-habit-p (a b)
  5486. "Compare the todo states of strings A and B."
  5487. (let ((ha (get-text-property 1 'org-habit-p a))
  5488. (hb (get-text-property 1 'org-habit-p b)))
  5489. (cond ((and ha (not hb)) -1)
  5490. ((and (not ha) hb) +1)
  5491. (t nil))))
  5492. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5493. (defun org-entries-lessp (a b)
  5494. "Predicate for sorting agenda entries."
  5495. ;; The following variables will be used when the form is evaluated.
  5496. ;; So even though the compiler complains, keep them.
  5497. (let* ((ss org-agenda-sorting-strategy-selected)
  5498. (time-up (and (org-em 'time-up 'time-down ss)
  5499. (org-cmp-time a b)))
  5500. (time-down (if time-up (- time-up) nil))
  5501. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5502. (org-cmp-priority a b)))
  5503. (priority-down (if priority-up (- priority-up) nil))
  5504. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5505. (org-cmp-effort a b)))
  5506. (effort-down (if effort-up (- effort-up) nil))
  5507. (category-up (and (or (org-em 'category-up 'category-down ss)
  5508. (memq 'category-keep ss))
  5509. (org-cmp-category a b)))
  5510. (category-down (if category-up (- category-up) nil))
  5511. (category-keep (if category-up +1 nil))
  5512. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5513. (org-cmp-tag a b)))
  5514. (tag-down (if tag-up (- tag-up) nil))
  5515. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5516. (org-cmp-todo-state a b)))
  5517. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5518. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5519. (org-cmp-habit-p a b)))
  5520. (habit-down (if habit-up (- habit-up) nil))
  5521. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5522. (org-cmp-alpha a b)))
  5523. (alpha-down (if alpha-up (- alpha-up) nil))
  5524. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5525. user-defined-up user-defined-down)
  5526. (if (and need-user-cmp org-agenda-cmp-user-defined
  5527. (functionp org-agenda-cmp-user-defined))
  5528. (setq user-defined-up
  5529. (funcall org-agenda-cmp-user-defined a b)
  5530. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5531. (cdr (assoc
  5532. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5533. '((-1 . t) (1 . nil) (nil . nil))))))
  5534. ;;; Agenda restriction lock
  5535. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5536. "Overlay to mark the headline to which agenda commands are restricted.")
  5537. (overlay-put org-agenda-restriction-lock-overlay
  5538. 'face 'org-agenda-restriction-lock)
  5539. (overlay-put org-agenda-restriction-lock-overlay
  5540. 'help-echo "Agendas are currently limited to this subtree.")
  5541. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5542. (defun org-agenda-set-restriction-lock (&optional type)
  5543. "Set restriction lock for agenda, to current subtree or file.
  5544. Restriction will be the file if TYPE is `file', or if type is the
  5545. universal prefix '(4), or if the cursor is before the first headline
  5546. in the file. Otherwise, restriction will be to the current subtree."
  5547. (interactive "P")
  5548. (and (equal type '(4)) (setq type 'file))
  5549. (setq type (cond
  5550. (type type)
  5551. ((org-at-heading-p) 'subtree)
  5552. ((condition-case nil (org-back-to-heading t) (error nil))
  5553. 'subtree)
  5554. (t 'file)))
  5555. (if (eq type 'subtree)
  5556. (progn
  5557. (setq org-agenda-restrict t)
  5558. (setq org-agenda-overriding-restriction 'subtree)
  5559. (put 'org-agenda-files 'org-restrict
  5560. (list (buffer-file-name (buffer-base-buffer))))
  5561. (org-back-to-heading t)
  5562. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5563. (move-marker org-agenda-restrict-begin (point))
  5564. (move-marker org-agenda-restrict-end
  5565. (save-excursion (org-end-of-subtree t)))
  5566. (message "Locking agenda restriction to subtree"))
  5567. (put 'org-agenda-files 'org-restrict
  5568. (list (buffer-file-name (buffer-base-buffer))))
  5569. (setq org-agenda-restrict nil)
  5570. (setq org-agenda-overriding-restriction 'file)
  5571. (move-marker org-agenda-restrict-begin nil)
  5572. (move-marker org-agenda-restrict-end nil)
  5573. (message "Locking agenda restriction to file"))
  5574. (setq current-prefix-arg nil)
  5575. (org-agenda-maybe-redo))
  5576. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5577. "Remove the agenda restriction lock."
  5578. (interactive "P")
  5579. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5580. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5581. (setq org-agenda-overriding-restriction nil)
  5582. (setq org-agenda-restrict nil)
  5583. (put 'org-agenda-files 'org-restrict nil)
  5584. (move-marker org-agenda-restrict-begin nil)
  5585. (move-marker org-agenda-restrict-end nil)
  5586. (setq current-prefix-arg nil)
  5587. (message "Agenda restriction lock removed")
  5588. (or noupdate (org-agenda-maybe-redo)))
  5589. (defun org-agenda-maybe-redo ()
  5590. "If there is any window showing the agenda view, update it."
  5591. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5592. (w0 (selected-window)))
  5593. (when w
  5594. (select-window w)
  5595. (org-agenda-redo)
  5596. (select-window w0)
  5597. (if org-agenda-overriding-restriction
  5598. (message "Agenda view shifted to new %s restriction"
  5599. org-agenda-overriding-restriction)
  5600. (message "Agenda restriction lock removed")))))
  5601. ;;; Agenda commands
  5602. (defun org-agenda-check-type (error &rest types)
  5603. "Check if agenda buffer is of allowed type.
  5604. If ERROR is non-nil, throw an error, otherwise just return nil."
  5605. (if (memq org-agenda-type types)
  5606. t
  5607. (if error
  5608. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5609. nil)))
  5610. (defun org-agenda-quit ()
  5611. "Exit agenda by removing the window or the buffer."
  5612. (interactive)
  5613. (if org-agenda-columns-active
  5614. (org-columns-quit)
  5615. (let ((buf (current-buffer)))
  5616. (if (eq org-agenda-window-setup 'other-frame)
  5617. (progn
  5618. (kill-buffer buf)
  5619. (org-agenda-reset-markers)
  5620. (org-columns-remove-overlays)
  5621. (setq org-agenda-archives-mode nil)
  5622. (delete-frame))
  5623. (and (not (eq org-agenda-window-setup 'current-window))
  5624. (not (one-window-p))
  5625. (delete-window))
  5626. (kill-buffer buf)
  5627. (org-agenda-reset-markers)
  5628. (org-columns-remove-overlays)
  5629. (setq org-agenda-archives-mode nil)))
  5630. ;; Maybe restore the pre-agenda window configuration.
  5631. (and org-agenda-restore-windows-after-quit
  5632. (not (eq org-agenda-window-setup 'other-frame))
  5633. org-pre-agenda-window-conf
  5634. (set-window-configuration org-pre-agenda-window-conf))))
  5635. (defun org-agenda-exit ()
  5636. "Exit agenda by removing the window or the buffer.
  5637. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5638. Org-mode buffers visited directly by the user will not be touched."
  5639. (interactive)
  5640. (org-release-buffers org-agenda-new-buffers)
  5641. (setq org-agenda-new-buffers nil)
  5642. (org-agenda-quit))
  5643. (defun org-agenda-execute (arg)
  5644. "Execute another agenda command, keeping same window.
  5645. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5646. in the agenda."
  5647. (interactive "P")
  5648. (let ((org-agenda-window-setup 'current-window))
  5649. (org-agenda arg)))
  5650. (defun org-agenda-redo ()
  5651. "Rebuild Agenda.
  5652. When this is the global TODO list, a prefix argument will be interpreted."
  5653. (interactive)
  5654. (let* ((org-agenda-keep-modes t)
  5655. (filter org-agenda-filter)
  5656. (preset (get 'org-agenda-filter :preset-filter))
  5657. (org-agenda-filter-while-redo (or filter preset))
  5658. (cols org-agenda-columns-active)
  5659. (line (org-current-line))
  5660. (window-line (- line (org-current-line (window-start))))
  5661. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5662. (put 'org-agenda-filter :preset-filter nil)
  5663. (and cols (org-columns-quit))
  5664. (message "Rebuilding agenda buffer...")
  5665. (org-let lprops '(eval org-agenda-redo-command))
  5666. (setq org-agenda-undo-list nil
  5667. org-agenda-pending-undo-list nil)
  5668. (message "Rebuilding agenda buffer...done")
  5669. (put 'org-agenda-filter :preset-filter preset)
  5670. (and (or filter preset) (org-agenda-filter-apply filter))
  5671. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5672. (org-goto-line line)
  5673. (recenter window-line)))
  5674. (defvar org-global-tags-completion-table nil)
  5675. (defvar org-agenda-filter-form nil)
  5676. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5677. "Keep only those lines in the agenda buffer that have a specific tag.
  5678. The tag is selected with its fast selection letter, as configured.
  5679. With prefix argument STRIP, remove all lines that do have the tag.
  5680. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5681. used to narrow the search - the interactive user can also press `-' or `+'
  5682. to switch to narrowing."
  5683. (interactive "P")
  5684. (let* ((alist org-tag-alist-for-agenda)
  5685. (tag-chars (mapconcat
  5686. (lambda (x) (if (and (not (symbolp (car x)))
  5687. (cdr x))
  5688. (char-to-string (cdr x))
  5689. ""))
  5690. alist ""))
  5691. (efforts (org-split-string
  5692. (or (cdr (assoc (concat org-effort-property "_ALL")
  5693. org-global-properties))
  5694. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5695. "")))
  5696. (effort-op org-agenda-filter-effort-default-operator)
  5697. (effort-prompt "")
  5698. (inhibit-read-only t)
  5699. (current org-agenda-filter)
  5700. maybe-refresh a n tag)
  5701. (unless char
  5702. (message
  5703. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5704. (if narrow "Narrow" "Filter") tag-chars
  5705. (if org-agenda-auto-exclude-function "[RET], " ""))
  5706. (setq char (read-char)))
  5707. (when (member char '(?+ ?-))
  5708. ;; Narrowing down
  5709. (cond ((equal char ?-) (setq strip t narrow t))
  5710. ((equal char ?+) (setq strip nil narrow t)))
  5711. (message
  5712. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5713. (setq char (read-char)))
  5714. (when (member char '(?< ?> ?= ??))
  5715. ;; An effort operator
  5716. (setq effort-op (char-to-string char))
  5717. (setq alist nil) ; to make sure it will be interpreted as effort.
  5718. (unless (equal char ??)
  5719. (loop for i from 0 to 9 do
  5720. (setq effort-prompt
  5721. (concat
  5722. effort-prompt " ["
  5723. (if (= i 9) "0" (int-to-string (1+ i)))
  5724. "]" (nth i efforts))))
  5725. (message "Effort%s: %s " effort-op effort-prompt)
  5726. (setq char (read-char))
  5727. (when (or (< char ?0) (> char ?9))
  5728. (error "Need 1-9,0 to select effort" ))))
  5729. (when (equal char ?\t)
  5730. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5731. (org-set-local 'org-global-tags-completion-table
  5732. (org-global-tags-completion-table)))
  5733. (let ((completion-ignore-case t))
  5734. (setq tag (org-icompleting-read
  5735. "Tag: " org-global-tags-completion-table))))
  5736. (cond
  5737. ((equal char ?\r)
  5738. (org-agenda-filter-by-tag-show-all)
  5739. (when org-agenda-auto-exclude-function
  5740. (setq org-agenda-filter '())
  5741. (dolist (tag (org-agenda-get-represented-tags))
  5742. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5743. (if modifier
  5744. (push modifier org-agenda-filter))))
  5745. (if (not (null org-agenda-filter))
  5746. (org-agenda-filter-apply org-agenda-filter)))
  5747. (setq maybe-refresh t))
  5748. ((equal char ?/)
  5749. (org-agenda-filter-by-tag-show-all)
  5750. (when (get 'org-agenda-filter :preset-filter)
  5751. (org-agenda-filter-apply org-agenda-filter))
  5752. (setq maybe-refresh t))
  5753. ((or (equal char ?\ )
  5754. (setq a (rassoc char alist))
  5755. (and (>= char ?0) (<= char ?9)
  5756. (setq n (if (= char ?0) 9 (- char ?0 1))
  5757. tag (concat effort-op (nth n efforts))
  5758. a (cons tag nil)))
  5759. (and (= char ??)
  5760. (setq tag "?eff")
  5761. a (cons tag nil))
  5762. (and tag (setq a (cons tag nil))))
  5763. (org-agenda-filter-by-tag-show-all)
  5764. (setq tag (car a))
  5765. (setq org-agenda-filter
  5766. (cons (concat (if strip "-" "+") tag)
  5767. (if narrow current nil)))
  5768. (org-agenda-filter-apply org-agenda-filter)
  5769. (setq maybe-refresh t))
  5770. (t (error "Invalid tag selection character %c" char)))
  5771. (when (and maybe-refresh
  5772. (eq org-agenda-clockreport-mode 'with-filter))
  5773. (org-agenda-redo))))
  5774. (defun org-agenda-get-represented-tags ()
  5775. "Get a list of all tags currently represented in the agenda."
  5776. (let (p tags)
  5777. (save-excursion
  5778. (goto-char (point-min))
  5779. (while (setq p (next-single-property-change (point) 'tags))
  5780. (goto-char p)
  5781. (mapc (lambda (x) (add-to-list 'tags x))
  5782. (get-text-property (point) 'tags))))
  5783. tags))
  5784. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5785. "Refine the current filter. See `org-agenda-filter-by-tag."
  5786. (interactive "P")
  5787. (org-agenda-filter-by-tag strip char 'refine))
  5788. (defun org-agenda-filter-make-matcher ()
  5789. "Create the form that tests a line for the agenda filter."
  5790. (let (f f1)
  5791. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5792. org-agenda-filter))
  5793. (if (member x '("-" "+"))
  5794. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5795. (if (string-match "[<=>?]" x)
  5796. (setq f1 (org-agenda-filter-effort-form x))
  5797. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5798. (if (equal (string-to-char x) ?-)
  5799. (setq f1 (list 'not f1))))
  5800. (push f1 f))
  5801. (cons 'and (nreverse f))))
  5802. (defun org-agenda-filter-effort-form (e)
  5803. "Return the form to compare the effort of the current line with what E says.
  5804. E looks like \"+<2:25\"."
  5805. (let (op)
  5806. (setq e (substring e 1))
  5807. (setq op (string-to-char e) e (substring e 1))
  5808. (setq op (cond ((equal op ?<) '<=)
  5809. ((equal op ?>) '>=)
  5810. ((equal op ??) op)
  5811. (t '=)))
  5812. (list 'org-agenda-compare-effort (list 'quote op)
  5813. (org-duration-string-to-minutes e))))
  5814. (defun org-agenda-compare-effort (op value)
  5815. "Compare the effort of the current line with VALUE, using OP.
  5816. If the line does not have an effort defined, return nil."
  5817. (let ((eff (org-get-at-bol 'effort-minutes)))
  5818. (if (equal op ??)
  5819. (not eff)
  5820. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5821. value))))
  5822. (defun org-agenda-filter-apply (filter)
  5823. "Set FILTER as the new agenda filter and apply it."
  5824. (let (tags)
  5825. (setq org-agenda-filter filter
  5826. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5827. (org-agenda-set-mode-name)
  5828. (save-excursion
  5829. (goto-char (point-min))
  5830. (while (not (eobp))
  5831. (if (org-get-at-bol 'org-marker)
  5832. (progn
  5833. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5834. (if (not (eval org-agenda-filter-form))
  5835. (org-agenda-filter-by-tag-hide-line))
  5836. (beginning-of-line 2))
  5837. (beginning-of-line 2))))
  5838. (if (get-char-property (point) 'invisible)
  5839. (org-agenda-previous-line))))
  5840. (defun org-agenda-filter-by-tag-hide-line ()
  5841. (let (ov)
  5842. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5843. (point-at-eol)))
  5844. (overlay-put ov 'invisible t)
  5845. (overlay-put ov 'type 'tags-filter)
  5846. (push ov org-agenda-filter-overlays)))
  5847. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5848. (setq pos (or pos (point)))
  5849. (save-excursion
  5850. (dolist (ov (overlays-at pos))
  5851. (when (and (overlay-get ov 'invisible)
  5852. (eq (overlay-get ov 'type) 'tags-filter))
  5853. (goto-char pos)
  5854. (if (< (overlay-start ov) (point-at-eol))
  5855. (move-overlay ov (point-at-eol)
  5856. (overlay-end ov)))))))
  5857. (defun org-agenda-filter-by-tag-show-all ()
  5858. (mapc 'delete-overlay org-agenda-filter-overlays)
  5859. (setq org-agenda-filter-overlays nil)
  5860. (setq org-agenda-filter nil)
  5861. (setq org-agenda-filter-form nil)
  5862. (org-agenda-set-mode-name))
  5863. (defun org-agenda-manipulate-query-add ()
  5864. "Manipulate the query by adding a search term with positive selection.
  5865. Positive selection means the term must be matched for selection of an entry."
  5866. (interactive)
  5867. (org-agenda-manipulate-query ?\[))
  5868. (defun org-agenda-manipulate-query-subtract ()
  5869. "Manipulate the query by adding a search term with negative selection.
  5870. Negative selection means term must not be matched for selection of an entry."
  5871. (interactive)
  5872. (org-agenda-manipulate-query ?\]))
  5873. (defun org-agenda-manipulate-query-add-re ()
  5874. "Manipulate the query by adding a search regexp with positive selection.
  5875. Positive selection means the regexp must match for selection of an entry."
  5876. (interactive)
  5877. (org-agenda-manipulate-query ?\{))
  5878. (defun org-agenda-manipulate-query-subtract-re ()
  5879. "Manipulate the query by adding a search regexp with negative selection.
  5880. Negative selection means regexp must not match for selection of an entry."
  5881. (interactive)
  5882. (org-agenda-manipulate-query ?\}))
  5883. (defun org-agenda-manipulate-query (char)
  5884. (cond
  5885. ((memq org-agenda-type '(timeline agenda))
  5886. (let ((org-agenda-include-inactive-timestamps t))
  5887. (org-agenda-redo))
  5888. (message "Display now includes inactive timestamps as well"))
  5889. ((eq org-agenda-type 'search)
  5890. (org-add-to-string
  5891. 'org-agenda-query-string
  5892. (if org-agenda-last-search-view-search-was-boolean
  5893. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5894. (?\{ . " +{}") (?\} . " -{}"))))
  5895. " "))
  5896. (setq org-agenda-redo-command
  5897. (list 'org-search-view
  5898. org-todo-only
  5899. org-agenda-query-string
  5900. (+ (length org-agenda-query-string)
  5901. (if (member char '(?\{ ?\})) 0 1))))
  5902. (set-register org-agenda-query-register org-agenda-query-string)
  5903. (org-agenda-redo))
  5904. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5905. org-agenda-type))))
  5906. (defun org-add-to-string (var string)
  5907. (set var (concat (symbol-value var) string)))
  5908. (defun org-agenda-goto-date (date)
  5909. "Jump to DATE in agenda."
  5910. (interactive (list (let ((org-read-date-prefer-future
  5911. (eval org-agenda-jump-prefer-future)))
  5912. (org-read-date))))
  5913. (org-agenda-list nil date))
  5914. (defun org-agenda-goto-today ()
  5915. "Go to today."
  5916. (interactive)
  5917. (org-agenda-check-type t 'timeline 'agenda)
  5918. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5919. (cond
  5920. (tdpos (goto-char tdpos))
  5921. ((eq org-agenda-type 'agenda)
  5922. (let* ((sd (org-agenda-compute-starting-span
  5923. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5924. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5925. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5926. (org-agenda-redo)
  5927. (org-agenda-find-same-or-today-or-agenda)))
  5928. (t (error "Cannot find today")))))
  5929. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5930. (goto-char
  5931. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5932. (text-property-any (point-min) (point-max) 'org-today t)
  5933. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5934. (point-min))))
  5935. (defun org-agenda-later (arg)
  5936. "Go forward in time by thee current span.
  5937. With prefix ARG, go forward that many times the current span."
  5938. (interactive "p")
  5939. (org-agenda-check-type t 'agenda)
  5940. (let* ((span org-agenda-current-span)
  5941. (sd org-starting-day)
  5942. (greg (calendar-gregorian-from-absolute sd))
  5943. (cnt (org-get-at-bol 'org-day-cnt))
  5944. greg2)
  5945. (cond
  5946. ((eq span 'day)
  5947. (setq sd (+ arg sd)))
  5948. ((eq span 'week)
  5949. (setq sd (+ (* 7 arg) sd)))
  5950. ((eq span 'month)
  5951. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5952. sd (calendar-absolute-from-gregorian greg2))
  5953. (setcar greg2 (1+ (car greg2))))
  5954. ((eq span 'year)
  5955. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5956. sd (calendar-absolute-from-gregorian greg2))
  5957. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5958. (t
  5959. (setq sd (+ (* span arg) sd))))
  5960. (let ((org-agenda-overriding-arguments
  5961. (list (car org-agenda-last-arguments) sd span t)))
  5962. (org-agenda-redo)
  5963. (org-agenda-find-same-or-today-or-agenda cnt))))
  5964. (defun org-agenda-earlier (arg)
  5965. "Go backward in time by the current span.
  5966. With prefix ARG, go backward that many times the current span."
  5967. (interactive "p")
  5968. (org-agenda-later (- arg)))
  5969. (defun org-agenda-view-mode-dispatch ()
  5970. "Call one of the view mode commands."
  5971. (interactive)
  5972. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5973. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5974. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5975. [E]ntryText")
  5976. (let ((a (read-char-exclusive)))
  5977. (case a
  5978. (?\ (call-interactively 'org-agenda-reset-view))
  5979. (?d (call-interactively 'org-agenda-day-view))
  5980. (?w (call-interactively 'org-agenda-week-view))
  5981. (?m (call-interactively 'org-agenda-month-view))
  5982. (?y (call-interactively 'org-agenda-year-view))
  5983. (?l (call-interactively 'org-agenda-log-mode))
  5984. (?L (org-agenda-log-mode '(4)))
  5985. (?c (org-agenda-log-mode 'clockcheck))
  5986. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5987. (?a (call-interactively 'org-agenda-archives-mode))
  5988. (?A (org-agenda-archives-mode 'files))
  5989. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5990. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5991. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5992. (?D (call-interactively 'org-agenda-toggle-diary))
  5993. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5994. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5995. (org-agenda-check-type t 'timeline 'agenda)
  5996. (org-agenda-redo))
  5997. (message "Display now includes inactive timestamps as well"))
  5998. (?q (message "Abort"))
  5999. (otherwise (error "Invalid key" )))))
  6000. (defun org-agenda-reset-view ()
  6001. "Switch to default view for agenda."
  6002. (interactive)
  6003. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6004. (defun org-agenda-day-view (&optional day-of-year)
  6005. "Switch to daily view for agenda.
  6006. With argument DAY-OF-YEAR, switch to that day of the year."
  6007. (interactive "P")
  6008. (org-agenda-change-time-span 'day day-of-year))
  6009. (defun org-agenda-week-view (&optional iso-week)
  6010. "Switch to daily view for agenda.
  6011. With argument ISO-WEEK, switch to the corresponding ISO week.
  6012. If ISO-WEEK has more then 2 digits, only the last two encode the
  6013. week. Any digits before this encode a year. So 200712 means
  6014. week 12 of year 2007. Years in the range 1938-2037 can also be
  6015. written as 2-digit years."
  6016. (interactive "P")
  6017. (org-agenda-change-time-span 'week iso-week))
  6018. (defun org-agenda-month-view (&optional month)
  6019. "Switch to monthly view for agenda.
  6020. With argument MONTH, switch to that month."
  6021. (interactive "P")
  6022. (org-agenda-change-time-span 'month month))
  6023. (defun org-agenda-year-view (&optional year)
  6024. "Switch to yearly view for agenda.
  6025. With argument YEAR, switch to that year.
  6026. If MONTH has more then 2 digits, only the last two encode the
  6027. month. Any digits before this encode a year. So 200712 means
  6028. December year 2007. Years in the range 1938-2037 can also be
  6029. written as 2-digit years."
  6030. (interactive "P")
  6031. (when year
  6032. (setq year (org-small-year-to-year year)))
  6033. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6034. (org-agenda-change-time-span 'year year)
  6035. (error "Abort")))
  6036. (defun org-agenda-change-time-span (span &optional n)
  6037. "Change the agenda view to SPAN.
  6038. SPAN may be `day', `week', `month', `year'."
  6039. (org-agenda-check-type t 'agenda)
  6040. (if (and (not n) (equal org-agenda-current-span span))
  6041. (error "Viewing span is already \"%s\"" span))
  6042. (let* ((sd (or (org-get-at-bol 'day)
  6043. org-starting-day))
  6044. (sd (org-agenda-compute-starting-span sd span n))
  6045. (org-agenda-overriding-arguments
  6046. (or org-agenda-overriding-arguments
  6047. (list (car org-agenda-last-arguments) sd span t))))
  6048. (org-agenda-redo)
  6049. (org-agenda-find-same-or-today-or-agenda))
  6050. (org-agenda-set-mode-name)
  6051. (message "Switched to %s view" span))
  6052. (defun org-agenda-compute-starting-span (sd span &optional n)
  6053. "Compute starting date for agenda.
  6054. SPAN may be `day', `week', `month', `year'. The return value
  6055. is a cons cell with the starting date and the number of days,
  6056. so that the date SD will be in that range."
  6057. (let* ((greg (calendar-gregorian-from-absolute sd))
  6058. (dg (nth 1 greg))
  6059. (mg (car greg))
  6060. (yg (nth 2 greg)))
  6061. (cond
  6062. ((eq span 'day)
  6063. (when n
  6064. (setq sd (+ (calendar-absolute-from-gregorian
  6065. (list mg 1 yg))
  6066. n -1))))
  6067. ((eq span 'week)
  6068. (let* ((nt (calendar-day-of-week
  6069. (calendar-gregorian-from-absolute sd)))
  6070. (d (if org-agenda-start-on-weekday
  6071. (- nt org-agenda-start-on-weekday)
  6072. 0))
  6073. y1)
  6074. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6075. (when n
  6076. (require 'cal-iso)
  6077. (when (> n 99)
  6078. (setq y1 (org-small-year-to-year (/ n 100))
  6079. n (mod n 100)))
  6080. (setq sd
  6081. (calendar-absolute-from-iso
  6082. (list n 1
  6083. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6084. ((eq span 'month)
  6085. (let (y1)
  6086. (when (and n (> n 99))
  6087. (setq y1 (org-small-year-to-year (/ n 100))
  6088. n (mod n 100)))
  6089. (setq sd (calendar-absolute-from-gregorian
  6090. (list (or n mg) 1 (or y1 yg))))))
  6091. ((eq span 'year)
  6092. (setq sd (calendar-absolute-from-gregorian
  6093. (list 1 1 (or n yg))))))
  6094. sd))
  6095. (defun org-agenda-next-date-line (&optional arg)
  6096. "Jump to the next line indicating a date in agenda buffer."
  6097. (interactive "p")
  6098. (org-agenda-check-type t 'agenda 'timeline)
  6099. (beginning-of-line 1)
  6100. ;; This does not work if user makes date format that starts with a blank
  6101. (if (looking-at "^\\S-") (forward-char 1))
  6102. (if (not (re-search-forward "^\\S-" nil t arg))
  6103. (progn
  6104. (backward-char 1)
  6105. (error "No next date after this line in this buffer")))
  6106. (goto-char (match-beginning 0)))
  6107. (defun org-agenda-previous-date-line (&optional arg)
  6108. "Jump to the previous line indicating a date in agenda buffer."
  6109. (interactive "p")
  6110. (org-agenda-check-type t 'agenda 'timeline)
  6111. (beginning-of-line 1)
  6112. (if (not (re-search-backward "^\\S-" nil t arg))
  6113. (error "No previous date before this line in this buffer")))
  6114. ;; Initialize the highlight
  6115. (defvar org-hl (make-overlay 1 1))
  6116. (overlay-put org-hl 'face 'highlight)
  6117. (defun org-highlight (begin end &optional buffer)
  6118. "Highlight a region with overlay."
  6119. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6120. (defun org-unhighlight ()
  6121. "Detach overlay INDEX."
  6122. (org-detach-overlay org-hl))
  6123. ;; FIXME this is currently not used.
  6124. (defun org-highlight-until-next-command (beg end &optional buffer)
  6125. "Move the highlight overlay to BEG/END, remove it before the next command."
  6126. (org-highlight beg end buffer)
  6127. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6128. (defun org-unhighlight-once ()
  6129. "Remove the highlight from its position, and this function from the hook."
  6130. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6131. (org-unhighlight))
  6132. (defun org-agenda-follow-mode ()
  6133. "Toggle follow mode in an agenda buffer."
  6134. (interactive)
  6135. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6136. (org-agenda-set-mode-name)
  6137. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6138. (org-agenda-show))
  6139. (message "Follow mode is %s"
  6140. (if org-agenda-follow-mode "on" "off")))
  6141. (defun org-agenda-entry-text-mode (&optional arg)
  6142. "Toggle entry text mode in an agenda buffer."
  6143. (interactive "P")
  6144. (setq org-agenda-entry-text-mode (or (integerp arg)
  6145. (not org-agenda-entry-text-mode)))
  6146. (org-agenda-entry-text-hide)
  6147. (and org-agenda-entry-text-mode
  6148. (let ((org-agenda-entry-text-maxlines
  6149. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6150. (org-agenda-entry-text-show)))
  6151. (org-agenda-set-mode-name)
  6152. (message "Entry text mode is %s. Maximum number of lines is %d"
  6153. (if org-agenda-entry-text-mode "on" "off")
  6154. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6155. (defun org-agenda-clockreport-mode (&optional with-filter)
  6156. "Toggle clocktable mode in an agenda buffer.
  6157. With prefix arg WITH-FILTER, make the clocktable respect the current
  6158. agenda filter."
  6159. (interactive "P")
  6160. (org-agenda-check-type t 'agenda)
  6161. (if with-filter
  6162. (setq org-agenda-clockreport-mode 'with-filter)
  6163. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6164. (org-agenda-set-mode-name)
  6165. (org-agenda-redo)
  6166. (message "Clocktable mode is %s"
  6167. (if org-agenda-clockreport-mode "on" "off")))
  6168. (defun org-agenda-log-mode (&optional special)
  6169. "Toggle log mode in an agenda buffer.
  6170. With argument SPECIAL, show all possible log items, not only the ones
  6171. configured in `org-agenda-log-mode-items'.
  6172. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6173. (interactive "P")
  6174. (org-agenda-check-type t 'agenda 'timeline)
  6175. (setq org-agenda-show-log
  6176. (cond
  6177. ((equal special '(16)) 'only)
  6178. ((eq special 'clockcheck)
  6179. (if (eq org-agenda-show-log 'clockcheck)
  6180. nil 'clockcheck))
  6181. (special '(closed clock state))
  6182. (t (not org-agenda-show-log))))
  6183. (org-agenda-set-mode-name)
  6184. (org-agenda-redo)
  6185. (message "Log mode is %s"
  6186. (if org-agenda-show-log "on" "off")))
  6187. (defun org-agenda-archives-mode (&optional with-files)
  6188. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6189. When called with a prefix argument, include all archive files as well."
  6190. (interactive "P")
  6191. (setq org-agenda-archives-mode
  6192. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6193. (org-agenda-set-mode-name)
  6194. (org-agenda-redo)
  6195. (message
  6196. "%s"
  6197. (cond
  6198. ((eq org-agenda-archives-mode nil)
  6199. "No archives are included")
  6200. ((eq org-agenda-archives-mode 'trees)
  6201. (format "Trees with :%s: tag are included" org-archive-tag))
  6202. ((eq org-agenda-archives-mode t)
  6203. (format "Trees with :%s: tag and all active archive files are included"
  6204. org-archive-tag)))))
  6205. (defun org-agenda-toggle-diary ()
  6206. "Toggle diary inclusion in an agenda buffer."
  6207. (interactive)
  6208. (org-agenda-check-type t 'agenda)
  6209. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6210. (org-agenda-redo)
  6211. (org-agenda-set-mode-name)
  6212. (message "Diary inclusion turned %s"
  6213. (if org-agenda-include-diary "on" "off")))
  6214. (defun org-agenda-toggle-deadlines ()
  6215. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6216. (interactive)
  6217. (org-agenda-check-type t 'agenda)
  6218. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6219. (org-agenda-redo)
  6220. (org-agenda-set-mode-name)
  6221. (message "Deadlines inclusion turned %s"
  6222. (if org-agenda-include-deadlines "on" "off")))
  6223. (defun org-agenda-toggle-time-grid ()
  6224. "Toggle time grid in an agenda buffer."
  6225. (interactive)
  6226. (org-agenda-check-type t 'agenda)
  6227. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6228. (org-agenda-redo)
  6229. (org-agenda-set-mode-name)
  6230. (message "Time-grid turned %s"
  6231. (if org-agenda-use-time-grid "on" "off")))
  6232. (defun org-agenda-set-mode-name ()
  6233. "Set the mode name to indicate all the small mode settings."
  6234. (setq mode-name
  6235. (list "Org-Agenda"
  6236. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6237. " "
  6238. '(:eval (org-agenda-span-name org-agenda-current-span))
  6239. (if org-agenda-follow-mode " Follow" "")
  6240. (if org-agenda-entry-text-mode " ETxt" "")
  6241. (if org-agenda-include-diary " Diary" "")
  6242. (if org-agenda-include-deadlines " Ddl" "")
  6243. (if org-agenda-use-time-grid " Grid" "")
  6244. (if (and (boundp 'org-habit-show-habits)
  6245. org-habit-show-habits) " Habit" "")
  6246. (cond
  6247. ((consp org-agenda-show-log) " LogAll")
  6248. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6249. (org-agenda-show-log " Log")
  6250. (t ""))
  6251. (if (or org-agenda-filter (get 'org-agenda-filter
  6252. :preset-filter))
  6253. (concat " {" (mapconcat
  6254. 'identity
  6255. (append (get 'org-agenda-filter
  6256. :preset-filter)
  6257. org-agenda-filter) "") "}")
  6258. "")
  6259. (if org-agenda-archives-mode
  6260. (if (eq org-agenda-archives-mode t)
  6261. " Archives"
  6262. (format " :%s:" org-archive-tag))
  6263. "")
  6264. (if org-agenda-clockreport-mode
  6265. (if (eq org-agenda-clockreport-mode 'with-filter)
  6266. " Clock{}" " Clock")
  6267. "")))
  6268. (force-mode-line-update))
  6269. (defun org-agenda-post-command-hook ()
  6270. (setq org-agenda-type
  6271. (or (get-text-property (point) 'org-agenda-type)
  6272. (get-text-property (max (point-min) (1- (point)))
  6273. 'org-agenda-type))))
  6274. (defun org-agenda-next-line ()
  6275. "Move cursor to the next line, and show if follow mode is active."
  6276. (interactive)
  6277. (call-interactively 'next-line)
  6278. (org-agenda-do-context-action))
  6279. (defun org-agenda-previous-line ()
  6280. "Move cursor to the previous line, and show if follow-mode is active."
  6281. (interactive)
  6282. (call-interactively 'previous-line)
  6283. (org-agenda-do-context-action))
  6284. (defun org-agenda-do-context-action ()
  6285. "Show outline path and, maybe, follow mode window."
  6286. (let ((m (org-get-at-bol 'org-marker)))
  6287. (if (and org-agenda-follow-mode m)
  6288. (org-agenda-show))
  6289. (if (and m org-agenda-show-outline-path)
  6290. (org-with-point-at m
  6291. (org-display-outline-path t)))))
  6292. (defun org-agenda-show-priority ()
  6293. "Show the priority of the current item.
  6294. This priority is composed of the main priority given with the [#A] cookies,
  6295. and by additional input from the age of a schedules or deadline entry."
  6296. (interactive)
  6297. (let* ((pri (org-get-at-bol 'priority)))
  6298. (message "Priority is %d" (if pri pri -1000))))
  6299. (defun org-agenda-show-tags ()
  6300. "Show the tags applicable to the current item."
  6301. (interactive)
  6302. (let* ((tags (org-get-at-bol 'tags)))
  6303. (if tags
  6304. (message "Tags are :%s:"
  6305. (org-no-properties (mapconcat 'identity tags ":")))
  6306. (message "No tags associated with this line"))))
  6307. (defun org-agenda-goto (&optional highlight)
  6308. "Go to the Org-mode file which contains the item at point."
  6309. (interactive)
  6310. (let* ((marker (or (org-get-at-bol 'org-marker)
  6311. (org-agenda-error)))
  6312. (buffer (marker-buffer marker))
  6313. (pos (marker-position marker)))
  6314. (switch-to-buffer-other-window buffer)
  6315. (widen)
  6316. (push-mark)
  6317. (goto-char pos)
  6318. (when (org-mode-p)
  6319. (org-show-context 'agenda)
  6320. (save-excursion
  6321. (and (outline-next-heading)
  6322. (org-flag-heading nil)))) ; show the next heading
  6323. (when (outline-invisible-p)
  6324. (show-entry)) ; display invisible text
  6325. (recenter (/ (window-height) 2))
  6326. (run-hooks 'org-agenda-after-show-hook)
  6327. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6328. (defvar org-agenda-after-show-hook nil
  6329. "Normal hook run after an item has been shown from the agenda.
  6330. Point is in the buffer where the item originated.")
  6331. (defun org-agenda-kill ()
  6332. "Kill the entry or subtree belonging to the current agenda entry."
  6333. (interactive)
  6334. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6335. (let* ((marker (or (org-get-at-bol 'org-marker)
  6336. (org-agenda-error)))
  6337. (buffer (marker-buffer marker))
  6338. (pos (marker-position marker))
  6339. (type (org-get-at-bol 'type))
  6340. dbeg dend (n 0) conf)
  6341. (org-with-remote-undo buffer
  6342. (with-current-buffer buffer
  6343. (save-excursion
  6344. (goto-char pos)
  6345. (if (and (org-mode-p) (not (member type '("sexp"))))
  6346. (setq dbeg (progn (org-back-to-heading t) (point))
  6347. dend (org-end-of-subtree t t))
  6348. (setq dbeg (point-at-bol)
  6349. dend (min (point-max) (1+ (point-at-eol)))))
  6350. (goto-char dbeg)
  6351. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6352. (setq conf (or (eq t org-agenda-confirm-kill)
  6353. (and (numberp org-agenda-confirm-kill)
  6354. (> n org-agenda-confirm-kill))))
  6355. (and conf
  6356. (not (y-or-n-p
  6357. (format "Delete entry with %d lines in buffer \"%s\"? "
  6358. n (buffer-name buffer))))
  6359. (error "Abort"))
  6360. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6361. (with-current-buffer buffer (delete-region dbeg dend))
  6362. (message "Agenda item and source killed"))))
  6363. (defvar org-archive-default-command)
  6364. (defun org-agenda-archive-default ()
  6365. "Archive the entry or subtree belonging to the current agenda entry."
  6366. (interactive)
  6367. (require 'org-archive)
  6368. (org-agenda-archive-with org-archive-default-command))
  6369. (defun org-agenda-archive-default-with-confirmation ()
  6370. "Archive the entry or subtree belonging to the current agenda entry."
  6371. (interactive)
  6372. (require 'org-archive)
  6373. (org-agenda-archive-with org-archive-default-command 'confirm))
  6374. (defun org-agenda-archive ()
  6375. "Archive the entry or subtree belonging to the current agenda entry."
  6376. (interactive)
  6377. (org-agenda-archive-with 'org-archive-subtree))
  6378. (defun org-agenda-archive-to-archive-sibling ()
  6379. "Move the entry to the archive sibling."
  6380. (interactive)
  6381. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6382. (defun org-agenda-archive-with (cmd &optional confirm)
  6383. "Move the entry to the archive sibling."
  6384. (interactive)
  6385. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6386. (let* ((marker (or (org-get-at-bol 'org-marker)
  6387. (org-agenda-error)))
  6388. (buffer (marker-buffer marker))
  6389. (pos (marker-position marker)))
  6390. (org-with-remote-undo buffer
  6391. (with-current-buffer buffer
  6392. (if (org-mode-p)
  6393. (if (and confirm
  6394. (not (y-or-n-p "Archive this subtree or entry? ")))
  6395. (error "Abort")
  6396. (save-excursion
  6397. (goto-char pos)
  6398. (org-remove-subtree-entries-from-agenda)
  6399. (org-back-to-heading t)
  6400. (funcall cmd)))
  6401. (error "Archiving works only in Org-mode files"))))))
  6402. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6403. "Remove all lines in the agenda that correspond to a given subtree.
  6404. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6405. If this information is not given, the function uses the tree at point."
  6406. (let ((buf (or buf (current-buffer))) m p)
  6407. (save-excursion
  6408. (unless (and beg end)
  6409. (org-back-to-heading t)
  6410. (setq beg (point))
  6411. (org-end-of-subtree t)
  6412. (setq end (point)))
  6413. (set-buffer (get-buffer org-agenda-buffer-name))
  6414. (save-excursion
  6415. (goto-char (point-max))
  6416. (beginning-of-line 1)
  6417. (while (not (bobp))
  6418. (when (and (setq m (org-get-at-bol 'org-marker))
  6419. (equal buf (marker-buffer m))
  6420. (setq p (marker-position m))
  6421. (>= p beg)
  6422. (< p end))
  6423. (let ((inhibit-read-only t))
  6424. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6425. (beginning-of-line 0))))))
  6426. (defun org-agenda-refile (&optional goto rfloc no-update)
  6427. "Refile the item at point."
  6428. (interactive "P")
  6429. (if (equal goto '(16))
  6430. (org-refile-goto-last-stored)
  6431. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6432. (org-agenda-error)))
  6433. (buffer (marker-buffer marker))
  6434. (pos (marker-position marker))
  6435. (rfloc (or rfloc
  6436. (org-refile-get-location
  6437. (if goto "Goto" "Refile to") buffer
  6438. org-refile-allow-creating-parent-nodes))))
  6439. (with-current-buffer buffer
  6440. (save-excursion
  6441. (save-restriction
  6442. (widen)
  6443. (goto-char marker)
  6444. (org-remove-subtree-entries-from-agenda)
  6445. (org-refile goto buffer rfloc)))))
  6446. (unless no-update (org-agenda-redo))))
  6447. (defun org-agenda-open-link (&optional arg)
  6448. "Follow the link in the current line, if any.
  6449. This looks for a link in the displayed line in the agenda. It also looks
  6450. at the text of the entry itself."
  6451. (interactive "P")
  6452. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6453. (org-get-at-bol 'org-marker)))
  6454. (buffer (and marker (marker-buffer marker)))
  6455. (prefix (buffer-substring
  6456. (point-at-bol) (point-at-eol))))
  6457. (cond
  6458. (buffer
  6459. (with-current-buffer buffer
  6460. (save-excursion
  6461. (save-restriction
  6462. (widen)
  6463. (goto-char marker)
  6464. (org-offer-links-in-entry arg prefix)))))
  6465. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6466. (save-excursion
  6467. (beginning-of-line 1)
  6468. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6469. (org-open-link-from-string (match-string 1)))
  6470. (t (error "No link to open here")))))
  6471. (defun org-agenda-copy-local-variable (var)
  6472. "Get a variable from a referenced buffer and install it here."
  6473. (let ((m (org-get-at-bol 'org-marker)))
  6474. (when (and m (buffer-live-p (marker-buffer m)))
  6475. (org-set-local var (with-current-buffer (marker-buffer m)
  6476. (symbol-value var))))))
  6477. (defun org-agenda-switch-to (&optional delete-other-windows)
  6478. "Go to the Org-mode file which contains the item at point."
  6479. (interactive)
  6480. (if (and org-return-follows-link
  6481. (not (org-get-at-bol 'org-marker))
  6482. (org-in-regexp org-bracket-link-regexp))
  6483. (org-open-link-from-string (match-string 0))
  6484. (let* ((marker (or (org-get-at-bol 'org-marker)
  6485. (org-agenda-error)))
  6486. (buffer (marker-buffer marker))
  6487. (pos (marker-position marker)))
  6488. (org-pop-to-buffer-same-window buffer)
  6489. (and delete-other-windows (delete-other-windows))
  6490. (widen)
  6491. (goto-char pos)
  6492. (when (org-mode-p)
  6493. (org-show-context 'agenda)
  6494. (save-excursion
  6495. (and (outline-next-heading)
  6496. (org-flag-heading nil))) ; show the next heading
  6497. (when (outline-invisible-p)
  6498. (show-entry)))))) ; display invisible text
  6499. (defun org-agenda-goto-mouse (ev)
  6500. "Go to the Org-mode file which contains the item at the mouse click."
  6501. (interactive "e")
  6502. (mouse-set-point ev)
  6503. (org-agenda-goto))
  6504. (defun org-agenda-show (&optional full-entry)
  6505. "Display the Org-mode file which contains the item at point.
  6506. With prefix argument FULL-ENTRY, make the entire entry visible
  6507. if it was hidden in the outline."
  6508. (interactive "P")
  6509. (let ((win (selected-window)))
  6510. (if full-entry
  6511. (let ((org-show-entry-below t))
  6512. (org-agenda-goto t))
  6513. (org-agenda-goto t))
  6514. (select-window win)))
  6515. (defvar org-agenda-show-window nil)
  6516. (defun org-agenda-show-and-scroll-up ()
  6517. "Display the Org-mode file which contains the item at point.
  6518. When called repeatedly, scroll the window that is displaying the buffer."
  6519. (interactive)
  6520. (let ((win (selected-window)))
  6521. (if (and (window-live-p org-agenda-show-window)
  6522. (eq this-command last-command))
  6523. (progn
  6524. (select-window org-agenda-show-window)
  6525. (ignore-errors (scroll-up)))
  6526. (org-agenda-goto t)
  6527. (show-subtree)
  6528. (setq org-agenda-show-window (selected-window)))
  6529. (select-window win)))
  6530. (defun org-agenda-show-scroll-down ()
  6531. "Scroll down the window showing the agenda."
  6532. (interactive)
  6533. (let ((win (selected-window)))
  6534. (when (window-live-p org-agenda-show-window)
  6535. (select-window org-agenda-show-window)
  6536. (ignore-errors (scroll-down))
  6537. (select-window win))))
  6538. (defun org-agenda-show-1 (&optional more)
  6539. "Display the Org-mode file which contains the item at point.
  6540. The prefix arg selects the amount of information to display:
  6541. 0 hide the subtree
  6542. 1 just show the entry according to defaults.
  6543. 2 show the children view
  6544. 3 show the subtree view
  6545. 4 show the entire subtree and any LOGBOOK drawers
  6546. 5 show the entire subtree and any drawers
  6547. With prefix argument FULL-ENTRY, make the entire entry visible
  6548. if it was hidden in the outline."
  6549. (interactive "p")
  6550. (let ((win (selected-window)))
  6551. (org-agenda-goto t)
  6552. (org-recenter-heading 1)
  6553. (cond
  6554. ((= more 0)
  6555. (hide-subtree)
  6556. (save-excursion
  6557. (org-back-to-heading)
  6558. (run-hook-with-args 'org-cycle-hook 'folded))
  6559. (message "Remote: FOLDED"))
  6560. ((and (org-called-interactively-p 'any) (= more 1))
  6561. (message "Remote: show with default settings"))
  6562. ((= more 2)
  6563. (show-entry)
  6564. (show-children)
  6565. (save-excursion
  6566. (org-back-to-heading)
  6567. (run-hook-with-args 'org-cycle-hook 'children))
  6568. (message "Remote: CHILDREN"))
  6569. ((= more 3)
  6570. (show-subtree)
  6571. (save-excursion
  6572. (org-back-to-heading)
  6573. (run-hook-with-args 'org-cycle-hook 'subtree))
  6574. (message "Remote: SUBTREE"))
  6575. ((= more 4)
  6576. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6577. (org-drawer-regexp
  6578. (concat "^[ \t]*:\\("
  6579. (mapconcat 'regexp-quote org-drawers "\\|")
  6580. "\\):[ \t]*$")))
  6581. (show-subtree)
  6582. (save-excursion
  6583. (org-back-to-heading)
  6584. (org-cycle-hide-drawers 'subtree)))
  6585. (message "Remote: SUBTREE AND LOGBOOK"))
  6586. ((> more 4)
  6587. (show-subtree)
  6588. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6589. (select-window win)))
  6590. (defun org-recenter-heading (n)
  6591. (save-excursion
  6592. (org-back-to-heading)
  6593. (recenter n)))
  6594. (defvar org-agenda-cycle-counter nil)
  6595. (defun org-agenda-cycle-show (&optional n)
  6596. "Show the current entry in another window, with default settings.
  6597. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6598. When use repeatedly in immediate succession, the remote entry will cycle
  6599. through visibility
  6600. children -> subtree -> folded
  6601. When called with a numeric prefix arg, that arg will be passed through to
  6602. `org-agenda-show-1'. For the interpretation of that argument, see the
  6603. docstring of `org-agenda-show-1'."
  6604. (interactive "P")
  6605. (if (integerp n)
  6606. (setq org-agenda-cycle-counter n)
  6607. (if (not (eq last-command this-command))
  6608. (setq org-agenda-cycle-counter 1)
  6609. (if (equal org-agenda-cycle-counter 0)
  6610. (setq org-agenda-cycle-counter 2)
  6611. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6612. (if (> org-agenda-cycle-counter 3)
  6613. (setq org-agenda-cycle-counter 0)))))
  6614. (org-agenda-show-1 org-agenda-cycle-counter))
  6615. (defun org-agenda-recenter (arg)
  6616. "Display the Org-mode file which contains the item at point and recenter."
  6617. (interactive "P")
  6618. (let ((win (selected-window)))
  6619. (org-agenda-goto t)
  6620. (recenter arg)
  6621. (select-window win)))
  6622. (defun org-agenda-show-mouse (ev)
  6623. "Display the Org-mode file which contains the item at the mouse click."
  6624. (interactive "e")
  6625. (mouse-set-point ev)
  6626. (org-agenda-show))
  6627. (defun org-agenda-check-no-diary ()
  6628. "Check if the entry is a diary link and abort if yes."
  6629. (if (org-get-at-bol 'org-agenda-diary-link)
  6630. (org-agenda-error)))
  6631. (defun org-agenda-error ()
  6632. (error "Command not allowed in this line"))
  6633. (defun org-agenda-tree-to-indirect-buffer ()
  6634. "Show the subtree corresponding to the current entry in an indirect buffer.
  6635. This calls the command `org-tree-to-indirect-buffer' from the original
  6636. Org-mode buffer.
  6637. With numerical prefix arg ARG, go up to this level and then take that tree.
  6638. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6639. use the dedicated frame)."
  6640. (interactive)
  6641. (org-agenda-check-no-diary)
  6642. (let* ((marker (or (org-get-at-bol 'org-marker)
  6643. (org-agenda-error)))
  6644. (buffer (marker-buffer marker))
  6645. (pos (marker-position marker)))
  6646. (with-current-buffer buffer
  6647. (save-excursion
  6648. (goto-char pos)
  6649. (call-interactively 'org-tree-to-indirect-buffer)))))
  6650. (defvar org-last-heading-marker (make-marker)
  6651. "Marker pointing to the headline that last changed its TODO state
  6652. by a remote command from the agenda.")
  6653. (defun org-agenda-todo-nextset ()
  6654. "Switch TODO entry to next sequence."
  6655. (interactive)
  6656. (org-agenda-todo 'nextset))
  6657. (defun org-agenda-todo-previousset ()
  6658. "Switch TODO entry to previous sequence."
  6659. (interactive)
  6660. (org-agenda-todo 'previousset))
  6661. (defun org-agenda-todo (&optional arg)
  6662. "Cycle TODO state of line at point, also in Org-mode file.
  6663. This changes the line at point, all other lines in the agenda referring to
  6664. the same tree node, and the headline of the tree node in the Org-mode file."
  6665. (interactive "P")
  6666. (org-agenda-check-no-diary)
  6667. (let* ((col (current-column))
  6668. (marker (or (org-get-at-bol 'org-marker)
  6669. (org-agenda-error)))
  6670. (buffer (marker-buffer marker))
  6671. (pos (marker-position marker))
  6672. (hdmarker (org-get-at-bol 'org-hd-marker))
  6673. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6674. (inhibit-read-only t)
  6675. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6676. (org-with-remote-undo buffer
  6677. (with-current-buffer buffer
  6678. (widen)
  6679. (goto-char pos)
  6680. (org-show-context 'agenda)
  6681. (save-excursion
  6682. (and (outline-next-heading)
  6683. (org-flag-heading nil))) ; show the next heading
  6684. (let ((current-prefix-arg arg))
  6685. (call-interactively 'org-todo))
  6686. (and (bolp) (forward-char 1))
  6687. (setq newhead (org-get-heading))
  6688. (when (and (org-bound-and-true-p
  6689. org-agenda-headline-snapshot-before-repeat)
  6690. (not (equal org-agenda-headline-snapshot-before-repeat
  6691. newhead))
  6692. todayp)
  6693. (setq newhead org-agenda-headline-snapshot-before-repeat
  6694. just-one t))
  6695. (save-excursion
  6696. (org-back-to-heading)
  6697. (move-marker org-last-heading-marker (point))))
  6698. (beginning-of-line 1)
  6699. (save-excursion
  6700. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6701. (org-move-to-column col))))
  6702. (defun org-agenda-add-note (&optional arg)
  6703. "Add a time-stamped note to the entry at point."
  6704. (interactive "P")
  6705. (org-agenda-check-no-diary)
  6706. (let* ((marker (or (org-get-at-bol 'org-marker)
  6707. (org-agenda-error)))
  6708. (buffer (marker-buffer marker))
  6709. (pos (marker-position marker))
  6710. (hdmarker (org-get-at-bol 'org-hd-marker))
  6711. (inhibit-read-only t))
  6712. (with-current-buffer buffer
  6713. (widen)
  6714. (goto-char pos)
  6715. (org-show-context 'agenda)
  6716. (save-excursion
  6717. (and (outline-next-heading)
  6718. (org-flag-heading nil))) ; show the next heading
  6719. (org-add-note))))
  6720. (defun org-agenda-change-all-lines (newhead hdmarker
  6721. &optional fixface just-this)
  6722. "Change all lines in the agenda buffer which match HDMARKER.
  6723. The new content of the line will be NEWHEAD (as modified by
  6724. `org-format-agenda-item'). HDMARKER is checked with
  6725. `equal' against all `org-hd-marker' text properties in the file.
  6726. If FIXFACE is non-nil, the face of each item is modified according to
  6727. the new TODO state.
  6728. If JUST-THIS is non-nil, change just the current line, not all.
  6729. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6730. (let* ((inhibit-read-only t)
  6731. (line (org-current-line))
  6732. (thetags (with-current-buffer (marker-buffer hdmarker)
  6733. (save-excursion (save-restriction (widen)
  6734. (goto-char hdmarker)
  6735. (org-get-tags-at)))))
  6736. props m pl undone-face done-face finish new dotime cat tags)
  6737. (save-excursion
  6738. (goto-char (point-max))
  6739. (beginning-of-line 1)
  6740. (while (not finish)
  6741. (setq finish (bobp))
  6742. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6743. (or (not just-this) (= (org-current-line) line))
  6744. (equal m hdmarker))
  6745. (setq props (text-properties-at (point))
  6746. dotime (org-get-at-bol 'dotime)
  6747. cat (org-get-at-bol 'org-category)
  6748. tags thetags
  6749. new
  6750. (let ((org-prefix-format-compiled
  6751. (or (get-text-property (point) 'format)
  6752. org-prefix-format-compiled)))
  6753. (with-current-buffer (marker-buffer hdmarker)
  6754. (save-excursion
  6755. (save-restriction
  6756. (widen)
  6757. (org-format-agenda-item (org-get-at-bol 'extra)
  6758. newhead cat tags dotime)))))
  6759. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6760. undone-face (org-get-at-bol 'undone-face)
  6761. done-face (org-get-at-bol 'done-face))
  6762. (beginning-of-line 1)
  6763. (cond
  6764. ((equal new "")
  6765. (and (looking-at ".*\n?") (replace-match "")))
  6766. ((looking-at ".*")
  6767. (replace-match new t t)
  6768. (beginning-of-line 1)
  6769. (add-text-properties (point-at-bol) (point-at-eol) props)
  6770. (when fixface
  6771. (add-text-properties
  6772. (point-at-bol) (point-at-eol)
  6773. (list 'face
  6774. (if org-last-todo-state-is-todo
  6775. undone-face done-face))))
  6776. (org-agenda-highlight-todo 'line)
  6777. (beginning-of-line 1))
  6778. (t (error "Line update did not work"))))
  6779. (beginning-of-line 0)))
  6780. (org-finalize-agenda)))
  6781. (defun org-agenda-align-tags (&optional line)
  6782. "Align all tags in agenda items to `org-agenda-tags-column'."
  6783. (let ((inhibit-read-only t) l c)
  6784. (save-excursion
  6785. (goto-char (if line (point-at-bol) (point-min)))
  6786. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6787. (if line (point-at-eol) nil) t)
  6788. (add-text-properties
  6789. (match-beginning 2) (match-end 2)
  6790. (list 'face (delq nil (let ((prop (get-text-property
  6791. (match-beginning 2) 'face)))
  6792. (or (listp prop) (setq prop (list prop)))
  6793. (if (memq 'org-tag prop)
  6794. prop
  6795. (cons 'org-tag prop))))))
  6796. (setq l (- (match-end 2) (match-beginning 2))
  6797. c (if (< org-agenda-tags-column 0)
  6798. (- (abs org-agenda-tags-column) l)
  6799. org-agenda-tags-column))
  6800. (delete-region (match-beginning 1) (match-end 1))
  6801. (goto-char (match-beginning 1))
  6802. (insert (org-add-props
  6803. (make-string (max 1 (- c (current-column))) ?\ )
  6804. (plist-put (copy-sequence (text-properties-at (point)))
  6805. 'face nil))))
  6806. (goto-char (point-min))
  6807. (org-font-lock-add-tag-faces (point-max)))))
  6808. (defun org-agenda-priority-up ()
  6809. "Increase the priority of line at point, also in Org-mode file."
  6810. (interactive)
  6811. (org-agenda-priority 'up))
  6812. (defun org-agenda-priority-down ()
  6813. "Decrease the priority of line at point, also in Org-mode file."
  6814. (interactive)
  6815. (org-agenda-priority 'down))
  6816. (defun org-agenda-priority (&optional force-direction)
  6817. "Set the priority of line at point, also in Org-mode file.
  6818. This changes the line at point, all other lines in the agenda referring to
  6819. the same tree node, and the headline of the tree node in the Org-mode file."
  6820. (interactive)
  6821. (unless org-enable-priority-commands
  6822. (error "Priority commands are disabled"))
  6823. (org-agenda-check-no-diary)
  6824. (let* ((marker (or (org-get-at-bol 'org-marker)
  6825. (org-agenda-error)))
  6826. (hdmarker (org-get-at-bol 'org-hd-marker))
  6827. (buffer (marker-buffer hdmarker))
  6828. (pos (marker-position hdmarker))
  6829. (inhibit-read-only t)
  6830. newhead)
  6831. (org-with-remote-undo buffer
  6832. (with-current-buffer buffer
  6833. (widen)
  6834. (goto-char pos)
  6835. (org-show-context 'agenda)
  6836. (save-excursion
  6837. (and (outline-next-heading)
  6838. (org-flag-heading nil))) ; show the next heading
  6839. (funcall 'org-priority force-direction)
  6840. (end-of-line 1)
  6841. (setq newhead (org-get-heading)))
  6842. (org-agenda-change-all-lines newhead hdmarker)
  6843. (beginning-of-line 1))))
  6844. ;; FIXME: should fix the tags property of the agenda line.
  6845. (defun org-agenda-set-tags (&optional tag onoff)
  6846. "Set tags for the current headline."
  6847. (interactive)
  6848. (org-agenda-check-no-diary)
  6849. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6850. (call-interactively 'org-change-tag-in-region)
  6851. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6852. (org-agenda-error)))
  6853. (buffer (marker-buffer hdmarker))
  6854. (pos (marker-position hdmarker))
  6855. (inhibit-read-only t)
  6856. newhead)
  6857. (org-with-remote-undo buffer
  6858. (with-current-buffer buffer
  6859. (widen)
  6860. (goto-char pos)
  6861. (save-excursion
  6862. (org-show-context 'agenda))
  6863. (save-excursion
  6864. (and (outline-next-heading)
  6865. (org-flag-heading nil))) ; show the next heading
  6866. (goto-char pos)
  6867. (if tag
  6868. (org-toggle-tag tag onoff)
  6869. (call-interactively 'org-set-tags))
  6870. (end-of-line 1)
  6871. (setq newhead (org-get-heading)))
  6872. (org-agenda-change-all-lines newhead hdmarker)
  6873. (beginning-of-line 1)))))
  6874. (defun org-agenda-set-property ()
  6875. "Set a property for the current headline."
  6876. (interactive)
  6877. (org-agenda-check-no-diary)
  6878. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6879. (org-agenda-error)))
  6880. (buffer (marker-buffer hdmarker))
  6881. (pos (marker-position hdmarker))
  6882. (inhibit-read-only t)
  6883. newhead)
  6884. (org-with-remote-undo buffer
  6885. (with-current-buffer buffer
  6886. (widen)
  6887. (goto-char pos)
  6888. (save-excursion
  6889. (org-show-context 'agenda))
  6890. (save-excursion
  6891. (and (outline-next-heading)
  6892. (org-flag-heading nil))) ; show the next heading
  6893. (goto-char pos)
  6894. (call-interactively 'org-set-property)))))
  6895. (defun org-agenda-set-effort ()
  6896. "Set the effort property for the current headline."
  6897. (interactive)
  6898. (org-agenda-check-no-diary)
  6899. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6900. (org-agenda-error)))
  6901. (buffer (marker-buffer hdmarker))
  6902. (pos (marker-position hdmarker))
  6903. (inhibit-read-only t)
  6904. newhead)
  6905. (org-with-remote-undo buffer
  6906. (with-current-buffer buffer
  6907. (widen)
  6908. (goto-char pos)
  6909. (save-excursion
  6910. (org-show-context 'agenda))
  6911. (save-excursion
  6912. (and (outline-next-heading)
  6913. (org-flag-heading nil))) ; show the next heading
  6914. (goto-char pos)
  6915. (call-interactively 'org-set-effort)
  6916. (end-of-line 1)
  6917. (setq newhead (org-get-heading)))
  6918. (org-agenda-change-all-lines newhead hdmarker))))
  6919. (defun org-agenda-toggle-archive-tag ()
  6920. "Toggle the archive tag for the current entry."
  6921. (interactive)
  6922. (org-agenda-check-no-diary)
  6923. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6924. (org-agenda-error)))
  6925. (buffer (marker-buffer hdmarker))
  6926. (pos (marker-position hdmarker))
  6927. (inhibit-read-only t)
  6928. newhead)
  6929. (org-with-remote-undo buffer
  6930. (with-current-buffer buffer
  6931. (widen)
  6932. (goto-char pos)
  6933. (org-show-context 'agenda)
  6934. (save-excursion
  6935. (and (outline-next-heading)
  6936. (org-flag-heading nil))) ; show the next heading
  6937. (call-interactively 'org-toggle-archive-tag)
  6938. (end-of-line 1)
  6939. (setq newhead (org-get-heading)))
  6940. (org-agenda-change-all-lines newhead hdmarker)
  6941. (beginning-of-line 1))))
  6942. (defun org-agenda-do-date-later (arg)
  6943. (interactive "P")
  6944. (cond
  6945. ((or (equal arg '(16))
  6946. (memq last-command
  6947. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6948. (setq this-command 'org-agenda-date-later-minutes)
  6949. (org-agenda-date-later-minutes 1))
  6950. ((or (equal arg '(4))
  6951. (memq last-command
  6952. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6953. (setq this-command 'org-agenda-date-later-hours)
  6954. (org-agenda-date-later-hours 1))
  6955. (t
  6956. (org-agenda-date-later (prefix-numeric-value arg)))))
  6957. (defun org-agenda-do-date-earlier (arg)
  6958. (interactive "P")
  6959. (cond
  6960. ((or (equal arg '(16))
  6961. (memq last-command
  6962. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6963. (setq this-command 'org-agenda-date-earlier-minutes)
  6964. (org-agenda-date-earlier-minutes 1))
  6965. ((or (equal arg '(4))
  6966. (memq last-command
  6967. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6968. (setq this-command 'org-agenda-date-earlier-hours)
  6969. (org-agenda-date-earlier-hours 1))
  6970. (t
  6971. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6972. (defun org-agenda-date-later (arg &optional what)
  6973. "Change the date of this item to ARG day(s) later."
  6974. (interactive "p")
  6975. (org-agenda-check-type t 'agenda 'timeline)
  6976. (org-agenda-check-no-diary)
  6977. (let* ((marker (or (org-get-at-bol 'org-marker)
  6978. (org-agenda-error)))
  6979. (buffer (marker-buffer marker))
  6980. (pos (marker-position marker)))
  6981. (org-with-remote-undo buffer
  6982. (with-current-buffer buffer
  6983. (widen)
  6984. (goto-char pos)
  6985. (if (not (org-at-timestamp-p))
  6986. (error "Cannot find time stamp"))
  6987. (org-timestamp-change arg (or what 'day)))
  6988. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6989. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6990. (defun org-agenda-date-earlier (arg &optional what)
  6991. "Change the date of this item to ARG day(s) earlier."
  6992. (interactive "p")
  6993. (org-agenda-date-later (- arg) what))
  6994. (defun org-agenda-date-later-minutes (arg)
  6995. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6996. (interactive "p")
  6997. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6998. (org-agenda-date-later arg 'minute))
  6999. (defun org-agenda-date-earlier-minutes (arg)
  7000. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7001. (interactive "p")
  7002. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7003. (org-agenda-date-earlier arg 'minute))
  7004. (defun org-agenda-date-later-hours (arg)
  7005. "Change the time of this item, in hour steps."
  7006. (interactive "p")
  7007. (org-agenda-date-later arg 'hour))
  7008. (defun org-agenda-date-earlier-hours (arg)
  7009. "Change the time of this item, in hour steps."
  7010. (interactive "p")
  7011. (org-agenda-date-earlier arg 'hour))
  7012. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7013. "Show new date stamp via text properties."
  7014. ;; We use text properties to make this undoable
  7015. (let ((inhibit-read-only t)
  7016. (buffer-invisibility-spec))
  7017. (setq stamp (concat " " prefix " => " stamp))
  7018. (save-excursion
  7019. (goto-char (point-max))
  7020. (while (not (bobp))
  7021. (when (equal marker (org-get-at-bol 'org-marker))
  7022. (org-move-to-column (- (window-width) (length stamp)) t)
  7023. (org-agenda-fix-tags-filter-overlays-at (point))
  7024. (if (featurep 'xemacs)
  7025. ;; Use `duplicable' property to trigger undo recording
  7026. (let ((ex (make-extent nil nil))
  7027. (gl (make-glyph stamp)))
  7028. (set-glyph-face gl 'secondary-selection)
  7029. (set-extent-properties
  7030. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7031. (insert-extent ex (1- (point)) (point-at-eol)))
  7032. (add-text-properties
  7033. (1- (point)) (point-at-eol)
  7034. (list 'display (org-add-props stamp nil
  7035. 'face 'secondary-selection))))
  7036. (beginning-of-line 1))
  7037. (beginning-of-line 0)))))
  7038. (defun org-agenda-date-prompt (arg)
  7039. "Change the date of this item. Date is prompted for, with default today.
  7040. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7041. be used to request time specification in the time stamp."
  7042. (interactive "P")
  7043. (org-agenda-check-type t 'agenda 'timeline)
  7044. (org-agenda-check-no-diary)
  7045. (let* ((marker (or (org-get-at-bol 'org-marker)
  7046. (org-agenda-error)))
  7047. (buffer (marker-buffer marker))
  7048. (pos (marker-position marker)))
  7049. (org-with-remote-undo buffer
  7050. (with-current-buffer buffer
  7051. (widen)
  7052. (goto-char pos)
  7053. (if (not (org-at-timestamp-p t))
  7054. (error "Cannot find time stamp"))
  7055. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7056. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7057. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7058. (defun org-agenda-schedule (arg &optional time)
  7059. "Schedule the item at point.
  7060. ARG is passed through to `org-schedule'."
  7061. (interactive "P")
  7062. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7063. (org-agenda-check-no-diary)
  7064. (let* ((marker (or (org-get-at-bol 'org-marker)
  7065. (org-agenda-error)))
  7066. (type (marker-insertion-type marker))
  7067. (buffer (marker-buffer marker))
  7068. (pos (marker-position marker))
  7069. (org-insert-labeled-timestamps-at-point nil)
  7070. ts)
  7071. (set-marker-insertion-type marker t)
  7072. (org-with-remote-undo buffer
  7073. (with-current-buffer buffer
  7074. (widen)
  7075. (goto-char pos)
  7076. (setq ts (org-schedule arg time)))
  7077. (org-agenda-show-new-time marker ts "S"))
  7078. (message "Item scheduled for %s" ts)))
  7079. (defun org-agenda-deadline (arg &optional time)
  7080. "Schedule the item at point.
  7081. ARG is passed through to `org-deadline'."
  7082. (interactive "P")
  7083. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7084. (org-agenda-check-no-diary)
  7085. (let* ((marker (or (org-get-at-bol 'org-marker)
  7086. (org-agenda-error)))
  7087. (buffer (marker-buffer marker))
  7088. (pos (marker-position marker))
  7089. (org-insert-labeled-timestamps-at-point nil)
  7090. ts)
  7091. (org-with-remote-undo buffer
  7092. (with-current-buffer buffer
  7093. (widen)
  7094. (goto-char pos)
  7095. (setq ts (org-deadline arg time)))
  7096. (org-agenda-show-new-time marker ts "D"))
  7097. (message "Deadline for this item set to %s" ts)))
  7098. (defun org-agenda-action ()
  7099. "Select entry for agenda action, or execute an agenda action.
  7100. This command prompts for another letter. Valid inputs are:
  7101. m Mark the entry at point for an agenda action
  7102. s Schedule the marked entry to the date at the cursor
  7103. d Set the deadline of the marked entry to the date at the cursor
  7104. r Call `org-remember' with cursor date as the default date
  7105. c Call `org-capture' with cursor date as the default date
  7106. SPC Show marked entry in other window
  7107. TAB Visit marked entry in other window
  7108. The cursor may be at a date in the calendar, or in the Org agenda."
  7109. (interactive)
  7110. (let (ans)
  7111. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7112. (setq ans (read-char-exclusive))
  7113. (cond
  7114. ((equal ans ?m)
  7115. ;; Mark this entry
  7116. (if (eq major-mode 'org-agenda-mode)
  7117. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7118. (org-get-at-bol 'org-marker))))
  7119. (if m
  7120. (progn
  7121. (move-marker org-agenda-action-marker
  7122. (marker-position m) (marker-buffer m))
  7123. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7124. (error "Don't know which entry to mark")))
  7125. (error "This command works only in the agenda")))
  7126. ((equal ans ?s)
  7127. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7128. ((equal ans ?d)
  7129. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7130. ((equal ans ?r)
  7131. (org-agenda-do-action '(org-remember) t))
  7132. ((equal ans ?c)
  7133. (org-agenda-do-action '(org-capture) t))
  7134. ((equal ans ?\ )
  7135. (let ((cw (selected-window)))
  7136. (org-switch-to-buffer-other-window
  7137. (marker-buffer org-agenda-action-marker))
  7138. (goto-char org-agenda-action-marker)
  7139. (org-show-context 'agenda)
  7140. (select-window cw)))
  7141. ((equal ans ?\C-i)
  7142. (org-switch-to-buffer-other-window
  7143. (marker-buffer org-agenda-action-marker))
  7144. (goto-char org-agenda-action-marker)
  7145. (org-show-context 'agenda))
  7146. (t (error "Invalid agenda action %c" ans)))))
  7147. (defun org-agenda-do-action (form &optional current-buffer)
  7148. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7149. (let ((org-overriding-default-time (org-get-cursor-date)))
  7150. (if current-buffer
  7151. (eval form)
  7152. (if (not (marker-buffer org-agenda-action-marker))
  7153. (error "No entry has been selected for agenda action")
  7154. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7155. (save-excursion
  7156. (save-restriction
  7157. (widen)
  7158. (goto-char org-agenda-action-marker)
  7159. (eval form))))))))
  7160. (defun org-agenda-clock-in (&optional arg)
  7161. "Start the clock on the currently selected item."
  7162. (interactive "P")
  7163. (org-agenda-check-no-diary)
  7164. (if (equal arg '(4))
  7165. (org-clock-in arg)
  7166. (let* ((marker (or (org-get-at-bol 'org-marker)
  7167. (org-agenda-error)))
  7168. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7169. marker))
  7170. (pos (marker-position marker))
  7171. newhead)
  7172. (org-with-remote-undo (marker-buffer marker)
  7173. (with-current-buffer (marker-buffer marker)
  7174. (widen)
  7175. (goto-char pos)
  7176. (org-show-context 'agenda)
  7177. (org-show-entry)
  7178. (org-cycle-hide-drawers 'children)
  7179. (org-clock-in arg)
  7180. (setq newhead (org-get-heading)))
  7181. (org-agenda-change-all-lines newhead hdmarker)))))
  7182. (defun org-agenda-clock-out ()
  7183. "Stop the currently running clock."
  7184. (interactive)
  7185. (unless (marker-buffer org-clock-marker)
  7186. (error "No running clock"))
  7187. (let ((marker (make-marker)) newhead)
  7188. (org-with-remote-undo (marker-buffer org-clock-marker)
  7189. (with-current-buffer (marker-buffer org-clock-marker)
  7190. (save-excursion
  7191. (save-restriction
  7192. (widen)
  7193. (goto-char org-clock-marker)
  7194. (org-back-to-heading t)
  7195. (move-marker marker (point))
  7196. (org-clock-out)
  7197. (setq newhead (org-get-heading))))))
  7198. (org-agenda-change-all-lines newhead marker)
  7199. (move-marker marker nil)))
  7200. (defun org-agenda-clock-cancel (&optional arg)
  7201. "Cancel the currently running clock."
  7202. (interactive "P")
  7203. (unless (marker-buffer org-clock-marker)
  7204. (error "No running clock"))
  7205. (org-with-remote-undo (marker-buffer org-clock-marker)
  7206. (org-clock-cancel)))
  7207. (defun org-agenda-clock-goto ()
  7208. "Jump to the currently clocked in task within the agenda.
  7209. If the currently clocked in task is not listed in the agenda
  7210. buffer, display it in another window."
  7211. (interactive)
  7212. (let (pos)
  7213. (mapc (lambda (o)
  7214. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7215. (setq pos (overlay-start o))))
  7216. (overlays-in (point-min) (point-max)))
  7217. (cond (pos (goto-char pos))
  7218. ;; If the currently clocked entry is not in the agenda
  7219. ;; buffer, we visit it in another window:
  7220. (org-clock-current-task
  7221. (org-switch-to-buffer-other-window (org-clock-goto)))
  7222. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7223. (defun org-agenda-diary-entry-in-org-file ()
  7224. "Make a diary entry in the file `org-agenda-diary-file'."
  7225. (let (d1 d2 char (text "") dp1 dp2)
  7226. (if (equal (buffer-name) "*Calendar*")
  7227. (setq d1 (calendar-cursor-to-date t)
  7228. d2 (car calendar-mark-ring))
  7229. (setq dp1 (get-text-property (point-at-bol) 'day))
  7230. (unless dp1 (error "No date defined in current line"))
  7231. (setq d1 (calendar-gregorian-from-absolute dp1)
  7232. d2 (and (ignore-errors (mark))
  7233. (save-excursion
  7234. (goto-char (mark))
  7235. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7236. (calendar-gregorian-from-absolute dp2))))
  7237. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7238. (setq char (read-char-exclusive))
  7239. (cond
  7240. ((equal char ?d)
  7241. (setq text (read-string "Day entry: "))
  7242. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7243. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7244. ((equal char ?a)
  7245. (setq d1 (list (car d1) (nth 1 d1)
  7246. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7247. (nth 2 d1))))
  7248. (setq text (read-string "Anniversary (use %d to show years): "))
  7249. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7250. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7251. ((equal char ?b)
  7252. (setq text (read-string "Block entry: "))
  7253. (unless (and d1 d2 (not (equal d1 d2)))
  7254. (error "No block of days selected"))
  7255. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7256. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7257. ((equal char ?j)
  7258. (org-switch-to-buffer-other-window
  7259. (find-file-noselect org-agenda-diary-file))
  7260. (require 'org-datetree)
  7261. (org-datetree-find-date-create d1)
  7262. (org-reveal t))
  7263. (t (error "Invalid selection character `%c'" char)))))
  7264. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7265. "Where in `org-agenda-diary-file' should new entries be added?
  7266. Valid values:
  7267. date-tree in the date tree, as child of the date
  7268. top-level as top-level entries at the end of the file."
  7269. :group 'org-agenda
  7270. :type '(choice
  7271. (const :tag "in a date tree" date-tree)
  7272. (const :tag "as top level at end of file" top-level)))
  7273. (defcustom org-agenda-insert-diary-extract-time nil
  7274. "Non-nil means extract any time specification from the diary entry."
  7275. :group 'org-agenda
  7276. :type 'boolean)
  7277. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7278. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7279. If TEXT is not empty, it will become the headline of the new entry, and
  7280. the resulting entry will not be shown. When TEXT is empty, switch to
  7281. `org-agenda-diary-file' and let the user finish the entry there."
  7282. (let ((cw (current-window-configuration)))
  7283. (org-switch-to-buffer-other-window
  7284. (find-file-noselect org-agenda-diary-file))
  7285. (widen)
  7286. (goto-char (point-min))
  7287. (cond
  7288. ((eq type 'anniversary)
  7289. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7290. (progn
  7291. (or (org-on-heading-p t)
  7292. (progn
  7293. (outline-next-heading)
  7294. (insert "* Anniversaries\n\n")
  7295. (beginning-of-line -1)))))
  7296. (outline-next-heading)
  7297. (org-back-over-empty-lines)
  7298. (backward-char 1)
  7299. (insert "\n")
  7300. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7301. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7302. ((eq type 'day)
  7303. (let ((org-prefix-has-time t)
  7304. (org-agenda-time-leading-zero t)
  7305. fmt time time2)
  7306. (if org-agenda-insert-diary-extract-time
  7307. ;; Use org-format-agenda-item to parse text for a time-range and
  7308. ;; remove it. FIXME: This is a hack, we should refactor
  7309. ;; that function to make time extraction available separately
  7310. (setq fmt (org-format-agenda-item nil text nil nil t)
  7311. time (get-text-property 0 'time fmt)
  7312. time2 (if (> (length time) 0)
  7313. ;; split-string removes trailing ...... if
  7314. ;; no end time given. First space
  7315. ;; separates time from date.
  7316. (concat " " (car (split-string time "\\.")))
  7317. nil)
  7318. text (get-text-property 0 'txt fmt)))
  7319. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7320. (org-agenda-insert-diary-as-top-level text)
  7321. (require 'org-datetree)
  7322. (org-datetree-find-date-create d1)
  7323. (org-agenda-insert-diary-make-new-entry text))
  7324. (org-insert-time-stamp (org-time-from-absolute
  7325. (calendar-absolute-from-gregorian d1))
  7326. nil nil nil nil time2))
  7327. (end-of-line 0))
  7328. ((eq type 'block)
  7329. (if (> (calendar-absolute-from-gregorian d1)
  7330. (calendar-absolute-from-gregorian d2))
  7331. (setq d1 (prog1 d2 (setq d2 d1))))
  7332. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7333. (org-agenda-insert-diary-as-top-level text)
  7334. (require 'org-datetree)
  7335. (org-datetree-find-date-create d1)
  7336. (org-agenda-insert-diary-make-new-entry text))
  7337. (org-insert-time-stamp (org-time-from-absolute
  7338. (calendar-absolute-from-gregorian d1)))
  7339. (insert "--")
  7340. (org-insert-time-stamp (org-time-from-absolute
  7341. (calendar-absolute-from-gregorian d2)))
  7342. (end-of-line 0)))
  7343. (if (string-match "\\S-" text)
  7344. (progn
  7345. (set-window-configuration cw)
  7346. (message "%s entry added to %s"
  7347. (capitalize (symbol-name type))
  7348. (abbreviate-file-name org-agenda-diary-file)))
  7349. (org-reveal t)
  7350. (message "Please finish entry here"))))
  7351. (defun org-agenda-insert-diary-as-top-level (text)
  7352. "Make new entry as a top-level entry at the end of the file.
  7353. Add TEXT as headline, and position the cursor in the second line so that
  7354. a timestamp can be added there."
  7355. (widen)
  7356. (goto-char (point-max))
  7357. (or (bolp) (insert "\n"))
  7358. (insert "* " text "\n")
  7359. (if org-adapt-indentation (org-indent-to-column 2)))
  7360. (defun org-agenda-insert-diary-make-new-entry (text)
  7361. "Make new entry as last child of current entry.
  7362. Add TEXT as headline, and position the cursor in the second line so that
  7363. a timestamp can be added there."
  7364. (let ((org-show-following-heading t)
  7365. (org-show-siblings t)
  7366. (org-show-hierarchy-above t)
  7367. (org-show-entry-below t)
  7368. col)
  7369. (outline-next-heading)
  7370. (org-back-over-empty-lines)
  7371. (or (looking-at "[ \t]*$")
  7372. (progn (insert "\n") (backward-char 1)))
  7373. (org-insert-heading nil t)
  7374. (org-do-demote)
  7375. (setq col (current-column))
  7376. (insert text "\n")
  7377. (if org-adapt-indentation (org-indent-to-column col))
  7378. (let ((org-show-following-heading t)
  7379. (org-show-siblings t)
  7380. (org-show-hierarchy-above t)
  7381. (org-show-entry-below t))
  7382. (org-show-context))))
  7383. (defun org-agenda-diary-entry ()
  7384. "Make a diary entry, like the `i' command from the calendar.
  7385. All the standard commands work: block, weekly etc.
  7386. When `org-agenda-diary-file' points to a file,
  7387. `org-agenda-diary-entry-in-org-file' is called instead to create
  7388. entries in that Org-mode file."
  7389. (interactive)
  7390. (org-agenda-check-type t 'agenda 'timeline)
  7391. (if (not (eq org-agenda-diary-file 'diary-file))
  7392. (org-agenda-diary-entry-in-org-file)
  7393. (require 'diary-lib)
  7394. (let* ((char (progn
  7395. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7396. (read-char-exclusive)))
  7397. (cmd (cdr (assoc char
  7398. '((?d . insert-diary-entry)
  7399. (?w . insert-weekly-diary-entry)
  7400. (?m . insert-monthly-diary-entry)
  7401. (?y . insert-yearly-diary-entry)
  7402. (?a . insert-anniversary-diary-entry)
  7403. (?b . insert-block-diary-entry)
  7404. (?c . insert-cyclic-diary-entry)))))
  7405. (oldf (symbol-function 'calendar-cursor-to-date))
  7406. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7407. (point (point))
  7408. (mark (or (mark t) (point))))
  7409. (unless cmd
  7410. (error "No command associated with <%c>" char))
  7411. (unless (and (get-text-property point 'day)
  7412. (or (not (equal ?b char))
  7413. (get-text-property mark 'day)))
  7414. (error "Don't know which date to use for diary entry"))
  7415. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7416. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7417. (let ((calendar-mark-ring
  7418. (list (calendar-gregorian-from-absolute
  7419. (or (get-text-property mark 'day)
  7420. (get-text-property point 'day))))))
  7421. (unwind-protect
  7422. (progn
  7423. (fset 'calendar-cursor-to-date
  7424. (lambda (&optional error dummy)
  7425. (calendar-gregorian-from-absolute
  7426. (get-text-property point 'day))))
  7427. (call-interactively cmd))
  7428. (fset 'calendar-cursor-to-date oldf))))))
  7429. (defun org-agenda-execute-calendar-command (cmd)
  7430. "Execute a calendar command from the agenda, with the date associated to
  7431. the cursor position."
  7432. (org-agenda-check-type t 'agenda 'timeline)
  7433. (require 'diary-lib)
  7434. (unless (get-text-property (point) 'day)
  7435. (error "Don't know which date to use for calendar command"))
  7436. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7437. (point (point))
  7438. (date (calendar-gregorian-from-absolute
  7439. (get-text-property point 'day)))
  7440. ;; the following 2 vars are needed in the calendar
  7441. (displayed-month (car date))
  7442. (displayed-year (nth 2 date)))
  7443. (unwind-protect
  7444. (progn
  7445. (fset 'calendar-cursor-to-date
  7446. (lambda (&optional error dummy)
  7447. (calendar-gregorian-from-absolute
  7448. (get-text-property point 'day))))
  7449. (call-interactively cmd))
  7450. (fset 'calendar-cursor-to-date oldf))))
  7451. (defun org-agenda-phases-of-moon ()
  7452. "Display the phases of the moon for the 3 months around the cursor date."
  7453. (interactive)
  7454. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7455. (defun org-agenda-holidays ()
  7456. "Display the holidays for the 3 months around the cursor date."
  7457. (interactive)
  7458. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7459. (defvar calendar-longitude)
  7460. (defvar calendar-latitude)
  7461. (defvar calendar-location-name)
  7462. (defun org-agenda-sunrise-sunset (arg)
  7463. "Display sunrise and sunset for the cursor date.
  7464. Latitude and longitude can be specified with the variables
  7465. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7466. argument, latitude and longitude will be prompted for."
  7467. (interactive "P")
  7468. (require 'solar)
  7469. (let ((calendar-longitude (if arg nil calendar-longitude))
  7470. (calendar-latitude (if arg nil calendar-latitude))
  7471. (calendar-location-name
  7472. (if arg "the given coordinates" calendar-location-name)))
  7473. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7474. (defun org-agenda-goto-calendar ()
  7475. "Open the Emacs calendar with the date at the cursor."
  7476. (interactive)
  7477. (org-agenda-check-type t 'agenda 'timeline)
  7478. (let* ((day (or (get-text-property (point) 'day)
  7479. (error "Don't know which date to open in calendar")))
  7480. (date (calendar-gregorian-from-absolute day))
  7481. (calendar-move-hook nil)
  7482. (calendar-view-holidays-initially-flag nil)
  7483. (calendar-view-diary-initially-flag nil))
  7484. (calendar)
  7485. (calendar-goto-date date)))
  7486. ;;;###autoload
  7487. (defun org-calendar-goto-agenda ()
  7488. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7489. This is a command that has to be installed in `calendar-mode-map'."
  7490. (interactive)
  7491. (org-agenda-list nil (calendar-absolute-from-gregorian
  7492. (calendar-cursor-to-date))
  7493. nil))
  7494. (defun org-agenda-convert-date ()
  7495. (interactive)
  7496. (org-agenda-check-type t 'agenda 'timeline)
  7497. (let ((day (get-text-property (point) 'day))
  7498. date s)
  7499. (unless day
  7500. (error "Don't know which date to convert"))
  7501. (setq date (calendar-gregorian-from-absolute day))
  7502. (setq s (concat
  7503. "Gregorian: " (calendar-date-string date) "\n"
  7504. "ISO: " (calendar-iso-date-string date) "\n"
  7505. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7506. "Julian: " (calendar-julian-date-string date) "\n"
  7507. "Astron. JD: " (calendar-astro-date-string date)
  7508. " (Julian date number at noon UTC)\n"
  7509. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7510. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7511. "French: " (calendar-french-date-string date) "\n"
  7512. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7513. "Mayan: " (calendar-mayan-date-string date) "\n"
  7514. "Coptic: " (calendar-coptic-date-string date) "\n"
  7515. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7516. "Persian: " (calendar-persian-date-string date) "\n"
  7517. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7518. (with-output-to-temp-buffer "*Dates*"
  7519. (princ s))
  7520. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7521. ;;; Bulk commands
  7522. (defvar org-agenda-bulk-marked-entries nil
  7523. "List of markers that refer to marked entries in the agenda.")
  7524. (defun org-agenda-bulk-marked-p ()
  7525. (eq (get-char-property (point-at-bol) 'type)
  7526. 'org-marked-entry-overlay))
  7527. (defun org-agenda-bulk-mark (&optional arg)
  7528. "Mark the entry at point for future bulk action."
  7529. (interactive "p")
  7530. (dotimes (i (max arg 1))
  7531. (unless (org-get-at-bol 'org-agenda-diary-link)
  7532. (let* ((m (org-get-at-bol 'org-hd-marker))
  7533. ov)
  7534. (unless (org-agenda-bulk-marked-p)
  7535. (unless m (error "Nothing to mark at point"))
  7536. (push m org-agenda-bulk-marked-entries)
  7537. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7538. (org-overlay-display ov "> "
  7539. (org-get-todo-face "TODO")
  7540. 'evaporate)
  7541. (overlay-put ov 'type 'org-marked-entry-overlay))
  7542. (beginning-of-line 2)
  7543. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7544. (beginning-of-line 2))
  7545. (message "%d entries marked for bulk action"
  7546. (length org-agenda-bulk-marked-entries))))))
  7547. (defun org-agenda-bulk-mark-regexp (regexp)
  7548. "Mark entries match REGEXP."
  7549. (interactive "sMark entries matching regexp: ")
  7550. (let (entries-marked)
  7551. (save-excursion
  7552. (goto-char (point-min))
  7553. (goto-char (next-single-property-change (point) 'txt))
  7554. (while (re-search-forward regexp nil t)
  7555. (when (string-match regexp (get-text-property (point) 'txt))
  7556. (setq entries-marked (+ entries-marked 1))
  7557. (call-interactively 'org-agenda-bulk-mark))))
  7558. (if (not entries-marked)
  7559. (message "No entry matching this regexp."))))
  7560. (defun org-agenda-bulk-unmark ()
  7561. "Unmark the entry at point for future bulk action."
  7562. (interactive)
  7563. (when (org-agenda-bulk-marked-p)
  7564. (org-agenda-bulk-remove-overlays
  7565. (point-at-bol) (+ 2 (point-at-bol)))
  7566. (setq org-agenda-bulk-marked-entries
  7567. (delete (org-get-at-bol 'org-hd-marker)
  7568. org-agenda-bulk-marked-entries)))
  7569. (beginning-of-line 2)
  7570. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7571. (beginning-of-line 2))
  7572. (message "%d entries marked for bulk action"
  7573. (length org-agenda-bulk-marked-entries)))
  7574. (defun org-agenda-bulk-toggle ()
  7575. "Toggle marking the entry at point for bulk action."
  7576. (interactive)
  7577. (if (org-agenda-bulk-marked-p)
  7578. (org-agenda-bulk-unmark)
  7579. (org-agenda-bulk-mark)))
  7580. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7581. "Remove the mark overlays between BEG and END in the agenda buffer.
  7582. BEG and END default to the buffer limits.
  7583. This only removes the overlays, it does not remove the markers
  7584. from the list in `org-agenda-bulk-marked-entries'."
  7585. (interactive)
  7586. (mapc (lambda (ov)
  7587. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7588. (delete-overlay ov)))
  7589. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7590. (defun org-agenda-bulk-remove-all-marks ()
  7591. "Remove all marks in the agenda buffer.
  7592. This will remove the markers, and the overlays."
  7593. (interactive)
  7594. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7595. (setq org-agenda-bulk-marked-entries nil)
  7596. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7597. (defun org-agenda-bulk-action (&optional arg)
  7598. "Execute an remote-editing action on all marked entries.
  7599. The prefix arg is passed through to the command if possible."
  7600. (interactive "P")
  7601. ;; Make sure we have markers, and only valid ones
  7602. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7603. (mapc
  7604. (lambda (m)
  7605. (unless (and (markerp m)
  7606. (marker-buffer m)
  7607. (buffer-live-p (marker-buffer m))
  7608. (marker-position m))
  7609. (error "Marker %s for bulk command is invalid" m)))
  7610. org-agenda-bulk-marked-entries)
  7611. ;; Prompt for the bulk command
  7612. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7613. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7614. (when org-agenda-bulk-custom-functions
  7615. (concat " Custom: ["
  7616. (mapconcat (lambda(f) (char-to-string (car f)))
  7617. org-agenda-bulk-custom-functions "")
  7618. "]"))))
  7619. (let* ((action (read-char-exclusive))
  7620. (org-log-refile (if org-log-refile 'time nil))
  7621. (entries (reverse org-agenda-bulk-marked-entries))
  7622. redo-at-end
  7623. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7624. (cond
  7625. ((equal action ?$)
  7626. (setq cmd '(org-agenda-archive)))
  7627. ((equal action ?A)
  7628. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7629. ((member action '(?r ?w))
  7630. (setq rfloc (org-refile-get-location
  7631. "Refile to"
  7632. (marker-buffer (car org-agenda-bulk-marked-entries))
  7633. org-refile-allow-creating-parent-nodes))
  7634. (if (nth 3 rfloc)
  7635. (setcar (nthcdr 3 rfloc)
  7636. (move-marker (make-marker) (nth 3 rfloc)
  7637. (or (get-file-buffer (nth 1 rfloc))
  7638. (find-buffer-visiting (nth 1 rfloc))
  7639. (error "This should not happen")))))
  7640. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7641. redo-at-end t))
  7642. ((equal action ?t)
  7643. (setq state (org-icompleting-read
  7644. "Todo state: "
  7645. (with-current-buffer (marker-buffer (car entries))
  7646. (mapcar 'list org-todo-keywords-1))))
  7647. (setq cmd `(let ((org-inhibit-blocking t)
  7648. (org-inhibit-logging 'note))
  7649. (org-agenda-todo ,state))))
  7650. ((memq action '(?- ?+))
  7651. (setq tag (org-icompleting-read
  7652. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7653. (with-current-buffer (marker-buffer (car entries))
  7654. (delq nil
  7655. (mapcar (lambda (x)
  7656. (if (stringp (car x)) x)) org-tag-alist)))))
  7657. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7658. ((memq action '(?s ?d))
  7659. (let* ((date (unless arg
  7660. (org-read-date
  7661. nil nil nil
  7662. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7663. (ans (if arg nil org-read-date-final-answer))
  7664. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7665. (setq cmd `(let* ((bound (fboundp 'read-string))
  7666. (old (and bound (symbol-function 'read-string))))
  7667. (unwind-protect
  7668. (progn
  7669. (fset 'read-string (lambda (&rest ignore) ,ans))
  7670. (eval '(,c1 arg)))
  7671. (if bound
  7672. (fset 'read-string old)
  7673. (fmakunbound 'read-string)))))))
  7674. ((equal action ?S)
  7675. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7676. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7677. (let ((days (read-number
  7678. (format "Scatter tasks across how many %sdays: "
  7679. (if arg "week" "")) 7)))
  7680. (setq cmd
  7681. `(let ((distance (1+ (random ,days))))
  7682. (if arg
  7683. (let ((dist distance)
  7684. (day-of-week
  7685. (calendar-day-of-week
  7686. (calendar-gregorian-from-absolute (org-today)))))
  7687. (dotimes (i (1+ dist))
  7688. (while (member day-of-week org-agenda-weekend-days)
  7689. (incf distance)
  7690. (incf day-of-week)
  7691. (if (= day-of-week 7)
  7692. (setq day-of-week 0)))
  7693. (incf day-of-week)
  7694. (if (= day-of-week 7)
  7695. (setq day-of-week 0)))))
  7696. ;; silently fail when try to replan a sexp entry
  7697. (condition-case nil
  7698. (let* ((date (calendar-gregorian-from-absolute
  7699. (+ (org-today) distance)))
  7700. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7701. (nth 2 date))))
  7702. (org-agenda-schedule nil time))
  7703. (error nil)))))))
  7704. ((assoc action org-agenda-bulk-custom-functions)
  7705. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7706. redo-at-end t))
  7707. ((equal action ?f)
  7708. (setq cmd (list (intern
  7709. (org-icompleting-read "Function: "
  7710. obarray 'fboundp t nil nil)))))
  7711. (t (error "Invalid bulk action")))
  7712. ;; Sort the markers, to make sure that parents are handled before children
  7713. (setq entries (sort entries
  7714. (lambda (a b)
  7715. (cond
  7716. ((equal (marker-buffer a) (marker-buffer b))
  7717. (< (marker-position a) (marker-position b)))
  7718. (t
  7719. (string< (buffer-name (marker-buffer a))
  7720. (buffer-name (marker-buffer b))))))))
  7721. ;; Now loop over all markers and apply cmd
  7722. (while (setq e (pop entries))
  7723. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7724. (if (not pos)
  7725. (progn (message "Skipping removed entry at %s" e)
  7726. (setq cntskip (1+ cntskip)))
  7727. (goto-char pos)
  7728. (eval cmd)
  7729. (setq org-agenda-bulk-marked-entries
  7730. (delete e org-agenda-bulk-marked-entries))
  7731. (setq cnt (1+ cnt))))
  7732. (setq org-agenda-bulk-marked-entries nil)
  7733. (org-agenda-bulk-remove-all-marks)
  7734. (when redo-at-end (org-agenda-redo))
  7735. (message "Acted on %d entries%s"
  7736. cnt
  7737. (if (= cntskip 0)
  7738. ""
  7739. (format ", skipped %d (disappeared before their turn)"
  7740. cntskip)))))
  7741. ;;; Flagging notes
  7742. (defun org-agenda-show-the-flagging-note ()
  7743. "Display the flagging note in the other window.
  7744. When called a second time in direct sequence, offer to remove the FLAGGING
  7745. tag and (if present) the flagging note."
  7746. (interactive)
  7747. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7748. (win (selected-window))
  7749. note heading newhead)
  7750. (unless hdmarker
  7751. (error "No linked entry at point"))
  7752. (if (and (eq this-command last-command)
  7753. (y-or-n-p "Unflag and remove any flagging note? "))
  7754. (progn
  7755. (org-agenda-remove-flag hdmarker)
  7756. (let ((win (get-buffer-window "*Flagging Note*")))
  7757. (and win (delete-window win)))
  7758. (message "Entry unflaged"))
  7759. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7760. (unless note
  7761. (error "No flagging note"))
  7762. (org-kill-new note)
  7763. (org-switch-to-buffer-other-window "*Flagging Note*")
  7764. (erase-buffer)
  7765. (insert note)
  7766. (goto-char (point-min))
  7767. (while (re-search-forward "\\\\n" nil t)
  7768. (replace-match "\n" t t))
  7769. (goto-char (point-min))
  7770. (select-window win)
  7771. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7772. (defun org-agenda-remove-flag (marker)
  7773. "Remove the FLAGGED tag and any flagging note in the entry."
  7774. (let (newhead)
  7775. (org-with-point-at marker
  7776. (org-toggle-tag "FLAGGED" 'off)
  7777. (org-entry-delete nil "THEFLAGGINGNOTE")
  7778. (setq newhead (org-get-heading)))
  7779. (org-agenda-change-all-lines newhead marker)
  7780. (message "Entry unflaged")))
  7781. (defun org-agenda-get-any-marker (&optional pos)
  7782. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7783. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7784. ;;; Appointment reminders
  7785. (defvar appt-time-msg-list)
  7786. ;;;###autoload
  7787. (defun org-agenda-to-appt (&optional refresh filter)
  7788. "Activate appointments found in `org-agenda-files'.
  7789. With a \\[universal-argument] prefix, refresh the list of
  7790. appointments.
  7791. If FILTER is t, interactively prompt the user for a regular
  7792. expression, and filter out entries that don't match it.
  7793. If FILTER is a string, use this string as a regular expression
  7794. for filtering entries out.
  7795. FILTER can also be an alist with the car of each cell being
  7796. either 'headline or 'category. For example:
  7797. '((headline \"IMPORTANT\")
  7798. (category \"Work\"))
  7799. will only add headlines containing IMPORTANT or headlines
  7800. belonging to the \"Work\" category."
  7801. (interactive "P")
  7802. (if refresh (setq appt-time-msg-list nil))
  7803. (if (eq filter t)
  7804. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7805. (let* ((cnt 0) ; count added events
  7806. (org-agenda-new-buffers nil)
  7807. (org-deadline-warning-days 0)
  7808. ;; Do not use `org-today' here because appt only takes
  7809. ;; time and without date as argument, so it may pass wrong
  7810. ;; information otherwise
  7811. (today (org-date-to-gregorian
  7812. (time-to-days (current-time))))
  7813. (org-agenda-restrict nil)
  7814. (files (org-agenda-files 'unrestricted)) entries file)
  7815. ;; Get all entries which may contain an appt
  7816. (org-prepare-agenda-buffers files)
  7817. (while (setq file (pop files))
  7818. (setq entries
  7819. (append entries
  7820. (org-agenda-get-day-entries
  7821. file today :timestamp :scheduled :deadline))))
  7822. (setq entries (delq nil entries))
  7823. ;; Map thru entries and find if we should filter them out
  7824. (mapc
  7825. (lambda(x)
  7826. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7827. (cat (get-text-property 1 'org-category x))
  7828. (tod (get-text-property 1 'time-of-day x))
  7829. (ok (or (null filter)
  7830. (and (stringp filter) (string-match filter evt))
  7831. (and (listp filter)
  7832. (or (string-match
  7833. (cadr (assoc 'category filter)) cat)
  7834. (string-match
  7835. (cadr (assoc 'headline filter)) evt))))))
  7836. ;; FIXME: Shall we remove text-properties for the appt text?
  7837. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7838. (when (and ok tod)
  7839. (setq tod (concat "00" (number-to-string tod))
  7840. tod (when (string-match
  7841. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7842. (concat (match-string 1 tod) ":"
  7843. (match-string 2 tod))))
  7844. (appt-add tod evt)
  7845. (setq cnt (1+ cnt))))) entries)
  7846. (org-release-buffers org-agenda-new-buffers)
  7847. (if (eq cnt 0)
  7848. (message "No event to add")
  7849. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7850. (defun org-agenda-todayp (date)
  7851. "Does DATE mean today, when considering `org-extend-today-until'?"
  7852. (let ((today (org-today))
  7853. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7854. date)))
  7855. (eq date today)))
  7856. (provide 'org-agenda)
  7857. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7858. ;;; org-agenda.el ends here