org-agenda.el 312 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193
  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.4
  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. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defcustom org-agenda-skip-function-global nil
  472. "Function to be called at each match during agenda construction.
  473. If this function returns nil, the current match should not be skipped.
  474. If the function decided to skip an agenda match, is must return the
  475. buffer position from which the search should be continued.
  476. This may also be a Lisp form, which will be evaluated.
  477. This variable will be applied to every agenda match, including
  478. tags/property searches and TODO lists. So try to make the test function
  479. do its checking as efficiently as possible. To implement a skipping
  480. condition just for specific agenda commands, use the variable
  481. `org-agenda-skip-function' which can be set in the options section
  482. of custom agenda commands."
  483. :group 'org-agenda-skip
  484. :type 'sexp)
  485. (defgroup org-agenda-daily/weekly nil
  486. "Options concerning the daily/weekly agenda."
  487. :tag "Org Agenda Daily/Weekly"
  488. :group 'org-agenda)
  489. (defgroup org-agenda-todo-list nil
  490. "Options concerning the global todo list agenda view."
  491. :tag "Org Agenda Todo List"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-match-view nil
  494. "Options concerning the general tags/property/todo match agenda view."
  495. :tag "Org Agenda Match View"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-search-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defvar org-agenda-archives-mode nil
  502. "Non-nil means the agenda will include archived items.
  503. If this is the symbol `trees', trees in the selected agenda scope
  504. that are marked with the ARCHIVE tag will be included anyway. When this is
  505. t, also all archive files associated with the current selection of agenda
  506. files will be included.")
  507. (defcustom org-agenda-skip-comment-trees t
  508. "Non-nil means skip trees that start with the COMMENT keyword.
  509. When nil, these trees are also scanned by agenda commands."
  510. :group 'org-agenda-skip
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-list-sublevels t
  513. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  514. When nil, the sublevels of a TODO entry are not checked, resulting in
  515. potentially much shorter TODO lists."
  516. :group 'org-agenda-skip
  517. :group 'org-agenda-todo-list
  518. :type 'boolean)
  519. (defcustom org-agenda-todo-ignore-with-date nil
  520. "Non-nil means don't show entries with a date in the global todo list.
  521. You can use this if you prefer to mark mere appointments with a TODO keyword,
  522. but don't want them to show up in the TODO list.
  523. When this is set, it also covers deadlines and scheduled items, the settings
  524. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  525. will be ignored.
  526. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type 'boolean)
  530. (defcustom org-agenda-todo-ignore-timestamp nil
  531. "Non-nil means don't show entries with a timestamp.
  532. This applies when creating the global todo list.
  533. Valid values are:
  534. past Don't show entries for today or in the past.
  535. future Don't show entries with a timestamp in the future.
  536. The idea behind this is that if it has a future
  537. timestamp, you don't want to think about it until the
  538. date.
  539. all Don't show any entries with a timestamp in the global todo list.
  540. The idea behind this is that by setting a timestamp, you
  541. have already \"taken care\" of this item.
  542. This variable can also have an integer as a value. If positive (N),
  543. todos with a timestamp N or more days in the future will be ignored. If
  544. negative (-N), todos with a timestamp N or more days in the past will be
  545. ignored. If 0, todos with a timestamp either today or in the future will
  546. be ignored. For example, a value of -1 will exclude todos with a
  547. timestamp in the past (yesterday or earlier), while a value of 7 will
  548. exclude todos with a timestamp a week or more in the future.
  549. See also `org-agenda-todo-ignore-with-date'.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  551. to make his option also apply to the tags-todo list."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type '(choice
  555. (const :tag "Ignore future timestamp todos" future)
  556. (const :tag "Ignore past or present timestamp todos" past)
  557. (const :tag "Ignore all timestamp todos" all)
  558. (const :tag "Show timestamp todos" nil)
  559. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  560. (defcustom org-agenda-todo-ignore-scheduled nil
  561. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  562. This applies when creating the global todo list.
  563. Valid values are:
  564. past Don't show entries scheduled today or in the past.
  565. future Don't show entries scheduled in the future.
  566. The idea behind this is that by scheduling it, you don't want to
  567. think about it until the scheduled date.
  568. all Don't show any scheduled entries in the global todo list.
  569. The idea behind this is that by scheduling it, you have already
  570. \"taken care\" of this item.
  571. t Same as `all', for backward compatibility.
  572. This variable can also have an integer as a value. See
  573. `org-agenda-todo-ignore-timestamp' for more details.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future-scheduled todos" future)
  581. (const :tag "Ignore past- or present-scheduled todos" past)
  582. (const :tag "Ignore all scheduled todos" all)
  583. (const :tag "Ignore all scheduled todos (compatibility)" t)
  584. (const :tag "Show scheduled todos" nil)
  585. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  586. (defcustom org-agenda-todo-ignore-deadlines nil
  587. "Non-nil means ignore some deadlined TODO items when making TODO list.
  588. There are different motivations for using different values, please think
  589. carefully when configuring this variable.
  590. This applies when creating the global todo list.
  591. Valid values are:
  592. near Don't show near deadline entries. A deadline is near when it is
  593. closer than `org-deadline-warning-days' days. The idea behind this
  594. is that such items will appear in the agenda anyway.
  595. far Don't show TODO entries where a deadline has been defined, but
  596. the deadline is not near. This is useful if you don't want to
  597. use the todo list to figure out what to do now.
  598. past Don't show entries with a deadline timestamp for today or in the past.
  599. future Don't show entries with a deadline timestamp in the future, not even
  600. when they become `near' ones. Use it with caution.
  601. all Ignore all TODO entries that do have a deadline.
  602. t Same as `near', for backward compatibility.
  603. This variable can also have an integer as a value. See
  604. `org-agenda-todo-ignore-timestamp' for more details.
  605. See also `org-agenda-todo-ignore-with-date'.
  606. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  607. to make his option also apply to the tags-todo list."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type '(choice
  611. (const :tag "Ignore near deadlines" near)
  612. (const :tag "Ignore near deadlines (compatibility)" t)
  613. (const :tag "Ignore far deadlines" far)
  614. (const :tag "Ignore all TODOs with a deadlines" all)
  615. (const :tag "Show all TODOs, even if they have a deadline" nil)
  616. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  617. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  618. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  619. The variables
  620. `org-agenda-todo-ignore-with-date',
  621. `org-agenda-todo-ignore-timestamp',
  622. `org-agenda-todo-ignore-scheduled',
  623. `org-agenda-todo-ignore-deadlines'
  624. make the global TODO list skip entries that have time stamps of certain
  625. kinds. If this option is set, the same options will also apply for the
  626. tags-todo search, which is the general tags/property matcher
  627. restricted to unfinished TODO entries only."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :group 'org-agenda-match-view
  631. :type 'boolean)
  632. (defcustom org-agenda-skip-scheduled-if-done nil
  633. "Non-nil means don't show scheduled items in agenda when they are done.
  634. This is relevant for the daily/weekly agenda, not for the TODO list. And
  635. it applies only to the actual date of the scheduling. Warnings about
  636. an item with a past scheduling dates are always turned off when the item
  637. is DONE."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-daily/weekly
  640. :type 'boolean)
  641. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  642. "Non-nil means skip scheduling line if same entry shows because of deadline.
  643. In the agenda of today, an entry can show up multiple times because
  644. it is both scheduled and has a nearby deadline, and maybe a plain time
  645. stamp as well.
  646. When this variable is t, then only the deadline is shown and the fact that
  647. the entry is scheduled today or was scheduled previously is not shown.
  648. When this variable is nil, the entry will be shown several times. When
  649. the variable is the symbol `not-today', then skip scheduled previously,
  650. but not scheduled today."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-daily/weekly
  653. :type '(choice
  654. (const :tag "Never" nil)
  655. (const :tag "Always" t)
  656. (const :tag "Not when scheduled today" not-today)))
  657. (defcustom org-agenda-skip-deadline-if-done nil
  658. "Non-nil means don't show deadlines when the corresponding item is done.
  659. When nil, the deadline is still shown and should give you a happy feeling.
  660. This is relevant for the daily/weekly agenda. And it applied only to the
  661. actually date of the deadline. Warnings about approaching and past-due
  662. deadlines are always turned off when the item is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  667. "Non-nil means skip deadline prewarning when entry is also scheduled.
  668. This will apply on all days where a prewarning for the deadline would
  669. be shown, but not at the day when the entry is actually due. On that day,
  670. the deadline will be shown anyway.
  671. This variable may be set to nil, t, or a number which will then give
  672. the number of days before the actual deadline when the prewarnings
  673. should resume.
  674. This can be used in a workflow where the first showing of the deadline will
  675. trigger you to schedule it, and then you don't want to be reminded of it
  676. because you will take care of it on the day when scheduled."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-daily/weekly
  679. :type '(choice
  680. (const :tag "Alwas show prewarning" nil)
  681. (const :tag "Remove prewarning if entry is scheduled" t)
  682. (integer :tag "Restart prewarning N days before deadline")))
  683. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  684. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  685. When non-nil, after the search for timestamps has matched once in an
  686. entry, the rest of the entry will not be searched."
  687. :group 'org-agenda-skip
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-timestamp-if-done nil
  690. "Non-nil means don't select item by timestamp or -range if it is DONE."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-daily/weekly
  693. :type 'boolean)
  694. (defcustom org-agenda-dim-blocked-tasks t
  695. "Non-nil means dim blocked tasks in the agenda display.
  696. This causes some overhead during agenda construction, but if you
  697. have turned on `org-enforce-todo-dependencies',
  698. `org-enforce-todo-checkbox-dependencies', or any other blocking
  699. mechanism, this will create useful feedback in the agenda.
  700. Instead of t, this variable can also have the value `invisible'.
  701. Then blocked tasks will be invisible and only become visible when
  702. they become unblocked. An exemption to this behavior is when a task is
  703. blocked because of unchecked checkboxes below it. Since checkboxes do
  704. not show up in the agenda views, making this task invisible you remove any
  705. trace from agenda views that there is something to do. Therefore, a task
  706. that is blocked because of checkboxes will never be made invisible, it
  707. will only be dimmed."
  708. :group 'org-agenda-daily/weekly
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Do not dim" nil)
  712. (const :tag "Dim to a grey face" t)
  713. (const :tag "Make invisible" invisible)))
  714. (defcustom org-timeline-show-empty-dates 3
  715. "Non-nil means `org-timeline' also shows dates without an entry.
  716. When nil, only the days which actually have entries are shown.
  717. When t, all days between the first and the last date are shown.
  718. When an integer, show also empty dates, but if there is a gap of more than
  719. N days, just insert a special line indicating the size of the gap."
  720. :group 'org-agenda-skip
  721. :type '(choice
  722. (const :tag "None" nil)
  723. (const :tag "All" t)
  724. (integer :tag "at most")))
  725. (defgroup org-agenda-startup nil
  726. "Options concerning initial settings in the Agenda in Org Mode."
  727. :tag "Org Agenda Startup"
  728. :group 'org-agenda)
  729. (defcustom org-agenda-menu-show-matcher t
  730. "Non-nil means show the match string in the agenda dispatcher menu.
  731. When nil, the matcher string is not shown, but is put into the help-echo
  732. property so than moving the mouse over the command shows it.
  733. Setting it to nil is good if matcher strings are very long and/or if
  734. you want to use two-column display (see `org-agenda-menu-two-column')."
  735. :group 'org-agenda
  736. :type 'boolean)
  737. (defcustom org-agenda-menu-two-column nil
  738. "Non-nil means, use two columns to show custom commands in the dispatcher.
  739. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  740. to nil."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-finalize-agenda-hook nil
  744. "Hook run just before displaying an agenda buffer."
  745. :group 'org-agenda-startup
  746. :type 'hook)
  747. (defcustom org-agenda-mouse-1-follows-link nil
  748. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  749. A longer mouse click will still set point. Does not work on XEmacs.
  750. Needs to be set before org.el is loaded."
  751. :group 'org-agenda-startup
  752. :type 'boolean)
  753. (defcustom org-agenda-start-with-follow-mode nil
  754. "The initial value of follow mode in a newly created agenda window."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-show-outline-path t
  758. "Non-nil means show outline path in echo area after line motion."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-start-with-entry-text-mode nil
  762. "The initial value of entry-text-mode in a newly created agenda window."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-entry-text-maxlines 5
  766. "Number of text lines to be added when `E' is pressed in the agenda.
  767. Note that this variable only used during agenda display. Add add entry text
  768. when exporting the agenda, configure the variable
  769. `org-agenda-add-entry-ext-maxlines'."
  770. :group 'org-agenda
  771. :type 'integer)
  772. (defcustom org-agenda-entry-text-exclude-regexps nil
  773. "List of regular expressions to clean up entry text.
  774. The complete matches of all regular expressions in this list will be
  775. removed from entry text before it is shown in the agenda."
  776. :group 'org-agenda
  777. :type '(repeat (regexp)))
  778. (defvar org-agenda-entry-text-cleanup-hook nil
  779. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  780. This cleanup is done in a temporary buffer, so the function may inspect and
  781. change the entire buffer.
  782. Some default stuff like drawers and scheduling/deadline dates will already
  783. have been removed when this is called, as will any matches for regular
  784. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  785. (defvar org-agenda-include-inactive-timestamps nil
  786. "Non-nil means include inactive time stamps in agenda and timeline.")
  787. (defgroup org-agenda-windows nil
  788. "Options concerning the windows used by the Agenda in Org Mode."
  789. :tag "Org Agenda Windows"
  790. :group 'org-agenda)
  791. (defcustom org-agenda-window-setup 'reorganize-frame
  792. "How the agenda buffer should be displayed.
  793. Possible values for this option are:
  794. current-window Show agenda in the current window, keeping all other windows.
  795. other-window Use `switch-to-buffer-other-window' to display agenda.
  796. reorganize-frame Show only two windows on the current frame, the current
  797. window and the agenda.
  798. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  799. Also, when exiting the agenda, kill that frame.
  800. See also the variable `org-agenda-restore-windows-after-quit'."
  801. :group 'org-agenda-windows
  802. :type '(choice
  803. (const current-window)
  804. (const other-frame)
  805. (const other-window)
  806. (const reorganize-frame)))
  807. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  808. "The min and max height of the agenda window as a fraction of frame height.
  809. The value of the variable is a cons cell with two numbers between 0 and 1.
  810. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  811. :group 'org-agenda-windows
  812. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  813. (defcustom org-agenda-restore-windows-after-quit nil
  814. "Non-nil means restore window configuration open exiting agenda.
  815. Before the window configuration is changed for displaying the agenda,
  816. the current status is recorded. When the agenda is exited with
  817. `q' or `x' and this option is set, the old state is restored. If
  818. `org-agenda-window-setup' is `other-frame', the value of this
  819. option will be ignored."
  820. :group 'org-agenda-windows
  821. :type 'boolean)
  822. (defcustom org-agenda-ndays nil
  823. "Number of days to include in overview display.
  824. Should be 1 or 7.
  825. Obsolete, see `org-agenda-span'."
  826. :group 'org-agenda-daily/weekly
  827. :type 'integer)
  828. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  829. (defcustom org-agenda-span 'week
  830. "Number of days to include in overview display.
  831. Can be day, week, month, year, or any number of days.
  832. Custom commands can set this variable in the options section."
  833. :group 'org-agenda-daily/weekly
  834. :type '(choice (const :tag "Day" day)
  835. (const :tag "Week" week)
  836. (const :tag "Month" month)
  837. (const :tag "Year" year)
  838. (integer :tag "Custom")))
  839. (defcustom org-agenda-start-on-weekday 1
  840. "Non-nil means start the overview always on the specified weekday.
  841. 0 denotes Sunday, 1 denotes Monday etc.
  842. When nil, always start on the current day.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type '(choice (const :tag "Today" nil)
  846. (integer :tag "Weekday No.")))
  847. (defcustom org-agenda-show-all-dates t
  848. "Non-nil means `org-agenda' shows every day in the selected range.
  849. When nil, only the days which actually have entries are shown."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  853. "Format string for displaying dates in the agenda.
  854. Used by the daily/weekly agenda and by the timeline. This should be
  855. a format string understood by `format-time-string', or a function returning
  856. the formatted date as a string. The function must take a single argument,
  857. a calendar-style date list like (month day year)."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice
  860. (string :tag "Format string")
  861. (function :tag "Function")))
  862. (defun org-agenda-format-date-aligned (date)
  863. "Format a date string for display in the daily/weekly agenda, or timeline.
  864. This function makes sure that dates are aligned for easy reading."
  865. (require 'cal-iso)
  866. (let* ((dayname (calendar-day-name date))
  867. (day (cadr date))
  868. (day-of-week (calendar-day-of-week date))
  869. (month (car date))
  870. (monthname (calendar-month-name month))
  871. (year (nth 2 date))
  872. (iso-week (org-days-to-iso-week
  873. (calendar-absolute-from-gregorian date)))
  874. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  875. (1- year))
  876. ((and (= month 12) (<= iso-week 1))
  877. (1+ year))
  878. (t year)))
  879. (weekstring (if (= day-of-week 1)
  880. (format " W%02d" iso-week)
  881. "")))
  882. (format "%-10s %2d %s %4d%s"
  883. dayname day monthname year weekstring)))
  884. (defcustom org-agenda-time-leading-zero nil
  885. "Non-nil means use leading zero for military times in agenda.
  886. For example, 9:30am would become 09:30 rather than 9:30."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-timegrid-use-ampm nil
  890. "When set, show AM/PM style timestamps on the timegrid."
  891. :group 'org-agenda
  892. :type 'boolean)
  893. (defun org-agenda-time-of-day-to-ampm (time)
  894. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  895. (let* ((hour-number (string-to-number (substring time 0 -3)))
  896. (minute (substring time -2))
  897. (ampm "am"))
  898. (cond
  899. ((equal hour-number 12)
  900. (setq ampm "pm"))
  901. ((> hour-number 12)
  902. (setq ampm "pm")
  903. (setq hour-number (- hour-number 12))))
  904. (concat
  905. (if org-agenda-time-leading-zero
  906. (format "%02d" hour-number)
  907. (format "%02s" (number-to-string hour-number)))
  908. ":" minute ampm)))
  909. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  910. "Conditionally convert TIME to AM/PM format
  911. based on `org-agenda-timegrid-use-ampm'"
  912. (if org-agenda-timegrid-use-ampm
  913. (org-agenda-time-of-day-to-ampm time)
  914. time))
  915. (defcustom org-agenda-weekend-days '(6 0)
  916. "Which days are weekend?
  917. These days get the special face `org-agenda-date-weekend' in the agenda
  918. and timeline buffers."
  919. :group 'org-agenda-daily/weekly
  920. :type '(set :greedy t
  921. (const :tag "Monday" 1)
  922. (const :tag "Tuesday" 2)
  923. (const :tag "Wednesday" 3)
  924. (const :tag "Thursday" 4)
  925. (const :tag "Friday" 5)
  926. (const :tag "Saturday" 6)
  927. (const :tag "Sunday" 0)))
  928. (defcustom org-agenda-include-diary nil
  929. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  930. Custom commands can set this variable in the options section."
  931. :group 'org-agenda-daily/weekly
  932. :type 'boolean)
  933. (defcustom org-agenda-include-deadlines t
  934. "If non-nil, include entries within their deadline warning period.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type 'boolean)
  938. (defcustom org-agenda-include-all-todo nil
  939. "Set means weekly/daily agenda will always contain all TODO entries.
  940. The TODO entries will be listed at the top of the agenda, before
  941. the entries for specific days.
  942. This option is deprecated, it is better to define a block agenda instead."
  943. :group 'org-agenda-daily/weekly
  944. :type 'boolean)
  945. (defcustom org-agenda-repeating-timestamp-show-all t
  946. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  947. When set to a list of strings, only show occurrences of repeating
  948. stamps for these TODO keywords. When nil, only one occurrence is
  949. shown, either today or the nearest into the future."
  950. :group 'org-agenda-daily/weekly
  951. :type '(choice
  952. (const :tag "Show repeating stamps" t)
  953. (repeat :tag "Show repeating stamps for these TODO keywords"
  954. (string :tag "TODO Keyword"))
  955. (const :tag "Don't show repeating stamps" nil)))
  956. (defcustom org-scheduled-past-days 10000
  957. "No. of days to continue listing scheduled items that are not marked DONE.
  958. When an item is scheduled on a date, it shows up in the agenda on this
  959. day and will be listed until it is marked done for the number of days
  960. given here."
  961. :group 'org-agenda-daily/weekly
  962. :type 'integer)
  963. (defcustom org-agenda-log-mode-items '(closed clock)
  964. "List of items that should be shown in agenda log mode.
  965. This list may contain the following symbols:
  966. closed Show entries that have been closed on that day.
  967. clock Show entries that have received clocked time on that day.
  968. state Show all logged state changes.
  969. Note that instead of changing this variable, you can also press `C-u l' in
  970. the agenda to display all available LOG items temporarily."
  971. :group 'org-agenda-daily/weekly
  972. :type '(set :greedy t (const closed) (const clock) (const state)))
  973. (defcustom org-agenda-log-mode-add-notes t
  974. "Non-nil means add first line of notes to log entries in agenda views.
  975. If a log item like a state change or a clock entry is associated with
  976. notes, the first line of these notes will be added to the entry in the
  977. agenda display."
  978. :group 'org-agenda-daily/weekly
  979. :type 'boolean)
  980. (defcustom org-agenda-start-with-log-mode nil
  981. "The initial value of log-mode in a newly created agenda window."
  982. :group 'org-agenda-startup
  983. :group 'org-agenda-daily/weekly
  984. :type 'boolean)
  985. (defcustom org-agenda-start-with-clockreport-mode nil
  986. "The initial value of clockreport-mode in a newly created agenda window."
  987. :group 'org-agenda-startup
  988. :group 'org-agenda-daily/weekly
  989. :type 'boolean)
  990. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  991. "Property list with parameters for the clocktable in clockreport mode.
  992. This is the display mode that shows a clock table in the daily/weekly
  993. agenda, the properties for this dynamic block can be set here.
  994. The usual clocktable parameters are allowed here, but you cannot set
  995. the properties :name, :tstart, :tend, :block, and :scope - these will
  996. be overwritten to make sure the content accurately reflects the
  997. current display in the agenda."
  998. :group 'org-agenda-daily/weekly
  999. :type 'plist)
  1000. (defcustom org-agenda-search-view-always-boolean nil
  1001. "Non-nil means the search string is interpreted as individual parts.
  1002. The search string for search view can either be interpreted as a phrase,
  1003. or as a list of snippets that define a boolean search for a number of
  1004. strings.
  1005. When this is non-nil, the string will be split on whitespace, and each
  1006. snippet will be searched individually, and all must match in order to
  1007. select an entry. A snippet is then a single string of non-white
  1008. characters, or a string in double quotes, or a regexp in {} braces.
  1009. If a snippet is preceded by \"-\", the snippet must *not* match.
  1010. \"+\" is syntactic sugar for positive selection. Each snippet may
  1011. be found as a full word or a partial word, but see the variable
  1012. `org-agenda-search-view-force-full-words'.
  1013. When this is nil, search will look for the entire search phrase as one,
  1014. with each space character matching any amount of whitespace, including
  1015. line breaks.
  1016. Even when this is nil, you can still switch to Boolean search dynamically
  1017. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1018. is a regexp marked with braces like \"{abc}\", this will also switch to
  1019. boolean search."
  1020. :group 'org-agenda-search-view
  1021. :type 'boolean)
  1022. (if (fboundp 'defvaralias)
  1023. (defvaralias 'org-agenda-search-view-search-words-only
  1024. 'org-agenda-search-view-always-boolean))
  1025. (defcustom org-agenda-search-view-force-full-words nil
  1026. "Non-nil means, search words must be matches as complete words.
  1027. When nil, they may also match part of a word."
  1028. :group 'org-agenda-search-view
  1029. :type 'boolean)
  1030. (defgroup org-agenda-time-grid nil
  1031. "Options concerning the time grid in the Org-mode Agenda."
  1032. :tag "Org Agenda Time Grid"
  1033. :group 'org-agenda)
  1034. (defcustom org-agenda-search-headline-for-time t
  1035. "Non-nil means search headline for a time-of-day.
  1036. If the headline contains a time-of-day in one format or another, it will
  1037. be used to sort the entry into the time sequence of items for a day.
  1038. Some people have time stamps in the headline that refer to the creation
  1039. time or so, and then this produces an unwanted side effect. If this is
  1040. the case for your, use this variable to turn off searching the headline
  1041. for a time."
  1042. :group 'org-agenda-time-grid
  1043. :type 'boolean)
  1044. (defcustom org-agenda-use-time-grid t
  1045. "Non-nil means show a time grid in the agenda schedule.
  1046. A time grid is a set of lines for specific times (like every two hours between
  1047. 8:00 and 20:00). The items scheduled for a day at specific times are
  1048. sorted in between these lines.
  1049. For details about when the grid will be shown, and what it will look like, see
  1050. the variable `org-agenda-time-grid'."
  1051. :group 'org-agenda-time-grid
  1052. :type 'boolean)
  1053. (defcustom org-agenda-time-grid
  1054. '((daily today require-timed)
  1055. "----------------"
  1056. (800 1000 1200 1400 1600 1800 2000))
  1057. "The settings for time grid for agenda display.
  1058. This is a list of three items. The first item is again a list. It contains
  1059. symbols specifying conditions when the grid should be displayed:
  1060. daily if the agenda shows a single day
  1061. weekly if the agenda shows an entire week
  1062. today show grid on current date, independent of daily/weekly display
  1063. require-timed show grid only if at least one item has a time specification
  1064. The second item is a string which will be placed behind the grid time.
  1065. The third item is a list of integers, indicating the times that should have
  1066. a grid line."
  1067. :group 'org-agenda-time-grid
  1068. :type
  1069. '(list
  1070. (set :greedy t :tag "Grid Display Options"
  1071. (const :tag "Show grid in single day agenda display" daily)
  1072. (const :tag "Show grid in weekly agenda display" weekly)
  1073. (const :tag "Always show grid for today" today)
  1074. (const :tag "Show grid only if any timed entries are present"
  1075. require-timed)
  1076. (const :tag "Skip grid times already present in an entry"
  1077. remove-match))
  1078. (string :tag "Grid String")
  1079. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1080. (defcustom org-agenda-show-current-time-in-grid t
  1081. "Non-nil means show the current time in the time grid."
  1082. :group 'org-agenda-time-grid
  1083. :type 'boolean)
  1084. (defcustom org-agenda-current-time-string
  1085. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1086. "The string for the current time marker in the agenda."
  1087. :group 'org-agenda-time-grid
  1088. :type 'string)
  1089. (defgroup org-agenda-sorting nil
  1090. "Options concerning sorting in the Org-mode Agenda."
  1091. :tag "Org Agenda Sorting"
  1092. :group 'org-agenda)
  1093. (defcustom org-agenda-sorting-strategy
  1094. '((agenda habit-down time-up priority-down category-keep)
  1095. (todo priority-down category-keep)
  1096. (tags priority-down category-keep)
  1097. (search category-keep))
  1098. "Sorting structure for the agenda items of a single day.
  1099. This is a list of symbols which will be used in sequence to determine
  1100. if an entry should be listed before another entry. The following
  1101. symbols are recognized:
  1102. time-up Put entries with time-of-day indications first, early first
  1103. time-down Put entries with time-of-day indications first, late first
  1104. category-keep Keep the default order of categories, corresponding to the
  1105. sequence in `org-agenda-files'.
  1106. category-up Sort alphabetically by category, A-Z.
  1107. category-down Sort alphabetically by category, Z-A.
  1108. tag-up Sort alphabetically by last tag, A-Z.
  1109. tag-down Sort alphabetically by last tag, Z-A.
  1110. priority-up Sort numerically by priority, high priority last.
  1111. priority-down Sort numerically by priority, high priority first.
  1112. todo-state-up Sort by todo state, tasks that are done last.
  1113. todo-state-down Sort by todo state, tasks that are done first.
  1114. effort-up Sort numerically by estimated effort, high effort last.
  1115. effort-down Sort numerically by estimated effort, high effort first.
  1116. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1117. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1118. habit-up Put entries that are habits first
  1119. habit-down Put entries that are habits last
  1120. alpha-up Sort headlines alphabetically
  1121. alpha-down Sort headlines alphabetically, reversed
  1122. The different possibilities will be tried in sequence, and testing stops
  1123. if one comparison returns a \"not-equal\". For example, the default
  1124. '(time-up category-keep priority-down)
  1125. means: Pull out all entries having a specified time of day and sort them,
  1126. in order to make a time schedule for the current day the first thing in the
  1127. agenda listing for the day. Of the entries without a time indication, keep
  1128. the grouped in categories, don't sort the categories, but keep them in
  1129. the sequence given in `org-agenda-files'. Within each category sort by
  1130. priority.
  1131. Leaving out `category-keep' would mean that items will be sorted across
  1132. categories by priority.
  1133. Instead of a single list, this can also be a set of list for specific
  1134. contents, with a context symbol in the car of the list, any of
  1135. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1136. Custom commands can bind this variable in the options section."
  1137. :group 'org-agenda-sorting
  1138. :type `(choice
  1139. (repeat :tag "General" ,org-sorting-choice)
  1140. (list :tag "Individually"
  1141. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1142. (repeat ,org-sorting-choice))
  1143. (cons (const :tag "Strategy for TODO lists" todo)
  1144. (repeat ,org-sorting-choice))
  1145. (cons (const :tag "Strategy for Tags matches" tags)
  1146. (repeat ,org-sorting-choice))
  1147. (cons (const :tag "Strategy for search matches" search)
  1148. (repeat ,org-sorting-choice)))))
  1149. (defcustom org-agenda-cmp-user-defined nil
  1150. "A function to define the comparison `user-defined'.
  1151. This function must receive two arguments, agenda entry a and b.
  1152. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1153. the user comparison, return nil.
  1154. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1155. part of an agenda sorting strategy."
  1156. :group 'org-agenda-sorting
  1157. :type 'symbol)
  1158. (defcustom org-sort-agenda-notime-is-late t
  1159. "Non-nil means items without time are considered late.
  1160. This is only relevant for sorting. When t, items which have no explicit
  1161. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1162. do have a time. When nil, the default time is before 0:00. You can use this
  1163. option to decide if the schedule for today should come before or after timeless
  1164. agenda entries."
  1165. :group 'org-agenda-sorting
  1166. :type 'boolean)
  1167. (defcustom org-sort-agenda-noeffort-is-high t
  1168. "Non-nil means items without effort estimate are sorted as high effort.
  1169. This also applies when filtering an agenda view with respect to the
  1170. < or > effort operator. Then, tasks with no effort defined will be treated
  1171. as tasks with high effort.
  1172. When nil, such items are sorted as 0 minutes effort."
  1173. :group 'org-agenda-sorting
  1174. :type 'boolean)
  1175. (defgroup org-agenda-line-format nil
  1176. "Options concerning the entry prefix in the Org-mode agenda display."
  1177. :tag "Org Agenda Line Format"
  1178. :group 'org-agenda)
  1179. (defcustom org-agenda-prefix-format
  1180. '((agenda . " %i %-12:c%?-12t% s")
  1181. (timeline . " % s")
  1182. (todo . " %i %-12:c")
  1183. (tags . " %i %-12:c")
  1184. (search . " %i %-12:c"))
  1185. "Format specifications for the prefix of items in the agenda views.
  1186. An alist with four entries, for the different agenda types. The keys to the
  1187. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1188. are format strings.
  1189. This format works similar to a printf format, with the following meaning:
  1190. %c the category of the item, \"Diary\" for entries from the diary, or
  1191. as given by the CATEGORY keyword or derived from the file name.
  1192. %i the icon category of the item, as give in
  1193. `org-agenda-category-icon-alist'.
  1194. %T the *last* tag of the item. Last because inherited tags come
  1195. first in the list.
  1196. %t the time-of-day specification if one applies to the entry, in the
  1197. format HH:MM
  1198. %s Scheduling/Deadline information, a short string
  1199. %(expression) Eval EXPRESSION and replace the control string
  1200. by the result
  1201. All specifiers work basically like the standard `%s' of printf, but may
  1202. contain two additional characters: A question mark just after the `%' and
  1203. a whitespace/punctuation character just before the final letter.
  1204. If the first character after `%' is a question mark, the entire field
  1205. will only be included if the corresponding value applies to the
  1206. current entry. This is useful for fields which should have fixed
  1207. width when present, but zero width when absent. For example,
  1208. \"%?-12t\" will result in a 12 character time field if a time of the
  1209. day is specified, but will completely disappear in entries which do
  1210. not contain a time.
  1211. If there is punctuation or whitespace character just before the final
  1212. format letter, this character will be appended to the field value if
  1213. the value is not empty. For example, the format \"%-12:c\" leads to
  1214. \"Diary: \" if the category is \"Diary\". If the category were be
  1215. empty, no additional colon would be inserted.
  1216. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1217. - Indent the line with two space characters
  1218. - Give the category in a 12 chars wide field, padded with whitespace on
  1219. the right (because of `-'). Append a colon if there is a category
  1220. (because of `:').
  1221. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1222. time, don't put in an empty field, just skip it (because of '?').
  1223. - Finally, put the scheduling information and append a whitespace.
  1224. As another example, if you don't want the time-of-day of entries in
  1225. the prefix, you could use:
  1226. (setq org-agenda-prefix-format \" %-11:c% s\")
  1227. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1228. `org-agenda-remove-tags'.
  1229. Custom commands can set this variable in the options section."
  1230. :type '(choice
  1231. (string :tag "General format")
  1232. (list :greedy t :tag "View dependent"
  1233. (cons (const agenda) (string :tag "Format"))
  1234. (cons (const timeline) (string :tag "Format"))
  1235. (cons (const todo) (string :tag "Format"))
  1236. (cons (const tags) (string :tag "Format"))
  1237. (cons (const search) (string :tag "Format"))))
  1238. :group 'org-agenda-line-format)
  1239. (defvar org-prefix-format-compiled nil
  1240. "The compiled version of the most recently used prefix format.
  1241. See the variable `org-agenda-prefix-format'.")
  1242. (defcustom org-agenda-todo-keyword-format "%-1s"
  1243. "Format for the TODO keyword in agenda lines.
  1244. Set this to something like \"%-12s\" if you want all TODO keywords
  1245. to occupy a fixed space in the agenda display."
  1246. :group 'org-agenda-line-format
  1247. :type 'string)
  1248. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1249. "Text preceding timerange entries in the agenda view.
  1250. This is a list with two strings. The first applies when the range
  1251. is entirely on one day. The second applies if the range spans several days.
  1252. The strings may have two \"%d\" format specifiers which will be filled
  1253. with the sequence number of the days, and the total number of days in the
  1254. range, respectively."
  1255. :group 'org-agenda-line-format
  1256. :type '(list
  1257. (string :tag "Deadline today ")
  1258. (choice :tag "Deadline relative"
  1259. (string :tag "Format string")
  1260. (function))))
  1261. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1262. "Text preceding scheduled items in the agenda view.
  1263. This is a list with two strings. The first applies when the item is
  1264. scheduled on the current day. The second applies when it has been scheduled
  1265. previously, it may contain a %d indicating that this is the nth time that
  1266. this item is scheduled, due to automatic rescheduling of unfinished items
  1267. for the following day. So this number is one larger than the number of days
  1268. that passed since this item was scheduled first."
  1269. :group 'org-agenda-line-format
  1270. :type '(list
  1271. (string :tag "Scheduled today ")
  1272. (string :tag "Scheduled previously")))
  1273. (defcustom org-agenda-inactive-leader "["
  1274. "Text preceding item pulled into the agenda by inactive time stamps.
  1275. These entries are added to the agenda when pressing \"[\"."
  1276. :group 'org-agenda-line-format
  1277. :type '(list
  1278. (string :tag "Scheduled today ")
  1279. (string :tag "Scheduled previously")))
  1280. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1281. "Text preceding deadline items in the agenda view.
  1282. This is a list with two strings. The first applies when the item has its
  1283. deadline on the current day. The second applies when it is in the past or
  1284. in the future, it may contain %d to capture how many days away the deadline
  1285. is (was)."
  1286. :group 'org-agenda-line-format
  1287. :type '(list
  1288. (string :tag "Deadline today ")
  1289. (choice :tag "Deadline relative"
  1290. (string :tag "Format string")
  1291. (function))))
  1292. (defcustom org-agenda-remove-times-when-in-prefix t
  1293. "Non-nil means remove duplicate time specifications in agenda items.
  1294. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1295. time-of-day specification in a headline or diary entry is extracted and
  1296. placed into the prefix. If this option is non-nil, the original specification
  1297. \(a timestamp or -range, or just a plain time(range) specification like
  1298. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1299. cluttered.
  1300. The option can be t or nil. It may also be the symbol `beg', indicating
  1301. that the time should only be removed when it is located at the beginning of
  1302. the headline/diary entry."
  1303. :group 'org-agenda-line-format
  1304. :type '(choice
  1305. (const :tag "Always" t)
  1306. (const :tag "Never" nil)
  1307. (const :tag "When at beginning of entry" beg)))
  1308. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1309. "Non-nil means remove time ranges specifications in agenda
  1310. items that span on several days."
  1311. :group 'org-agenda-line-format
  1312. :type 'boolean)
  1313. (defcustom org-agenda-default-appointment-duration nil
  1314. "Default duration for appointments that only have a starting time.
  1315. When nil, no duration is specified in such cases.
  1316. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1317. :group 'org-agenda-line-format
  1318. :type '(choice
  1319. (integer :tag "Minutes")
  1320. (const :tag "No default duration")))
  1321. (defcustom org-agenda-show-inherited-tags t
  1322. "Non-nil means show inherited tags in each agenda line."
  1323. :group 'org-agenda-line-format
  1324. :type 'boolean)
  1325. (defcustom org-agenda-hide-tags-regexp nil
  1326. "Regular expression used to filter away specific tags in agenda views.
  1327. This means that these tags will be present, but not be shown in the agenda
  1328. line. Secondary filtering will still work on the hidden tags.
  1329. Nil means don't hide any tags."
  1330. :group 'org-agenda-line-format
  1331. :type '(choice
  1332. (const :tag "Hide none" nil)
  1333. (string :tag "Regexp ")))
  1334. (defcustom org-agenda-remove-tags nil
  1335. "Non-nil means remove the tags from the headline copy in the agenda.
  1336. When this is the symbol `prefix', only remove tags when
  1337. `org-agenda-prefix-format' contains a `%T' specifier."
  1338. :group 'org-agenda-line-format
  1339. :type '(choice
  1340. (const :tag "Always" t)
  1341. (const :tag "Never" nil)
  1342. (const :tag "When prefix format contains %T" prefix)))
  1343. (if (fboundp 'defvaralias)
  1344. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1345. 'org-agenda-remove-tags))
  1346. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1347. "Shift tags in agenda items to this column.
  1348. If this number is positive, it specifies the column. If it is negative,
  1349. it means that the tags should be flushright to that column. For example,
  1350. -80 works well for a normal 80 character screen."
  1351. :group 'org-agenda-line-format
  1352. :type 'integer)
  1353. (if (fboundp 'defvaralias)
  1354. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1355. (defcustom org-agenda-fontify-priorities 'cookies
  1356. "Non-nil means highlight low and high priorities in agenda.
  1357. When t, the highest priority entries are bold, lowest priority italic.
  1358. However, settings in `org-priority-faces' will overrule these faces.
  1359. When this variable is the symbol `cookies', only fontify the
  1360. cookies, not the entire task.
  1361. This may also be an association list of priority faces, whose
  1362. keys are the character values of `org-highest-priority',
  1363. `org-default-priority', and `org-lowest-priority' (the default values
  1364. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1365. color as a string, or a list like `(:background \"Red\")'.
  1366. If it is a color, the variable `org-faces-easy-properties'
  1367. determines if it is a foreground or a background color."
  1368. :group 'org-agenda-line-format
  1369. :type '(choice
  1370. (const :tag "Never" nil)
  1371. (const :tag "Defaults" t)
  1372. (const :tag "Cookies only" cookies)
  1373. (repeat :tag "Specify"
  1374. (list (character :tag "Priority" :value ?A)
  1375. (choice :tag "Face "
  1376. (string :tag "Color")
  1377. (sexp :tag "Face"))))))
  1378. (defcustom org-agenda-day-face-function nil
  1379. "Function called to determine what face should be used to display a day.
  1380. The only argument passed to that function is the day. It should
  1381. returns a face, or nil if does not want to specify a face and let
  1382. the normal rules apply."
  1383. :group 'org-agenda-line-format
  1384. :type 'function)
  1385. (defcustom org-agenda-category-icon-alist nil
  1386. "Alist of category icon to be displayed in agenda views.
  1387. Each entry should have the following format:
  1388. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1389. Where CATEGORY-REGEXP is a regexp matching the categories where
  1390. the icon should be displayed.
  1391. FILE-OR-DATA either a file path or a string containing image data.
  1392. The other fields can be omited safely if not needed:
  1393. TYPE indicates the image type.
  1394. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1395. image data.
  1396. PROPS are additional image attributes to assign to the image,
  1397. like, e.g. `:ascent center'.
  1398. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1399. If you want to set the display properties yourself, just put a
  1400. list as second element:
  1401. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1402. For example, to display a 16px horizontal space for Emacs
  1403. category, you can use:
  1404. (\"Emacs\" '(space . (:width (16))))"
  1405. :group 'org-agenda-line-format
  1406. :type '(alist :key-type (string :tag "Regexp matching category")
  1407. :value-type (choice (list :tag "Icon"
  1408. (string :tag "File or data")
  1409. (symbol :tag "Type")
  1410. (boolean :tag "Data?")
  1411. (repeat :tag "Extra image properties" :inline t symbol))
  1412. (list :tag "Display properties" sexp))))
  1413. (defgroup org-agenda-column-view nil
  1414. "Options concerning column view in the agenda."
  1415. :tag "Org Agenda Column View"
  1416. :group 'org-agenda)
  1417. (defcustom org-agenda-columns-show-summaries t
  1418. "Non-nil means show summaries for columns displayed in the agenda view."
  1419. :group 'org-agenda-column-view
  1420. :type 'boolean)
  1421. (defcustom org-agenda-columns-remove-prefix-from-item t
  1422. "Non-nil means remove the prefix from a headline for agenda column view.
  1423. The special ITEM field in the columns format contains the current line, with
  1424. all information shown in other columns (like the TODO state or a tag).
  1425. When this variable is non-nil, also the agenda prefix will be removed from
  1426. the content of the ITEM field, to make sure as much as possible of the
  1427. headline can be shown in the limited width of the field."
  1428. :group 'org-agenda
  1429. :type 'boolean)
  1430. (defcustom org-agenda-columns-compute-summary-properties t
  1431. "Non-nil means recompute all summary properties before column view.
  1432. When column view in the agenda is listing properties that have a summary
  1433. operator, it can go to all relevant buffers and recompute the summaries
  1434. there. This can mean overhead for the agenda column view, but is necessary
  1435. to have thing up to date.
  1436. As a special case, a CLOCKSUM property also makes sure that the clock
  1437. computations are current."
  1438. :group 'org-agenda-column-view
  1439. :type 'boolean)
  1440. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1441. "Non-nil means the duration of an appointment will add to day effort.
  1442. The property to which appointment durations will be added is the one given
  1443. in the option `org-effort-property'. If an appointment does not have
  1444. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1445. is not set, an appointment without end time will not contribute to the time
  1446. estimate."
  1447. :group 'org-agenda-column-view
  1448. :type 'boolean)
  1449. (defcustom org-agenda-auto-exclude-function nil
  1450. "A function called with a tag to decide if it is filtered on '/ RET'.
  1451. The sole argument to the function, which is called once for each
  1452. possible tag, is a string giving the name of the tag. The
  1453. function should return either nil if the tag should be included
  1454. as normal, or \"-<TAG>\" to exclude the tag.
  1455. Note that for the purpose of tag filtering, only the lower-case version of
  1456. all tags will be considered, so that this function will only ever see
  1457. the lower-case version of all tags."
  1458. :group 'org-agenda
  1459. :type 'function)
  1460. (eval-when-compile
  1461. (require 'cl))
  1462. (require 'org)
  1463. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1464. "Execute BODY with point at location given by `org-hd-marker' property.
  1465. If STRING is non-nil, the text property will be fetched from position 0
  1466. in that string. If STRING is nil, it will be fetched from the beginning
  1467. of the current line."
  1468. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1469. 'org-hd-marker string)))
  1470. (with-current-buffer (marker-buffer marker)
  1471. (save-excursion
  1472. (goto-char marker)
  1473. ,@body))))
  1474. (defun org-add-agenda-custom-command (entry)
  1475. "Replace or add a command in `org-agenda-custom-commands'.
  1476. This is mostly for hacking and trying a new command - once the command
  1477. works you probably want to add it to `org-agenda-custom-commands' for good."
  1478. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1479. (if ass
  1480. (setcdr ass (cdr entry))
  1481. (push entry org-agenda-custom-commands))))
  1482. ;;; Define the Org-agenda-mode
  1483. (defvar org-agenda-mode-map (make-sparse-keymap)
  1484. "Keymap for `org-agenda-mode'.")
  1485. (if (fboundp 'defvaralias)
  1486. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1487. (defvar org-agenda-menu) ; defined later in this file.
  1488. (defvar org-agenda-restrict) ; defined later in this file.
  1489. (defvar org-agenda-follow-mode nil)
  1490. (defvar org-agenda-entry-text-mode nil)
  1491. (defvar org-agenda-clockreport-mode nil)
  1492. (defvar org-agenda-show-log nil)
  1493. (defvar org-agenda-redo-command nil)
  1494. (defvar org-agenda-query-string nil)
  1495. (defvar org-agenda-mode-hook nil
  1496. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1497. (defvar org-agenda-type nil)
  1498. (defvar org-agenda-force-single-file nil)
  1499. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1500. (defun org-agenda-mode ()
  1501. "Mode for time-sorted view on action items in Org-mode files.
  1502. The following commands are available:
  1503. \\{org-agenda-mode-map}"
  1504. (interactive)
  1505. (kill-all-local-variables)
  1506. (setq org-agenda-undo-list nil
  1507. org-agenda-pending-undo-list nil
  1508. org-agenda-bulk-marked-entries nil)
  1509. (setq major-mode 'org-agenda-mode)
  1510. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1511. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1512. (setq mode-name "Org-Agenda")
  1513. (use-local-map org-agenda-mode-map)
  1514. (easy-menu-add org-agenda-menu)
  1515. (if org-startup-truncated (setq truncate-lines t))
  1516. (org-set-local 'line-move-visual nil)
  1517. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1518. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1519. ;; Make sure properties are removed when copying text
  1520. (when (boundp 'buffer-substring-filters)
  1521. (org-set-local 'buffer-substring-filters
  1522. (cons (lambda (x)
  1523. (set-text-properties 0 (length x) nil x) x)
  1524. buffer-substring-filters)))
  1525. (unless org-agenda-keep-modes
  1526. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1527. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1528. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1529. org-agenda-show-log org-agenda-start-with-log-mode))
  1530. (easy-menu-change
  1531. '("Agenda") "Agenda Files"
  1532. (append
  1533. (list
  1534. (vector
  1535. (if (get 'org-agenda-files 'org-restrict)
  1536. "Restricted to single file"
  1537. "Edit File List")
  1538. '(org-edit-agenda-file-list)
  1539. (not (get 'org-agenda-files 'org-restrict)))
  1540. "--")
  1541. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1542. (org-agenda-set-mode-name)
  1543. (apply
  1544. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1545. (list 'org-agenda-mode-hook)))
  1546. (substitute-key-definition 'undo 'org-agenda-undo
  1547. org-agenda-mode-map global-map)
  1548. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1549. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1550. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1551. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1552. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1553. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1554. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1555. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1556. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1557. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1558. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1559. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1560. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1561. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1562. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1563. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1564. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1565. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1566. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1567. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1568. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1569. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1570. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1571. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1572. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1573. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1574. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1575. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1576. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1577. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1578. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1579. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1580. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1581. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1582. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1583. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1584. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1585. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1586. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1587. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1588. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1589. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1590. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1591. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1592. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1593. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1595. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1596. (while l (org-defkey org-agenda-mode-map
  1597. (int-to-string (pop l)) 'digit-argument)))
  1598. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1599. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1600. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1601. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1602. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1603. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1604. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1605. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1606. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1607. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1608. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1609. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1611. 'org-clock-modify-effort-estimate)
  1612. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1613. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1614. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1615. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1616. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1617. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1618. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1619. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1620. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1621. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1622. (substitute-key-definition 'next-line 'org-agenda-next-line
  1623. org-agenda-mode-map global-map)
  1624. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1625. org-agenda-mode-map global-map)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1628. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1629. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1630. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1631. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1632. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1633. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1634. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1635. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1636. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1637. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1638. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1639. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1640. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1641. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1642. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1643. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1644. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1645. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1646. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1647. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1648. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1649. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1650. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1651. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1652. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1653. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1654. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1656. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1657. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1658. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1659. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1660. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1661. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1662. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1663. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1664. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1666. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1667. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1668. (when org-agenda-mouse-1-follows-link
  1669. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1670. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1671. '("Agenda"
  1672. ("Agenda Files")
  1673. "--"
  1674. ("Agenda Dates"
  1675. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1676. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1677. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1678. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1679. "--"
  1680. ("View"
  1681. ["Day View" org-agenda-day-view
  1682. :active (org-agenda-check-type nil 'agenda)
  1683. :style radio :selected (eq org-agenda-current-span 'day)
  1684. :keys "v d (or just d)"]
  1685. ["Week View" org-agenda-week-view
  1686. :active (org-agenda-check-type nil 'agenda)
  1687. :style radio :selected (eq org-agenda-current-span 'week)
  1688. :keys "v w (or just w)"]
  1689. ["Month View" org-agenda-month-view
  1690. :active (org-agenda-check-type nil 'agenda)
  1691. :style radio :selected (eq org-agenda-current-span 'month)
  1692. :keys "v m"]
  1693. ["Year View" org-agenda-year-view
  1694. :active (org-agenda-check-type nil 'agenda)
  1695. :style radio :selected (eq org-agenda-current-span 'year)
  1696. :keys "v y"]
  1697. "--"
  1698. ["Include Diary" org-agenda-toggle-diary
  1699. :style toggle :selected org-agenda-include-diary
  1700. :active (org-agenda-check-type nil 'agenda)]
  1701. ["Include Deadlines" org-agenda-toggle-deadlines
  1702. :style toggle :selected org-agenda-include-deadlines
  1703. :active (org-agenda-check-type nil 'agenda)]
  1704. ["Use Time Grid" org-agenda-toggle-time-grid
  1705. :style toggle :selected org-agenda-use-time-grid
  1706. :active (org-agenda-check-type nil 'agenda)]
  1707. "--"
  1708. ["Show clock report" org-agenda-clockreport-mode
  1709. :style toggle :selected org-agenda-clockreport-mode
  1710. :active (org-agenda-check-type nil 'agenda)]
  1711. ["Show some entry text" org-agenda-entry-text-mode
  1712. :style toggle :selected org-agenda-entry-text-mode
  1713. :active t]
  1714. "--"
  1715. ["Show Logbook entries" org-agenda-log-mode
  1716. :style toggle :selected org-agenda-show-log
  1717. :active (org-agenda-check-type nil 'agenda 'timeline)
  1718. :keys "v l (or just l)"]
  1719. ["Include archived trees" org-agenda-archives-mode
  1720. :style toggle :selected org-agenda-archives-mode :active t
  1721. :keys "v a"]
  1722. ["Include archive files" (org-agenda-archives-mode t)
  1723. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1724. :keys "v A"]
  1725. "--"
  1726. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1727. ["Write view to file" org-write-agenda t]
  1728. ["Rebuild buffer" org-agenda-redo t]
  1729. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1730. "--"
  1731. ["Show original entry" org-agenda-show t]
  1732. ["Go To (other window)" org-agenda-goto t]
  1733. ["Go To (this window)" org-agenda-switch-to t]
  1734. ["Follow Mode" org-agenda-follow-mode
  1735. :style toggle :selected org-agenda-follow-mode :active t]
  1736. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1737. "--"
  1738. ("TODO"
  1739. ["Cycle TODO" org-agenda-todo t]
  1740. ["Next TODO set" org-agenda-todo-nextset t]
  1741. ["Previous TODO set" org-agenda-todo-previousset t]
  1742. ["Add note" org-agenda-add-note t])
  1743. ("Archive/Refile/Delete"
  1744. ["Archive default" org-agenda-archive-default t]
  1745. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1746. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1747. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1748. ["Archive subtree" org-agenda-archive t]
  1749. "--"
  1750. ["Refile" org-agenda-refile t]
  1751. "--"
  1752. ["Delete subtree" org-agenda-kill t])
  1753. ("Bulk action"
  1754. ["Mark entry" org-agenda-bulk-mark t]
  1755. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1756. ["Unmark entry" org-agenda-bulk-unmark t]
  1757. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1758. ["Act on all marked" org-agenda-bulk-action t]
  1759. "--"
  1760. ("Tags and Properties"
  1761. ["Show all Tags" org-agenda-show-tags t]
  1762. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1763. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1764. "--"
  1765. ["Column View" org-columns t])
  1766. ("Deadline/Schedule"
  1767. ["Schedule" org-agenda-schedule t]
  1768. ["Set Deadline" org-agenda-deadline t]
  1769. "--"
  1770. ["Mark item" org-agenda-action :active t :keys "k m"]
  1771. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1772. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1773. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1774. "--"
  1775. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1776. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1777. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1778. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1779. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1780. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1781. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1782. ("Clock and Effort"
  1783. ["Clock in" org-agenda-clock-in t]
  1784. ["Clock out" org-agenda-clock-out t]
  1785. ["Clock cancel" org-agenda-clock-cancel t]
  1786. ["Goto running clock" org-clock-goto t]
  1787. "--"
  1788. ["Set Effort" org-agenda-set-effort t]
  1789. ["Change clocked effort" org-clock-modify-effort-estimate
  1790. (org-clock-is-active)])
  1791. ("Priority"
  1792. ["Set Priority" org-agenda-priority t]
  1793. ["Increase Priority" org-agenda-priority-up t]
  1794. ["Decrease Priority" org-agenda-priority-down t]
  1795. ["Show Priority" org-agenda-show-priority t])
  1796. ("Calendar/Diary"
  1797. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1798. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1799. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1800. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1801. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1802. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1803. "--"
  1804. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1805. "--"
  1806. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1807. "--"
  1808. ("MobileOrg"
  1809. ["Push Files and Views" org-mobile-push t]
  1810. ["Get Captured and Flagged" org-mobile-pull t]
  1811. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1812. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1813. "--"
  1814. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1815. "--"
  1816. ["Quit" org-agenda-quit t]
  1817. ["Exit and Release Buffers" org-agenda-exit t]
  1818. ))
  1819. ;;; Agenda undo
  1820. (defvar org-agenda-allow-remote-undo t
  1821. "Non-nil means allow remote undo from the agenda buffer.")
  1822. (defvar org-agenda-undo-list nil
  1823. "List of undoable operations in the agenda since last refresh.")
  1824. (defvar org-agenda-undo-has-started-in nil
  1825. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1826. (defvar org-agenda-pending-undo-list nil
  1827. "In a series of undo commands, this is the list of remaining undo items.")
  1828. (defun org-agenda-undo ()
  1829. "Undo a remote editing step in the agenda.
  1830. This undoes changes both in the agenda buffer and in the remote buffer
  1831. that have been changed along."
  1832. (interactive)
  1833. (or org-agenda-allow-remote-undo
  1834. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1835. (if (not (eq this-command last-command))
  1836. (setq org-agenda-undo-has-started-in nil
  1837. org-agenda-pending-undo-list org-agenda-undo-list))
  1838. (if (not org-agenda-pending-undo-list)
  1839. (error "No further undo information"))
  1840. (let* ((entry (pop org-agenda-pending-undo-list))
  1841. buf line cmd rembuf)
  1842. (setq cmd (pop entry) line (pop entry))
  1843. (setq rembuf (nth 2 entry))
  1844. (org-with-remote-undo rembuf
  1845. (while (bufferp (setq buf (pop entry)))
  1846. (if (pop entry)
  1847. (with-current-buffer buf
  1848. (let ((last-undo-buffer buf)
  1849. (inhibit-read-only t))
  1850. (unless (memq buf org-agenda-undo-has-started-in)
  1851. (push buf org-agenda-undo-has-started-in)
  1852. (make-local-variable 'pending-undo-list)
  1853. (undo-start))
  1854. (while (and pending-undo-list
  1855. (listp pending-undo-list)
  1856. (not (car pending-undo-list)))
  1857. (pop pending-undo-list))
  1858. (undo-more 1))))))
  1859. (org-goto-line line)
  1860. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1861. (defun org-verify-change-for-undo (l1 l2)
  1862. "Verify that a real change occurred between the undo lists L1 and L2."
  1863. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1864. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1865. (not (eq l1 l2)))
  1866. ;;; Agenda dispatch
  1867. (defvar org-agenda-restrict nil)
  1868. (defvar org-agenda-restrict-begin (make-marker))
  1869. (defvar org-agenda-restrict-end (make-marker))
  1870. (defvar org-agenda-last-dispatch-buffer nil)
  1871. (defvar org-agenda-overriding-restriction nil)
  1872. ;;;###autoload
  1873. (defun org-agenda (&optional arg keys restriction)
  1874. "Dispatch agenda commands to collect entries to the agenda buffer.
  1875. Prompts for a command to execute. Any prefix arg will be passed
  1876. on to the selected command. The default selections are:
  1877. a Call `org-agenda-list' to display the agenda for current day or week.
  1878. t Call `org-todo-list' to display the global todo list.
  1879. T Call `org-todo-list' to display the global todo list, select only
  1880. entries with a specific TODO keyword (the user gets a prompt).
  1881. m Call `org-tags-view' to display headlines with tags matching
  1882. a condition (the user is prompted for the condition).
  1883. M Like `m', but select only TODO entries, no ordinary headlines.
  1884. L Create a timeline for the current buffer.
  1885. e Export views to associated files.
  1886. s Search entries for keywords.
  1887. / Multi occur across all agenda files and also files listed
  1888. in `org-agenda-text-search-extra-files'.
  1889. < Restrict agenda commands to buffer, subtree, or region.
  1890. Press several times to get the desired effect.
  1891. > Remove a previous restriction.
  1892. # List \"stuck\" projects.
  1893. ! Configure what \"stuck\" means.
  1894. C Configure custom agenda commands.
  1895. More commands can be added by configuring the variable
  1896. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1897. searches can be pre-defined in this way.
  1898. If the current buffer is in Org-mode and visiting a file, you can also
  1899. first press `<' once to indicate that the agenda should be temporarily
  1900. \(until the next use of \\[org-agenda]) restricted to the current file.
  1901. Pressing `<' twice means to restrict to the current subtree or region
  1902. \(if active)."
  1903. (interactive "P")
  1904. (catch 'exit
  1905. (let* ((prefix-descriptions nil)
  1906. (org-agenda-window-setup (if (equal (buffer-name)
  1907. org-agenda-buffer-name)
  1908. 'current-window
  1909. org-agenda-window-setup))
  1910. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1911. (org-agenda-custom-commands
  1912. ;; normalize different versions
  1913. (delq nil
  1914. (mapcar
  1915. (lambda (x)
  1916. (cond ((stringp (cdr x))
  1917. (push x prefix-descriptions)
  1918. nil)
  1919. ((stringp (nth 1 x)) x)
  1920. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1921. (t (cons (car x) (cons "" (cdr x))))))
  1922. org-agenda-custom-commands)))
  1923. (buf (current-buffer))
  1924. (bfn (buffer-file-name (buffer-base-buffer)))
  1925. entry key type match lprops ans)
  1926. ;; Turn off restriction unless there is an overriding one,
  1927. (unless org-agenda-overriding-restriction
  1928. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1929. ;; There is a request to keep the file list in place
  1930. (put 'org-agenda-files 'org-restrict nil))
  1931. (setq org-agenda-restrict nil)
  1932. (move-marker org-agenda-restrict-begin nil)
  1933. (move-marker org-agenda-restrict-end nil))
  1934. ;; Delete old local properties
  1935. (put 'org-agenda-redo-command 'org-lprops nil)
  1936. ;; Remember where this call originated
  1937. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1938. (unless keys
  1939. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1940. keys (car ans)
  1941. restriction (cdr ans)))
  1942. ;; Establish the restriction, if any
  1943. (when (and (not org-agenda-overriding-restriction) restriction)
  1944. (put 'org-agenda-files 'org-restrict (list bfn))
  1945. (cond
  1946. ((eq restriction 'region)
  1947. (setq org-agenda-restrict t)
  1948. (move-marker org-agenda-restrict-begin (region-beginning))
  1949. (move-marker org-agenda-restrict-end (region-end)))
  1950. ((eq restriction 'subtree)
  1951. (save-excursion
  1952. (setq org-agenda-restrict t)
  1953. (org-back-to-heading t)
  1954. (move-marker org-agenda-restrict-begin (point))
  1955. (move-marker org-agenda-restrict-end
  1956. (progn (org-end-of-subtree t)))))))
  1957. ;; For example the todo list should not need it (but does...)
  1958. (cond
  1959. ((setq entry (assoc keys org-agenda-custom-commands))
  1960. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1961. (progn
  1962. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1963. lprops (nth 4 entry))
  1964. (put 'org-agenda-redo-command 'org-lprops lprops)
  1965. (cond
  1966. ((eq type 'agenda)
  1967. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1968. ((eq type 'alltodo)
  1969. (org-let lprops '(org-todo-list current-prefix-arg)))
  1970. ((eq type 'search)
  1971. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1972. ((eq type 'stuck)
  1973. (org-let lprops '(org-agenda-list-stuck-projects
  1974. current-prefix-arg)))
  1975. ((eq type 'tags)
  1976. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1977. ((eq type 'tags-todo)
  1978. (org-let lprops '(org-tags-view '(4) match)))
  1979. ((eq type 'todo)
  1980. (org-let lprops '(org-todo-list match)))
  1981. ((eq type 'tags-tree)
  1982. (org-check-for-org-mode)
  1983. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1984. ((eq type 'todo-tree)
  1985. (org-check-for-org-mode)
  1986. (org-let lprops
  1987. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1988. (regexp-quote match) "\\>"))))
  1989. ((eq type 'occur-tree)
  1990. (org-check-for-org-mode)
  1991. (org-let lprops '(org-occur match)))
  1992. ((functionp type)
  1993. (org-let lprops '(funcall type match)))
  1994. ((fboundp type)
  1995. (org-let lprops '(funcall type match)))
  1996. (t (error "Invalid custom agenda command type %s" type))))
  1997. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1998. ((equal keys "C")
  1999. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2000. (customize-variable 'org-agenda-custom-commands))
  2001. ((equal keys "a") (call-interactively 'org-agenda-list))
  2002. ((equal keys "s") (call-interactively 'org-search-view))
  2003. ((equal keys "t") (call-interactively 'org-todo-list))
  2004. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2005. ((equal keys "m") (call-interactively 'org-tags-view))
  2006. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2007. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2008. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2009. (org-add-hook
  2010. 'post-command-hook
  2011. (lambda ()
  2012. (unless (current-message)
  2013. (let* ((m (org-agenda-get-any-marker))
  2014. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2015. (when note
  2016. (message (concat
  2017. "FLAGGING-NOTE ([?] for more info): "
  2018. (org-add-props
  2019. (replace-regexp-in-string
  2020. "\\\\n" "//"
  2021. (copy-sequence note))
  2022. nil 'face 'org-warning)))))))
  2023. t t))
  2024. ((equal keys "L")
  2025. (unless (org-mode-p)
  2026. (error "This is not an Org-mode file"))
  2027. (unless restriction
  2028. (put 'org-agenda-files 'org-restrict (list bfn))
  2029. (org-call-with-arg 'org-timeline arg)))
  2030. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2031. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2032. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2033. (t (error "Invalid agenda key"))))))
  2034. (defun org-agenda-normalize-custom-commands (cmds)
  2035. (delq nil
  2036. (mapcar
  2037. (lambda (x)
  2038. (cond ((stringp (cdr x)) nil)
  2039. ((stringp (nth 1 x)) x)
  2040. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2041. (t (cons (car x) (cons "" (cdr x))))))
  2042. cmds)))
  2043. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2044. "The user interface for selecting an agenda command."
  2045. (catch 'exit
  2046. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2047. (restrict-ok (and bfn (org-mode-p)))
  2048. (region-p (org-region-active-p))
  2049. (custom org-agenda-custom-commands)
  2050. (selstring "")
  2051. restriction second-time
  2052. c entry key type match prefixes rmheader header-end custom1 desc
  2053. line lines left right n n1)
  2054. (save-window-excursion
  2055. (delete-other-windows)
  2056. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2057. (erase-buffer)
  2058. (insert (eval-when-compile
  2059. (let ((header
  2060. "
  2061. Press key for an agenda command: < Buffer, subtree/region restriction
  2062. -------------------------------- > Remove restriction
  2063. a Agenda for current week or day e Export agenda views
  2064. t List of all TODO entries T Entries with special TODO kwd
  2065. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2066. L Timeline for current buffer # List stuck projects (!=configure)
  2067. s Search for keywords C Configure custom agenda commands
  2068. / Multi-occur ? Find :FLAGGED: entries
  2069. ")
  2070. (start 0))
  2071. (while (string-match
  2072. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2073. header start)
  2074. (setq start (match-end 0))
  2075. (add-text-properties (match-beginning 2) (match-end 2)
  2076. '(face bold) header))
  2077. header)))
  2078. (setq header-end (move-marker (make-marker) (point)))
  2079. (while t
  2080. (setq custom1 custom)
  2081. (when (eq rmheader t)
  2082. (org-goto-line 1)
  2083. (re-search-forward ":" nil t)
  2084. (delete-region (match-end 0) (point-at-eol))
  2085. (forward-char 1)
  2086. (looking-at "-+")
  2087. (delete-region (match-end 0) (point-at-eol))
  2088. (move-marker header-end (match-end 0)))
  2089. (goto-char header-end)
  2090. (delete-region (point) (point-max))
  2091. ;; Produce all the lines that describe custom commands and prefixes
  2092. (setq lines nil)
  2093. (while (setq entry (pop custom1))
  2094. (setq key (car entry) desc (nth 1 entry)
  2095. type (nth 2 entry)
  2096. match (nth 3 entry))
  2097. (if (> (length key) 1)
  2098. (add-to-list 'prefixes (string-to-char key))
  2099. (setq line
  2100. (format
  2101. "%-4s%-14s"
  2102. (org-add-props (copy-sequence key)
  2103. '(face bold))
  2104. (cond
  2105. ((string-match "\\S-" desc) desc)
  2106. ((eq type 'agenda) "Agenda for current week or day")
  2107. ((eq type 'alltodo) "List of all TODO entries")
  2108. ((eq type 'search) "Word search")
  2109. ((eq type 'stuck) "List of stuck projects")
  2110. ((eq type 'todo) "TODO keyword")
  2111. ((eq type 'tags) "Tags query")
  2112. ((eq type 'tags-todo) "Tags (TODO)")
  2113. ((eq type 'tags-tree) "Tags tree")
  2114. ((eq type 'todo-tree) "TODO kwd tree")
  2115. ((eq type 'occur-tree) "Occur tree")
  2116. ((functionp type) (if (symbolp type)
  2117. (symbol-name type)
  2118. "Lambda expression"))
  2119. (t "???"))))
  2120. (if org-agenda-menu-show-matcher
  2121. (setq line
  2122. (concat line ": "
  2123. (cond
  2124. ((stringp match)
  2125. (setq match (copy-sequence match))
  2126. (org-add-props match nil 'face 'org-warning))
  2127. (match
  2128. (format "set of %d commands" (length match)))
  2129. (t ""))))
  2130. (if (org-string-nw-p match)
  2131. (add-text-properties
  2132. 0 (length line) (list 'help-echo
  2133. (concat "Matcher: "match)) line)))
  2134. (push line lines)))
  2135. (setq lines (nreverse lines))
  2136. (when prefixes
  2137. (mapc (lambda (x)
  2138. (push
  2139. (format "%s %s"
  2140. (org-add-props (char-to-string x)
  2141. nil 'face 'bold)
  2142. (or (cdr (assoc (concat selstring
  2143. (char-to-string x))
  2144. prefix-descriptions))
  2145. "Prefix key"))
  2146. lines))
  2147. prefixes))
  2148. ;; Check if we should display in two columns
  2149. (if org-agenda-menu-two-column
  2150. (progn
  2151. (setq n (length lines)
  2152. n1 (+ (/ n 2) (mod n 2))
  2153. right (nthcdr n1 lines)
  2154. left (copy-sequence lines))
  2155. (setcdr (nthcdr (1- n1) left) nil))
  2156. (setq left lines right nil))
  2157. (while left
  2158. (insert "\n" (pop left))
  2159. (when right
  2160. (if (< (current-column) 40)
  2161. (move-to-column 40 t)
  2162. (insert " "))
  2163. (insert (pop right))))
  2164. ;; Make the window the right size
  2165. (goto-char (point-min))
  2166. (if second-time
  2167. (if (not (pos-visible-in-window-p (point-max)))
  2168. (org-fit-window-to-buffer))
  2169. (setq second-time t)
  2170. (org-fit-window-to-buffer))
  2171. ;; Ask for selection
  2172. (message "Press key for agenda command%s:"
  2173. (if (or restrict-ok org-agenda-overriding-restriction)
  2174. (if org-agenda-overriding-restriction
  2175. " (restriction lock active)"
  2176. (if restriction
  2177. (format " (restricted to %s)" restriction)
  2178. " (unrestricted)"))
  2179. ""))
  2180. (setq c (read-char-exclusive))
  2181. (message "")
  2182. (cond
  2183. ((assoc (char-to-string c) custom)
  2184. (setq selstring (concat selstring (char-to-string c)))
  2185. (throw 'exit (cons selstring restriction)))
  2186. ((memq c prefixes)
  2187. (setq selstring (concat selstring (char-to-string c))
  2188. prefixes nil
  2189. rmheader (or rmheader t)
  2190. custom (delq nil (mapcar
  2191. (lambda (x)
  2192. (if (or (= (length (car x)) 1)
  2193. (/= (string-to-char (car x)) c))
  2194. nil
  2195. (cons (substring (car x) 1) (cdr x))))
  2196. custom))))
  2197. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2198. (message "Restriction is only possible in Org-mode buffers")
  2199. (ding) (sit-for 1))
  2200. ((eq c ?1)
  2201. (org-agenda-remove-restriction-lock 'noupdate)
  2202. (setq restriction 'buffer))
  2203. ((eq c ?0)
  2204. (org-agenda-remove-restriction-lock 'noupdate)
  2205. (setq restriction (if region-p 'region 'subtree)))
  2206. ((eq c ?<)
  2207. (org-agenda-remove-restriction-lock 'noupdate)
  2208. (setq restriction
  2209. (cond
  2210. ((eq restriction 'buffer)
  2211. (if region-p 'region 'subtree))
  2212. ((memq restriction '(subtree region))
  2213. nil)
  2214. (t 'buffer))))
  2215. ((eq c ?>)
  2216. (org-agenda-remove-restriction-lock 'noupdate)
  2217. (setq restriction nil))
  2218. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2219. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2220. ((and (> (length selstring) 0) (eq c ?\d))
  2221. (delete-window)
  2222. (org-agenda-get-restriction-and-command prefix-descriptions))
  2223. ((equal c ?q) (error "Abort"))
  2224. (t (error "Invalid key %c" c))))))))
  2225. (defun org-run-agenda-series (name series)
  2226. (org-let (nth 1 series) '(org-prepare-agenda name))
  2227. (let* ((org-agenda-multi t)
  2228. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2229. (cmds (car series))
  2230. (gprops (nth 1 series))
  2231. match ;; The byte compiler incorrectly complains about this. Keep it!
  2232. cmd type lprops)
  2233. (while (setq cmd (pop cmds))
  2234. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2235. (cond
  2236. ((eq type 'agenda)
  2237. (org-let2 gprops lprops
  2238. '(call-interactively 'org-agenda-list)))
  2239. ((eq type 'alltodo)
  2240. (org-let2 gprops lprops
  2241. '(call-interactively 'org-todo-list)))
  2242. ((eq type 'search)
  2243. (org-let2 gprops lprops
  2244. '(org-search-view current-prefix-arg match nil)))
  2245. ((eq type 'stuck)
  2246. (org-let2 gprops lprops
  2247. '(call-interactively 'org-agenda-list-stuck-projects)))
  2248. ((eq type 'tags)
  2249. (org-let2 gprops lprops
  2250. '(org-tags-view current-prefix-arg match)))
  2251. ((eq type 'tags-todo)
  2252. (org-let2 gprops lprops
  2253. '(org-tags-view '(4) match)))
  2254. ((eq type 'todo)
  2255. (org-let2 gprops lprops
  2256. '(org-todo-list match)))
  2257. ((fboundp type)
  2258. (org-let2 gprops lprops
  2259. '(funcall type match)))
  2260. (t (error "Invalid type in command series"))))
  2261. (widen)
  2262. (setq org-agenda-redo-command redo)
  2263. (goto-char (point-min)))
  2264. (org-fit-agenda-window)
  2265. (org-let (nth 1 series) '(org-finalize-agenda)))
  2266. ;;;###autoload
  2267. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2268. "Run an agenda command in batch mode and send the result to STDOUT.
  2269. If CMD-KEY is a string of length 1, it is used as a key in
  2270. `org-agenda-custom-commands' and triggers this command. If it is a
  2271. longer string it is used as a tags/todo match string.
  2272. Parameters are alternating variable names and values that will be bound
  2273. before running the agenda command."
  2274. (let (pars)
  2275. (while parameters
  2276. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2277. (if (> (length cmd-key) 2)
  2278. (eval (list 'let (nreverse pars)
  2279. (list 'org-tags-view nil cmd-key)))
  2280. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2281. (set-buffer org-agenda-buffer-name)
  2282. (princ (org-encode-for-stdout (buffer-string)))))
  2283. ;(defun org-encode-for-stdout (string)
  2284. ; (if (fboundp 'encode-coding-string)
  2285. ; (encode-coding-string string buffer-file-coding-system)
  2286. ; string))
  2287. (defun org-encode-for-stdout (string)
  2288. string)
  2289. (defvar org-agenda-info nil)
  2290. ;;;###autoload
  2291. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2292. "Run an agenda command in batch mode and send the result to STDOUT.
  2293. If CMD-KEY is a string of length 1, it is used as a key in
  2294. `org-agenda-custom-commands' and triggers this command. If it is a
  2295. longer string it is used as a tags/todo match string.
  2296. Parameters are alternating variable names and values that will be bound
  2297. before running the agenda command.
  2298. The output gives a line for each selected agenda item. Each
  2299. item is a list of comma-separated values, like this:
  2300. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2301. category The category of the item
  2302. head The headline, without TODO kwd, TAGS and PRIORITY
  2303. type The type of the agenda entry, can be
  2304. todo selected in TODO match
  2305. tagsmatch selected in tags match
  2306. diary imported from diary
  2307. deadline a deadline on given date
  2308. scheduled scheduled on given date
  2309. timestamp entry has timestamp on given date
  2310. closed entry was closed on given date
  2311. upcoming-deadline warning about deadline
  2312. past-scheduled forwarded scheduled item
  2313. block entry has date block including g. date
  2314. todo The todo keyword, if any
  2315. tags All tags including inherited ones, separated by colons
  2316. date The relevant date, like 2007-2-14
  2317. time The time, like 15:00-16:50
  2318. extra Sting with extra planning info
  2319. priority-l The priority letter if any was given
  2320. priority-n The computed numerical priority
  2321. agenda-day The day in the agenda where this is listed"
  2322. (let (pars)
  2323. (while parameters
  2324. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2325. (push (list 'org-agenda-remove-tags t) pars)
  2326. (if (> (length cmd-key) 2)
  2327. (eval (list 'let (nreverse pars)
  2328. (list 'org-tags-view nil cmd-key)))
  2329. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2330. (set-buffer org-agenda-buffer-name)
  2331. (let* ((lines (org-split-string (buffer-string) "\n"))
  2332. line)
  2333. (while (setq line (pop lines))
  2334. (catch 'next
  2335. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2336. (setq org-agenda-info
  2337. (org-fix-agenda-info (text-properties-at 0 line)))
  2338. (princ
  2339. (org-encode-for-stdout
  2340. (mapconcat 'org-agenda-export-csv-mapper
  2341. '(org-category txt type todo tags date time extra
  2342. priority-letter priority agenda-day)
  2343. ",")))
  2344. (princ "\n"))))))
  2345. (defun org-fix-agenda-info (props)
  2346. "Make sure all properties on an agenda item have a canonical form.
  2347. This ensures the export commands can easily use it."
  2348. (let (tmp re)
  2349. (when (setq tmp (plist-get props 'tags))
  2350. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2351. (when (setq tmp (plist-get props 'date))
  2352. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2353. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2354. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2355. (setq tmp (calendar-date-string tmp)))
  2356. (setq props (plist-put props 'date tmp)))
  2357. (when (setq tmp (plist-get props 'day))
  2358. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2359. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2360. (setq tmp (calendar-date-string tmp)))
  2361. (setq props (plist-put props 'day tmp))
  2362. (setq props (plist-put props 'agenda-day tmp)))
  2363. (when (setq tmp (plist-get props 'txt))
  2364. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2365. (plist-put props 'priority-letter (match-string 1 tmp))
  2366. (setq tmp (replace-match "" t t tmp)))
  2367. (when (and (setq re (plist-get props 'org-todo-regexp))
  2368. (setq re (concat "\\`\\.*" re " ?"))
  2369. (string-match re tmp))
  2370. (plist-put props 'todo (match-string 1 tmp))
  2371. (setq tmp (replace-match "" t t tmp)))
  2372. (plist-put props 'txt tmp)))
  2373. props)
  2374. (defun org-agenda-export-csv-mapper (prop)
  2375. (let ((res (plist-get org-agenda-info prop)))
  2376. (setq res
  2377. (cond
  2378. ((not res) "")
  2379. ((stringp res) res)
  2380. (t (prin1-to-string res))))
  2381. (while (string-match "," res)
  2382. (setq res (replace-match ";" t t res)))
  2383. (org-trim res)))
  2384. ;;;###autoload
  2385. (defun org-store-agenda-views (&rest parameters)
  2386. (interactive)
  2387. (eval (list 'org-batch-store-agenda-views)))
  2388. ;; FIXME, why is this a macro?????
  2389. ;;;###autoload
  2390. (defmacro org-batch-store-agenda-views (&rest parameters)
  2391. "Run all custom agenda commands that have a file argument."
  2392. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2393. (pop-up-frames nil)
  2394. (dir default-directory)
  2395. pars cmd thiscmdkey files opts cmd-or-set)
  2396. (while parameters
  2397. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2398. (setq pars (reverse pars))
  2399. (save-window-excursion
  2400. (while cmds
  2401. (setq cmd (pop cmds)
  2402. thiscmdkey (car cmd)
  2403. cmd-or-set (nth 2 cmd)
  2404. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2405. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2406. (if (stringp files) (setq files (list files)))
  2407. (when files
  2408. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2409. (list 'org-agenda nil thiscmdkey)))
  2410. (set-buffer org-agenda-buffer-name)
  2411. (while files
  2412. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2413. (list 'org-write-agenda
  2414. (expand-file-name (pop files) dir) nil t))))
  2415. (and (get-buffer org-agenda-buffer-name)
  2416. (kill-buffer org-agenda-buffer-name)))))))
  2417. (defun org-agenda-mark-header-line (pos)
  2418. "Mark the line at POS as an agenda structure header."
  2419. (save-excursion
  2420. (goto-char pos)
  2421. (put-text-property (point-at-bol) (point-at-eol)
  2422. 'org-agenda-structural-header t)
  2423. (when org-agenda-title-append
  2424. (put-text-property (point-at-bol) (point-at-eol)
  2425. 'org-agenda-title-append org-agenda-title-append))))
  2426. (defvar org-mobile-creating-agendas)
  2427. (defun org-write-agenda (file &optional open nosettings)
  2428. "Write the current buffer (an agenda view) as a file.
  2429. Depending on the extension of the file name, plain text (.txt),
  2430. HTML (.html or .htm) or Postscript (.ps) is produced.
  2431. If the extension is .ics, run icalendar export over all files used
  2432. to construct the agenda and limit the export to entries listed in the
  2433. agenda now.
  2434. With prefix argument OPEN, open the new file immediately.
  2435. If NOSETTINGS is given, do not scope the settings of
  2436. `org-agenda-exporter-settings' into the export commands. This is used when
  2437. the settings have already been scoped and we do not wish to overrule other,
  2438. higher priority settings."
  2439. (interactive "FWrite agenda to file: \nP")
  2440. (if (not (file-writable-p file))
  2441. (error "Cannot write agenda to file %s" file))
  2442. (org-let (if nosettings nil org-agenda-exporter-settings)
  2443. '(save-excursion
  2444. (save-window-excursion
  2445. (org-agenda-mark-filtered-text)
  2446. (let ((bs (copy-sequence (buffer-string))) beg)
  2447. (org-agenda-unmark-filtered-text)
  2448. (with-temp-buffer
  2449. (rename-buffer "Agenda View" t)
  2450. (set-buffer-modified-p nil)
  2451. (insert bs)
  2452. (org-agenda-remove-marked-text 'org-filtered)
  2453. (while (setq beg (text-property-any (point-min) (point-max)
  2454. 'org-filtered t))
  2455. (delete-region
  2456. beg (or (next-single-property-change beg 'org-filtered)
  2457. (point-max))))
  2458. (run-hooks 'org-agenda-before-write-hook)
  2459. (cond
  2460. ((org-bound-and-true-p org-mobile-creating-agendas)
  2461. (org-mobile-write-agenda-for-mobile file))
  2462. ((string-match "\\.html?\\'" file)
  2463. (require 'htmlize)
  2464. (set-buffer (htmlize-buffer (current-buffer)))
  2465. (when (and org-agenda-export-html-style
  2466. (string-match "<style>" org-agenda-export-html-style))
  2467. ;; replace <style> section with org-agenda-export-html-style
  2468. (goto-char (point-min))
  2469. (kill-region (- (search-forward "<style") 6)
  2470. (search-forward "</style>"))
  2471. (insert org-agenda-export-html-style))
  2472. (write-file file)
  2473. (kill-buffer (current-buffer))
  2474. (message "HTML written to %s" file))
  2475. ((string-match "\\.ps\\'" file)
  2476. (require 'ps-print)
  2477. (ps-print-buffer-with-faces file)
  2478. (message "Postscript written to %s" file))
  2479. ((string-match "\\.pdf\\'" file)
  2480. (require 'ps-print)
  2481. (ps-print-buffer-with-faces
  2482. (concat (file-name-sans-extension file) ".ps"))
  2483. (call-process "ps2pdf" nil nil nil
  2484. (expand-file-name
  2485. (concat (file-name-sans-extension file) ".ps"))
  2486. (expand-file-name file))
  2487. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2488. (message "PDF written to %s" file))
  2489. ((string-match "\\.ics\\'" file)
  2490. (require 'org-icalendar)
  2491. (let ((org-agenda-marker-table
  2492. (org-create-marker-find-array
  2493. (org-agenda-collect-markers)))
  2494. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2495. (org-combined-agenda-icalendar-file file))
  2496. (apply 'org-export-icalendar 'combine
  2497. (org-agenda-files nil 'ifmode))))
  2498. (t
  2499. (let ((bs (buffer-string)))
  2500. (find-file file)
  2501. (erase-buffer)
  2502. (insert bs)
  2503. (save-buffer 0)
  2504. (kill-buffer (current-buffer))
  2505. (message "Plain text written to %s" file))))))))
  2506. (set-buffer org-agenda-buffer-name))
  2507. (when open (org-open-file file)))
  2508. (defvar org-agenda-filter-overlays nil)
  2509. (defun org-agenda-mark-filtered-text ()
  2510. "Mark all text hidden by filtering with a text property."
  2511. (let ((inhibit-read-only t))
  2512. (mapc
  2513. (lambda (o)
  2514. (when (equal (overlay-buffer o) (current-buffer))
  2515. (put-text-property
  2516. (overlay-start o) (overlay-end o)
  2517. 'org-filtered t)))
  2518. org-agenda-filter-overlays)))
  2519. (defun org-agenda-unmark-filtered-text ()
  2520. "Remove the filtering text property."
  2521. (let ((inhibit-read-only t))
  2522. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2523. (defun org-agenda-remove-marked-text (property &optional value)
  2524. "Delete all text marked with VALUE of PROPERTY.
  2525. VALUE defaults to t."
  2526. (let (beg)
  2527. (setq value (or value t))
  2528. (while (setq beg (text-property-any (point-min) (point-max)
  2529. property value))
  2530. (delete-region
  2531. beg (or (next-single-property-change beg 'org-filtered)
  2532. (point-max))))))
  2533. (defun org-agenda-add-entry-text ()
  2534. "Add entry text to agenda lines.
  2535. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2536. entry text following headings shown in the agenda.
  2537. Drawers will be excluded, also the line with scheduling/deadline info."
  2538. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2539. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2540. (let (m txt)
  2541. (goto-char (point-min))
  2542. (while (not (eobp))
  2543. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2544. (beginning-of-line 2)
  2545. (setq txt (org-agenda-get-some-entry-text
  2546. m org-agenda-add-entry-text-maxlines " > "))
  2547. (end-of-line 1)
  2548. (if (string-match "\\S-" txt)
  2549. (insert "\n" txt)
  2550. (or (eobp) (forward-char 1))))))))
  2551. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2552. &rest keep)
  2553. "Extract entry text from MARKER, at most N-LINES lines.
  2554. This will ignore drawers etc, just get the text.
  2555. If INDENT is given, prefix every line with this string. If KEEP is
  2556. given, it is a list of symbols, defining stuff that should not be
  2557. removed from the entry content. Currently only `planning' is allowed here."
  2558. (let (txt drawer-re kwd-time-re ind)
  2559. (save-excursion
  2560. (with-current-buffer (marker-buffer marker)
  2561. (if (not (org-mode-p))
  2562. (setq txt "")
  2563. (save-excursion
  2564. (save-restriction
  2565. (widen)
  2566. (goto-char marker)
  2567. (end-of-line 1)
  2568. (setq txt (buffer-substring
  2569. (min (1+ (point)) (point-max))
  2570. (progn (outline-next-heading) (point)))
  2571. drawer-re org-drawer-regexp
  2572. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2573. ".*\n?"))
  2574. (with-temp-buffer
  2575. (insert txt)
  2576. (when org-agenda-add-entry-text-descriptive-links
  2577. (goto-char (point-min))
  2578. (while (org-activate-bracket-links (point-max))
  2579. (add-text-properties (match-beginning 0) (match-end 0)
  2580. '(face org-link))))
  2581. (goto-char (point-min))
  2582. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2583. (set-text-properties (match-beginning 0) (match-end 0)
  2584. nil))
  2585. (goto-char (point-min))
  2586. (while (re-search-forward drawer-re nil t)
  2587. (delete-region
  2588. (match-beginning 0)
  2589. (progn (re-search-forward
  2590. "^[ \t]*:END:.*\n?" nil 'move)
  2591. (point))))
  2592. (unless (member 'planning keep)
  2593. (goto-char (point-min))
  2594. (while (re-search-forward kwd-time-re nil t)
  2595. (replace-match "")))
  2596. (goto-char (point-min))
  2597. (when org-agenda-entry-text-exclude-regexps
  2598. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2599. (while (setq re (pop re-list))
  2600. (goto-char (point-min))
  2601. (while (re-search-forward re nil t)
  2602. (replace-match "")))))
  2603. (goto-char (point-max))
  2604. (skip-chars-backward " \t\n")
  2605. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2606. ;; find and remove min common indentation
  2607. (goto-char (point-min))
  2608. (untabify (point-min) (point-max))
  2609. (setq ind (org-get-indentation))
  2610. (while (not (eobp))
  2611. (unless (looking-at "[ \t]*$")
  2612. (setq ind (min ind (org-get-indentation))))
  2613. (beginning-of-line 2))
  2614. (goto-char (point-min))
  2615. (while (not (eobp))
  2616. (unless (looking-at "[ \t]*$")
  2617. (move-to-column ind)
  2618. (delete-region (point-at-bol) (point)))
  2619. (beginning-of-line 2))
  2620. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2621. (goto-char (point-min))
  2622. (when indent
  2623. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2624. (replace-match indent t t)))
  2625. (goto-char (point-min))
  2626. (while (looking-at "[ \t]*\n") (replace-match ""))
  2627. (goto-char (point-max))
  2628. (when (> (org-current-line)
  2629. n-lines)
  2630. (org-goto-line (1+ n-lines))
  2631. (backward-char 1))
  2632. (setq txt (buffer-substring (point-min) (point)))))))))
  2633. txt))
  2634. (defun org-agenda-collect-markers ()
  2635. "Collect the markers pointing to entries in the agenda buffer."
  2636. (let (m markers)
  2637. (save-excursion
  2638. (goto-char (point-min))
  2639. (while (not (eobp))
  2640. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2641. (org-get-at-bol 'org-marker)))
  2642. (push m markers))
  2643. (beginning-of-line 2)))
  2644. (nreverse markers)))
  2645. (defun org-create-marker-find-array (marker-list)
  2646. "Create a alist of files names with all marker positions in that file."
  2647. (let (f tbl m a p)
  2648. (while (setq m (pop marker-list))
  2649. (setq p (marker-position m)
  2650. f (buffer-file-name (or (buffer-base-buffer
  2651. (marker-buffer m))
  2652. (marker-buffer m))))
  2653. (if (setq a (assoc f tbl))
  2654. (push (marker-position m) (cdr a))
  2655. (push (list f p) tbl)))
  2656. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2657. tbl)))
  2658. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2659. (defun org-check-agenda-marker-table ()
  2660. "Check of the current entry is on the marker list."
  2661. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2662. a)
  2663. (and (setq a (assoc file org-agenda-marker-table))
  2664. (save-match-data
  2665. (save-excursion
  2666. (org-back-to-heading t)
  2667. (member (point) (cdr a)))))))
  2668. (defun org-check-for-org-mode ()
  2669. "Make sure current buffer is in org-mode. Error if not."
  2670. (or (org-mode-p)
  2671. (error "Cannot execute org-mode agenda command on buffer in %s"
  2672. major-mode)))
  2673. (defun org-fit-agenda-window ()
  2674. "Fit the window to the buffer size."
  2675. (and (memq org-agenda-window-setup '(reorganize-frame))
  2676. (fboundp 'fit-window-to-buffer)
  2677. (org-fit-window-to-buffer
  2678. nil
  2679. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2680. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2681. ;;; Agenda prepare and finalize
  2682. (defvar org-agenda-multi nil) ; dynamically scoped
  2683. (defvar org-agenda-buffer-name "*Org Agenda*")
  2684. (defvar org-pre-agenda-window-conf nil)
  2685. (defvar org-agenda-columns-active nil)
  2686. (defvar org-agenda-name nil)
  2687. (defvar org-agenda-filter nil)
  2688. (defvar org-agenda-filter-while-redo nil)
  2689. (defvar org-agenda-filter-preset nil
  2690. "A preset of the tags filter used for secondary agenda filtering.
  2691. This must be a list of strings, each string must be a single tag preceded
  2692. by \"+\" or \"-\".
  2693. This variable should not be set directly, but agenda custom commands can
  2694. bind it in the options section. The preset filter is a global property of
  2695. the entire agenda view. In a block agenda, it will not work reliably to
  2696. define a filter for one of the individual blocks. You need to set it in
  2697. the global options and expect it to be applied to the entire view.")
  2698. (defun org-prepare-agenda (&optional name)
  2699. (setq org-todo-keywords-for-agenda nil)
  2700. (setq org-done-keywords-for-agenda nil)
  2701. (setq org-drawers-for-agenda nil)
  2702. (unless org-agenda-persistent-filter
  2703. (setq org-agenda-filter nil))
  2704. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2705. (if org-agenda-multi
  2706. (progn
  2707. (setq buffer-read-only nil)
  2708. (goto-char (point-max))
  2709. (unless (or (bobp) org-agenda-compact-blocks)
  2710. (insert "\n"
  2711. (if (stringp org-agenda-block-separator)
  2712. org-agenda-block-separator
  2713. (make-string (window-width) org-agenda-block-separator))
  2714. "\n"))
  2715. (narrow-to-region (point) (point-max)))
  2716. (org-agenda-reset-markers)
  2717. (setq org-agenda-contributing-files nil)
  2718. (setq org-agenda-columns-active nil)
  2719. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2720. (setq org-todo-keywords-for-agenda
  2721. (org-uniquify org-todo-keywords-for-agenda))
  2722. (setq org-done-keywords-for-agenda
  2723. (org-uniquify org-done-keywords-for-agenda))
  2724. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2725. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2726. (awin (get-buffer-window abuf)))
  2727. (cond
  2728. ((equal (current-buffer) abuf) nil)
  2729. (awin (select-window awin))
  2730. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2731. ((equal org-agenda-window-setup 'current-window)
  2732. (switch-to-buffer abuf))
  2733. ((equal org-agenda-window-setup 'other-window)
  2734. (org-switch-to-buffer-other-window abuf))
  2735. ((equal org-agenda-window-setup 'other-frame)
  2736. (switch-to-buffer-other-frame abuf))
  2737. ((equal org-agenda-window-setup 'reorganize-frame)
  2738. (delete-other-windows)
  2739. (org-switch-to-buffer-other-window abuf)))
  2740. ;; additional test in case agenda is invoked from within agenda
  2741. ;; buffer via elisp link
  2742. (unless (equal (current-buffer) abuf)
  2743. (switch-to-buffer abuf)))
  2744. (setq buffer-read-only nil)
  2745. (let ((inhibit-read-only t)) (erase-buffer))
  2746. (org-agenda-mode)
  2747. (and name (not org-agenda-name)
  2748. (org-set-local 'org-agenda-name name)))
  2749. (setq buffer-read-only nil))
  2750. (defun org-finalize-agenda ()
  2751. "Finishing touch for the agenda buffer, called just before displaying it."
  2752. (unless org-agenda-multi
  2753. (save-excursion
  2754. (let ((inhibit-read-only t))
  2755. (goto-char (point-min))
  2756. (while (org-activate-bracket-links (point-max))
  2757. (add-text-properties (match-beginning 0) (match-end 0)
  2758. '(face org-link)))
  2759. (org-agenda-align-tags)
  2760. (unless org-agenda-with-colors
  2761. (remove-text-properties (point-min) (point-max) '(face nil))))
  2762. (if (and (boundp 'org-agenda-overriding-columns-format)
  2763. org-agenda-overriding-columns-format)
  2764. (org-set-local 'org-agenda-overriding-columns-format
  2765. org-agenda-overriding-columns-format))
  2766. (if (and (boundp 'org-agenda-view-columns-initially)
  2767. org-agenda-view-columns-initially)
  2768. (org-agenda-columns))
  2769. (when org-agenda-fontify-priorities
  2770. (org-agenda-fontify-priorities))
  2771. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2772. (org-agenda-dim-blocked-tasks))
  2773. (org-agenda-mark-clocking-task)
  2774. (when org-agenda-entry-text-mode
  2775. (org-agenda-entry-text-hide)
  2776. (org-agenda-entry-text-show))
  2777. (if (functionp 'org-habit-insert-consistency-graphs)
  2778. (org-habit-insert-consistency-graphs))
  2779. (run-hooks 'org-finalize-agenda-hook)
  2780. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2781. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2782. (org-agenda-filter-apply org-agenda-filter))
  2783. )))
  2784. (defun org-agenda-mark-clocking-task ()
  2785. "Mark the current clock entry in the agenda if it is present."
  2786. (mapc (lambda (o)
  2787. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2788. (delete-overlay o)))
  2789. (overlays-in (point-min) (point-max)))
  2790. (when (marker-buffer org-clock-hd-marker)
  2791. (save-excursion
  2792. (goto-char (point-min))
  2793. (let (s ov)
  2794. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2795. (goto-char s)
  2796. (when (equal (org-get-at-bol 'org-hd-marker)
  2797. org-clock-hd-marker)
  2798. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2799. (overlay-put ov 'type 'org-agenda-clocking)
  2800. (overlay-put ov 'face 'org-agenda-clocking)
  2801. (overlay-put ov 'help-echo
  2802. "The clock is running in this item")))))))
  2803. (defun org-agenda-fontify-priorities ()
  2804. "Make highest priority lines bold, and lowest italic."
  2805. (interactive)
  2806. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2807. (delete-overlay o)))
  2808. (overlays-in (point-min) (point-max)))
  2809. (save-excursion
  2810. (let ((inhibit-read-only t)
  2811. b e p ov h l)
  2812. (goto-char (point-min))
  2813. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2814. (setq h (or (get-char-property (point) 'org-highest-priority)
  2815. org-highest-priority)
  2816. l (or (get-char-property (point) 'org-lowest-priority)
  2817. org-lowest-priority)
  2818. p (string-to-char (match-string 1))
  2819. b (match-beginning 0)
  2820. e (if (eq org-agenda-fontify-priorities 'cookies)
  2821. (match-end 0)
  2822. (point-at-eol))
  2823. ov (make-overlay b e))
  2824. (overlay-put
  2825. ov 'face
  2826. (cond ((org-face-from-face-or-color
  2827. 'priority nil
  2828. (cdr (assoc p org-priority-faces))))
  2829. ((and (listp org-agenda-fontify-priorities)
  2830. (org-face-from-face-or-color
  2831. 'priority nil
  2832. (cdr (assoc p org-agenda-fontify-priorities)))))
  2833. ((equal p l) 'italic)
  2834. ((equal p h) 'bold)))
  2835. (overlay-put ov 'org-type 'org-priority)))))
  2836. (defun org-agenda-dim-blocked-tasks ()
  2837. "Dim currently blocked TODO's in the agenda display."
  2838. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2839. (delete-overlay o)))
  2840. (overlays-in (point-min) (point-max)))
  2841. (save-excursion
  2842. (let ((inhibit-read-only t)
  2843. (org-depend-tag-blocked nil)
  2844. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2845. org-blocked-by-checkboxes
  2846. invis1 b e p ov h l)
  2847. (goto-char (point-min))
  2848. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2849. (and pos (goto-char (1+ pos))))
  2850. (setq org-blocked-by-checkboxes nil invis1 invis)
  2851. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2852. (when (and marker
  2853. (not (with-current-buffer (marker-buffer marker)
  2854. (save-excursion
  2855. (goto-char marker)
  2856. (if (org-entry-get nil "NOBLOCKING")
  2857. t ;; Never block this entry
  2858. (run-hook-with-args-until-failure
  2859. 'org-blocker-hook
  2860. (list :type 'todo-state-change
  2861. :position marker
  2862. :from 'todo
  2863. :to 'done)))))))
  2864. (if org-blocked-by-checkboxes (setq invis1 nil))
  2865. (setq b (if invis1
  2866. (max (point-min) (1- (point-at-bol)))
  2867. (point-at-bol))
  2868. e (point-at-eol)
  2869. ov (make-overlay b e))
  2870. (if invis1
  2871. (overlay-put ov 'invisible t)
  2872. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2873. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2874. (defvar org-agenda-skip-function nil
  2875. "Function to be called at each match during agenda construction.
  2876. If this function returns nil, the current match should not be skipped.
  2877. Otherwise, the function must return a position from where the search
  2878. should be continued.
  2879. This may also be a Lisp form, it will be evaluated.
  2880. Never set this variable using `setq' or so, because then it will apply
  2881. to all future agenda commands. If you do want a global skipping condition,
  2882. use the option `org-agenda-skip-function-global' instead.
  2883. The correct usage for `org-agenda-skip-function' is to bind it with
  2884. `let' to scope it dynamically into the agenda-constructing command.
  2885. A good way to set it is through options in `org-agenda-custom-commands'.")
  2886. (defun org-agenda-skip ()
  2887. "Throw to `:skip' in places that should be skipped.
  2888. Also moves point to the end of the skipped region, so that search can
  2889. continue from there."
  2890. (let ((p (point-at-bol)) to)
  2891. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2892. (get-text-property p :org-archived)
  2893. (org-end-of-subtree t)
  2894. (throw :skip t))
  2895. (and org-agenda-skip-comment-trees
  2896. (get-text-property p :org-comment)
  2897. (org-end-of-subtree t)
  2898. (throw :skip t))
  2899. (if (equal (char-after p) ?#) (throw :skip t))
  2900. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2901. (org-agenda-skip-eval org-agenda-skip-function)))
  2902. (goto-char to)
  2903. (throw :skip t))))
  2904. (defun org-agenda-skip-eval (form)
  2905. "If FORM is a function or a list, call (or eval) is and return result.
  2906. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2907. and match data are returned to the previous state no matter what these
  2908. functions do."
  2909. (let (fp)
  2910. (and form
  2911. (or (setq fp (functionp form))
  2912. (consp form))
  2913. (save-excursion
  2914. (save-match-data
  2915. (if fp
  2916. (funcall form)
  2917. (eval form)))))))
  2918. (defvar org-agenda-markers nil
  2919. "List of all currently active markers created by `org-agenda'.")
  2920. (defvar org-agenda-last-marker-time (org-float-time)
  2921. "Creation time of the last agenda marker.")
  2922. (defun org-agenda-new-marker (&optional pos)
  2923. "Return a new agenda marker.
  2924. Org-mode keeps a list of these markers and resets them when they are
  2925. no longer in use."
  2926. (let ((m (copy-marker (or pos (point)))))
  2927. (setq org-agenda-last-marker-time (org-float-time))
  2928. (push m org-agenda-markers)
  2929. m))
  2930. (defun org-agenda-reset-markers ()
  2931. "Reset markers created by `org-agenda'."
  2932. (while org-agenda-markers
  2933. (move-marker (pop org-agenda-markers) nil)))
  2934. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2935. "Save relative positions of markers in region."
  2936. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2937. org-agenda-markers))
  2938. ;;; Entry text mode
  2939. (defun org-agenda-entry-text-show-here ()
  2940. "Add some text from the entry as context to the current line."
  2941. (let (m txt o)
  2942. (setq m (org-get-at-bol 'org-hd-marker))
  2943. (unless (marker-buffer m)
  2944. (error "No marker points to an entry here"))
  2945. (setq txt (concat "\n" (org-no-properties
  2946. (org-agenda-get-some-entry-text
  2947. m org-agenda-entry-text-maxlines " > "))))
  2948. (when (string-match "\\S-" txt)
  2949. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2950. (overlay-put o 'evaporate t)
  2951. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2952. (overlay-put o 'after-string txt))))
  2953. (defun org-agenda-entry-text-show ()
  2954. "Add entry context for all agenda lines."
  2955. (interactive)
  2956. (save-excursion
  2957. (goto-char (point-max))
  2958. (beginning-of-line 1)
  2959. (while (not (bobp))
  2960. (when (org-get-at-bol 'org-hd-marker)
  2961. (org-agenda-entry-text-show-here))
  2962. (beginning-of-line 0))))
  2963. (defun org-agenda-entry-text-hide ()
  2964. "Remove any shown entry context."
  2965. (delq nil
  2966. (mapcar (lambda (o)
  2967. (if (eq (overlay-get o 'org-overlay-type)
  2968. 'agenda-entry-content)
  2969. (progn (delete-overlay o) t)))
  2970. (overlays-in (point-min) (point-max)))))
  2971. (defun org-agenda-get-day-face (date)
  2972. "Return the face DATE should be displayed with."
  2973. (or (and (functionp org-agenda-day-face-function)
  2974. (funcall org-agenda-day-face-function date))
  2975. (cond ((org-agenda-todayp date)
  2976. 'org-agenda-date-today)
  2977. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2978. 'org-agenda-date-weekend)
  2979. (t 'org-agenda-date))))
  2980. ;;; Agenda timeline
  2981. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2982. (defun org-timeline (&optional include-all)
  2983. "Show a time-sorted view of the entries in the current org file.
  2984. Only entries with a time stamp of today or later will be listed. With
  2985. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2986. under the current date.
  2987. If the buffer contains an active region, only check the region for
  2988. dates."
  2989. (interactive "P")
  2990. (org-compile-prefix-format 'timeline)
  2991. (org-set-sorting-strategy 'timeline)
  2992. (let* ((dopast t)
  2993. (dotodo include-all)
  2994. (doclosed org-agenda-show-log)
  2995. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2996. (current-buffer))))
  2997. (date (calendar-current-date))
  2998. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2999. (end (if (org-region-active-p) (region-end) (point-max)))
  3000. (day-numbers (org-get-all-dates beg end 'no-ranges
  3001. t doclosed ; always include today
  3002. org-timeline-show-empty-dates))
  3003. (org-deadline-warning-days 0)
  3004. (org-agenda-only-exact-dates t)
  3005. (today (org-today))
  3006. (past t)
  3007. args
  3008. s e rtn d emptyp)
  3009. (setq org-agenda-redo-command
  3010. (list 'progn
  3011. (list 'org-switch-to-buffer-other-window (current-buffer))
  3012. (list 'org-timeline (list 'quote include-all))))
  3013. (if (not dopast)
  3014. ;; Remove past dates from the list of dates.
  3015. (setq day-numbers (delq nil (mapcar (lambda(x)
  3016. (if (>= x today) x nil))
  3017. day-numbers))))
  3018. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3019. (if doclosed (push :closed args))
  3020. (push :timestamp args)
  3021. (push :deadline args)
  3022. (push :scheduled args)
  3023. (push :sexp args)
  3024. (if dotodo (push :todo args))
  3025. (insert "Timeline of file " entry "\n")
  3026. (add-text-properties (point-min) (point)
  3027. (list 'face 'org-agenda-structure))
  3028. (org-agenda-mark-header-line (point-min))
  3029. (while (setq d (pop day-numbers))
  3030. (if (and (listp d) (eq (car d) :omitted))
  3031. (progn
  3032. (setq s (point))
  3033. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3034. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3035. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3036. (if (and (>= d today)
  3037. dopast
  3038. past)
  3039. (progn
  3040. (setq past nil)
  3041. (insert (make-string 79 ?-) "\n")))
  3042. (setq date (calendar-gregorian-from-absolute d))
  3043. (setq s (point))
  3044. (setq rtn (and (not emptyp)
  3045. (apply 'org-agenda-get-day-entries entry
  3046. date args)))
  3047. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3048. (progn
  3049. (insert
  3050. (if (stringp org-agenda-format-date)
  3051. (format-time-string org-agenda-format-date
  3052. (org-time-from-absolute date))
  3053. (funcall org-agenda-format-date date))
  3054. "\n")
  3055. (put-text-property s (1- (point)) 'face
  3056. (org-agenda-get-day-face date))
  3057. (put-text-property s (1- (point)) 'org-date-line t)
  3058. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3059. (if (equal d today)
  3060. (put-text-property s (1- (point)) 'org-today t))
  3061. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3062. (put-text-property s (1- (point)) 'day d)))))
  3063. (goto-char (point-min))
  3064. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3065. (point-min)))
  3066. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3067. (org-finalize-agenda)
  3068. (setq buffer-read-only t)))
  3069. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3070. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3071. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3072. not every single day in the range. If FORCE-TODAY is non-nil, make
  3073. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3074. inactive time stamps (those in square brackets) are included.
  3075. When EMPTY is non-nil, also include days without any entries."
  3076. (let ((re (concat
  3077. (if pre-re pre-re "")
  3078. (if inactive org-ts-regexp-both org-ts-regexp)))
  3079. dates dates1 date day day1 day2 ts1 ts2)
  3080. (if force-today
  3081. (setq dates (list (org-today))))
  3082. (save-excursion
  3083. (goto-char beg)
  3084. (while (re-search-forward re end t)
  3085. (setq day (time-to-days (org-time-string-to-time
  3086. (substring (match-string 1) 0 10))))
  3087. (or (memq day dates) (push day dates)))
  3088. (unless no-ranges
  3089. (goto-char beg)
  3090. (while (re-search-forward org-tr-regexp end t)
  3091. (setq ts1 (substring (match-string 1) 0 10)
  3092. ts2 (substring (match-string 2) 0 10)
  3093. day1 (time-to-days (org-time-string-to-time ts1))
  3094. day2 (time-to-days (org-time-string-to-time ts2)))
  3095. (while (< (setq day1 (1+ day1)) day2)
  3096. (or (memq day1 dates) (push day1 dates)))))
  3097. (setq dates (sort dates '<))
  3098. (when empty
  3099. (while (setq day (pop dates))
  3100. (setq day2 (car dates))
  3101. (push day dates1)
  3102. (when (and day2 empty)
  3103. (if (or (eq empty t)
  3104. (and (numberp empty) (<= (- day2 day) empty)))
  3105. (while (< (setq day (1+ day)) day2)
  3106. (push (list day) dates1))
  3107. (push (cons :omitted (- day2 day)) dates1))))
  3108. (setq dates (nreverse dates1)))
  3109. dates)))
  3110. ;;; Agenda Daily/Weekly
  3111. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3112. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3113. "Custom commands can set this variable in the options section.")
  3114. (defvar org-agenda-last-arguments nil
  3115. "The arguments of the previous call to `org-agenda'.")
  3116. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3117. (defvar org-agenda-current-span nil
  3118. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3119. (defvar org-include-all-loc nil) ; local variable
  3120. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3121. "List of types searched for when creating the daily/weekly agenda.
  3122. This variable is a list of symbols that controls the types of
  3123. items that appear in the daily/weekly agenda. Allowed symbols in this
  3124. list are are
  3125. :timestamp List items containing a date stamp or date range matching
  3126. the selected date. This includes sexp entries in
  3127. angular brackets.
  3128. :sexp List entries resulting from plain diary-like sexps.
  3129. :deadline List deadline due on that date. When the date is today,
  3130. also list any deadlines past due, or due within
  3131. `org-deadline-warning-days'. `:deadline' must appear before
  3132. `:scheduled' if the setting of
  3133. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3134. any effect.
  3135. :scheduled List all items which are scheduled for the given date.
  3136. The diary for *today* also contains items which were
  3137. scheduled earlier and are not yet marked DONE.
  3138. By default, all four types are turned on.
  3139. Never set this variable globally using `setq', because then it
  3140. will apply to all future agenda commands. Instead, bind it with
  3141. `let' to scope it dynamically into the the agenda-constructing
  3142. command. A good way to set it is through options in
  3143. `org-agenda-custom-commands'. For a more flexible (though
  3144. somewhat less efficient) way of determining what is included in
  3145. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3146. ;;;###autoload
  3147. (defun org-agenda-list (&optional include-all start-day span)
  3148. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3149. The view will be for the current day or week, but from the overview buffer
  3150. you will be able to go to other days/weeks.
  3151. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3152. all unfinished TODO items will also be shown, before the agenda.
  3153. This feature is considered obsolete, please use the TODO list or a block
  3154. agenda instead.
  3155. With a numeric prefix argument in an interactive call, the agenda will
  3156. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3157. the number of days. SPAN defaults to `org-agenda-span'.
  3158. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3159. given in `org-agenda-start-on-weekday'."
  3160. (interactive "P")
  3161. (if (and (integerp include-all) (> include-all 0))
  3162. (setq span include-all include-all nil))
  3163. (setq start-day (or start-day org-agenda-start-day))
  3164. (if org-agenda-overriding-arguments
  3165. (setq include-all (car org-agenda-overriding-arguments)
  3166. start-day (nth 1 org-agenda-overriding-arguments)
  3167. span (nth 2 org-agenda-overriding-arguments)))
  3168. (if (stringp start-day)
  3169. ;; Convert to an absolute day number
  3170. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3171. (setq org-agenda-last-arguments (list include-all start-day span))
  3172. (org-compile-prefix-format 'agenda)
  3173. (org-set-sorting-strategy 'agenda)
  3174. (let* ((span (org-agenda-ndays-to-span (or span
  3175. org-agenda-current-span
  3176. org-agenda-ndays
  3177. org-agenda-span)))
  3178. (today (org-today))
  3179. (sd (or start-day today))
  3180. (ndays (org-agenda-span-to-ndays span sd))
  3181. (org-agenda-start-on-weekday
  3182. (if (eq ndays 7)
  3183. org-agenda-start-on-weekday))
  3184. (thefiles (org-agenda-files nil 'ifmode))
  3185. (files thefiles)
  3186. (start (if (or (null org-agenda-start-on-weekday)
  3187. (< ndays 7))
  3188. sd
  3189. (let* ((nt (calendar-day-of-week
  3190. (calendar-gregorian-from-absolute sd)))
  3191. (n1 org-agenda-start-on-weekday)
  3192. (d (- nt n1)))
  3193. (- sd (+ (if (< d 0) 7 0) d)))))
  3194. (day-numbers (list start))
  3195. (day-cnt 0)
  3196. (inhibit-redisplay (not debug-on-error))
  3197. s e rtn rtnall file date d start-pos end-pos todayp
  3198. clocktable-start clocktable-end filter)
  3199. (setq org-agenda-redo-command
  3200. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3201. (dotimes (n (1- ndays))
  3202. (push (1+ (car day-numbers)) day-numbers))
  3203. (setq day-numbers (nreverse day-numbers))
  3204. (setq clocktable-start (car day-numbers)
  3205. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3206. (org-prepare-agenda "Day/Week")
  3207. (org-set-local 'org-starting-day (car day-numbers))
  3208. (org-set-local 'org-include-all-loc include-all)
  3209. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3210. (when (and (or include-all org-agenda-include-all-todo)
  3211. (member today day-numbers))
  3212. (setq files thefiles
  3213. rtnall nil)
  3214. (while (setq file (pop files))
  3215. (catch 'nextfile
  3216. (org-check-agenda-file file)
  3217. (setq date (calendar-gregorian-from-absolute today)
  3218. rtn (org-agenda-get-day-entries
  3219. file date :todo))
  3220. (setq rtnall (append rtnall rtn))))
  3221. (when rtnall
  3222. (insert "All currently open TODO items:\n")
  3223. (add-text-properties (point-min) (1- (point))
  3224. (list 'face 'org-agenda-structure
  3225. 'short-heading "All TODO items"))
  3226. (org-agenda-mark-header-line (point-min))
  3227. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3228. (unless org-agenda-compact-blocks
  3229. (let* ((d1 (car day-numbers))
  3230. (d2 (org-last day-numbers))
  3231. (w1 (org-days-to-iso-week d1))
  3232. (w2 (org-days-to-iso-week d2)))
  3233. (setq s (point))
  3234. (if org-agenda-overriding-header
  3235. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3236. nil 'face 'org-agenda-structure) "\n")
  3237. (insert (org-agenda-span-name span)
  3238. "-agenda"
  3239. (if (< (- d2 d1) 350)
  3240. (if (= w1 w2)
  3241. (format " (W%02d)" w1)
  3242. (format " (W%02d-W%02d)" w1 w2))
  3243. "")
  3244. ":\n")))
  3245. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3246. 'org-date-line t))
  3247. (org-agenda-mark-header-line s))
  3248. (while (setq d (pop day-numbers))
  3249. (setq date (calendar-gregorian-from-absolute d)
  3250. s (point))
  3251. (if (or (setq todayp (= d today))
  3252. (and (not start-pos) (= d sd)))
  3253. (setq start-pos (point))
  3254. (if (and start-pos (not end-pos))
  3255. (setq end-pos (point))))
  3256. (setq files thefiles
  3257. rtnall nil)
  3258. (while (setq file (pop files))
  3259. (catch 'nextfile
  3260. (org-check-agenda-file file)
  3261. (let ((org-agenda-entry-types org-agenda-entry-types))
  3262. (unless org-agenda-include-deadlines
  3263. (setq org-agenda-entry-types
  3264. (delq :deadline org-agenda-entry-types)))
  3265. (cond
  3266. ((eq org-agenda-show-log 'only)
  3267. (setq rtn (org-agenda-get-day-entries
  3268. file date :closed)))
  3269. (org-agenda-show-log
  3270. (setq rtn (apply 'org-agenda-get-day-entries
  3271. file date
  3272. (append '(:closed) org-agenda-entry-types))))
  3273. (t
  3274. (setq rtn (apply 'org-agenda-get-day-entries
  3275. file date
  3276. org-agenda-entry-types)))))
  3277. (setq rtnall (append rtnall rtn))))
  3278. (if org-agenda-include-diary
  3279. (let ((org-agenda-search-headline-for-time t))
  3280. (require 'diary-lib)
  3281. (setq rtn (org-get-entries-from-diary date))
  3282. (setq rtnall (append rtnall rtn))))
  3283. (if (or rtnall org-agenda-show-all-dates)
  3284. (progn
  3285. (setq day-cnt (1+ day-cnt))
  3286. (insert
  3287. (if (stringp org-agenda-format-date)
  3288. (format-time-string org-agenda-format-date
  3289. (org-time-from-absolute date))
  3290. (funcall org-agenda-format-date date))
  3291. "\n")
  3292. (put-text-property s (1- (point)) 'face
  3293. (org-agenda-get-day-face date))
  3294. (put-text-property s (1- (point)) 'org-date-line t)
  3295. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3296. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3297. (when todayp
  3298. (put-text-property s (1- (point)) 'org-today t))
  3299. (if rtnall (insert
  3300. (org-finalize-agenda-entries
  3301. (org-agenda-add-time-grid-maybe
  3302. rtnall ndays todayp))
  3303. "\n"))
  3304. (put-text-property s (1- (point)) 'day d)
  3305. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3306. (when (and org-agenda-clockreport-mode clocktable-start)
  3307. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3308. ;; the above line is to ensure the restricted range!
  3309. (p org-agenda-clockreport-parameter-plist)
  3310. tbl)
  3311. (setq p (org-plist-delete p :block))
  3312. (setq p (plist-put p :tstart clocktable-start))
  3313. (setq p (plist-put p :tend clocktable-end))
  3314. (setq p (plist-put p :scope 'agenda))
  3315. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3316. (setq filter (or org-agenda-filter-while-redo
  3317. (get 'org-agenda-filter :preset-filter))))
  3318. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3319. (if (string-match "[<>=]" x)
  3320. ""
  3321. x))
  3322. filter ""))))
  3323. (message "%s" (plist-get p :tags)) (sit-for 2)
  3324. (setq tbl (apply 'org-get-clocktable p))
  3325. (insert tbl)))
  3326. (goto-char (point-min))
  3327. (or org-agenda-multi (org-fit-agenda-window))
  3328. (unless (and (pos-visible-in-window-p (point-min))
  3329. (pos-visible-in-window-p (point-max)))
  3330. (goto-char (1- (point-max)))
  3331. (recenter -1)
  3332. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3333. (progn
  3334. (goto-char (or start-pos 1))
  3335. (recenter 1))))
  3336. (goto-char (or start-pos 1))
  3337. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3338. (org-finalize-agenda)
  3339. (setq buffer-read-only t)
  3340. (message "")))
  3341. (defun org-agenda-ndays-to-span (n)
  3342. "Return a span symbol for a span of N days, or N if none matches."
  3343. (cond ((symbolp n) n)
  3344. ((= n 1) 'day)
  3345. ((= n 7) 'week)
  3346. (t n)))
  3347. (defun org-agenda-span-to-ndays (span start-day)
  3348. "Return ndays from SPAN starting at START-DAY."
  3349. (cond ((numberp span) span)
  3350. ((eq span 'day) 1)
  3351. ((eq span 'week) 7)
  3352. ((eq span 'month)
  3353. (let ((date (calendar-gregorian-from-absolute start-day)))
  3354. (calendar-last-day-of-month (car date) (caddr date))))
  3355. ((eq span 'year)
  3356. (let ((date (calendar-gregorian-from-absolute start-day)))
  3357. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3358. (defun org-agenda-span-name (span)
  3359. "Return a SPAN name."
  3360. (if (null span)
  3361. ""
  3362. (if (symbolp span)
  3363. (capitalize (symbol-name span))
  3364. (format "%d days" span))))
  3365. ;;; Agenda word search
  3366. (defvar org-agenda-search-history nil)
  3367. (defvar org-todo-only nil)
  3368. (defvar org-search-syntax-table nil
  3369. "Special syntax table for org-mode search.
  3370. In this table, we have single quotes not as word constituents, to
  3371. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3372. (defun org-search-syntax-table ()
  3373. (unless org-search-syntax-table
  3374. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3375. (modify-syntax-entry ?' "." org-search-syntax-table)
  3376. (modify-syntax-entry ?` "." org-search-syntax-table))
  3377. org-search-syntax-table)
  3378. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3379. ;;;###autoload
  3380. (defun org-search-view (&optional todo-only string edit-at)
  3381. "Show all entries that contain a phrase or words or regular expressions.
  3382. With optional prefix argument TODO-ONLY, only consider entries that are
  3383. TODO entries. The argument STRING can be used to pass a default search
  3384. string into this function. If EDIT-AT is non-nil, it means that the
  3385. user should get a chance to edit this string, with cursor at position
  3386. EDIT-AT.
  3387. The search string can be viewed either as a phrase that should be found as
  3388. is, or it can be broken into a number of snippets, each of which must match
  3389. in a Boolean way to select an entry. The default depends on the variable
  3390. `org-agenda-search-view-always-boolean'.
  3391. Even if this is turned off (the default) you can always switch to
  3392. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3393. The default is a direct search of the whole phrase, where each space in
  3394. the search string can expand to an arbitrary amount of whitespace,
  3395. including newlines.
  3396. If using a Boolean search, the search string is split on whitespace and
  3397. each snippet is searched separately, with logical AND to select an entry.
  3398. Words prefixed with a minus must *not* occur in the entry. Words without
  3399. a prefix or prefixed with a plus must occur in the entry. Matching is
  3400. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3401. match whole words, not parts of a word) if
  3402. `org-agenda-search-view-force-full-words' is set (default is nil).
  3403. Boolean search snippets enclosed by curly braces are interpreted as
  3404. regular expressions that must or (when preceded with \"-\") must not
  3405. match in the entry. Snippets enclosed into double quotes will be taken
  3406. as a whole, to include whitespace.
  3407. - If the search string starts with an asterisk, search only in headlines.
  3408. - If (possibly after the leading star) the search string starts with an
  3409. exclamation mark, this also means to look at TODO entries only, an effect
  3410. that can also be achieved with a prefix argument.
  3411. - If (possibly after star and exclamation mark) the search string starts
  3412. with a colon, this will mean that the (non-regexp) snippets of the
  3413. Boolean search must match as full words.
  3414. This command searches the agenda files, and in addition the files listed
  3415. in `org-agenda-text-search-extra-files'."
  3416. (interactive "P")
  3417. (org-compile-prefix-format 'search)
  3418. (org-set-sorting-strategy 'search)
  3419. (org-prepare-agenda "SEARCH")
  3420. (let* ((props (list 'face nil
  3421. 'done-face 'org-agenda-done
  3422. 'org-not-done-regexp org-not-done-regexp
  3423. 'org-todo-regexp org-todo-regexp
  3424. 'org-complex-heading-regexp org-complex-heading-regexp
  3425. 'mouse-face 'highlight
  3426. 'help-echo (format "mouse-2 or RET jump to location")))
  3427. (full-words org-agenda-search-view-force-full-words)
  3428. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3429. regexp rtn rtnall files file pos
  3430. marker category tags c neg re boolean
  3431. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3432. (unless (and (not edit-at)
  3433. (stringp string)
  3434. (string-match "\\S-" string))
  3435. (setq string (read-string
  3436. (if org-agenda-search-view-always-boolean
  3437. "[+-]Word/{Regexp} ...: "
  3438. "Phrase, or [+-]Word/{Regexp} ...: ")
  3439. (cond
  3440. ((integerp edit-at) (cons string edit-at))
  3441. (edit-at string))
  3442. 'org-agenda-search-history)))
  3443. (org-set-local 'org-todo-only todo-only)
  3444. (setq org-agenda-redo-command
  3445. (list 'org-search-view (if todo-only t nil) string
  3446. '(if current-prefix-arg 1 nil)))
  3447. (setq org-agenda-query-string string)
  3448. (if (equal (string-to-char string) ?*)
  3449. (setq hdl-only t
  3450. words (substring string 1))
  3451. (setq words string))
  3452. (when (equal (string-to-char words) ?!)
  3453. (setq todo-only t
  3454. words (substring words 1)))
  3455. (when (equal (string-to-char words) ?:)
  3456. (setq full-words t
  3457. words (substring words 1)))
  3458. (if (or org-agenda-search-view-always-boolean
  3459. (member (string-to-char words) '(?- ?+ ?\{)))
  3460. (setq boolean t))
  3461. (setq words (org-split-string words))
  3462. (let (www w)
  3463. (while (setq w (pop words))
  3464. (while (and (string-match "\\\\\\'" w) words)
  3465. (setq w (concat (substring w 0 -1) " " (pop words))))
  3466. (push w www))
  3467. (setq words (nreverse www) www nil)
  3468. (while (setq w (pop words))
  3469. (when (and (string-match "\\`[-+]?{" w)
  3470. (not (string-match "}\\'" w)))
  3471. (while (and words (not (string-match "}\\'" (car words))))
  3472. (setq w (concat w " " (pop words))))
  3473. (setq w (concat w " " (pop words))))
  3474. (push w www))
  3475. (setq words (nreverse www)))
  3476. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3477. (when boolean
  3478. (let (wds w)
  3479. (while (setq w (pop words))
  3480. (if (or (equal (substring w 0 1) "\"")
  3481. (and (> (length w) 1)
  3482. (member (substring w 0 1) '("+" "-"))
  3483. (equal (substring w 1 2) "\"")))
  3484. (while (and words (not (equal (substring w -1) "\"")))
  3485. (setq w (concat w " " (pop words)))))
  3486. (and (string-match "\\`\\([-+]?\\)\"" w)
  3487. (setq w (replace-match "\\1" nil nil w)))
  3488. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3489. (push w wds))
  3490. (setq words (nreverse wds))))
  3491. (if boolean
  3492. (mapc (lambda (w)
  3493. (setq c (string-to-char w))
  3494. (if (equal c ?-)
  3495. (setq neg t w (substring w 1))
  3496. (if (equal c ?+)
  3497. (setq neg nil w (substring w 1))
  3498. (setq neg nil)))
  3499. (if (string-match "\\`{.*}\\'" w)
  3500. (setq re (substring w 1 -1))
  3501. (if full-words
  3502. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3503. (setq re (regexp-quote (downcase w)))))
  3504. (if neg (push re regexps-) (push re regexps+)))
  3505. words)
  3506. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3507. regexps+))
  3508. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3509. (if (not regexps+)
  3510. (setq regexp (concat "^" org-outline-regexp))
  3511. (setq regexp (pop regexps+))
  3512. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3513. regexp))))
  3514. (setq files (org-agenda-files nil 'ifmode))
  3515. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3516. (pop org-agenda-text-search-extra-files)
  3517. (setq files (org-add-archive-files files)))
  3518. (setq files (append files org-agenda-text-search-extra-files)
  3519. rtnall nil)
  3520. (while (setq file (pop files))
  3521. (setq ee nil)
  3522. (catch 'nextfile
  3523. (org-check-agenda-file file)
  3524. (setq buffer (if (file-exists-p file)
  3525. (org-get-agenda-file-buffer file)
  3526. (error "No such file %s" file)))
  3527. (if (not buffer)
  3528. ;; If file does not exist, make sure an error message is sent
  3529. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3530. file))))
  3531. (with-current-buffer buffer
  3532. (with-syntax-table (org-search-syntax-table)
  3533. (unless (org-mode-p)
  3534. (error "Agenda file %s is not in `org-mode'" file))
  3535. (let ((case-fold-search t))
  3536. (save-excursion
  3537. (save-restriction
  3538. (if org-agenda-restrict
  3539. (narrow-to-region org-agenda-restrict-begin
  3540. org-agenda-restrict-end)
  3541. (widen))
  3542. (goto-char (point-min))
  3543. (unless (or (org-on-heading-p)
  3544. (outline-next-heading))
  3545. (throw 'nextfile t))
  3546. (goto-char (max (point-min) (1- (point))))
  3547. (while (re-search-forward regexp nil t)
  3548. (org-back-to-heading t)
  3549. (skip-chars-forward "* ")
  3550. (setq beg (point-at-bol)
  3551. beg1 (point)
  3552. end (progn (outline-next-heading) (point)))
  3553. (catch :skip
  3554. (goto-char beg)
  3555. (org-agenda-skip)
  3556. (setq str (buffer-substring-no-properties
  3557. (point-at-bol)
  3558. (if hdl-only (point-at-eol) end)))
  3559. (mapc (lambda (wr) (when (string-match wr str)
  3560. (goto-char (1- end))
  3561. (throw :skip t)))
  3562. regexps-)
  3563. (mapc (lambda (wr) (unless (string-match wr str)
  3564. (goto-char (1- end))
  3565. (throw :skip t)))
  3566. (if todo-only
  3567. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3568. regexps+)
  3569. regexps+))
  3570. (goto-char beg)
  3571. (setq marker (org-agenda-new-marker (point))
  3572. category (org-get-category)
  3573. tags (org-get-tags-at (point))
  3574. txt (org-format-agenda-item
  3575. ""
  3576. (buffer-substring-no-properties
  3577. beg1 (point-at-eol))
  3578. category tags))
  3579. (org-add-props txt props
  3580. 'org-marker marker 'org-hd-marker marker
  3581. 'org-todo-regexp org-todo-regexp
  3582. 'org-complex-heading-regexp org-complex-heading-regexp
  3583. 'priority 1000 'org-category category
  3584. 'type "search")
  3585. (push txt ee)
  3586. (goto-char (1- end))))))))))
  3587. (setq rtn (nreverse ee))
  3588. (setq rtnall (append rtnall rtn)))
  3589. (if org-agenda-overriding-header
  3590. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3591. nil 'face 'org-agenda-structure) "\n")
  3592. (insert "Search words: ")
  3593. (add-text-properties (point-min) (1- (point))
  3594. (list 'face 'org-agenda-structure))
  3595. (setq pos (point))
  3596. (insert string "\n")
  3597. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3598. (setq pos (point))
  3599. (unless org-agenda-multi
  3600. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3601. (add-text-properties pos (1- (point))
  3602. (list 'face 'org-agenda-structure))))
  3603. (org-agenda-mark-header-line (point-min))
  3604. (when rtnall
  3605. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3606. (goto-char (point-min))
  3607. (or org-agenda-multi (org-fit-agenda-window))
  3608. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3609. (org-finalize-agenda)
  3610. (setq buffer-read-only t)))
  3611. ;;; Agenda TODO list
  3612. (defvar org-select-this-todo-keyword nil)
  3613. (defvar org-last-arg nil)
  3614. ;;;###autoload
  3615. (defun org-todo-list (arg)
  3616. "Show all (not done) TODO entries from all agenda file in a single list.
  3617. The prefix arg can be used to select a specific TODO keyword and limit
  3618. the list to these. When using \\[universal-argument], you will be prompted
  3619. for a keyword. A numeric prefix directly selects the Nth keyword in
  3620. `org-todo-keywords-1'."
  3621. (interactive "P")
  3622. (org-compile-prefix-format 'todo)
  3623. (org-set-sorting-strategy 'todo)
  3624. (org-prepare-agenda "TODO")
  3625. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3626. (let* ((today (org-today))
  3627. (date (calendar-gregorian-from-absolute today))
  3628. (kwds org-todo-keywords-for-agenda)
  3629. (completion-ignore-case t)
  3630. (org-select-this-todo-keyword
  3631. (if (stringp arg) arg
  3632. (and arg (integerp arg) (> arg 0)
  3633. (nth (1- arg) kwds))))
  3634. rtn rtnall files file pos)
  3635. (when (equal arg '(4))
  3636. (setq org-select-this-todo-keyword
  3637. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3638. (mapcar 'list kwds) nil nil)))
  3639. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3640. (org-set-local 'org-last-arg arg)
  3641. (setq org-agenda-redo-command
  3642. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3643. (setq files (org-agenda-files nil 'ifmode)
  3644. rtnall nil)
  3645. (while (setq file (pop files))
  3646. (catch 'nextfile
  3647. (org-check-agenda-file file)
  3648. (setq rtn (org-agenda-get-day-entries file date :todo))
  3649. (setq rtnall (append rtnall rtn))))
  3650. (if org-agenda-overriding-header
  3651. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3652. nil 'face 'org-agenda-structure) "\n")
  3653. (insert "Global list of TODO items of type: ")
  3654. (add-text-properties (point-min) (1- (point))
  3655. (list 'face 'org-agenda-structure
  3656. 'short-heading
  3657. (concat "ToDo: "
  3658. (or org-select-this-todo-keyword "ALL"))))
  3659. (org-agenda-mark-header-line (point-min))
  3660. (setq pos (point))
  3661. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3662. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3663. (setq pos (point))
  3664. (unless org-agenda-multi
  3665. (insert "Available with `N r': (0)ALL")
  3666. (let ((n 0) s)
  3667. (mapc (lambda (x)
  3668. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3669. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3670. (insert "\n "))
  3671. (insert " " s))
  3672. kwds))
  3673. (insert "\n"))
  3674. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3675. (org-agenda-mark-header-line (point-min))
  3676. (when rtnall
  3677. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3678. (goto-char (point-min))
  3679. (or org-agenda-multi (org-fit-agenda-window))
  3680. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3681. (org-finalize-agenda)
  3682. (setq buffer-read-only t)))
  3683. ;;; Agenda tags match
  3684. ;;;###autoload
  3685. (defun org-tags-view (&optional todo-only match)
  3686. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3687. The prefix arg TODO-ONLY limits the search to TODO entries."
  3688. (interactive "P")
  3689. (org-compile-prefix-format 'tags)
  3690. (org-set-sorting-strategy 'tags)
  3691. (let* ((org-tags-match-list-sublevels
  3692. org-tags-match-list-sublevels)
  3693. (completion-ignore-case t)
  3694. rtn rtnall files file pos matcher
  3695. buffer)
  3696. (when (and (stringp match) (not (string-match "\\S-" match)))
  3697. (setq match nil))
  3698. (setq matcher (org-make-tags-matcher match)
  3699. match (car matcher) matcher (cdr matcher))
  3700. (org-prepare-agenda (concat "TAGS " match))
  3701. (setq org-agenda-query-string match)
  3702. (setq org-agenda-redo-command
  3703. (list 'org-tags-view (list 'quote todo-only)
  3704. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3705. (setq files (org-agenda-files nil 'ifmode)
  3706. rtnall nil)
  3707. (while (setq file (pop files))
  3708. (catch 'nextfile
  3709. (org-check-agenda-file file)
  3710. (setq buffer (if (file-exists-p file)
  3711. (org-get-agenda-file-buffer file)
  3712. (error "No such file %s" file)))
  3713. (if (not buffer)
  3714. ;; If file does not exist, error message to agenda
  3715. (setq rtn (list
  3716. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3717. rtnall (append rtnall rtn))
  3718. (with-current-buffer buffer
  3719. (unless (org-mode-p)
  3720. (error "Agenda file %s is not in `org-mode'" file))
  3721. (save-excursion
  3722. (save-restriction
  3723. (if org-agenda-restrict
  3724. (narrow-to-region org-agenda-restrict-begin
  3725. org-agenda-restrict-end)
  3726. (widen))
  3727. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3728. (setq rtnall (append rtnall rtn))))))))
  3729. (if org-agenda-overriding-header
  3730. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3731. nil 'face 'org-agenda-structure) "\n")
  3732. (insert "Headlines with TAGS match: ")
  3733. (add-text-properties (point-min) (1- (point))
  3734. (list 'face 'org-agenda-structure
  3735. 'short-heading
  3736. (concat "Match: " match)))
  3737. (setq pos (point))
  3738. (insert match "\n")
  3739. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3740. (setq pos (point))
  3741. (unless org-agenda-multi
  3742. (insert "Press `C-u r' to search again with new search string\n"))
  3743. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3744. (org-agenda-mark-header-line (point-min))
  3745. (when rtnall
  3746. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3747. (goto-char (point-min))
  3748. (or org-agenda-multi (org-fit-agenda-window))
  3749. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3750. (org-finalize-agenda)
  3751. (setq buffer-read-only t)))
  3752. ;;; Agenda Finding stuck projects
  3753. (defvar org-agenda-skip-regexp nil
  3754. "Regular expression used in skipping subtrees for the agenda.
  3755. This is basically a temporary global variable that can be set and then
  3756. used by user-defined selections using `org-agenda-skip-function'.")
  3757. (defvar org-agenda-overriding-header nil
  3758. "When this is set during todo and tags searches, will replace header.
  3759. This variable should not be set directly, but custom commands can bind it
  3760. in the options section.")
  3761. (defun org-agenda-skip-entry-when-regexp-matches ()
  3762. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3763. If yes, it returns the end position of this entry, causing agenda commands
  3764. to skip the entry but continuing the search in the subtree. This is a
  3765. function that can be put into `org-agenda-skip-function' for the duration
  3766. of a command."
  3767. (let ((end (save-excursion (org-end-of-subtree t)))
  3768. skip)
  3769. (save-excursion
  3770. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3771. (and skip end)))
  3772. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3773. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3774. If yes, it returns the end position of this tree, causing agenda commands
  3775. to skip this subtree. This is a function that can be put into
  3776. `org-agenda-skip-function' for the duration of a command."
  3777. (let ((end (save-excursion (org-end-of-subtree t)))
  3778. skip)
  3779. (save-excursion
  3780. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3781. (and skip end)))
  3782. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3783. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3784. If yes, it returns the end position of the current entry (NOT the tree),
  3785. causing agenda commands to skip the entry but continuing the search in
  3786. the subtree. This is a function that can be put into
  3787. `org-agenda-skip-function' for the duration of a command. An important
  3788. use of this function is for the stuck project list."
  3789. (let ((end (save-excursion (org-end-of-subtree t)))
  3790. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3791. skip)
  3792. (save-excursion
  3793. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3794. (and skip entry-end)))
  3795. (defun org-agenda-skip-entry-if (&rest conditions)
  3796. "Skip entry if any of CONDITIONS is true.
  3797. See `org-agenda-skip-if' for details."
  3798. (org-agenda-skip-if nil conditions))
  3799. (defun org-agenda-skip-subtree-if (&rest conditions)
  3800. "Skip entry if any of CONDITIONS is true.
  3801. See `org-agenda-skip-if' for details."
  3802. (org-agenda-skip-if t conditions))
  3803. (defun org-agenda-skip-if (subtree conditions)
  3804. "Checks current entity for CONDITIONS.
  3805. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3806. the entry, i.e. the text before the next heading is checked.
  3807. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3808. from different tests. Valid conditions are:
  3809. scheduled Check if there is a scheduled cookie
  3810. notscheduled Check if there is no scheduled cookie
  3811. deadline Check if there is a deadline
  3812. notdeadline Check if there is no deadline
  3813. timestamp Check if there is a timestamp (also deadline or scheduled)
  3814. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3815. regexp Check if regexp matches
  3816. notregexp Check if regexp does not match.
  3817. todo Check if TODO keyword matches
  3818. nottodo Check if TODO keyword does not match
  3819. The regexp is taken from the conditions list, it must come right after
  3820. the `regexp' or `notregexp' element.
  3821. `todo' and `nottodo' accept as an argument a list of todo
  3822. keywords, which may include \"*\" to match any todo keyword.
  3823. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3824. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3825. Instead of a list a keyword class may be given
  3826. (org-agenda-skip-entry-if 'nottodo 'done)
  3827. would skip entries that haven't been marked with any of \"DONE\"
  3828. keywords. Possible classes are: `todo', `done', `any'.
  3829. If any of these conditions is met, this function returns the end point of
  3830. the entity, causing the search to continue from there. This is a function
  3831. that can be put into `org-agenda-skip-function' for the duration of a command."
  3832. (let (beg end m)
  3833. (org-back-to-heading t)
  3834. (setq beg (point)
  3835. end (if subtree
  3836. (progn (org-end-of-subtree t) (point))
  3837. (progn (outline-next-heading) (1- (point)))))
  3838. (goto-char beg)
  3839. (and
  3840. (or
  3841. (and (memq 'scheduled conditions)
  3842. (re-search-forward org-scheduled-time-regexp end t))
  3843. (and (memq 'notscheduled conditions)
  3844. (not (re-search-forward org-scheduled-time-regexp end t)))
  3845. (and (memq 'deadline conditions)
  3846. (re-search-forward org-deadline-time-regexp end t))
  3847. (and (memq 'notdeadline conditions)
  3848. (not (re-search-forward org-deadline-time-regexp end t)))
  3849. (and (memq 'timestamp conditions)
  3850. (re-search-forward org-ts-regexp end t))
  3851. (and (memq 'nottimestamp conditions)
  3852. (not (re-search-forward org-ts-regexp end t)))
  3853. (and (setq m (memq 'regexp conditions))
  3854. (stringp (nth 1 m))
  3855. (re-search-forward (nth 1 m) end t))
  3856. (and (setq m (memq 'notregexp conditions))
  3857. (stringp (nth 1 m))
  3858. (not (re-search-forward (nth 1 m) end t)))
  3859. (and (or
  3860. (setq m (memq 'todo conditions))
  3861. (setq m (memq 'nottodo conditions)))
  3862. (org-agenda-skip-if-todo m end)))
  3863. end)))
  3864. (defun org-agenda-skip-if-todo (args end)
  3865. "Helper function for `org-agenda-skip-if', do not use it directly.
  3866. ARGS is a list with first element either `todo' or `nottodo'.
  3867. The remainder is either a list of TODO keywords, or a state symbol
  3868. `todo' or `done' or `any'."
  3869. (let ((kw (car args))
  3870. (arg (cadr args))
  3871. todo-wds todo-re)
  3872. (setq todo-wds
  3873. (org-uniquify
  3874. (cond
  3875. ((listp arg) ;; list of keywords
  3876. (if (member "*" arg)
  3877. (mapcar 'substring-no-properties org-todo-keywords-1)
  3878. arg))
  3879. ((symbolp arg) ;; keyword class name
  3880. (cond
  3881. ((eq arg 'todo)
  3882. (org-delete-all org-done-keywords
  3883. (mapcar 'substring-no-properties
  3884. org-todo-keywords-1)))
  3885. ((eq arg 'done) org-done-keywords)
  3886. ((eq arg 'any)
  3887. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3888. (setq todo-re
  3889. (concat "^\\*+[ \t]+\\<\\("
  3890. (mapconcat 'identity todo-wds "\\|")
  3891. "\\)\\>"))
  3892. (if (eq kw 'todo)
  3893. (re-search-forward todo-re end t)
  3894. (not (re-search-forward todo-re end t)))))
  3895. ;;;###autoload
  3896. (defun org-agenda-list-stuck-projects (&rest ignore)
  3897. "Create agenda view for projects that are stuck.
  3898. Stuck projects are project that have no next actions. For the definitions
  3899. of what a project is and how to check if it stuck, customize the variable
  3900. `org-stuck-projects'."
  3901. (interactive)
  3902. (let* ((org-agenda-skip-function
  3903. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3904. ;; We could have used org-agenda-skip-if here.
  3905. (org-agenda-overriding-header
  3906. (or org-agenda-overriding-header "List of stuck projects: "))
  3907. (matcher (nth 0 org-stuck-projects))
  3908. (todo (nth 1 org-stuck-projects))
  3909. (todo-wds (if (member "*" todo)
  3910. (progn
  3911. (org-prepare-agenda-buffers (org-agenda-files
  3912. nil 'ifmode))
  3913. (org-delete-all
  3914. org-done-keywords-for-agenda
  3915. (copy-sequence org-todo-keywords-for-agenda)))
  3916. todo))
  3917. (todo-re (concat "^\\*+[ \t]+\\("
  3918. (mapconcat 'identity todo-wds "\\|")
  3919. "\\)\\>"))
  3920. (tags (nth 2 org-stuck-projects))
  3921. (tags-re (if (member "*" tags)
  3922. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3923. (if tags
  3924. (concat "^\\*+ .*:\\("
  3925. (mapconcat 'identity tags "\\|")
  3926. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3927. (gen-re (nth 3 org-stuck-projects))
  3928. (re-list
  3929. (delq nil
  3930. (list
  3931. (if todo todo-re)
  3932. (if tags tags-re)
  3933. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3934. gen-re)))))
  3935. (setq org-agenda-skip-regexp
  3936. (if re-list
  3937. (mapconcat 'identity re-list "\\|")
  3938. (error "No information how to identify unstuck projects")))
  3939. (org-tags-view nil matcher)
  3940. (with-current-buffer org-agenda-buffer-name
  3941. (setq org-agenda-redo-command
  3942. '(org-agenda-list-stuck-projects
  3943. (or current-prefix-arg org-last-arg))))))
  3944. ;;; Diary integration
  3945. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3946. (defvar list-diary-entries-hook)
  3947. (defun org-get-entries-from-diary (date)
  3948. "Get the (Emacs Calendar) diary entries for DATE."
  3949. (require 'diary-lib)
  3950. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3951. (diary-display-hook '(fancy-diary-display))
  3952. (diary-display-function 'fancy-diary-display)
  3953. (pop-up-frames nil)
  3954. (list-diary-entries-hook
  3955. (cons 'org-diary-default-entry list-diary-entries-hook))
  3956. (diary-file-name-prefix-function nil) ; turn this feature off
  3957. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3958. entries
  3959. (org-disable-agenda-to-diary t))
  3960. (save-excursion
  3961. (save-window-excursion
  3962. (funcall (if (fboundp 'diary-list-entries)
  3963. 'diary-list-entries 'list-diary-entries)
  3964. date 1)))
  3965. (if (not (get-buffer diary-fancy-buffer))
  3966. (setq entries nil)
  3967. (with-current-buffer diary-fancy-buffer
  3968. (setq buffer-read-only nil)
  3969. (if (zerop (buffer-size))
  3970. ;; No entries
  3971. (setq entries nil)
  3972. ;; Omit the date and other unnecessary stuff
  3973. (org-agenda-cleanup-fancy-diary)
  3974. ;; Add prefix to each line and extend the text properties
  3975. (if (zerop (buffer-size))
  3976. (setq entries nil)
  3977. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3978. (set-buffer-modified-p nil)
  3979. (kill-buffer diary-fancy-buffer)))
  3980. (when entries
  3981. (setq entries (org-split-string entries "\n"))
  3982. (setq entries
  3983. (mapcar
  3984. (lambda (x)
  3985. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3986. ;; Extend the text properties to the beginning of the line
  3987. (org-add-props x (text-properties-at (1- (length x)) x)
  3988. 'type "diary" 'date date 'face 'org-agenda-diary))
  3989. entries)))))
  3990. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3991. "Hook run when the fancy diary buffer is cleaned up.")
  3992. (defun org-agenda-cleanup-fancy-diary ()
  3993. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3994. This gets rid of the date, the underline under the date, and
  3995. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3996. date. It also removes lines that contain only whitespace."
  3997. (goto-char (point-min))
  3998. (if (looking-at ".*?:[ \t]*")
  3999. (progn
  4000. (replace-match "")
  4001. (re-search-forward "\n=+$" nil t)
  4002. (replace-match "")
  4003. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4004. (re-search-forward "\n=+$" nil t)
  4005. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4006. (goto-char (point-min))
  4007. (while (re-search-forward "^ +\n" nil t)
  4008. (replace-match ""))
  4009. (goto-char (point-min))
  4010. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4011. (replace-match ""))
  4012. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4013. ;; Make sure entries from the diary have the right text properties.
  4014. (eval-after-load "diary-lib"
  4015. '(if (boundp 'diary-modify-entry-list-string-function)
  4016. ;; We can rely on the hook, nothing to do
  4017. nil
  4018. ;; Hook not available, must use advice to make this work
  4019. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4020. "Make the position visible."
  4021. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4022. (stringp string)
  4023. buffer-file-name)
  4024. (setq string (org-modify-diary-entry-string string))))))
  4025. (defun org-modify-diary-entry-string (string)
  4026. "Add text properties to string, allowing org-mode to act on it."
  4027. (org-add-props string nil
  4028. 'mouse-face 'highlight
  4029. 'help-echo (if buffer-file-name
  4030. (format "mouse-2 or RET jump to diary file %s"
  4031. (abbreviate-file-name buffer-file-name))
  4032. "")
  4033. 'org-agenda-diary-link t
  4034. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4035. (defun org-diary-default-entry ()
  4036. "Add a dummy entry to the diary.
  4037. Needed to avoid empty dates which mess up holiday display."
  4038. ;; Catch the error if dealing with the new add-to-diary-alist
  4039. (when org-disable-agenda-to-diary
  4040. (condition-case nil
  4041. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4042. (error
  4043. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4044. (defun org-add-to-diary-list (&rest args)
  4045. (if (fboundp 'diary-add-to-list)
  4046. (apply 'diary-add-to-list args)
  4047. (apply 'add-to-diary-list args)))
  4048. (defvar org-diary-last-run-time nil)
  4049. ;;;###autoload
  4050. (defun org-diary (&rest args)
  4051. "Return diary information from org-files.
  4052. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4053. It accesses org files and extracts information from those files to be
  4054. listed in the diary. The function accepts arguments specifying what
  4055. items should be listed. For a list of arguments allowed here, see the
  4056. variable `org-agenda-entry-types'.
  4057. The call in the diary file should look like this:
  4058. &%%(org-diary) ~/path/to/some/orgfile.org
  4059. Use a separate line for each org file to check. Or, if you omit the file name,
  4060. all files listed in `org-agenda-files' will be checked automatically:
  4061. &%%(org-diary)
  4062. If you don't give any arguments (as in the example above), the default
  4063. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4064. So the example above may also be written as
  4065. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4066. The function expects the lisp variables `entry' and `date' to be provided
  4067. by the caller, because this is how the calendar works. Don't use this
  4068. function from a program - use `org-agenda-get-day-entries' instead."
  4069. (when (> (- (org-float-time)
  4070. org-agenda-last-marker-time)
  4071. 5)
  4072. (org-agenda-reset-markers))
  4073. (org-compile-prefix-format 'agenda)
  4074. (org-set-sorting-strategy 'agenda)
  4075. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4076. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4077. (list entry)
  4078. (org-agenda-files t)))
  4079. (time (org-float-time))
  4080. file rtn results)
  4081. (when (or (not org-diary-last-run-time)
  4082. (> (- time
  4083. org-diary-last-run-time)
  4084. 3))
  4085. (org-prepare-agenda-buffers files))
  4086. (setq org-diary-last-run-time time)
  4087. ;; If this is called during org-agenda, don't return any entries to
  4088. ;; the calendar. Org Agenda will list these entries itself.
  4089. (if org-disable-agenda-to-diary (setq files nil))
  4090. (while (setq file (pop files))
  4091. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4092. (setq results (append results rtn)))
  4093. (if results
  4094. (concat (org-finalize-agenda-entries results) "\n"))))
  4095. ;;; Agenda entry finders
  4096. (defun org-agenda-get-day-entries (file date &rest args)
  4097. "Does the work for `org-diary' and `org-agenda'.
  4098. FILE is the path to a file to be checked for entries. DATE is date like
  4099. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4100. which kind of entries should be extracted. For details about these, see
  4101. the documentation of `org-diary'."
  4102. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4103. (let* ((org-startup-folded nil)
  4104. (org-startup-align-all-tables nil)
  4105. (buffer (if (file-exists-p file)
  4106. (org-get-agenda-file-buffer file)
  4107. (error "No such file %s" file)))
  4108. arg results rtn deadline-results)
  4109. (if (not buffer)
  4110. ;; If file does not exist, make sure an error message ends up in diary
  4111. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4112. (with-current-buffer buffer
  4113. (unless (org-mode-p)
  4114. (error "Agenda file %s is not in `org-mode'" file))
  4115. (let ((case-fold-search nil))
  4116. (save-excursion
  4117. (save-restriction
  4118. (if org-agenda-restrict
  4119. (narrow-to-region org-agenda-restrict-begin
  4120. org-agenda-restrict-end)
  4121. (widen))
  4122. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4123. (while (setq arg (pop args))
  4124. (cond
  4125. ((and (eq arg :todo)
  4126. (equal date (calendar-current-date)))
  4127. (setq rtn (org-agenda-get-todos))
  4128. (setq results (append results rtn)))
  4129. ((eq arg :timestamp)
  4130. (setq rtn (org-agenda-get-blocks))
  4131. (setq results (append results rtn))
  4132. (setq rtn (org-agenda-get-timestamps))
  4133. (setq results (append results rtn)))
  4134. ((eq arg :sexp)
  4135. (setq rtn (org-agenda-get-sexps))
  4136. (setq results (append results rtn)))
  4137. ((eq arg :scheduled)
  4138. (setq rtn (org-agenda-get-scheduled deadline-results))
  4139. (setq results (append results rtn)))
  4140. ((eq arg :closed)
  4141. (setq rtn (org-agenda-get-progress))
  4142. (setq results (append results rtn)))
  4143. ((eq arg :deadline)
  4144. (setq rtn (org-agenda-get-deadlines))
  4145. (setq deadline-results (copy-sequence rtn))
  4146. (setq results (append results rtn))))))))
  4147. results))))
  4148. (defun org-agenda-get-todos ()
  4149. "Return the TODO information for agenda display."
  4150. (let* ((props (list 'face nil
  4151. 'done-face 'org-agenda-done
  4152. 'org-not-done-regexp org-not-done-regexp
  4153. 'org-todo-regexp org-todo-regexp
  4154. 'org-complex-heading-regexp org-complex-heading-regexp
  4155. 'mouse-face 'highlight
  4156. 'help-echo
  4157. (format "mouse-2 or RET jump to org file %s"
  4158. (abbreviate-file-name buffer-file-name))))
  4159. (regexp (concat "^\\*+[ \t]+\\("
  4160. (if org-select-this-todo-keyword
  4161. (if (equal org-select-this-todo-keyword "*")
  4162. org-todo-regexp
  4163. (concat "\\<\\("
  4164. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4165. "\\)\\>"))
  4166. org-not-done-regexp)
  4167. "[^\n\r]*\\)"))
  4168. marker priority category tags todo-state
  4169. ee txt beg end)
  4170. (goto-char (point-min))
  4171. (while (re-search-forward regexp nil t)
  4172. (catch :skip
  4173. (save-match-data
  4174. (beginning-of-line)
  4175. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4176. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4177. (goto-char (1+ beg))
  4178. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4179. (throw :skip nil)))
  4180. (goto-char beg)
  4181. (org-agenda-skip)
  4182. (goto-char (match-beginning 1))
  4183. (setq marker (org-agenda-new-marker (match-beginning 0))
  4184. category (org-get-category)
  4185. txt (match-string 1)
  4186. tags (org-get-tags-at (point))
  4187. txt (org-format-agenda-item "" txt category tags)
  4188. priority (1+ (org-get-priority txt))
  4189. todo-state (org-get-todo-state))
  4190. (org-add-props txt props
  4191. 'org-marker marker 'org-hd-marker marker
  4192. 'priority priority 'org-category category
  4193. 'type "todo" 'todo-state todo-state)
  4194. (push txt ee)
  4195. (if org-agenda-todo-list-sublevels
  4196. (goto-char (match-end 1))
  4197. (org-end-of-subtree 'invisible))))
  4198. (nreverse ee)))
  4199. (defun org-agenda-todo-custom-ignore-p (time n)
  4200. "Check whether timestamp is farther away then n number of days.
  4201. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4202. `org-agenda-todo-ignore-scheduled' or
  4203. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4204. (let ((days (org-days-to-time time)))
  4205. (if (>= n 0)
  4206. (>= days n)
  4207. (<= days n))))
  4208. ;;;###autoload
  4209. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4210. (&optional end)
  4211. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4212. (when (or org-agenda-todo-ignore-with-date
  4213. org-agenda-todo-ignore-scheduled
  4214. org-agenda-todo-ignore-deadlines
  4215. org-agenda-todo-ignore-timestamp)
  4216. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4217. (save-excursion
  4218. (or (and org-agenda-todo-ignore-with-date
  4219. (re-search-forward org-ts-regexp end t))
  4220. (and org-agenda-todo-ignore-scheduled
  4221. (re-search-forward org-scheduled-time-regexp end t)
  4222. (cond
  4223. ((eq org-agenda-todo-ignore-scheduled 'future)
  4224. (> (org-days-to-time (match-string 1)) 0))
  4225. ((eq org-agenda-todo-ignore-scheduled 'past)
  4226. (<= (org-days-to-time (match-string 1)) 0))
  4227. ((numberp org-agenda-todo-ignore-scheduled)
  4228. (org-agenda-todo-custom-ignore-p
  4229. (match-string 1) org-agenda-todo-ignore-scheduled))
  4230. (t)))
  4231. (and org-agenda-todo-ignore-deadlines
  4232. (re-search-forward org-deadline-time-regexp end t)
  4233. (cond
  4234. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4235. ((eq org-agenda-todo-ignore-deadlines 'far)
  4236. (not (org-deadline-close (match-string 1))))
  4237. ((eq org-agenda-todo-ignore-deadlines 'future)
  4238. (> (org-days-to-time (match-string 1)) 0))
  4239. ((eq org-agenda-todo-ignore-deadlines 'past)
  4240. (<= (org-days-to-time (match-string 1)) 0))
  4241. ((numberp org-agenda-todo-ignore-deadlines)
  4242. (org-agenda-todo-custom-ignore-p
  4243. (match-string 1) org-agenda-todo-ignore-deadlines))
  4244. (t (org-deadline-close (match-string 1)))))
  4245. (and org-agenda-todo-ignore-timestamp
  4246. (let ((buffer (current-buffer))
  4247. (regexp
  4248. (concat
  4249. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4250. (start (point)))
  4251. ;; Copy current buffer into a temporary one
  4252. (with-temp-buffer
  4253. (insert-buffer-substring buffer start end)
  4254. (goto-char (point-min))
  4255. ;; Delete SCHEDULED and DEADLINE items
  4256. (while (re-search-forward regexp end t)
  4257. (delete-region (match-beginning 0) (match-end 0)))
  4258. (goto-char (point-min))
  4259. ;; No search for timestamp left
  4260. (when (re-search-forward org-ts-regexp nil t)
  4261. (cond
  4262. ((eq org-agenda-todo-ignore-timestamp 'future)
  4263. (> (org-days-to-time (match-string 1)) 0))
  4264. ((eq org-agenda-todo-ignore-timestamp 'past)
  4265. (<= (org-days-to-time (match-string 1)) 0))
  4266. ((numberp org-agenda-todo-ignore-timestamp)
  4267. (org-agenda-todo-custom-ignore-p
  4268. (match-string 1) org-agenda-todo-ignore-timestamp))
  4269. (t))))))))))
  4270. (defconst org-agenda-no-heading-message
  4271. "No heading for this item in buffer or region.")
  4272. (defun org-agenda-get-timestamps ()
  4273. "Return the date stamp information for agenda display."
  4274. (let* ((props (list 'face nil
  4275. 'org-not-done-regexp org-not-done-regexp
  4276. 'org-todo-regexp org-todo-regexp
  4277. 'org-complex-heading-regexp org-complex-heading-regexp
  4278. 'mouse-face 'highlight
  4279. 'help-echo
  4280. (format "mouse-2 or RET jump to org file %s"
  4281. (abbreviate-file-name buffer-file-name))))
  4282. (d1 (calendar-absolute-from-gregorian date))
  4283. (remove-re
  4284. (concat
  4285. (regexp-quote
  4286. (format-time-string
  4287. "<%Y-%m-%d"
  4288. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4289. ".*?>"))
  4290. (regexp
  4291. (concat
  4292. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4293. (regexp-quote
  4294. (substring
  4295. (format-time-string
  4296. (car org-time-stamp-formats)
  4297. (apply 'encode-time ; DATE bound by calendar
  4298. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4299. 1 11))
  4300. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4301. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4302. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4303. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4304. todo-state end-of-match)
  4305. (goto-char (point-min))
  4306. (while (setq end-of-match (re-search-forward regexp nil t))
  4307. (setq b0 (match-beginning 0)
  4308. b3 (match-beginning 3) e3 (match-end 3)
  4309. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4310. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4311. (member todo-state
  4312. org-agenda-repeating-timestamp-show-all)))
  4313. (catch :skip
  4314. (and (org-at-date-range-p) (throw :skip nil))
  4315. (org-agenda-skip)
  4316. (if (and (match-end 1)
  4317. (not (= d1 (org-time-string-to-absolute
  4318. (match-string 1) d1 nil show-all))))
  4319. (throw :skip nil))
  4320. (if (and e3
  4321. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4322. (throw :skip nil))
  4323. (setq tmp (buffer-substring (max (point-min)
  4324. (- b0 org-ds-keyword-length))
  4325. b0)
  4326. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4327. inactivep (= (char-after b0) ?\[)
  4328. deadlinep (string-match org-deadline-regexp tmp)
  4329. scheduledp (string-match org-scheduled-regexp tmp)
  4330. closedp (and org-agenda-include-inactive-timestamps
  4331. (string-match org-closed-string tmp))
  4332. clockp (and org-agenda-include-inactive-timestamps
  4333. (or (string-match org-clock-string tmp)
  4334. (string-match "]-+\\'" tmp)))
  4335. donep (member todo-state org-done-keywords))
  4336. (if (or scheduledp deadlinep closedp clockp
  4337. (and donep org-agenda-skip-timestamp-if-done))
  4338. (throw :skip t))
  4339. (if (string-match ">" timestr)
  4340. ;; substring should only run to end of time stamp
  4341. (setq timestr (substring timestr 0 (match-end 0))))
  4342. (setq marker (org-agenda-new-marker b0)
  4343. category (org-get-category b0))
  4344. (save-excursion
  4345. (if (not (re-search-backward "^\\*+ " nil t))
  4346. (setq txt org-agenda-no-heading-message)
  4347. (goto-char (match-beginning 0))
  4348. (setq hdmarker (org-agenda-new-marker)
  4349. tags (org-get-tags-at))
  4350. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4351. (setq head (match-string 1))
  4352. (setq txt (org-format-agenda-item
  4353. (if inactivep org-agenda-inactive-leader nil)
  4354. head category tags timestr nil
  4355. remove-re)))
  4356. (setq priority (org-get-priority txt))
  4357. (org-add-props txt props
  4358. 'org-marker marker 'org-hd-marker hdmarker)
  4359. (org-add-props txt nil 'priority priority
  4360. 'org-category category 'date date
  4361. 'todo-state todo-state
  4362. 'type "timestamp")
  4363. (push txt ee))
  4364. (if org-agenda-skip-additional-timestamps-same-entry
  4365. (outline-next-heading)
  4366. (goto-char end-of-match))))
  4367. (nreverse ee)))
  4368. (defun org-agenda-get-sexps ()
  4369. "Return the sexp information for agenda display."
  4370. (require 'diary-lib)
  4371. (let* ((props (list 'mouse-face 'highlight
  4372. 'help-echo
  4373. (format "mouse-2 or RET jump to org file %s"
  4374. (abbreviate-file-name buffer-file-name))))
  4375. (regexp "^&?%%(")
  4376. marker category ee txt tags entry result beg b sexp sexp-entry
  4377. todo-state)
  4378. (goto-char (point-min))
  4379. (while (re-search-forward regexp nil t)
  4380. (catch :skip
  4381. (org-agenda-skip)
  4382. (setq beg (match-beginning 0))
  4383. (goto-char (1- (match-end 0)))
  4384. (setq b (point))
  4385. (forward-sexp 1)
  4386. (setq sexp (buffer-substring b (point)))
  4387. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4388. (org-trim (match-string 1))
  4389. ""))
  4390. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4391. (when result
  4392. (setq marker (org-agenda-new-marker beg)
  4393. category (org-get-category beg)
  4394. todo-state (org-get-todo-state))
  4395. (dolist (r (if (stringp result)
  4396. (list result)
  4397. result)) ;; we expect a list here
  4398. (if (string-match "\\S-" r)
  4399. (setq txt r)
  4400. (setq txt "SEXP entry returned empty string"))
  4401. (setq txt (org-format-agenda-item
  4402. "" txt category tags 'time))
  4403. (org-add-props txt props 'org-marker marker)
  4404. (org-add-props txt nil
  4405. 'org-category category 'date date 'todo-state todo-state
  4406. 'type "sexp")
  4407. (push txt ee)))))
  4408. (nreverse ee)))
  4409. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4410. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4411. The order of the first 2 times 3 arguments depends on the variable
  4412. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4413. So for American calendars, give this as MONTH DAY YEAR, for European as
  4414. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4415. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4416. is any number of ISO weeks in the block period for which the item should
  4417. be skipped."
  4418. (let* ((date1 (calendar-absolute-from-gregorian
  4419. (org-order-calendar-date-args m1 d1 y1)))
  4420. (date2 (calendar-absolute-from-gregorian
  4421. (org-order-calendar-date-args m2 d2 y2)))
  4422. (d (calendar-absolute-from-gregorian date)))
  4423. (and
  4424. (<= date1 d)
  4425. (<= d date2)
  4426. (= (calendar-day-of-week date) dayname)
  4427. (or (not skip-weeks)
  4428. (progn
  4429. (require 'cal-iso)
  4430. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4431. entry)))
  4432. (defalias 'org-get-closed 'org-agenda-get-progress)
  4433. (defun org-agenda-get-progress ()
  4434. "Return the logged TODO entries for agenda display."
  4435. (let* ((props (list 'mouse-face 'highlight
  4436. 'org-not-done-regexp org-not-done-regexp
  4437. 'org-todo-regexp org-todo-regexp
  4438. 'org-complex-heading-regexp org-complex-heading-regexp
  4439. 'help-echo
  4440. (format "mouse-2 or RET jump to org file %s"
  4441. (abbreviate-file-name buffer-file-name))))
  4442. (items (if (consp org-agenda-show-log)
  4443. org-agenda-show-log
  4444. org-agenda-log-mode-items))
  4445. (parts
  4446. (delq nil
  4447. (list
  4448. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4449. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4450. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4451. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4452. (error "`org-agenda-log-mode-items' is empty")))
  4453. (regexp (concat
  4454. "\\(" parts-re "\\)"
  4455. " *\\["
  4456. (regexp-quote
  4457. (substring
  4458. (format-time-string
  4459. (car org-time-stamp-formats)
  4460. (apply 'encode-time ; DATE bound by calendar
  4461. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4462. 1 11))))
  4463. (org-agenda-search-headline-for-time nil)
  4464. marker hdmarker priority category tags closedp statep clockp state
  4465. ee txt extra timestr rest clocked)
  4466. (goto-char (point-min))
  4467. (while (re-search-forward regexp nil t)
  4468. (catch :skip
  4469. (org-agenda-skip)
  4470. (setq marker (org-agenda-new-marker (match-beginning 0))
  4471. closedp (equal (match-string 1) org-closed-string)
  4472. statep (equal (string-to-char (match-string 1)) ?-)
  4473. clockp (not (or closedp statep))
  4474. state (and statep (match-string 2))
  4475. category (org-get-category (match-beginning 0))
  4476. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4477. )
  4478. (when (string-match "\\]" timestr)
  4479. ;; substring should only run to end of time stamp
  4480. (setq rest (substring timestr (match-end 0))
  4481. timestr (substring timestr 0 (match-end 0)))
  4482. (if (and (not closedp) (not statep)
  4483. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4484. (progn (setq timestr (concat (substring timestr 0 -1)
  4485. "-" (match-string 1 rest) "]"))
  4486. (setq clocked (match-string 2 rest)))
  4487. (setq clocked "-")))
  4488. (save-excursion
  4489. (setq extra
  4490. (cond
  4491. ((not org-agenda-log-mode-add-notes) nil)
  4492. (statep
  4493. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4494. (match-string 1)))
  4495. (clockp
  4496. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4497. (match-string 1)))))
  4498. (if (not (re-search-backward "^\\*+ " nil t))
  4499. (setq txt org-agenda-no-heading-message)
  4500. (goto-char (match-beginning 0))
  4501. (setq hdmarker (org-agenda-new-marker)
  4502. tags (org-get-tags-at))
  4503. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4504. (setq txt (match-string 1))
  4505. (when extra
  4506. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4507. (setq txt (concat (substring txt 0 (match-beginning 1))
  4508. " - " extra " " (match-string 2 txt)))
  4509. (setq txt (concat txt " - " extra))))
  4510. (setq txt (org-format-agenda-item
  4511. (cond
  4512. (closedp "Closed: ")
  4513. (statep (concat "State: (" state ")"))
  4514. (t (concat "Clocked: (" clocked ")")))
  4515. txt category tags timestr)))
  4516. (setq priority 100000)
  4517. (org-add-props txt props
  4518. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4519. 'priority priority 'org-category category
  4520. 'type "closed" 'date date
  4521. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4522. (push txt ee))
  4523. (goto-char (point-at-eol))))
  4524. (nreverse ee)))
  4525. (defun org-agenda-get-deadlines ()
  4526. "Return the deadline information 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. (regexp org-deadline-time-regexp)
  4535. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4536. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4537. d2 diff dfrac wdays pos pos1 category tags
  4538. suppress-prewarning
  4539. ee txt head face s todo-state show-all upcomingp donep timestr)
  4540. (goto-char (point-min))
  4541. (while (re-search-forward regexp nil t)
  4542. (setq suppress-prewarning nil)
  4543. (catch :skip
  4544. (org-agenda-skip)
  4545. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4546. (save-match-data
  4547. (string-match org-scheduled-time-regexp
  4548. (buffer-substring (point-at-bol)
  4549. (point-at-eol)))))
  4550. (setq suppress-prewarning
  4551. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4552. org-agenda-skip-deadline-prewarning-if-scheduled
  4553. 0)))
  4554. (setq s (match-string 1)
  4555. txt nil
  4556. pos (1- (match-beginning 1))
  4557. todo-state (save-match-data (org-get-todo-state))
  4558. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4559. (member todo-state
  4560. org-agenda-repeating-timestamp-show-all))
  4561. d2 (org-time-string-to-absolute
  4562. (match-string 1) d1 'past show-all)
  4563. diff (- d2 d1)
  4564. wdays (if suppress-prewarning
  4565. (let ((org-deadline-warning-days suppress-prewarning))
  4566. (org-get-wdays s))
  4567. (org-get-wdays s))
  4568. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4569. upcomingp (and todayp (> diff 0)))
  4570. ;; When to show a deadline in the calendar:
  4571. ;; If the expiration is within wdays warning time.
  4572. ;; Past-due deadlines are only shown on the current date
  4573. (if (and (or (and (<= diff wdays)
  4574. (and todayp (not org-agenda-only-exact-dates)))
  4575. (= diff 0)))
  4576. (save-excursion
  4577. ;; (setq todo-state (org-get-todo-state))
  4578. (setq donep (member todo-state org-done-keywords))
  4579. (if (and donep
  4580. (or org-agenda-skip-deadline-if-done
  4581. (not (= diff 0))))
  4582. (setq txt nil)
  4583. (setq category (org-get-category))
  4584. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4585. (setq txt org-agenda-no-heading-message)
  4586. (goto-char (match-end 0))
  4587. (setq pos1 (match-beginning 0))
  4588. (setq tags (org-get-tags-at pos1))
  4589. (setq head (buffer-substring-no-properties
  4590. (point)
  4591. (progn (skip-chars-forward "^\r\n")
  4592. (point))))
  4593. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4594. (setq timestr
  4595. (concat (substring s (match-beginning 1)) " "))
  4596. (setq timestr 'time))
  4597. (setq txt (org-format-agenda-item
  4598. (if (= diff 0)
  4599. (car org-agenda-deadline-leaders)
  4600. (if (functionp
  4601. (nth 1 org-agenda-deadline-leaders))
  4602. (funcall
  4603. (nth 1 org-agenda-deadline-leaders)
  4604. diff date)
  4605. (format (nth 1 org-agenda-deadline-leaders)
  4606. diff)))
  4607. head category tags
  4608. (if (not (= diff 0)) nil timestr)))))
  4609. (when txt
  4610. (setq face (org-agenda-deadline-face dfrac wdays))
  4611. (org-add-props txt props
  4612. 'org-marker (org-agenda-new-marker pos)
  4613. 'org-hd-marker (org-agenda-new-marker pos1)
  4614. 'priority (+ (- diff)
  4615. (org-get-priority txt))
  4616. 'org-category category
  4617. 'todo-state todo-state
  4618. 'type (if upcomingp "upcoming-deadline" "deadline")
  4619. 'date (if upcomingp date d2)
  4620. 'face (if donep 'org-agenda-done face)
  4621. 'undone-face face 'done-face 'org-agenda-done)
  4622. (push txt ee))))))
  4623. (nreverse ee)))
  4624. (defun org-agenda-deadline-face (fraction &optional wdays)
  4625. "Return the face to displaying a deadline item.
  4626. FRACTION is what fraction of the head-warning time has passed."
  4627. (if (equal wdays 0) (setq fraction 1.))
  4628. (let ((faces org-agenda-deadline-faces) f)
  4629. (catch 'exit
  4630. (while (setq f (pop faces))
  4631. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4632. (defun org-agenda-get-scheduled (&optional deadline-results)
  4633. "Return the scheduled information for agenda display."
  4634. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4635. 'org-todo-regexp org-todo-regexp
  4636. 'org-complex-heading-regexp org-complex-heading-regexp
  4637. 'done-face 'org-agenda-done
  4638. 'mouse-face 'highlight
  4639. 'help-echo
  4640. (format "mouse-2 or RET jump to org file %s"
  4641. (abbreviate-file-name buffer-file-name))))
  4642. (regexp org-scheduled-time-regexp)
  4643. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4644. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4645. mm
  4646. (deadline-position-alist
  4647. (mapcar (lambda (a) (and (setq mm (get-text-property
  4648. 0 'org-hd-marker a))
  4649. (cons (marker-position mm) a)))
  4650. deadline-results))
  4651. d2 diff pos pos1 category tags donep
  4652. ee txt head pastschedp todo-state face timestr s habitp)
  4653. (goto-char (point-min))
  4654. (while (re-search-forward regexp nil t)
  4655. (catch :skip
  4656. (org-agenda-skip)
  4657. (setq s (match-string 1)
  4658. txt nil
  4659. pos (1- (match-beginning 1))
  4660. todo-state (save-match-data (org-get-todo-state))
  4661. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4662. (member todo-state
  4663. org-agenda-repeating-timestamp-show-all))
  4664. d2 (org-time-string-to-absolute
  4665. (match-string 1) d1 'past show-all)
  4666. diff (- d2 d1))
  4667. (setq pastschedp (and todayp (< diff 0)))
  4668. ;; When to show a scheduled item in the calendar:
  4669. ;; If it is on or past the date.
  4670. (when (or (and (< diff 0)
  4671. (< (abs diff) org-scheduled-past-days)
  4672. (and todayp (not org-agenda-only-exact-dates)))
  4673. (= diff 0))
  4674. (save-excursion
  4675. (setq donep (member todo-state org-done-keywords))
  4676. (if (and donep
  4677. (or org-agenda-skip-scheduled-if-done
  4678. (not (= diff 0))
  4679. (and (functionp 'org-is-habit-p)
  4680. (org-is-habit-p))))
  4681. (setq txt nil)
  4682. (setq habitp (and (functionp 'org-is-habit-p)
  4683. (org-is-habit-p)))
  4684. (setq category (org-get-category))
  4685. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4686. (setq txt org-agenda-no-heading-message)
  4687. (goto-char (match-end 0))
  4688. (setq pos1 (match-beginning 0))
  4689. (if habitp
  4690. (if (or (not org-habit-show-habits)
  4691. (and (not todayp)
  4692. org-habit-show-habits-only-for-today))
  4693. (throw :skip nil))
  4694. (if (and
  4695. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4696. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4697. pastschedp))
  4698. (setq mm (assoc pos1 deadline-position-alist)))
  4699. (throw :skip nil)))
  4700. (setq tags (org-get-tags-at))
  4701. (setq head (buffer-substring-no-properties
  4702. (point)
  4703. (progn (skip-chars-forward "^\r\n") (point))))
  4704. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4705. (setq timestr
  4706. (concat (substring s (match-beginning 1)) " "))
  4707. (setq timestr 'time))
  4708. (setq txt (org-format-agenda-item
  4709. (if (= diff 0)
  4710. (car org-agenda-scheduled-leaders)
  4711. (format (nth 1 org-agenda-scheduled-leaders)
  4712. (- 1 diff)))
  4713. head category tags
  4714. (if (not (= diff 0)) nil timestr)
  4715. nil nil habitp))))
  4716. (when txt
  4717. (setq face
  4718. (cond
  4719. ((and (not habitp) pastschedp)
  4720. 'org-scheduled-previously)
  4721. (todayp 'org-scheduled-today)
  4722. (t 'org-scheduled))
  4723. habitp (and habitp (org-habit-parse-todo)))
  4724. (org-add-props txt props
  4725. 'undone-face face
  4726. 'face (if donep 'org-agenda-done face)
  4727. 'org-marker (org-agenda-new-marker pos)
  4728. 'org-hd-marker (org-agenda-new-marker pos1)
  4729. 'type (if pastschedp "past-scheduled" "scheduled")
  4730. 'date (if pastschedp d2 date)
  4731. 'priority (if habitp
  4732. (org-habit-get-priority habitp)
  4733. (+ 94 (- 5 diff) (org-get-priority txt)))
  4734. 'org-category category
  4735. 'org-habit-p habitp
  4736. 'todo-state todo-state)
  4737. (push txt ee))))))
  4738. (nreverse ee)))
  4739. (defun org-agenda-get-blocks ()
  4740. "Return the date-range information for agenda display."
  4741. (let* ((props (list 'face nil
  4742. 'org-not-done-regexp org-not-done-regexp
  4743. 'org-todo-regexp org-todo-regexp
  4744. 'org-complex-heading-regexp org-complex-heading-regexp
  4745. 'mouse-face 'highlight
  4746. 'help-echo
  4747. (format "mouse-2 or RET jump to org file %s"
  4748. (abbreviate-file-name buffer-file-name))))
  4749. (regexp org-tr-regexp)
  4750. (d0 (calendar-absolute-from-gregorian date))
  4751. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4752. head donep)
  4753. (goto-char (point-min))
  4754. (while (re-search-forward regexp nil t)
  4755. (catch :skip
  4756. (org-agenda-skip)
  4757. (setq pos (point))
  4758. (let ((start-time (match-string 1))
  4759. (end-time (match-string 2)))
  4760. (setq s1 (match-string 1)
  4761. s2 (match-string 2)
  4762. d1 (time-to-days (org-time-string-to-time s1))
  4763. d2 (time-to-days (org-time-string-to-time s2)))
  4764. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4765. ;; Only allow days between the limits, because the normal
  4766. ;; date stamps will catch the limits.
  4767. (save-excursion
  4768. (setq todo-state (org-get-todo-state))
  4769. (setq donep (member todo-state org-done-keywords))
  4770. (if (and donep org-agenda-skip-timestamp-if-done)
  4771. (throw :skip t))
  4772. (setq marker (org-agenda-new-marker (point)))
  4773. (setq category (org-get-category))
  4774. (if (not (re-search-backward "^\\*+ " nil t))
  4775. (setq txt org-agenda-no-heading-message)
  4776. (goto-char (match-beginning 0))
  4777. (setq hdmarker (org-agenda-new-marker (point)))
  4778. (setq tags (org-get-tags-at))
  4779. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4780. (setq head (match-string 1))
  4781. (let ((remove-re
  4782. (if org-agenda-remove-timeranges-from-blocks
  4783. (concat
  4784. "<" (regexp-quote s1) ".*?>"
  4785. "--"
  4786. "<" (regexp-quote s2) ".*?>")
  4787. nil)))
  4788. (setq txt (org-format-agenda-item
  4789. (format
  4790. (nth (if (= d1 d2) 0 1)
  4791. org-agenda-timerange-leaders)
  4792. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4793. head category tags
  4794. (cond ((= d1 d0)
  4795. (concat "<" start-time ">"))
  4796. ((= d2 d0)
  4797. (concat "<" end-time ">"))
  4798. (t nil))
  4799. remove-re))))
  4800. (org-add-props txt props
  4801. 'org-marker marker 'org-hd-marker hdmarker
  4802. 'type "block" 'date date
  4803. 'todo-state todo-state
  4804. 'priority (org-get-priority txt) 'org-category category)
  4805. (push txt ee))))
  4806. (goto-char pos)))
  4807. ;; Sort the entries by expiration date.
  4808. (nreverse ee)))
  4809. ;;; Agenda presentation and sorting
  4810. (defvar org-prefix-has-time nil
  4811. "A flag, set by `org-compile-prefix-format'.
  4812. The flag is set if the currently compiled format contains a `%t'.")
  4813. (defvar org-prefix-has-tag nil
  4814. "A flag, set by `org-compile-prefix-format'.
  4815. The flag is set if the currently compiled format contains a `%T'.")
  4816. (defvar org-prefix-has-effort nil
  4817. "A flag, set by `org-compile-prefix-format'.
  4818. The flag is set if the currently compiled format contains a `%e'.")
  4819. (defvar org-prefix-category-length nil
  4820. "Used by `org-compile-prefix-format' to remember the category field width.")
  4821. (defvar org-prefix-category-max-length nil
  4822. "Used by `org-compile-prefix-format' to remember the category field width.")
  4823. (defun org-agenda-get-category-icon (category)
  4824. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4825. (dolist (entry org-agenda-category-icon-alist)
  4826. (when (org-string-match-p (car entry) category)
  4827. (if (listp (cadr entry))
  4828. (return (cadr entry))
  4829. (return (apply 'create-image (cdr entry)))))))
  4830. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4831. noprefix remove-re habitp)
  4832. "Format TXT to be inserted into the agenda buffer.
  4833. In particular, it adds the prefix and corresponding text properties. EXTRA
  4834. must be a string and replaces the `%s' specifier in the prefix format.
  4835. CATEGORY (string, symbol or nil) may be used to overrule the default
  4836. category taken from local variable or file name. It will replace the `%c'
  4837. specifier in the format. DOTIME, when non-nil, indicates that a
  4838. time-of-day should be extracted from TXT for sorting of this entry, and for
  4839. the `%t' specifier in the format. When DOTIME is a string, this string is
  4840. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4841. only the correctly processes TXT should be returned - this is used by
  4842. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4843. Any match of REMOVE-RE will be removed from TXT."
  4844. (save-match-data
  4845. ;; Diary entries sometimes have extra whitespace at the beginning
  4846. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4847. ;; Fix the tags part in txt
  4848. (setq txt (org-agenda-fix-displayed-tags
  4849. txt tags
  4850. org-agenda-show-inherited-tags
  4851. org-agenda-hide-tags-regexp))
  4852. (let* ((category (or category
  4853. (if (stringp org-category)
  4854. org-category
  4855. (and org-category (symbol-name org-category)))
  4856. (if buffer-file-name
  4857. (file-name-sans-extension
  4858. (file-name-nondirectory buffer-file-name))
  4859. "")))
  4860. (category-icon (org-agenda-get-category-icon category))
  4861. (category-icon (if category-icon
  4862. (propertize " " 'display category-icon)
  4863. ""))
  4864. ;; time, tag, effort are needed for the eval of the prefix format
  4865. (tag (if tags (nth (1- (length tags)) tags) ""))
  4866. time effort neffort
  4867. (ts (if dotime (concat
  4868. (if (stringp dotime) dotime "")
  4869. (and org-agenda-search-headline-for-time txt))))
  4870. (time-of-day (and dotime (org-get-time-of-day ts)))
  4871. stamp plain s0 s1 s2 rtn srp l
  4872. duration thecategory)
  4873. (and (org-mode-p) buffer-file-name
  4874. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4875. (when (and dotime time-of-day)
  4876. ;; Extract starting and ending time and move them to prefix
  4877. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4878. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4879. (setq s0 (match-string 0 ts)
  4880. srp (and stamp (match-end 3))
  4881. s1 (match-string (if plain 1 2) ts)
  4882. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4883. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4884. ;; them, we might want to remove them there to avoid duplication.
  4885. ;; The user can turn this off with a variable.
  4886. (if (and org-prefix-has-time
  4887. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4888. (string-match (concat (regexp-quote s0) " *") txt)
  4889. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4890. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4891. (= (match-beginning 0) 0)
  4892. t))
  4893. (setq txt (replace-match "" nil nil txt))))
  4894. ;; Normalize the time(s) to 24 hour
  4895. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4896. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4897. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  4898. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  4899. (setq s2
  4900. (org-minutes-to-hh:mm-string
  4901. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  4902. ;; Compute the duration
  4903. (when s2
  4904. (setq duration (- (org-hh:mm-string-to-minutes s2)
  4905. (org-hh:mm-string-to-minutes s1)))))
  4906. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4907. txt)
  4908. ;; Tags are in the string
  4909. (if (or (eq org-agenda-remove-tags t)
  4910. (and org-agenda-remove-tags
  4911. org-prefix-has-tag))
  4912. (setq txt (replace-match "" t t txt))
  4913. (setq txt (replace-match
  4914. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4915. (match-string 2 txt))
  4916. t t txt))))
  4917. (when (org-mode-p)
  4918. (setq effort
  4919. (condition-case nil
  4920. (org-get-effort
  4921. (or (get-text-property 0 'org-hd-marker txt)
  4922. (get-text-property 0 'org-marker txt)))
  4923. (error nil)))
  4924. (when effort
  4925. (setq neffort (org-hh:mm-string-to-minutes effort)
  4926. effort (setq effort (concat "[" effort "]" )))))
  4927. (when remove-re
  4928. (while (string-match remove-re txt)
  4929. (setq txt (replace-match "" t t txt))))
  4930. ;; Create the final string
  4931. (if noprefix
  4932. (setq rtn txt)
  4933. ;; Prepare the variables needed in the eval of the compiled format
  4934. (setq time (cond (s2 (concat
  4935. (org-agenda-time-of-day-to-ampm-maybe s1)
  4936. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4937. (if org-agenda-timegrid-use-ampm " ")))
  4938. (s1 (concat
  4939. (org-agenda-time-of-day-to-ampm-maybe s1)
  4940. (if org-agenda-timegrid-use-ampm
  4941. "........ "
  4942. "......")))
  4943. (t ""))
  4944. extra (or (and (not habitp) extra) "")
  4945. category (if (symbolp category) (symbol-name category) category)
  4946. thecategory (copy-sequence category))
  4947. (if (string-match org-bracket-link-regexp category)
  4948. (progn
  4949. (setq l (if (match-end 3)
  4950. (- (match-end 3) (match-beginning 3))
  4951. (- (match-end 1) (match-beginning 1))))
  4952. (when (< l (or org-prefix-category-length 0))
  4953. (setq category (copy-sequence category))
  4954. (org-add-props category nil
  4955. 'extra-space (make-string
  4956. (- org-prefix-category-length l 1) ?\ ))))
  4957. (if (and org-prefix-category-max-length
  4958. (>= (length category) org-prefix-category-max-length))
  4959. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4960. ;; Evaluate the compiled format
  4961. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4962. ;; And finally add the text properties
  4963. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4964. (org-add-props rtn nil
  4965. 'org-category (if thecategory (downcase thecategory) category)
  4966. 'tags (mapcar 'org-downcase-keep-props tags)
  4967. 'org-highest-priority org-highest-priority
  4968. 'org-lowest-priority org-lowest-priority
  4969. 'prefix-length (- (length rtn) (length txt))
  4970. 'time-of-day time-of-day
  4971. 'duration duration
  4972. 'effort effort
  4973. 'effort-minutes neffort
  4974. 'txt txt
  4975. 'time time
  4976. 'extra extra
  4977. 'dotime dotime))))
  4978. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4979. "Remove tags string from TXT, and add a modified list of tags.
  4980. The modified list may contain inherited tags, and tags matched by
  4981. `org-agenda-hide-tags-regexp' will be removed."
  4982. (when (or add-inherited hide-re)
  4983. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4984. (setq txt (substring txt 0 (match-beginning 0))))
  4985. (setq tags
  4986. (delq nil
  4987. (mapcar (lambda (tg)
  4988. (if (or (and hide-re (string-match hide-re tg))
  4989. (and (not add-inherited)
  4990. (get-text-property 0 'inherited tg)))
  4991. nil
  4992. tg))
  4993. tags)))
  4994. (when tags
  4995. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4996. i)
  4997. (setq txt (concat txt " :"
  4998. (mapconcat
  4999. (lambda (x)
  5000. (setq i (get-text-property 0 'inherited x))
  5001. (if (and have-i (not i))
  5002. (progn
  5003. (setq have-i nil)
  5004. (concat ":" x))
  5005. x))
  5006. tags ":")
  5007. (if have-i "::" ":"))))))
  5008. txt)
  5009. (defun org-downcase-keep-props (s)
  5010. (let ((props (text-properties-at 0 s)))
  5011. (setq s (downcase s))
  5012. (add-text-properties 0 (length s) props s)
  5013. s))
  5014. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5015. (defvar org-agenda-sorting-strategy-selected nil)
  5016. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5017. (catch 'exit
  5018. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5019. ((and todayp (member 'today (car org-agenda-time-grid))))
  5020. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5021. ((member 'weekly (car org-agenda-time-grid)))
  5022. (t (throw 'exit list)))
  5023. (let* ((have (delq nil (mapcar
  5024. (lambda (x) (get-text-property 1 'time-of-day x))
  5025. list)))
  5026. (string (nth 1 org-agenda-time-grid))
  5027. (gridtimes (nth 2 org-agenda-time-grid))
  5028. (req (car org-agenda-time-grid))
  5029. (remove (member 'remove-match req))
  5030. new time)
  5031. (if (and (member 'require-timed req) (not have))
  5032. ;; don't show empty grid
  5033. (throw 'exit list))
  5034. (while (setq time (pop gridtimes))
  5035. (unless (and remove (member time have))
  5036. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5037. (push (org-format-agenda-item
  5038. nil string "" nil
  5039. (concat (substring time 0 -2) ":" (substring time -2)))
  5040. new)
  5041. (put-text-property
  5042. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5043. (when (and todayp org-agenda-show-current-time-in-grid)
  5044. (push (org-format-agenda-item
  5045. nil
  5046. org-agenda-current-time-string
  5047. "" nil
  5048. (format-time-string "%H:%M "))
  5049. new)
  5050. (put-text-property
  5051. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5052. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5053. (append new list)
  5054. (append list new)))))
  5055. (defun org-eval (form)
  5056. "Eval FORM and return result."
  5057. (condition-case error
  5058. (eval form)
  5059. (error (format "%%![Error: %s]" error))))
  5060. (defun org-compile-prefix-format (key)
  5061. "Compile the prefix format into a Lisp form that can be evaluated.
  5062. The resulting form is returned and stored in the variable
  5063. `org-prefix-format-compiled'."
  5064. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5065. org-prefix-category-length nil org-prefix-has-effort nil)
  5066. (let ((s (cond
  5067. ((stringp org-agenda-prefix-format)
  5068. org-agenda-prefix-format)
  5069. ((assq key org-agenda-prefix-format)
  5070. (cdr (assq key org-agenda-prefix-format)))
  5071. (t " %-12:c%?-12t% s")))
  5072. (start 0)
  5073. varform vars var e c f opt)
  5074. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5075. s start)
  5076. (setq var (or (cdr (assoc (match-string 4 s)
  5077. '(("c" . category) ("t" . time) ("s" . extra)
  5078. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5079. 'eval)
  5080. c (or (match-string 3 s) "")
  5081. opt (match-beginning 1)
  5082. start (1+ (match-beginning 0)))
  5083. (if (equal var 'time) (setq org-prefix-has-time t))
  5084. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5085. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5086. (setq f (concat "%" (match-string 2 s) "s"))
  5087. (when (equal var 'category)
  5088. (setq org-prefix-category-length
  5089. (floor (abs (string-to-number (match-string 2 s)))))
  5090. (setq org-prefix-category-max-length
  5091. (let ((x (match-string 2 s)))
  5092. (save-match-data
  5093. (if (string-match "\\.[0-9]+" x)
  5094. (string-to-number (substring (match-string 0 x) 1)))))))
  5095. (if (eq var 'eval)
  5096. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5097. (if opt
  5098. (setq varform
  5099. `(if (equal "" ,var)
  5100. ""
  5101. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5102. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5103. (setq s (replace-match "%s" t nil s))
  5104. (push varform vars))
  5105. (setq vars (nreverse vars))
  5106. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5107. (defun org-set-sorting-strategy (key)
  5108. (if (symbolp (car org-agenda-sorting-strategy))
  5109. ;; the old format
  5110. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5111. (setq org-agenda-sorting-strategy-selected
  5112. (or (cdr (assq key org-agenda-sorting-strategy))
  5113. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5114. '(time-up category-keep priority-down)))))
  5115. (defun org-get-time-of-day (s &optional string mod24)
  5116. "Check string S for a time of day.
  5117. If found, return it as a military time number between 0 and 2400.
  5118. If not found, return nil.
  5119. The optional STRING argument forces conversion into a 5 character wide string
  5120. HH:MM."
  5121. (save-match-data
  5122. (when
  5123. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5124. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5125. (let* ((h (string-to-number (match-string 1 s)))
  5126. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5127. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5128. (am-p (equal ampm "am"))
  5129. (h1 (cond ((not ampm) h)
  5130. ((= h 12) (if am-p 0 12))
  5131. (t (+ h (if am-p 0 12)))))
  5132. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5133. (mod h1 24) h1))
  5134. (t0 (+ (* 100 h2) m))
  5135. (t1 (concat (if (>= h1 24) "+" " ")
  5136. (if (and org-agenda-time-leading-zero
  5137. (< t0 1000)) "0" "")
  5138. (if (< t0 100) "0" "")
  5139. (if (< t0 10) "0" "")
  5140. (int-to-string t0))))
  5141. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5142. (defvar org-agenda-before-sorting-filter-function nil
  5143. "Function to be applied to agenda items prior to sorting.
  5144. Prior to sorting also means just before they are inserted into the agenda.
  5145. To aid sorting, you may revisit the original entries and add more text
  5146. properties which will later be used by the sorting functions.
  5147. The function should take a string argument, an agenda line.
  5148. It has access to the text properties in that line, which contain among
  5149. other things, the property `org-hd-marker' that points to the entry
  5150. where the line comes from. Note that not all lines going into the agenda
  5151. have this property, only most.
  5152. The function should return the modified string. It is probably best
  5153. to ONLY change text properties.
  5154. You can also use this function as a filter, by returning nil for lines
  5155. you don't want to have in the agenda at all. For this application, you
  5156. could bind the variable in the options section of a custom command.")
  5157. (defun org-finalize-agenda-entries (list &optional nosort)
  5158. "Sort and concatenate the agenda items."
  5159. (setq list (mapcar 'org-agenda-highlight-todo list))
  5160. (if nosort
  5161. list
  5162. (when org-agenda-before-sorting-filter-function
  5163. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5164. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5165. (defun org-agenda-highlight-todo (x)
  5166. (let ((org-done-keywords org-done-keywords-for-agenda)
  5167. (case-fold-search nil)
  5168. re pl)
  5169. (if (eq x 'line)
  5170. (save-excursion
  5171. (beginning-of-line 1)
  5172. (setq re (org-get-at-bol 'org-todo-regexp))
  5173. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5174. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5175. (add-text-properties (match-beginning 0) (match-end 1)
  5176. (list 'face (org-get-todo-face 1)))
  5177. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5178. (delete-region (match-beginning 1) (1- (match-end 0)))
  5179. (goto-char (match-beginning 1))
  5180. (insert (format org-agenda-todo-keyword-format s)))))
  5181. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5182. pl (get-text-property 0 'prefix-length x))
  5183. (when (and re
  5184. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5185. x (or pl 0)) pl))
  5186. (add-text-properties
  5187. (or (match-end 1) (match-end 0)) (match-end 0)
  5188. (list 'face (org-get-todo-face (match-string 2 x)))
  5189. x)
  5190. (when (match-end 1)
  5191. (setq x (concat (substring x 0 (match-end 1))
  5192. (format org-agenda-todo-keyword-format
  5193. (match-string 2 x))
  5194. (org-add-props " " (text-properties-at 0 x))
  5195. (substring x (match-end 3))))))
  5196. x)))
  5197. (defsubst org-cmp-priority (a b)
  5198. "Compare the priorities of string A and B."
  5199. (let ((pa (or (get-text-property 1 'priority a) 0))
  5200. (pb (or (get-text-property 1 'priority b) 0)))
  5201. (cond ((> pa pb) +1)
  5202. ((< pa pb) -1)
  5203. (t nil))))
  5204. (defsubst org-cmp-effort (a b)
  5205. "Compare the priorities of string A and B."
  5206. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5207. (ea (or (get-text-property 1 'effort-minutes a) def))
  5208. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5209. (cond ((> ea eb) +1)
  5210. ((< ea eb) -1)
  5211. (t nil))))
  5212. (defsubst org-cmp-category (a b)
  5213. "Compare the string values of categories of strings A and B."
  5214. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5215. (cb (or (get-text-property 1 'org-category b) "")))
  5216. (cond ((string-lessp ca cb) -1)
  5217. ((string-lessp cb ca) +1)
  5218. (t nil))))
  5219. (defsubst org-cmp-todo-state (a b)
  5220. "Compare the todo states of strings A and B."
  5221. (let* ((ma (or (get-text-property 1 'org-marker a)
  5222. (get-text-property 1 'org-hd-marker a)))
  5223. (mb (or (get-text-property 1 'org-marker b)
  5224. (get-text-property 1 'org-hd-marker b)))
  5225. (fa (and ma (marker-buffer ma)))
  5226. (fb (and mb (marker-buffer mb)))
  5227. (todo-kwds
  5228. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5229. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5230. (ta (or (get-text-property 1 'todo-state a) ""))
  5231. (tb (or (get-text-property 1 'todo-state b) ""))
  5232. (la (- (length (member ta todo-kwds))))
  5233. (lb (- (length (member tb todo-kwds))))
  5234. (donepa (member ta org-done-keywords-for-agenda))
  5235. (donepb (member tb org-done-keywords-for-agenda)))
  5236. (cond ((and donepa (not donepb)) -1)
  5237. ((and (not donepa) donepb) +1)
  5238. ((< la lb) -1)
  5239. ((< lb la) +1)
  5240. (t nil))))
  5241. (defsubst org-cmp-alpha (a b)
  5242. "Compare the headlines, alphabetically."
  5243. (let* ((pla (get-text-property 0 'prefix-length a))
  5244. (plb (get-text-property 0 'prefix-length b))
  5245. (ta (and pla (substring a pla)))
  5246. (tb (and plb (substring b plb))))
  5247. (when pla
  5248. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5249. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5250. (setq ta (substring ta (match-end 0))))
  5251. (setq ta (downcase ta)))
  5252. (when plb
  5253. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5254. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5255. (setq tb (substring tb (match-end 0))))
  5256. (setq tb (downcase tb)))
  5257. (cond ((not ta) +1)
  5258. ((not tb) -1)
  5259. ((string-lessp ta tb) -1)
  5260. ((string-lessp tb ta) +1)
  5261. (t nil))))
  5262. (defsubst org-cmp-tag (a b)
  5263. "Compare the string values of the first tags of A and B."
  5264. (let ((ta (car (last (get-text-property 1 'tags a))))
  5265. (tb (car (last (get-text-property 1 'tags b)))))
  5266. (cond ((not ta) +1)
  5267. ((not tb) -1)
  5268. ((string-lessp ta tb) -1)
  5269. ((string-lessp tb ta) +1)
  5270. (t nil))))
  5271. (defsubst org-cmp-time (a b)
  5272. "Compare the time-of-day values of strings A and B."
  5273. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5274. (ta (or (get-text-property 1 'time-of-day a) def))
  5275. (tb (or (get-text-property 1 'time-of-day b) def)))
  5276. (cond ((< ta tb) -1)
  5277. ((< tb ta) +1)
  5278. (t nil))))
  5279. (defsubst org-cmp-habit-p (a b)
  5280. "Compare the todo states of strings A and B."
  5281. (let ((ha (get-text-property 1 'org-habit-p a))
  5282. (hb (get-text-property 1 'org-habit-p b)))
  5283. (cond ((and ha (not hb)) -1)
  5284. ((and (not ha) hb) +1)
  5285. (t nil))))
  5286. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5287. (defun org-entries-lessp (a b)
  5288. "Predicate for sorting agenda entries."
  5289. ;; The following variables will be used when the form is evaluated.
  5290. ;; So even though the compiler complains, keep them.
  5291. (let* ((ss org-agenda-sorting-strategy-selected)
  5292. (time-up (and (org-em 'time-up 'time-down ss)
  5293. (org-cmp-time a b)))
  5294. (time-down (if time-up (- time-up) nil))
  5295. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5296. (org-cmp-priority a b)))
  5297. (priority-down (if priority-up (- priority-up) nil))
  5298. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5299. (org-cmp-effort a b)))
  5300. (effort-down (if effort-up (- effort-up) nil))
  5301. (category-up (and (or (org-em 'category-up 'category-down ss)
  5302. (memq 'category-keep ss))
  5303. (org-cmp-category a b)))
  5304. (category-down (if category-up (- category-up) nil))
  5305. (category-keep (if category-up +1 nil))
  5306. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5307. (org-cmp-tag a b)))
  5308. (tag-down (if tag-up (- tag-up) nil))
  5309. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5310. (org-cmp-todo-state a b)))
  5311. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5312. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5313. (org-cmp-habit-p a b)))
  5314. (habit-down (if habit-up (- habit-up) nil))
  5315. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5316. (org-cmp-alpha a b)))
  5317. (alpha-down (if alpha-up (- alpha-up) nil))
  5318. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5319. user-defined-up user-defined-down)
  5320. (if (and need-user-cmp org-agenda-cmp-user-defined
  5321. (functionp org-agenda-cmp-user-defined))
  5322. (setq user-defined-up
  5323. (funcall org-agenda-cmp-user-defined a b)
  5324. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5325. (cdr (assoc
  5326. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5327. '((-1 . t) (1 . nil) (nil . nil))))))
  5328. ;;; Agenda restriction lock
  5329. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5330. "Overlay to mark the headline to which agenda commands are restricted.")
  5331. (overlay-put org-agenda-restriction-lock-overlay
  5332. 'face 'org-agenda-restriction-lock)
  5333. (overlay-put org-agenda-restriction-lock-overlay
  5334. 'help-echo "Agendas are currently limited to this subtree.")
  5335. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5336. (defun org-agenda-set-restriction-lock (&optional type)
  5337. "Set restriction lock for agenda, to current subtree or file.
  5338. Restriction will be the file if TYPE is `file', or if type is the
  5339. universal prefix '(4), or if the cursor is before the first headline
  5340. in the file. Otherwise, restriction will be to the current subtree."
  5341. (interactive "P")
  5342. (and (equal type '(4)) (setq type 'file))
  5343. (setq type (cond
  5344. (type type)
  5345. ((org-at-heading-p) 'subtree)
  5346. ((condition-case nil (org-back-to-heading t) (error nil))
  5347. 'subtree)
  5348. (t 'file)))
  5349. (if (eq type 'subtree)
  5350. (progn
  5351. (setq org-agenda-restrict t)
  5352. (setq org-agenda-overriding-restriction 'subtree)
  5353. (put 'org-agenda-files 'org-restrict
  5354. (list (buffer-file-name (buffer-base-buffer))))
  5355. (org-back-to-heading t)
  5356. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5357. (move-marker org-agenda-restrict-begin (point))
  5358. (move-marker org-agenda-restrict-end
  5359. (save-excursion (org-end-of-subtree t)))
  5360. (message "Locking agenda restriction to subtree"))
  5361. (put 'org-agenda-files 'org-restrict
  5362. (list (buffer-file-name (buffer-base-buffer))))
  5363. (setq org-agenda-restrict nil)
  5364. (setq org-agenda-overriding-restriction 'file)
  5365. (move-marker org-agenda-restrict-begin nil)
  5366. (move-marker org-agenda-restrict-end nil)
  5367. (message "Locking agenda restriction to file"))
  5368. (setq current-prefix-arg nil)
  5369. (org-agenda-maybe-redo))
  5370. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5371. "Remove the agenda restriction lock."
  5372. (interactive "P")
  5373. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5374. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5375. (setq org-agenda-overriding-restriction nil)
  5376. (setq org-agenda-restrict nil)
  5377. (put 'org-agenda-files 'org-restrict nil)
  5378. (move-marker org-agenda-restrict-begin nil)
  5379. (move-marker org-agenda-restrict-end nil)
  5380. (setq current-prefix-arg nil)
  5381. (message "Agenda restriction lock removed")
  5382. (or noupdate (org-agenda-maybe-redo)))
  5383. (defun org-agenda-maybe-redo ()
  5384. "If there is any window showing the agenda view, update it."
  5385. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5386. (w0 (selected-window)))
  5387. (when w
  5388. (select-window w)
  5389. (org-agenda-redo)
  5390. (select-window w0)
  5391. (if org-agenda-overriding-restriction
  5392. (message "Agenda view shifted to new %s restriction"
  5393. org-agenda-overriding-restriction)
  5394. (message "Agenda restriction lock removed")))))
  5395. ;;; Agenda commands
  5396. (defun org-agenda-check-type (error &rest types)
  5397. "Check if agenda buffer is of allowed type.
  5398. If ERROR is non-nil, throw an error, otherwise just return nil."
  5399. (if (memq org-agenda-type types)
  5400. t
  5401. (if error
  5402. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5403. nil)))
  5404. (defun org-agenda-quit ()
  5405. "Exit agenda by removing the window or the buffer."
  5406. (interactive)
  5407. (if org-agenda-columns-active
  5408. (org-columns-quit)
  5409. (let ((buf (current-buffer)))
  5410. (if (eq org-agenda-window-setup 'other-frame)
  5411. (progn
  5412. (kill-buffer buf)
  5413. (org-agenda-reset-markers)
  5414. (org-columns-remove-overlays)
  5415. (setq org-agenda-archives-mode nil)
  5416. (delete-frame))
  5417. (and (not (eq org-agenda-window-setup 'current-window))
  5418. (not (one-window-p))
  5419. (delete-window))
  5420. (kill-buffer buf)
  5421. (org-agenda-reset-markers)
  5422. (org-columns-remove-overlays)
  5423. (setq org-agenda-archives-mode nil)))
  5424. ;; Maybe restore the pre-agenda window configuration.
  5425. (and org-agenda-restore-windows-after-quit
  5426. (not (eq org-agenda-window-setup 'other-frame))
  5427. org-pre-agenda-window-conf
  5428. (set-window-configuration org-pre-agenda-window-conf))))
  5429. (defun org-agenda-exit ()
  5430. "Exit agenda by removing the window or the buffer.
  5431. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5432. Org-mode buffers visited directly by the user will not be touched."
  5433. (interactive)
  5434. (org-release-buffers org-agenda-new-buffers)
  5435. (setq org-agenda-new-buffers nil)
  5436. (org-agenda-quit))
  5437. (defun org-agenda-execute (arg)
  5438. "Execute another agenda command, keeping same window.
  5439. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5440. in the agenda."
  5441. (interactive "P")
  5442. (let ((org-agenda-window-setup 'current-window))
  5443. (org-agenda arg)))
  5444. (defun org-agenda-redo ()
  5445. "Rebuild Agenda.
  5446. When this is the global TODO list, a prefix argument will be interpreted."
  5447. (interactive)
  5448. (let* ((org-agenda-keep-modes t)
  5449. (filter org-agenda-filter)
  5450. (preset (get 'org-agenda-filter :preset-filter))
  5451. (org-agenda-filter-while-redo (or filter preset))
  5452. (cols org-agenda-columns-active)
  5453. (line (org-current-line))
  5454. (window-line (- line (org-current-line (window-start))))
  5455. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5456. (put 'org-agenda-filter :preset-filter nil)
  5457. (and cols (org-columns-quit))
  5458. (message "Rebuilding agenda buffer...")
  5459. (org-let lprops '(eval org-agenda-redo-command))
  5460. (setq org-agenda-undo-list nil
  5461. org-agenda-pending-undo-list nil)
  5462. (message "Rebuilding agenda buffer...done")
  5463. (put 'org-agenda-filter :preset-filter preset)
  5464. (and (or filter preset) (org-agenda-filter-apply filter))
  5465. (and cols (interactive-p) (org-agenda-columns))
  5466. (org-goto-line line)
  5467. (recenter window-line)))
  5468. (defvar org-global-tags-completion-table nil)
  5469. (defvar org-agenda-filter-form nil)
  5470. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5471. "Keep only those lines in the agenda buffer that have a specific tag.
  5472. The tag is selected with its fast selection letter, as configured.
  5473. With prefix argument STRIP, remove all lines that do have the tag.
  5474. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5475. used to narrow the search - the interactive user can also press `-' or `+'
  5476. to switch to narrowing."
  5477. (interactive "P")
  5478. (let* ((alist org-tag-alist-for-agenda)
  5479. (tag-chars (mapconcat
  5480. (lambda (x) (if (and (not (symbolp (car x)))
  5481. (cdr x))
  5482. (char-to-string (cdr x))
  5483. ""))
  5484. alist ""))
  5485. (efforts (org-split-string
  5486. (or (cdr (assoc (concat org-effort-property "_ALL")
  5487. org-global-properties))
  5488. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5489. (effort-op org-agenda-filter-effort-default-operator)
  5490. (effort-prompt "")
  5491. (inhibit-read-only t)
  5492. (current org-agenda-filter)
  5493. a n tag)
  5494. (unless char
  5495. (message
  5496. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5497. (if narrow "Narrow" "Filter") tag-chars
  5498. (if org-agenda-auto-exclude-function "[RET], " ""))
  5499. (setq char (read-char)))
  5500. (when (member char '(?+ ?-))
  5501. ;; Narrowing down
  5502. (cond ((equal char ?-) (setq strip t narrow t))
  5503. ((equal char ?+) (setq strip nil narrow t)))
  5504. (message
  5505. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5506. (setq char (read-char)))
  5507. (when (member char '(?< ?> ?= ??))
  5508. ;; An effort operator
  5509. (setq effort-op (char-to-string char))
  5510. (setq alist nil) ; to make sure it will be interpreted as effort.
  5511. (unless (equal char ??)
  5512. (loop for i from 0 to 9 do
  5513. (setq effort-prompt
  5514. (concat
  5515. effort-prompt " ["
  5516. (if (= i 9) "0" (int-to-string (1+ i)))
  5517. "]" (nth i efforts))))
  5518. (message "Effort%s: %s " effort-op effort-prompt)
  5519. (setq char (read-char))
  5520. (when (or (< char ?0) (> char ?9))
  5521. (error "Need 1-9,0 to select effort" ))))
  5522. (when (equal char ?\t)
  5523. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5524. (org-set-local 'org-global-tags-completion-table
  5525. (org-global-tags-completion-table)))
  5526. (let ((completion-ignore-case t))
  5527. (setq tag (org-icompleting-read
  5528. "Tag: " org-global-tags-completion-table))))
  5529. (cond
  5530. ((equal char ?\r)
  5531. (org-agenda-filter-by-tag-show-all)
  5532. (when org-agenda-auto-exclude-function
  5533. (setq org-agenda-filter '())
  5534. (dolist (tag (org-agenda-get-represented-tags))
  5535. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5536. (if modifier
  5537. (push modifier org-agenda-filter))))
  5538. (if (not (null org-agenda-filter))
  5539. (org-agenda-filter-apply org-agenda-filter))))
  5540. ((equal char ?/)
  5541. (org-agenda-filter-by-tag-show-all)
  5542. (when (get 'org-agenda-filter :preset-filter)
  5543. (org-agenda-filter-apply org-agenda-filter)))
  5544. ((or (equal char ?\ )
  5545. (setq a (rassoc char alist))
  5546. (and (>= char ?0) (<= char ?9)
  5547. (setq n (if (= char ?0) 9 (- char ?0 1))
  5548. tag (concat effort-op (nth n efforts))
  5549. a (cons tag nil)))
  5550. (and (= char ??)
  5551. (setq tag "?eff")
  5552. a (cons tag nil))
  5553. (and tag (setq a (cons tag nil))))
  5554. (org-agenda-filter-by-tag-show-all)
  5555. (setq tag (car a))
  5556. (setq org-agenda-filter
  5557. (cons (concat (if strip "-" "+") tag)
  5558. (if narrow current nil)))
  5559. (org-agenda-filter-apply org-agenda-filter))
  5560. (t (error "Invalid tag selection character %c" char)))))
  5561. (defun org-agenda-get-represented-tags ()
  5562. "Get a list of all tags currently represented in the agenda."
  5563. (let (p tags)
  5564. (save-excursion
  5565. (goto-char (point-min))
  5566. (while (setq p (next-single-property-change (point) 'tags))
  5567. (goto-char p)
  5568. (mapc (lambda (x) (add-to-list 'tags x))
  5569. (get-text-property (point) 'tags))))
  5570. tags))
  5571. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5572. "Refine the current filter. See `org-agenda-filter-by-tag."
  5573. (interactive "P")
  5574. (org-agenda-filter-by-tag strip char 'refine))
  5575. (defun org-agenda-filter-make-matcher ()
  5576. "Create the form that tests a line for the agenda filter."
  5577. (let (f f1)
  5578. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5579. org-agenda-filter))
  5580. (if (member x '("-" "+"))
  5581. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5582. (if (string-match "[<=>?]" x)
  5583. (setq f1 (org-agenda-filter-effort-form x))
  5584. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5585. (if (equal (string-to-char x) ?-)
  5586. (setq f1 (list 'not f1))))
  5587. (push f1 f))
  5588. (cons 'and (nreverse f))))
  5589. (defun org-agenda-filter-effort-form (e)
  5590. "Return the form to compare the effort of the current line with what E says.
  5591. E looks like \"+<2:25\"."
  5592. (let (op)
  5593. (setq e (substring e 1))
  5594. (setq op (string-to-char e) e (substring e 1))
  5595. (setq op (cond ((equal op ?<) '<=)
  5596. ((equal op ?>) '>=)
  5597. ((equal op ??) op)
  5598. (t '=)))
  5599. (list 'org-agenda-compare-effort (list 'quote op)
  5600. (org-hh:mm-string-to-minutes e))))
  5601. (defun org-agenda-compare-effort (op value)
  5602. "Compare the effort of the current line with VALUE, using OP.
  5603. If the line does not have an effort defined, return nil."
  5604. (let ((eff (org-get-at-bol 'effort-minutes)))
  5605. (if (equal op ??)
  5606. (not eff)
  5607. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5608. value))))
  5609. (defun org-agenda-filter-apply (filter)
  5610. "Set FILTER as the new agenda filter and apply it."
  5611. (let (tags)
  5612. (setq org-agenda-filter filter
  5613. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5614. (org-agenda-set-mode-name)
  5615. (save-excursion
  5616. (goto-char (point-min))
  5617. (while (not (eobp))
  5618. (if (org-get-at-bol 'org-marker)
  5619. (progn
  5620. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5621. (if (not (eval org-agenda-filter-form))
  5622. (org-agenda-filter-by-tag-hide-line))
  5623. (beginning-of-line 2))
  5624. (beginning-of-line 2))))
  5625. (if (get-char-property (point) 'invisible)
  5626. (org-agenda-previous-line))))
  5627. (defun org-agenda-filter-by-tag-hide-line ()
  5628. (let (ov)
  5629. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5630. (point-at-eol)))
  5631. (overlay-put ov 'invisible t)
  5632. (overlay-put ov 'type 'tags-filter)
  5633. (push ov org-agenda-filter-overlays)))
  5634. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5635. (setq pos (or pos (point)))
  5636. (save-excursion
  5637. (dolist (ov (overlays-at pos))
  5638. (when (and (overlay-get ov 'invisible)
  5639. (eq (overlay-get ov 'type) 'tags-filter))
  5640. (goto-char pos)
  5641. (if (< (overlay-start ov) (point-at-eol))
  5642. (move-overlay ov (point-at-eol)
  5643. (overlay-end ov)))))))
  5644. (defun org-agenda-filter-by-tag-show-all ()
  5645. (mapc 'delete-overlay org-agenda-filter-overlays)
  5646. (setq org-agenda-filter-overlays nil)
  5647. (setq org-agenda-filter nil)
  5648. (setq org-agenda-filter-form nil)
  5649. (org-agenda-set-mode-name))
  5650. (defun org-agenda-manipulate-query-add ()
  5651. "Manipulate the query by adding a search term with positive selection.
  5652. Positive selection means the term must be matched for selection of an entry."
  5653. (interactive)
  5654. (org-agenda-manipulate-query ?\[))
  5655. (defun org-agenda-manipulate-query-subtract ()
  5656. "Manipulate the query by adding a search term with negative selection.
  5657. Negative selection means term must not be matched for selection of an entry."
  5658. (interactive)
  5659. (org-agenda-manipulate-query ?\]))
  5660. (defun org-agenda-manipulate-query-add-re ()
  5661. "Manipulate the query by adding a search regexp with positive selection.
  5662. Positive selection means the regexp must match for selection of an entry."
  5663. (interactive)
  5664. (org-agenda-manipulate-query ?\{))
  5665. (defun org-agenda-manipulate-query-subtract-re ()
  5666. "Manipulate the query by adding a search regexp with negative selection.
  5667. Negative selection means regexp must not match for selection of an entry."
  5668. (interactive)
  5669. (org-agenda-manipulate-query ?\}))
  5670. (defun org-agenda-manipulate-query (char)
  5671. (cond
  5672. ((memq org-agenda-type '(timeline agenda))
  5673. (let ((org-agenda-include-inactive-timestamps t))
  5674. (org-agenda-redo))
  5675. (message "Display now includes inactive timestamps as well"))
  5676. ((eq org-agenda-type 'search)
  5677. (org-add-to-string
  5678. 'org-agenda-query-string
  5679. (if org-agenda-last-search-view-search-was-boolean
  5680. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5681. (?\{ . " +{}") (?\} . " -{}"))))
  5682. " "))
  5683. (setq org-agenda-redo-command
  5684. (list 'org-search-view
  5685. org-todo-only
  5686. org-agenda-query-string
  5687. (+ (length org-agenda-query-string)
  5688. (if (member char '(?\{ ?\})) 0 1))))
  5689. (set-register org-agenda-query-register org-agenda-query-string)
  5690. (org-agenda-redo))
  5691. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5692. org-agenda-type))))
  5693. (defun org-add-to-string (var string)
  5694. (set var (concat (symbol-value var) string)))
  5695. (defun org-agenda-goto-date (date)
  5696. "Jump to DATE in agenda."
  5697. (interactive (list (let ((org-read-date-prefer-future
  5698. (eval org-agenda-jump-prefer-future)))
  5699. (org-read-date))))
  5700. (org-agenda-list nil date))
  5701. (defun org-agenda-goto-today ()
  5702. "Go to today."
  5703. (interactive)
  5704. (org-agenda-check-type t 'timeline 'agenda)
  5705. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5706. (cond
  5707. (tdpos (goto-char tdpos))
  5708. ((eq org-agenda-type 'agenda)
  5709. (let* ((sd (org-agenda-compute-starting-span
  5710. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5711. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5712. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5713. (org-agenda-redo)
  5714. (org-agenda-find-same-or-today-or-agenda)))
  5715. (t (error "Cannot find today")))))
  5716. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5717. (goto-char
  5718. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5719. (text-property-any (point-min) (point-max) 'org-today t)
  5720. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5721. (point-min))))
  5722. (defun org-agenda-later (arg)
  5723. "Go forward in time by thee current span.
  5724. With prefix ARG, go forward that many times the current span."
  5725. (interactive "p")
  5726. (org-agenda-check-type t 'agenda)
  5727. (let* ((span org-agenda-current-span)
  5728. (sd org-starting-day)
  5729. (greg (calendar-gregorian-from-absolute sd))
  5730. (cnt (org-get-at-bol 'org-day-cnt))
  5731. greg2)
  5732. (cond
  5733. ((eq span 'day)
  5734. (setq sd (+ arg sd)))
  5735. ((eq span 'week)
  5736. (setq sd (+ (* 7 arg) sd)))
  5737. ((eq span 'month)
  5738. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5739. sd (calendar-absolute-from-gregorian greg2))
  5740. (setcar greg2 (1+ (car greg2))))
  5741. ((eq span 'year)
  5742. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5743. sd (calendar-absolute-from-gregorian greg2))
  5744. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5745. (t
  5746. (setq sd (+ (* span arg) sd))))
  5747. (let ((org-agenda-overriding-arguments
  5748. (list (car org-agenda-last-arguments) sd span t)))
  5749. (org-agenda-redo)
  5750. (org-agenda-find-same-or-today-or-agenda cnt))))
  5751. (defun org-agenda-earlier (arg)
  5752. "Go backward in time by the current span.
  5753. With prefix ARG, go backward that many times the current span."
  5754. (interactive "p")
  5755. (org-agenda-later (- arg)))
  5756. (defun org-agenda-view-mode-dispatch ()
  5757. "Call one of the view mode commands."
  5758. (interactive)
  5759. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5760. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5761. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5762. (let ((a (read-char-exclusive)))
  5763. (case a
  5764. (?\ (call-interactively 'org-agenda-reset-view))
  5765. (?d (call-interactively 'org-agenda-day-view))
  5766. (?w (call-interactively 'org-agenda-week-view))
  5767. (?m (call-interactively 'org-agenda-month-view))
  5768. (?y (call-interactively 'org-agenda-year-view))
  5769. (?l (call-interactively 'org-agenda-log-mode))
  5770. (?L (org-agenda-log-mode '(4)))
  5771. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5772. (?a (call-interactively 'org-agenda-archives-mode))
  5773. (?A (org-agenda-archives-mode 'files))
  5774. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5775. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5776. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5777. (?D (call-interactively 'org-agenda-toggle-diary))
  5778. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5779. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5780. (org-agenda-check-type t 'timeline 'agenda)
  5781. (org-agenda-redo))
  5782. (message "Display now includes inactive timestamps as well"))
  5783. (?q (message "Abort"))
  5784. (otherwise (error "Invalid key" )))))
  5785. (defun org-agenda-reset-view ()
  5786. "Switch to default view for agenda."
  5787. (interactive)
  5788. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5789. (defun org-agenda-day-view (&optional day-of-year)
  5790. "Switch to daily view for agenda.
  5791. With argument DAY-OF-YEAR, switch to that day of the year."
  5792. (interactive "P")
  5793. (org-agenda-change-time-span 'day day-of-year))
  5794. (defun org-agenda-week-view (&optional iso-week)
  5795. "Switch to daily view for agenda.
  5796. With argument ISO-WEEK, switch to the corresponding ISO week.
  5797. If ISO-WEEK has more then 2 digits, only the last two encode the
  5798. week. Any digits before this encode a year. So 200712 means
  5799. week 12 of year 2007. Years in the range 1938-2037 can also be
  5800. written as 2-digit years."
  5801. (interactive "P")
  5802. (org-agenda-change-time-span 'week iso-week))
  5803. (defun org-agenda-month-view (&optional month)
  5804. "Switch to monthly view for agenda.
  5805. With argument MONTH, switch to that month."
  5806. (interactive "P")
  5807. (org-agenda-change-time-span 'month month))
  5808. (defun org-agenda-year-view (&optional year)
  5809. "Switch to yearly view for agenda.
  5810. With argument YEAR, switch to that year.
  5811. If MONTH has more then 2 digits, only the last two encode the
  5812. month. Any digits before this encode a year. So 200712 means
  5813. December year 2007. Years in the range 1938-2037 can also be
  5814. written as 2-digit years."
  5815. (interactive "P")
  5816. (when year
  5817. (setq year (org-small-year-to-year year)))
  5818. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5819. (org-agenda-change-time-span 'year year)
  5820. (error "Abort")))
  5821. (defun org-agenda-change-time-span (span &optional n)
  5822. "Change the agenda view to SPAN.
  5823. SPAN may be `day', `week', `month', `year'."
  5824. (org-agenda-check-type t 'agenda)
  5825. (if (and (not n) (equal org-agenda-current-span span))
  5826. (error "Viewing span is already \"%s\"" span))
  5827. (let* ((sd (or (org-get-at-bol 'day)
  5828. org-starting-day))
  5829. (sd (org-agenda-compute-starting-span sd span n))
  5830. (org-agenda-overriding-arguments
  5831. (list (car org-agenda-last-arguments) sd span t)))
  5832. (org-agenda-redo)
  5833. (org-agenda-find-same-or-today-or-agenda))
  5834. (org-agenda-set-mode-name)
  5835. (message "Switched to %s view" span))
  5836. (defun org-agenda-compute-starting-span (sd span &optional n)
  5837. "Compute starting date for agenda.
  5838. SPAN may be `day', `week', `month', `year'. The return value
  5839. is a cons cell with the starting date and the number of days,
  5840. so that the date SD will be in that range."
  5841. (let* ((greg (calendar-gregorian-from-absolute sd))
  5842. (dg (nth 1 greg))
  5843. (mg (car greg))
  5844. (yg (nth 2 greg)))
  5845. (cond
  5846. ((eq span 'day)
  5847. (when n
  5848. (setq sd (+ (calendar-absolute-from-gregorian
  5849. (list mg 1 yg))
  5850. n -1))))
  5851. ((eq span 'week)
  5852. (let* ((nt (calendar-day-of-week
  5853. (calendar-gregorian-from-absolute sd)))
  5854. (d (if org-agenda-start-on-weekday
  5855. (- nt org-agenda-start-on-weekday)
  5856. 0))
  5857. y1)
  5858. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5859. (when n
  5860. (require 'cal-iso)
  5861. (when (> n 99)
  5862. (setq y1 (org-small-year-to-year (/ n 100))
  5863. n (mod n 100)))
  5864. (setq sd
  5865. (calendar-absolute-from-iso
  5866. (list n 1
  5867. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  5868. ((eq span 'month)
  5869. (let (y1)
  5870. (when (and n (> n 99))
  5871. (setq y1 (org-small-year-to-year (/ n 100))
  5872. n (mod n 100)))
  5873. (setq sd (calendar-absolute-from-gregorian
  5874. (list (or n mg) 1 (or y1 yg))))))
  5875. ((eq span 'year)
  5876. (setq sd (calendar-absolute-from-gregorian
  5877. (list 1 1 (or n yg))))))
  5878. sd))
  5879. (defun org-agenda-next-date-line (&optional arg)
  5880. "Jump to the next line indicating a date in agenda buffer."
  5881. (interactive "p")
  5882. (org-agenda-check-type t 'agenda 'timeline)
  5883. (beginning-of-line 1)
  5884. ;; This does not work if user makes date format that starts with a blank
  5885. (if (looking-at "^\\S-") (forward-char 1))
  5886. (if (not (re-search-forward "^\\S-" nil t arg))
  5887. (progn
  5888. (backward-char 1)
  5889. (error "No next date after this line in this buffer")))
  5890. (goto-char (match-beginning 0)))
  5891. (defun org-agenda-previous-date-line (&optional arg)
  5892. "Jump to the previous line indicating a date in agenda buffer."
  5893. (interactive "p")
  5894. (org-agenda-check-type t 'agenda 'timeline)
  5895. (beginning-of-line 1)
  5896. (if (not (re-search-backward "^\\S-" nil t arg))
  5897. (error "No previous date before this line in this buffer")))
  5898. ;; Initialize the highlight
  5899. (defvar org-hl (make-overlay 1 1))
  5900. (overlay-put org-hl 'face 'highlight)
  5901. (defun org-highlight (begin end &optional buffer)
  5902. "Highlight a region with overlay."
  5903. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5904. (defun org-unhighlight ()
  5905. "Detach overlay INDEX."
  5906. (org-detach-overlay org-hl))
  5907. ;; FIXME this is currently not used.
  5908. (defun org-highlight-until-next-command (beg end &optional buffer)
  5909. "Move the highlight overlay to BEG/END, remove it before the next command."
  5910. (org-highlight beg end buffer)
  5911. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5912. (defun org-unhighlight-once ()
  5913. "Remove the highlight from its position, and this function from the hook."
  5914. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5915. (org-unhighlight))
  5916. (defun org-agenda-follow-mode ()
  5917. "Toggle follow mode in an agenda buffer."
  5918. (interactive)
  5919. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5920. (org-agenda-set-mode-name)
  5921. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5922. (org-agenda-show))
  5923. (message "Follow mode is %s"
  5924. (if org-agenda-follow-mode "on" "off")))
  5925. (defun org-agenda-entry-text-mode (&optional arg)
  5926. "Toggle entry text mode in an agenda buffer."
  5927. (interactive "P")
  5928. (setq org-agenda-entry-text-mode (or (integerp arg)
  5929. (not org-agenda-entry-text-mode)))
  5930. (org-agenda-entry-text-hide)
  5931. (and org-agenda-entry-text-mode
  5932. (let ((org-agenda-entry-text-maxlines
  5933. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5934. (org-agenda-entry-text-show)))
  5935. (org-agenda-set-mode-name)
  5936. (message "Entry text mode is %s. Maximum number of lines is %d"
  5937. (if org-agenda-entry-text-mode "on" "off")
  5938. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5939. (defun org-agenda-clockreport-mode (&optional with-filter)
  5940. "Toggle clocktable mode in an agenda buffer.
  5941. With prefix arg WITH-FILTER, make the clocktable respect the current
  5942. agenda filter."
  5943. (interactive "P")
  5944. (org-agenda-check-type t 'agenda)
  5945. (if with-filter
  5946. (setq org-agenda-clockreport-mode 'with-filter)
  5947. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5948. (org-agenda-set-mode-name)
  5949. (org-agenda-redo)
  5950. (message "Clocktable mode is %s"
  5951. (if org-agenda-clockreport-mode "on" "off")))
  5952. (defun org-agenda-log-mode (&optional special)
  5953. "Toggle log mode in an agenda buffer.
  5954. With argument SPECIAL, show all possible log items, not only the ones
  5955. configured in `org-agenda-log-mode-items'.
  5956. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5957. (interactive "P")
  5958. (org-agenda-check-type t 'agenda 'timeline)
  5959. (setq org-agenda-show-log
  5960. (if (equal special '(16))
  5961. 'only
  5962. (if special '(closed clock state)
  5963. (not org-agenda-show-log))))
  5964. (org-agenda-set-mode-name)
  5965. (org-agenda-redo)
  5966. (message "Log mode is %s"
  5967. (if org-agenda-show-log "on" "off")))
  5968. (defun org-agenda-archives-mode (&optional with-files)
  5969. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5970. When called with a prefix argument, include all archive files as well."
  5971. (interactive "P")
  5972. (setq org-agenda-archives-mode
  5973. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5974. (org-agenda-set-mode-name)
  5975. (org-agenda-redo)
  5976. (message
  5977. "%s"
  5978. (cond
  5979. ((eq org-agenda-archives-mode nil)
  5980. "No archives are included")
  5981. ((eq org-agenda-archives-mode 'trees)
  5982. (format "Trees with :%s: tag are included" org-archive-tag))
  5983. ((eq org-agenda-archives-mode t)
  5984. (format "Trees with :%s: tag and all active archive files are included"
  5985. org-archive-tag)))))
  5986. (defun org-agenda-toggle-diary ()
  5987. "Toggle diary inclusion in an agenda buffer."
  5988. (interactive)
  5989. (org-agenda-check-type t 'agenda)
  5990. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5991. (org-agenda-redo)
  5992. (org-agenda-set-mode-name)
  5993. (message "Diary inclusion turned %s"
  5994. (if org-agenda-include-diary "on" "off")))
  5995. (defun org-agenda-toggle-deadlines ()
  5996. "Toggle inclusion of entries with a deadline in an agenda buffer."
  5997. (interactive)
  5998. (org-agenda-check-type t 'agenda)
  5999. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6000. (org-agenda-redo)
  6001. (org-agenda-set-mode-name)
  6002. (message "Deadlines inclusion turned %s"
  6003. (if org-agenda-include-deadlines "on" "off")))
  6004. (defun org-agenda-toggle-time-grid ()
  6005. "Toggle time grid in an agenda buffer."
  6006. (interactive)
  6007. (org-agenda-check-type t 'agenda)
  6008. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6009. (org-agenda-redo)
  6010. (org-agenda-set-mode-name)
  6011. (message "Time-grid turned %s"
  6012. (if org-agenda-use-time-grid "on" "off")))
  6013. (defun org-agenda-set-mode-name ()
  6014. "Set the mode name to indicate all the small mode settings."
  6015. (setq mode-name
  6016. (list "Org-Agenda"
  6017. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6018. " "
  6019. '(:eval (org-agenda-span-name org-agenda-current-span))
  6020. (if org-agenda-follow-mode " Follow" "")
  6021. (if org-agenda-entry-text-mode " ETxt" "")
  6022. (if org-agenda-include-diary " Diary" "")
  6023. (if org-agenda-include-deadlines " Ddl" "")
  6024. (if org-agenda-use-time-grid " Grid" "")
  6025. (if (and (boundp 'org-habit-show-habits)
  6026. org-habit-show-habits) " Habit" "")
  6027. (if (consp org-agenda-show-log) " LogAll"
  6028. (if org-agenda-show-log " Log" ""))
  6029. (if (or org-agenda-filter (get 'org-agenda-filter
  6030. :preset-filter))
  6031. (concat " {" (mapconcat
  6032. 'identity
  6033. (append (get 'org-agenda-filter
  6034. :preset-filter)
  6035. org-agenda-filter) "") "}")
  6036. "")
  6037. (if org-agenda-archives-mode
  6038. (if (eq org-agenda-archives-mode t)
  6039. " Archives"
  6040. (format " :%s:" org-archive-tag))
  6041. "")
  6042. (if org-agenda-clockreport-mode
  6043. (if (eq org-agenda-clockreport-mode 'with-filter)
  6044. " Clock{}" " Clock")
  6045. "")))
  6046. (force-mode-line-update))
  6047. (defun org-agenda-post-command-hook ()
  6048. (setq org-agenda-type
  6049. (or (get-text-property (point) 'org-agenda-type)
  6050. (get-text-property (max (point-min) (1- (point)))
  6051. 'org-agenda-type))))
  6052. (defun org-agenda-next-line ()
  6053. "Move cursor to the next line, and show if follow mode is active."
  6054. (interactive)
  6055. (call-interactively 'next-line)
  6056. (org-agenda-do-context-action))
  6057. (defun org-agenda-previous-line ()
  6058. "Move cursor to the previous line, and show if follow-mode is active."
  6059. (interactive)
  6060. (call-interactively 'previous-line)
  6061. (org-agenda-do-context-action))
  6062. (defun org-agenda-do-context-action ()
  6063. "Show outline path and, maybe, follow mode window."
  6064. (let ((m (org-get-at-bol 'org-marker)))
  6065. (if (and org-agenda-follow-mode m)
  6066. (org-agenda-show))
  6067. (if (and m org-agenda-show-outline-path)
  6068. (org-with-point-at m
  6069. (org-display-outline-path t)))))
  6070. (defun org-agenda-show-priority ()
  6071. "Show the priority of the current item.
  6072. This priority is composed of the main priority given with the [#A] cookies,
  6073. and by additional input from the age of a schedules or deadline entry."
  6074. (interactive)
  6075. (let* ((pri (org-get-at-bol 'priority)))
  6076. (message "Priority is %d" (if pri pri -1000))))
  6077. (defun org-agenda-show-tags ()
  6078. "Show the tags applicable to the current item."
  6079. (interactive)
  6080. (let* ((tags (org-get-at-bol 'tags)))
  6081. (if tags
  6082. (message "Tags are :%s:"
  6083. (org-no-properties (mapconcat 'identity tags ":")))
  6084. (message "No tags associated with this line"))))
  6085. (defun org-agenda-goto (&optional highlight)
  6086. "Go to the Org-mode file which contains the item at point."
  6087. (interactive)
  6088. (let* ((marker (or (org-get-at-bol 'org-marker)
  6089. (org-agenda-error)))
  6090. (buffer (marker-buffer marker))
  6091. (pos (marker-position marker)))
  6092. (switch-to-buffer-other-window buffer)
  6093. (widen)
  6094. (push-mark)
  6095. (goto-char pos)
  6096. (when (org-mode-p)
  6097. (org-show-context 'agenda)
  6098. (save-excursion
  6099. (and (outline-next-heading)
  6100. (org-flag-heading nil)))) ; show the next heading
  6101. (when (outline-invisible-p)
  6102. (show-entry)) ; display invisible text
  6103. (recenter (/ (window-height) 2))
  6104. (run-hooks 'org-agenda-after-show-hook)
  6105. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6106. (defvar org-agenda-after-show-hook nil
  6107. "Normal hook run after an item has been shown from the agenda.
  6108. Point is in the buffer where the item originated.")
  6109. (defun org-agenda-kill ()
  6110. "Kill the entry or subtree belonging to the current agenda entry."
  6111. (interactive)
  6112. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6113. (let* ((marker (or (org-get-at-bol 'org-marker)
  6114. (org-agenda-error)))
  6115. (buffer (marker-buffer marker))
  6116. (pos (marker-position marker))
  6117. (type (org-get-at-bol 'type))
  6118. dbeg dend (n 0) conf)
  6119. (org-with-remote-undo buffer
  6120. (with-current-buffer buffer
  6121. (save-excursion
  6122. (goto-char pos)
  6123. (if (and (org-mode-p) (not (member type '("sexp"))))
  6124. (setq dbeg (progn (org-back-to-heading t) (point))
  6125. dend (org-end-of-subtree t t))
  6126. (setq dbeg (point-at-bol)
  6127. dend (min (point-max) (1+ (point-at-eol)))))
  6128. (goto-char dbeg)
  6129. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6130. (setq conf (or (eq t org-agenda-confirm-kill)
  6131. (and (numberp org-agenda-confirm-kill)
  6132. (> n org-agenda-confirm-kill))))
  6133. (and conf
  6134. (not (y-or-n-p
  6135. (format "Delete entry with %d lines in buffer \"%s\"? "
  6136. n (buffer-name buffer))))
  6137. (error "Abort"))
  6138. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6139. (with-current-buffer buffer (delete-region dbeg dend))
  6140. (message "Agenda item and source killed"))))
  6141. (defvar org-archive-default-command)
  6142. (defun org-agenda-archive-default ()
  6143. "Archive the entry or subtree belonging to the current agenda entry."
  6144. (interactive)
  6145. (require 'org-archive)
  6146. (org-agenda-archive-with org-archive-default-command))
  6147. (defun org-agenda-archive-default-with-confirmation ()
  6148. "Archive the entry or subtree belonging to the current agenda entry."
  6149. (interactive)
  6150. (require 'org-archive)
  6151. (org-agenda-archive-with org-archive-default-command 'confirm))
  6152. (defun org-agenda-archive ()
  6153. "Archive the entry or subtree belonging to the current agenda entry."
  6154. (interactive)
  6155. (org-agenda-archive-with 'org-archive-subtree))
  6156. (defun org-agenda-archive-to-archive-sibling ()
  6157. "Move the entry to the archive sibling."
  6158. (interactive)
  6159. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6160. (defun org-agenda-archive-with (cmd &optional confirm)
  6161. "Move the entry to the archive sibling."
  6162. (interactive)
  6163. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6164. (let* ((marker (or (org-get-at-bol 'org-marker)
  6165. (org-agenda-error)))
  6166. (buffer (marker-buffer marker))
  6167. (pos (marker-position marker)))
  6168. (org-with-remote-undo buffer
  6169. (with-current-buffer buffer
  6170. (if (org-mode-p)
  6171. (if (and confirm
  6172. (not (y-or-n-p "Archive this subtree or entry? ")))
  6173. (error "Abort")
  6174. (save-excursion
  6175. (goto-char pos)
  6176. (org-remove-subtree-entries-from-agenda)
  6177. (org-back-to-heading t)
  6178. (funcall cmd)))
  6179. (error "Archiving works only in Org-mode files"))))))
  6180. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6181. "Remove all lines in the agenda that correspond to a given subtree.
  6182. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6183. If this information is not given, the function uses the tree at point."
  6184. (let ((buf (or buf (current-buffer))) m p)
  6185. (save-excursion
  6186. (unless (and beg end)
  6187. (org-back-to-heading t)
  6188. (setq beg (point))
  6189. (org-end-of-subtree t)
  6190. (setq end (point)))
  6191. (set-buffer (get-buffer org-agenda-buffer-name))
  6192. (save-excursion
  6193. (goto-char (point-max))
  6194. (beginning-of-line 1)
  6195. (while (not (bobp))
  6196. (when (and (setq m (org-get-at-bol 'org-marker))
  6197. (equal buf (marker-buffer m))
  6198. (setq p (marker-position m))
  6199. (>= p beg)
  6200. (< p end))
  6201. (let ((inhibit-read-only t))
  6202. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6203. (beginning-of-line 0))))))
  6204. (defun org-agenda-refile (&optional goto rfloc no-update)
  6205. "Refile the item at point."
  6206. (interactive "P")
  6207. (if (equal goto '(16))
  6208. (org-refile-goto-last-stored)
  6209. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6210. (org-agenda-error)))
  6211. (buffer (marker-buffer marker))
  6212. (pos (marker-position marker))
  6213. (rfloc (or rfloc
  6214. (org-refile-get-location
  6215. (if goto "Goto: " "Refile to: ") buffer
  6216. org-refile-allow-creating-parent-nodes))))
  6217. (with-current-buffer buffer
  6218. (save-excursion
  6219. (save-restriction
  6220. (widen)
  6221. (goto-char marker)
  6222. (org-remove-subtree-entries-from-agenda)
  6223. (org-refile goto buffer rfloc)))))
  6224. (unless no-update (org-agenda-redo))))
  6225. (defun org-agenda-open-link (&optional arg)
  6226. "Follow the link in the current line, if any.
  6227. This looks for a link in the displayed line in the agenda. It also looks
  6228. at the text of the entry itself."
  6229. (interactive "P")
  6230. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6231. (org-get-at-bol 'org-marker)))
  6232. (buffer (and marker (marker-buffer marker)))
  6233. (prefix (buffer-substring
  6234. (point-at-bol)
  6235. (+ (point-at-bol)
  6236. (or (org-get-at-bol 'prefix-length) 0)))))
  6237. (cond
  6238. (buffer
  6239. (with-current-buffer buffer
  6240. (save-excursion
  6241. (save-restriction
  6242. (widen)
  6243. (goto-char marker)
  6244. (org-offer-links-in-entry arg prefix)))))
  6245. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6246. (save-excursion
  6247. (beginning-of-line 1)
  6248. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6249. (org-open-link-from-string (match-string 1)))
  6250. (t (error "No link to open here")))))
  6251. (defun org-agenda-copy-local-variable (var)
  6252. "Get a variable from a referenced buffer and install it here."
  6253. (let ((m (org-get-at-bol 'org-marker)))
  6254. (when (and m (buffer-live-p (marker-buffer m)))
  6255. (org-set-local var (with-current-buffer (marker-buffer m)
  6256. (symbol-value var))))))
  6257. (defun org-agenda-switch-to (&optional delete-other-windows)
  6258. "Go to the Org-mode file which contains the item at point."
  6259. (interactive)
  6260. (if (and org-return-follows-link
  6261. (not (org-get-at-bol 'org-marker))
  6262. (org-in-regexp org-bracket-link-regexp))
  6263. (org-open-link-from-string (match-string 0))
  6264. (let* ((marker (or (org-get-at-bol 'org-marker)
  6265. (org-agenda-error)))
  6266. (buffer (marker-buffer marker))
  6267. (pos (marker-position marker)))
  6268. (switch-to-buffer buffer)
  6269. (and delete-other-windows (delete-other-windows))
  6270. (widen)
  6271. (goto-char pos)
  6272. (when (org-mode-p)
  6273. (org-show-context 'agenda)
  6274. (save-excursion
  6275. (and (outline-next-heading)
  6276. (org-flag-heading nil))) ; show the next heading
  6277. (when (outline-invisible-p)
  6278. (show-entry)))))) ; display invisible text
  6279. (defun org-agenda-goto-mouse (ev)
  6280. "Go to the Org-mode file which contains the item at the mouse click."
  6281. (interactive "e")
  6282. (mouse-set-point ev)
  6283. (org-agenda-goto))
  6284. (defun org-agenda-show (&optional full-entry)
  6285. "Display the Org-mode file which contains the item at point.
  6286. With prefix argument FULL-ENTRY, make the entire entry visible
  6287. if it was hidden in the outline."
  6288. (interactive "P")
  6289. (let ((win (selected-window)))
  6290. (if full-entry
  6291. (let ((org-show-entry-below t))
  6292. (org-agenda-goto t))
  6293. (org-agenda-goto t))
  6294. (select-window win)))
  6295. (defvar org-agenda-show-window nil)
  6296. (defun org-agenda-show-and-scroll-up ()
  6297. "Display the Org-mode file which contains the item at point.
  6298. When called repeatedly, scroll the window that is displaying the buffer."
  6299. (interactive)
  6300. (let ((win (selected-window)))
  6301. (if (and (window-live-p org-agenda-show-window)
  6302. (eq this-command last-command))
  6303. (progn
  6304. (select-window org-agenda-show-window)
  6305. (ignore-errors (scroll-up)))
  6306. (org-agenda-goto t)
  6307. (show-subtree)
  6308. (setq org-agenda-show-window (selected-window)))
  6309. (select-window win)))
  6310. (defun org-agenda-show-scroll-down ()
  6311. "Scroll down the window showing the agenda."
  6312. (interactive)
  6313. (let ((win (selected-window)))
  6314. (when (window-live-p org-agenda-show-window)
  6315. (select-window org-agenda-show-window)
  6316. (ignore-errors (scroll-down))
  6317. (select-window win))))
  6318. (defun org-agenda-show-1 (&optional more)
  6319. "Display the Org-mode file which contains the item at point.
  6320. The prefix arg selects the amount of information to display:
  6321. 0 hide the subtree
  6322. 1 just show the entry according to defaults.
  6323. 2 show the children view
  6324. 3 show the subtree view
  6325. 4 show the entire subtree and any LOGBOOK drawers
  6326. 5 show the entire subtree and any drawers
  6327. With prefix argument FULL-ENTRY, make the entire entry visible
  6328. if it was hidden in the outline."
  6329. (interactive "p")
  6330. (let ((win (selected-window)))
  6331. (org-agenda-goto t)
  6332. (org-recenter-heading 1)
  6333. (cond
  6334. ((= more 0)
  6335. (hide-subtree)
  6336. (save-excursion
  6337. (org-back-to-heading)
  6338. (run-hook-with-args 'org-cycle-hook 'folded))
  6339. (message "Remote: FOLDED"))
  6340. ((and (interactive-p) (= more 1))
  6341. (message "Remote: show with default settings"))
  6342. ((= more 2)
  6343. (show-entry)
  6344. (show-children)
  6345. (save-excursion
  6346. (org-back-to-heading)
  6347. (run-hook-with-args 'org-cycle-hook 'children))
  6348. (message "Remote: CHILDREN"))
  6349. ((= more 3)
  6350. (show-subtree)
  6351. (save-excursion
  6352. (org-back-to-heading)
  6353. (run-hook-with-args 'org-cycle-hook 'subtree))
  6354. (message "Remote: SUBTREE"))
  6355. ((= more 4)
  6356. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6357. (org-drawer-regexp
  6358. (concat "^[ \t]*:\\("
  6359. (mapconcat 'regexp-quote org-drawers "\\|")
  6360. "\\):[ \t]*$")))
  6361. (show-subtree)
  6362. (save-excursion
  6363. (org-back-to-heading)
  6364. (org-cycle-hide-drawers 'subtree)))
  6365. (message "Remote: SUBTREE AND LOGBOOK"))
  6366. ((> more 4)
  6367. (show-subtree)
  6368. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6369. (select-window win)))
  6370. (defun org-recenter-heading (n)
  6371. (save-excursion
  6372. (org-back-to-heading)
  6373. (recenter n)))
  6374. (defvar org-agenda-cycle-counter nil)
  6375. (defun org-agenda-cycle-show (&optional n)
  6376. "Show the current entry in another window, with default settings.
  6377. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6378. When use repeatedly in immediate succession, the remote entry will cycle
  6379. through visibility
  6380. children -> subtree -> folded
  6381. When called with a numeric prefix arg, that arg will be passed through to
  6382. `org-agenda-show-1'. For the interpretation of that argument, see the
  6383. docstring of `org-agenda-show-1'."
  6384. (interactive "P")
  6385. (if (integerp n)
  6386. (setq org-agenda-cycle-counter n)
  6387. (if (not (eq last-command this-command))
  6388. (setq org-agenda-cycle-counter 1)
  6389. (if (equal org-agenda-cycle-counter 0)
  6390. (setq org-agenda-cycle-counter 2)
  6391. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6392. (if (> org-agenda-cycle-counter 3)
  6393. (setq org-agenda-cycle-counter 0)))))
  6394. (org-agenda-show-1 org-agenda-cycle-counter))
  6395. (defun org-agenda-recenter (arg)
  6396. "Display the Org-mode file which contains the item at point and recenter."
  6397. (interactive "P")
  6398. (let ((win (selected-window)))
  6399. (org-agenda-goto t)
  6400. (recenter arg)
  6401. (select-window win)))
  6402. (defun org-agenda-show-mouse (ev)
  6403. "Display the Org-mode file which contains the item at the mouse click."
  6404. (interactive "e")
  6405. (mouse-set-point ev)
  6406. (org-agenda-show))
  6407. (defun org-agenda-check-no-diary ()
  6408. "Check if the entry is a diary link and abort if yes."
  6409. (if (org-get-at-bol 'org-agenda-diary-link)
  6410. (org-agenda-error)))
  6411. (defun org-agenda-error ()
  6412. (error "Command not allowed in this line"))
  6413. (defun org-agenda-tree-to-indirect-buffer ()
  6414. "Show the subtree corresponding to the current entry in an indirect buffer.
  6415. This calls the command `org-tree-to-indirect-buffer' from the original
  6416. Org-mode buffer.
  6417. With numerical prefix arg ARG, go up to this level and then take that tree.
  6418. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6419. use the dedicated frame)."
  6420. (interactive)
  6421. (org-agenda-check-no-diary)
  6422. (let* ((marker (or (org-get-at-bol 'org-marker)
  6423. (org-agenda-error)))
  6424. (buffer (marker-buffer marker))
  6425. (pos (marker-position marker)))
  6426. (with-current-buffer buffer
  6427. (save-excursion
  6428. (goto-char pos)
  6429. (call-interactively 'org-tree-to-indirect-buffer)))))
  6430. (defvar org-last-heading-marker (make-marker)
  6431. "Marker pointing to the headline that last changed its TODO state
  6432. by a remote command from the agenda.")
  6433. (defun org-agenda-todo-nextset ()
  6434. "Switch TODO entry to next sequence."
  6435. (interactive)
  6436. (org-agenda-todo 'nextset))
  6437. (defun org-agenda-todo-previousset ()
  6438. "Switch TODO entry to previous sequence."
  6439. (interactive)
  6440. (org-agenda-todo 'previousset))
  6441. (defun org-agenda-todo (&optional arg)
  6442. "Cycle TODO state of line at point, also in Org-mode file.
  6443. This changes the line at point, all other lines in the agenda referring to
  6444. the same tree node, and the headline of the tree node in the Org-mode file."
  6445. (interactive "P")
  6446. (org-agenda-check-no-diary)
  6447. (let* ((col (current-column))
  6448. (marker (or (org-get-at-bol 'org-marker)
  6449. (org-agenda-error)))
  6450. (buffer (marker-buffer marker))
  6451. (pos (marker-position marker))
  6452. (hdmarker (org-get-at-bol 'org-hd-marker))
  6453. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6454. (inhibit-read-only t)
  6455. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6456. (org-with-remote-undo buffer
  6457. (with-current-buffer buffer
  6458. (widen)
  6459. (goto-char pos)
  6460. (org-show-context 'agenda)
  6461. (save-excursion
  6462. (and (outline-next-heading)
  6463. (org-flag-heading nil))) ; show the next heading
  6464. (let ((current-prefix-arg arg))
  6465. (call-interactively 'org-todo))
  6466. (and (bolp) (forward-char 1))
  6467. (setq newhead (org-get-heading))
  6468. (when (and (org-bound-and-true-p
  6469. org-agenda-headline-snapshot-before-repeat)
  6470. (not (equal org-agenda-headline-snapshot-before-repeat
  6471. newhead))
  6472. todayp)
  6473. (setq newhead org-agenda-headline-snapshot-before-repeat
  6474. just-one t))
  6475. (save-excursion
  6476. (org-back-to-heading)
  6477. (move-marker org-last-heading-marker (point))))
  6478. (beginning-of-line 1)
  6479. (save-excursion
  6480. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6481. (org-move-to-column col))))
  6482. (defun org-agenda-add-note (&optional arg)
  6483. "Add a time-stamped note to the entry at point."
  6484. (interactive "P")
  6485. (org-agenda-check-no-diary)
  6486. (let* ((marker (or (org-get-at-bol 'org-marker)
  6487. (org-agenda-error)))
  6488. (buffer (marker-buffer marker))
  6489. (pos (marker-position marker))
  6490. (hdmarker (org-get-at-bol 'org-hd-marker))
  6491. (inhibit-read-only t))
  6492. (with-current-buffer buffer
  6493. (widen)
  6494. (goto-char pos)
  6495. (org-show-context 'agenda)
  6496. (save-excursion
  6497. (and (outline-next-heading)
  6498. (org-flag-heading nil))) ; show the next heading
  6499. (org-add-note))))
  6500. (defun org-agenda-change-all-lines (newhead hdmarker
  6501. &optional fixface just-this)
  6502. "Change all lines in the agenda buffer which match HDMARKER.
  6503. The new content of the line will be NEWHEAD (as modified by
  6504. `org-format-agenda-item'). HDMARKER is checked with
  6505. `equal' against all `org-hd-marker' text properties in the file.
  6506. If FIXFACE is non-nil, the face of each item is modified according to
  6507. the new TODO state.
  6508. If JUST-THIS is non-nil, change just the current line, not all.
  6509. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6510. (let* ((inhibit-read-only t)
  6511. (line (org-current-line))
  6512. (thetags (with-current-buffer (marker-buffer hdmarker)
  6513. (save-excursion (save-restriction (widen)
  6514. (goto-char hdmarker)
  6515. (org-get-tags-at)))))
  6516. props m pl undone-face done-face finish new dotime cat tags)
  6517. (save-excursion
  6518. (goto-char (point-max))
  6519. (beginning-of-line 1)
  6520. (while (not finish)
  6521. (setq finish (bobp))
  6522. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6523. (or (not just-this) (= (org-current-line) line))
  6524. (equal m hdmarker))
  6525. (setq props (text-properties-at (point))
  6526. dotime (org-get-at-bol 'dotime)
  6527. cat (org-get-at-bol 'org-category)
  6528. tags thetags
  6529. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6530. pl (org-get-at-bol 'prefix-length)
  6531. undone-face (org-get-at-bol 'undone-face)
  6532. done-face (org-get-at-bol 'done-face))
  6533. (goto-char (+ (point) pl))
  6534. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6535. (cond
  6536. ((equal new "")
  6537. (beginning-of-line 1)
  6538. (and (looking-at ".*\n?") (replace-match "")))
  6539. ((looking-at ".*")
  6540. (replace-match new t t)
  6541. (beginning-of-line 1)
  6542. (add-text-properties (point-at-bol) (point-at-eol) props)
  6543. (when fixface
  6544. (add-text-properties
  6545. (point-at-bol) (point-at-eol)
  6546. (list 'face
  6547. (if org-last-todo-state-is-todo
  6548. undone-face done-face))))
  6549. (org-agenda-highlight-todo 'line)
  6550. (beginning-of-line 1))
  6551. (t (error "Line update did not work"))))
  6552. (beginning-of-line 0)))
  6553. (org-finalize-agenda)))
  6554. (defun org-agenda-align-tags (&optional line)
  6555. "Align all tags in agenda items to `org-agenda-tags-column'."
  6556. (let ((inhibit-read-only t) l c)
  6557. (save-excursion
  6558. (goto-char (if line (point-at-bol) (point-min)))
  6559. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6560. (if line (point-at-eol) nil) t)
  6561. (add-text-properties
  6562. (match-beginning 2) (match-end 2)
  6563. (list 'face (delq nil (let ((prop (get-text-property
  6564. (match-beginning 2) 'face)))
  6565. (or (listp prop) (setq prop (list prop)))
  6566. (if (memq 'org-tag prop)
  6567. prop
  6568. (cons 'org-tag prop))))))
  6569. (setq l (- (match-end 2) (match-beginning 2))
  6570. c (if (< org-agenda-tags-column 0)
  6571. (- (abs org-agenda-tags-column) l)
  6572. org-agenda-tags-column))
  6573. (delete-region (match-beginning 1) (match-end 1))
  6574. (goto-char (match-beginning 1))
  6575. (insert (org-add-props
  6576. (make-string (max 1 (- c (current-column))) ?\ )
  6577. (plist-put (copy-sequence (text-properties-at (point)))
  6578. 'face nil))))
  6579. (goto-char (point-min))
  6580. (org-font-lock-add-tag-faces (point-max)))))
  6581. (defun org-agenda-priority-up ()
  6582. "Increase the priority of line at point, also in Org-mode file."
  6583. (interactive)
  6584. (org-agenda-priority 'up))
  6585. (defun org-agenda-priority-down ()
  6586. "Decrease the priority of line at point, also in Org-mode file."
  6587. (interactive)
  6588. (org-agenda-priority 'down))
  6589. (defun org-agenda-priority (&optional force-direction)
  6590. "Set the priority of line at point, also in Org-mode file.
  6591. This changes the line at point, all other lines in the agenda referring to
  6592. the same tree node, and the headline of the tree node in the Org-mode file."
  6593. (interactive)
  6594. (unless org-enable-priority-commands
  6595. (error "Priority commands are disabled"))
  6596. (org-agenda-check-no-diary)
  6597. (let* ((marker (or (org-get-at-bol 'org-marker)
  6598. (org-agenda-error)))
  6599. (hdmarker (org-get-at-bol 'org-hd-marker))
  6600. (buffer (marker-buffer hdmarker))
  6601. (pos (marker-position hdmarker))
  6602. (inhibit-read-only t)
  6603. newhead)
  6604. (org-with-remote-undo buffer
  6605. (with-current-buffer buffer
  6606. (widen)
  6607. (goto-char pos)
  6608. (org-show-context 'agenda)
  6609. (save-excursion
  6610. (and (outline-next-heading)
  6611. (org-flag-heading nil))) ; show the next heading
  6612. (funcall 'org-priority force-direction)
  6613. (end-of-line 1)
  6614. (setq newhead (org-get-heading)))
  6615. (org-agenda-change-all-lines newhead hdmarker)
  6616. (beginning-of-line 1))))
  6617. ;; FIXME: should fix the tags property of the agenda line.
  6618. (defun org-agenda-set-tags (&optional tag onoff)
  6619. "Set tags for the current headline."
  6620. (interactive)
  6621. (org-agenda-check-no-diary)
  6622. (if (and (org-region-active-p) (interactive-p))
  6623. (call-interactively 'org-change-tag-in-region)
  6624. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6625. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6626. (org-agenda-error)))
  6627. (buffer (marker-buffer hdmarker))
  6628. (pos (marker-position hdmarker))
  6629. (inhibit-read-only t)
  6630. newhead)
  6631. (org-with-remote-undo buffer
  6632. (with-current-buffer buffer
  6633. (widen)
  6634. (goto-char pos)
  6635. (save-excursion
  6636. (org-show-context 'agenda))
  6637. (save-excursion
  6638. (and (outline-next-heading)
  6639. (org-flag-heading nil))) ; show the next heading
  6640. (goto-char pos)
  6641. (if tag
  6642. (org-toggle-tag tag onoff)
  6643. (call-interactively 'org-set-tags))
  6644. (end-of-line 1)
  6645. (setq newhead (org-get-heading)))
  6646. (org-agenda-change-all-lines newhead hdmarker)
  6647. (beginning-of-line 1)))))
  6648. (defun org-agenda-set-property ()
  6649. "Set a property for the current headline."
  6650. (interactive)
  6651. (org-agenda-check-no-diary)
  6652. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6653. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6654. (org-agenda-error)))
  6655. (buffer (marker-buffer hdmarker))
  6656. (pos (marker-position hdmarker))
  6657. (inhibit-read-only t)
  6658. newhead)
  6659. (org-with-remote-undo buffer
  6660. (with-current-buffer buffer
  6661. (widen)
  6662. (goto-char pos)
  6663. (save-excursion
  6664. (org-show-context 'agenda))
  6665. (save-excursion
  6666. (and (outline-next-heading)
  6667. (org-flag-heading nil))) ; show the next heading
  6668. (goto-char pos)
  6669. (call-interactively 'org-set-property)))))
  6670. (defun org-agenda-set-effort ()
  6671. "Set the effort property for the current headline."
  6672. (interactive)
  6673. (org-agenda-check-no-diary)
  6674. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6675. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6676. (org-agenda-error)))
  6677. (buffer (marker-buffer hdmarker))
  6678. (pos (marker-position hdmarker))
  6679. (inhibit-read-only t)
  6680. newhead)
  6681. (org-with-remote-undo buffer
  6682. (with-current-buffer buffer
  6683. (widen)
  6684. (goto-char pos)
  6685. (save-excursion
  6686. (org-show-context 'agenda))
  6687. (save-excursion
  6688. (and (outline-next-heading)
  6689. (org-flag-heading nil))) ; show the next heading
  6690. (goto-char pos)
  6691. (call-interactively 'org-set-effort)
  6692. (end-of-line 1)))))
  6693. (defun org-agenda-toggle-archive-tag ()
  6694. "Toggle the archive tag for the current entry."
  6695. (interactive)
  6696. (org-agenda-check-no-diary)
  6697. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6698. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6699. (org-agenda-error)))
  6700. (buffer (marker-buffer hdmarker))
  6701. (pos (marker-position hdmarker))
  6702. (inhibit-read-only t)
  6703. newhead)
  6704. (org-with-remote-undo buffer
  6705. (with-current-buffer buffer
  6706. (widen)
  6707. (goto-char pos)
  6708. (org-show-context 'agenda)
  6709. (save-excursion
  6710. (and (outline-next-heading)
  6711. (org-flag-heading nil))) ; show the next heading
  6712. (call-interactively 'org-toggle-archive-tag)
  6713. (end-of-line 1)
  6714. (setq newhead (org-get-heading)))
  6715. (org-agenda-change-all-lines newhead hdmarker)
  6716. (beginning-of-line 1))))
  6717. (defun org-agenda-do-date-later (arg)
  6718. (interactive "P")
  6719. (cond
  6720. ((or (equal arg '(16))
  6721. (memq last-command
  6722. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6723. (setq this-command 'org-agenda-date-later-minutes)
  6724. (org-agenda-date-later-minutes 1))
  6725. ((or (equal arg '(4))
  6726. (memq last-command
  6727. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6728. (setq this-command 'org-agenda-date-later-hours)
  6729. (org-agenda-date-later-hours 1))
  6730. (t
  6731. (org-agenda-date-later (prefix-numeric-value arg)))))
  6732. (defun org-agenda-do-date-earlier (arg)
  6733. (interactive "P")
  6734. (cond
  6735. ((or (equal arg '(16))
  6736. (memq last-command
  6737. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6738. (setq this-command 'org-agenda-date-earlier-minutes)
  6739. (org-agenda-date-earlier-minutes 1))
  6740. ((or (equal arg '(4))
  6741. (memq last-command
  6742. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6743. (setq this-command 'org-agenda-date-earlier-hours)
  6744. (org-agenda-date-earlier-hours 1))
  6745. (t
  6746. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6747. (defun org-agenda-date-later (arg &optional what)
  6748. "Change the date of this item to one day later."
  6749. (interactive "p")
  6750. (org-agenda-check-type t 'agenda 'timeline)
  6751. (org-agenda-check-no-diary)
  6752. (let* ((marker (or (org-get-at-bol 'org-marker)
  6753. (org-agenda-error)))
  6754. (buffer (marker-buffer marker))
  6755. (pos (marker-position marker)))
  6756. (org-with-remote-undo buffer
  6757. (with-current-buffer buffer
  6758. (widen)
  6759. (goto-char pos)
  6760. (if (not (org-at-timestamp-p))
  6761. (error "Cannot find time stamp"))
  6762. (org-timestamp-change arg (or what 'day)))
  6763. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6764. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6765. (defun org-agenda-date-earlier (arg &optional what)
  6766. "Change the date of this item to one day earlier."
  6767. (interactive "p")
  6768. (org-agenda-date-later (- arg) what))
  6769. (defun org-agenda-date-later-minutes (arg)
  6770. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6771. (interactive "p")
  6772. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6773. (org-agenda-date-later arg 'minute))
  6774. (defun org-agenda-date-earlier-minutes (arg)
  6775. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6776. (interactive "p")
  6777. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6778. (org-agenda-date-earlier arg 'minute))
  6779. (defun org-agenda-date-later-hours (arg)
  6780. "Change the time of this item, in hour steps."
  6781. (interactive "p")
  6782. (org-agenda-date-later arg 'hour))
  6783. (defun org-agenda-date-earlier-hours (arg)
  6784. "Change the time of this item, in hour steps."
  6785. (interactive "p")
  6786. (org-agenda-date-earlier arg 'hour))
  6787. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6788. "Show new date stamp via text properties."
  6789. ;; We use text properties to make this undoable
  6790. (let ((inhibit-read-only t)
  6791. (buffer-invisibility-spec))
  6792. (setq stamp (concat " " prefix " => " stamp))
  6793. (save-excursion
  6794. (goto-char (point-max))
  6795. (while (not (bobp))
  6796. (when (equal marker (org-get-at-bol 'org-marker))
  6797. (org-move-to-column (- (window-width) (length stamp)) t)
  6798. (org-agenda-fix-tags-filter-overlays-at (point))
  6799. (if (featurep 'xemacs)
  6800. ;; Use `duplicable' property to trigger undo recording
  6801. (let ((ex (make-extent nil nil))
  6802. (gl (make-glyph stamp)))
  6803. (set-glyph-face gl 'secondary-selection)
  6804. (set-extent-properties
  6805. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6806. (insert-extent ex (1- (point)) (point-at-eol)))
  6807. (add-text-properties
  6808. (1- (point)) (point-at-eol)
  6809. (list 'display (org-add-props stamp nil
  6810. 'face 'secondary-selection))))
  6811. (beginning-of-line 1))
  6812. (beginning-of-line 0)))))
  6813. (defun org-agenda-date-prompt (arg)
  6814. "Change the date of this item. Date is prompted for, with default today.
  6815. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6816. be used to request time specification in the time stamp."
  6817. (interactive "P")
  6818. (org-agenda-check-type t 'agenda 'timeline)
  6819. (org-agenda-check-no-diary)
  6820. (let* ((marker (or (org-get-at-bol 'org-marker)
  6821. (org-agenda-error)))
  6822. (buffer (marker-buffer marker))
  6823. (pos (marker-position marker)))
  6824. (org-with-remote-undo buffer
  6825. (with-current-buffer buffer
  6826. (widen)
  6827. (goto-char pos)
  6828. (if (not (org-at-timestamp-p t))
  6829. (error "Cannot find time stamp"))
  6830. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6831. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6832. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6833. (defun org-agenda-schedule (arg &optional time)
  6834. "Schedule the item at point.
  6835. Arg is passed through to `org-schedule'."
  6836. (interactive "P")
  6837. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6838. (org-agenda-check-no-diary)
  6839. (let* ((marker (or (org-get-at-bol 'org-marker)
  6840. (org-agenda-error)))
  6841. (type (marker-insertion-type marker))
  6842. (buffer (marker-buffer marker))
  6843. (pos (marker-position marker))
  6844. (org-insert-labeled-timestamps-at-point nil)
  6845. ts)
  6846. (set-marker-insertion-type marker t)
  6847. (org-with-remote-undo buffer
  6848. (with-current-buffer buffer
  6849. (widen)
  6850. (goto-char pos)
  6851. (setq ts (org-schedule arg time)))
  6852. (org-agenda-show-new-time marker ts "S"))
  6853. (message "Item scheduled for %s" ts)))
  6854. (defun org-agenda-deadline (arg &optional time)
  6855. "Schedule the item at point.
  6856. Arg is passed through to `org-deadline'."
  6857. (interactive "P")
  6858. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6859. (org-agenda-check-no-diary)
  6860. (let* ((marker (or (org-get-at-bol 'org-marker)
  6861. (org-agenda-error)))
  6862. (buffer (marker-buffer marker))
  6863. (pos (marker-position marker))
  6864. (org-insert-labeled-timestamps-at-point nil)
  6865. ts)
  6866. (org-with-remote-undo buffer
  6867. (with-current-buffer buffer
  6868. (widen)
  6869. (goto-char pos)
  6870. (setq ts (org-deadline arg time)))
  6871. (org-agenda-show-new-time marker ts "D"))
  6872. (message "Deadline for this item set to %s" ts)))
  6873. (defun org-agenda-action ()
  6874. "Select entry for agenda action, or execute an agenda action.
  6875. This command prompts for another letter. Valid inputs are:
  6876. m Mark the entry at point for an agenda action
  6877. s Schedule the marked entry to the date at the cursor
  6878. d Set the deadline of the marked entry to the date at the cursor
  6879. r Call `org-remember' with cursor date as the default date
  6880. c Call `org-capture' with cursor date as the default date
  6881. SPC Show marked entry in other window
  6882. TAB Visit marked entry in other window
  6883. The cursor may be at a date in the calendar, or in the Org agenda."
  6884. (interactive)
  6885. (let (ans)
  6886. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6887. (setq ans (read-char-exclusive))
  6888. (cond
  6889. ((equal ans ?m)
  6890. ;; Mark this entry
  6891. (if (eq major-mode 'org-agenda-mode)
  6892. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6893. (org-get-at-bol 'org-marker))))
  6894. (if m
  6895. (progn
  6896. (move-marker org-agenda-action-marker
  6897. (marker-position m) (marker-buffer m))
  6898. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6899. (error "Don't know which entry to mark")))
  6900. (error "This command works only in the agenda")))
  6901. ((equal ans ?s)
  6902. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6903. ((equal ans ?d)
  6904. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6905. ((equal ans ?r)
  6906. (org-agenda-do-action '(org-remember) t))
  6907. ((equal ans ?c)
  6908. (org-agenda-do-action '(org-capture) t))
  6909. ((equal ans ?\ )
  6910. (let ((cw (selected-window)))
  6911. (org-switch-to-buffer-other-window
  6912. (marker-buffer org-agenda-action-marker))
  6913. (goto-char org-agenda-action-marker)
  6914. (org-show-context 'agenda)
  6915. (select-window cw)))
  6916. ((equal ans ?\C-i)
  6917. (org-switch-to-buffer-other-window
  6918. (marker-buffer org-agenda-action-marker))
  6919. (goto-char org-agenda-action-marker)
  6920. (org-show-context 'agenda))
  6921. (t (error "Invalid agenda action %c" ans)))))
  6922. (defun org-agenda-do-action (form &optional current-buffer)
  6923. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6924. (let ((org-overriding-default-time (org-get-cursor-date)))
  6925. (if current-buffer
  6926. (eval form)
  6927. (if (not (marker-buffer org-agenda-action-marker))
  6928. (error "No entry has been selected for agenda action")
  6929. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6930. (save-excursion
  6931. (save-restriction
  6932. (widen)
  6933. (goto-char org-agenda-action-marker)
  6934. (eval form))))))))
  6935. (defun org-agenda-clock-in (&optional arg)
  6936. "Start the clock on the currently selected item."
  6937. (interactive "P")
  6938. (org-agenda-check-no-diary)
  6939. (if (equal arg '(4))
  6940. (org-clock-in arg)
  6941. (let* ((marker (or (org-get-at-bol 'org-marker)
  6942. (org-agenda-error)))
  6943. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6944. marker))
  6945. (pos (marker-position marker))
  6946. newhead)
  6947. (org-with-remote-undo (marker-buffer marker)
  6948. (with-current-buffer (marker-buffer marker)
  6949. (widen)
  6950. (goto-char pos)
  6951. (org-show-context 'agenda)
  6952. (org-show-entry)
  6953. (org-cycle-hide-drawers 'children)
  6954. (org-clock-in arg)
  6955. (setq newhead (org-get-heading)))
  6956. (org-agenda-change-all-lines newhead hdmarker)))))
  6957. (defun org-agenda-clock-out ()
  6958. "Stop the currently running clock."
  6959. (interactive)
  6960. (unless (marker-buffer org-clock-marker)
  6961. (error "No running clock"))
  6962. (let ((marker (make-marker)) newhead)
  6963. (org-with-remote-undo (marker-buffer org-clock-marker)
  6964. (with-current-buffer (marker-buffer org-clock-marker)
  6965. (save-excursion
  6966. (save-restriction
  6967. (widen)
  6968. (goto-char org-clock-marker)
  6969. (org-back-to-heading t)
  6970. (move-marker marker (point))
  6971. (org-clock-out)
  6972. (setq newhead (org-get-heading))))))
  6973. (org-agenda-change-all-lines newhead marker)
  6974. (move-marker marker nil)))
  6975. (defun org-agenda-clock-cancel (&optional arg)
  6976. "Cancel the currently running clock."
  6977. (interactive "P")
  6978. (unless (marker-buffer org-clock-marker)
  6979. (error "No running clock"))
  6980. (org-with-remote-undo (marker-buffer org-clock-marker)
  6981. (org-clock-cancel)))
  6982. (defun org-agenda-clock-goto ()
  6983. "Jump to the currently clocked in task within the agenda.
  6984. If the currently clocked in task is not listed in the agenda
  6985. buffer, display it in another window."
  6986. (interactive)
  6987. (let (pos)
  6988. (mapc (lambda (o)
  6989. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6990. (setq pos (overlay-start o))))
  6991. (overlays-in (point-min) (point-max)))
  6992. (cond (pos (goto-char pos))
  6993. ;; If the currently clocked entry is not in the agenda
  6994. ;; buffer, we visit it in another window:
  6995. (org-clock-current-task
  6996. (org-switch-to-buffer-other-window (org-clock-goto)))
  6997. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6998. (defun org-agenda-diary-entry-in-org-file ()
  6999. "Make a diary entry in the file `org-agenda-diary-file'."
  7000. (let (d1 d2 char (text "") dp1 dp2)
  7001. (if (equal (buffer-name) "*Calendar*")
  7002. (setq d1 (calendar-cursor-to-date t)
  7003. d2 (car calendar-mark-ring))
  7004. (setq dp1 (get-text-property (point-at-bol) 'day))
  7005. (unless dp1 (error "No date defined in current line"))
  7006. (setq d1 (calendar-gregorian-from-absolute dp1)
  7007. d2 (and (ignore-errors (mark))
  7008. (save-excursion
  7009. (goto-char (mark))
  7010. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7011. (calendar-gregorian-from-absolute dp2))))
  7012. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7013. (setq char (read-char-exclusive))
  7014. (cond
  7015. ((equal char ?d)
  7016. (setq text (read-string "Day entry: "))
  7017. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7018. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7019. ((equal char ?a)
  7020. (setq d1 (list (car d1) (nth 1 d1)
  7021. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7022. (nth 2 d1))))
  7023. (setq text (read-string "Anniversary (use %d to show years): "))
  7024. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7025. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7026. ((equal char ?b)
  7027. (setq text (read-string "Block entry: "))
  7028. (unless (and d1 d2 (not (equal d1 d2)))
  7029. (error "No block of days selected"))
  7030. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7031. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7032. ((equal char ?j)
  7033. (org-switch-to-buffer-other-window
  7034. (find-file-noselect org-agenda-diary-file))
  7035. (require 'org-datetree)
  7036. (org-datetree-find-date-create d1)
  7037. (org-reveal t))
  7038. (t (error "Invalid selection character `%c'" char)))))
  7039. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7040. "Where in `org-agenda-diary-file' should new entries be added?
  7041. Valid values:
  7042. date-tree in the date tree, as child of the date
  7043. top-level as top-level entries at the end of the file."
  7044. :group 'org-agenda
  7045. :type '(choice
  7046. (const :tag "in a date tree" date-tree)
  7047. (const :tag "as top level at end of file" top-level)))
  7048. (defcustom org-agenda-insert-diary-extract-time nil
  7049. "Non-nil means extract any time specification from the diary entry."
  7050. :group 'org-agenda
  7051. :type 'boolean)
  7052. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7053. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7054. If TEXT is not empty, it will become the headline of the new entry, and
  7055. the resulting entry will not be shown. When TEXT is empty, switch to
  7056. `org-agenda-diary-file' and let the user finish the entry there."
  7057. (let ((cw (current-window-configuration)))
  7058. (org-switch-to-buffer-other-window
  7059. (find-file-noselect org-agenda-diary-file))
  7060. (widen)
  7061. (goto-char (point-min))
  7062. (cond
  7063. ((eq type 'anniversary)
  7064. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7065. (progn
  7066. (or (org-on-heading-p t)
  7067. (progn
  7068. (outline-next-heading)
  7069. (insert "* Anniversaries\n\n")
  7070. (beginning-of-line -1)))))
  7071. (outline-next-heading)
  7072. (org-back-over-empty-lines)
  7073. (backward-char 1)
  7074. (insert "\n")
  7075. (require 'diary-lib)
  7076. (let ((calendar-date-display-form
  7077. (if (if (boundp 'calendar-date-style)
  7078. (eq calendar-date-style 'european)
  7079. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7080. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7081. '(day " " month " " year)
  7082. '(month " " day " " year))))
  7083. (insert (format "%%%%(diary-anniversary %s) %s"
  7084. (calendar-date-string d1 nil t) text))))
  7085. ((eq type 'day)
  7086. (let ((org-prefix-has-time t)
  7087. (org-agenda-time-leading-zero t)
  7088. fmt time time2)
  7089. (if org-agenda-insert-diary-extract-time
  7090. ;; Use org-format-agenda-item to parse text for a time-range and
  7091. ;; remove it. FIXME: This is a hack, we should refactor
  7092. ;; that function to make time extraction available separately
  7093. (setq fmt (org-format-agenda-item nil text nil nil t)
  7094. time (get-text-property 0 'time fmt)
  7095. time2 (if (> (length time) 0)
  7096. ;; split-string removes trailing ...... if
  7097. ;; no end time given. First space
  7098. ;; separates time from date.
  7099. (concat " " (car (split-string time "\\.")))
  7100. nil)
  7101. text (get-text-property 0 'txt fmt)))
  7102. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7103. (org-agenda-insert-diary-as-top-level text)
  7104. (require 'org-datetree)
  7105. (org-datetree-find-date-create d1)
  7106. (org-agenda-insert-diary-make-new-entry text))
  7107. (org-insert-time-stamp (org-time-from-absolute
  7108. (calendar-absolute-from-gregorian d1))
  7109. nil nil nil nil time2))
  7110. (end-of-line 0))
  7111. ((eq type 'block)
  7112. (if (> (calendar-absolute-from-gregorian d1)
  7113. (calendar-absolute-from-gregorian d2))
  7114. (setq d1 (prog1 d2 (setq d2 d1))))
  7115. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7116. (org-agenda-insert-diary-as-top-level text)
  7117. (require 'org-datetree)
  7118. (org-datetree-find-date-create d1)
  7119. (org-agenda-insert-diary-make-new-entry text))
  7120. (org-insert-time-stamp (org-time-from-absolute
  7121. (calendar-absolute-from-gregorian d1)))
  7122. (insert "--")
  7123. (org-insert-time-stamp (org-time-from-absolute
  7124. (calendar-absolute-from-gregorian d2)))
  7125. (end-of-line 0)))
  7126. (if (string-match "\\S-" text)
  7127. (progn
  7128. (set-window-configuration cw)
  7129. (message "%s entry added to %s"
  7130. (capitalize (symbol-name type))
  7131. (abbreviate-file-name org-agenda-diary-file)))
  7132. (org-reveal t)
  7133. (message "Please finish entry here"))))
  7134. (defun org-agenda-insert-diary-as-top-level (text)
  7135. "Make new entry as a top-level entry at the end of the file.
  7136. Add TEXT as headline, and position the cursor in the second line so that
  7137. a timestamp can be added there."
  7138. (widen)
  7139. (goto-char (point-max))
  7140. (or (bolp) (insert "\n"))
  7141. (insert "* " text "\n")
  7142. (if org-adapt-indentation (org-indent-to-column 2)))
  7143. (defun org-agenda-insert-diary-make-new-entry (text)
  7144. "Make new entry as last child of current entry.
  7145. Add TEXT as headline, and position the cursor in the second line so that
  7146. a timestamp can be added there."
  7147. (let ((org-show-following-heading t)
  7148. (org-show-siblings t)
  7149. (org-show-hierarchy-above t)
  7150. (org-show-entry-below t)
  7151. col)
  7152. (outline-next-heading)
  7153. (org-back-over-empty-lines)
  7154. (or (looking-at "[ \t]*$")
  7155. (progn (insert "\n") (backward-char 1)))
  7156. (org-insert-heading nil t)
  7157. (org-do-demote)
  7158. (setq col (current-column))
  7159. (insert text "\n")
  7160. (if org-adapt-indentation (org-indent-to-column col))
  7161. (let ((org-show-following-heading t)
  7162. (org-show-siblings t)
  7163. (org-show-hierarchy-above t)
  7164. (org-show-entry-below t))
  7165. (org-show-context))))
  7166. (defun org-agenda-diary-entry ()
  7167. "Make a diary entry, like the `i' command from the calendar.
  7168. All the standard commands work: block, weekly etc.
  7169. When `org-agenda-diary-file' points to a file,
  7170. `org-agenda-diary-entry-in-org-file' is called instead to create
  7171. entries in that Org-mode file."
  7172. (interactive)
  7173. (org-agenda-check-type t 'agenda 'timeline)
  7174. (if (not (eq org-agenda-diary-file 'diary-file))
  7175. (org-agenda-diary-entry-in-org-file)
  7176. (require 'diary-lib)
  7177. (let* ((char (progn
  7178. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7179. (read-char-exclusive)))
  7180. (cmd (cdr (assoc char
  7181. '((?d . insert-diary-entry)
  7182. (?w . insert-weekly-diary-entry)
  7183. (?m . insert-monthly-diary-entry)
  7184. (?y . insert-yearly-diary-entry)
  7185. (?a . insert-anniversary-diary-entry)
  7186. (?b . insert-block-diary-entry)
  7187. (?c . insert-cyclic-diary-entry)))))
  7188. (oldf (symbol-function 'calendar-cursor-to-date))
  7189. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7190. (point (point))
  7191. (mark (or (mark t) (point))))
  7192. (unless cmd
  7193. (error "No command associated with <%c>" char))
  7194. (unless (and (get-text-property point 'day)
  7195. (or (not (equal ?b char))
  7196. (get-text-property mark 'day)))
  7197. (error "Don't know which date to use for diary entry"))
  7198. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7199. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7200. (let ((calendar-mark-ring
  7201. (list (calendar-gregorian-from-absolute
  7202. (or (get-text-property mark 'day)
  7203. (get-text-property point 'day))))))
  7204. (unwind-protect
  7205. (progn
  7206. (fset 'calendar-cursor-to-date
  7207. (lambda (&optional error dummy)
  7208. (calendar-gregorian-from-absolute
  7209. (get-text-property point 'day))))
  7210. (call-interactively cmd))
  7211. (fset 'calendar-cursor-to-date oldf))))))
  7212. (defun org-agenda-execute-calendar-command (cmd)
  7213. "Execute a calendar command from the agenda, with the date associated to
  7214. the cursor position."
  7215. (org-agenda-check-type t 'agenda 'timeline)
  7216. (require 'diary-lib)
  7217. (unless (get-text-property (point) 'day)
  7218. (error "Don't know which date to use for calendar command"))
  7219. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7220. (point (point))
  7221. (date (calendar-gregorian-from-absolute
  7222. (get-text-property point 'day)))
  7223. ;; the following 2 vars are needed in the calendar
  7224. (displayed-month (car date))
  7225. (displayed-year (nth 2 date)))
  7226. (unwind-protect
  7227. (progn
  7228. (fset 'calendar-cursor-to-date
  7229. (lambda (&optional error dummy)
  7230. (calendar-gregorian-from-absolute
  7231. (get-text-property point 'day))))
  7232. (call-interactively cmd))
  7233. (fset 'calendar-cursor-to-date oldf))))
  7234. (defun org-agenda-phases-of-moon ()
  7235. "Display the phases of the moon for the 3 months around the cursor date."
  7236. (interactive)
  7237. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7238. (defun org-agenda-holidays ()
  7239. "Display the holidays for the 3 months around the cursor date."
  7240. (interactive)
  7241. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7242. (defvar calendar-longitude)
  7243. (defvar calendar-latitude)
  7244. (defvar calendar-location-name)
  7245. (defun org-agenda-sunrise-sunset (arg)
  7246. "Display sunrise and sunset for the cursor date.
  7247. Latitude and longitude can be specified with the variables
  7248. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7249. argument, latitude and longitude will be prompted for."
  7250. (interactive "P")
  7251. (require 'solar)
  7252. (let ((calendar-longitude (if arg nil calendar-longitude))
  7253. (calendar-latitude (if arg nil calendar-latitude))
  7254. (calendar-location-name
  7255. (if arg "the given coordinates" calendar-location-name)))
  7256. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7257. (defun org-agenda-goto-calendar ()
  7258. "Open the Emacs calendar with the date at the cursor."
  7259. (interactive)
  7260. (org-agenda-check-type t 'agenda 'timeline)
  7261. (let* ((day (or (get-text-property (point) 'day)
  7262. (error "Don't know which date to open in calendar")))
  7263. (date (calendar-gregorian-from-absolute day))
  7264. (calendar-move-hook nil)
  7265. (calendar-view-holidays-initially-flag nil)
  7266. (calendar-view-diary-initially-flag nil))
  7267. (calendar)
  7268. (calendar-goto-date date)))
  7269. ;;;###autoload
  7270. (defun org-calendar-goto-agenda ()
  7271. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7272. This is a command that has to be installed in `calendar-mode-map'."
  7273. (interactive)
  7274. (org-agenda-list nil (calendar-absolute-from-gregorian
  7275. (calendar-cursor-to-date))
  7276. nil))
  7277. (defun org-agenda-convert-date ()
  7278. (interactive)
  7279. (org-agenda-check-type t 'agenda 'timeline)
  7280. (let ((day (get-text-property (point) 'day))
  7281. date s)
  7282. (unless day
  7283. (error "Don't know which date to convert"))
  7284. (setq date (calendar-gregorian-from-absolute day))
  7285. (setq s (concat
  7286. "Gregorian: " (calendar-date-string date) "\n"
  7287. "ISO: " (calendar-iso-date-string date) "\n"
  7288. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7289. "Julian: " (calendar-julian-date-string date) "\n"
  7290. "Astron. JD: " (calendar-astro-date-string date)
  7291. " (Julian date number at noon UTC)\n"
  7292. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7293. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7294. "French: " (calendar-french-date-string date) "\n"
  7295. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7296. "Mayan: " (calendar-mayan-date-string date) "\n"
  7297. "Coptic: " (calendar-coptic-date-string date) "\n"
  7298. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7299. "Persian: " (calendar-persian-date-string date) "\n"
  7300. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7301. (with-output-to-temp-buffer "*Dates*"
  7302. (princ s))
  7303. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7304. ;;; Bulk commands
  7305. (defvar org-agenda-bulk-marked-entries nil
  7306. "List of markers that refer to marked entries in the agenda.")
  7307. (defun org-agenda-bulk-marked-p ()
  7308. (eq (get-char-property (point-at-bol) 'type)
  7309. 'org-marked-entry-overlay))
  7310. (defun org-agenda-bulk-mark (&optional arg)
  7311. "Mark the entry at point for future bulk action."
  7312. (interactive "p")
  7313. (dotimes (i (max arg 1))
  7314. (unless (org-get-at-bol 'org-agenda-diary-link)
  7315. (let* ((m (org-get-at-bol 'org-hd-marker))
  7316. ov)
  7317. (unless (org-agenda-bulk-marked-p)
  7318. (unless m (error "Nothing to mark at point"))
  7319. (push m org-agenda-bulk-marked-entries)
  7320. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7321. (org-overlay-display ov "> "
  7322. (org-get-todo-face "TODO")
  7323. 'evaporate)
  7324. (overlay-put ov 'type 'org-marked-entry-overlay))
  7325. (beginning-of-line 2)
  7326. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7327. (beginning-of-line 2))
  7328. (message "%d entries marked for bulk action"
  7329. (length org-agenda-bulk-marked-entries))))))
  7330. (defun org-agenda-bulk-mark-regexp (regexp)
  7331. "Mark entries match REGEXP."
  7332. (interactive "sRegexp: ")
  7333. (save-excursion
  7334. (goto-char (point-min))
  7335. (while (re-search-forward regexp nil t)
  7336. (call-interactively 'org-agenda-bulk-mark))))
  7337. (defun org-agenda-bulk-unmark ()
  7338. "Unmark the entry at point for future bulk action."
  7339. (interactive)
  7340. (when (org-agenda-bulk-marked-p)
  7341. (org-agenda-bulk-remove-overlays
  7342. (point-at-bol) (+ 2 (point-at-bol)))
  7343. (setq org-agenda-bulk-marked-entries
  7344. (delete (org-get-at-bol 'org-hd-marker)
  7345. org-agenda-bulk-marked-entries)))
  7346. (beginning-of-line 2)
  7347. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7348. (beginning-of-line 2))
  7349. (message "%d entries marked for bulk action"
  7350. (length org-agenda-bulk-marked-entries)))
  7351. (defun org-agenda-bulk-toggle ()
  7352. "Toggle marking the entry at point for bulk action."
  7353. (interactive)
  7354. (if (org-agenda-bulk-marked-p)
  7355. (org-agenda-bulk-unmark)
  7356. (org-agenda-bulk-mark)))
  7357. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7358. "Remove the mark overlays between BEG and END in the agenda buffer.
  7359. BEG and END default to the buffer limits.
  7360. This only removes the overlays, it does not remove the markers
  7361. from the list in `org-agenda-bulk-marked-entries'."
  7362. (interactive)
  7363. (mapc (lambda (ov)
  7364. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7365. (delete-overlay ov)))
  7366. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7367. (defun org-agenda-bulk-remove-all-marks ()
  7368. "Remove all marks in the agenda buffer.
  7369. This will remove the markers, and the overlays."
  7370. (interactive)
  7371. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7372. (setq org-agenda-bulk-marked-entries nil)
  7373. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7374. (defun org-agenda-bulk-action (&optional arg)
  7375. "Execute an remote-editing action on all marked entries.
  7376. The prefix arg is passed through to the command if possible."
  7377. (interactive "P")
  7378. (unless org-agenda-bulk-marked-entries
  7379. (error "No entries are marked"))
  7380. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
  7381. (let* ((action (read-char-exclusive))
  7382. (org-log-refile (if org-log-refile 'time nil))
  7383. (entries (reverse org-agenda-bulk-marked-entries))
  7384. redo-at-end
  7385. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7386. (cond
  7387. ((equal action ?$)
  7388. (setq cmd '(org-agenda-archive)))
  7389. ((equal action ?A)
  7390. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7391. ((member action '(?r ?w))
  7392. (setq rfloc (org-refile-get-location
  7393. "Refile to: "
  7394. (marker-buffer (car org-agenda-bulk-marked-entries))
  7395. org-refile-allow-creating-parent-nodes))
  7396. (if (nth 3 rfloc)
  7397. (setcar (nthcdr 3 rfloc)
  7398. (move-marker (make-marker) (nth 3 rfloc)
  7399. (or (get-file-buffer (nth 1 rfloc))
  7400. (find-buffer-visiting (nth 1 rfloc))
  7401. (error "This should not happen")))))
  7402. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7403. redo-at-end t))
  7404. ((equal action ?t)
  7405. (setq state (org-icompleting-read
  7406. "Todo state: "
  7407. (with-current-buffer (marker-buffer (car entries))
  7408. (mapcar 'list org-todo-keywords-1))))
  7409. (setq cmd `(let ((org-inhibit-blocking t)
  7410. (org-inhibit-logging 'note))
  7411. (org-agenda-todo ,state))))
  7412. ((memq action '(?- ?+))
  7413. (setq tag (org-icompleting-read
  7414. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7415. (with-current-buffer (marker-buffer (car entries))
  7416. (delq nil
  7417. (mapcar (lambda (x)
  7418. (if (stringp (car x)) x)) org-tag-alist)))))
  7419. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7420. ((memq action '(?s ?d))
  7421. (let* ((date (unless arg
  7422. (org-read-date
  7423. nil nil nil
  7424. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7425. (ans (if arg nil org-read-date-final-answer))
  7426. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7427. (setq cmd `(let* ((bound (fboundp 'read-string))
  7428. (old (and bound (symbol-function 'read-string))))
  7429. (unwind-protect
  7430. (progn
  7431. (fset 'read-string (lambda (&rest ignore) ,ans))
  7432. (eval '(,c1 arg)))
  7433. (if bound
  7434. (fset 'read-string old)
  7435. (fmakunbound 'read-string)))))))
  7436. ((eq action '?S)
  7437. (let ((days (read-number
  7438. (format "Scatter tasks across how many %sdays: "
  7439. (if arg "week" "")) 7)))
  7440. (setq cmd
  7441. `(let ((distance (1+ (random ,days))))
  7442. (if arg
  7443. (let ((dist distance)
  7444. (day-of-week
  7445. (calendar-day-of-week
  7446. (calendar-gregorian-from-absolute (org-today)))))
  7447. (dotimes (i (1+ dist))
  7448. (while (member day-of-week org-agenda-weekend-days)
  7449. (incf distance)
  7450. (incf day-of-week)
  7451. (if (= day-of-week 7)
  7452. (setq day-of-week 0)))
  7453. (incf day-of-week)
  7454. (if (= day-of-week 7)
  7455. (setq day-of-week 0)))))
  7456. (org-agenda-schedule nil (current-time))
  7457. (org-agenda-date-later distance)))))
  7458. (t (error "Invalid bulk action")))
  7459. ;; Sort the markers, to make sure that parents are handled before children
  7460. (setq entries (sort entries
  7461. (lambda (a b)
  7462. (cond
  7463. ((equal (marker-buffer a) (marker-buffer b))
  7464. (< (marker-position a) (marker-position b)))
  7465. (t
  7466. (string< (buffer-name (marker-buffer a))
  7467. (buffer-name (marker-buffer b))))))))
  7468. ;; Now loop over all markers and apply cmd
  7469. (while (setq e (pop entries))
  7470. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7471. (if (not pos)
  7472. (progn (message "Skipping removed entry at %s" e)
  7473. (setq cntskip (1+ cntskip)))
  7474. (goto-char pos)
  7475. (eval cmd)
  7476. (setq org-agenda-bulk-marked-entries
  7477. (delete e org-agenda-bulk-marked-entries))
  7478. (setq cnt (1+ cnt))))
  7479. (setq org-agenda-bulk-marked-entries nil)
  7480. (org-agenda-bulk-remove-all-marks)
  7481. (when redo-at-end (org-agenda-redo))
  7482. (message "Acted on %d entries%s"
  7483. cnt
  7484. (if (= cntskip 0)
  7485. ""
  7486. (format ", skipped %d (disappeared before their turn)"
  7487. cntskip)))))
  7488. ;;; Flagging notes
  7489. (defun org-agenda-show-the-flagging-note ()
  7490. "Display the flagging note in the other window.
  7491. When called a second time in direct sequence, offer to remove the FLAGGING
  7492. tag and (if present) the flagging note."
  7493. (interactive)
  7494. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7495. (win (selected-window))
  7496. note heading newhead)
  7497. (unless hdmarker
  7498. (error "No linked entry at point"))
  7499. (if (and (eq this-command last-command)
  7500. (y-or-n-p "Unflag and remove any flagging note? "))
  7501. (progn
  7502. (org-agenda-remove-flag hdmarker)
  7503. (let ((win (get-buffer-window "*Flagging Note*")))
  7504. (and win (delete-window win)))
  7505. (message "Entry unflaged"))
  7506. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7507. (unless note
  7508. (error "No flagging note"))
  7509. (org-kill-new note)
  7510. (org-switch-to-buffer-other-window "*Flagging Note*")
  7511. (erase-buffer)
  7512. (insert note)
  7513. (goto-char (point-min))
  7514. (while (re-search-forward "\\\\n" nil t)
  7515. (replace-match "\n" t t))
  7516. (goto-char (point-min))
  7517. (select-window win)
  7518. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7519. (defun org-agenda-remove-flag (marker)
  7520. "Remove the FLAGGED tag and any flagging note in the entry."
  7521. (let (newhead)
  7522. (org-with-point-at marker
  7523. (org-toggle-tag "FLAGGED" 'off)
  7524. (org-entry-delete nil "THEFLAGGINGNOTE")
  7525. (setq newhead (org-get-heading)))
  7526. (org-agenda-change-all-lines newhead marker)
  7527. (message "Entry unflaged")))
  7528. (defun org-agenda-get-any-marker (&optional pos)
  7529. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7530. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7531. ;;; Appointment reminders
  7532. (defvar appt-time-msg-list)
  7533. ;;;###autoload
  7534. (defun org-agenda-to-appt (&optional refresh filter)
  7535. "Activate appointments found in `org-agenda-files'.
  7536. With a \\[universal-argument] prefix, refresh the list of
  7537. appointments.
  7538. If FILTER is t, interactively prompt the user for a regular
  7539. expression, and filter out entries that don't match it.
  7540. If FILTER is a string, use this string as a regular expression
  7541. for filtering entries out.
  7542. FILTER can also be an alist with the car of each cell being
  7543. either 'headline or 'category. For example:
  7544. '((headline \"IMPORTANT\")
  7545. (category \"Work\"))
  7546. will only add headlines containing IMPORTANT or headlines
  7547. belonging to the \"Work\" category."
  7548. (interactive "P")
  7549. (if refresh (setq appt-time-msg-list nil))
  7550. (if (eq filter t)
  7551. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7552. (let* ((cnt 0) ; count added events
  7553. (org-agenda-new-buffers nil)
  7554. (org-deadline-warning-days 0)
  7555. ;; Do not use `org-today' here because appt only takes
  7556. ;; time and without date as argument, so it may pass wrong
  7557. ;; information otherwise
  7558. (today (org-date-to-gregorian
  7559. (time-to-days (current-time))))
  7560. (org-agenda-restrict nil)
  7561. (files (org-agenda-files 'unrestricted)) entries file)
  7562. ;; Get all entries which may contain an appt
  7563. (org-prepare-agenda-buffers files)
  7564. (while (setq file (pop files))
  7565. (setq entries
  7566. (append entries
  7567. (org-agenda-get-day-entries
  7568. file today :timestamp :scheduled :deadline))))
  7569. (setq entries (delq nil entries))
  7570. ;; Map thru entries and find if we should filter them out
  7571. (mapc
  7572. (lambda(x)
  7573. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7574. (cat (get-text-property 1 'org-category x))
  7575. (tod (get-text-property 1 'time-of-day x))
  7576. (ok (or (null filter)
  7577. (and (stringp filter) (string-match filter evt))
  7578. (and (listp filter)
  7579. (or (string-match
  7580. (cadr (assoc 'category filter)) cat)
  7581. (string-match
  7582. (cadr (assoc 'headline filter)) evt))))))
  7583. ;; FIXME: Shall we remove text-properties for the appt text?
  7584. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7585. (when (and ok tod)
  7586. (setq tod (concat "00" (number-to-string tod))
  7587. tod (when (string-match
  7588. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7589. (concat (match-string 1 tod) ":"
  7590. (match-string 2 tod))))
  7591. (appt-add tod evt)
  7592. (setq cnt (1+ cnt))))) entries)
  7593. (org-release-buffers org-agenda-new-buffers)
  7594. (if (eq cnt 0)
  7595. (message "No event to add")
  7596. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7597. (defun org-agenda-todayp (date)
  7598. "Does DATE mean today, when considering `org-extend-today-until'?"
  7599. (let ((today (org-today))
  7600. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7601. date)))
  7602. (eq date today)))
  7603. (provide 'org-agenda)
  7604. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7605. ;;; org-agenda.el ends here