org-agenda.el 294 KB

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