org-agenda.el 292 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650
  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: 6.35trans
  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-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  58. (defvar org-habit-show-habits)
  59. (defvar org-habit-show-habits-only-for-today)
  60. ;; Defined somewhere in this file, but used before definition.
  61. (defvar org-agenda-buffer-name)
  62. (defvar org-agenda-overriding-header)
  63. (defvar org-agenda-title-append nil)
  64. (defvar entry)
  65. (defvar date)
  66. (defvar org-agenda-undo-list)
  67. (defvar org-agenda-pending-undo-list)
  68. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  69. (defcustom org-agenda-confirm-kill 1
  70. "When set, remote killing from the agenda buffer needs confirmation.
  71. When t, a confirmation is always needed. When a number N, confirmation is
  72. only needed when the text to be killed contains more than N non-white lines."
  73. :group 'org-agenda
  74. :type '(choice
  75. (const :tag "Never" nil)
  76. (const :tag "Always" t)
  77. (integer :tag "When more than N lines")))
  78. (defcustom org-agenda-compact-blocks nil
  79. "Non-nil means make the block agenda more compact.
  80. This is done by leaving out unnecessary lines."
  81. :group 'org-agenda
  82. :type 'boolean)
  83. (defcustom org-agenda-block-separator ?=
  84. "The separator between blocks in the agenda.
  85. If this is a string, it will be used as the separator, with a newline added.
  86. If it is a character, it will be repeated to fill the window width."
  87. :group 'org-agenda
  88. :type '(choice
  89. (character)
  90. (string)))
  91. (defgroup org-agenda-export nil
  92. "Options concerning exporting agenda views in Org-mode."
  93. :tag "Org Agenda Export"
  94. :group 'org-agenda)
  95. (defcustom org-agenda-with-colors t
  96. "Non-nil means use colors in agenda views."
  97. :group 'org-agenda-export
  98. :type 'boolean)
  99. (defcustom org-agenda-exporter-settings nil
  100. "Alist of variable/value pairs that should be active during agenda export.
  101. This is a good place to set options for ps-print and for htmlize.
  102. Note that the way this is implemented, the values will be evaluated
  103. before assigned to the variables. So make sure to quote values you do
  104. *not* want evaluated, for example
  105. (setq org-agenda-exporter-settings
  106. '((ps-print-color-p 'black-white)))"
  107. :group 'org-agenda-export
  108. :type '(repeat
  109. (list
  110. (variable)
  111. (sexp :tag "Value"))))
  112. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  113. "Hook run in temporary buffer before writing it to an export file.
  114. A useful function is `org-agenda-add-entry-text'."
  115. :group 'org-agenda-export
  116. :type 'hook
  117. :options '(org-agenda-add-entry-text))
  118. (defcustom org-agenda-add-entry-text-maxlines 0
  119. "Maximum number of entry text lines to be added to agenda.
  120. This is only relevant when `org-agenda-add-entry-text' is part of
  121. `org-agenda-before-write-hook', which it is by default.
  122. When this is 0, nothing will happen. When it is greater than 0, it
  123. specifies the maximum number of lines that will be added for each entry
  124. that is listed in the agenda view.
  125. Note that this variable is not used during display, only when exporting
  126. the agenda. For agenda display, see org-agenda-entry-text-mode and the
  127. variable `org-agenda-entry-text-maxlines'."
  128. :group 'org-agenda
  129. :type 'integer)
  130. (defcustom org-agenda-add-entry-text-descriptive-links t
  131. "Non-nil means export org-links as descriptive links in agenda added text.
  132. This variable applies to the text added to the agenda when
  133. `org-agenda-add-entry-text-maxlines' is larger than 0.
  134. When this variable nil, the URL will (also) be shown."
  135. :group 'org-agenda
  136. :type 'boolean)
  137. (defcustom org-agenda-export-html-style ""
  138. "The style specification for exported HTML Agenda files.
  139. If this variable contains a string, it will replace the default <style>
  140. section as produced by `htmlize'.
  141. Since there are different ways of setting style information, this variable
  142. needs to contain the full HTML structure to provide a style, including the
  143. surrounding HTML tags. The style specifications should include definitions
  144. the fonts used by the agenda, here is an example:
  145. <style type=\"text/css\">
  146. p { font-weight: normal; color: gray; }
  147. .org-agenda-structure {
  148. font-size: 110%;
  149. color: #003399;
  150. font-weight: 600;
  151. }
  152. .org-todo {
  153. color: #cc6666;
  154. font-weight: bold;
  155. }
  156. .org-agenda-done {
  157. color: #339933;
  158. }
  159. .org-done {
  160. color: #339933;
  161. }
  162. .title { text-align: center; }
  163. .todo, .deadline { color: red; }
  164. .done { color: green; }
  165. </style>
  166. or, if you want to keep the style in a file,
  167. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  168. As the value of this option simply gets inserted into the HTML <head> header,
  169. you can \"misuse\" it to also add other text to the header. However,
  170. <style>...</style> is required, if not present the variable will be ignored."
  171. :group 'org-agenda-export
  172. :group 'org-export-html
  173. :type 'string)
  174. (defgroup org-agenda-custom-commands nil
  175. "Options concerning agenda views in Org-mode."
  176. :tag "Org Agenda Custom Commands"
  177. :group 'org-agenda)
  178. (defconst org-sorting-choice
  179. '(choice
  180. (const time-up) (const time-down)
  181. (const category-keep) (const category-up) (const category-down)
  182. (const tag-down) (const tag-up)
  183. (const priority-up) (const priority-down)
  184. (const todo-state-up) (const todo-state-down)
  185. (const effort-up) (const effort-down)
  186. (const habit-up) (const habit-down)
  187. (const user-defined-up) (const user-defined-down))
  188. "Sorting choices.")
  189. (defconst org-agenda-custom-commands-local-options
  190. `(repeat :tag "Local settings for this command. Remember to quote values"
  191. (choice :tag "Setting"
  192. (list :tag "Heading for this block"
  193. (const org-agenda-overriding-header)
  194. (string :tag "Headline"))
  195. (list :tag "Files to be searched"
  196. (const org-agenda-files)
  197. (list
  198. (const :format "" quote)
  199. (repeat (file))))
  200. (list :tag "Sorting strategy"
  201. (const org-agenda-sorting-strategy)
  202. (list
  203. (const :format "" quote)
  204. (repeat
  205. ,org-sorting-choice)))
  206. (list :tag "Prefix format"
  207. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  208. (string))
  209. (list :tag "Number of days in agenda"
  210. (const org-agenda-ndays)
  211. (integer :value 1))
  212. (list :tag "Fixed starting date"
  213. (const org-agenda-start-day)
  214. (string :value "2007-11-01"))
  215. (list :tag "Start on day of week"
  216. (const org-agenda-start-on-weekday)
  217. (choice :value 1
  218. (const :tag "Today" nil)
  219. (integer :tag "Weekday No.")))
  220. (list :tag "Include data from diary"
  221. (const org-agenda-include-diary)
  222. (boolean))
  223. (list :tag "Deadline Warning days"
  224. (const org-deadline-warning-days)
  225. (integer :value 1))
  226. (list :tag "Tags filter preset"
  227. (const org-agenda-filter-preset)
  228. (list
  229. (const :format "" quote)
  230. (repeat
  231. (string :tag "+tag or -tag"))))
  232. (list :tag "Set daily/weekly entry types"
  233. (const org-agenda-entry-types)
  234. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  235. (const :deadline)
  236. (const :scheduled)
  237. (const :timestamp)
  238. (const :sexp)))
  239. (list :tag "Standard skipping condition"
  240. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  241. (const org-agenda-skip-function)
  242. (list
  243. (const :format "" quote)
  244. (list
  245. (choice
  246. :tag "Skipping range"
  247. (const :tag "Skip entry" org-agenda-skip-entry-if)
  248. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  249. (repeat :inline t :tag "Conditions for skipping"
  250. (choice
  251. :tag "Condition type"
  252. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  253. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  254. (list :tag "TODO state is" :inline t
  255. (const 'todo)
  256. (choice
  257. (const :tag "any not-done state" 'todo)
  258. (const :tag "any done state" 'done)
  259. (const :tag "any state" 'any)
  260. (list :tag "Keyword list"
  261. (const :format "" quote)
  262. (repeat (string :tag "Keyword")))))
  263. (list :tag "TODO state is not" :inline t
  264. (const 'nottodo)
  265. (choice
  266. (const :tag "any not-done state" 'todo)
  267. (const :tag "any done state" 'done)
  268. (const :tag "any state" 'any)
  269. (list :tag "Keyword list"
  270. (const :format "" quote)
  271. (repeat (string :tag "Keyword")))))
  272. (const :tag "scheduled" 'scheduled)
  273. (const :tag "not scheduled" 'notscheduled)
  274. (const :tag "deadline" 'deadline)
  275. (const :tag "no deadline" 'notdeadline)
  276. (const :tag "timestamp" 'timestamp)
  277. (const :tag "no timestamp" 'nottimestamp))))))
  278. (list :tag "Non-standard skipping condition"
  279. :value (org-agenda-skip-function)
  280. (const org-agenda-skip-function)
  281. (sexp :tag "Function or form (quoted!)"))
  282. (list :tag "Any variable"
  283. (variable :tag "Variable")
  284. (sexp :tag "Value (sexp)"))))
  285. "Selection of examples for agenda command settings.
  286. This will be spliced into the custom type of
  287. `org-agenda-custom-commands'.")
  288. (defcustom org-agenda-custom-commands nil
  289. "Custom commands for the agenda.
  290. These commands will be offered on the splash screen displayed by the
  291. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  292. (key desc type match settings files)
  293. key The key (one or more characters as a string) to be associated
  294. with the command.
  295. desc A description of the command, when omitted or nil, a default
  296. description is built using MATCH.
  297. type The command type, any of the following symbols:
  298. agenda The daily/weekly agenda.
  299. todo Entries with a specific TODO keyword, in all agenda files.
  300. search Entries containing search words entry or headline.
  301. tags Tags/Property/TODO match in all agenda files.
  302. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  303. todo-tree Sparse tree of specific TODO keyword in *current* file.
  304. tags-tree Sparse tree with all tags matches in *current* file.
  305. occur-tree Occur sparse tree for *current* file.
  306. ... A user-defined function.
  307. match What to search for:
  308. - a single keyword for TODO keyword searches
  309. - a tags match expression for tags searches
  310. - a word search expression for text searches.
  311. - a regular expression for occur searches
  312. For all other commands, this should be the empty string.
  313. settings A list of option settings, similar to that in a let form, so like
  314. this: ((opt1 val1) (opt2 val2) ...). The values will be
  315. evaluated at the moment of execution, so quote them when needed.
  316. files A list of files file to write the produced agenda buffer to
  317. with the command `org-store-agenda-views'.
  318. If a file name ends in \".html\", an HTML version of the buffer
  319. is written out. If it ends in \".ps\", a postscript version is
  320. produced. Otherwise, only the plain text is written to the file.
  321. You can also define a set of commands, to create a composite agenda buffer.
  322. In this case, an entry looks like this:
  323. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  324. where
  325. desc A description string to be displayed in the dispatcher menu.
  326. cmd An agenda command, similar to the above. However, tree commands
  327. are no allowed, but instead you can get agenda and global todo list.
  328. So valid commands for a set are:
  329. (agenda \"\" settings)
  330. (alltodo \"\" settings)
  331. (stuck \"\" settings)
  332. (todo \"match\" settings files)
  333. (search \"match\" settings files)
  334. (tags \"match\" settings files)
  335. (tags-todo \"match\" settings files)
  336. Each command can carry a list of options, and another set of options can be
  337. given for the whole set of commands. Individual command options take
  338. precedence over the general options.
  339. When using several characters as key to a command, the first characters
  340. are prefix commands. For the dispatcher to display useful information, you
  341. should provide a description for the prefix, like
  342. (setq org-agenda-custom-commands
  343. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  344. (\"hl\" tags \"+HOME+Lisa\")
  345. (\"hp\" tags \"+HOME+Peter\")
  346. (\"hk\" tags \"+HOME+Kim\")))"
  347. :group 'org-agenda-custom-commands
  348. :type `(repeat
  349. (choice :value ("x" "Describe command here" tags "" nil)
  350. (list :tag "Single command"
  351. (string :tag "Access Key(s) ")
  352. (option (string :tag "Description"))
  353. (choice
  354. (const :tag "Agenda" agenda)
  355. (const :tag "TODO list" alltodo)
  356. (const :tag "Search words" search)
  357. (const :tag "Stuck projects" stuck)
  358. (const :tag "Tags/Property match (all agenda files)" tags)
  359. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  360. (const :tag "TODO keyword search (all agenda files)" todo)
  361. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  362. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  363. (const :tag "Occur tree (current buffer)" occur-tree)
  364. (sexp :tag "Other, user-defined function"))
  365. (string :tag "Match (only for some commands)")
  366. ,org-agenda-custom-commands-local-options
  367. (option (repeat :tag "Export" (file :tag "Export to"))))
  368. (list :tag "Command series, all agenda files"
  369. (string :tag "Access Key(s)")
  370. (string :tag "Description ")
  371. (repeat :tag "Component"
  372. (choice
  373. (list :tag "Agenda"
  374. (const :format "" agenda)
  375. (const :tag "" :format "" "")
  376. ,org-agenda-custom-commands-local-options)
  377. (list :tag "TODO list (all keywords)"
  378. (const :format "" alltodo)
  379. (const :tag "" :format "" "")
  380. ,org-agenda-custom-commands-local-options)
  381. (list :tag "Search words"
  382. (const :format "" search)
  383. (string :tag "Match")
  384. ,org-agenda-custom-commands-local-options)
  385. (list :tag "Stuck projects"
  386. (const :format "" stuck)
  387. (const :tag "" :format "" "")
  388. ,org-agenda-custom-commands-local-options)
  389. (list :tag "Tags search"
  390. (const :format "" tags)
  391. (string :tag "Match")
  392. ,org-agenda-custom-commands-local-options)
  393. (list :tag "Tags search, TODO entries only"
  394. (const :format "" tags-todo)
  395. (string :tag "Match")
  396. ,org-agenda-custom-commands-local-options)
  397. (list :tag "TODO keyword search"
  398. (const :format "" todo)
  399. (string :tag "Match")
  400. ,org-agenda-custom-commands-local-options)
  401. (list :tag "Other, user-defined function"
  402. (symbol :tag "function")
  403. (string :tag "Match")
  404. ,org-agenda-custom-commands-local-options)))
  405. (repeat :tag "Settings for entire command set"
  406. (list (variable :tag "Any variable")
  407. (sexp :tag "Value")))
  408. (option (repeat :tag "Export" (file :tag "Export to"))))
  409. (cons :tag "Prefix key documentation"
  410. (string :tag "Access Key(s)")
  411. (string :tag "Description ")))))
  412. (defcustom org-agenda-query-register ?o
  413. "The register holding the current query string.
  414. The purpose of this is that if you construct a query string interactively,
  415. you can then use it to define a custom command."
  416. :group 'org-agenda-custom-commands
  417. :type 'character)
  418. (defcustom org-stuck-projects
  419. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  420. "How to identify stuck projects.
  421. This is a list of four items:
  422. 1. A tags/todo/property matcher string that is used to identify a project.
  423. See the manual for a description of tag and property searches.
  424. The entire tree below a headline matched by this is considered one project.
  425. 2. A list of TODO keywords identifying non-stuck projects.
  426. If the project subtree contains any headline with one of these todo
  427. keywords, the project is considered to be not stuck. If you specify
  428. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  429. 3. A list of tags identifying non-stuck projects.
  430. If the project subtree contains any headline with one of these tags,
  431. the project is considered to be not stuck. If you specify \"*\" as
  432. a tag, any tag will mark the project unstuck. Note that this is about
  433. the explicit presence of a tag somewhere in the subtree, inherited
  434. tags to not count here. If inherited tags make a project not stuck,
  435. use \"-TAG\" in the tags part of the matcher under (1.) above.
  436. 4. An arbitrary regular expression matching non-stuck projects.
  437. If the project turns out to be not stuck, search continues also in the
  438. subtree to see if any of the subtasks have project status.
  439. See also the variable `org-tags-match-list-sublevels' which applies
  440. to projects matched by this search as well.
  441. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  442. or `C-c a #' to produce the list."
  443. :group 'org-agenda-custom-commands
  444. :type '(list
  445. (string :tag "Tags/TODO match to identify a project")
  446. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  447. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  448. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  449. (defcustom org-agenda-filter-effort-default-operator "<"
  450. "The default operator for effort estimate filtering.
  451. If you select an effort estimate limit without first pressing an operator,
  452. this one will be used."
  453. :group 'org-agenda-custom-commands
  454. :type '(choice (const :tag "less or equal" "<")
  455. (const :tag "greater or equal"">")
  456. (const :tag "equal" "=")))
  457. (defgroup org-agenda-skip nil
  458. "Options concerning skipping parts of agenda files."
  459. :tag "Org Agenda Skip"
  460. :group 'org-agenda)
  461. (defgroup org-agenda-daily/weekly nil
  462. "Options concerning the daily/weekly agenda."
  463. :tag "Org Agenda Daily/Weekly"
  464. :group 'org-agenda)
  465. (defgroup org-agenda-todo-list nil
  466. "Options concerning the global todo list agenda view."
  467. :tag "Org Agenda Todo List"
  468. :group 'org-agenda)
  469. (defgroup org-agenda-match-view nil
  470. "Options concerning the general tags/property/todo match agenda view."
  471. :tag "Org Agenda Match View"
  472. :group 'org-agenda)
  473. (defgroup org-agenda-search-view nil
  474. "Options concerning the general tags/property/todo match agenda view."
  475. :tag "Org Agenda Match View"
  476. :group 'org-agenda)
  477. (defvar org-agenda-archives-mode nil
  478. "Non-nil means the agenda will include archived items.
  479. If this is the symbol `trees', trees in the selected agenda scope
  480. that are marked with the ARCHIVE tag will be included anyway. When this is
  481. t, also all archive files associated with the current selection of agenda
  482. files will be included.")
  483. (defcustom org-agenda-skip-comment-trees t
  484. "Non-nil means skip trees that start with the COMMENT keyword.
  485. When nil, these trees are also scanned by agenda commands."
  486. :group 'org-agenda-skip
  487. :type 'boolean)
  488. (defcustom org-agenda-todo-list-sublevels t
  489. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  490. When nil, the sublevels of a TODO entry are not checked, resulting in
  491. potentially much shorter TODO lists."
  492. :group 'org-agenda-skip
  493. :group 'org-agenda-todo-list
  494. :type 'boolean)
  495. (defcustom org-agenda-todo-ignore-with-date nil
  496. "Non-nil means don't show entries with a date in the global todo list.
  497. You can use this if you prefer to mark mere appointments with a TODO keyword,
  498. but don't want them to show up in the TODO list.
  499. When this is set, it also covers deadlines and scheduled items, the settings
  500. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  501. will be ignored.
  502. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  503. :group 'org-agenda-skip
  504. :group 'org-agenda-todo-list
  505. :type 'boolean)
  506. (defcustom org-agenda-todo-ignore-scheduled nil
  507. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  508. This applies when creating the global todo list.
  509. Valid values are:
  510. past Don't show entries scheduled today or in the past.
  511. future Don't show entries scheduled in the future.
  512. The idea behind this is that by scheduling it, you don't want to
  513. think about it until the scheduled date.
  514. all Don't show any scheduled entries in the global todo list.
  515. The idea behind this is that by scheduling it, you have already
  516. \"taken care\" of this item.
  517. t Same as `all', for backward compatibility.
  518. See also `org-agenda-todo-ignore-with-date'.
  519. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  520. to make his option also apply to the tags-todo list."
  521. :group 'org-agenda-skip
  522. :group 'org-agenda-todo-list
  523. :type '(choice
  524. (const :tag "Ignore future-scheduled todos" future)
  525. (const :tag "Ignore past- or present-scheduled todos" past)
  526. (const :tag "Ignore all scheduled todos" all)
  527. (const :tag "Ignore all scheduled todos (compatibility)" t)
  528. (const :tag "Show scheduled todos" nil)))
  529. (defcustom org-agenda-todo-ignore-deadlines nil
  530. "Non-nil means ignore some deadlined TODO items when making TODO list.
  531. There are different motivations for using different values, please think
  532. carefully when configuring this variable.
  533. This applie when creating the global todo list.
  534. Valid values are:
  535. near Don't show near deadline entries. A deadline is near when it is
  536. closer than `org-deadline-warning-days' days. The idea behind this
  537. is that such items will appear in the agenda anyway.
  538. far Don't show TODO entries where a deadline has been defined, but
  539. the deadline is not near. This is useful if you don't want to
  540. use the todo list to figure out what to do now.
  541. past Don't show entries with a deadline timestamp for today or in the past.
  542. future Don't show entries with a deadline timestamp in the future, not even
  543. when they become `near' ones. Use it with caution.
  544. all Ignore all TODO entries that do have a deadline.
  545. t Same as `near', for backward compatibility.
  546. See also `org-agenda-todo-ignore-with-date'.
  547. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  548. to make his option also apply to the tags-todo list."
  549. :group 'org-agenda-skip
  550. :group 'org-agenda-todo-list
  551. :type '(choice
  552. (const :tag "Ignore near deadlines" near)
  553. (const :tag "Ignore near deadlines (compatibility)" t)
  554. (const :tag "Ignore far deadlines" far)
  555. (const :tag "Ignore all TODOs with a deadlines" all)
  556. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  557. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  558. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  559. The variables
  560. `org-agenda-todo-ignore-with-date',
  561. `org-agenda-todo-ignore-scheduled'
  562. `org-agenda-todo-ignore-deadlines'
  563. make the global TODO list skip entries that have time stamps of certain
  564. kinds. If this option is set, the same options will also apply for the
  565. tags-todo search, which is the general tags/property matcher
  566. restricted to unfinished TODO entries only."
  567. :group 'org-agenda-skip
  568. :group 'org-agenda-todo-list
  569. :group 'org-agenda-match-view
  570. :type 'boolean)
  571. (defcustom org-agenda-skip-scheduled-if-done nil
  572. "Non-nil means don't show scheduled items in agenda when they are done.
  573. This is relevant for the daily/weekly agenda, not for the TODO list. And
  574. it applies only to the actual date of the scheduling. Warnings about
  575. an item with a past scheduling dates are always turned off when the item
  576. is DONE."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-daily/weekly
  579. :type 'boolean)
  580. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  581. "Non-nil means skip scheduling line if same entry shows because of deadline.
  582. In the agenda of today, an entry can show up multiple times because
  583. it is both scheduled and has a nearby deadline, and maybe a plain time
  584. stamp as well.
  585. When this variable is t, then only the deadline is shown and the fact that
  586. the entry is scheduled today or was scheduled previously is not shown.
  587. When this variable is nil, the entry will be shown several times. When
  588. the variable is the symbol `not-today', then skip scheduled previously,
  589. but not scheduled today."
  590. :group 'org-agenda-skip
  591. :group 'org-agenda-daily/weekly
  592. :type '(choice
  593. (const :tag "Never" nil)
  594. (const :tag "Always" t)
  595. (const :tag "Not when scheduled today" not-today)))
  596. (defcustom org-agenda-skip-deadline-if-done nil
  597. "Non-nil means don't show deadlines when the corresponding item is done.
  598. When nil, the deadline is still shown and should give you a happy feeling.
  599. This is relevant for the daily/weekly agenda. And it applied only to the
  600. actually date of the deadline. Warnings about approaching and past-due
  601. deadlines are always turned off when the item is DONE."
  602. :group 'org-agenda-skip
  603. :group 'org-agenda-daily/weekly
  604. :type 'boolean)
  605. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  606. "Non-nil means skip deadline prewarning when entry is also scheduled.
  607. This will apply on all days where a prewarning for the deadline would
  608. be shown, but not at the day when the entry is actually due. On that day,
  609. the deadline will be shown anyway.
  610. This variable may be set to nil, t, or a number which will then give
  611. the number of days before the actual deadline when the prewarnings
  612. should resume.
  613. This can be used in a workflow where the first showing of the deadline will
  614. trigger you to schedule it, and then you don't want to be reminded of it
  615. because you will take care of it on the day when scheduled."
  616. :group 'org-agenda-skip
  617. :group 'org-agenda-daily/weekly
  618. :type '(choice
  619. (const :tag "Alwas show prewarning" nil)
  620. (const :tag "Remove prewarning if entry is scheduled" t)
  621. (integer :tag "Restart prewarning N days before deadline")))
  622. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  623. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  624. When non-nil, after the search for timestamps has matched once in an
  625. entry, the rest of the entry will not be searched."
  626. :group 'org-agenda-skip
  627. :type 'boolean)
  628. (defcustom org-agenda-skip-timestamp-if-done nil
  629. "Non-nil means don't select item by timestamp or -range if it is DONE."
  630. :group 'org-agenda-skip
  631. :group 'org-agenda-daily/weekly
  632. :type 'boolean)
  633. (defcustom org-agenda-dim-blocked-tasks t
  634. "Non-nil means dim blocked tasks in the agenda display.
  635. This causes some overhead during agenda construction, but if you
  636. have turned on `org-enforce-todo-dependencies',
  637. `org-enforce-todo-checkbox-dependencies', or any other blocking
  638. mechanism, this will create useful feedback in the agenda.
  639. Instead of t, this variable can also have the value `invisible'.
  640. Then blocked tasks will be invisible and only become visible when
  641. they become unblocked. An exemption to this behavior is when a task is
  642. blocked because of unchecked checkboxes below it. Since checkboxes do
  643. not show up in the agenda views, making this task invisible you remove any
  644. trace from agenda views that there is something to do. Therefore, a task
  645. that is blocked because of checkboxes will never be made invisible, it
  646. will only be dimmed."
  647. :group 'org-agenda-daily/weekly
  648. :group 'org-agenda-todo-list
  649. :type '(choice
  650. (const :tag "Do not dim" nil)
  651. (const :tag "Dim to a grey face" t)
  652. (const :tag "Make invisible" invisible)))
  653. (defcustom org-timeline-show-empty-dates 3
  654. "Non-nil means `org-timeline' also shows dates without an entry.
  655. When nil, only the days which actually have entries are shown.
  656. When t, all days between the first and the last date are shown.
  657. When an integer, show also empty dates, but if there is a gap of more than
  658. N days, just insert a special line indicating the size of the gap."
  659. :group 'org-agenda-skip
  660. :type '(choice
  661. (const :tag "None" nil)
  662. (const :tag "All" t)
  663. (integer :tag "at most")))
  664. (defgroup org-agenda-startup nil
  665. "Options concerning initial settings in the Agenda in Org Mode."
  666. :tag "Org Agenda Startup"
  667. :group 'org-agenda)
  668. (defcustom org-finalize-agenda-hook nil
  669. "Hook run just before displaying an agenda buffer."
  670. :group 'org-agenda-startup
  671. :type 'hook)
  672. (defcustom org-agenda-mouse-1-follows-link nil
  673. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  674. A longer mouse click will still set point. Does not work on XEmacs.
  675. Needs to be set before org.el is loaded."
  676. :group 'org-agenda-startup
  677. :type 'boolean)
  678. (defcustom org-agenda-start-with-follow-mode nil
  679. "The initial value of follow-mode in a newly created agenda window."
  680. :group 'org-agenda-startup
  681. :type 'boolean)
  682. (defcustom org-agenda-show-outline-path t
  683. "Non-nil means show outline path in echo area after line motion."
  684. :group 'org-agenda-startup
  685. :type 'boolean)
  686. (defcustom org-agenda-start-with-entry-text-mode nil
  687. "The initial value of entry-text-mode in a newly created agenda window."
  688. :group 'org-agenda-startup
  689. :type 'boolean)
  690. (defcustom org-agenda-entry-text-maxlines 5
  691. "Number of text lines to be added when `E' is pressed in the agenda.
  692. Note that this variable only used during agenda display. Add add entry text
  693. when exporting the agenda, configure the variable
  694. `org-agenda-add-entry-ext-maxlines'."
  695. :group 'org-agenda
  696. :type 'integer)
  697. (defcustom org-agenda-entry-text-exclude-regexps nil
  698. "List of regular expressions to clean up entry text.
  699. The complete matches of all regular expressions in this list will be
  700. removed from entry text before it is shown in the agenda."
  701. :group 'org-agenda
  702. :type '(repeat (regexp)))
  703. (defvar org-agenda-entry-text-cleanup-hook nil
  704. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  705. This cleanup is done in a temporary buffer, so the function may inspect and
  706. change the entire buffer.
  707. Some default stuff like drawers and scheduling/deadline dates will already
  708. have been removed when this is called, as will any matches for regular
  709. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  710. (defvar org-agenda-include-inactive-timestamps nil
  711. "Non-nil means include inactive time stamps in agenda and timeline.")
  712. (defgroup org-agenda-windows nil
  713. "Options concerning the windows used by the Agenda in Org Mode."
  714. :tag "Org Agenda Windows"
  715. :group 'org-agenda)
  716. (defcustom org-agenda-window-setup 'reorganize-frame
  717. "How the agenda buffer should be displayed.
  718. Possible values for this option are:
  719. current-window Show agenda in the current window, keeping all other windows.
  720. other-window Use `switch-to-buffer-other-window' to display agenda.
  721. reorganize-frame Show only two windows on the current frame, the current
  722. window and the agenda.
  723. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  724. Also, when exiting the agenda, kill that frame.
  725. See also the variable `org-agenda-restore-windows-after-quit'."
  726. :group 'org-agenda-windows
  727. :type '(choice
  728. (const current-window)
  729. (const other-frame)
  730. (const other-window)
  731. (const reorganize-frame)))
  732. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  733. "The min and max height of the agenda window as a fraction of frame height.
  734. The value of the variable is a cons cell with two numbers between 0 and 1.
  735. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  736. :group 'org-agenda-windows
  737. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  738. (defcustom org-agenda-restore-windows-after-quit nil
  739. "Non-nil means restore window configuration open exiting agenda.
  740. Before the window configuration is changed for displaying the agenda,
  741. the current status is recorded. When the agenda is exited with
  742. `q' or `x' and this option is set, the old state is restored. If
  743. `org-agenda-window-setup' is `other-frame', the value of this
  744. option will be ignored."
  745. :group 'org-agenda-windows
  746. :type 'boolean)
  747. (defcustom org-agenda-ndays 7
  748. "Number of days to include in overview display.
  749. Should be 1 or 7.
  750. Custom commands can set this variable in the options section."
  751. :group 'org-agenda-daily/weekly
  752. :type 'integer)
  753. (defcustom org-agenda-start-on-weekday 1
  754. "Non-nil means start the overview always on the specified weekday.
  755. 0 denotes Sunday, 1 denotes Monday etc.
  756. When nil, always start on the current day.
  757. Custom commands can set this variable in the options section."
  758. :group 'org-agenda-daily/weekly
  759. :type '(choice (const :tag "Today" nil)
  760. (integer :tag "Weekday No.")))
  761. (defcustom org-agenda-show-all-dates t
  762. "Non-nil means `org-agenda' shows every day in the selected range.
  763. When nil, only the days which actually have entries are shown."
  764. :group 'org-agenda-daily/weekly
  765. :type 'boolean)
  766. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  767. "Format string for displaying dates in the agenda.
  768. Used by the daily/weekly agenda and by the timeline. This should be
  769. a format string understood by `format-time-string', or a function returning
  770. the formatted date as a string. The function must take a single argument,
  771. a calendar-style date list like (month day year)."
  772. :group 'org-agenda-daily/weekly
  773. :type '(choice
  774. (string :tag "Format string")
  775. (function :tag "Function")))
  776. (defun org-agenda-format-date-aligned (date)
  777. "Format a date string for display in the daily/weekly agenda, or timeline.
  778. This function makes sure that dates are aligned for easy reading."
  779. (require 'cal-iso)
  780. (let* ((dayname (calendar-day-name date))
  781. (day (cadr date))
  782. (day-of-week (calendar-day-of-week date))
  783. (month (car date))
  784. (monthname (calendar-month-name month))
  785. (year (nth 2 date))
  786. (iso-week (org-days-to-iso-week
  787. (calendar-absolute-from-gregorian date)))
  788. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  789. (1- year))
  790. ((and (= month 12) (<= iso-week 1))
  791. (1+ year))
  792. (t year)))
  793. (weekstring (if (= day-of-week 1)
  794. (format " W%02d" iso-week)
  795. "")))
  796. (format "%-10s %2d %s %4d%s"
  797. dayname day monthname year weekstring)))
  798. (defcustom org-agenda-time-leading-zero nil
  799. "Non-nil means use leading zero for military times in agenda.
  800. For example, 9:30am would become 09:30 rather than 9:30."
  801. :group 'org-agenda-daily/weekly
  802. :type 'boolean)
  803. (defcustom org-agenda-weekend-days '(6 0)
  804. "Which days are weekend?
  805. These days get the special face `org-agenda-date-weekend' in the agenda
  806. and timeline buffers."
  807. :group 'org-agenda-daily/weekly
  808. :type '(set :greedy t
  809. (const :tag "Monday" 1)
  810. (const :tag "Tuesday" 2)
  811. (const :tag "Wednesday" 3)
  812. (const :tag "Thursday" 4)
  813. (const :tag "Friday" 5)
  814. (const :tag "Saturday" 6)
  815. (const :tag "Sunday" 0)))
  816. (defcustom org-agenda-include-diary nil
  817. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  818. Custom commands can set this variable in the options section."
  819. :group 'org-agenda-daily/weekly
  820. :type 'boolean)
  821. (defcustom org-agenda-include-deadlines t
  822. "If non-nil, include entries within their deadline warning period.
  823. Custom commands can set this variable in the options section."
  824. :group 'org-agenda-daily/weekly
  825. :type 'boolean)
  826. (defcustom org-agenda-include-all-todo nil
  827. "Set means weekly/daily agenda will always contain all TODO entries.
  828. The TODO entries will be listed at the top of the agenda, before
  829. the entries for specific days.
  830. This option is deprecated, it is better to define a block agenda instead."
  831. :group 'org-agenda-daily/weekly
  832. :type 'boolean)
  833. (defcustom org-agenda-repeating-timestamp-show-all t
  834. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  835. When nil, only one occurrence is shown, either today or the
  836. nearest into the future."
  837. :group 'org-agenda-daily/weekly
  838. :type 'boolean)
  839. (defcustom org-scheduled-past-days 10000
  840. "No. of days to continue listing scheduled items that are not marked DONE.
  841. When an item is scheduled on a date, it shows up in the agenda on this
  842. day and will be listed until it is marked done for the number of days
  843. given here."
  844. :group 'org-agenda-daily/weekly
  845. :type 'integer)
  846. (defcustom org-agenda-log-mode-items '(closed clock)
  847. "List of items that should be shown in agenda log mode.
  848. This list may contain the following symbols:
  849. closed Show entries that have been closed on that day.
  850. clock Show entries that have received clocked time on that day.
  851. state Show all logged state changes.
  852. Note that instead of changing this variable, you can also press `C-u l' in
  853. the agenda to display all available LOG items temporarily."
  854. :group 'org-agenda-daily/weekly
  855. :type '(set :greedy t (const closed) (const clock) (const state)))
  856. (defcustom org-agenda-log-mode-add-notes t
  857. "Non-nil means add first line of notes to log entries in agenda views.
  858. If a log item like a state change or a clock entry is associated with
  859. notes, the first line of these notes will be added to the entry in the
  860. agenda display."
  861. :group 'org-agenda-daily/weekly
  862. :type 'boolean)
  863. (defcustom org-agenda-start-with-log-mode nil
  864. "The initial value of log-mode in a newly created agenda window."
  865. :group 'org-agenda-startup
  866. :group 'org-agenda-daily/weekly
  867. :type 'boolean)
  868. (defcustom org-agenda-start-with-clockreport-mode nil
  869. "The initial value of clockreport-mode in a newly created agenda window."
  870. :group 'org-agenda-startup
  871. :group 'org-agenda-daily/weekly
  872. :type 'boolean)
  873. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  874. "Property list with parameters for the clocktable in clockreport mode.
  875. This is the display mode that shows a clock table in the daily/weekly
  876. agenda, the properties for this dynamic block can be set here.
  877. The usual clocktable parameters are allowed here, but you cannot set
  878. the properties :name, :tstart, :tend, :block, and :scope - these will
  879. be overwritten to make sure the content accurately reflects the
  880. current display in the agenda."
  881. :group 'org-agenda-daily/weekly
  882. :type 'plist)
  883. (defcustom org-agenda-search-view-always-boolean nil
  884. "Non-nil means the search string is interpreted as individual parts.
  885. The search string for search view can either be interpreted as a phrase,
  886. or as a list of snippets that define a boolean search for a number of
  887. strings.
  888. When this is non-nil, the string will be split on whitespace, and each
  889. snippet will be searched individually, and all must match in order to
  890. select an entry. A snippet is then a single string of non-white
  891. characters, or a string in double quotes, or a regexp in {} braces.
  892. If a snippet is preceeded by \"-\", the snippet must *not* match.
  893. \"+\" is syntactic sugar for positive selection. Each snippet may
  894. be found as a full word or a partial word, but see the variable
  895. `org-agenda-search-view-force-full-words'.
  896. When this is nil, search will look for the entire search phrase as one,
  897. with each space character matching any amount of whitespace, including
  898. line breaks.
  899. Even when this is nil, you can still switch to Boolean search dynamically
  900. by preceeding the first snippet with \"+\" or \"-\". If the first snippet
  901. is a regexp marked with braces like \"{abc}\", this will also switch to
  902. boolean search."
  903. :group 'org-agenda-search-view
  904. :type 'boolean)
  905. (if (fboundp 'defvaralias)
  906. (defvaralias 'org-agenda-search-view-search-words-only
  907. 'org-agenda-search-view-always-boolean))
  908. (defcustom org-agenda-search-view-force-full-words nil
  909. "Non-nil me
  910. ans, search words must be matches as complete words.
  911. When nil, they may also match part of a word."
  912. :group 'org-agenda-search-view
  913. :type 'boolean)
  914. (defgroup org-agenda-time-grid nil
  915. "Options concerning the time grid in the Org-mode Agenda."
  916. :tag "Org Agenda Time Grid"
  917. :group 'org-agenda)
  918. (defcustom org-agenda-search-headline-for-time t
  919. "Non-nil means search headline for a time-of-day.
  920. If the headline contains a time-of-day in one format or another, it will
  921. be used to sort the entry into the time sequence of items for a day.
  922. Some people have time stamps in the headline that refer to the creation
  923. time or so, and then this produces an unwanted side effect. If this is
  924. the case for your, use this variable to turn off searching the headline
  925. for a time."
  926. :group 'org-agenda-time-grid
  927. :type 'boolean)
  928. (defcustom org-agenda-use-time-grid t
  929. "Non-nil means show a time grid in the agenda schedule.
  930. A time grid is a set of lines for specific times (like every two hours between
  931. 8:00 and 20:00). The items scheduled for a day at specific times are
  932. sorted in between these lines.
  933. For details about when the grid will be shown, and what it will look like, see
  934. the variable `org-agenda-time-grid'."
  935. :group 'org-agenda-time-grid
  936. :type 'boolean)
  937. (defcustom org-agenda-time-grid
  938. '((daily today require-timed)
  939. "----------------"
  940. (800 1000 1200 1400 1600 1800 2000))
  941. "The settings for time grid for agenda display.
  942. This is a list of three items. The first item is again a list. It contains
  943. symbols specifying conditions when the grid should be displayed:
  944. daily if the agenda shows a single day
  945. weekly if the agenda shows an entire week
  946. today show grid on current date, independent of daily/weekly display
  947. require-timed show grid only if at least one item has a time specification
  948. The second item is a string which will be placed behind the grid time.
  949. The third item is a list of integers, indicating the times that should have
  950. a grid line."
  951. :group 'org-agenda-time-grid
  952. :type
  953. '(list
  954. (set :greedy t :tag "Grid Display Options"
  955. (const :tag "Show grid in single day agenda display" daily)
  956. (const :tag "Show grid in weekly agenda display" weekly)
  957. (const :tag "Always show grid for today" today)
  958. (const :tag "Show grid only if any timed entries are present"
  959. require-timed)
  960. (const :tag "Skip grid times already present in an entry"
  961. remove-match))
  962. (string :tag "Grid String")
  963. (repeat :tag "Grid Times" (integer :tag "Time"))))
  964. (defgroup org-agenda-sorting nil
  965. "Options concerning sorting in the Org-mode Agenda."
  966. :tag "Org Agenda Sorting"
  967. :group 'org-agenda)
  968. (defcustom org-agenda-sorting-strategy
  969. '((agenda habit-down time-up priority-down category-keep)
  970. (todo priority-down category-keep)
  971. (tags priority-down category-keep)
  972. (search category-keep))
  973. "Sorting structure for the agenda items of a single day.
  974. This is a list of symbols which will be used in sequence to determine
  975. if an entry should be listed before another entry. The following
  976. symbols are recognized:
  977. time-up Put entries with time-of-day indications first, early first
  978. time-down Put entries with time-of-day indications first, late first
  979. category-keep Keep the default order of categories, corresponding to the
  980. sequence in `org-agenda-files'.
  981. category-up Sort alphabetically by category, A-Z.
  982. category-down Sort alphabetically by category, Z-A.
  983. tag-up Sort alphabetically by last tag, A-Z.
  984. tag-down Sort alphabetically by last tag, Z-A.
  985. priority-up Sort numerically by priority, high priority last.
  986. priority-down Sort numerically by priority, high priority first.
  987. todo-state-up Sort by todo state, tasks that are done last.
  988. todo-state-down Sort by todo state, tasks that are done first.
  989. effort-up Sort numerically by estimated effort, high effort last.
  990. effort-down Sort numerically by estimated effort, high effort first.
  991. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  992. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  993. habit-up Put entries that are habits first
  994. habit-down Put entries that are habits last
  995. The different possibilities will be tried in sequence, and testing stops
  996. if one comparison returns a \"not-equal\". For example, the default
  997. '(time-up category-keep priority-down)
  998. means: Pull out all entries having a specified time of day and sort them,
  999. in order to make a time schedule for the current day the first thing in the
  1000. agenda listing for the day. Of the entries without a time indication, keep
  1001. the grouped in categories, don't sort the categories, but keep them in
  1002. the sequence given in `org-agenda-files'. Within each category sort by
  1003. priority.
  1004. Leaving out `category-keep' would mean that items will be sorted across
  1005. categories by priority.
  1006. Instead of a single list, this can also be a set of list for specific
  1007. contents, with a context symbol in the car of the list, any of
  1008. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1009. Custom commands can bind this variable in the options section."
  1010. :group 'org-agenda-sorting
  1011. :type `(choice
  1012. (repeat :tag "General" ,org-sorting-choice)
  1013. (list :tag "Individually"
  1014. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1015. (repeat ,org-sorting-choice))
  1016. (cons (const :tag "Strategy for TODO lists" todo)
  1017. (repeat ,org-sorting-choice))
  1018. (cons (const :tag "Strategy for Tags matches" tags)
  1019. (repeat ,org-sorting-choice))
  1020. (cons (const :tag "Strategy for search matches" search)
  1021. (repeat ,org-sorting-choice)))))
  1022. (defcustom org-agenda-cmp-user-defined nil
  1023. "A function to define the comparison `user-defined'.
  1024. This function must receive two arguments, agenda entry a and b.
  1025. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1026. the user comparison, return nil.
  1027. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1028. part of an agenda sorting strategy."
  1029. :group 'org-agenda-sorting
  1030. :type 'symbol)
  1031. (defcustom org-sort-agenda-notime-is-late t
  1032. "Non-nil means items without time are considered late.
  1033. This is only relevant for sorting. When t, items which have no explicit
  1034. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1035. do have a time. When nil, the default time is before 0:00. You can use this
  1036. option to decide if the schedule for today should come before or after timeless
  1037. agenda entries."
  1038. :group 'org-agenda-sorting
  1039. :type 'boolean)
  1040. (defcustom org-sort-agenda-noeffort-is-high t
  1041. "Non-nil means items without effort estimate are sorted as high effort.
  1042. This also applies when filtering an agenda view with respect to the
  1043. < or > effort operator. Then, tasks with no effort defined will be treated
  1044. as tasks with high effort.
  1045. When nil, such items are sorted as 0 minutes effort."
  1046. :group 'org-agenda-sorting
  1047. :type 'boolean)
  1048. (defgroup org-agenda-line-format nil
  1049. "Options concerning the entry prefix in the Org-mode agenda display."
  1050. :tag "Org Agenda Line Format"
  1051. :group 'org-agenda)
  1052. (defcustom org-agenda-prefix-format
  1053. '((agenda . " %-12:c%?-12t% s")
  1054. (timeline . " % s")
  1055. (todo . " %-12:c")
  1056. (tags . " %-12:c")
  1057. (search . " %-12:c"))
  1058. "Format specifications for the prefix of items in the agenda views.
  1059. An alist with four entries, for the different agenda types. The keys to the
  1060. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1061. are format strings.
  1062. This format works similar to a printf format, with the following meaning:
  1063. %c the category of the item, \"Diary\" for entries from the diary, or
  1064. as given by the CATEGORY keyword or derived from the file name.
  1065. %T the *last* tag of the item. Last because inherited tags come
  1066. first in the list.
  1067. %t the time-of-day specification if one applies to the entry, in the
  1068. format HH:MM
  1069. %s Scheduling/Deadline information, a short string
  1070. All specifiers work basically like the standard `%s' of printf, but may
  1071. contain two additional characters: A question mark just after the `%' and
  1072. a whitespace/punctuation character just before the final letter.
  1073. If the first character after `%' is a question mark, the entire field
  1074. will only be included if the corresponding value applies to the
  1075. current entry. This is useful for fields which should have fixed
  1076. width when present, but zero width when absent. For example,
  1077. \"%?-12t\" will result in a 12 character time field if a time of the
  1078. day is specified, but will completely disappear in entries which do
  1079. not contain a time.
  1080. If there is punctuation or whitespace character just before the final
  1081. format letter, this character will be appended to the field value if
  1082. the value is not empty. For example, the format \"%-12:c\" leads to
  1083. \"Diary: \" if the category is \"Diary\". If the category were be
  1084. empty, no additional colon would be inserted.
  1085. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1086. - Indent the line with two space characters
  1087. - Give the category in a 12 chars wide field, padded with whitespace on
  1088. the right (because of `-'). Append a colon if there is a category
  1089. (because of `:').
  1090. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1091. time, don't put in an empty field, just skip it (because of '?').
  1092. - Finally, put the scheduling information and append a whitespace.
  1093. As another example, if you don't want the time-of-day of entries in
  1094. the prefix, you could use:
  1095. (setq org-agenda-prefix-format \" %-11:c% s\")
  1096. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1097. `org-agenda-remove-tags'.
  1098. Custom commands can set this variable in the options section."
  1099. :type '(choice
  1100. (string :tag "General format")
  1101. (list :greedy t :tag "View dependent"
  1102. (cons (const agenda) (string :tag "Format"))
  1103. (cons (const timeline) (string :tag "Format"))
  1104. (cons (const todo) (string :tag "Format"))
  1105. (cons (const tags) (string :tag "Format"))
  1106. (cons (const search) (string :tag "Format"))))
  1107. :group 'org-agenda-line-format)
  1108. (defvar org-prefix-format-compiled nil
  1109. "The compiled version of the most recently used prefix format.
  1110. See the variable `org-agenda-prefix-format'.")
  1111. (defcustom org-agenda-todo-keyword-format "%-1s"
  1112. "Format for the TODO keyword in agenda lines.
  1113. Set this to something like \"%-12s\" if you want all TODO keywords
  1114. to occupy a fixed space in the agenda display."
  1115. :group 'org-agenda-line-format
  1116. :type 'string)
  1117. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1118. "Text preceding timerange entries in the agenda view.
  1119. This is a list with two strings. The first applies when the range
  1120. is entirely on one day. The second applies if the range spans several days.
  1121. The strings may have two \"%d\" format specifiers which will be filled
  1122. with the sequence number of the days, and the total number of days in the
  1123. range, respectively."
  1124. :group 'org-agenda-line-format
  1125. :type '(list
  1126. (string :tag "Deadline today ")
  1127. (choice :tag "Deadline relative"
  1128. (string :tag "Format string")
  1129. (function))))
  1130. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1131. "Text preceeding scheduled items in the agenda view.
  1132. This is a list with two strings. The first applies when the item is
  1133. scheduled on the current day. The second applies when it has been scheduled
  1134. previously, it may contain a %d indicating that this is the nth time that
  1135. this item is scheduled, due to automatic rescheduling of unfinished items
  1136. for the following day. So this number is one larger than the number of days
  1137. that passed since this item was scheduled first."
  1138. :group 'org-agenda-line-format
  1139. :type '(list
  1140. (string :tag "Scheduled today ")
  1141. (string :tag "Scheduled previously")))
  1142. (defcustom org-agenda-inactive-leader "["
  1143. "Text preceeding item pulled into the agenda by inactive time stamps.
  1144. These entries are added to the agenda when pressing \"[\"."
  1145. :group 'org-agenda-line-format
  1146. :type '(list
  1147. (string :tag "Scheduled today ")
  1148. (string :tag "Scheduled previously")))
  1149. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1150. "Text preceeding deadline items in the agenda view.
  1151. This is a list with two strings. The first applies when the item has its
  1152. deadline on the current day. The second applies when it is in the past or
  1153. in the future, it may contain %d to capture how many days away the deadline
  1154. is (was)."
  1155. :group 'org-agenda-line-format
  1156. :type '(list
  1157. (string :tag "Deadline today ")
  1158. (choice :tag "Deadline relative"
  1159. (string :tag "Format string")
  1160. (function))))
  1161. (defcustom org-agenda-remove-times-when-in-prefix t
  1162. "Non-nil means remove duplicate time specifications in agenda items.
  1163. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1164. time-of-day specification in a headline or diary entry is extracted and
  1165. placed into the prefix. If this option is non-nil, the original specification
  1166. \(a timestamp or -range, or just a plain time(range) specification like
  1167. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1168. cluttered.
  1169. The option can be t or nil. It may also be the symbol `beg', indicating
  1170. that the time should only be removed when it is located at the beginning of
  1171. the headline/diary entry."
  1172. :group 'org-agenda-line-format
  1173. :type '(choice
  1174. (const :tag "Always" t)
  1175. (const :tag "Never" nil)
  1176. (const :tag "When at beginning of entry" beg)))
  1177. (defcustom org-agenda-default-appointment-duration nil
  1178. "Default duration for appointments that only have a starting time.
  1179. When nil, no duration is specified in such cases.
  1180. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1181. :group 'org-agenda-line-format
  1182. :type '(choice
  1183. (integer :tag "Minutes")
  1184. (const :tag "No default duration")))
  1185. (defcustom org-agenda-show-inherited-tags t
  1186. "Non-nil means show inherited tags in each agenda line."
  1187. :group 'org-agenda-line-format
  1188. :type 'boolean)
  1189. (defcustom org-agenda-hide-tags-regexp nil
  1190. "Regular expression used to filter away specific tags in agenda views.
  1191. This means that these tags will be present, but not be shown in the agenda
  1192. line. Secondayt filltering will still work on the hidden tags.
  1193. Nil means don't hide any tags."
  1194. :group 'org-agenda-line-format
  1195. :type '(choice
  1196. (const :tag "Hide none" nil)
  1197. (string :tag "Regexp ")))
  1198. (defcustom org-agenda-remove-tags nil
  1199. "Non-nil means remove the tags from the headline copy in the agenda.
  1200. When this is the symbol `prefix', only remove tags when
  1201. `org-agenda-prefix-format' contains a `%T' specifier."
  1202. :group 'org-agenda-line-format
  1203. :type '(choice
  1204. (const :tag "Always" t)
  1205. (const :tag "Never" nil)
  1206. (const :tag "When prefix format contains %T" prefix)))
  1207. (if (fboundp 'defvaralias)
  1208. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1209. 'org-agenda-remove-tags))
  1210. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1211. "Shift tags in agenda items to this column.
  1212. If this number is positive, it specifies the column. If it is negative,
  1213. it means that the tags should be flushright to that column. For example,
  1214. -80 works well for a normal 80 character screen."
  1215. :group 'org-agenda-line-format
  1216. :type 'integer)
  1217. (if (fboundp 'defvaralias)
  1218. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1219. (defcustom org-agenda-fontify-priorities 'cookies
  1220. "Non-nil means highlight low and high priorities in agenda.
  1221. When t, the highest priority entries are bold, lowest priority italic.
  1222. However, settings in org-priority-faces will overrule these faces.
  1223. When this variable is the symbol `cookies', only fontify the
  1224. cookies, not the entire task.
  1225. This may also be an association list of priority faces, whose
  1226. keys are the character values of `org-highest-priority',
  1227. `org-default-priority', and `org-lowest-priority' (the default values
  1228. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1229. color as a string, or a list like `(:background \"Red\")'.
  1230. If it is a color, the variable `org-faces-easy-properties'
  1231. determines if it is a foreground or a background color."
  1232. :group 'org-agenda-line-format
  1233. :type '(choice
  1234. (const :tag "Never" nil)
  1235. (const :tag "Defaults" t)
  1236. (const :tag "Cookies only" cookies)
  1237. (repeat :tag "Specify"
  1238. (list (character :tag "Priority" :value ?A)
  1239. (choice :tag "Face "
  1240. (string :tag "Color")
  1241. (sexp :tag "Face"))))))
  1242. (defgroup org-agenda-column-view nil
  1243. "Options concerning column view in the agenda."
  1244. :tag "Org Agenda Column View"
  1245. :group 'org-agenda)
  1246. (defcustom org-agenda-columns-show-summaries t
  1247. "Non-nil means show summaries for columns displayed in the agenda view."
  1248. :group 'org-agenda-column-view
  1249. :type 'boolean)
  1250. (defcustom org-agenda-columns-remove-prefix-from-item t
  1251. "Non-nil means remove the prefix from a headline for agenda column view.
  1252. The special ITEM field in the columns format contains the current line, with
  1253. all information shown in other columns (like the TODO state or a tag).
  1254. When this variable is non-nil, also the agenda prefix will be removed from
  1255. the content of the ITEM field, to make sure as much as possible of the
  1256. headline can be shown in the limited width of the field."
  1257. :group 'org-agenda
  1258. :type 'boolean)
  1259. (defcustom org-agenda-columns-compute-summary-properties t
  1260. "Non-nil means recompute all summary properties before column view.
  1261. When column view in the agenda is listing properties that have a summary
  1262. operator, it can go to all relevant buffers and recompute the summaries
  1263. there. This can mean overhead for the agenda column view, but is necessary
  1264. to have thing up to date.
  1265. As a special case, a CLOCKSUM property also makes sure that the clock
  1266. computations are current."
  1267. :group 'org-agenda-column-view
  1268. :type 'boolean)
  1269. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1270. "Non-nil means the duration of an appointment will add to day effort.
  1271. The property to which appointment durations will be added is the one given
  1272. in the option `org-effort-property'. If an appointment does not have
  1273. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1274. is not set, an appointment without end time will not contribute to the time
  1275. estimate."
  1276. :group 'org-agenda-column-view
  1277. :type 'boolean)
  1278. (defcustom org-agenda-auto-exclude-function nil
  1279. "A function called with a tag to decide if it is filtered on '/ RET'.
  1280. The sole argument to the function, which is called once for each
  1281. possible tag, is a string giving the name of the tag. The
  1282. function should return either nil if the tag should be included
  1283. as normal, or \"-<TAG>\" to exclude the tag.
  1284. Note that for the purpose of tag filtering, only the lower-case version of
  1285. all tags will be considered, so that this function will only ever see
  1286. the lower-case version of all tags."
  1287. :group 'org-agenda
  1288. :type 'function)
  1289. (eval-when-compile
  1290. (require 'cl))
  1291. (require 'org)
  1292. (defun org-add-agenda-custom-command (entry)
  1293. "Replace or add a command in `org-agenda-custom-commands'.
  1294. This is mostly for hacking and trying a new command - once the command
  1295. works you probably want to add it to `org-agenda-custom-commands' for good."
  1296. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1297. (if ass
  1298. (setcdr ass (cdr entry))
  1299. (push entry org-agenda-custom-commands))))
  1300. ;;; Define the Org-agenda-mode
  1301. (defvar org-agenda-mode-map (make-sparse-keymap)
  1302. "Keymap for `org-agenda-mode'.")
  1303. (if (fboundp 'defvaralias)
  1304. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1305. (defvar org-agenda-menu) ; defined later in this file.
  1306. (defvar org-agenda-restrict) ; defined later in this file.
  1307. (defvar org-agenda-follow-mode nil)
  1308. (defvar org-agenda-entry-text-mode nil)
  1309. (defvar org-agenda-clockreport-mode nil)
  1310. (defvar org-agenda-show-log nil)
  1311. (defvar org-agenda-redo-command nil)
  1312. (defvar org-agenda-query-string nil)
  1313. (defvar org-agenda-mode-hook nil
  1314. "Hook for org-agenda-mode, run after the mode is turned on.")
  1315. (defvar org-agenda-type nil)
  1316. (defvar org-agenda-force-single-file nil)
  1317. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1318. (defun org-agenda-mode ()
  1319. "Mode for time-sorted view on action items in Org-mode files.
  1320. The following commands are available:
  1321. \\{org-agenda-mode-map}"
  1322. (interactive)
  1323. (kill-all-local-variables)
  1324. (setq org-agenda-undo-list nil
  1325. org-agenda-pending-undo-list nil
  1326. org-agenda-bulk-marked-entries nil)
  1327. (setq major-mode 'org-agenda-mode)
  1328. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1329. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1330. (setq mode-name "Org-Agenda")
  1331. (use-local-map org-agenda-mode-map)
  1332. (easy-menu-add org-agenda-menu)
  1333. (if org-startup-truncated (setq truncate-lines t))
  1334. (org-set-local 'line-move-visual nil)
  1335. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1336. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1337. ;; Make sure properties are removed when copying text
  1338. (when (boundp 'buffer-substring-filters)
  1339. (org-set-local 'buffer-substring-filters
  1340. (cons (lambda (x)
  1341. (set-text-properties 0 (length x) nil x) x)
  1342. buffer-substring-filters)))
  1343. (unless org-agenda-keep-modes
  1344. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1345. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1346. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1347. org-agenda-show-log org-agenda-start-with-log-mode))
  1348. (easy-menu-change
  1349. '("Agenda") "Agenda Files"
  1350. (append
  1351. (list
  1352. (vector
  1353. (if (get 'org-agenda-files 'org-restrict)
  1354. "Restricted to single file"
  1355. "Edit File List")
  1356. '(org-edit-agenda-file-list)
  1357. (not (get 'org-agenda-files 'org-restrict)))
  1358. "--")
  1359. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1360. (org-agenda-set-mode-name)
  1361. (apply
  1362. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1363. (list 'org-agenda-mode-hook)))
  1364. (substitute-key-definition 'undo 'org-agenda-undo
  1365. org-agenda-mode-map global-map)
  1366. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1367. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1368. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1369. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1370. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1371. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1372. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1373. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1374. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1375. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1376. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1377. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1378. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1379. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1380. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1381. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1382. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1383. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1384. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1385. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1386. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1387. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1388. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1389. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1390. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1391. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1392. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1393. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1394. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1395. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1396. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1397. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1398. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1399. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1400. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1401. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1402. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1403. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1404. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1405. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1406. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1407. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1408. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1409. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1410. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1411. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1412. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1413. (while l (org-defkey org-agenda-mode-map
  1414. (int-to-string (pop l)) 'digit-argument)))
  1415. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1416. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1417. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1418. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1419. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1420. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1421. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1422. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1423. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1424. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1425. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1426. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1427. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1428. 'org-clock-modify-effort-estimate)
  1429. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1430. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1431. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1432. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1433. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1434. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1435. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1436. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1437. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1438. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1439. (substitute-key-definition 'next-line 'org-agenda-next-line
  1440. org-agenda-mode-map global-map)
  1441. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1442. org-agenda-mode-map global-map)
  1443. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1444. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1445. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1446. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1447. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1448. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1449. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1450. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1451. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1452. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1453. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1454. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1455. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1456. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1457. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1458. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1459. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1460. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1461. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1462. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1463. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1464. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1465. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1466. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1467. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1468. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1469. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1470. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1471. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1472. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1473. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1474. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1475. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1476. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1477. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1478. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1479. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1480. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1481. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1483. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1484. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1485. (when org-agenda-mouse-1-follows-link
  1486. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1487. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1488. '("Agenda"
  1489. ("Agenda Files")
  1490. "--"
  1491. ("Agenda Dates"
  1492. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1493. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1494. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1495. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1496. "--"
  1497. ("View"
  1498. ["Day View" org-agenda-day-view
  1499. :active (org-agenda-check-type nil 'agenda)
  1500. :style radio :selected (equal org-agenda-ndays 1)
  1501. :keys "v d (or just d)"]
  1502. ["Week View" org-agenda-week-view
  1503. :active (org-agenda-check-type nil 'agenda)
  1504. :style radio :selected (equal org-agenda-ndays 7)
  1505. :keys "v w (or just w)"]
  1506. ["Month View" org-agenda-month-view
  1507. :active (org-agenda-check-type nil 'agenda)
  1508. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1509. :keys "v m"]
  1510. ["Year View" org-agenda-year-view
  1511. :active (org-agenda-check-type nil 'agenda)
  1512. :style radio :selected (member org-agenda-ndays '(365 366))
  1513. :keys "v y"]
  1514. "--"
  1515. ["Include Diary" org-agenda-toggle-diary
  1516. :style toggle :selected org-agenda-include-diary
  1517. :active (org-agenda-check-type nil 'agenda)]
  1518. ["Include Deadlines" org-agenda-toggle-deadlines
  1519. :style toggle :selected org-agenda-include-deadlines
  1520. :active (org-agenda-check-type nil 'agenda)]
  1521. ["Use Time Grid" org-agenda-toggle-time-grid
  1522. :style toggle :selected org-agenda-use-time-grid
  1523. :active (org-agenda-check-type nil 'agenda)]
  1524. "--"
  1525. ["Show clock report" org-agenda-clockreport-mode
  1526. :style toggle :selected org-agenda-clockreport-mode
  1527. :active (org-agenda-check-type nil 'agenda)]
  1528. ["Show some entry text" org-agenda-entry-text-mode
  1529. :style toggle :selected org-agenda-entry-text-mode
  1530. :active t]
  1531. "--"
  1532. ["Show Logbook entries" org-agenda-log-mode
  1533. :style toggle :selected org-agenda-show-log
  1534. :active (org-agenda-check-type nil 'agenda 'timeline)
  1535. :keys "v l (or just l)"]
  1536. ["Include archived trees" org-agenda-archives-mode
  1537. :style toggle :selected org-agenda-archives-mode :active t
  1538. :keys "v a"]
  1539. ["Include archive files" (org-agenda-archives-mode t)
  1540. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1541. :keys "v A"]
  1542. "--"
  1543. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1544. ["Write view to file" org-write-agenda t]
  1545. ["Rebuild buffer" org-agenda-redo t]
  1546. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1547. "--"
  1548. ["Show original entry" org-agenda-show t]
  1549. ["Go To (other window)" org-agenda-goto t]
  1550. ["Go To (this window)" org-agenda-switch-to t]
  1551. ["Follow Mode" org-agenda-follow-mode
  1552. :style toggle :selected org-agenda-follow-mode :active t]
  1553. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1554. "--"
  1555. ("TODO"
  1556. ["Cycle TODO" org-agenda-todo t]
  1557. ["Next TODO set" org-agenda-todo-nextset t]
  1558. ["Previous TODO set" org-agenda-todo-previousset t]
  1559. ["Add note" org-agenda-add-note t])
  1560. ("Archive/Refile/Delete"
  1561. ["Archive default" org-agenda-archive-default t]
  1562. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1563. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1564. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1565. ["Archive subtree" org-agenda-archive t]
  1566. "--"
  1567. ["Refile" org-agenda-refile t]
  1568. "--"
  1569. ["Delete subtree" org-agenda-kill t])
  1570. ("Bulk action"
  1571. ["Mark entry" org-agenda-bulk-mark t]
  1572. ["Unmark entry" org-agenda-bulk-unmark t]
  1573. ["Act on all marked" org-agenda-bulk-action t]
  1574. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1575. "--"
  1576. ("Tags and Properties"
  1577. ["Show all Tags" org-agenda-show-tags t]
  1578. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1579. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1580. "--"
  1581. ["Column View" org-columns t])
  1582. ("Deadline/Schedule"
  1583. ["Schedule" org-agenda-schedule t]
  1584. ["Set Deadline" org-agenda-deadline t]
  1585. "--"
  1586. ["Mark item" org-agenda-action :active t :keys "k m"]
  1587. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1588. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1589. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1590. "--"
  1591. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1592. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1593. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1594. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1595. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1596. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1597. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1598. ("Clock and Effort"
  1599. ["Clock in" org-agenda-clock-in t]
  1600. ["Clock out" org-agenda-clock-out t]
  1601. ["Clock cancel" org-agenda-clock-cancel t]
  1602. ["Goto running clock" org-clock-goto t]
  1603. "--"
  1604. ["Set Effort" org-agenda-set-effort t]
  1605. ["Change clocked effort" org-clock-modify-effort-estimate
  1606. (org-clock-is-active)])
  1607. ("Priority"
  1608. ["Set Priority" org-agenda-priority t]
  1609. ["Increase Priority" org-agenda-priority-up t]
  1610. ["Decrease Priority" org-agenda-priority-down t]
  1611. ["Show Priority" org-agenda-show-priority t])
  1612. ("Calendar/Diary"
  1613. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1614. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1615. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1616. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1617. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1618. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1619. "--"
  1620. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1621. "--"
  1622. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1623. "--"
  1624. ("MobileOrg"
  1625. ["Push Files and Views" org-mobile-push t]
  1626. ["Get Captured and Flagged" org-mobile-pull t]
  1627. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1628. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1629. "--"
  1630. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1631. "--"
  1632. ["Quit" org-agenda-quit t]
  1633. ["Exit and Release Buffers" org-agenda-exit t]
  1634. ))
  1635. ;;; Agenda undo
  1636. (defvar org-agenda-allow-remote-undo t
  1637. "Non-nil means allow remote undo from the agenda buffer.")
  1638. (defvar org-agenda-undo-list nil
  1639. "List of undoable operations in the agenda since last refresh.")
  1640. (defvar org-agenda-undo-has-started-in nil
  1641. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1642. (defvar org-agenda-pending-undo-list nil
  1643. "In a series of undo commands, this is the list of remaining undo items.")
  1644. (defun org-agenda-undo ()
  1645. "Undo a remote editing step in the agenda.
  1646. This undoes changes both in the agenda buffer and in the remote buffer
  1647. that have been changed along."
  1648. (interactive)
  1649. (or org-agenda-allow-remote-undo
  1650. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1651. (if (not (eq this-command last-command))
  1652. (setq org-agenda-undo-has-started-in nil
  1653. org-agenda-pending-undo-list org-agenda-undo-list))
  1654. (if (not org-agenda-pending-undo-list)
  1655. (error "No further undo information"))
  1656. (let* ((entry (pop org-agenda-pending-undo-list))
  1657. buf line cmd rembuf)
  1658. (setq cmd (pop entry) line (pop entry))
  1659. (setq rembuf (nth 2 entry))
  1660. (org-with-remote-undo rembuf
  1661. (while (bufferp (setq buf (pop entry)))
  1662. (if (pop entry)
  1663. (with-current-buffer buf
  1664. (let ((last-undo-buffer buf)
  1665. (inhibit-read-only t))
  1666. (unless (memq buf org-agenda-undo-has-started-in)
  1667. (push buf org-agenda-undo-has-started-in)
  1668. (make-local-variable 'pending-undo-list)
  1669. (undo-start))
  1670. (while (and pending-undo-list
  1671. (listp pending-undo-list)
  1672. (not (car pending-undo-list)))
  1673. (pop pending-undo-list))
  1674. (undo-more 1))))))
  1675. (org-goto-line line)
  1676. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1677. (defun org-verify-change-for-undo (l1 l2)
  1678. "Verify that a real change occurred between the undo lists L1 and L2."
  1679. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1680. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1681. (not (eq l1 l2)))
  1682. ;;; Agenda dispatch
  1683. (defvar org-agenda-restrict nil)
  1684. (defvar org-agenda-restrict-begin (make-marker))
  1685. (defvar org-agenda-restrict-end (make-marker))
  1686. (defvar org-agenda-last-dispatch-buffer nil)
  1687. (defvar org-agenda-overriding-restriction nil)
  1688. ;;;###autoload
  1689. (defun org-agenda (&optional arg keys restriction)
  1690. "Dispatch agenda commands to collect entries to the agenda buffer.
  1691. Prompts for a command to execute. Any prefix arg will be passed
  1692. on to the selected command. The default selections are:
  1693. a Call `org-agenda-list' to display the agenda for current day or week.
  1694. t Call `org-todo-list' to display the global todo list.
  1695. T Call `org-todo-list' to display the global todo list, select only
  1696. entries with a specific TODO keyword (the user gets a prompt).
  1697. m Call `org-tags-view' to display headlines with tags matching
  1698. a condition (the user is prompted for the condition).
  1699. M Like `m', but select only TODO entries, no ordinary headlines.
  1700. L Create a timeline for the current buffer.
  1701. e Export views to associated files.
  1702. s Search entries for keywords.
  1703. / Multi occur across all agenda files and also files listed
  1704. in `org-agenda-text-search-extra-files'.
  1705. < Restrict agenda commands to buffer, subtree, or region.
  1706. Press several times to get the desired effect.
  1707. > Remove a previous restriction.
  1708. # List \"stuck\" projects.
  1709. ! Configure what \"stuck\" means.
  1710. C Configure custom agenda commands.
  1711. More commands can be added by configuring the variable
  1712. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1713. searches can be pre-defined in this way.
  1714. If the current buffer is in Org-mode and visiting a file, you can also
  1715. first press `<' once to indicate that the agenda should be temporarily
  1716. \(until the next use of \\[org-agenda]) restricted to the current file.
  1717. Pressing `<' twice means to restrict to the current subtree or region
  1718. \(if active)."
  1719. (interactive "P")
  1720. (catch 'exit
  1721. (let* ((prefix-descriptions nil)
  1722. (org-agenda-window-setup (if (equal (buffer-name)
  1723. org-agenda-buffer-name)
  1724. 'current-window
  1725. org-agenda-window-setup))
  1726. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1727. (org-agenda-custom-commands
  1728. ;; normalize different versions
  1729. (delq nil
  1730. (mapcar
  1731. (lambda (x)
  1732. (cond ((stringp (cdr x))
  1733. (push x prefix-descriptions)
  1734. nil)
  1735. ((stringp (nth 1 x)) x)
  1736. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1737. (t (cons (car x) (cons "" (cdr x))))))
  1738. org-agenda-custom-commands)))
  1739. (buf (current-buffer))
  1740. (bfn (buffer-file-name (buffer-base-buffer)))
  1741. entry key type match lprops ans)
  1742. ;; Turn off restriction unless there is an overriding one,
  1743. (unless org-agenda-overriding-restriction
  1744. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1745. ;; There is a request to keep the file list in place
  1746. (put 'org-agenda-files 'org-restrict nil))
  1747. (setq org-agenda-restrict nil)
  1748. (move-marker org-agenda-restrict-begin nil)
  1749. (move-marker org-agenda-restrict-end nil))
  1750. ;; Delete old local properties
  1751. (put 'org-agenda-redo-command 'org-lprops nil)
  1752. ;; Remember where this call originated
  1753. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1754. (unless keys
  1755. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1756. keys (car ans)
  1757. restriction (cdr ans)))
  1758. ;; Establish the restriction, if any
  1759. (when (and (not org-agenda-overriding-restriction) restriction)
  1760. (put 'org-agenda-files 'org-restrict (list bfn))
  1761. (cond
  1762. ((eq restriction 'region)
  1763. (setq org-agenda-restrict t)
  1764. (move-marker org-agenda-restrict-begin (region-beginning))
  1765. (move-marker org-agenda-restrict-end (region-end)))
  1766. ((eq restriction 'subtree)
  1767. (save-excursion
  1768. (setq org-agenda-restrict t)
  1769. (org-back-to-heading t)
  1770. (move-marker org-agenda-restrict-begin (point))
  1771. (move-marker org-agenda-restrict-end
  1772. (progn (org-end-of-subtree t)))))))
  1773. ;; For example the todo list should not need it (but does...)
  1774. (cond
  1775. ((setq entry (assoc keys org-agenda-custom-commands))
  1776. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1777. (progn
  1778. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1779. lprops (nth 4 entry))
  1780. (put 'org-agenda-redo-command 'org-lprops lprops)
  1781. (cond
  1782. ((eq type 'agenda)
  1783. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1784. ((eq type 'alltodo)
  1785. (org-let lprops '(org-todo-list current-prefix-arg)))
  1786. ((eq type 'search)
  1787. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1788. ((eq type 'stuck)
  1789. (org-let lprops '(org-agenda-list-stuck-projects
  1790. current-prefix-arg)))
  1791. ((eq type 'tags)
  1792. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1793. ((eq type 'tags-todo)
  1794. (org-let lprops '(org-tags-view '(4) match)))
  1795. ((eq type 'todo)
  1796. (org-let lprops '(org-todo-list match)))
  1797. ((eq type 'tags-tree)
  1798. (org-check-for-org-mode)
  1799. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1800. ((eq type 'todo-tree)
  1801. (org-check-for-org-mode)
  1802. (org-let lprops
  1803. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1804. (regexp-quote match) "\\>"))))
  1805. ((eq type 'occur-tree)
  1806. (org-check-for-org-mode)
  1807. (org-let lprops '(org-occur match)))
  1808. ((functionp type)
  1809. (org-let lprops '(funcall type match)))
  1810. ((fboundp type)
  1811. (org-let lprops '(funcall type match)))
  1812. (t (error "Invalid custom agenda command type %s" type))))
  1813. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1814. ((equal keys "C")
  1815. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1816. (customize-variable 'org-agenda-custom-commands))
  1817. ((equal keys "a") (call-interactively 'org-agenda-list))
  1818. ((equal keys "s") (call-interactively 'org-search-view))
  1819. ((equal keys "t") (call-interactively 'org-todo-list))
  1820. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1821. ((equal keys "m") (call-interactively 'org-tags-view))
  1822. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1823. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1824. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1825. (org-add-hook
  1826. 'post-command-hook
  1827. (lambda ()
  1828. (unless (current-message)
  1829. (let* ((m (org-agenda-get-any-marker))
  1830. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1831. (when note
  1832. (message (concat
  1833. "FLAGGING-NOTE ([?] for more info): "
  1834. (org-add-props
  1835. (replace-regexp-in-string
  1836. "\\\\n" "//"
  1837. (copy-sequence note))
  1838. nil 'face 'org-warning)))))))
  1839. t t))
  1840. ((equal keys "L")
  1841. (unless (org-mode-p)
  1842. (error "This is not an Org-mode file"))
  1843. (unless restriction
  1844. (put 'org-agenda-files 'org-restrict (list bfn))
  1845. (org-call-with-arg 'org-timeline arg)))
  1846. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1847. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1848. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1849. (t (error "Invalid agenda key"))))))
  1850. (defun org-agenda-normalize-custom-commands (cmds)
  1851. (delq nil
  1852. (mapcar
  1853. (lambda (x)
  1854. (cond ((stringp (cdr x)) nil)
  1855. ((stringp (nth 1 x)) x)
  1856. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1857. (t (cons (car x) (cons "" (cdr x))))))
  1858. cmds)))
  1859. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1860. "The user interface for selecting an agenda command."
  1861. (catch 'exit
  1862. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1863. (restrict-ok (and bfn (org-mode-p)))
  1864. (region-p (org-region-active-p))
  1865. (custom org-agenda-custom-commands)
  1866. (selstring "")
  1867. restriction second-time
  1868. c entry key type match prefixes rmheader header-end custom1 desc)
  1869. (save-window-excursion
  1870. (delete-other-windows)
  1871. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1872. (erase-buffer)
  1873. (insert (eval-when-compile
  1874. (let ((header
  1875. "
  1876. Press key for an agenda command: < Buffer, subtree/region restriction
  1877. -------------------------------- > Remove restriction
  1878. a Agenda for current week or day e Export agenda views
  1879. t List of all TODO entries T Entries with special TODO kwd
  1880. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1881. L Timeline for current buffer # List stuck projects (!=configure)
  1882. s Search for keywords C Configure custom agenda commands
  1883. / Multi-occur ? Find :FLAGGED: entries
  1884. ")
  1885. (start 0))
  1886. (while (string-match
  1887. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1888. header start)
  1889. (setq start (match-end 0))
  1890. (add-text-properties (match-beginning 2) (match-end 2)
  1891. '(face bold) header))
  1892. header)))
  1893. (setq header-end (move-marker (make-marker) (point)))
  1894. (while t
  1895. (setq custom1 custom)
  1896. (when (eq rmheader t)
  1897. (org-goto-line 1)
  1898. (re-search-forward ":" nil t)
  1899. (delete-region (match-end 0) (point-at-eol))
  1900. (forward-char 1)
  1901. (looking-at "-+")
  1902. (delete-region (match-end 0) (point-at-eol))
  1903. (move-marker header-end (match-end 0)))
  1904. (goto-char header-end)
  1905. (delete-region (point) (point-max))
  1906. (while (setq entry (pop custom1))
  1907. (setq key (car entry) desc (nth 1 entry)
  1908. type (nth 2 entry)
  1909. match (nth 3 entry))
  1910. (if (> (length key) 1)
  1911. (add-to-list 'prefixes (string-to-char key))
  1912. (insert
  1913. (format
  1914. "\n%-4s%-14s: %s"
  1915. (org-add-props (copy-sequence key)
  1916. '(face bold))
  1917. (cond
  1918. ((string-match "\\S-" desc) desc)
  1919. ((eq type 'agenda) "Agenda for current week or day")
  1920. ((eq type 'alltodo) "List of all TODO entries")
  1921. ((eq type 'search) "Word search")
  1922. ((eq type 'stuck) "List of stuck projects")
  1923. ((eq type 'todo) "TODO keyword")
  1924. ((eq type 'tags) "Tags query")
  1925. ((eq type 'tags-todo) "Tags (TODO)")
  1926. ((eq type 'tags-tree) "Tags tree")
  1927. ((eq type 'todo-tree) "TODO kwd tree")
  1928. ((eq type 'occur-tree) "Occur tree")
  1929. ((functionp type) (if (symbolp type)
  1930. (symbol-name type)
  1931. "Lambda expression"))
  1932. (t "???"))
  1933. (cond
  1934. ((stringp match)
  1935. (setq match (copy-sequence match))
  1936. (org-add-props match nil 'face 'org-warning))
  1937. (match
  1938. (format "set of %d commands" (length match)))
  1939. (t ""))))))
  1940. (when prefixes
  1941. (mapc (lambda (x)
  1942. (insert
  1943. (format "\n%s %s"
  1944. (org-add-props (char-to-string x)
  1945. nil 'face 'bold)
  1946. (or (cdr (assoc (concat selstring (char-to-string x))
  1947. prefix-descriptions))
  1948. "Prefix key"))))
  1949. prefixes))
  1950. (goto-char (point-min))
  1951. (if second-time
  1952. (if (not (pos-visible-in-window-p (point-max)))
  1953. (org-fit-window-to-buffer))
  1954. (setq second-time t)
  1955. (org-fit-window-to-buffer))
  1956. (message "Press key for agenda command%s:"
  1957. (if (or restrict-ok org-agenda-overriding-restriction)
  1958. (if org-agenda-overriding-restriction
  1959. " (restriction lock active)"
  1960. (if restriction
  1961. (format " (restricted to %s)" restriction)
  1962. " (unrestricted)"))
  1963. ""))
  1964. (setq c (read-char-exclusive))
  1965. (message "")
  1966. (cond
  1967. ((assoc (char-to-string c) custom)
  1968. (setq selstring (concat selstring (char-to-string c)))
  1969. (throw 'exit (cons selstring restriction)))
  1970. ((memq c prefixes)
  1971. (setq selstring (concat selstring (char-to-string c))
  1972. prefixes nil
  1973. rmheader (or rmheader t)
  1974. custom (delq nil (mapcar
  1975. (lambda (x)
  1976. (if (or (= (length (car x)) 1)
  1977. (/= (string-to-char (car x)) c))
  1978. nil
  1979. (cons (substring (car x) 1) (cdr x))))
  1980. custom))))
  1981. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1982. (message "Restriction is only possible in Org-mode buffers")
  1983. (ding) (sit-for 1))
  1984. ((eq c ?1)
  1985. (org-agenda-remove-restriction-lock 'noupdate)
  1986. (setq restriction 'buffer))
  1987. ((eq c ?0)
  1988. (org-agenda-remove-restriction-lock 'noupdate)
  1989. (setq restriction (if region-p 'region 'subtree)))
  1990. ((eq c ?<)
  1991. (org-agenda-remove-restriction-lock 'noupdate)
  1992. (setq restriction
  1993. (cond
  1994. ((eq restriction 'buffer)
  1995. (if region-p 'region 'subtree))
  1996. ((memq restriction '(subtree region))
  1997. nil)
  1998. (t 'buffer))))
  1999. ((eq c ?>)
  2000. (org-agenda-remove-restriction-lock 'noupdate)
  2001. (setq restriction nil))
  2002. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2003. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2004. ((and (> (length selstring) 0) (eq c ?\d))
  2005. (delete-window)
  2006. (org-agenda-get-restriction-and-command prefix-descriptions))
  2007. ((equal c ?q) (error "Abort"))
  2008. (t (error "Invalid key %c" c))))))))
  2009. (defun org-run-agenda-series (name series)
  2010. (org-let (nth 1 series) '(org-prepare-agenda name))
  2011. (let* ((org-agenda-multi t)
  2012. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2013. (cmds (car series))
  2014. (gprops (nth 1 series))
  2015. match ;; The byte compiler incorrectly complains about this. Keep it!
  2016. cmd type lprops)
  2017. (while (setq cmd (pop cmds))
  2018. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2019. (cond
  2020. ((eq type 'agenda)
  2021. (org-let2 gprops lprops
  2022. '(call-interactively 'org-agenda-list)))
  2023. ((eq type 'alltodo)
  2024. (org-let2 gprops lprops
  2025. '(call-interactively 'org-todo-list)))
  2026. ((eq type 'search)
  2027. (org-let2 gprops lprops
  2028. '(org-search-view current-prefix-arg match nil)))
  2029. ((eq type 'stuck)
  2030. (org-let2 gprops lprops
  2031. '(call-interactively 'org-agenda-list-stuck-projects)))
  2032. ((eq type 'tags)
  2033. (org-let2 gprops lprops
  2034. '(org-tags-view current-prefix-arg match)))
  2035. ((eq type 'tags-todo)
  2036. (org-let2 gprops lprops
  2037. '(org-tags-view '(4) match)))
  2038. ((eq type 'todo)
  2039. (org-let2 gprops lprops
  2040. '(org-todo-list match)))
  2041. ((fboundp type)
  2042. (org-let2 gprops lprops
  2043. '(funcall type match)))
  2044. (t (error "Invalid type in command series"))))
  2045. (widen)
  2046. (setq org-agenda-redo-command redo)
  2047. (goto-char (point-min)))
  2048. (org-fit-agenda-window)
  2049. (org-let (nth 1 series) '(org-finalize-agenda)))
  2050. ;;;###autoload
  2051. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2052. "Run an agenda command in batch mode and send the result to STDOUT.
  2053. If CMD-KEY is a string of length 1, it is used as a key in
  2054. `org-agenda-custom-commands' and triggers this command. If it is a
  2055. longer string it is used as a tags/todo match string.
  2056. Paramters are alternating variable names and values that will be bound
  2057. before running the agenda command."
  2058. (let (pars)
  2059. (while parameters
  2060. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2061. (if (> (length cmd-key) 2)
  2062. (eval (list 'let (nreverse pars)
  2063. (list 'org-tags-view nil cmd-key)))
  2064. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2065. (set-buffer org-agenda-buffer-name)
  2066. (princ (org-encode-for-stdout (buffer-string)))))
  2067. ;(defun org-encode-for-stdout (string)
  2068. ; (if (fboundp 'encode-coding-string)
  2069. ; (encode-coding-string string buffer-file-coding-system)
  2070. ; string))
  2071. (defun org-encode-for-stdout (string)
  2072. string)
  2073. (defvar org-agenda-info nil)
  2074. ;;;###autoload
  2075. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2076. "Run an agenda command in batch mode and send the result to STDOUT.
  2077. If CMD-KEY is a string of length 1, it is used as a key in
  2078. `org-agenda-custom-commands' and triggers this command. If it is a
  2079. longer string it is used as a tags/todo match string.
  2080. Paramters are alternating variable names and values that will be bound
  2081. before running the agenda command.
  2082. The output gives a line for each selected agenda item. Each
  2083. item is a list of comma-separated values, like this:
  2084. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2085. category The category of the item
  2086. head The headline, without TODO kwd, TAGS and PRIORITY
  2087. type The type of the agenda entry, can be
  2088. todo selected in TODO match
  2089. tagsmatch selected in tags match
  2090. diary imported from diary
  2091. deadline a deadline on given date
  2092. scheduled scheduled on given date
  2093. timestamp entry has timestamp on given date
  2094. closed entry was closed on given date
  2095. upcoming-deadline warning about deadline
  2096. past-scheduled forwarded scheduled item
  2097. block entry has date block including g. date
  2098. todo The todo keyword, if any
  2099. tags All tags including inherited ones, separated by colons
  2100. date The relevant date, like 2007-2-14
  2101. time The time, like 15:00-16:50
  2102. extra Sting with extra planning info
  2103. priority-l The priority letter if any was given
  2104. priority-n The computed numerical priority
  2105. agenda-day The day in the agenda where this is listed"
  2106. (let (pars)
  2107. (while parameters
  2108. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2109. (push (list 'org-agenda-remove-tags t) pars)
  2110. (if (> (length cmd-key) 2)
  2111. (eval (list 'let (nreverse pars)
  2112. (list 'org-tags-view nil cmd-key)))
  2113. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2114. (set-buffer org-agenda-buffer-name)
  2115. (let* ((lines (org-split-string (buffer-string) "\n"))
  2116. line)
  2117. (while (setq line (pop lines))
  2118. (catch 'next
  2119. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2120. (setq org-agenda-info
  2121. (org-fix-agenda-info (text-properties-at 0 line)))
  2122. (princ
  2123. (org-encode-for-stdout
  2124. (mapconcat 'org-agenda-export-csv-mapper
  2125. '(org-category txt type todo tags date time extra
  2126. priority-letter priority agenda-day)
  2127. ",")))
  2128. (princ "\n"))))))
  2129. (defun org-fix-agenda-info (props)
  2130. "Make sure all properties on an agenda item have a canonical form,
  2131. so the export commands can easily use it."
  2132. (let (tmp re)
  2133. (when (setq tmp (plist-get props 'tags))
  2134. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2135. (when (setq tmp (plist-get props 'date))
  2136. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2137. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2138. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2139. (setq tmp (calendar-date-string tmp)))
  2140. (setq props (plist-put props 'date tmp)))
  2141. (when (setq tmp (plist-get props 'day))
  2142. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2143. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2144. (setq tmp (calendar-date-string tmp)))
  2145. (setq props (plist-put props 'day tmp))
  2146. (setq props (plist-put props 'agenda-day tmp)))
  2147. (when (setq tmp (plist-get props 'txt))
  2148. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2149. (plist-put props 'priority-letter (match-string 1 tmp))
  2150. (setq tmp (replace-match "" t t tmp)))
  2151. (when (and (setq re (plist-get props 'org-todo-regexp))
  2152. (setq re (concat "\\`\\.*" re " ?"))
  2153. (string-match re tmp))
  2154. (plist-put props 'todo (match-string 1 tmp))
  2155. (setq tmp (replace-match "" t t tmp)))
  2156. (plist-put props 'txt tmp)))
  2157. props)
  2158. (defun org-agenda-export-csv-mapper (prop)
  2159. (let ((res (plist-get org-agenda-info prop)))
  2160. (setq res
  2161. (cond
  2162. ((not res) "")
  2163. ((stringp res) res)
  2164. (t (prin1-to-string res))))
  2165. (while (string-match "," res)
  2166. (setq res (replace-match ";" t t res)))
  2167. (org-trim res)))
  2168. ;;;###autoload
  2169. (defun org-store-agenda-views (&rest parameters)
  2170. (interactive)
  2171. (eval (list 'org-batch-store-agenda-views)))
  2172. ;; FIXME, why is this a macro?????
  2173. ;;;###autoload
  2174. (defmacro org-batch-store-agenda-views (&rest parameters)
  2175. "Run all custom agenda commands that have a file argument."
  2176. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2177. (pop-up-frames nil)
  2178. (dir default-directory)
  2179. pars cmd thiscmdkey files opts cmd-or-set)
  2180. (while parameters
  2181. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2182. (setq pars (reverse pars))
  2183. (save-window-excursion
  2184. (while cmds
  2185. (setq cmd (pop cmds)
  2186. thiscmdkey (car cmd)
  2187. cmd-or-set (nth 2 cmd)
  2188. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2189. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2190. (if (stringp files) (setq files (list files)))
  2191. (when files
  2192. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2193. (list 'org-agenda nil thiscmdkey)))
  2194. (set-buffer org-agenda-buffer-name)
  2195. (while files
  2196. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2197. (list 'org-write-agenda
  2198. (expand-file-name (pop files) dir) nil t))))
  2199. (and (get-buffer org-agenda-buffer-name)
  2200. (kill-buffer org-agenda-buffer-name)))))))
  2201. (defun org-agenda-mark-header-line (pos)
  2202. "Mark the line at POS as an agenda structure header."
  2203. (save-excursion
  2204. (goto-char pos)
  2205. (put-text-property (point-at-bol) (point-at-eol)
  2206. 'org-agenda-structural-header t)
  2207. (when org-agenda-title-append
  2208. (put-text-property (point-at-bol) (point-at-eol)
  2209. 'org-agenda-title-append org-agenda-title-append))))
  2210. (defvar org-mobile-creating-agendas)
  2211. (defun org-write-agenda (file &optional open nosettings)
  2212. "Write the current buffer (an agenda view) as a file.
  2213. Depending on the extension of the file name, plain text (.txt),
  2214. HTML (.html or .htm) or Postscript (.ps) is produced.
  2215. If the extension is .ics, run icalendar export over all files used
  2216. to construct the agenda and limit the export to entries listed in the
  2217. agenda now.
  2218. With prefix argument OPEN, open the new file immediately.
  2219. If NOSETTINGS is given, do not scope the settings of
  2220. `org-agenda-exporter-settings' into the export commands. This is used when
  2221. the settings have already been scoped and we do not wish to overrule other,
  2222. higher priority settings."
  2223. (interactive "FWrite agenda to file: \nP")
  2224. (if (not (file-writable-p file))
  2225. (error "Cannot write agenda to file %s" file))
  2226. (cond
  2227. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2228. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2229. (org-let (if nosettings nil org-agenda-exporter-settings)
  2230. '(save-excursion
  2231. (save-window-excursion
  2232. (org-agenda-mark-filtered-text)
  2233. (let ((bs (copy-sequence (buffer-string))) beg)
  2234. (org-agenda-unmark-filtered-text)
  2235. (with-temp-buffer
  2236. (insert bs)
  2237. (org-agenda-remove-marked-text 'org-filtered)
  2238. (while (setq beg (text-property-any (point-min) (point-max)
  2239. 'org-filtered t))
  2240. (delete-region
  2241. beg (or (next-single-property-change beg 'org-filtered)
  2242. (point-max))))
  2243. (run-hooks 'org-agenda-before-write-hook)
  2244. (cond
  2245. ((org-bound-and-true-p org-mobile-creating-agendas)
  2246. (org-mobile-write-agenda-for-mobile file))
  2247. ((string-match "\\.html?\\'" file)
  2248. (set-buffer (htmlize-buffer (current-buffer)))
  2249. (when (and org-agenda-export-html-style
  2250. (string-match "<style>" org-agenda-export-html-style))
  2251. ;; replace <style> section with org-agenda-export-html-style
  2252. (goto-char (point-min))
  2253. (kill-region (- (search-forward "<style") 6)
  2254. (search-forward "</style>"))
  2255. (insert org-agenda-export-html-style))
  2256. (write-file file)
  2257. (kill-buffer (current-buffer))
  2258. (message "HTML written to %s" file))
  2259. ((string-match "\\.ps\\'" file)
  2260. (require 'ps-print)
  2261. (flet ((ps-get-buffer-name () "Agenda View"))
  2262. (ps-print-buffer-with-faces file))
  2263. (message "Postscript written to %s" file))
  2264. ((string-match "\\.pdf\\'" file)
  2265. (require 'ps-print)
  2266. (flet ((ps-get-buffer-name () "Agenda View"))
  2267. (ps-print-buffer-with-faces
  2268. (concat (file-name-sans-extension file) ".ps")))
  2269. (call-process "ps2pdf" nil nil nil
  2270. (expand-file-name
  2271. (concat (file-name-sans-extension file) ".ps"))
  2272. (expand-file-name file))
  2273. (message "PDF written to %s" file))
  2274. ((string-match "\\.ics\\'" file)
  2275. (require 'org-icalendar)
  2276. (let ((org-agenda-marker-table
  2277. (org-create-marker-find-array
  2278. (org-agenda-collect-markers)))
  2279. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2280. (org-combined-agenda-icalendar-file file))
  2281. (apply 'org-export-icalendar 'combine
  2282. (org-agenda-files nil 'ifmode))))
  2283. (t
  2284. (let ((bs (buffer-string)))
  2285. (find-file file)
  2286. (erase-buffer)
  2287. (insert bs)
  2288. (save-buffer 0)
  2289. (kill-buffer (current-buffer))
  2290. (message "Plain text written to %s" file))))))))
  2291. (set-buffer org-agenda-buffer-name))
  2292. (when open (org-open-file file)))
  2293. (defvar org-agenda-filter-overlays nil)
  2294. (defun org-agenda-mark-filtered-text ()
  2295. "Mark all text hidden by filtering with a text property."
  2296. (let ((inhibit-read-only t))
  2297. (mapc
  2298. (lambda (o)
  2299. (when (equal (overlay-buffer o) (current-buffer))
  2300. (put-text-property
  2301. (overlay-start o) (overlay-end o)
  2302. 'org-filtered t)))
  2303. org-agenda-filter-overlays)))
  2304. (defun org-agenda-unmark-filtered-text ()
  2305. "Remove the filtering text property."
  2306. (let ((inhibit-read-only t))
  2307. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2308. (defun org-agenda-remove-marked-text (property &optional value)
  2309. "Delete all text marked with VALUE of PROPERTY.
  2310. VALUE defaults to t."
  2311. (let (beg)
  2312. (setq value (or value t))
  2313. (while (setq beg (text-property-any (point-min) (point-max)
  2314. property value))
  2315. (delete-region
  2316. beg (or (next-single-property-change beg 'org-filtered)
  2317. (point-max))))))
  2318. (defun org-agenda-add-entry-text ()
  2319. "Add entry text to agenda lines.
  2320. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2321. entry text following headings shown in the agenda.
  2322. Drawers will be excluded, also the line with scheduling/deadline info."
  2323. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2324. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2325. (let (m txt)
  2326. (goto-char (point-min))
  2327. (while (not (eobp))
  2328. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2329. (beginning-of-line 2)
  2330. (setq txt (org-agenda-get-some-entry-text
  2331. m org-agenda-add-entry-text-maxlines " > "))
  2332. (end-of-line 1)
  2333. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2334. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2335. &rest keep)
  2336. "Extract entry text from MARKER, at most N-LINES lines.
  2337. This will ignore drawers etc, just get the text.
  2338. If INDENT is given, prefix every line with this string. If KEEP is
  2339. given, it is a list of symbols, defining stuff that should not be
  2340. removed from the entry content. Currently only `planning' is allowed here."
  2341. (let (txt drawer-re kwd-time-re ind)
  2342. (save-excursion
  2343. (with-current-buffer (marker-buffer marker)
  2344. (if (not (org-mode-p))
  2345. (setq txt "")
  2346. (save-excursion
  2347. (save-restriction
  2348. (widen)
  2349. (goto-char marker)
  2350. (end-of-line 1)
  2351. (setq txt (buffer-substring
  2352. (min (1+ (point)) (point-max))
  2353. (progn (outline-next-heading) (point)))
  2354. drawer-re org-drawer-regexp
  2355. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2356. ".*\n?"))
  2357. (with-temp-buffer
  2358. (insert txt)
  2359. (when org-agenda-add-entry-text-descriptive-links
  2360. (goto-char (point-min))
  2361. (while (org-activate-bracket-links (point-max))
  2362. (add-text-properties (match-beginning 0) (match-end 0)
  2363. '(face org-link))))
  2364. (goto-char (point-min))
  2365. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2366. (set-text-properties (match-beginning 0) (match-end 0)
  2367. nil))
  2368. (goto-char (point-min))
  2369. (while (re-search-forward drawer-re nil t)
  2370. (delete-region
  2371. (match-beginning 0)
  2372. (progn (re-search-forward
  2373. "^[ \t]*:END:.*\n?" nil 'move)
  2374. (point))))
  2375. (unless (member 'planning keep)
  2376. (goto-char (point-min))
  2377. (while (re-search-forward kwd-time-re nil t)
  2378. (replace-match "")))
  2379. (goto-char (point-min))
  2380. (when org-agenda-entry-text-exclude-regexps
  2381. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2382. (while (setq re (pop re-list))
  2383. (goto-char (point-min))
  2384. (while (re-search-forward re nil t)
  2385. (replace-match "")))))
  2386. (goto-char (point-max))
  2387. (skip-chars-backward " \t\n")
  2388. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2389. ;; find and remove min common indentation
  2390. (goto-char (point-min))
  2391. (untabify (point-min) (point-max))
  2392. (setq ind (org-get-indentation))
  2393. (while (not (eobp))
  2394. (unless (looking-at "[ \t]*$")
  2395. (setq ind (min ind (org-get-indentation))))
  2396. (beginning-of-line 2))
  2397. (goto-char (point-min))
  2398. (while (not (eobp))
  2399. (unless (looking-at "[ \t]*$")
  2400. (move-to-column ind)
  2401. (delete-region (point-at-bol) (point)))
  2402. (beginning-of-line 2))
  2403. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2404. (goto-char (point-min))
  2405. (when indent
  2406. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2407. (replace-match indent t t)))
  2408. (goto-char (point-min))
  2409. (while (looking-at "[ \t]*\n") (replace-match ""))
  2410. (goto-char (point-max))
  2411. (when (> (org-current-line)
  2412. n-lines)
  2413. (org-goto-line (1+ n-lines))
  2414. (backward-char 1))
  2415. (setq txt (buffer-substring (point-min) (point)))))))))
  2416. txt))
  2417. (defun org-agenda-collect-markers ()
  2418. "Collect the markers pointing to entries in the agenda buffer."
  2419. (let (m markers)
  2420. (save-excursion
  2421. (goto-char (point-min))
  2422. (while (not (eobp))
  2423. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2424. (org-get-at-bol 'org-marker)))
  2425. (push m markers))
  2426. (beginning-of-line 2)))
  2427. (nreverse markers)))
  2428. (defun org-create-marker-find-array (marker-list)
  2429. "Create a alist of files names with all marker positions in that file."
  2430. (let (f tbl m a p)
  2431. (while (setq m (pop marker-list))
  2432. (setq p (marker-position m)
  2433. f (buffer-file-name (or (buffer-base-buffer
  2434. (marker-buffer m))
  2435. (marker-buffer m))))
  2436. (if (setq a (assoc f tbl))
  2437. (push (marker-position m) (cdr a))
  2438. (push (list f p) tbl)))
  2439. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2440. tbl)))
  2441. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2442. (defun org-check-agenda-marker-table ()
  2443. "Check of the current entry is on the marker list."
  2444. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2445. a)
  2446. (and (setq a (assoc file org-agenda-marker-table))
  2447. (save-match-data
  2448. (save-excursion
  2449. (org-back-to-heading t)
  2450. (member (point) (cdr a)))))))
  2451. (defun org-check-for-org-mode ()
  2452. "Make sure current buffer is in org-mode. Error if not."
  2453. (or (org-mode-p)
  2454. (error "Cannot execute org-mode agenda command on buffer in %s"
  2455. major-mode)))
  2456. (defun org-fit-agenda-window ()
  2457. "Fit the window to the buffer size."
  2458. (and (memq org-agenda-window-setup '(reorganize-frame))
  2459. (fboundp 'fit-window-to-buffer)
  2460. (org-fit-window-to-buffer
  2461. nil
  2462. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2463. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2464. ;;; Agenda prepare and finalize
  2465. (defvar org-agenda-multi nil) ; dynamically scoped
  2466. (defvar org-agenda-buffer-name "*Org Agenda*")
  2467. (defvar org-pre-agenda-window-conf nil)
  2468. (defvar org-agenda-columns-active nil)
  2469. (defvar org-agenda-name nil)
  2470. (defvar org-agenda-filter nil)
  2471. (defvar org-agenda-filter-preset nil
  2472. "A preset of the tags filter used for secondary agenda filtering.
  2473. This must be a list of strings, each string must be a single tag preceeded
  2474. by \"+\" or \"-\".
  2475. This variable should not be set directly, but agenda custom commands can
  2476. bind it in the options section.")
  2477. (defun org-prepare-agenda (&optional name)
  2478. (setq org-todo-keywords-for-agenda nil)
  2479. (setq org-done-keywords-for-agenda nil)
  2480. (setq org-drawers-for-agenda nil)
  2481. (setq org-agenda-filter nil)
  2482. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2483. (if org-agenda-multi
  2484. (progn
  2485. (setq buffer-read-only nil)
  2486. (goto-char (point-max))
  2487. (unless (or (bobp) org-agenda-compact-blocks)
  2488. (insert "\n"
  2489. (if (stringp org-agenda-block-separator)
  2490. org-agenda-block-separator
  2491. (make-string (window-width) org-agenda-block-separator))
  2492. "\n"))
  2493. (narrow-to-region (point) (point-max)))
  2494. (org-agenda-reset-markers)
  2495. (setq org-agenda-contributing-files nil)
  2496. (setq org-agenda-columns-active nil)
  2497. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2498. (setq org-todo-keywords-for-agenda
  2499. (org-uniquify org-todo-keywords-for-agenda))
  2500. (setq org-done-keywords-for-agenda
  2501. (org-uniquify org-done-keywords-for-agenda))
  2502. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2503. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2504. (awin (get-buffer-window abuf)))
  2505. (cond
  2506. ((equal (current-buffer) abuf) nil)
  2507. (awin (select-window awin))
  2508. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2509. ((equal org-agenda-window-setup 'current-window)
  2510. (switch-to-buffer abuf))
  2511. ((equal org-agenda-window-setup 'other-window)
  2512. (org-switch-to-buffer-other-window abuf))
  2513. ((equal org-agenda-window-setup 'other-frame)
  2514. (switch-to-buffer-other-frame abuf))
  2515. ((equal org-agenda-window-setup 'reorganize-frame)
  2516. (delete-other-windows)
  2517. (org-switch-to-buffer-other-window abuf))))
  2518. (setq buffer-read-only nil)
  2519. (let ((inhibit-read-only t)) (erase-buffer))
  2520. (org-agenda-mode)
  2521. (and name (not org-agenda-name)
  2522. (org-set-local 'org-agenda-name name)))
  2523. (setq buffer-read-only nil))
  2524. (defun org-finalize-agenda ()
  2525. "Finishing touch for the agenda buffer, called just before displaying it."
  2526. (unless org-agenda-multi
  2527. (save-excursion
  2528. (let ((inhibit-read-only t))
  2529. (goto-char (point-min))
  2530. (while (org-activate-bracket-links (point-max))
  2531. (add-text-properties (match-beginning 0) (match-end 0)
  2532. '(face org-link)))
  2533. (org-agenda-align-tags)
  2534. (unless org-agenda-with-colors
  2535. (remove-text-properties (point-min) (point-max) '(face nil))))
  2536. (if (and (boundp 'org-agenda-overriding-columns-format)
  2537. org-agenda-overriding-columns-format)
  2538. (org-set-local 'org-agenda-overriding-columns-format
  2539. org-agenda-overriding-columns-format))
  2540. (if (and (boundp 'org-agenda-view-columns-initially)
  2541. org-agenda-view-columns-initially)
  2542. (org-agenda-columns))
  2543. (when org-agenda-fontify-priorities
  2544. (org-agenda-fontify-priorities))
  2545. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2546. (org-agenda-dim-blocked-tasks))
  2547. (org-agenda-mark-clocking-task)
  2548. (when org-agenda-entry-text-mode
  2549. (org-agenda-entry-text-hide)
  2550. (org-agenda-entry-text-show))
  2551. (if (functionp 'org-habit-insert-consistency-graphs)
  2552. (org-habit-insert-consistency-graphs))
  2553. (run-hooks 'org-finalize-agenda-hook)
  2554. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2555. (when (get 'org-agenda-filter :preset-filter)
  2556. (org-agenda-filter-apply org-agenda-filter))
  2557. )))
  2558. (defun org-agenda-mark-clocking-task ()
  2559. "Mark the current clock entry in the agenda if it is present."
  2560. (mapc (lambda (o)
  2561. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2562. (delete-overlay o)))
  2563. (overlays-in (point-min) (point-max)))
  2564. (when (marker-buffer org-clock-hd-marker)
  2565. (save-excursion
  2566. (goto-char (point-min))
  2567. (let (s ov)
  2568. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2569. (goto-char s)
  2570. (when (equal (org-get-at-bol 'org-hd-marker)
  2571. org-clock-hd-marker)
  2572. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2573. (overlay-put ov 'type 'org-agenda-clocking)
  2574. (overlay-put ov 'face 'org-agenda-clocking)
  2575. (overlay-put ov 'help-echo
  2576. "The clock is running in this item")))))))
  2577. (defun org-agenda-fontify-priorities ()
  2578. "Make highest priority lines bold, and lowest italic."
  2579. (interactive)
  2580. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2581. (delete-overlay o)))
  2582. (overlays-in (point-min) (point-max)))
  2583. (save-excursion
  2584. (let ((inhibit-read-only t)
  2585. b e p ov h l)
  2586. (goto-char (point-min))
  2587. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2588. (setq h (or (get-char-property (point) 'org-highest-priority)
  2589. org-highest-priority)
  2590. l (or (get-char-property (point) 'org-lowest-priority)
  2591. org-lowest-priority)
  2592. p (string-to-char (match-string 1))
  2593. b (match-beginning 0)
  2594. e (if (eq org-agenda-fontify-priorities 'cookies)
  2595. (match-end 0)
  2596. (point-at-eol))
  2597. ov (make-overlay b e))
  2598. (overlay-put
  2599. ov 'face
  2600. (cond ((org-face-from-face-or-color
  2601. 'priority nil
  2602. (cdr (assoc p org-priority-faces))))
  2603. ((and (listp org-agenda-fontify-priorities)
  2604. (org-face-from-face-or-color
  2605. 'priority nil
  2606. (cdr (assoc p org-agenda-fontify-priorities)))))
  2607. ((equal p l) 'italic)
  2608. ((equal p h) 'bold)))
  2609. (overlay-put ov 'org-type 'org-priority)))))
  2610. (defun org-agenda-dim-blocked-tasks ()
  2611. "Dim currently blocked TODO's in the agenda display."
  2612. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2613. (delete-overlay o)))
  2614. (overlays-in (point-min) (point-max)))
  2615. (save-excursion
  2616. (let ((inhibit-read-only t)
  2617. (org-depend-tag-blocked nil)
  2618. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2619. org-blocked-by-checkboxes
  2620. invis1 b e p ov h l)
  2621. (goto-char (point-min))
  2622. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2623. (and pos (goto-char (1+ pos))))
  2624. (setq org-blocked-by-checkboxes nil invis1 invis)
  2625. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2626. (when (and marker
  2627. (not (with-current-buffer (marker-buffer marker)
  2628. (save-excursion
  2629. (goto-char marker)
  2630. (if (org-entry-get nil "NOBLOCKING")
  2631. t ;; Never block this entry
  2632. (run-hook-with-args-until-failure
  2633. 'org-blocker-hook
  2634. (list :type 'todo-state-change
  2635. :position marker
  2636. :from 'todo
  2637. :to 'done)))))))
  2638. (if org-blocked-by-checkboxes (setq invis1 nil))
  2639. (setq b (if invis1
  2640. (max (point-min) (1- (point-at-bol)))
  2641. (point-at-bol))
  2642. e (point-at-eol)
  2643. ov (make-overlay b e))
  2644. (if invis1
  2645. (overlay-put ov 'invisible t)
  2646. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2647. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2648. (defvar org-agenda-skip-function nil
  2649. "Function to be called at each match during agenda construction.
  2650. If this function returns nil, the current match should not be skipped.
  2651. Otherwise, the function must return a position from where the search
  2652. should be continued.
  2653. This may also be a Lisp form, it will be evaluated.
  2654. Never set this variable using `setq' or so, because then it will apply
  2655. to all future agenda commands. Instead, bind it with `let' to scope
  2656. it dynamically into the agenda-constructing command. A good way to set
  2657. it is through options in org-agenda-custom-commands.")
  2658. (defun org-agenda-skip ()
  2659. "Throw to `:skip' in places that should be skipped.
  2660. Also moves point to the end of the skipped region, so that search can
  2661. continue from there."
  2662. (let ((p (point-at-bol)) to fp)
  2663. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2664. (get-text-property p :org-archived)
  2665. (org-end-of-subtree t)
  2666. (throw :skip t))
  2667. (and org-agenda-skip-comment-trees
  2668. (get-text-property p :org-comment)
  2669. (org-end-of-subtree t)
  2670. (throw :skip t))
  2671. (if (equal (char-after p) ?#) (throw :skip t))
  2672. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2673. (consp org-agenda-skip-function))
  2674. (setq to (save-excursion
  2675. (save-match-data
  2676. (if fp
  2677. (funcall org-agenda-skip-function)
  2678. (eval org-agenda-skip-function))))))
  2679. (goto-char to)
  2680. (throw :skip t))))
  2681. (defvar org-agenda-markers nil
  2682. "List of all currently active markers created by `org-agenda'.")
  2683. (defvar org-agenda-last-marker-time (org-float-time)
  2684. "Creation time of the last agenda marker.")
  2685. (defun org-agenda-new-marker (&optional pos)
  2686. "Return a new agenda marker.
  2687. Org-mode keeps a list of these markers and resets them when they are
  2688. no longer in use."
  2689. (let ((m (copy-marker (or pos (point)))))
  2690. (setq org-agenda-last-marker-time (org-float-time))
  2691. (push m org-agenda-markers)
  2692. m))
  2693. (defun org-agenda-reset-markers ()
  2694. "Reset markers created by `org-agenda'."
  2695. (while org-agenda-markers
  2696. (move-marker (pop org-agenda-markers) nil)))
  2697. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2698. "Save relative positions of markers in region."
  2699. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2700. org-agenda-markers))
  2701. ;;; Entry text mode
  2702. (defun org-agenda-entry-text-show-here ()
  2703. "Add some text from the entry as context to the current line."
  2704. (let (m txt o)
  2705. (setq m (org-get-at-bol 'org-hd-marker))
  2706. (unless (marker-buffer m)
  2707. (error "No marker points to an entry here"))
  2708. (setq txt (concat "\n" (org-no-properties
  2709. (org-agenda-get-some-entry-text
  2710. m org-agenda-entry-text-maxlines " > "))))
  2711. (when (string-match "\\S-" txt)
  2712. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2713. (overlay-put o 'evaporate t)
  2714. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2715. (overlay-put o 'after-string txt))))
  2716. (defun org-agenda-entry-text-show ()
  2717. "Add entry context for all agenda lines."
  2718. (interactive)
  2719. (save-excursion
  2720. (goto-char (point-max))
  2721. (beginning-of-line 1)
  2722. (while (not (bobp))
  2723. (when (org-get-at-bol 'org-hd-marker)
  2724. (org-agenda-entry-text-show-here))
  2725. (beginning-of-line 0))))
  2726. (defun org-agenda-entry-text-hide ()
  2727. "Remove any shown entry context."
  2728. (delq nil
  2729. (mapcar (lambda (o)
  2730. (if (eq (overlay-get o 'org-overlay-type)
  2731. 'agenda-entry-content)
  2732. (progn (delete-overlay o) t)))
  2733. (overlays-in (point-min) (point-max)))))
  2734. ;;; Agenda timeline
  2735. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2736. (defun org-timeline (&optional include-all)
  2737. "Show a time-sorted view of the entries in the current org file.
  2738. Only entries with a time stamp of today or later will be listed. With
  2739. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2740. under the current date.
  2741. If the buffer contains an active region, only check the region for
  2742. dates."
  2743. (interactive "P")
  2744. (org-compile-prefix-format 'timeline)
  2745. (org-set-sorting-strategy 'timeline)
  2746. (let* ((dopast t)
  2747. (dotodo include-all)
  2748. (doclosed org-agenda-show-log)
  2749. (entry buffer-file-name)
  2750. (date (calendar-current-date))
  2751. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2752. (end (if (org-region-active-p) (region-end) (point-max)))
  2753. (day-numbers (org-get-all-dates beg end 'no-ranges
  2754. t doclosed ; always include today
  2755. org-timeline-show-empty-dates))
  2756. (org-deadline-warning-days 0)
  2757. (org-agenda-only-exact-dates t)
  2758. (today (time-to-days (current-time)))
  2759. (past t)
  2760. args
  2761. s e rtn d emptyp wd)
  2762. (setq org-agenda-redo-command
  2763. (list 'progn
  2764. (list 'org-switch-to-buffer-other-window (current-buffer))
  2765. (list 'org-timeline (list 'quote include-all))))
  2766. (if (not dopast)
  2767. ;; Remove past dates from the list of dates.
  2768. (setq day-numbers (delq nil (mapcar (lambda(x)
  2769. (if (>= x today) x nil))
  2770. day-numbers))))
  2771. (org-prepare-agenda (concat "Timeline "
  2772. (file-name-nondirectory buffer-file-name)))
  2773. (if doclosed (push :closed args))
  2774. (push :timestamp args)
  2775. (push :deadline args)
  2776. (push :scheduled args)
  2777. (push :sexp args)
  2778. (if dotodo (push :todo args))
  2779. (insert "Timeline of file " entry "\n")
  2780. (add-text-properties (point-min) (point)
  2781. (list 'face 'org-agenda-structure))
  2782. (org-agenda-mark-header-line (point-min))
  2783. (while (setq d (pop day-numbers))
  2784. (if (and (listp d) (eq (car d) :omitted))
  2785. (progn
  2786. (setq s (point))
  2787. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2788. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2789. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2790. (if (and (>= d today)
  2791. dopast
  2792. past)
  2793. (progn
  2794. (setq past nil)
  2795. (insert (make-string 79 ?-) "\n")))
  2796. (setq date (calendar-gregorian-from-absolute d)
  2797. wd (calendar-day-of-week date))
  2798. (setq s (point))
  2799. (setq rtn (and (not emptyp)
  2800. (apply 'org-agenda-get-day-entries entry
  2801. date args)))
  2802. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2803. (progn
  2804. (insert
  2805. (if (stringp org-agenda-format-date)
  2806. (format-time-string org-agenda-format-date
  2807. (org-time-from-absolute date))
  2808. (funcall org-agenda-format-date date))
  2809. "\n")
  2810. (put-text-property s (1- (point)) 'face
  2811. (if (member wd org-agenda-weekend-days)
  2812. 'org-agenda-date-weekend
  2813. 'org-agenda-date))
  2814. (put-text-property s (1- (point)) 'org-date-line t)
  2815. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2816. (if (equal d today)
  2817. (put-text-property s (1- (point)) 'org-today t))
  2818. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2819. (put-text-property s (1- (point)) 'day d)))))
  2820. (goto-char (point-min))
  2821. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2822. (point-min)))
  2823. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2824. (org-finalize-agenda)
  2825. (setq buffer-read-only t)))
  2826. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2827. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2828. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2829. not every single day in the range. If FORCE-TODAY is non-nil, make
  2830. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2831. inactive time stamps (those in square brackets) are included.
  2832. When EMPTY is non-nil, also include days without any entries."
  2833. (let ((re (concat
  2834. (if pre-re pre-re "")
  2835. (if inactive org-ts-regexp-both org-ts-regexp)))
  2836. dates dates1 date day day1 day2 ts1 ts2)
  2837. (if force-today
  2838. (setq dates (list (time-to-days (current-time)))))
  2839. (save-excursion
  2840. (goto-char beg)
  2841. (while (re-search-forward re end t)
  2842. (setq day (time-to-days (org-time-string-to-time
  2843. (substring (match-string 1) 0 10))))
  2844. (or (memq day dates) (push day dates)))
  2845. (unless no-ranges
  2846. (goto-char beg)
  2847. (while (re-search-forward org-tr-regexp end t)
  2848. (setq ts1 (substring (match-string 1) 0 10)
  2849. ts2 (substring (match-string 2) 0 10)
  2850. day1 (time-to-days (org-time-string-to-time ts1))
  2851. day2 (time-to-days (org-time-string-to-time ts2)))
  2852. (while (< (setq day1 (1+ day1)) day2)
  2853. (or (memq day1 dates) (push day1 dates)))))
  2854. (setq dates (sort dates '<))
  2855. (when empty
  2856. (while (setq day (pop dates))
  2857. (setq day2 (car dates))
  2858. (push day dates1)
  2859. (when (and day2 empty)
  2860. (if (or (eq empty t)
  2861. (and (numberp empty) (<= (- day2 day) empty)))
  2862. (while (< (setq day (1+ day)) day2)
  2863. (push (list day) dates1))
  2864. (push (cons :omitted (- day2 day)) dates1))))
  2865. (setq dates (nreverse dates1)))
  2866. dates)))
  2867. ;;; Agenda Daily/Weekly
  2868. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2869. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2870. "Custom commands can set this variable in the options section.")
  2871. (defvar org-agenda-last-arguments nil
  2872. "The arguments of the previous call to org-agenda")
  2873. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2874. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2875. (defvar org-include-all-loc nil) ; local variable
  2876. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2877. "List of types searched for when creating the daily/weekly agenda.
  2878. This variable is a list of symbols that controls the types of
  2879. items that appear in the daily/weekly agenda. Allowed symbols in this
  2880. list are are
  2881. :timestamp List items containing a date stamp or date range matching
  2882. the selected date. This includes sexp entries in
  2883. angular brackets.
  2884. :sexp List entries resulting from plain diary-like sexps.
  2885. :deadline List deadline due on that date. When the date is today,
  2886. also list any deadlines past due, or due within
  2887. `org-deadline-warning-days'. `:deadline' must appear before
  2888. `:scheduled' if the setting of
  2889. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2890. any effect.
  2891. :scheduled List all items which are scheduled for the given date.
  2892. The diary for *today* also contains items which were
  2893. scheduled earlier and are not yet marked DONE.
  2894. By default, all four types are turned on.
  2895. Never set this variable globally using `setq', because then it
  2896. will apply to all future agenda commands. Instead, bind it with
  2897. `let' to scope it dynamically into the the agenda-constructing
  2898. command. A good way to set it is through options in
  2899. `org-agenda-custom-commands'. For a more flexible (though
  2900. somewhat less efficient) way of determining what is included in
  2901. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2902. ;;;###autoload
  2903. (defun org-agenda-list (&optional include-all start-day ndays)
  2904. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2905. The view will be for the current day or week, but from the overview buffer
  2906. you will be able to go to other days/weeks.
  2907. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2908. all unfinished TODO items will also be shown, before the agenda.
  2909. This feature is considered obsolete, please use the TODO list or a block
  2910. agenda instead.
  2911. With a numeric prefix argument in an interactive call, the agenda will
  2912. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2913. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2914. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2915. given in `org-agenda-start-on-weekday'."
  2916. (interactive "P")
  2917. (if (and (integerp include-all) (> include-all 0))
  2918. (setq ndays include-all include-all nil))
  2919. (setq ndays (or ndays org-agenda-ndays)
  2920. start-day (or start-day org-agenda-start-day))
  2921. (if org-agenda-overriding-arguments
  2922. (setq include-all (car org-agenda-overriding-arguments)
  2923. start-day (nth 1 org-agenda-overriding-arguments)
  2924. ndays (nth 2 org-agenda-overriding-arguments)))
  2925. (if (stringp start-day)
  2926. ;; Convert to an absolute day number
  2927. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2928. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2929. (org-compile-prefix-format 'agenda)
  2930. (org-set-sorting-strategy 'agenda)
  2931. (let* ((org-agenda-start-on-weekday
  2932. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2933. org-agenda-start-on-weekday nil))
  2934. (thefiles (org-agenda-files nil 'ifmode))
  2935. (files thefiles)
  2936. (today (time-to-days
  2937. (time-subtract (current-time)
  2938. (list 0 (* 3600 org-extend-today-until) 0))))
  2939. (sd (or start-day today))
  2940. (start (if (or (null org-agenda-start-on-weekday)
  2941. (< org-agenda-ndays 7))
  2942. sd
  2943. (let* ((nt (calendar-day-of-week
  2944. (calendar-gregorian-from-absolute sd)))
  2945. (n1 org-agenda-start-on-weekday)
  2946. (d (- nt n1)))
  2947. (- sd (+ (if (< d 0) 7 0) d)))))
  2948. (day-numbers (list start))
  2949. (day-cnt 0)
  2950. (inhibit-redisplay (not debug-on-error))
  2951. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2952. clocktable-start clocktable-end)
  2953. (setq org-agenda-redo-command
  2954. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2955. ;; Make the list of days
  2956. (setq ndays (or ndays org-agenda-ndays)
  2957. nd ndays)
  2958. (while (> ndays 1)
  2959. (push (1+ (car day-numbers)) day-numbers)
  2960. (setq ndays (1- ndays)))
  2961. (setq day-numbers (nreverse day-numbers))
  2962. (setq clocktable-start (car day-numbers)
  2963. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2964. (org-prepare-agenda "Day/Week")
  2965. (org-set-local 'org-starting-day (car day-numbers))
  2966. (org-set-local 'org-include-all-loc include-all)
  2967. (org-set-local 'org-agenda-span
  2968. (org-agenda-ndays-to-span nd))
  2969. (when (and (or include-all org-agenda-include-all-todo)
  2970. (member today day-numbers))
  2971. (setq files thefiles
  2972. rtnall nil)
  2973. (while (setq file (pop files))
  2974. (catch 'nextfile
  2975. (org-check-agenda-file file)
  2976. (setq date (calendar-gregorian-from-absolute today)
  2977. rtn (org-agenda-get-day-entries
  2978. file date :todo))
  2979. (setq rtnall (append rtnall rtn))))
  2980. (when rtnall
  2981. (insert "All currently open TODO items:\n")
  2982. (add-text-properties (point-min) (1- (point))
  2983. (list 'face 'org-agenda-structure
  2984. 'short-heading "All TODO items"))
  2985. (org-agenda-mark-header-line (point-min))
  2986. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2987. (unless org-agenda-compact-blocks
  2988. (let* ((d1 (car day-numbers))
  2989. (d2 (org-last day-numbers))
  2990. (w1 (org-days-to-iso-week d1))
  2991. (w2 (org-days-to-iso-week d2)))
  2992. (setq s (point))
  2993. (if org-agenda-overriding-header
  2994. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2995. nil 'face 'org-agenda-structure) "\n")
  2996. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2997. "-agenda"
  2998. (if (< (- d2 d1) 350)
  2999. (if (= w1 w2)
  3000. (format " (W%02d)" w1)
  3001. (format " (W%02d-W%02d)" w1 w2))
  3002. "")
  3003. ":\n")))
  3004. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3005. 'org-date-line t))
  3006. (org-agenda-mark-header-line s))
  3007. (while (setq d (pop day-numbers))
  3008. (setq date (calendar-gregorian-from-absolute d)
  3009. wd (calendar-day-of-week date)
  3010. s (point))
  3011. (if (or (setq todayp (= d today))
  3012. (and (not start-pos) (= d sd)))
  3013. (setq start-pos (point))
  3014. (if (and start-pos (not end-pos))
  3015. (setq end-pos (point))))
  3016. (setq files thefiles
  3017. rtnall nil)
  3018. (while (setq file (pop files))
  3019. (catch 'nextfile
  3020. (org-check-agenda-file file)
  3021. (let ((org-agenda-entry-types org-agenda-entry-types))
  3022. (unless org-agenda-include-deadlines
  3023. (setq org-agenda-entry-types
  3024. (delq :deadline org-agenda-entry-types)))
  3025. (cond
  3026. ((eq org-agenda-show-log 'only)
  3027. (setq rtn (org-agenda-get-day-entries
  3028. file date :closed)))
  3029. (org-agenda-show-log
  3030. (setq rtn (apply 'org-agenda-get-day-entries
  3031. file date
  3032. (append '(:closed) org-agenda-entry-types))))
  3033. (t
  3034. (setq rtn (apply 'org-agenda-get-day-entries
  3035. file date
  3036. org-agenda-entry-types)))))
  3037. (setq rtnall (append rtnall rtn))))
  3038. (if org-agenda-include-diary
  3039. (let ((org-agenda-search-headline-for-time t))
  3040. (require 'diary-lib)
  3041. (setq rtn (org-get-entries-from-diary date))
  3042. (setq rtnall (append rtnall rtn))))
  3043. (if (or rtnall org-agenda-show-all-dates)
  3044. (progn
  3045. (setq day-cnt (1+ day-cnt))
  3046. (insert
  3047. (if (stringp org-agenda-format-date)
  3048. (format-time-string org-agenda-format-date
  3049. (org-time-from-absolute date))
  3050. (funcall org-agenda-format-date date))
  3051. "\n")
  3052. (put-text-property s (1- (point)) 'face
  3053. (if (member wd org-agenda-weekend-days)
  3054. 'org-agenda-date-weekend
  3055. 'org-agenda-date))
  3056. (put-text-property s (1- (point)) 'org-date-line t)
  3057. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3058. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3059. (when todayp
  3060. (put-text-property s (1- (point)) 'org-today t)
  3061. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3062. (if rtnall (insert
  3063. (org-finalize-agenda-entries
  3064. (org-agenda-add-time-grid-maybe
  3065. rtnall nd todayp))
  3066. "\n"))
  3067. (put-text-property s (1- (point)) 'day d)
  3068. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3069. (when (and org-agenda-clockreport-mode clocktable-start)
  3070. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3071. ;; the above line is to ensure the restricted range!
  3072. (p org-agenda-clockreport-parameter-plist)
  3073. tbl)
  3074. (setq p (org-plist-delete p :block))
  3075. (setq p (plist-put p :tstart clocktable-start))
  3076. (setq p (plist-put p :tend clocktable-end))
  3077. (setq p (plist-put p :scope 'agenda))
  3078. (setq tbl (apply 'org-get-clocktable p))
  3079. (insert tbl)))
  3080. (goto-char (point-min))
  3081. (or org-agenda-multi (org-fit-agenda-window))
  3082. (unless (and (pos-visible-in-window-p (point-min))
  3083. (pos-visible-in-window-p (point-max)))
  3084. (goto-char (1- (point-max)))
  3085. (recenter -1)
  3086. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3087. (progn
  3088. (goto-char (or start-pos 1))
  3089. (recenter 1))))
  3090. (goto-char (or start-pos 1))
  3091. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3092. (org-finalize-agenda)
  3093. (setq buffer-read-only t)
  3094. (message "")))
  3095. (defun org-agenda-ndays-to-span (n)
  3096. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3097. ;;; Agenda word search
  3098. (defvar org-agenda-search-history nil)
  3099. (defvar org-todo-only nil)
  3100. (defvar org-search-syntax-table nil
  3101. "Special syntax table for org-mode search.
  3102. In this table, we have single quotes not as word constituents, to
  3103. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3104. (defun org-search-syntax-table ()
  3105. (unless org-search-syntax-table
  3106. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3107. (modify-syntax-entry ?' "." org-search-syntax-table)
  3108. (modify-syntax-entry ?` "." org-search-syntax-table))
  3109. org-search-syntax-table)
  3110. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3111. ;;;###autoload
  3112. (defun org-search-view (&optional todo-only string edit-at)
  3113. "Show all entries that contain a phrase or words or regular expressions.
  3114. With optional prefix argument TODO-ONLY, only consider entries that are
  3115. TODO entries. The argument STRING can be used to pass a default search
  3116. string into this function. If EDIT-AT is non-nil, it means that the
  3117. user should get a chance to edit this string, with cursor at position
  3118. EDIT-AT.
  3119. The search string can be viewed either as a phrase that should be found as
  3120. is, or it can be broken into a number of snippets, each of which must match
  3121. in a Boolean way to select an entry. The default depends on the variable
  3122. `org-agenda-search-view-always-boolean'.
  3123. Even if this is turned off (the default) you can always switch to
  3124. Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
  3125. The default is a direct search of the whole phrase, where each space in
  3126. the search string can expand to an arbitrary amount of whitespace,
  3127. including newlines.
  3128. If using a Boolean search, the search string is split on whitespace and
  3129. each snippet is searched separately, with logical AND to select an entry.
  3130. Words prefixed with a minus must *not* occur in the entry. Words without
  3131. a prefix or prefixed with a plus must occur in the entry. Matching is
  3132. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3133. match whole words, not parts of a word) if
  3134. `org-agenda-search-view-force-full-words' is set (default is nil).
  3135. Boolean search snippets enclosed by curly braces are interpreted as
  3136. regular expressions that must or (when preceeded with \"-\") must not
  3137. match in the entry. Snippets enclosed into double quotes will be taken
  3138. as a whole, to incude whitespace.
  3139. - If the search string starts with an asterisk, search only in headlines.
  3140. - If (possibly after the leading star) the search string starts with an
  3141. exclamation mark, this also means to look at TODO entries only, an effect
  3142. that can also be achieved with a prefix argument.
  3143. - If (possibly after star and exclamation mark) the search string starts
  3144. with a colon, this will mean that the (non-regexp) snippets of the
  3145. Boolean search must match as full words.
  3146. This command searches the agenda files, and in addition the files listed
  3147. in `org-agenda-text-search-extra-files'."
  3148. (interactive "P")
  3149. (org-compile-prefix-format 'search)
  3150. (org-set-sorting-strategy 'search)
  3151. (org-prepare-agenda "SEARCH")
  3152. (let* ((props (list 'face nil
  3153. 'done-face 'org-agenda-done
  3154. 'org-not-done-regexp org-not-done-regexp
  3155. 'org-todo-regexp org-todo-regexp
  3156. 'org-complex-heading-regexp org-complex-heading-regexp
  3157. 'mouse-face 'highlight
  3158. 'help-echo (format "mouse-2 or RET jump to location")))
  3159. (full-words org-agenda-search-view-force-full-words)
  3160. regexp rtn rtnall files file pos
  3161. marker category tags c neg re boolean
  3162. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3163. (unless (and (not edit-at)
  3164. (stringp string)
  3165. (string-match "\\S-" string))
  3166. (setq string (read-string
  3167. (if org-agenda-search-view-always-boolean
  3168. "[+-]Word/{Regexp} ...: "
  3169. "Phrase, or [+-]Word/{Regexp} ...: ")
  3170. (cond
  3171. ((integerp edit-at) (cons string edit-at))
  3172. (edit-at string))
  3173. 'org-agenda-search-history)))
  3174. (org-set-local 'org-todo-only todo-only)
  3175. (setq org-agenda-redo-command
  3176. (list 'org-search-view (if todo-only t nil) string
  3177. '(if current-prefix-arg 1 nil)))
  3178. (setq org-agenda-query-string string)
  3179. (if (equal (string-to-char string) ?*)
  3180. (setq hdl-only t
  3181. words (substring string 1))
  3182. (setq words string))
  3183. (when (equal (string-to-char words) ?!)
  3184. (setq todo-only t
  3185. words (substring words 1)))
  3186. (when (equal (string-to-char words) ?:)
  3187. (setq full-words t
  3188. words (substring words 1)))
  3189. (if (or org-agenda-search-view-always-boolean
  3190. (member (string-to-char words) '(?- ?+ ?\{)))
  3191. (setq boolean t))
  3192. (setq words (org-split-string words))
  3193. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3194. (when boolean
  3195. (let (wds w)
  3196. (while (setq w (pop words))
  3197. (if (or (equal (substring w 0 1) "\"")
  3198. (and (> (length w) 1)
  3199. (member (substring w 0 1) '("+" "-"))
  3200. (equal (substring w 1 2) "\"")))
  3201. (while (and words (not (equal (substring w -1) "\"")))
  3202. (setq w (concat w " " (pop words)))))
  3203. (and (string-match "\\`\\([-+]?\\)\"" w)
  3204. (setq w (replace-match "\\1" nil nil w)))
  3205. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3206. (push w wds))
  3207. (setq words (nreverse wds))))
  3208. (if boolean
  3209. (mapc (lambda (w)
  3210. (setq c (string-to-char w))
  3211. (if (equal c ?-)
  3212. (setq neg t w (substring w 1))
  3213. (if (equal c ?+)
  3214. (setq neg nil w (substring w 1))
  3215. (setq neg nil)))
  3216. (if (string-match "\\`{.*}\\'" w)
  3217. (setq re (substring w 1 -1))
  3218. (if full-words
  3219. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3220. (setq re (regexp-quote (downcase w)))))
  3221. (if neg (push re regexps-) (push re regexps+)))
  3222. words)
  3223. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3224. regexps+))
  3225. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3226. (if (not regexps+)
  3227. (setq regexp (concat "^" org-outline-regexp))
  3228. (setq regexp (pop regexps+))
  3229. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3230. regexp))))
  3231. (setq files (org-agenda-files nil 'ifmode))
  3232. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3233. (pop org-agenda-text-search-extra-files)
  3234. (setq files (org-add-archive-files files)))
  3235. (setq files (append files org-agenda-text-search-extra-files)
  3236. rtnall nil)
  3237. (while (setq file (pop files))
  3238. (setq ee nil)
  3239. (catch 'nextfile
  3240. (org-check-agenda-file file)
  3241. (setq buffer (if (file-exists-p file)
  3242. (org-get-agenda-file-buffer file)
  3243. (error "No such file %s" file)))
  3244. (if (not buffer)
  3245. ;; If file does not exist, make sure an error message is sent
  3246. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3247. file))))
  3248. (with-current-buffer buffer
  3249. (with-syntax-table (org-search-syntax-table)
  3250. (unless (org-mode-p)
  3251. (error "Agenda file %s is not in `org-mode'" file))
  3252. (let ((case-fold-search t))
  3253. (save-excursion
  3254. (save-restriction
  3255. (if org-agenda-restrict
  3256. (narrow-to-region org-agenda-restrict-begin
  3257. org-agenda-restrict-end)
  3258. (widen))
  3259. (goto-char (point-min))
  3260. (unless (or (org-on-heading-p)
  3261. (outline-next-heading))
  3262. (throw 'nextfile t))
  3263. (goto-char (max (point-min) (1- (point))))
  3264. (while (re-search-forward regexp nil t)
  3265. (org-back-to-heading t)
  3266. (skip-chars-forward "* ")
  3267. (setq beg (point-at-bol)
  3268. beg1 (point)
  3269. end (progn (outline-next-heading) (point)))
  3270. (catch :skip
  3271. (goto-char beg)
  3272. (org-agenda-skip)
  3273. (setq str (buffer-substring-no-properties
  3274. (point-at-bol)
  3275. (if hdl-only (point-at-eol) end)))
  3276. (mapc (lambda (wr) (when (string-match wr str)
  3277. (goto-char (1- end))
  3278. (throw :skip t)))
  3279. regexps-)
  3280. (mapc (lambda (wr) (unless (string-match wr str)
  3281. (goto-char (1- end))
  3282. (throw :skip t)))
  3283. (if todo-only
  3284. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3285. regexps+)
  3286. regexps+))
  3287. (goto-char beg)
  3288. (setq marker (org-agenda-new-marker (point))
  3289. category (org-get-category)
  3290. tags (org-get-tags-at (point))
  3291. txt (org-format-agenda-item
  3292. ""
  3293. (buffer-substring-no-properties
  3294. beg1 (point-at-eol))
  3295. category tags))
  3296. (org-add-props txt props
  3297. 'org-marker marker 'org-hd-marker marker
  3298. 'org-todo-regexp org-todo-regexp
  3299. 'org-complex-heading-regexp org-complex-heading-regexp
  3300. 'priority 1000 'org-category category
  3301. 'type "search")
  3302. (push txt ee)
  3303. (goto-char (1- end))))))))))
  3304. (setq rtn (nreverse ee))
  3305. (setq rtnall (append rtnall rtn)))
  3306. (if org-agenda-overriding-header
  3307. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3308. nil 'face 'org-agenda-structure) "\n")
  3309. (insert "Search words: ")
  3310. (add-text-properties (point-min) (1- (point))
  3311. (list 'face 'org-agenda-structure))
  3312. (setq pos (point))
  3313. (insert string "\n")
  3314. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3315. (setq pos (point))
  3316. (unless org-agenda-multi
  3317. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3318. (add-text-properties pos (1- (point))
  3319. (list 'face 'org-agenda-structure))))
  3320. (org-agenda-mark-header-line (point-min))
  3321. (when rtnall
  3322. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3323. (goto-char (point-min))
  3324. (or org-agenda-multi (org-fit-agenda-window))
  3325. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3326. (org-finalize-agenda)
  3327. (setq buffer-read-only t)))
  3328. ;;; Agenda TODO list
  3329. (defvar org-select-this-todo-keyword nil)
  3330. (defvar org-last-arg nil)
  3331. ;;;###autoload
  3332. (defun org-todo-list (arg)
  3333. "Show all TODO entries from all agenda file in a single list.
  3334. The prefix arg can be used to select a specific TODO keyword and limit
  3335. the list to these. When using \\[universal-argument], you will be prompted
  3336. for a keyword. A numeric prefix directly selects the Nth keyword in
  3337. `org-todo-keywords-1'."
  3338. (interactive "P")
  3339. (org-compile-prefix-format 'todo)
  3340. (org-set-sorting-strategy 'todo)
  3341. (org-prepare-agenda "TODO")
  3342. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3343. (let* ((today (time-to-days (current-time)))
  3344. (date (calendar-gregorian-from-absolute today))
  3345. (kwds org-todo-keywords-for-agenda)
  3346. (completion-ignore-case t)
  3347. (org-select-this-todo-keyword
  3348. (if (stringp arg) arg
  3349. (and arg (integerp arg) (> arg 0)
  3350. (nth (1- arg) kwds))))
  3351. rtn rtnall files file pos)
  3352. (when (equal arg '(4))
  3353. (setq org-select-this-todo-keyword
  3354. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3355. (mapcar 'list kwds) nil nil)))
  3356. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3357. (org-set-local 'org-last-arg arg)
  3358. (setq org-agenda-redo-command
  3359. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3360. (setq files (org-agenda-files nil 'ifmode)
  3361. rtnall nil)
  3362. (while (setq file (pop files))
  3363. (catch 'nextfile
  3364. (org-check-agenda-file file)
  3365. (setq rtn (org-agenda-get-day-entries file date :todo))
  3366. (setq rtnall (append rtnall rtn))))
  3367. (if org-agenda-overriding-header
  3368. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3369. nil 'face 'org-agenda-structure) "\n")
  3370. (insert "Global list of TODO items of type: ")
  3371. (add-text-properties (point-min) (1- (point))
  3372. (list 'face 'org-agenda-structure
  3373. 'short-heading
  3374. (concat "ToDo: "
  3375. (or org-select-this-todo-keyword "ALL"))))
  3376. (org-agenda-mark-header-line (point-min))
  3377. (setq pos (point))
  3378. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3379. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3380. (setq pos (point))
  3381. (unless org-agenda-multi
  3382. (insert "Available with `N r': (0)ALL")
  3383. (let ((n 0) s)
  3384. (mapc (lambda (x)
  3385. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3386. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3387. (insert "\n "))
  3388. (insert " " s))
  3389. kwds))
  3390. (insert "\n"))
  3391. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3392. (org-agenda-mark-header-line (point-min))
  3393. (when rtnall
  3394. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3395. (goto-char (point-min))
  3396. (or org-agenda-multi (org-fit-agenda-window))
  3397. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3398. (org-finalize-agenda)
  3399. (setq buffer-read-only t)))
  3400. ;;; Agenda tags match
  3401. ;;;###autoload
  3402. (defun org-tags-view (&optional todo-only match)
  3403. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3404. The prefix arg TODO-ONLY limits the search to TODO entries."
  3405. (interactive "P")
  3406. (org-compile-prefix-format 'tags)
  3407. (org-set-sorting-strategy 'tags)
  3408. (let* ((org-tags-match-list-sublevels
  3409. org-tags-match-list-sublevels)
  3410. (completion-ignore-case t)
  3411. rtn rtnall files file pos matcher
  3412. buffer)
  3413. (when (and (stringp match) (not (string-match "\\S-" match)))
  3414. (setq match nil))
  3415. (setq matcher (org-make-tags-matcher match)
  3416. match (car matcher) matcher (cdr matcher))
  3417. (org-prepare-agenda (concat "TAGS " match))
  3418. (setq org-agenda-query-string match)
  3419. (setq org-agenda-redo-command
  3420. (list 'org-tags-view (list 'quote todo-only)
  3421. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3422. (setq files (org-agenda-files nil 'ifmode)
  3423. rtnall nil)
  3424. (while (setq file (pop files))
  3425. (catch 'nextfile
  3426. (org-check-agenda-file file)
  3427. (setq buffer (if (file-exists-p file)
  3428. (org-get-agenda-file-buffer file)
  3429. (error "No such file %s" file)))
  3430. (if (not buffer)
  3431. ;; If file does not exist, error message to agenda
  3432. (setq rtn (list
  3433. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3434. rtnall (append rtnall rtn))
  3435. (with-current-buffer buffer
  3436. (unless (org-mode-p)
  3437. (error "Agenda file %s is not in `org-mode'" file))
  3438. (save-excursion
  3439. (save-restriction
  3440. (if org-agenda-restrict
  3441. (narrow-to-region org-agenda-restrict-begin
  3442. org-agenda-restrict-end)
  3443. (widen))
  3444. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3445. (setq rtnall (append rtnall rtn))))))))
  3446. (if org-agenda-overriding-header
  3447. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3448. nil 'face 'org-agenda-structure) "\n")
  3449. (insert "Headlines with TAGS match: ")
  3450. (add-text-properties (point-min) (1- (point))
  3451. (list 'face 'org-agenda-structure
  3452. 'short-heading
  3453. (concat "Match: " match)))
  3454. (setq pos (point))
  3455. (insert match "\n")
  3456. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3457. (setq pos (point))
  3458. (unless org-agenda-multi
  3459. (insert "Press `C-u r' to search again with new search string\n"))
  3460. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3461. (org-agenda-mark-header-line (point-min))
  3462. (when rtnall
  3463. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3464. (goto-char (point-min))
  3465. (or org-agenda-multi (org-fit-agenda-window))
  3466. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3467. (org-finalize-agenda)
  3468. (setq buffer-read-only t)))
  3469. ;;; Agenda Finding stuck projects
  3470. (defvar org-agenda-skip-regexp nil
  3471. "Regular expression used in skipping subtrees for the agenda.
  3472. This is basically a temporary global variable that can be set and then
  3473. used by user-defined selections using `org-agenda-skip-function'.")
  3474. (defvar org-agenda-overriding-header nil
  3475. "When this is set during todo and tags searches, will replace header.
  3476. This variable should not be set directly, but custom commands can bind it
  3477. in the options section.")
  3478. (defun org-agenda-skip-entry-when-regexp-matches ()
  3479. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3480. If yes, it returns the end position of this entry, causing agenda commands
  3481. to skip the entry but continuing the search in the subtree. This is a
  3482. function that can be put into `org-agenda-skip-function' for the duration
  3483. of a command."
  3484. (let ((end (save-excursion (org-end-of-subtree t)))
  3485. skip)
  3486. (save-excursion
  3487. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3488. (and skip end)))
  3489. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3490. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3491. If yes, it returns the end position of this tree, causing agenda commands
  3492. to skip this subtree. This is a function that can be put into
  3493. `org-agenda-skip-function' for the duration of a command."
  3494. (let ((end (save-excursion (org-end-of-subtree t)))
  3495. skip)
  3496. (save-excursion
  3497. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3498. (and skip end)))
  3499. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3500. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3501. If yes, it returns the end position of the current entry (NOT the tree),
  3502. causing agenda commands to skip the entry but continuing the search in
  3503. the subtree. This is a function that can be put into
  3504. `org-agenda-skip-function' for the duration of a command. An important
  3505. use of this function is for the stuck project list."
  3506. (let ((end (save-excursion (org-end-of-subtree t)))
  3507. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3508. skip)
  3509. (save-excursion
  3510. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3511. (and skip entry-end)))
  3512. (defun org-agenda-skip-entry-if (&rest conditions)
  3513. "Skip entry if any of CONDITIONS is true.
  3514. See `org-agenda-skip-if' for details."
  3515. (org-agenda-skip-if nil conditions))
  3516. (defun org-agenda-skip-subtree-if (&rest conditions)
  3517. "Skip entry if any of CONDITIONS is true.
  3518. See `org-agenda-skip-if' for details."
  3519. (org-agenda-skip-if t conditions))
  3520. (defun org-agenda-skip-if (subtree conditions)
  3521. "Checks current entity for CONDITIONS.
  3522. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3523. the entry, i.e. the text before the next heading is checked.
  3524. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3525. from different tests. Valid conditions are:
  3526. scheduled Check if there is a scheduled cookie
  3527. notscheduled Check if there is no scheduled cookie
  3528. deadline Check if there is a deadline
  3529. notdeadline Check if there is no deadline
  3530. timestamp Check if there is a timestamp (also deadline or scheduled)
  3531. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3532. regexp Check if regexp matches
  3533. notregexp Check if regexp does not match.
  3534. todo Check if TODO keyword matches
  3535. nottodo Check if TODO keyword does not match
  3536. The regexp is taken from the conditions list, it must come right after
  3537. the `regexp' or `notregexp' element.
  3538. `todo' and `nottodo' accept as an argument a list of todo
  3539. keywords, which may include \"*\" to match any todo keyword.
  3540. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3541. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3542. Instead of a list a keyword class may be given
  3543. (org-agenda-skip-entry-if 'nottodo 'done)
  3544. would skip entries that haven't been marked with any of \"DONE\"
  3545. keywords. Possible classes are: `todo', `done', `any'.
  3546. If any of these conditions is met, this function returns the end point of
  3547. the entity, causing the search to continue from there. This is a function
  3548. that can be put into `org-agenda-skip-function' for the duration of a command."
  3549. (let (beg end m)
  3550. (org-back-to-heading t)
  3551. (setq beg (point)
  3552. end (if subtree
  3553. (progn (org-end-of-subtree t) (point))
  3554. (progn (outline-next-heading) (1- (point)))))
  3555. (goto-char beg)
  3556. (and
  3557. (or
  3558. (and (memq 'scheduled conditions)
  3559. (re-search-forward org-scheduled-time-regexp end t))
  3560. (and (memq 'notscheduled conditions)
  3561. (not (re-search-forward org-scheduled-time-regexp end t)))
  3562. (and (memq 'deadline conditions)
  3563. (re-search-forward org-deadline-time-regexp end t))
  3564. (and (memq 'notdeadline conditions)
  3565. (not (re-search-forward org-deadline-time-regexp end t)))
  3566. (and (memq 'timestamp conditions)
  3567. (re-search-forward org-ts-regexp end t))
  3568. (and (memq 'nottimestamp conditions)
  3569. (not (re-search-forward org-ts-regexp end t)))
  3570. (and (setq m (memq 'regexp conditions))
  3571. (stringp (nth 1 m))
  3572. (re-search-forward (nth 1 m) end t))
  3573. (and (setq m (memq 'notregexp conditions))
  3574. (stringp (nth 1 m))
  3575. (not (re-search-forward (nth 1 m) end t)))
  3576. (and (or
  3577. (setq m (memq 'todo conditions))
  3578. (setq m (memq 'nottodo conditions)))
  3579. (org-agenda-skip-if-todo m end)))
  3580. end)))
  3581. (defun org-agenda-skip-if-todo (args end)
  3582. "Helper function for `org-agenda-skip-if', do not use it directly.
  3583. ARGS is a list with first element either `todo' or `nottodo'.
  3584. The remainder is either a list of TODO keywords, or a state symbol
  3585. `todo' or `done' or `any'."
  3586. (let ((kw (car args))
  3587. (arg (cadr args))
  3588. todo-wds todo-re)
  3589. (setq todo-wds
  3590. (org-uniquify
  3591. (cond
  3592. ((listp arg) ;; list of keywords
  3593. (if (member "*" arg)
  3594. (mapcar 'substring-no-properties org-todo-keywords-1)
  3595. arg))
  3596. ((symbolp arg) ;; keyword class name
  3597. (cond
  3598. ((eq arg 'todo)
  3599. (org-delete-all org-done-keywords
  3600. (mapcar 'substring-no-properties
  3601. org-todo-keywords-1)))
  3602. ((eq arg 'done) org-done-keywords)
  3603. ((eq arg 'any)
  3604. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3605. (setq todo-re
  3606. (concat "^\\*+[ \t]+\\<\\("
  3607. (mapconcat 'identity todo-wds "\\|")
  3608. "\\)\\>"))
  3609. (if (eq kw 'todo)
  3610. (re-search-forward todo-re end t)
  3611. (not (re-search-forward todo-re end t)))))
  3612. ;;;###autoload
  3613. (defun org-agenda-list-stuck-projects (&rest ignore)
  3614. "Create agenda view for projects that are stuck.
  3615. Stuck projects are project that have no next actions. For the definitions
  3616. of what a project is and how to check if it stuck, customize the variable
  3617. `org-stuck-projects'.
  3618. MATCH is being ignored."
  3619. (interactive)
  3620. (let* ((org-agenda-skip-function
  3621. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3622. ;; We could have used org-agenda-skip-if here.
  3623. (org-agenda-overriding-header
  3624. (or org-agenda-overriding-header "List of stuck projects: "))
  3625. (matcher (nth 0 org-stuck-projects))
  3626. (todo (nth 1 org-stuck-projects))
  3627. (todo-wds (if (member "*" todo)
  3628. (progn
  3629. (org-prepare-agenda-buffers (org-agenda-files
  3630. nil 'ifmode))
  3631. (org-delete-all
  3632. org-done-keywords-for-agenda
  3633. (copy-sequence org-todo-keywords-for-agenda)))
  3634. todo))
  3635. (todo-re (concat "^\\*+[ \t]+\\("
  3636. (mapconcat 'identity todo-wds "\\|")
  3637. "\\)\\>"))
  3638. (tags (nth 2 org-stuck-projects))
  3639. (tags-re (if (member "*" tags)
  3640. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3641. (if tags
  3642. (concat "^\\*+ .*:\\("
  3643. (mapconcat 'identity tags "\\|")
  3644. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3645. (gen-re (nth 3 org-stuck-projects))
  3646. (re-list
  3647. (delq nil
  3648. (list
  3649. (if todo todo-re)
  3650. (if tags tags-re)
  3651. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3652. gen-re)))))
  3653. (setq org-agenda-skip-regexp
  3654. (if re-list
  3655. (mapconcat 'identity re-list "\\|")
  3656. (error "No information how to identify unstuck projects")))
  3657. (org-tags-view nil matcher)
  3658. (with-current-buffer org-agenda-buffer-name
  3659. (setq org-agenda-redo-command
  3660. '(org-agenda-list-stuck-projects
  3661. (or current-prefix-arg org-last-arg))))))
  3662. ;;; Diary integration
  3663. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3664. (defvar list-diary-entries-hook)
  3665. (defun org-get-entries-from-diary (date)
  3666. "Get the (Emacs Calendar) diary entries for DATE."
  3667. (require 'diary-lib)
  3668. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3669. (diary-display-hook '(fancy-diary-display))
  3670. (diary-display-function 'fancy-diary-display)
  3671. (pop-up-frames nil)
  3672. (list-diary-entries-hook
  3673. (cons 'org-diary-default-entry list-diary-entries-hook))
  3674. (diary-file-name-prefix-function nil) ; turn this feature off
  3675. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3676. entries
  3677. (org-disable-agenda-to-diary t))
  3678. (save-excursion
  3679. (save-window-excursion
  3680. (funcall (if (fboundp 'diary-list-entries)
  3681. 'diary-list-entries 'list-diary-entries)
  3682. date 1)))
  3683. (if (not (get-buffer diary-fancy-buffer))
  3684. (setq entries nil)
  3685. (with-current-buffer diary-fancy-buffer
  3686. (setq buffer-read-only nil)
  3687. (if (zerop (buffer-size))
  3688. ;; No entries
  3689. (setq entries nil)
  3690. ;; Omit the date and other unnecessary stuff
  3691. (org-agenda-cleanup-fancy-diary)
  3692. ;; Add prefix to each line and extend the text properties
  3693. (if (zerop (buffer-size))
  3694. (setq entries nil)
  3695. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3696. (set-buffer-modified-p nil)
  3697. (kill-buffer diary-fancy-buffer)))
  3698. (when entries
  3699. (setq entries (org-split-string entries "\n"))
  3700. (setq entries
  3701. (mapcar
  3702. (lambda (x)
  3703. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3704. ;; Extend the text properties to the beginning of the line
  3705. (org-add-props x (text-properties-at (1- (length x)) x)
  3706. 'type "diary" 'date date 'face 'org-agenda-diary))
  3707. entries)))))
  3708. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3709. "Hook run when the fancy diary buffer is cleaned up.")
  3710. (defun org-agenda-cleanup-fancy-diary ()
  3711. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3712. This gets rid of the date, the underline under the date, and
  3713. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3714. date. It also removes lines that contain only whitespace."
  3715. (goto-char (point-min))
  3716. (if (looking-at ".*?:[ \t]*")
  3717. (progn
  3718. (replace-match "")
  3719. (re-search-forward "\n=+$" nil t)
  3720. (replace-match "")
  3721. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3722. (re-search-forward "\n=+$" nil t)
  3723. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3724. (goto-char (point-min))
  3725. (while (re-search-forward "^ +\n" nil t)
  3726. (replace-match ""))
  3727. (goto-char (point-min))
  3728. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3729. (replace-match ""))
  3730. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3731. ;; Make sure entries from the diary have the right text properties.
  3732. (eval-after-load "diary-lib"
  3733. '(if (boundp 'diary-modify-entry-list-string-function)
  3734. ;; We can rely on the hook, nothing to do
  3735. nil
  3736. ;; Hook not available, must use advice to make this work
  3737. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3738. "Make the position visible."
  3739. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3740. (stringp string)
  3741. buffer-file-name)
  3742. (setq string (org-modify-diary-entry-string string))))))
  3743. (defun org-modify-diary-entry-string (string)
  3744. "Add text properties to string, allowing org-mode to act on it."
  3745. (org-add-props string nil
  3746. 'mouse-face 'highlight
  3747. 'help-echo (if buffer-file-name
  3748. (format "mouse-2 or RET jump to diary file %s"
  3749. (abbreviate-file-name buffer-file-name))
  3750. "")
  3751. 'org-agenda-diary-link t
  3752. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3753. (defun org-diary-default-entry ()
  3754. "Add a dummy entry to the diary.
  3755. Needed to avoid empty dates which mess up holiday display."
  3756. ;; Catch the error if dealing with the new add-to-diary-alist
  3757. (when org-disable-agenda-to-diary
  3758. (condition-case nil
  3759. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3760. (error
  3761. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3762. (defun org-add-to-diary-list (&rest args)
  3763. (if (fboundp 'diary-add-to-list)
  3764. (apply 'diary-add-to-list args)
  3765. (apply 'add-to-diary-list args)))
  3766. (defvar org-diary-last-run-time nil)
  3767. ;;;###autoload
  3768. (defun org-diary (&rest args)
  3769. "Return diary information from org-files.
  3770. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3771. It accesses org files and extracts information from those files to be
  3772. listed in the diary. The function accepts arguments specifying what
  3773. items should be listed. For a list of arguments allowed here, see the
  3774. variable `org-agenda-entry-types'.
  3775. The call in the diary file should look like this:
  3776. &%%(org-diary) ~/path/to/some/orgfile.org
  3777. Use a separate line for each org file to check. Or, if you omit the file name,
  3778. all files listed in `org-agenda-files' will be checked automatically:
  3779. &%%(org-diary)
  3780. If you don't give any arguments (as in the example above), the default
  3781. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3782. So the example above may also be written as
  3783. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3784. The function expects the lisp variables `entry' and `date' to be provided
  3785. by the caller, because this is how the calendar works. Don't use this
  3786. function from a program - use `org-agenda-get-day-entries' instead."
  3787. (when (> (- (org-float-time)
  3788. org-agenda-last-marker-time)
  3789. 5)
  3790. (org-agenda-reset-markers))
  3791. (org-compile-prefix-format 'agenda)
  3792. (org-set-sorting-strategy 'agenda)
  3793. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3794. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3795. (list entry)
  3796. (org-agenda-files t)))
  3797. (time (org-float-time))
  3798. file rtn results)
  3799. (when (or (not org-diary-last-run-time)
  3800. (> (- time
  3801. org-diary-last-run-time)
  3802. 3))
  3803. (org-prepare-agenda-buffers files))
  3804. (setq org-diary-last-run-time time)
  3805. ;; If this is called during org-agenda, don't return any entries to
  3806. ;; the calendar. Org Agenda will list these entries itself.
  3807. (if org-disable-agenda-to-diary (setq files nil))
  3808. (while (setq file (pop files))
  3809. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3810. (setq results (append results rtn)))
  3811. (if results
  3812. (concat (org-finalize-agenda-entries results) "\n"))))
  3813. ;;; Agenda entry finders
  3814. (defun org-agenda-get-day-entries (file date &rest args)
  3815. "Does the work for `org-diary' and `org-agenda'.
  3816. FILE is the path to a file to be checked for entries. DATE is date like
  3817. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3818. which kind of entries should be extracted. For details about these, see
  3819. the documentation of `org-diary'."
  3820. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3821. (let* ((org-startup-folded nil)
  3822. (org-startup-align-all-tables nil)
  3823. (buffer (if (file-exists-p file)
  3824. (org-get-agenda-file-buffer file)
  3825. (error "No such file %s" file)))
  3826. arg results rtn deadline-results)
  3827. (if (not buffer)
  3828. ;; If file does not exist, make sure an error message ends up in diary
  3829. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3830. (with-current-buffer buffer
  3831. (unless (org-mode-p)
  3832. (error "Agenda file %s is not in `org-mode'" file))
  3833. (let ((case-fold-search nil))
  3834. (save-excursion
  3835. (save-restriction
  3836. (if org-agenda-restrict
  3837. (narrow-to-region org-agenda-restrict-begin
  3838. org-agenda-restrict-end)
  3839. (widen))
  3840. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3841. (while (setq arg (pop args))
  3842. (cond
  3843. ((and (eq arg :todo)
  3844. (equal date (calendar-current-date)))
  3845. (setq rtn (org-agenda-get-todos))
  3846. (setq results (append results rtn)))
  3847. ((eq arg :timestamp)
  3848. (setq rtn (org-agenda-get-blocks))
  3849. (setq results (append results rtn))
  3850. (setq rtn (org-agenda-get-timestamps))
  3851. (setq results (append results rtn)))
  3852. ((eq arg :sexp)
  3853. (setq rtn (org-agenda-get-sexps))
  3854. (setq results (append results rtn)))
  3855. ((eq arg :scheduled)
  3856. (setq rtn (org-agenda-get-scheduled deadline-results))
  3857. (setq results (append results rtn)))
  3858. ((eq arg :closed)
  3859. (setq rtn (org-agenda-get-progress))
  3860. (setq results (append results rtn)))
  3861. ((eq arg :deadline)
  3862. (setq rtn (org-agenda-get-deadlines))
  3863. (setq deadline-results (copy-sequence rtn))
  3864. (setq results (append results rtn))))))))
  3865. results))))
  3866. (defun org-agenda-get-todos ()
  3867. "Return the TODO information for agenda display."
  3868. (let* ((props (list 'face nil
  3869. 'done-face 'org-agenda-done
  3870. 'org-not-done-regexp org-not-done-regexp
  3871. 'org-todo-regexp org-todo-regexp
  3872. 'org-complex-heading-regexp org-complex-heading-regexp
  3873. 'mouse-face 'highlight
  3874. 'help-echo
  3875. (format "mouse-2 or RET jump to org file %s"
  3876. (abbreviate-file-name buffer-file-name))))
  3877. (regexp (concat "^\\*+[ \t]+\\("
  3878. (if org-select-this-todo-keyword
  3879. (if (equal org-select-this-todo-keyword "*")
  3880. org-todo-regexp
  3881. (concat "\\<\\("
  3882. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3883. "\\)\\>"))
  3884. org-not-done-regexp)
  3885. "[^\n\r]*\\)"))
  3886. marker priority category tags todo-state
  3887. ee txt beg end)
  3888. (goto-char (point-min))
  3889. (while (re-search-forward regexp nil t)
  3890. (catch :skip
  3891. (save-match-data
  3892. (beginning-of-line)
  3893. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3894. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3895. (goto-char (1+ beg))
  3896. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3897. (throw :skip nil)))
  3898. (goto-char beg)
  3899. (org-agenda-skip)
  3900. (goto-char (match-beginning 1))
  3901. (setq marker (org-agenda-new-marker (match-beginning 0))
  3902. category (org-get-category)
  3903. txt (match-string 1)
  3904. tags (org-get-tags-at (point))
  3905. txt (org-format-agenda-item "" txt category tags)
  3906. priority (1+ (org-get-priority txt))
  3907. todo-state (org-get-todo-state))
  3908. (org-add-props txt props
  3909. 'org-marker marker 'org-hd-marker marker
  3910. 'priority priority 'org-category category
  3911. 'type "todo" 'todo-state todo-state)
  3912. (push txt ee)
  3913. (if org-agenda-todo-list-sublevels
  3914. (goto-char (match-end 1))
  3915. (org-end-of-subtree 'invisible))))
  3916. (nreverse ee)))
  3917. ;;;###autoload
  3918. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3919. (&optional end)
  3920. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3921. (when (or org-agenda-todo-ignore-with-date
  3922. org-agenda-todo-ignore-scheduled
  3923. org-agenda-todo-ignore-deadlines)
  3924. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3925. (save-excursion
  3926. (or (and org-agenda-todo-ignore-with-date
  3927. (re-search-forward org-ts-regexp end t))
  3928. (and org-agenda-todo-ignore-scheduled
  3929. (re-search-forward org-scheduled-time-regexp end t)
  3930. (cond
  3931. ((eq org-agenda-todo-ignore-scheduled 'future)
  3932. (> (org-days-to-time (match-string 1)) 0))
  3933. ((eq org-agenda-todo-ignore-scheduled 'past)
  3934. (<= (org-days-to-time (match-string 1)) 0))
  3935. (t)))
  3936. (and org-agenda-todo-ignore-deadlines
  3937. (re-search-forward org-deadline-time-regexp end t)
  3938. (cond
  3939. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  3940. ((eq org-agenda-todo-ignore-deadlines 'far)
  3941. (not (org-deadline-close (match-string 1))))
  3942. ((eq org-agenda-todo-ignore-deadlines 'future)
  3943. (> (org-days-to-time (match-string 1)) 0))
  3944. ((eq org-agenda-todo-ignore-deadlines 'past)
  3945. (<= (org-days-to-time (match-string 1)) 0))
  3946. (t (org-deadline-close (match-string 1)))))))))
  3947. (defconst org-agenda-no-heading-message
  3948. "No heading for this item in buffer or region.")
  3949. (defun org-agenda-get-timestamps ()
  3950. "Return the date stamp information for agenda display."
  3951. (let* ((props (list 'face nil
  3952. 'org-not-done-regexp org-not-done-regexp
  3953. 'org-todo-regexp org-todo-regexp
  3954. 'org-complex-heading-regexp org-complex-heading-regexp
  3955. 'mouse-face 'highlight
  3956. 'help-echo
  3957. (format "mouse-2 or RET jump to org file %s"
  3958. (abbreviate-file-name buffer-file-name))))
  3959. (d1 (calendar-absolute-from-gregorian date))
  3960. (remove-re
  3961. (concat
  3962. (regexp-quote
  3963. (format-time-string
  3964. "<%Y-%m-%d"
  3965. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3966. ".*?>"))
  3967. (regexp
  3968. (concat
  3969. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3970. (regexp-quote
  3971. (substring
  3972. (format-time-string
  3973. (car org-time-stamp-formats)
  3974. (apply 'encode-time ; DATE bound by calendar
  3975. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3976. 1 11))
  3977. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3978. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3979. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3980. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3981. todo-state end-of-match)
  3982. (goto-char (point-min))
  3983. (while (setq end-of-match (re-search-forward regexp nil t))
  3984. (setq b0 (match-beginning 0)
  3985. b3 (match-beginning 3) e3 (match-end 3))
  3986. (catch :skip
  3987. (and (org-at-date-range-p) (throw :skip nil))
  3988. (org-agenda-skip)
  3989. (if (and (match-end 1)
  3990. (not (= d1 (org-time-string-to-absolute
  3991. (match-string 1) d1 nil
  3992. org-agenda-repeating-timestamp-show-all))))
  3993. (throw :skip nil))
  3994. (if (and e3
  3995. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3996. (throw :skip nil))
  3997. (setq tmp (buffer-substring (max (point-min)
  3998. (- b0 org-ds-keyword-length))
  3999. b0)
  4000. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4001. inactivep (= (char-after b0) ?\[)
  4002. deadlinep (string-match org-deadline-regexp tmp)
  4003. scheduledp (string-match org-scheduled-regexp tmp)
  4004. closedp (and org-agenda-include-inactive-timestamps
  4005. (string-match org-closed-string tmp))
  4006. clockp (and org-agenda-include-inactive-timestamps
  4007. (or (string-match org-clock-string tmp)
  4008. (string-match "]-+\\'" tmp)))
  4009. todo-state (org-get-todo-state)
  4010. donep (member todo-state org-done-keywords))
  4011. (if (or scheduledp deadlinep closedp clockp
  4012. (and donep org-agenda-skip-timestamp-if-done))
  4013. (throw :skip t))
  4014. (if (string-match ">" timestr)
  4015. ;; substring should only run to end of time stamp
  4016. (setq timestr (substring timestr 0 (match-end 0))))
  4017. (setq marker (org-agenda-new-marker b0)
  4018. category (org-get-category b0))
  4019. (save-excursion
  4020. (if (not (re-search-backward "^\\*+ " nil t))
  4021. (setq txt org-agenda-no-heading-message)
  4022. (goto-char (match-beginning 0))
  4023. (setq hdmarker (org-agenda-new-marker)
  4024. tags (org-get-tags-at))
  4025. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4026. (setq head (match-string 1))
  4027. (setq txt (org-format-agenda-item
  4028. (if inactivep org-agenda-inactive-leader nil)
  4029. head category tags timestr nil
  4030. remove-re)))
  4031. (setq priority (org-get-priority txt))
  4032. (org-add-props txt props
  4033. 'org-marker marker 'org-hd-marker hdmarker)
  4034. (org-add-props txt nil 'priority priority
  4035. 'org-category category 'date date
  4036. 'todo-state todo-state
  4037. 'type "timestamp")
  4038. (push txt ee))
  4039. (if org-agenda-skip-additional-timestamps-same-entry
  4040. (outline-next-heading)
  4041. (goto-char end-of-match))))
  4042. (nreverse ee)))
  4043. (defun org-agenda-get-sexps ()
  4044. "Return the sexp information for agenda display."
  4045. (require 'diary-lib)
  4046. (let* ((props (list 'face nil
  4047. 'mouse-face 'highlight
  4048. 'help-echo
  4049. (format "mouse-2 or RET jump to org file %s"
  4050. (abbreviate-file-name buffer-file-name))))
  4051. (regexp "^&?%%(")
  4052. marker category ee txt tags entry result beg b sexp sexp-entry
  4053. todo-state)
  4054. (goto-char (point-min))
  4055. (while (re-search-forward regexp nil t)
  4056. (catch :skip
  4057. (org-agenda-skip)
  4058. (setq beg (match-beginning 0))
  4059. (goto-char (1- (match-end 0)))
  4060. (setq b (point))
  4061. (forward-sexp 1)
  4062. (setq sexp (buffer-substring b (point)))
  4063. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4064. (org-trim (match-string 1))
  4065. ""))
  4066. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4067. (when result
  4068. (setq marker (org-agenda-new-marker beg)
  4069. category (org-get-category beg)
  4070. todo-state (org-get-todo-state))
  4071. (if (string-match "\\S-" result)
  4072. (setq txt result)
  4073. (setq txt "SEXP entry returned empty string"))
  4074. (setq txt (org-format-agenda-item
  4075. "" txt category tags 'time))
  4076. (org-add-props txt props 'org-marker marker)
  4077. (org-add-props txt nil
  4078. 'org-category category 'date date 'todo-state todo-state
  4079. 'type "sexp")
  4080. (push txt ee))))
  4081. (nreverse ee)))
  4082. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4083. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4084. The order of the first 2 times 3 arguments depends on the variable
  4085. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4086. So for american calendars, give this as MONTH DAY YEAR, for european as
  4087. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4088. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4089. is any number of ISO weeks in the block period for which the item should
  4090. be skipped."
  4091. (let* ((date1 (calendar-absolute-from-gregorian
  4092. (org-order-calendar-date-args m1 d1 y1)))
  4093. (date2 (calendar-absolute-from-gregorian
  4094. (org-order-calendar-date-args m2 d2 y2)))
  4095. (d (calendar-absolute-from-gregorian date)))
  4096. (and
  4097. (<= date1 d)
  4098. (<= d date2)
  4099. (= (calendar-day-of-week date) dayname)
  4100. (or (not skip-weeks)
  4101. (progn
  4102. (require 'cal-iso)
  4103. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4104. entry)))
  4105. (defalias 'org-get-closed 'org-agenda-get-progress)
  4106. (defun org-agenda-get-progress ()
  4107. "Return the logged TODO entries for agenda display."
  4108. (let* ((props (list 'mouse-face 'highlight
  4109. 'org-not-done-regexp org-not-done-regexp
  4110. 'org-todo-regexp org-todo-regexp
  4111. 'org-complex-heading-regexp org-complex-heading-regexp
  4112. 'help-echo
  4113. (format "mouse-2 or RET jump to org file %s"
  4114. (abbreviate-file-name buffer-file-name))))
  4115. (items (if (consp org-agenda-show-log)
  4116. org-agenda-show-log
  4117. org-agenda-log-mode-items))
  4118. (parts
  4119. (delq nil
  4120. (list
  4121. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4122. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4123. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4124. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4125. (error "`org-agenda-log-mode-items' is empty")))
  4126. (regexp (concat
  4127. "\\(" parts-re "\\)"
  4128. " *\\["
  4129. (regexp-quote
  4130. (substring
  4131. (format-time-string
  4132. (car org-time-stamp-formats)
  4133. (apply 'encode-time ; DATE bound by calendar
  4134. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4135. 1 11))))
  4136. (org-agenda-search-headline-for-time nil)
  4137. marker hdmarker priority category tags closedp statep clockp state
  4138. ee txt extra timestr rest clocked)
  4139. (goto-char (point-min))
  4140. (while (re-search-forward regexp nil t)
  4141. (catch :skip
  4142. (org-agenda-skip)
  4143. (setq marker (org-agenda-new-marker (match-beginning 0))
  4144. closedp (equal (match-string 1) org-closed-string)
  4145. statep (equal (string-to-char (match-string 1)) ?-)
  4146. clockp (not (or closedp statep))
  4147. state (and statep (match-string 2))
  4148. category (org-get-category (match-beginning 0))
  4149. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4150. )
  4151. (when (string-match "\\]" timestr)
  4152. ;; substring should only run to end of time stamp
  4153. (setq rest (substring timestr (match-end 0))
  4154. timestr (substring timestr 0 (match-end 0)))
  4155. (if (and (not closedp) (not statep)
  4156. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4157. (progn (setq timestr (concat (substring timestr 0 -1)
  4158. "-" (match-string 1 rest) "]"))
  4159. (setq clocked (match-string 2 rest)))
  4160. (setq clocked "-")))
  4161. (save-excursion
  4162. (cond
  4163. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  4164. (statep
  4165. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4166. (setq extra (match-string 1))))
  4167. (clockp
  4168. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4169. (setq extra (match-string 1))))
  4170. (t (setq extra nil)))
  4171. (if (not (re-search-backward "^\\*+ " nil t))
  4172. (setq txt org-agenda-no-heading-message)
  4173. (goto-char (match-beginning 0))
  4174. (setq hdmarker (org-agenda-new-marker)
  4175. tags (org-get-tags-at))
  4176. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4177. (setq txt (match-string 1))
  4178. (when extra
  4179. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4180. (setq txt (concat (substring txt 0 (match-beginning 1))
  4181. " - " extra " " (match-string 2 txt)))
  4182. (setq txt (concat txt " - " extra))))
  4183. (setq txt (org-format-agenda-item
  4184. (cond
  4185. (closedp "Closed: ")
  4186. (statep (concat "State: (" state ")"))
  4187. (t (concat "Clocked: (" clocked ")")))
  4188. txt category tags timestr)))
  4189. (setq priority 100000)
  4190. (org-add-props txt props
  4191. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4192. 'priority priority 'org-category category
  4193. 'type "closed" 'date date
  4194. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4195. (push txt ee))
  4196. (goto-char (point-at-eol))))
  4197. (nreverse ee)))
  4198. (defun org-agenda-get-deadlines ()
  4199. "Return the deadline information for agenda display."
  4200. (let* ((props (list 'mouse-face 'highlight
  4201. 'org-not-done-regexp org-not-done-regexp
  4202. 'org-todo-regexp org-todo-regexp
  4203. 'org-complex-heading-regexp org-complex-heading-regexp
  4204. 'help-echo
  4205. (format "mouse-2 or RET jump to org file %s"
  4206. (abbreviate-file-name buffer-file-name))))
  4207. (regexp org-deadline-time-regexp)
  4208. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4209. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4210. d2 diff dfrac wdays pos pos1 category tags
  4211. suppress-prewarning
  4212. ee txt head face s todo-state upcomingp donep timestr)
  4213. (goto-char (point-min))
  4214. (while (re-search-forward regexp nil t)
  4215. (setq suppress-prewarning nil)
  4216. (catch :skip
  4217. (org-agenda-skip)
  4218. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4219. (save-match-data
  4220. (string-match org-scheduled-time-regexp
  4221. (buffer-substring (point-at-bol)
  4222. (point-at-eol)))))
  4223. (setq suppress-prewarning
  4224. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4225. org-agenda-skip-deadline-prewarning-if-scheduled
  4226. 0)))
  4227. (setq s (match-string 1)
  4228. txt nil
  4229. pos (1- (match-beginning 1))
  4230. d2 (org-time-string-to-absolute
  4231. (match-string 1) d1 'past
  4232. org-agenda-repeating-timestamp-show-all)
  4233. diff (- d2 d1)
  4234. wdays (if suppress-prewarning
  4235. (let ((org-deadline-warning-days suppress-prewarning))
  4236. (org-get-wdays s))
  4237. (org-get-wdays s))
  4238. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4239. upcomingp (and todayp (> diff 0)))
  4240. ;; When to show a deadline in the calendar:
  4241. ;; If the expiration is within wdays warning time.
  4242. ;; Past-due deadlines are only shown on the current date
  4243. (if (and (or (and (<= diff wdays)
  4244. (and todayp (not org-agenda-only-exact-dates)))
  4245. (= diff 0)))
  4246. (save-excursion
  4247. (setq todo-state (org-get-todo-state))
  4248. (setq donep (member todo-state org-done-keywords))
  4249. (if (and donep
  4250. (or org-agenda-skip-deadline-if-done
  4251. (not (= diff 0))))
  4252. (setq txt nil)
  4253. (setq category (org-get-category))
  4254. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4255. (setq txt org-agenda-no-heading-message)
  4256. (goto-char (match-end 0))
  4257. (setq pos1 (match-beginning 0))
  4258. (setq tags (org-get-tags-at pos1))
  4259. (setq head (buffer-substring-no-properties
  4260. (point)
  4261. (progn (skip-chars-forward "^\r\n")
  4262. (point))))
  4263. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4264. (setq timestr
  4265. (concat (substring s (match-beginning 1)) " "))
  4266. (setq timestr 'time))
  4267. (setq txt (org-format-agenda-item
  4268. (if (= diff 0)
  4269. (car org-agenda-deadline-leaders)
  4270. (if (functionp
  4271. (nth 1 org-agenda-deadline-leaders))
  4272. (funcall
  4273. (nth 1 org-agenda-deadline-leaders)
  4274. diff date)
  4275. (format (nth 1 org-agenda-deadline-leaders)
  4276. diff)))
  4277. head category tags
  4278. (if (not (= diff 0)) nil timestr)))))
  4279. (when txt
  4280. (setq face (org-agenda-deadline-face dfrac wdays))
  4281. (org-add-props txt props
  4282. 'org-marker (org-agenda-new-marker pos)
  4283. 'org-hd-marker (org-agenda-new-marker pos1)
  4284. 'priority (+ (- diff)
  4285. (org-get-priority txt))
  4286. 'org-category category
  4287. 'todo-state todo-state
  4288. 'type (if upcomingp "upcoming-deadline" "deadline")
  4289. 'date (if upcomingp date d2)
  4290. 'face (if donep 'org-agenda-done face)
  4291. 'undone-face face 'done-face 'org-agenda-done)
  4292. (push txt ee))))))
  4293. (nreverse ee)))
  4294. (defun org-agenda-deadline-face (fraction &optional wdays)
  4295. "Return the face to displaying a deadline item.
  4296. FRACTION is what fraction of the head-warning time has passed."
  4297. (if (equal wdays 0) (setq fraction 1.))
  4298. (let ((faces org-agenda-deadline-faces) f)
  4299. (catch 'exit
  4300. (while (setq f (pop faces))
  4301. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4302. (defun org-agenda-get-scheduled (&optional deadline-results)
  4303. "Return the scheduled information for agenda display."
  4304. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4305. 'org-todo-regexp org-todo-regexp
  4306. 'org-complex-heading-regexp org-complex-heading-regexp
  4307. 'done-face 'org-agenda-done
  4308. 'mouse-face 'highlight
  4309. 'help-echo
  4310. (format "mouse-2 or RET jump to org file %s"
  4311. (abbreviate-file-name buffer-file-name))))
  4312. (regexp org-scheduled-time-regexp)
  4313. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4314. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4315. mm
  4316. (deadline-position-alist
  4317. (mapcar (lambda (a) (and (setq mm (get-text-property
  4318. 0 'org-hd-marker a))
  4319. (cons (marker-position mm) a)))
  4320. deadline-results))
  4321. d2 diff pos pos1 category tags donep
  4322. ee txt head pastschedp todo-state face timestr s habitp)
  4323. (goto-char (point-min))
  4324. (while (re-search-forward regexp nil t)
  4325. (catch :skip
  4326. (org-agenda-skip)
  4327. (setq s (match-string 1)
  4328. txt nil
  4329. pos (1- (match-beginning 1))
  4330. d2 (org-time-string-to-absolute
  4331. (match-string 1) d1 'past
  4332. org-agenda-repeating-timestamp-show-all)
  4333. diff (- d2 d1))
  4334. (setq pastschedp (and todayp (< diff 0)))
  4335. ;; When to show a scheduled item in the calendar:
  4336. ;; If it is on or past the date.
  4337. (when (or (and (< diff 0)
  4338. (< (abs diff) org-scheduled-past-days)
  4339. (and todayp (not org-agenda-only-exact-dates)))
  4340. (= diff 0))
  4341. (save-excursion
  4342. (setq todo-state (org-get-todo-state))
  4343. (setq donep (member todo-state org-done-keywords))
  4344. (setq habitp (and (functionp 'org-is-habit-p)
  4345. (org-is-habit-p)))
  4346. (if (and donep
  4347. (or habitp org-agenda-skip-scheduled-if-done
  4348. (not (= diff 0))))
  4349. (setq txt nil)
  4350. (setq category (org-get-category))
  4351. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4352. (setq txt org-agenda-no-heading-message)
  4353. (goto-char (match-end 0))
  4354. (setq pos1 (match-beginning 0))
  4355. (if habitp
  4356. (if (or (not org-habit-show-habits)
  4357. (and (not todayp)
  4358. org-habit-show-habits-only-for-today))
  4359. (throw :skip nil))
  4360. (if (and
  4361. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4362. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4363. pastschedp))
  4364. (setq mm (assoc pos1 deadline-position-alist)))
  4365. (throw :skip nil)))
  4366. (setq tags (org-get-tags-at))
  4367. (setq head (buffer-substring-no-properties
  4368. (point)
  4369. (progn (skip-chars-forward "^\r\n") (point))))
  4370. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4371. (setq timestr
  4372. (concat (substring s (match-beginning 1)) " "))
  4373. (setq timestr 'time))
  4374. (setq txt (org-format-agenda-item
  4375. (if (= diff 0)
  4376. (car org-agenda-scheduled-leaders)
  4377. (format (nth 1 org-agenda-scheduled-leaders)
  4378. (- 1 diff)))
  4379. head category tags
  4380. (if (not (= diff 0)) nil timestr)
  4381. nil nil habitp))))
  4382. (when txt
  4383. (setq face
  4384. (cond
  4385. ((and (not habitp) pastschedp)
  4386. 'org-scheduled-previously)
  4387. (todayp 'org-scheduled-today)
  4388. (t 'org-scheduled))
  4389. habitp (and habitp (org-habit-parse-todo)))
  4390. (org-add-props txt props
  4391. 'undone-face face
  4392. 'face (if donep 'org-agenda-done face)
  4393. 'org-marker (org-agenda-new-marker pos)
  4394. 'org-hd-marker (org-agenda-new-marker pos1)
  4395. 'type (if pastschedp "past-scheduled" "scheduled")
  4396. 'date (if pastschedp d2 date)
  4397. 'priority (if habitp
  4398. (org-habit-get-priority habitp)
  4399. (+ 94 (- 5 diff) (org-get-priority txt)))
  4400. 'org-category category
  4401. 'org-habit-p habitp
  4402. 'todo-state todo-state)
  4403. (push txt ee))))))
  4404. (nreverse ee)))
  4405. (defun org-agenda-get-blocks ()
  4406. "Return the date-range information for agenda display."
  4407. (let* ((props (list 'face nil
  4408. 'org-not-done-regexp org-not-done-regexp
  4409. 'org-todo-regexp org-todo-regexp
  4410. 'org-complex-heading-regexp org-complex-heading-regexp
  4411. 'mouse-face 'highlight
  4412. 'help-echo
  4413. (format "mouse-2 or RET jump to org file %s"
  4414. (abbreviate-file-name buffer-file-name))))
  4415. (regexp org-tr-regexp)
  4416. (d0 (calendar-absolute-from-gregorian date))
  4417. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4418. head donep)
  4419. (goto-char (point-min))
  4420. (while (re-search-forward regexp nil t)
  4421. (catch :skip
  4422. (org-agenda-skip)
  4423. (setq pos (point))
  4424. (setq timestr (match-string 0)
  4425. s1 (match-string 1)
  4426. s2 (match-string 2)
  4427. d1 (time-to-days (org-time-string-to-time s1))
  4428. d2 (time-to-days (org-time-string-to-time s2)))
  4429. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4430. ;; Only allow days between the limits, because the normal
  4431. ;; date stamps will catch the limits.
  4432. (save-excursion
  4433. (setq todo-state (org-get-todo-state))
  4434. (setq donep (member todo-state org-done-keywords))
  4435. (if (and donep org-agenda-skip-timestamp-if-done)
  4436. (throw :skip t))
  4437. (setq marker (org-agenda-new-marker (point)))
  4438. (setq category (org-get-category))
  4439. (if (not (re-search-backward "^\\*+ " nil t))
  4440. (setq txt org-agenda-no-heading-message)
  4441. (goto-char (match-beginning 0))
  4442. (setq hdmarker (org-agenda-new-marker (point)))
  4443. (setq tags (org-get-tags-at))
  4444. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4445. (setq head (match-string 1))
  4446. (setq txt (org-format-agenda-item
  4447. (format
  4448. (nth (if (= d1 d2) 0 1)
  4449. org-agenda-timerange-leaders)
  4450. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4451. head category tags
  4452. timestr)))
  4453. (org-add-props txt props
  4454. 'org-marker marker 'org-hd-marker hdmarker
  4455. 'type "block" 'date date
  4456. 'todo-state todo-state
  4457. 'priority (org-get-priority txt) 'org-category category)
  4458. (push txt ee)))
  4459. (goto-char pos)))
  4460. ;; Sort the entries by expiration date.
  4461. (nreverse ee)))
  4462. ;;; Agenda presentation and sorting
  4463. (defvar org-prefix-has-time nil
  4464. "A flag, set by `org-compile-prefix-format'.
  4465. The flag is set if the currently compiled format contains a `%t'.")
  4466. (defvar org-prefix-has-tag nil
  4467. "A flag, set by `org-compile-prefix-format'.
  4468. The flag is set if the currently compiled format contains a `%T'.")
  4469. (defvar org-prefix-has-effort nil
  4470. "A flag, set by `org-compile-prefix-format'.
  4471. The flag is set if the currently compiled format contains a `%e'.")
  4472. (defvar org-prefix-category-length nil
  4473. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4474. (defvar org-prefix-category-max-length nil
  4475. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4476. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4477. noprefix remove-re habitp)
  4478. "Format TXT to be inserted into the agenda buffer.
  4479. In particular, it adds the prefix and corresponding text properties. EXTRA
  4480. must be a string and replaces the `%s' specifier in the prefix format.
  4481. CATEGORY (string, symbol or nil) may be used to overrule the default
  4482. category taken from local variable or file name. It will replace the `%c'
  4483. specifier in the format. DOTIME, when non-nil, indicates that a
  4484. time-of-day should be extracted from TXT for sorting of this entry, and for
  4485. the `%t' specifier in the format. When DOTIME is a string, this string is
  4486. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4487. only the correctly processes TXT should be returned - this is used by
  4488. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4489. Any match of REMOVE-RE will be removed from TXT."
  4490. (save-match-data
  4491. ;; Diary entries sometimes have extra whitespace at the beginning
  4492. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4493. ;; Fix the tags part in txt
  4494. (setq txt (org-agenda-fix-displayed-tags
  4495. txt tags
  4496. org-agenda-show-inherited-tags
  4497. org-agenda-hide-tags-regexp))
  4498. (let* ((category (or category
  4499. org-category
  4500. (if buffer-file-name
  4501. (file-name-sans-extension
  4502. (file-name-nondirectory buffer-file-name))
  4503. "")))
  4504. ;; time, tag, effort are needed for the eval of the prefix format
  4505. (tag (if tags (nth (1- (length tags)) tags) ""))
  4506. time effort neffort
  4507. (ts (if dotime (concat
  4508. (if (stringp dotime) dotime "")
  4509. (and org-agenda-search-headline-for-time txt))))
  4510. (time-of-day (and dotime (org-get-time-of-day ts)))
  4511. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4512. duration thecategory)
  4513. (and (org-mode-p) buffer-file-name
  4514. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4515. (when (and dotime time-of-day)
  4516. ;; Extract starting and ending time and move them to prefix
  4517. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4518. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4519. (setq s0 (match-string 0 ts)
  4520. srp (and stamp (match-end 3))
  4521. s1 (match-string (if plain 1 2) ts)
  4522. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4523. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4524. ;; them, we might want to remove them there to avoid duplication.
  4525. ;; The user can turn this off with a variable.
  4526. (if (and org-prefix-has-time
  4527. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4528. (string-match (concat (regexp-quote s0) " *") txt)
  4529. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4530. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4531. (= (match-beginning 0) 0)
  4532. t))
  4533. (setq txt (replace-match "" nil nil txt))))
  4534. ;; Normalize the time(s) to 24 hour
  4535. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4536. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4537. ;; Compute the duration
  4538. (when s1
  4539. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4540. (string-to-number (substring s1 3)))
  4541. t2 (cond
  4542. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4543. (string-to-number (substring s2 3))))
  4544. (org-agenda-default-appointment-duration
  4545. (+ t1 org-agenda-default-appointment-duration))
  4546. (t nil)))
  4547. (setq duration (if t2 (- t2 t1)))))
  4548. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4549. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4550. (let ((m (+ (string-to-number (match-string 2 s1))
  4551. (* 60 (string-to-number (match-string 1 s1)))
  4552. org-agenda-default-appointment-duration))
  4553. h)
  4554. (setq h (/ m 60) m (- m (* h 60)))
  4555. (setq s2 (format "%02d:%02d" h m))))
  4556. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4557. txt)
  4558. ;; Tags are in the string
  4559. (if (or (eq org-agenda-remove-tags t)
  4560. (and org-agenda-remove-tags
  4561. org-prefix-has-tag))
  4562. (setq txt (replace-match "" t t txt))
  4563. (setq txt (replace-match
  4564. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4565. (match-string 2 txt))
  4566. t t txt))))
  4567. (when (org-mode-p)
  4568. (setq effort
  4569. (condition-case nil
  4570. (org-get-effort
  4571. (or (get-text-property 0 'org-hd-marker txt)
  4572. (get-text-property 0 'org-marker txt)))
  4573. (error nil)))
  4574. (when effort
  4575. (setq neffort (org-hh:mm-string-to-minutes effort)
  4576. effort (setq effort (concat "[" effort "]" )))))
  4577. (when remove-re
  4578. (while (string-match remove-re txt)
  4579. (setq txt (replace-match "" t t txt))))
  4580. ;; Create the final string
  4581. (if noprefix
  4582. (setq rtn txt)
  4583. ;; Prepare the variables needed in the eval of the compiled format
  4584. (setq time (cond (s2 (concat s1 "-" s2))
  4585. (s1 (concat s1 "......"))
  4586. (t ""))
  4587. extra (or (and (not habitp) extra) "")
  4588. category (if (symbolp category) (symbol-name category) category)
  4589. thecategory (copy-sequence category))
  4590. (if (string-match org-bracket-link-regexp category)
  4591. (progn
  4592. (setq l (if (match-end 3)
  4593. (- (match-end 3) (match-beginning 3))
  4594. (- (match-end 1) (match-beginning 1))))
  4595. (when (< l (or org-prefix-category-length 0))
  4596. (setq category (copy-sequence category))
  4597. (org-add-props category nil
  4598. 'extra-space (make-string
  4599. (- org-prefix-category-length l 1) ?\ ))))
  4600. (if (and org-prefix-category-max-length
  4601. (>= (length category) org-prefix-category-max-length))
  4602. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4603. ;; Evaluate the compiled format
  4604. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4605. ;; And finally add the text properties
  4606. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4607. (org-add-props rtn nil
  4608. 'org-category (if thecategory (downcase thecategory) category)
  4609. 'tags (mapcar 'org-downcase-keep-props tags)
  4610. 'org-highest-priority org-highest-priority
  4611. 'org-lowest-priority org-lowest-priority
  4612. 'prefix-length (- (length rtn) (length txt))
  4613. 'time-of-day time-of-day
  4614. 'duration duration
  4615. 'effort effort
  4616. 'effort-minutes neffort
  4617. 'txt txt
  4618. 'time time
  4619. 'extra extra
  4620. 'dotime dotime))))
  4621. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4622. "Remove tags string from TXT, and add a modified list of tags.
  4623. The modified list may contain inherited tags, and tags matched by
  4624. `org-agenda-hide-tags-regexp' will be removed."
  4625. (when (or add-inherited hide-re)
  4626. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4627. (setq txt (substring txt 0 (match-beginning 0))))
  4628. (setq tags
  4629. (delq nil
  4630. (mapcar (lambda (tg)
  4631. (if (or (and hide-re (string-match hide-re tg))
  4632. (and (not add-inherited)
  4633. (get-text-property 0 'inherited tg)))
  4634. nil
  4635. tg))
  4636. tags)))
  4637. (when tags
  4638. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4639. i)
  4640. (setq txt (concat txt " :"
  4641. (mapconcat
  4642. (lambda (x)
  4643. (setq i (get-text-property 0 'inherited x))
  4644. (if (and have-i (not i))
  4645. (progn
  4646. (setq have-i nil)
  4647. (concat ":" x))
  4648. x))
  4649. tags ":")
  4650. (if have-i "::" ":"))))))
  4651. txt)
  4652. (defun org-downcase-keep-props (s)
  4653. (let ((props (text-properties-at 0 s)))
  4654. (setq s (downcase s))
  4655. (add-text-properties 0 (length s) props s)
  4656. s))
  4657. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4658. (defvar org-agenda-sorting-strategy-selected nil)
  4659. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4660. (catch 'exit
  4661. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4662. ((and todayp (member 'today (car org-agenda-time-grid))))
  4663. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4664. ((member 'weekly (car org-agenda-time-grid)))
  4665. (t (throw 'exit list)))
  4666. (let* ((have (delq nil (mapcar
  4667. (lambda (x) (get-text-property 1 'time-of-day x))
  4668. list)))
  4669. (string (nth 1 org-agenda-time-grid))
  4670. (gridtimes (nth 2 org-agenda-time-grid))
  4671. (req (car org-agenda-time-grid))
  4672. (remove (member 'remove-match req))
  4673. new time)
  4674. (if (and (member 'require-timed req) (not have))
  4675. ;; don't show empty grid
  4676. (throw 'exit list))
  4677. (while (setq time (pop gridtimes))
  4678. (unless (and remove (member time have))
  4679. (setq time (int-to-string time))
  4680. (push (org-format-agenda-item
  4681. nil string "" nil
  4682. (concat (substring time 0 -2) ":" (substring time -2)))
  4683. new)
  4684. (put-text-property
  4685. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4686. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4687. (append new list)
  4688. (append list new)))))
  4689. (defun org-compile-prefix-format (key)
  4690. "Compile the prefix format into a Lisp form that can be evaluated.
  4691. The resulting form is returned and stored in the variable
  4692. `org-prefix-format-compiled'."
  4693. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4694. org-prefix-category-length nil org-prefix-has-effort nil)
  4695. (let ((s (cond
  4696. ((stringp org-agenda-prefix-format)
  4697. org-agenda-prefix-format)
  4698. ((assq key org-agenda-prefix-format)
  4699. (cdr (assq key org-agenda-prefix-format)))
  4700. (t " %-12:c%?-12t% s")))
  4701. (start 0)
  4702. varform vars var e c f opt)
  4703. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4704. s start)
  4705. (setq var (cdr (assoc (match-string 4 s)
  4706. '(("c" . category) ("t" . time) ("s" . extra)
  4707. ("T" . tag) ("e" . effort))))
  4708. c (or (match-string 3 s) "")
  4709. opt (match-beginning 1)
  4710. start (1+ (match-beginning 0)))
  4711. (if (equal var 'time) (setq org-prefix-has-time t))
  4712. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4713. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4714. (setq f (concat "%" (match-string 2 s) "s"))
  4715. (when (equal var 'category)
  4716. (setq org-prefix-category-length
  4717. (floor (abs (string-to-number (match-string 2 s)))))
  4718. (setq org-prefix-category-max-length
  4719. (let ((x (match-string 2 s)))
  4720. (save-match-data
  4721. (if (string-match "\\.[0-9]+" x)
  4722. (string-to-number (substring (match-string 0 x) 1)))))))
  4723. (if opt
  4724. (setq varform
  4725. `(if (equal "" ,var)
  4726. ""
  4727. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4728. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4729. (setq s (replace-match "%s" t nil s))
  4730. (push varform vars))
  4731. (setq vars (nreverse vars))
  4732. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4733. (defun org-set-sorting-strategy (key)
  4734. (if (symbolp (car org-agenda-sorting-strategy))
  4735. ;; the old format
  4736. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4737. (setq org-agenda-sorting-strategy-selected
  4738. (or (cdr (assq key org-agenda-sorting-strategy))
  4739. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4740. '(time-up category-keep priority-down)))))
  4741. (defun org-get-time-of-day (s &optional string mod24)
  4742. "Check string S for a time of day.
  4743. If found, return it as a military time number between 0 and 2400.
  4744. If not found, return nil.
  4745. The optional STRING argument forces conversion into a 5 character wide string
  4746. HH:MM."
  4747. (save-match-data
  4748. (when
  4749. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4750. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4751. (let* ((h (string-to-number (match-string 1 s)))
  4752. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4753. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4754. (am-p (equal ampm "am"))
  4755. (h1 (cond ((not ampm) h)
  4756. ((= h 12) (if am-p 0 12))
  4757. (t (+ h (if am-p 0 12)))))
  4758. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4759. (mod h1 24) h1))
  4760. (t0 (+ (* 100 h2) m))
  4761. (t1 (concat (if (>= h1 24) "+" " ")
  4762. (if (and org-agenda-time-leading-zero
  4763. (< t0 1000)) "0" "")
  4764. (if (< t0 100) "0" "")
  4765. (if (< t0 10) "0" "")
  4766. (int-to-string t0))))
  4767. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4768. (defun org-finalize-agenda-entries (list &optional nosort)
  4769. "Sort and concatenate the agenda items."
  4770. (setq list (mapcar 'org-agenda-highlight-todo list))
  4771. (if nosort
  4772. list
  4773. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4774. (defun org-agenda-highlight-todo (x)
  4775. (let ((org-done-keywords org-done-keywords-for-agenda)
  4776. (case-fold-search nil)
  4777. re pl)
  4778. (if (eq x 'line)
  4779. (save-excursion
  4780. (beginning-of-line 1)
  4781. (setq re (org-get-at-bol 'org-todo-regexp))
  4782. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4783. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4784. (add-text-properties (match-beginning 0) (match-end 1)
  4785. (list 'face (org-get-todo-face 1)))
  4786. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4787. (delete-region (match-beginning 1) (1- (match-end 0)))
  4788. (goto-char (match-beginning 1))
  4789. (insert (format org-agenda-todo-keyword-format s)))))
  4790. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4791. pl (get-text-property 0 'prefix-length x))
  4792. (when (and re
  4793. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4794. x (or pl 0)) pl))
  4795. (add-text-properties
  4796. (or (match-end 1) (match-end 0)) (match-end 0)
  4797. (list 'face (org-get-todo-face (match-string 2 x)))
  4798. x)
  4799. (setq x (concat (substring x 0 (match-end 1))
  4800. (format org-agenda-todo-keyword-format
  4801. (match-string 2 x))
  4802. (org-add-props " " (text-properties-at 0 x))
  4803. (substring x (match-end 3)))))
  4804. x)))
  4805. (defsubst org-cmp-priority (a b)
  4806. "Compare the priorities of string A and B."
  4807. (let ((pa (or (get-text-property 1 'priority a) 0))
  4808. (pb (or (get-text-property 1 'priority b) 0)))
  4809. (cond ((> pa pb) +1)
  4810. ((< pa pb) -1)
  4811. (t nil))))
  4812. (defsubst org-cmp-effort (a b)
  4813. "Compare the priorities of string A and B."
  4814. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4815. (ea (or (get-text-property 1 'effort-minutes a) def))
  4816. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4817. (cond ((> ea eb) +1)
  4818. ((< ea eb) -1)
  4819. (t nil))))
  4820. (defsubst org-cmp-category (a b)
  4821. "Compare the string values of categories of strings A and B."
  4822. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4823. (cb (or (get-text-property 1 'org-category b) "")))
  4824. (cond ((string-lessp ca cb) -1)
  4825. ((string-lessp cb ca) +1)
  4826. (t nil))))
  4827. (defsubst org-cmp-todo-state (a b)
  4828. "Compare the todo states of strings A and B."
  4829. (let* ((ma (or (get-text-property 1 'org-marker a)
  4830. (get-text-property 1 'org-hd-marker a)))
  4831. (mb (or (get-text-property 1 'org-marker b)
  4832. (get-text-property 1 'org-hd-marker b)))
  4833. (fa (and ma (marker-buffer ma)))
  4834. (fb (and mb (marker-buffer mb)))
  4835. (todo-kwds
  4836. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4837. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4838. (ta (or (get-text-property 1 'todo-state a) ""))
  4839. (tb (or (get-text-property 1 'todo-state b) ""))
  4840. (la (- (length (member ta todo-kwds))))
  4841. (lb (- (length (member tb todo-kwds))))
  4842. (donepa (member ta org-done-keywords-for-agenda))
  4843. (donepb (member tb org-done-keywords-for-agenda)))
  4844. (cond ((and donepa (not donepb)) -1)
  4845. ((and (not donepa) donepb) +1)
  4846. ((< la lb) -1)
  4847. ((< lb la) +1)
  4848. (t nil))))
  4849. (defsubst org-cmp-tag (a b)
  4850. "Compare the string values of the first tags of A and B."
  4851. (let ((ta (car (last (get-text-property 1 'tags a))))
  4852. (tb (car (last (get-text-property 1 'tags b)))))
  4853. (cond ((not ta) +1)
  4854. ((not tb) -1)
  4855. ((string-lessp ta tb) -1)
  4856. ((string-lessp tb ta) +1)
  4857. (t nil))))
  4858. (defsubst org-cmp-time (a b)
  4859. "Compare the time-of-day values of strings A and B."
  4860. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4861. (ta (or (get-text-property 1 'time-of-day a) def))
  4862. (tb (or (get-text-property 1 'time-of-day b) def)))
  4863. (cond ((< ta tb) -1)
  4864. ((< tb ta) +1)
  4865. (t nil))))
  4866. (defsubst org-cmp-habit-p (a b)
  4867. "Compare the todo states of strings A and B."
  4868. (let ((ha (get-text-property 1 'org-habit-p a))
  4869. (hb (get-text-property 1 'org-habit-p b)))
  4870. (cond ((and ha (not hb)) -1)
  4871. ((and (not ha) hb) +1)
  4872. (t nil))))
  4873. (defun org-entries-lessp (a b)
  4874. "Predicate for sorting agenda entries."
  4875. ;; The following variables will be used when the form is evaluated.
  4876. ;; So even though the compiler complains, keep them.
  4877. (let* ((time-up (org-cmp-time a b))
  4878. (time-down (if time-up (- time-up) nil))
  4879. (priority-up (org-cmp-priority a b))
  4880. (priority-down (if priority-up (- priority-up) nil))
  4881. (effort-up (org-cmp-effort a b))
  4882. (effort-down (if effort-up (- effort-up) nil))
  4883. (category-up (org-cmp-category a b))
  4884. (category-down (if category-up (- category-up) nil))
  4885. (category-keep (if category-up +1 nil))
  4886. (tag-up (org-cmp-tag a b))
  4887. (tag-down (if tag-up (- tag-up) nil))
  4888. (todo-state-up (org-cmp-todo-state a b))
  4889. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4890. (habit-up (org-cmp-habit-p a b))
  4891. (habit-down (if habit-up (- habit-up) nil))
  4892. user-defined-up user-defined-down)
  4893. (if (and org-agenda-cmp-user-defined
  4894. (functionp org-agenda-cmp-user-defined))
  4895. (setq user-defined-up
  4896. (funcall org-agenda-cmp-user-defined a b)
  4897. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4898. (cdr (assoc
  4899. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4900. '((-1 . t) (1 . nil) (nil . nil))))))
  4901. ;;; Agenda restriction lock
  4902. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  4903. "Overlay to mark the headline to which agenda commands are restricted.")
  4904. (overlay-put org-agenda-restriction-lock-overlay
  4905. 'face 'org-agenda-restriction-lock)
  4906. (overlay-put org-agenda-restriction-lock-overlay
  4907. 'help-echo "Agendas are currently limited to this subtree.")
  4908. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4909. (defun org-agenda-set-restriction-lock (&optional type)
  4910. "Set restriction lock for agenda, to current subtree or file.
  4911. Restriction will be the file if TYPE is `file', or if type is the
  4912. universal prefix '(4), or if the cursor is before the first headline
  4913. in the file. Otherwise, restriction will be to the current subtree."
  4914. (interactive "P")
  4915. (and (equal type '(4)) (setq type 'file))
  4916. (setq type (cond
  4917. (type type)
  4918. ((org-at-heading-p) 'subtree)
  4919. ((condition-case nil (org-back-to-heading t) (error nil))
  4920. 'subtree)
  4921. (t 'file)))
  4922. (if (eq type 'subtree)
  4923. (progn
  4924. (setq org-agenda-restrict t)
  4925. (setq org-agenda-overriding-restriction 'subtree)
  4926. (put 'org-agenda-files 'org-restrict
  4927. (list (buffer-file-name (buffer-base-buffer))))
  4928. (org-back-to-heading t)
  4929. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4930. (move-marker org-agenda-restrict-begin (point))
  4931. (move-marker org-agenda-restrict-end
  4932. (save-excursion (org-end-of-subtree t)))
  4933. (message "Locking agenda restriction to subtree"))
  4934. (put 'org-agenda-files 'org-restrict
  4935. (list (buffer-file-name (buffer-base-buffer))))
  4936. (setq org-agenda-restrict nil)
  4937. (setq org-agenda-overriding-restriction 'file)
  4938. (move-marker org-agenda-restrict-begin nil)
  4939. (move-marker org-agenda-restrict-end nil)
  4940. (message "Locking agenda restriction to file"))
  4941. (setq current-prefix-arg nil)
  4942. (org-agenda-maybe-redo))
  4943. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4944. "Remove the agenda restriction lock."
  4945. (interactive "P")
  4946. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4947. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4948. (setq org-agenda-overriding-restriction nil)
  4949. (setq org-agenda-restrict nil)
  4950. (put 'org-agenda-files 'org-restrict nil)
  4951. (move-marker org-agenda-restrict-begin nil)
  4952. (move-marker org-agenda-restrict-end nil)
  4953. (setq current-prefix-arg nil)
  4954. (message "Agenda restriction lock removed")
  4955. (or noupdate (org-agenda-maybe-redo)))
  4956. (defun org-agenda-maybe-redo ()
  4957. "If there is any window showing the agenda view, update it."
  4958. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4959. (w0 (selected-window)))
  4960. (when w
  4961. (select-window w)
  4962. (org-agenda-redo)
  4963. (select-window w0)
  4964. (if org-agenda-overriding-restriction
  4965. (message "Agenda view shifted to new %s restriction"
  4966. org-agenda-overriding-restriction)
  4967. (message "Agenda restriction lock removed")))))
  4968. ;;; Agenda commands
  4969. (defun org-agenda-check-type (error &rest types)
  4970. "Check if agenda buffer is of allowed type.
  4971. If ERROR is non-nil, throw an error, otherwise just return nil."
  4972. (if (memq org-agenda-type types)
  4973. t
  4974. (if error
  4975. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4976. nil)))
  4977. (defun org-agenda-quit ()
  4978. "Exit agenda by removing the window or the buffer."
  4979. (interactive)
  4980. (if org-agenda-columns-active
  4981. (org-columns-quit)
  4982. (let ((buf (current-buffer)))
  4983. (if (eq org-agenda-window-setup 'other-frame)
  4984. (progn
  4985. (kill-buffer buf)
  4986. (org-agenda-reset-markers)
  4987. (org-columns-remove-overlays)
  4988. (setq org-agenda-archives-mode nil)
  4989. (delete-frame))
  4990. (and (not (eq org-agenda-window-setup 'current-window))
  4991. (not (one-window-p))
  4992. (delete-window))
  4993. (kill-buffer buf)
  4994. (org-agenda-reset-markers)
  4995. (org-columns-remove-overlays)
  4996. (setq org-agenda-archives-mode nil)))
  4997. ;; Maybe restore the pre-agenda window configuration.
  4998. (and org-agenda-restore-windows-after-quit
  4999. (not (eq org-agenda-window-setup 'other-frame))
  5000. org-pre-agenda-window-conf
  5001. (set-window-configuration org-pre-agenda-window-conf))))
  5002. (defun org-agenda-exit ()
  5003. "Exit agenda by removing the window or the buffer.
  5004. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5005. Org-mode buffers visited directly by the user will not be touched."
  5006. (interactive)
  5007. (org-release-buffers org-agenda-new-buffers)
  5008. (setq org-agenda-new-buffers nil)
  5009. (org-agenda-quit))
  5010. (defun org-agenda-execute (arg)
  5011. "Execute another agenda command, keeping same window.\\<global-map>
  5012. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  5013. (interactive "P")
  5014. (let ((org-agenda-window-setup 'current-window))
  5015. (org-agenda arg)))
  5016. (defun org-agenda-redo ()
  5017. "Rebuild Agenda.
  5018. When this is the global TODO list, a prefix argument will be interpreted."
  5019. (interactive)
  5020. (let* ((org-agenda-keep-modes t)
  5021. (filter org-agenda-filter)
  5022. (preset (get 'org-agenda-filter :preset-filter))
  5023. (cols org-agenda-columns-active)
  5024. (line (org-current-line))
  5025. (window-line (- line (org-current-line (window-start))))
  5026. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5027. (put 'org-agenda-filter :preset-filter nil)
  5028. (and cols (org-columns-quit))
  5029. (message "Rebuilding agenda buffer...")
  5030. (org-let lprops '(eval org-agenda-redo-command))
  5031. (setq org-agenda-undo-list nil
  5032. org-agenda-pending-undo-list nil)
  5033. (message "Rebuilding agenda buffer...done")
  5034. (put 'org-agenda-filter :preset-filter preset)
  5035. (and (or filter preset) (org-agenda-filter-apply filter))
  5036. (and cols (interactive-p) (org-agenda-columns))
  5037. (org-goto-line line)
  5038. (recenter window-line)))
  5039. (defvar org-global-tags-completion-table nil)
  5040. (defvar org-agenda-filter-form nil)
  5041. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5042. "Keep only those lines in the agenda buffer that have a specific tag.
  5043. The tag is selected with its fast selection letter, as configured.
  5044. With prefix argument STRIP, remove all lines that do have the tag.
  5045. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5046. used to narrow the search - the interactive user can also press `-' or `+'
  5047. to switch to narrowing."
  5048. (interactive "P")
  5049. (let* ((alist org-tag-alist-for-agenda)
  5050. (tag-chars (mapconcat
  5051. (lambda (x) (if (and (not (symbolp (car x)))
  5052. (cdr x))
  5053. (char-to-string (cdr x))
  5054. ""))
  5055. alist ""))
  5056. (efforts (org-split-string
  5057. (or (cdr (assoc (concat org-effort-property "_ALL")
  5058. org-global-properties))
  5059. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5060. (effort-op org-agenda-filter-effort-default-operator)
  5061. (effort-prompt "")
  5062. (inhibit-read-only t)
  5063. (current org-agenda-filter)
  5064. a n tag)
  5065. (unless char
  5066. (message
  5067. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5068. (if narrow "Narrow" "Filter") tag-chars
  5069. (if org-agenda-auto-exclude-function "[RET], " ""))
  5070. (setq char (read-char)))
  5071. (when (member char '(?+ ?-))
  5072. ;; Narrowing down
  5073. (cond ((equal char ?-) (setq strip t narrow t))
  5074. ((equal char ?+) (setq strip nil narrow t)))
  5075. (message
  5076. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5077. (setq char (read-char)))
  5078. (when (member char '(?< ?> ?= ??))
  5079. ;; An effort operator
  5080. (setq effort-op (char-to-string char))
  5081. (setq alist nil) ; to make sure it will be interpreted as effort.
  5082. (unless (equal char ??)
  5083. (loop for i from 0 to 9 do
  5084. (setq effort-prompt
  5085. (concat
  5086. effort-prompt " ["
  5087. (if (= i 9) "0" (int-to-string (1+ i)))
  5088. "]" (nth i efforts))))
  5089. (message "Effort%s: %s " effort-op effort-prompt)
  5090. (setq char (read-char))
  5091. (when (or (< char ?0) (> char ?9))
  5092. (error "Need 1-9,0 to select effort" ))))
  5093. (when (equal char ?\t)
  5094. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5095. (org-set-local 'org-global-tags-completion-table
  5096. (org-global-tags-completion-table)))
  5097. (let ((completion-ignore-case t))
  5098. (setq tag (org-icompleting-read
  5099. "Tag: " org-global-tags-completion-table))))
  5100. (cond
  5101. ((equal char ?\r)
  5102. (org-agenda-filter-by-tag-show-all)
  5103. (when org-agenda-auto-exclude-function
  5104. (setq org-agenda-filter '())
  5105. (dolist (tag (org-agenda-get-represented-tags))
  5106. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5107. (if modifier
  5108. (push modifier org-agenda-filter))))
  5109. (if (not (null org-agenda-filter))
  5110. (org-agenda-filter-apply org-agenda-filter))))
  5111. ((equal char ?/)
  5112. (org-agenda-filter-by-tag-show-all)
  5113. (when (get 'org-agenda-filter :preset-filter)
  5114. (org-agenda-filter-apply org-agenda-filter)))
  5115. ((or (equal char ?\ )
  5116. (setq a (rassoc char alist))
  5117. (and (>= char ?0) (<= char ?9)
  5118. (setq n (if (= char ?0) 9 (- char ?0 1))
  5119. tag (concat effort-op (nth n efforts))
  5120. a (cons tag nil)))
  5121. (and (= char ??)
  5122. (setq tag "?eff")
  5123. a (cons tag nil))
  5124. (and tag (setq a (cons tag nil))))
  5125. (org-agenda-filter-by-tag-show-all)
  5126. (setq tag (car a))
  5127. (setq org-agenda-filter
  5128. (cons (concat (if strip "-" "+") tag)
  5129. (if narrow current nil)))
  5130. (org-agenda-filter-apply org-agenda-filter))
  5131. (t (error "Invalid tag selection character %c" char)))))
  5132. (defun org-agenda-get-represented-tags ()
  5133. "Get a list of all tags currently represented in the agenda."
  5134. (let (p tags)
  5135. (save-excursion
  5136. (goto-char (point-min))
  5137. (while (setq p (next-single-property-change (point) 'tags))
  5138. (goto-char p)
  5139. (mapc (lambda (x) (add-to-list 'tags x))
  5140. (get-text-property (point) 'tags))))
  5141. tags))
  5142. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5143. "Refine the current filter. See `org-agenda-filter-by-tag."
  5144. (interactive "P")
  5145. (org-agenda-filter-by-tag strip char 'refine))
  5146. (defun org-agenda-filter-make-matcher ()
  5147. "Create the form that tests a line for the agenda filter."
  5148. (let (f f1)
  5149. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5150. org-agenda-filter))
  5151. (if (member x '("-" "+"))
  5152. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5153. (if (string-match "[<=>?]" x)
  5154. (setq f1 (org-agenda-filter-effort-form x))
  5155. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5156. (if (equal (string-to-char x) ?-)
  5157. (setq f1 (list 'not f1))))
  5158. (push f1 f))
  5159. (cons 'and (nreverse f))))
  5160. (defun org-agenda-filter-effort-form (e)
  5161. "Return the form to compare the effort of the current line with what E says.
  5162. E looks line \"+<2:25\"."
  5163. (let (op)
  5164. (setq e (substring e 1))
  5165. (setq op (string-to-char e) e (substring e 1))
  5166. (setq op (cond ((equal op ?<) '<=)
  5167. ((equal op ?>) '>=)
  5168. ((equal op ??) op)
  5169. (t '=)))
  5170. (list 'org-agenda-compare-effort (list 'quote op)
  5171. (org-hh:mm-string-to-minutes e))))
  5172. (defun org-agenda-compare-effort (op value)
  5173. "Compare the effort of the current line with VALUE, using OP.
  5174. If the line does not have an effort defined, return nil."
  5175. (let ((eff (org-get-at-bol 'effort-minutes)))
  5176. (if (equal op ??)
  5177. (not eff)
  5178. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5179. value))))
  5180. (defun org-agenda-filter-apply (filter)
  5181. "Set FILTER as the new agenda filter and apply it."
  5182. (let (tags)
  5183. (setq org-agenda-filter filter
  5184. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5185. (org-agenda-set-mode-name)
  5186. (save-excursion
  5187. (goto-char (point-min))
  5188. (while (not (eobp))
  5189. (if (org-get-at-bol 'org-marker)
  5190. (progn
  5191. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5192. (if (not (eval org-agenda-filter-form))
  5193. (org-agenda-filter-by-tag-hide-line))
  5194. (beginning-of-line 2))
  5195. (beginning-of-line 2))))))
  5196. (defun org-agenda-filter-by-tag-hide-line ()
  5197. (let (ov)
  5198. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5199. (point-at-eol)))
  5200. (overlay-put ov 'invisible t)
  5201. (overlay-put ov 'type 'tags-filter)
  5202. (push ov org-agenda-filter-overlays)))
  5203. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5204. (setq pos (or pos (point)))
  5205. (save-excursion
  5206. (dolist (ov (overlays-at pos))
  5207. (when (and (overlay-get ov 'invisible)
  5208. (eq (overlay-get ov 'type) 'tags-filter))
  5209. (goto-char pos)
  5210. (if (< (overlay-start ov) (point-at-eol))
  5211. (move-overlay ov (point-at-eol)
  5212. (overlay-end ov)))))))
  5213. (defun org-agenda-filter-by-tag-show-all ()
  5214. (mapc 'delete-overlay org-agenda-filter-overlays)
  5215. (setq org-agenda-filter-overlays nil)
  5216. (setq org-agenda-filter nil)
  5217. (setq org-agenda-filter-form nil)
  5218. (org-agenda-set-mode-name))
  5219. (defun org-agenda-manipulate-query-add ()
  5220. "Manipulate the query by adding a search term with positive selection.
  5221. Positive selection means the term must be matched for selection of an entry."
  5222. (interactive)
  5223. (org-agenda-manipulate-query ?\[))
  5224. (defun org-agenda-manipulate-query-subtract ()
  5225. "Manipulate the query by adding a search term with negative selection.
  5226. Negative selection means term must not be matched for selection of an entry."
  5227. (interactive)
  5228. (org-agenda-manipulate-query ?\]))
  5229. (defun org-agenda-manipulate-query-add-re ()
  5230. "Manipulate the query by adding a search regexp with positive selection.
  5231. Positive selection means the regexp must match for selection of an entry."
  5232. (interactive)
  5233. (org-agenda-manipulate-query ?\{))
  5234. (defun org-agenda-manipulate-query-subtract-re ()
  5235. "Manipulate the query by adding a search regexp with negative selection.
  5236. Negative selection means regexp must not match for selection of an entry."
  5237. (interactive)
  5238. (org-agenda-manipulate-query ?\}))
  5239. (defun org-agenda-manipulate-query (char)
  5240. (cond
  5241. ((memq org-agenda-type '(timeline agenda))
  5242. (let ((org-agenda-include-inactive-timestamps t))
  5243. (org-agenda-redo))
  5244. (message "Display now includes inactive timestamps as well"))
  5245. ((eq org-agenda-type 'search)
  5246. (org-add-to-string
  5247. 'org-agenda-query-string
  5248. (if org-agenda-last-search-view-search-was-boolean
  5249. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5250. (?\{ . " +{}") (?\} . " -{}"))))
  5251. " "))
  5252. (setq org-agenda-redo-command
  5253. (list 'org-search-view
  5254. org-todo-only
  5255. org-agenda-query-string
  5256. (+ (length org-agenda-query-string)
  5257. (if (member char '(?\{ ?\})) 0 1))))
  5258. (set-register org-agenda-query-register org-agenda-query-string)
  5259. (org-agenda-redo))
  5260. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5261. org-agenda-type))))
  5262. (defun org-add-to-string (var string)
  5263. (set var (concat (symbol-value var) string)))
  5264. (defun org-agenda-goto-date (date)
  5265. "Jump to DATE in agenda."
  5266. (interactive (list (org-read-date)))
  5267. (org-agenda-list nil date))
  5268. (defun org-agenda-goto-today ()
  5269. "Go to today."
  5270. (interactive)
  5271. (org-agenda-check-type t 'timeline 'agenda)
  5272. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5273. (cond
  5274. (tdpos (goto-char tdpos))
  5275. ((eq org-agenda-type 'agenda)
  5276. (let* ((sd (time-to-days
  5277. (time-subtract (current-time)
  5278. (list 0 (* 3600 org-extend-today-until) 0))))
  5279. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5280. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5281. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5282. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5283. (org-agenda-redo)
  5284. (org-agenda-find-same-or-today-or-agenda)))
  5285. (t (error "Cannot find today")))))
  5286. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5287. (goto-char
  5288. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5289. (text-property-any (point-min) (point-max) 'org-today t)
  5290. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5291. (point-min))))
  5292. (defun org-agenda-later (arg)
  5293. "Go forward in time by thee current span.
  5294. With prefix ARG, go forward that many times the current span."
  5295. (interactive "p")
  5296. (org-agenda-check-type t 'agenda)
  5297. (let* ((span org-agenda-span)
  5298. (sd org-starting-day)
  5299. (greg (calendar-gregorian-from-absolute sd))
  5300. (cnt (org-get-at-bol 'org-day-cnt))
  5301. greg2 nd)
  5302. (cond
  5303. ((eq span 'day)
  5304. (setq sd (+ arg sd) nd 1))
  5305. ((eq span 'week)
  5306. (setq sd (+ (* 7 arg) sd) nd 7))
  5307. ((eq span 'month)
  5308. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5309. sd (calendar-absolute-from-gregorian greg2))
  5310. (setcar greg2 (1+ (car greg2)))
  5311. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5312. ((eq span 'year)
  5313. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5314. sd (calendar-absolute-from-gregorian greg2))
  5315. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5316. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5317. (let ((org-agenda-overriding-arguments
  5318. (list (car org-agenda-last-arguments) sd nd t)))
  5319. (org-agenda-redo)
  5320. (org-agenda-find-same-or-today-or-agenda cnt))))
  5321. (defun org-agenda-earlier (arg)
  5322. "Go backward in time by the current span.
  5323. With prefix ARG, go backward that many times the current span."
  5324. (interactive "p")
  5325. (org-agenda-later (- arg)))
  5326. (defun org-agenda-view-mode-dispatch ()
  5327. "Call one of the view mode commands."
  5328. (interactive)
  5329. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5330. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5331. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5332. (let ((a (read-char-exclusive)))
  5333. (case a
  5334. (?d (call-interactively 'org-agenda-day-view))
  5335. (?w (call-interactively 'org-agenda-week-view))
  5336. (?m (call-interactively 'org-agenda-month-view))
  5337. (?y (call-interactively 'org-agenda-year-view))
  5338. (?l (call-interactively 'org-agenda-log-mode))
  5339. (?L (org-agenda-log-mode '(4)))
  5340. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5341. (?a (call-interactively 'org-agenda-archives-mode))
  5342. (?A (org-agenda-archives-mode 'files))
  5343. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5344. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5345. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5346. (?D (call-interactively 'org-agenda-toggle-diary))
  5347. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5348. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5349. (org-agenda-check-type t 'timeline 'agenda)
  5350. (org-agenda-redo))
  5351. (message "Display now includes inactive timestamps as well"))
  5352. (?q (message "Abort"))
  5353. (otherwise (error "Invalid key" )))))
  5354. (defun org-agenda-day-view (&optional day-of-year)
  5355. "Switch to daily view for agenda.
  5356. With argument DAY-OF-YEAR, switch to that day of the year."
  5357. (interactive "P")
  5358. (setq org-agenda-ndays 1)
  5359. (org-agenda-change-time-span 'day day-of-year))
  5360. (defun org-agenda-week-view (&optional iso-week)
  5361. "Switch to daily view for agenda.
  5362. With argument ISO-WEEK, switch to the corresponding ISO week.
  5363. If ISO-WEEK has more then 2 digits, only the last two encode the
  5364. week. Any digits before this encode a year. So 200712 means
  5365. week 12 of year 2007. Years in the range 1938-2037 can also be
  5366. written as 2-digit years."
  5367. (interactive "P")
  5368. (setq org-agenda-ndays 7)
  5369. (org-agenda-change-time-span 'week iso-week))
  5370. (defun org-agenda-month-view (&optional month)
  5371. "Switch to monthly view for agenda.
  5372. With argument MONTH, switch to that month."
  5373. (interactive "P")
  5374. (org-agenda-change-time-span 'month month))
  5375. (defun org-agenda-year-view (&optional year)
  5376. "Switch to yearly view for agenda.
  5377. With argument YEAR, switch to that year.
  5378. If MONTH has more then 2 digits, only the last two encode the
  5379. month. Any digits before this encode a year. So 200712 means
  5380. December year 2007. Years in the range 1938-2037 can also be
  5381. written as 2-digit years."
  5382. (interactive "P")
  5383. (when year
  5384. (setq year (org-small-year-to-year year)))
  5385. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5386. (org-agenda-change-time-span 'year year)
  5387. (error "Abort")))
  5388. (defun org-agenda-change-time-span (span &optional n)
  5389. "Change the agenda view to SPAN.
  5390. SPAN may be `day', `week', `month', `year'."
  5391. (org-agenda-check-type t 'agenda)
  5392. (if (and (not n) (equal org-agenda-span span))
  5393. (error "Viewing span is already \"%s\"" span))
  5394. (let* ((sd (or (org-get-at-bol 'day)
  5395. org-starting-day))
  5396. (computed (org-agenda-compute-time-span sd span n))
  5397. (org-agenda-overriding-arguments
  5398. (list (car org-agenda-last-arguments)
  5399. (car computed) (cdr computed) t)))
  5400. (org-agenda-redo)
  5401. (org-agenda-find-same-or-today-or-agenda))
  5402. (org-agenda-set-mode-name)
  5403. (message "Switched to %s view" span))
  5404. (defun org-agenda-compute-time-span (sd span &optional n)
  5405. "Compute starting date and number of days for agenda.
  5406. SPAN may be `day', `week', `month', `year'. The return value
  5407. is a cons cell with the starting date and the number of days,
  5408. so that the date SD will be in that range."
  5409. (let* ((greg (calendar-gregorian-from-absolute sd))
  5410. (dg (nth 1 greg))
  5411. (mg (car greg))
  5412. (yg (nth 2 greg))
  5413. nd w1 y1 m1 thisweek)
  5414. (cond
  5415. ((eq span 'day)
  5416. (when n
  5417. (setq sd (+ (calendar-absolute-from-gregorian
  5418. (list mg 1 yg))
  5419. n -1)))
  5420. (setq nd 1))
  5421. ((eq span 'week)
  5422. (let* ((nt (calendar-day-of-week
  5423. (calendar-gregorian-from-absolute sd)))
  5424. (d (if org-agenda-start-on-weekday
  5425. (- nt org-agenda-start-on-weekday)
  5426. 0)))
  5427. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5428. (when n
  5429. (require 'cal-iso)
  5430. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5431. (when (> n 99)
  5432. (setq y1 (org-small-year-to-year (/ n 100))
  5433. n (mod n 100)))
  5434. (setq sd
  5435. (calendar-absolute-from-iso
  5436. (list n 1
  5437. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5438. (setq nd 7)))
  5439. ((eq span 'month)
  5440. (when (and n (> n 99))
  5441. (setq y1 (org-small-year-to-year (/ n 100))
  5442. n (mod n 100)))
  5443. (setq sd (calendar-absolute-from-gregorian
  5444. (list (or n mg) 1 (or y1 yg)))
  5445. nd (- (calendar-absolute-from-gregorian
  5446. (list (1+ (or n mg)) 1 (or y1 yg)))
  5447. sd)))
  5448. ((eq span 'year)
  5449. (setq sd (calendar-absolute-from-gregorian
  5450. (list 1 1 (or n yg)))
  5451. nd (- (calendar-absolute-from-gregorian
  5452. (list 1 1 (1+ (or n yg))))
  5453. sd))))
  5454. (cons sd nd)))
  5455. (defun org-agenda-next-date-line (&optional arg)
  5456. "Jump to the next line indicating a date in agenda buffer."
  5457. (interactive "p")
  5458. (org-agenda-check-type t 'agenda 'timeline)
  5459. (beginning-of-line 1)
  5460. ;; This does not work if user makes date format that starts with a blank
  5461. (if (looking-at "^\\S-") (forward-char 1))
  5462. (if (not (re-search-forward "^\\S-" nil t arg))
  5463. (progn
  5464. (backward-char 1)
  5465. (error "No next date after this line in this buffer")))
  5466. (goto-char (match-beginning 0)))
  5467. (defun org-agenda-previous-date-line (&optional arg)
  5468. "Jump to the previous line indicating a date in agenda buffer."
  5469. (interactive "p")
  5470. (org-agenda-check-type t 'agenda 'timeline)
  5471. (beginning-of-line 1)
  5472. (if (not (re-search-backward "^\\S-" nil t arg))
  5473. (error "No previous date before this line in this buffer")))
  5474. ;; Initialize the highlight
  5475. (defvar org-hl (make-overlay 1 1))
  5476. (overlay-put org-hl 'face 'highlight)
  5477. (defun org-highlight (begin end &optional buffer)
  5478. "Highlight a region with overlay."
  5479. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5480. org-hl begin end (or buffer (current-buffer))))
  5481. (defun org-unhighlight ()
  5482. "Detach overlay INDEX."
  5483. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5484. ;; FIXME this is currently not used.
  5485. (defun org-highlight-until-next-command (beg end &optional buffer)
  5486. "Move the highlight overlay to BEG/END, remove it before the next command."
  5487. (org-highlight beg end buffer)
  5488. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5489. (defun org-unhighlight-once ()
  5490. "Remove the highlight from its position, and this function from the hook."
  5491. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5492. (org-unhighlight))
  5493. (defun org-agenda-follow-mode ()
  5494. "Toggle follow mode in an agenda buffer."
  5495. (interactive)
  5496. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5497. (org-agenda-set-mode-name)
  5498. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5499. (org-agenda-show))
  5500. (message "Follow mode is %s"
  5501. (if org-agenda-follow-mode "on" "off")))
  5502. (defun org-agenda-entry-text-mode (&optional arg)
  5503. "Toggle entry text mode in an agenda buffer."
  5504. (interactive "P")
  5505. (if (integerp arg)
  5506. (setq org-agenda-entry-text-mode t)
  5507. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5508. (org-agenda-entry-text-hide)
  5509. (and org-agenda-entry-text-mode
  5510. (let ((org-agenda-entry-text-maxlines
  5511. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5512. (org-agenda-entry-text-show)))
  5513. (org-agenda-set-mode-name)
  5514. (message "Entry text mode is %s. Maximum number of lines is %d"
  5515. (if org-agenda-entry-text-mode "on" "off")
  5516. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5517. (defun org-agenda-clockreport-mode ()
  5518. "Toggle clocktable mode in an agenda buffer."
  5519. (interactive)
  5520. (org-agenda-check-type t 'agenda)
  5521. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5522. (org-agenda-set-mode-name)
  5523. (org-agenda-redo)
  5524. (message "Clocktable mode is %s"
  5525. (if org-agenda-clockreport-mode "on" "off")))
  5526. (defun org-agenda-log-mode (&optional special)
  5527. "Toggle log mode in an agenda buffer.
  5528. With argument SPECIAL, show all possible log items, not only the ones
  5529. configured in `org-agenda-log-mode-items'.
  5530. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5531. (interactive "P")
  5532. (org-agenda-check-type t 'agenda 'timeline)
  5533. (setq org-agenda-show-log
  5534. (if (equal special '(16))
  5535. 'only
  5536. (if special '(closed clock state)
  5537. (not org-agenda-show-log))))
  5538. (org-agenda-set-mode-name)
  5539. (org-agenda-redo)
  5540. (message "Log mode is %s"
  5541. (if org-agenda-show-log "on" "off")))
  5542. (defun org-agenda-archives-mode (&optional with-files)
  5543. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5544. When called with a prefix argument, include all archive files as well."
  5545. (interactive "P")
  5546. (setq org-agenda-archives-mode
  5547. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5548. (org-agenda-set-mode-name)
  5549. (org-agenda-redo)
  5550. (message
  5551. "%s"
  5552. (cond
  5553. ((eq org-agenda-archives-mode nil)
  5554. "No archives are included")
  5555. ((eq org-agenda-archives-mode 'trees)
  5556. (format "Trees with :%s: tag are included" org-archive-tag))
  5557. ((eq org-agenda-archives-mode t)
  5558. (format "Trees with :%s: tag and all active archive files are included"
  5559. org-archive-tag)))))
  5560. (defun org-agenda-toggle-diary ()
  5561. "Toggle diary inclusion in an agenda buffer."
  5562. (interactive)
  5563. (org-agenda-check-type t 'agenda)
  5564. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5565. (org-agenda-redo)
  5566. (org-agenda-set-mode-name)
  5567. (message "Diary inclusion turned %s"
  5568. (if org-agenda-include-diary "on" "off")))
  5569. (defun org-agenda-toggle-deadlines ()
  5570. "Toggle diary inclusion in an agenda buffer."
  5571. (interactive)
  5572. (org-agenda-check-type t 'agenda)
  5573. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5574. (org-agenda-redo)
  5575. (org-agenda-set-mode-name)
  5576. (message "Deadlines inclusion turned %s"
  5577. (if org-agenda-include-deadlines "on" "off")))
  5578. (defun org-agenda-toggle-time-grid ()
  5579. "Toggle time grid in an agenda buffer."
  5580. (interactive)
  5581. (org-agenda-check-type t 'agenda)
  5582. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5583. (org-agenda-redo)
  5584. (org-agenda-set-mode-name)
  5585. (message "Time-grid turned %s"
  5586. (if org-agenda-use-time-grid "on" "off")))
  5587. (defun org-agenda-set-mode-name ()
  5588. "Set the mode name to indicate all the small mode settings."
  5589. (setq mode-name
  5590. (concat "Org-Agenda"
  5591. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5592. (if (equal org-agenda-ndays 1) " Day" "")
  5593. (if (equal org-agenda-ndays 7) " Week" "")
  5594. (if org-agenda-follow-mode " Follow" "")
  5595. (if org-agenda-entry-text-mode " ETxt" "")
  5596. (if org-agenda-include-diary " Diary" "")
  5597. (if org-agenda-include-deadlines " Ddl" "")
  5598. (if org-agenda-use-time-grid " Grid" "")
  5599. (if (and (boundp 'org-habit-show-habits)
  5600. org-habit-show-habits) " Habit" "")
  5601. (if (consp org-agenda-show-log) " LogAll"
  5602. (if org-agenda-show-log " Log" ""))
  5603. (if (or org-agenda-filter (get 'org-agenda-filter
  5604. :preset-filter))
  5605. (concat " {" (mapconcat
  5606. 'identity
  5607. (append (get 'org-agenda-filter
  5608. :preset-filter)
  5609. org-agenda-filter) "") "}")
  5610. "")
  5611. (if org-agenda-archives-mode
  5612. (if (eq org-agenda-archives-mode t)
  5613. " Archives"
  5614. (format " :%s:" org-archive-tag))
  5615. "")
  5616. (if org-agenda-clockreport-mode " Clock" "")))
  5617. (force-mode-line-update))
  5618. (defun org-agenda-post-command-hook ()
  5619. (setq org-agenda-type
  5620. (or (get-text-property (point) 'org-agenda-type)
  5621. (get-text-property (max (point-min) (1- (point)))
  5622. 'org-agenda-type))))
  5623. (defun org-agenda-next-line ()
  5624. "Move cursor to the next line, and show if follow-mode is active."
  5625. (interactive)
  5626. (call-interactively 'next-line)
  5627. (org-agenda-do-context-action))
  5628. (defun org-agenda-previous-line ()
  5629. "Move cursor to the previous line, and show if follow-mode is active."
  5630. (interactive)
  5631. (call-interactively 'previous-line)
  5632. (org-agenda-do-context-action))
  5633. (defun org-agenda-do-context-action ()
  5634. "Show outline path and, maybe, follow-mode window."
  5635. (let ((m (org-get-at-bol 'org-marker)))
  5636. (if (and org-agenda-follow-mode m)
  5637. (org-agenda-show))
  5638. (if (and m org-agenda-show-outline-path)
  5639. (org-with-point-at m
  5640. (org-display-outline-path t)))))
  5641. (defun org-agenda-show-priority ()
  5642. "Show the priority of the current item.
  5643. This priority is composed of the main priority given with the [#A] cookies,
  5644. and by additional input from the age of a schedules or deadline entry."
  5645. (interactive)
  5646. (let* ((pri (org-get-at-bol 'priority)))
  5647. (message "Priority is %d" (if pri pri -1000))))
  5648. (defun org-agenda-show-tags ()
  5649. "Show the tags applicable to the current item."
  5650. (interactive)
  5651. (let* ((tags (org-get-at-bol 'tags)))
  5652. (if tags
  5653. (message "Tags are :%s:"
  5654. (org-no-properties (mapconcat 'identity tags ":")))
  5655. (message "No tags associated with this line"))))
  5656. (defun org-agenda-goto (&optional highlight)
  5657. "Go to the Org-mode file which contains the item at point."
  5658. (interactive)
  5659. (let* ((marker (or (org-get-at-bol 'org-marker)
  5660. (org-agenda-error)))
  5661. (buffer (marker-buffer marker))
  5662. (pos (marker-position marker)))
  5663. (switch-to-buffer-other-window buffer)
  5664. (widen)
  5665. (goto-char pos)
  5666. (when (org-mode-p)
  5667. (org-show-context 'agenda)
  5668. (save-excursion
  5669. (and (outline-next-heading)
  5670. (org-flag-heading nil)))) ; show the next heading
  5671. (recenter (/ (window-height) 2))
  5672. (run-hooks 'org-agenda-after-show-hook)
  5673. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5674. (defvar org-agenda-after-show-hook nil
  5675. "Normal hook run after an item has been shown from the agenda.
  5676. Point is in the buffer where the item originated.")
  5677. (defun org-agenda-kill ()
  5678. "Kill the entry or subtree belonging to the current agenda entry."
  5679. (interactive)
  5680. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5681. (let* ((marker (or (org-get-at-bol 'org-marker)
  5682. (org-agenda-error)))
  5683. (buffer (marker-buffer marker))
  5684. (pos (marker-position marker))
  5685. (type (org-get-at-bol 'type))
  5686. dbeg dend (n 0) conf)
  5687. (org-with-remote-undo buffer
  5688. (with-current-buffer buffer
  5689. (save-excursion
  5690. (goto-char pos)
  5691. (if (and (org-mode-p) (not (member type '("sexp"))))
  5692. (setq dbeg (progn (org-back-to-heading t) (point))
  5693. dend (org-end-of-subtree t t))
  5694. (setq dbeg (point-at-bol)
  5695. dend (min (point-max) (1+ (point-at-eol)))))
  5696. (goto-char dbeg)
  5697. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5698. (setq conf (or (eq t org-agenda-confirm-kill)
  5699. (and (numberp org-agenda-confirm-kill)
  5700. (> n org-agenda-confirm-kill))))
  5701. (and conf
  5702. (not (y-or-n-p
  5703. (format "Delete entry with %d lines in buffer \"%s\"? "
  5704. n (buffer-name buffer))))
  5705. (error "Abort"))
  5706. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5707. (with-current-buffer buffer (delete-region dbeg dend))
  5708. (message "Agenda item and source killed"))))
  5709. (defvar org-archive-default-command)
  5710. (defun org-agenda-archive-default ()
  5711. "Archive the entry or subtree belonging to the current agenda entry."
  5712. (interactive)
  5713. (require 'org-archive)
  5714. (org-agenda-archive-with org-archive-default-command))
  5715. (defun org-agenda-archive-default-with-confirmation ()
  5716. "Archive the entry or subtree belonging to the current agenda entry."
  5717. (interactive)
  5718. (require 'org-archive)
  5719. (org-agenda-archive-with org-archive-default-command 'confirm))
  5720. (defun org-agenda-archive ()
  5721. "Archive the entry or subtree belonging to the current agenda entry."
  5722. (interactive)
  5723. (org-agenda-archive-with 'org-archive-subtree))
  5724. (defun org-agenda-archive-to-archive-sibling ()
  5725. "Move the entry to the archive sibling."
  5726. (interactive)
  5727. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5728. (defun org-agenda-archive-with (cmd &optional confirm)
  5729. "Move the entry to the archive sibling."
  5730. (interactive)
  5731. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5732. (let* ((marker (or (org-get-at-bol 'org-marker)
  5733. (org-agenda-error)))
  5734. (buffer (marker-buffer marker))
  5735. (pos (marker-position marker)))
  5736. (org-with-remote-undo buffer
  5737. (with-current-buffer buffer
  5738. (if (org-mode-p)
  5739. (if (and confirm
  5740. (not (y-or-n-p "Archive this subtree or entry? ")))
  5741. (error "Abort")
  5742. (save-excursion
  5743. (goto-char pos)
  5744. (org-remove-subtree-entries-from-agenda)
  5745. (org-back-to-heading t)
  5746. (funcall cmd)))
  5747. (error "Archiving works only in Org-mode files"))))))
  5748. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5749. "Remove all lines in the agenda that correspond to a given subtree.
  5750. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5751. If this information is not given, the function uses the tree at point."
  5752. (let ((buf (or buf (current-buffer))) m p)
  5753. (save-excursion
  5754. (unless (and beg end)
  5755. (org-back-to-heading t)
  5756. (setq beg (point))
  5757. (org-end-of-subtree t)
  5758. (setq end (point)))
  5759. (set-buffer (get-buffer org-agenda-buffer-name))
  5760. (save-excursion
  5761. (goto-char (point-max))
  5762. (beginning-of-line 1)
  5763. (while (not (bobp))
  5764. (when (and (setq m (org-get-at-bol 'org-marker))
  5765. (equal buf (marker-buffer m))
  5766. (setq p (marker-position m))
  5767. (>= p beg)
  5768. (< p end))
  5769. (let ((inhibit-read-only t))
  5770. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5771. (beginning-of-line 0))))))
  5772. (defun org-agenda-refile (&optional goto rfloc)
  5773. "Refile the item at point."
  5774. (interactive "P")
  5775. (if (equal goto '(16))
  5776. (org-refile-goto-last-stored)
  5777. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5778. (org-agenda-error)))
  5779. (buffer (marker-buffer marker))
  5780. (pos (marker-position marker))
  5781. (rfloc (or rfloc
  5782. (org-refile-get-location
  5783. (if goto "Goto: " "Refile to: ") buffer
  5784. org-refile-allow-creating-parent-nodes))))
  5785. (with-current-buffer buffer
  5786. (save-excursion
  5787. (save-restriction
  5788. (widen)
  5789. (goto-char marker)
  5790. (org-remove-subtree-entries-from-agenda)
  5791. (org-refile goto buffer rfloc)))))))
  5792. (defun org-agenda-open-link (&optional arg)
  5793. "Follow the link in the current line, if any.
  5794. This looks for a link in the displayed line in the agenda. It also looks
  5795. at the text of the entry itself."
  5796. (interactive "P")
  5797. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5798. (org-get-at-bol 'org-marker)))
  5799. (buffer (and marker (marker-buffer marker)))
  5800. (prefix (buffer-substring
  5801. (point-at-bol)
  5802. (+ (point-at-bol)
  5803. (or (org-get-at-bol 'prefix-length) 0)))))
  5804. (cond
  5805. (buffer
  5806. (with-current-buffer buffer
  5807. (save-excursion
  5808. (save-restriction
  5809. (widen)
  5810. (goto-char marker)
  5811. (org-offer-links-in-entry arg prefix)))))
  5812. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5813. (save-excursion
  5814. (beginning-of-line 1)
  5815. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5816. (org-open-link-from-string (match-string 1)))
  5817. (t (error "No link to open here")))))
  5818. (defun org-agenda-copy-local-variable (var)
  5819. "Get a variable from a referenced buffer and install it here."
  5820. (let ((m (org-get-at-bol 'org-marker)))
  5821. (when (and m (buffer-live-p (marker-buffer m)))
  5822. (org-set-local var (with-current-buffer (marker-buffer m)
  5823. (symbol-value var))))))
  5824. (defun org-agenda-switch-to (&optional delete-other-windows)
  5825. "Go to the Org-mode file which contains the item at point."
  5826. (interactive)
  5827. (if (and org-return-follows-link
  5828. (not (org-get-at-bol 'org-marker))
  5829. (org-in-regexp org-bracket-link-regexp))
  5830. (org-open-link-from-string (match-string 0))
  5831. (let* ((marker (or (org-get-at-bol 'org-marker)
  5832. (org-agenda-error)))
  5833. (buffer (marker-buffer marker))
  5834. (pos (marker-position marker)))
  5835. (switch-to-buffer buffer)
  5836. (and delete-other-windows (delete-other-windows))
  5837. (widen)
  5838. (goto-char pos)
  5839. (when (org-mode-p)
  5840. (org-show-context 'agenda)
  5841. (save-excursion
  5842. (and (outline-next-heading)
  5843. (org-flag-heading nil))))))) ; show the next heading
  5844. (defun org-agenda-goto-mouse (ev)
  5845. "Go to the Org-mode file which contains the item at the mouse click."
  5846. (interactive "e")
  5847. (mouse-set-point ev)
  5848. (org-agenda-goto))
  5849. (defun org-agenda-show (&optional full-entry)
  5850. "Display the Org-mode file which contains the item at point.
  5851. With prefix argument FULL-ENTRY, make the entire entry visible
  5852. if it was hidden in the outline."
  5853. (interactive "P")
  5854. (let ((win (selected-window)))
  5855. (if full-entry
  5856. (let ((org-show-entry-below t))
  5857. (org-agenda-goto t))
  5858. (org-agenda-goto t))
  5859. (select-window win)))
  5860. (defvar org-agenda-show-window nil)
  5861. (defun org-agenda-show-and-scroll-up ()
  5862. "Display the Org-mode file which contains the item at point.
  5863. When called repeatedly, scroll the window that is displaying the buffer."
  5864. (interactive)
  5865. (let ((win (selected-window)))
  5866. (if (and (window-live-p org-agenda-show-window)
  5867. (eq this-command last-command))
  5868. (progn
  5869. (select-window org-agenda-show-window)
  5870. (ignore-errors (scroll-up)))
  5871. (org-agenda-goto t)
  5872. (show-subtree)
  5873. (setq org-agenda-show-window (selected-window)))
  5874. (select-window win)))
  5875. (defun org-agenda-show-scroll-down ()
  5876. "Scroll down the window showing the agenda."
  5877. (interactive)
  5878. (let ((win (selected-window)))
  5879. (when (window-live-p org-agenda-show-window)
  5880. (select-window org-agenda-show-window)
  5881. (ignore-errors (scroll-down))
  5882. (select-window win))))
  5883. (defun org-agenda-show-1 (&optional more)
  5884. "Display the Org-mode file which contains the item at point.
  5885. The prefix arg selects the amount of information to display:
  5886. 0 hide the subtree
  5887. 1 just show the entry according to defaults.
  5888. 2 show the children view
  5889. 3 show the subtree view
  5890. 4 show the entire subtree and any LOGBOOK drawers
  5891. 5 show the entire subtree and any drawers
  5892. With prefix argument FULL-ENTRY, make the entire entry visible
  5893. if it was hidden in the outline."
  5894. (interactive "p")
  5895. (let ((win (selected-window)))
  5896. (org-agenda-goto t)
  5897. (org-recenter-heading 1)
  5898. (cond
  5899. ((= more 0)
  5900. (hide-subtree)
  5901. (save-excursion
  5902. (org-back-to-heading)
  5903. (run-hook-with-args 'org-cycle-hook 'folded))
  5904. (message "Remote: FOLDED"))
  5905. ((and (interactive-p) (= more 1))
  5906. (message "Remote: show with default settings"))
  5907. ((= more 2)
  5908. (show-entry)
  5909. (show-children)
  5910. (save-excursion
  5911. (org-back-to-heading)
  5912. (run-hook-with-args 'org-cycle-hook 'children))
  5913. (message "Remote: CHILDREN"))
  5914. ((= more 3)
  5915. (show-subtree)
  5916. (save-excursion
  5917. (org-back-to-heading)
  5918. (run-hook-with-args 'org-cycle-hook 'subtree))
  5919. (message "Remote: SUBTREE"))
  5920. ((= more 4)
  5921. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5922. (org-drawer-regexp
  5923. (concat "^[ \t]*:\\("
  5924. (mapconcat 'regexp-quote org-drawers "\\|")
  5925. "\\):[ \t]*$")))
  5926. (show-subtree)
  5927. (save-excursion
  5928. (org-back-to-heading)
  5929. (org-cycle-hide-drawers 'subtree)))
  5930. (message "Remote: SUBTREE AND LOGBOOK"))
  5931. ((> more 4)
  5932. (show-subtree)
  5933. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5934. (select-window win)))
  5935. (defun org-recenter-heading (n)
  5936. (save-excursion
  5937. (org-back-to-heading)
  5938. (recenter n)))
  5939. (defvar org-agenda-cycle-counter nil)
  5940. (defun org-agenda-cycle-show (&optional n)
  5941. "Show the current entry in another window, with default settings.
  5942. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5943. When use repeatedly in immediate succession, the remote entry will cycle
  5944. through visibility
  5945. children -> subtree -> folded
  5946. When called with a numeric prefix arg, that arg will be passed through to
  5947. `org-agenda-show-1'. For the interpretation of that argument, see the
  5948. docstring of `org-agenda-show-1'."
  5949. (interactive "P")
  5950. (if (integerp n)
  5951. (setq org-agenda-cycle-counter n)
  5952. (if (not (eq last-command this-command))
  5953. (setq org-agenda-cycle-counter 1)
  5954. (if (equal org-agenda-cycle-counter 0)
  5955. (setq org-agenda-cycle-counter 2)
  5956. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5957. (if (> org-agenda-cycle-counter 3)
  5958. (setq org-agenda-cycle-counter 0)))))
  5959. (org-agenda-show-1 org-agenda-cycle-counter))
  5960. (defun org-agenda-recenter (arg)
  5961. "Display the Org-mode file which contains the item at point and recenter."
  5962. (interactive "P")
  5963. (let ((win (selected-window)))
  5964. (org-agenda-goto t)
  5965. (recenter arg)
  5966. (select-window win)))
  5967. (defun org-agenda-show-mouse (ev)
  5968. "Display the Org-mode file which contains the item at the mouse click."
  5969. (interactive "e")
  5970. (mouse-set-point ev)
  5971. (org-agenda-show))
  5972. (defun org-agenda-check-no-diary ()
  5973. "Check if the entry is a diary link and abort if yes."
  5974. (if (org-get-at-bol 'org-agenda-diary-link)
  5975. (org-agenda-error)))
  5976. (defun org-agenda-error ()
  5977. (error "Command not allowed in this line"))
  5978. (defun org-agenda-tree-to-indirect-buffer ()
  5979. "Show the subtree corresponding to the current entry in an indirect buffer.
  5980. This calls the command `org-tree-to-indirect-buffer' from the original
  5981. Org-mode buffer.
  5982. With numerical prefix arg ARG, go up to this level and then take that tree.
  5983. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5984. dedicated frame)."
  5985. (interactive)
  5986. (org-agenda-check-no-diary)
  5987. (let* ((marker (or (org-get-at-bol 'org-marker)
  5988. (org-agenda-error)))
  5989. (buffer (marker-buffer marker))
  5990. (pos (marker-position marker)))
  5991. (with-current-buffer buffer
  5992. (save-excursion
  5993. (goto-char pos)
  5994. (call-interactively 'org-tree-to-indirect-buffer)))))
  5995. (defvar org-last-heading-marker (make-marker)
  5996. "Marker pointing to the headline that last changed its TODO state
  5997. by a remote command from the agenda.")
  5998. (defun org-agenda-todo-nextset ()
  5999. "Switch TODO entry to next sequence."
  6000. (interactive)
  6001. (org-agenda-todo 'nextset))
  6002. (defun org-agenda-todo-previousset ()
  6003. "Switch TODO entry to previous sequence."
  6004. (interactive)
  6005. (org-agenda-todo 'previousset))
  6006. (defun org-agenda-todo (&optional arg)
  6007. "Cycle TODO state of line at point, also in Org-mode file.
  6008. This changes the line at point, all other lines in the agenda referring to
  6009. the same tree node, and the headline of the tree node in the Org-mode file."
  6010. (interactive "P")
  6011. (org-agenda-check-no-diary)
  6012. (let* ((col (current-column))
  6013. (marker (or (org-get-at-bol 'org-marker)
  6014. (org-agenda-error)))
  6015. (buffer (marker-buffer marker))
  6016. (pos (marker-position marker))
  6017. (hdmarker (org-get-at-bol 'org-hd-marker))
  6018. (todayp (equal (org-get-at-bol 'day)
  6019. (time-to-days (current-time))))
  6020. (inhibit-read-only t)
  6021. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6022. (org-with-remote-undo buffer
  6023. (with-current-buffer buffer
  6024. (widen)
  6025. (goto-char pos)
  6026. (org-show-context 'agenda)
  6027. (save-excursion
  6028. (and (outline-next-heading)
  6029. (org-flag-heading nil))) ; show the next heading
  6030. (let ((current-prefix-arg arg))
  6031. (call-interactively 'org-todo))
  6032. (and (bolp) (forward-char 1))
  6033. (setq newhead (org-get-heading))
  6034. (when (and (org-bound-and-true-p
  6035. org-agenda-headline-snapshot-before-repeat)
  6036. (not (equal org-agenda-headline-snapshot-before-repeat
  6037. newhead))
  6038. todayp)
  6039. (setq newhead org-agenda-headline-snapshot-before-repeat
  6040. just-one t))
  6041. (save-excursion
  6042. (org-back-to-heading)
  6043. (move-marker org-last-heading-marker (point))))
  6044. (beginning-of-line 1)
  6045. (save-excursion
  6046. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6047. (org-move-to-column col))))
  6048. (defun org-agenda-add-note (&optional arg)
  6049. "Add a time-stamped note to the entry at point."
  6050. (interactive "P")
  6051. (org-agenda-check-no-diary)
  6052. (let* ((marker (or (org-get-at-bol 'org-marker)
  6053. (org-agenda-error)))
  6054. (buffer (marker-buffer marker))
  6055. (pos (marker-position marker))
  6056. (hdmarker (org-get-at-bol 'org-hd-marker))
  6057. (inhibit-read-only t))
  6058. (with-current-buffer buffer
  6059. (widen)
  6060. (goto-char pos)
  6061. (org-show-context 'agenda)
  6062. (save-excursion
  6063. (and (outline-next-heading)
  6064. (org-flag-heading nil))) ; show the next heading
  6065. (org-add-note))))
  6066. (defun org-agenda-change-all-lines (newhead hdmarker
  6067. &optional fixface just-this)
  6068. "Change all lines in the agenda buffer which match HDMARKER.
  6069. The new content of the line will be NEWHEAD (as modified by
  6070. `org-format-agenda-item'). HDMARKER is checked with
  6071. `equal' against all `org-hd-marker' text properties in the file.
  6072. If FIXFACE is non-nil, the face of each item is modified according to
  6073. the new TODO state.
  6074. If JUST-THIS is non-nil, change just the current line, not all.
  6075. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6076. (let* ((inhibit-read-only t)
  6077. (line (org-current-line))
  6078. (thetags (with-current-buffer (marker-buffer hdmarker)
  6079. (save-excursion (save-restriction (widen)
  6080. (goto-char hdmarker)
  6081. (org-get-tags-at)))))
  6082. props m pl undone-face done-face finish new dotime cat tags)
  6083. (save-excursion
  6084. (goto-char (point-max))
  6085. (beginning-of-line 1)
  6086. (while (not finish)
  6087. (setq finish (bobp))
  6088. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6089. (or (not just-this) (= (org-current-line) line))
  6090. (equal m hdmarker))
  6091. (setq props (text-properties-at (point))
  6092. dotime (org-get-at-bol 'dotime)
  6093. cat (org-get-at-bol 'org-category)
  6094. tags thetags
  6095. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6096. pl (org-get-at-bol 'prefix-length)
  6097. undone-face (org-get-at-bol 'undone-face)
  6098. done-face (org-get-at-bol 'done-face))
  6099. (goto-char (+ (point) pl))
  6100. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6101. (cond
  6102. ((equal new "")
  6103. (beginning-of-line 1)
  6104. (and (looking-at ".*\n?") (replace-match "")))
  6105. ((looking-at ".*")
  6106. (replace-match new t t)
  6107. (beginning-of-line 1)
  6108. (add-text-properties (point-at-bol) (point-at-eol) props)
  6109. (when fixface
  6110. (add-text-properties
  6111. (point-at-bol) (point-at-eol)
  6112. (list 'face
  6113. (if org-last-todo-state-is-todo
  6114. undone-face done-face))))
  6115. (org-agenda-highlight-todo 'line)
  6116. (beginning-of-line 1))
  6117. (t (error "Line update did not work"))))
  6118. (beginning-of-line 0)))
  6119. (org-finalize-agenda)))
  6120. (defun org-agenda-align-tags (&optional line)
  6121. "Align all tags in agenda items to `org-agenda-tags-column'."
  6122. (let ((inhibit-read-only t) l c)
  6123. (save-excursion
  6124. (goto-char (if line (point-at-bol) (point-min)))
  6125. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  6126. (if line (point-at-eol) nil) t)
  6127. (add-text-properties
  6128. (match-beginning 2) (match-end 2)
  6129. (list 'face (delq nil (let ((prop (get-text-property
  6130. (match-beginning 2) 'face)))
  6131. (or (listp prop) (setq prop (list prop)))
  6132. (if (memq 'org-tag prop)
  6133. prop
  6134. (cons 'org-tag prop))))))
  6135. (setq l (- (match-end 2) (match-beginning 2))
  6136. c (if (< org-agenda-tags-column 0)
  6137. (- (abs org-agenda-tags-column) l)
  6138. org-agenda-tags-column))
  6139. (delete-region (match-beginning 1) (match-end 1))
  6140. (goto-char (match-beginning 1))
  6141. (insert (org-add-props
  6142. (make-string (max 1 (- c (current-column))) ?\ )
  6143. (plist-put (copy-sequence (text-properties-at (point)))
  6144. 'face nil))))
  6145. (goto-char (point-min))
  6146. (org-font-lock-add-tag-faces (point-max)))))
  6147. (defun org-agenda-priority-up ()
  6148. "Increase the priority of line at point, also in Org-mode file."
  6149. (interactive)
  6150. (org-agenda-priority 'up))
  6151. (defun org-agenda-priority-down ()
  6152. "Decrease the priority of line at point, also in Org-mode file."
  6153. (interactive)
  6154. (org-agenda-priority 'down))
  6155. (defun org-agenda-priority (&optional force-direction)
  6156. "Set the priority of line at point, also in Org-mode file.
  6157. This changes the line at point, all other lines in the agenda referring to
  6158. the same tree node, and the headline of the tree node in the Org-mode file."
  6159. (interactive)
  6160. (unless org-enable-priority-commands
  6161. (error "Priority commands are disabled"))
  6162. (org-agenda-check-no-diary)
  6163. (let* ((marker (or (org-get-at-bol 'org-marker)
  6164. (org-agenda-error)))
  6165. (hdmarker (org-get-at-bol 'org-hd-marker))
  6166. (buffer (marker-buffer hdmarker))
  6167. (pos (marker-position hdmarker))
  6168. (inhibit-read-only t)
  6169. newhead)
  6170. (org-with-remote-undo buffer
  6171. (with-current-buffer buffer
  6172. (widen)
  6173. (goto-char pos)
  6174. (org-show-context 'agenda)
  6175. (save-excursion
  6176. (and (outline-next-heading)
  6177. (org-flag-heading nil))) ; show the next heading
  6178. (funcall 'org-priority force-direction)
  6179. (end-of-line 1)
  6180. (setq newhead (org-get-heading)))
  6181. (org-agenda-change-all-lines newhead hdmarker)
  6182. (beginning-of-line 1))))
  6183. ;; FIXME: should fix the tags property of the agenda line.
  6184. (defun org-agenda-set-tags (&optional tag onoff)
  6185. "Set tags for the current headline."
  6186. (interactive)
  6187. (org-agenda-check-no-diary)
  6188. (if (and (org-region-active-p) (interactive-p))
  6189. (call-interactively 'org-change-tag-in-region)
  6190. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6191. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6192. (org-agenda-error)))
  6193. (buffer (marker-buffer hdmarker))
  6194. (pos (marker-position hdmarker))
  6195. (inhibit-read-only t)
  6196. newhead)
  6197. (org-with-remote-undo buffer
  6198. (with-current-buffer buffer
  6199. (widen)
  6200. (goto-char pos)
  6201. (save-excursion
  6202. (org-show-context 'agenda))
  6203. (save-excursion
  6204. (and (outline-next-heading)
  6205. (org-flag-heading nil))) ; show the next heading
  6206. (goto-char pos)
  6207. (if tag
  6208. (org-toggle-tag tag onoff)
  6209. (call-interactively 'org-set-tags))
  6210. (end-of-line 1)
  6211. (setq newhead (org-get-heading)))
  6212. (org-agenda-change-all-lines newhead hdmarker)
  6213. (beginning-of-line 1)))))
  6214. (defun org-agenda-set-property ()
  6215. "Set a property for the current headline."
  6216. (interactive)
  6217. (org-agenda-check-no-diary)
  6218. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6219. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6220. (org-agenda-error)))
  6221. (buffer (marker-buffer hdmarker))
  6222. (pos (marker-position hdmarker))
  6223. (inhibit-read-only t)
  6224. newhead)
  6225. (org-with-remote-undo buffer
  6226. (with-current-buffer buffer
  6227. (widen)
  6228. (goto-char pos)
  6229. (save-excursion
  6230. (org-show-context 'agenda))
  6231. (save-excursion
  6232. (and (outline-next-heading)
  6233. (org-flag-heading nil))) ; show the next heading
  6234. (goto-char pos)
  6235. (call-interactively 'org-set-property)))))
  6236. (defun org-agenda-set-effort ()
  6237. "Set the effort property for the current headline."
  6238. (interactive)
  6239. (org-agenda-check-no-diary)
  6240. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6241. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6242. (org-agenda-error)))
  6243. (buffer (marker-buffer hdmarker))
  6244. (pos (marker-position hdmarker))
  6245. (inhibit-read-only t)
  6246. newhead)
  6247. (org-with-remote-undo buffer
  6248. (with-current-buffer buffer
  6249. (widen)
  6250. (goto-char pos)
  6251. (save-excursion
  6252. (org-show-context 'agenda))
  6253. (save-excursion
  6254. (and (outline-next-heading)
  6255. (org-flag-heading nil))) ; show the next heading
  6256. (goto-char pos)
  6257. (call-interactively 'org-set-effort)
  6258. (end-of-line 1)))))
  6259. (defun org-agenda-toggle-archive-tag ()
  6260. "Toggle the archive tag for the current entry."
  6261. (interactive)
  6262. (org-agenda-check-no-diary)
  6263. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6264. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6265. (org-agenda-error)))
  6266. (buffer (marker-buffer hdmarker))
  6267. (pos (marker-position hdmarker))
  6268. (inhibit-read-only t)
  6269. newhead)
  6270. (org-with-remote-undo buffer
  6271. (with-current-buffer buffer
  6272. (widen)
  6273. (goto-char pos)
  6274. (org-show-context 'agenda)
  6275. (save-excursion
  6276. (and (outline-next-heading)
  6277. (org-flag-heading nil))) ; show the next heading
  6278. (call-interactively 'org-toggle-archive-tag)
  6279. (end-of-line 1)
  6280. (setq newhead (org-get-heading)))
  6281. (org-agenda-change-all-lines newhead hdmarker)
  6282. (beginning-of-line 1))))
  6283. (defun org-agenda-do-date-later (arg)
  6284. (interactive "P")
  6285. (cond
  6286. ((or (equal arg '(16))
  6287. (memq last-command
  6288. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6289. (setq this-command 'org-agenda-date-later-minutes)
  6290. (org-agenda-date-later-minutes 1))
  6291. ((or (equal arg '(4))
  6292. (memq last-command
  6293. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6294. (setq this-command 'org-agenda-date-later-hours)
  6295. (org-agenda-date-later-hours 1))
  6296. (t
  6297. (org-agenda-date-later (prefix-numeric-value arg)))))
  6298. (defun org-agenda-do-date-earlier (arg)
  6299. (interactive "P")
  6300. (cond
  6301. ((or (equal arg '(16))
  6302. (memq last-command
  6303. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6304. (setq this-command 'org-agenda-date-earlier-minutes)
  6305. (org-agenda-date-earlier-minutes 1))
  6306. ((or (equal arg '(4))
  6307. (memq last-command
  6308. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6309. (setq this-command 'org-agenda-date-earlier-hours)
  6310. (org-agenda-date-earlier-hours 1))
  6311. (t
  6312. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6313. (defun org-agenda-date-later (arg &optional what)
  6314. "Change the date of this item to one day later."
  6315. (interactive "p")
  6316. (org-agenda-check-type t 'agenda 'timeline)
  6317. (org-agenda-check-no-diary)
  6318. (let* ((marker (or (org-get-at-bol 'org-marker)
  6319. (org-agenda-error)))
  6320. (buffer (marker-buffer marker))
  6321. (pos (marker-position marker)))
  6322. (org-with-remote-undo buffer
  6323. (with-current-buffer buffer
  6324. (widen)
  6325. (goto-char pos)
  6326. (if (not (org-at-timestamp-p))
  6327. (error "Cannot find time stamp"))
  6328. (org-timestamp-change arg (or what 'day)))
  6329. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6330. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6331. (defun org-agenda-date-earlier (arg &optional what)
  6332. "Change the date of this item to one day earlier."
  6333. (interactive "p")
  6334. (org-agenda-date-later (- arg) what))
  6335. (defun org-agenda-date-later-minutes (arg)
  6336. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6337. (interactive "p")
  6338. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6339. (org-agenda-date-later arg 'minute))
  6340. (defun org-agenda-date-earlier-minutes (arg)
  6341. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6342. (interactive "p")
  6343. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6344. (org-agenda-date-earlier arg 'minute))
  6345. (defun org-agenda-date-later-hours (arg)
  6346. "Change the time of this item, in hour steps."
  6347. (interactive "p")
  6348. (org-agenda-date-later arg 'hour))
  6349. (defun org-agenda-date-earlier-hours (arg)
  6350. "Change the time of this item, in hour steps."
  6351. (interactive "p")
  6352. (org-agenda-date-earlier arg 'hour))
  6353. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6354. "Show new date stamp via text properties."
  6355. ;; We use text properties to make this undoable
  6356. (let ((inhibit-read-only t)
  6357. (buffer-invisibility-spec))
  6358. (setq stamp (concat " " prefix " => " stamp))
  6359. (save-excursion
  6360. (goto-char (point-max))
  6361. (while (not (bobp))
  6362. (when (equal marker (org-get-at-bol 'org-marker))
  6363. (org-move-to-column (- (window-width) (length stamp)) t)
  6364. (org-agenda-fix-tags-filter-overlays-at (point))
  6365. (if (featurep 'xemacs)
  6366. ;; Use `duplicable' property to trigger undo recording
  6367. (let ((ex (make-extent nil nil))
  6368. (gl (make-glyph stamp)))
  6369. (set-glyph-face gl 'secondary-selection)
  6370. (set-extent-properties
  6371. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6372. (insert-extent ex (1- (point)) (point-at-eol)))
  6373. (add-text-properties
  6374. (1- (point)) (point-at-eol)
  6375. (list 'display (org-add-props stamp nil
  6376. 'face 'secondary-selection))))
  6377. (beginning-of-line 1))
  6378. (beginning-of-line 0)))))
  6379. (defun org-agenda-date-prompt (arg)
  6380. "Change the date of this item. Date is prompted for, with default today.
  6381. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6382. be used to request time specification in the time stamp."
  6383. (interactive "P")
  6384. (org-agenda-check-type t 'agenda 'timeline)
  6385. (org-agenda-check-no-diary)
  6386. (let* ((marker (or (org-get-at-bol 'org-marker)
  6387. (org-agenda-error)))
  6388. (buffer (marker-buffer marker))
  6389. (pos (marker-position marker)))
  6390. (org-with-remote-undo buffer
  6391. (with-current-buffer buffer
  6392. (widen)
  6393. (goto-char pos)
  6394. (if (not (org-at-timestamp-p t))
  6395. (error "Cannot find time stamp"))
  6396. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6397. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6398. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6399. (defun org-agenda-schedule (arg)
  6400. "Schedule the item at point.
  6401. Arg is passed through to `org-schedule'."
  6402. (interactive "P")
  6403. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6404. (org-agenda-check-no-diary)
  6405. (let* ((marker (or (org-get-at-bol 'org-marker)
  6406. (org-agenda-error)))
  6407. (type (marker-insertion-type marker))
  6408. (buffer (marker-buffer marker))
  6409. (pos (marker-position marker))
  6410. (org-insert-labeled-timestamps-at-point nil)
  6411. ts)
  6412. (set-marker-insertion-type marker t)
  6413. (org-with-remote-undo buffer
  6414. (with-current-buffer buffer
  6415. (widen)
  6416. (goto-char pos)
  6417. (setq ts (org-schedule arg)))
  6418. (org-agenda-show-new-time marker ts "S"))
  6419. (message "Item scheduled for %s" ts)))
  6420. (defun org-agenda-deadline (arg)
  6421. "Schedule the item at point.
  6422. Arg is passed through to `org-deadline'."
  6423. (interactive "P")
  6424. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6425. (org-agenda-check-no-diary)
  6426. (let* ((marker (or (org-get-at-bol 'org-marker)
  6427. (org-agenda-error)))
  6428. (buffer (marker-buffer marker))
  6429. (pos (marker-position marker))
  6430. (org-insert-labeled-timestamps-at-point nil)
  6431. ts)
  6432. (org-with-remote-undo buffer
  6433. (with-current-buffer buffer
  6434. (widen)
  6435. (goto-char pos)
  6436. (setq ts (org-deadline arg)))
  6437. (org-agenda-show-new-time marker ts "D"))
  6438. (message "Deadline for this item set to %s" ts)))
  6439. (defun org-agenda-action ()
  6440. "Select entry for agenda action, or execute an agenda action.
  6441. This command prompts for another letter. Valid inputs are:
  6442. m Mark the entry at point for an agenda action
  6443. s Schedule the marked entry to the date at the cursor
  6444. d Set the deadline of the marked entry to the date at the cursor
  6445. r Call `org-remember' with cursor date as the default date
  6446. SPC Show marked entry in other window
  6447. TAB Visit marked entry in other window
  6448. The cursor may be at a date in the calendar, or in the Org agenda."
  6449. (interactive)
  6450. (let (ans)
  6451. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6452. (setq ans (read-char-exclusive))
  6453. (cond
  6454. ((equal ans ?m)
  6455. ;; Mark this entry
  6456. (if (eq major-mode 'org-agenda-mode)
  6457. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6458. (org-get-at-bol 'org-marker))))
  6459. (if m
  6460. (progn
  6461. (move-marker org-agenda-action-marker
  6462. (marker-position m) (marker-buffer m))
  6463. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6464. (error "Don't know which entry to mark")))
  6465. (error "This command works only in the agenda")))
  6466. ((equal ans ?s)
  6467. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6468. ((equal ans ?d)
  6469. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6470. ((equal ans ?r)
  6471. (org-agenda-do-action '(org-remember) t))
  6472. ((equal ans ?\ )
  6473. (let ((cw (selected-window)))
  6474. (org-switch-to-buffer-other-window
  6475. (marker-buffer org-agenda-action-marker))
  6476. (goto-char org-agenda-action-marker)
  6477. (org-show-context 'agenda)
  6478. (select-window cw)))
  6479. ((equal ans ?\C-i)
  6480. (org-switch-to-buffer-other-window
  6481. (marker-buffer org-agenda-action-marker))
  6482. (goto-char org-agenda-action-marker)
  6483. (org-show-context 'agenda))
  6484. (t (error "Invalid agenda action %c" ans)))))
  6485. (defun org-agenda-do-action (form &optional current-buffer)
  6486. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6487. (let ((org-overriding-default-time (org-get-cursor-date)))
  6488. (if current-buffer
  6489. (eval form)
  6490. (if (not (marker-buffer org-agenda-action-marker))
  6491. (error "No entry has been selected for agenda action")
  6492. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6493. (save-excursion
  6494. (save-restriction
  6495. (widen)
  6496. (goto-char org-agenda-action-marker)
  6497. (eval form))))))))
  6498. (defun org-agenda-clock-in (&optional arg)
  6499. "Start the clock on the currently selected item."
  6500. (interactive "P")
  6501. (org-agenda-check-no-diary)
  6502. (if (equal arg '(4))
  6503. (org-clock-in arg)
  6504. (let* ((marker (or (org-get-at-bol 'org-marker)
  6505. (org-agenda-error)))
  6506. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6507. marker))
  6508. (pos (marker-position marker))
  6509. newhead)
  6510. (org-with-remote-undo (marker-buffer marker)
  6511. (with-current-buffer (marker-buffer marker)
  6512. (widen)
  6513. (goto-char pos)
  6514. (org-show-context 'agenda)
  6515. (org-show-entry)
  6516. (org-cycle-hide-drawers 'children)
  6517. (org-clock-in arg)
  6518. (setq newhead (org-get-heading)))
  6519. (org-agenda-change-all-lines newhead hdmarker)))))
  6520. (defun org-agenda-clock-out (&optional arg)
  6521. "Stop the currently running clock."
  6522. (interactive "P")
  6523. (unless (marker-buffer org-clock-marker)
  6524. (error "No running clock"))
  6525. (let ((marker (make-marker)) newhead)
  6526. (org-with-remote-undo (marker-buffer org-clock-marker)
  6527. (with-current-buffer (marker-buffer org-clock-marker)
  6528. (save-excursion
  6529. (save-restriction
  6530. (widen)
  6531. (goto-char org-clock-marker)
  6532. (org-back-to-heading t)
  6533. (move-marker marker (point))
  6534. (org-clock-out)
  6535. (setq newhead (org-get-heading))))))
  6536. (org-agenda-change-all-lines newhead marker)
  6537. (move-marker marker nil)))
  6538. (defun org-agenda-clock-cancel (&optional arg)
  6539. "Cancel the currently running clock."
  6540. (interactive "P")
  6541. (unless (marker-buffer org-clock-marker)
  6542. (error "No running clock"))
  6543. (org-with-remote-undo (marker-buffer org-clock-marker)
  6544. (org-clock-cancel)))
  6545. (defun org-agenda-diary-entry-in-org-file ()
  6546. "Make a diary entry in the file `org-agenda-diary-file'."
  6547. (let (d1 d2 char (text "") dp1 dp2)
  6548. (if (equal (buffer-name) "*Calendar*")
  6549. (setq d1 (calendar-cursor-to-date t)
  6550. d2 (car calendar-mark-ring))
  6551. (setq dp1 (get-text-property (point-at-bol) 'day))
  6552. (unless dp1 (error "No date defined in current line"))
  6553. (setq d1 (calendar-gregorian-from-absolute dp1)
  6554. d2 (and (ignore-errors (mark))
  6555. (save-excursion
  6556. (goto-char (mark))
  6557. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6558. (calendar-gregorian-from-absolute dp2))))
  6559. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6560. (setq char (read-char-exclusive))
  6561. (cond
  6562. ((equal char ?d)
  6563. (setq text (read-string "Day entry: "))
  6564. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6565. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6566. ((equal char ?a)
  6567. (setq d1 (list (car d1) (nth 1 d1)
  6568. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6569. (nth 2 d1))))
  6570. (setq text (read-string "Anniversary (use %d to show years): "))
  6571. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6572. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6573. ((equal char ?b)
  6574. (setq text (read-string "Block entry: "))
  6575. (unless (and d1 d2 (not (equal d1 d2)))
  6576. (error "No block of days selected"))
  6577. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6578. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6579. ((equal char ?j)
  6580. (org-switch-to-buffer-other-window
  6581. (find-file-noselect org-agenda-diary-file))
  6582. (require 'org-datetree)
  6583. (org-datetree-find-date-create d1)
  6584. (org-reveal t))
  6585. (t (error "Invalid selection character `%c'" char)))))
  6586. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6587. "Where in `org-agenda-diary-file' should new entries be added?
  6588. Valid values:
  6589. date-tree in the date tree, as child of the date
  6590. top-level as top-level entries at the end of the file."
  6591. :group 'org-agenda
  6592. :type '(choice
  6593. (const :tag "in a date tree" date-tree)
  6594. (const :tag "as top level at end of file" top-level)))
  6595. (defcustom org-agenda-insert-diary-extract-time nil
  6596. "Non-nil means extract any time specification from the diary entry."
  6597. :group 'org-agenda
  6598. :type 'boolean)
  6599. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6600. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6601. If TEXT is not empty, it will become the headline of the new entry, and
  6602. the resulting entry will not be shown. When TEXT is empty, switch to
  6603. `org-agenda-diary-file' and let the user finish the entry there."
  6604. (let ((cw (current-window-configuration)))
  6605. (org-switch-to-buffer-other-window
  6606. (find-file-noselect org-agenda-diary-file))
  6607. (widen)
  6608. (goto-char (point-min))
  6609. (cond
  6610. ((eq type 'anniversary)
  6611. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6612. (progn
  6613. (or (org-on-heading-p t)
  6614. (progn
  6615. (outline-next-heading)
  6616. (insert "* Anniversaries\n\n")
  6617. (beginning-of-line -1)))))
  6618. (outline-next-heading)
  6619. (org-back-over-empty-lines)
  6620. (backward-char 1)
  6621. (insert "\n")
  6622. (require 'diary-lib)
  6623. (let ((calendar-date-display-form
  6624. (if (if (boundp 'calendar-date-style)
  6625. (eq calendar-date-style 'european)
  6626. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6627. '(day " " month " " year)
  6628. '(month " " day " " year))))
  6629. (insert (format "%%%%(diary-anniversary %s) %s"
  6630. (calendar-date-string d1 nil t) text))))
  6631. ((eq type 'day)
  6632. (let ((org-prefix-has-time t)
  6633. (org-agenda-time-leading-zero t)
  6634. fmt time time2)
  6635. (if org-agenda-insert-diary-extract-time
  6636. ;; Use org-format-agenda-item to parse text for a time-range and
  6637. ;; remove it. FIXME: This is a hack, we should refactor
  6638. ;; that function to make time extraction available separately
  6639. (setq fmt (org-format-agenda-item nil text nil nil t)
  6640. time (get-text-property 0 'time fmt)
  6641. time2 (if (> (length time) 0)
  6642. ;; split-string removes trailing ...... if
  6643. ;; no end time given. First space
  6644. ;; separates time from date.
  6645. (concat " " (car (split-string time "\\.")))
  6646. nil)
  6647. text (get-text-property 0 'txt fmt)))
  6648. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6649. (org-agenda-insert-diary-as-top-level text)
  6650. (require 'org-datetree)
  6651. (org-datetree-find-date-create d1)
  6652. (org-agenda-insert-diary-make-new-entry text))
  6653. (org-insert-time-stamp (org-time-from-absolute
  6654. (calendar-absolute-from-gregorian d1))
  6655. nil nil nil nil time2))
  6656. (end-of-line 0))
  6657. ((eq type 'block)
  6658. (if (> (calendar-absolute-from-gregorian d1)
  6659. (calendar-absolute-from-gregorian d2))
  6660. (setq d1 (prog1 d2 (setq d2 d1))))
  6661. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6662. (org-agenda-insert-diary-as-top-level text)
  6663. (require 'org-datetree)
  6664. (org-datetree-find-date-create d1)
  6665. (org-agenda-insert-diary-make-new-entry text))
  6666. (org-insert-time-stamp (org-time-from-absolute
  6667. (calendar-absolute-from-gregorian d1)))
  6668. (insert "--")
  6669. (org-insert-time-stamp (org-time-from-absolute
  6670. (calendar-absolute-from-gregorian d2)))
  6671. (end-of-line 0)))
  6672. (if (string-match "\\S-" text)
  6673. (progn
  6674. (set-window-configuration cw)
  6675. (message "%s entry added to %s"
  6676. (capitalize (symbol-name type))
  6677. (abbreviate-file-name org-agenda-diary-file)))
  6678. (org-reveal t)
  6679. (message "Please finish entry here"))))
  6680. (defun org-agenda-insert-diary-as-top-level (text)
  6681. "Make new entry as a top-level entry at the end of the file.
  6682. Add TEXT as headline, and position the cursor in the second line so that
  6683. a timestamp can be added there."
  6684. (widen)
  6685. (goto-char (point-max))
  6686. (or (bolp) (insert "\n"))
  6687. (insert "* " text "\n")
  6688. (if org-adapt-indentation (org-indent-to-column 2)))
  6689. (defun org-agenda-insert-diary-make-new-entry (text)
  6690. "Make new entry as last child of current entry.
  6691. Add TEXT as headline, and position the cursor in the second line so that
  6692. a timestamp can be added there."
  6693. (let ((org-show-following-heading t)
  6694. (org-show-siblings t)
  6695. (org-show-hierarchy-above t)
  6696. (org-show-entry-below t)
  6697. col)
  6698. (outline-next-heading)
  6699. (org-back-over-empty-lines)
  6700. (or (looking-at "[ \t]*$")
  6701. (progn (insert "\n") (backward-char 1)))
  6702. (org-insert-heading nil t)
  6703. (org-do-demote)
  6704. (setq col (current-column))
  6705. (insert text "\n")
  6706. (if org-adapt-indentation (org-indent-to-column col))
  6707. (let ((org-show-following-heading t)
  6708. (org-show-siblings t)
  6709. (org-show-hierarchy-above t)
  6710. (org-show-entry-below t))
  6711. (org-show-context))))
  6712. (defun org-agenda-diary-entry ()
  6713. "Make a diary entry, like the `i' command from the calendar.
  6714. All the standard commands work: block, weekly etc.
  6715. When `org-agenda-diary-file' points to a file,
  6716. `org-agenda-diary-entry-in-org-file' is called instead to create
  6717. entries in that Org-mode file."
  6718. (interactive)
  6719. (org-agenda-check-type t 'agenda 'timeline)
  6720. (if (not (eq org-agenda-diary-file 'diary-file))
  6721. (org-agenda-diary-entry-in-org-file)
  6722. (require 'diary-lib)
  6723. (let* ((char (progn
  6724. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6725. (read-char-exclusive)))
  6726. (cmd (cdr (assoc char
  6727. '((?d . insert-diary-entry)
  6728. (?w . insert-weekly-diary-entry)
  6729. (?m . insert-monthly-diary-entry)
  6730. (?y . insert-yearly-diary-entry)
  6731. (?a . insert-anniversary-diary-entry)
  6732. (?b . insert-block-diary-entry)
  6733. (?c . insert-cyclic-diary-entry)))))
  6734. (oldf (symbol-function 'calendar-cursor-to-date))
  6735. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6736. (point (point))
  6737. (mark (or (mark t) (point))))
  6738. (unless cmd
  6739. (error "No command associated with <%c>" char))
  6740. (unless (and (get-text-property point 'day)
  6741. (or (not (equal ?b char))
  6742. (get-text-property mark 'day)))
  6743. (error "Don't know which date to use for diary entry"))
  6744. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6745. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6746. (let ((calendar-mark-ring
  6747. (list (calendar-gregorian-from-absolute
  6748. (or (get-text-property mark 'day)
  6749. (get-text-property point 'day))))))
  6750. (unwind-protect
  6751. (progn
  6752. (fset 'calendar-cursor-to-date
  6753. (lambda (&optional error dummy)
  6754. (calendar-gregorian-from-absolute
  6755. (get-text-property point 'day))))
  6756. (call-interactively cmd))
  6757. (fset 'calendar-cursor-to-date oldf))))))
  6758. (defun org-agenda-execute-calendar-command (cmd)
  6759. "Execute a calendar command from the agenda, with the date associated to
  6760. the cursor position."
  6761. (org-agenda-check-type t 'agenda 'timeline)
  6762. (require 'diary-lib)
  6763. (unless (get-text-property (point) 'day)
  6764. (error "Don't know which date to use for calendar command"))
  6765. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6766. (point (point))
  6767. (date (calendar-gregorian-from-absolute
  6768. (get-text-property point 'day)))
  6769. ;; the following 2 vars are needed in the calendar
  6770. (displayed-month (car date))
  6771. (displayed-year (nth 2 date)))
  6772. (unwind-protect
  6773. (progn
  6774. (fset 'calendar-cursor-to-date
  6775. (lambda (&optional error dummy)
  6776. (calendar-gregorian-from-absolute
  6777. (get-text-property point 'day))))
  6778. (call-interactively cmd))
  6779. (fset 'calendar-cursor-to-date oldf))))
  6780. (defun org-agenda-phases-of-moon ()
  6781. "Display the phases of the moon for the 3 months around the cursor date."
  6782. (interactive)
  6783. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6784. (defun org-agenda-holidays ()
  6785. "Display the holidays for the 3 months around the cursor date."
  6786. (interactive)
  6787. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6788. (defvar calendar-longitude)
  6789. (defvar calendar-latitude)
  6790. (defvar calendar-location-name)
  6791. (defun org-agenda-sunrise-sunset (arg)
  6792. "Display sunrise and sunset for the cursor date.
  6793. Latitude and longitude can be specified with the variables
  6794. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6795. argument, latitude and longitude will be prompted for."
  6796. (interactive "P")
  6797. (require 'solar)
  6798. (let ((calendar-longitude (if arg nil calendar-longitude))
  6799. (calendar-latitude (if arg nil calendar-latitude))
  6800. (calendar-location-name
  6801. (if arg "the given coordinates" calendar-location-name)))
  6802. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6803. (defun org-agenda-goto-calendar ()
  6804. "Open the Emacs calendar with the date at the cursor."
  6805. (interactive)
  6806. (org-agenda-check-type t 'agenda 'timeline)
  6807. (let* ((day (or (get-text-property (point) 'day)
  6808. (error "Don't know which date to open in calendar")))
  6809. (date (calendar-gregorian-from-absolute day))
  6810. (calendar-move-hook nil)
  6811. (calendar-view-holidays-initially-flag nil)
  6812. (calendar-view-diary-initially-flag nil))
  6813. (calendar)
  6814. (calendar-goto-date date)))
  6815. ;;;###autoload
  6816. (defun org-calendar-goto-agenda ()
  6817. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6818. This is a command that has to be installed in `calendar-mode-map'."
  6819. (interactive)
  6820. (org-agenda-list nil (calendar-absolute-from-gregorian
  6821. (calendar-cursor-to-date))
  6822. nil))
  6823. (defun org-agenda-convert-date ()
  6824. (interactive)
  6825. (org-agenda-check-type t 'agenda 'timeline)
  6826. (let ((day (get-text-property (point) 'day))
  6827. date s)
  6828. (unless day
  6829. (error "Don't know which date to convert"))
  6830. (setq date (calendar-gregorian-from-absolute day))
  6831. (setq s (concat
  6832. "Gregorian: " (calendar-date-string date) "\n"
  6833. "ISO: " (calendar-iso-date-string date) "\n"
  6834. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6835. "Julian: " (calendar-julian-date-string date) "\n"
  6836. "Astron. JD: " (calendar-astro-date-string date)
  6837. " (Julian date number at noon UTC)\n"
  6838. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6839. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6840. "French: " (calendar-french-date-string date) "\n"
  6841. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6842. "Mayan: " (calendar-mayan-date-string date) "\n"
  6843. "Coptic: " (calendar-coptic-date-string date) "\n"
  6844. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6845. "Persian: " (calendar-persian-date-string date) "\n"
  6846. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6847. (with-output-to-temp-buffer "*Dates*"
  6848. (princ s))
  6849. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6850. ;;; Bulk commands
  6851. (defvar org-agenda-bulk-marked-entries nil
  6852. "List of markers that refer to marked entries in the agenda.")
  6853. (defun org-agenda-bulk-marked-p ()
  6854. (eq (get-char-property (point-at-bol) 'type)
  6855. 'org-marked-entry-overlay))
  6856. (defun org-agenda-bulk-mark ()
  6857. "Mark the entry at point for future bulk action."
  6858. (interactive)
  6859. (org-agenda-check-no-diary)
  6860. (let* ((m (org-get-at-bol 'org-hd-marker))
  6861. ov)
  6862. (unless (org-agenda-bulk-marked-p)
  6863. (unless m (error "Nothing to mark at point"))
  6864. (push m org-agenda-bulk-marked-entries)
  6865. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6866. (org-overlay-display ov "> "
  6867. (org-get-todo-face "TODO")
  6868. 'evaporate)
  6869. (overlay-put ov 'type 'org-marked-entry-overlay))
  6870. (beginning-of-line 2)
  6871. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6872. (beginning-of-line 2))
  6873. (message "%d entries marked for bulk action"
  6874. (length org-agenda-bulk-marked-entries))))
  6875. (defun org-agenda-bulk-unmark ()
  6876. "Unmark the entry at point for future bulk action."
  6877. (interactive)
  6878. (when (org-agenda-bulk-marked-p)
  6879. (org-agenda-bulk-remove-overlays
  6880. (point-at-bol) (+ 2 (point-at-bol)))
  6881. (setq org-agenda-bulk-marked-entries
  6882. (delete (org-get-at-bol 'org-hd-marker)
  6883. org-agenda-bulk-marked-entries)))
  6884. (beginning-of-line 2)
  6885. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6886. (beginning-of-line 2))
  6887. (message "%d entries marked for bulk action"
  6888. (length org-agenda-bulk-marked-entries)))
  6889. (defun org-agenda-bulk-toggle ()
  6890. "Toggle marking the entry at point for bulk action."
  6891. (interactive)
  6892. (if (org-agenda-bulk-marked-p)
  6893. (org-agenda-bulk-unmark)
  6894. (org-agenda-bulk-mark)))
  6895. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6896. "Remove the mark overlays between BEG and END in the agenda buffer.
  6897. BEG and END default to the buffer limits.
  6898. This only removes the overlays, it does not remove the markers
  6899. from the list in `org-agenda-bulk-marked-entries'."
  6900. (interactive)
  6901. (mapc (lambda (ov)
  6902. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  6903. (delete-overlay ov)))
  6904. (overlays-in (or beg (point-min)) (or end (point-max)))))
  6905. (defun org-agenda-bulk-remove-all-marks ()
  6906. "Remove all marks in the agenda buffer.
  6907. This will remove the markers, and the overlays."
  6908. (interactive)
  6909. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6910. (setq org-agenda-bulk-marked-entries nil)
  6911. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6912. (defun org-agenda-bulk-action (&optional arg)
  6913. "Execute an remote-editing action on all marked entries.
  6914. The prefix arg is passed through to the command if possible."
  6915. (interactive "P")
  6916. (unless org-agenda-bulk-marked-entries
  6917. (error "No entries are marked"))
  6918. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6919. (let* ((action (read-char-exclusive))
  6920. (org-log-refile (if org-log-refile 'time nil))
  6921. (entries (reverse org-agenda-bulk-marked-entries))
  6922. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6923. (cond
  6924. ((equal action ?$)
  6925. (setq cmd '(org-agenda-archive)))
  6926. ((equal action ?A)
  6927. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6928. ((member action '(?r ?w))
  6929. (setq rfloc (org-refile-get-location
  6930. "Refile to: "
  6931. (marker-buffer (car org-agenda-bulk-marked-entries))
  6932. org-refile-allow-creating-parent-nodes))
  6933. (setcar (nthcdr 3 rfloc)
  6934. (move-marker (make-marker) (nth 3 rfloc)
  6935. (or (get-file-buffer (nth 1 rfloc))
  6936. (find-buffer-visiting (nth 1 rfloc))
  6937. (error "This should not happen"))))
  6938. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6939. ((equal action ?t)
  6940. (setq state (org-icompleting-read
  6941. "Todo state: "
  6942. (with-current-buffer (marker-buffer (car entries))
  6943. (mapcar 'list org-todo-keywords-1))))
  6944. (setq cmd `(let ((org-inhibit-blocking t)
  6945. (org-inhibit-logging 'note))
  6946. (org-agenda-todo ,state))))
  6947. ((memq action '(?- ?+))
  6948. (setq tag (org-icompleting-read
  6949. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6950. (with-current-buffer (marker-buffer (car entries))
  6951. (delq nil
  6952. (mapcar (lambda (x)
  6953. (if (stringp (car x)) x)) org-tag-alist)))))
  6954. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6955. ((memq action '(?s ?d))
  6956. (let* ((date (unless arg
  6957. (org-read-date
  6958. nil nil nil
  6959. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  6960. (ans (if arg nil org-read-date-final-answer))
  6961. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6962. (setq cmd `(let* ((bound (fboundp 'read-string))
  6963. (old (and bound (symbol-function 'read-string))))
  6964. (unwind-protect
  6965. (progn
  6966. (fset 'read-string (lambda (&rest ignore) ,ans))
  6967. (eval '(,c1 arg)))
  6968. (if bound
  6969. (fset 'read-string old)
  6970. (fmakunbound 'read-string)))))))
  6971. (t (error "Invalid bulk action")))
  6972. ;; Sort the markers, to make sure that parents are handled before children
  6973. (setq entries (sort entries
  6974. (lambda (a b)
  6975. (cond
  6976. ((equal (marker-buffer a) (marker-buffer b))
  6977. (< (marker-position a) (marker-position b)))
  6978. (t
  6979. (string< (buffer-name (marker-buffer a))
  6980. (buffer-name (marker-buffer b))))))))
  6981. ;; Now loop over all markers and apply cmd
  6982. (while (setq e (pop entries))
  6983. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6984. (if (not pos)
  6985. (progn (message "Skipping removed entry at %s" e)
  6986. (setq cntskip (1+ cntskip)))
  6987. (goto-char pos)
  6988. (eval cmd)
  6989. (setq org-agenda-bulk-marked-entries
  6990. (delete e org-agenda-bulk-marked-entries))
  6991. (setq cnt (1+ cnt))))
  6992. (setq org-agenda-bulk-marked-entries nil)
  6993. (org-agenda-bulk-remove-all-marks)
  6994. (message "Acted on %d entries%s"
  6995. cnt
  6996. (if (= cntskip 0)
  6997. ""
  6998. (format ", skipped %d (disappeared before their turn)"
  6999. cntskip)))))
  7000. ;;; Flagging notes
  7001. (defun org-agenda-show-the-flagging-note ()
  7002. "Display the flagging note in the other window.
  7003. When called a second time in direct sequence, offer to remove the FLAGGING
  7004. tag and (if present) the flagging note."
  7005. (interactive)
  7006. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7007. (win (selected-window))
  7008. note heading newhead)
  7009. (unless hdmarker
  7010. (error "No linked entry at point"))
  7011. (if (and (eq this-command last-command)
  7012. (y-or-n-p "Unflag and remove any flagging note? "))
  7013. (progn
  7014. (org-agenda-remove-flag hdmarker)
  7015. (let ((win (get-buffer-window "*Flagging Note*")))
  7016. (and win (delete-window win)))
  7017. (message "Entry unflaged"))
  7018. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7019. (unless note
  7020. (error "No flagging note"))
  7021. (org-kill-new note)
  7022. (org-switch-to-buffer-other-window "*Flagging Note*")
  7023. (erase-buffer)
  7024. (insert note)
  7025. (goto-char (point-min))
  7026. (while (re-search-forward "\\\\n" nil t)
  7027. (replace-match "\n" t t))
  7028. (goto-char (point-min))
  7029. (select-window win)
  7030. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7031. (defun org-agenda-remove-flag (marker)
  7032. "Remove the FLAGGED tag and any flagging note in the entry."
  7033. (let (newhead)
  7034. (org-with-point-at marker
  7035. (org-toggle-tag "FLAGGED" 'off)
  7036. (org-entry-delete nil "THEFLAGGINGNOTE")
  7037. (setq newhead (org-get-heading)))
  7038. (org-agenda-change-all-lines newhead marker)
  7039. (message "Entry unflaged")))
  7040. (defun org-agenda-get-any-marker (&optional pos)
  7041. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7042. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7043. ;;; Appointment reminders
  7044. (defvar appt-time-msg-list)
  7045. ;;;###autoload
  7046. (defun org-agenda-to-appt (&optional refresh filter)
  7047. "Activate appointments found in `org-agenda-files'.
  7048. With a \\[universal-argument] prefix, refresh the list of
  7049. appointments.
  7050. If FILTER is t, interactively prompt the user for a regular
  7051. expression, and filter out entries that don't match it.
  7052. If FILTER is a string, use this string as a regular expression
  7053. for filtering entries out.
  7054. FILTER can also be an alist with the car of each cell being
  7055. either 'headline or 'category. For example:
  7056. '((headline \"IMPORTANT\")
  7057. (category \"Work\"))
  7058. will only add headlines containing IMPORTANT or headlines
  7059. belonging to the \"Work\" category."
  7060. (interactive "P")
  7061. (if refresh (setq appt-time-msg-list nil))
  7062. (if (eq filter t)
  7063. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7064. (let* ((cnt 0) ; count added events
  7065. (org-agenda-new-buffers nil)
  7066. (org-deadline-warning-days 0)
  7067. (today (org-date-to-gregorian
  7068. (time-to-days (current-time))))
  7069. (org-agenda-restrict nil)
  7070. (files (org-agenda-files 'unrestricted)) entries file)
  7071. ;; Get all entries which may contain an appt
  7072. (org-prepare-agenda-buffers files)
  7073. (while (setq file (pop files))
  7074. (setq entries
  7075. (append entries
  7076. (org-agenda-get-day-entries
  7077. file today :timestamp :scheduled :deadline))))
  7078. (setq entries (delq nil entries))
  7079. ;; Map thru entries and find if we should filter them out
  7080. (mapc
  7081. (lambda(x)
  7082. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7083. (cat (get-text-property 1 'org-category x))
  7084. (tod (get-text-property 1 'time-of-day x))
  7085. (ok (or (null filter)
  7086. (and (stringp filter) (string-match filter evt))
  7087. (and (listp filter)
  7088. (or (string-match
  7089. (cadr (assoc 'category filter)) cat)
  7090. (string-match
  7091. (cadr (assoc 'headline filter)) evt))))))
  7092. ;; FIXME: Shall we remove text-properties for the appt text?
  7093. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7094. (when (and ok tod)
  7095. (setq tod (concat "00" (number-to-string tod))
  7096. tod (when (string-match
  7097. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7098. (concat (match-string 1 tod) ":"
  7099. (match-string 2 tod))))
  7100. (appt-add tod evt)
  7101. (setq cnt (1+ cnt))))) entries)
  7102. (org-release-buffers org-agenda-new-buffers)
  7103. (if (eq cnt 0)
  7104. (message "No event to add")
  7105. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7106. (defun org-agenda-todayp (date)
  7107. "Does DATE mean today, when considering `org-extend-today-until'?"
  7108. (let (today h)
  7109. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7110. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7111. (setq h (nth 2 (decode-time (current-time))))
  7112. (or (and (>= h org-extend-today-until)
  7113. (= date today))
  7114. (and (< h org-extend-today-until)
  7115. (= date (1- today))))))
  7116. (provide 'org-agenda)
  7117. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7118. ;;; org-agenda.el ends here